The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1257 lines
58KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: PushNotificationsDemo
  20. version: 2.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Showcases push notifications features. To run this demo you must enable the
  24. "Push Notifications Capability" option in the Projucer exporter.
  25. dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
  26. juce_audio_processors, juce_audio_utils, juce_core,
  27. juce_data_structures, juce_events, juce_graphics,
  28. juce_gui_basics, juce_gui_extra
  29. exporters: xcode_mac, xcode_iphone, androidstudio
  30. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  31. JUCE_PUSH_NOTIFICATIONS=1
  32. type: Component
  33. mainClass: PushNotificationsDemo
  34. useLocalCopy: 1
  35. END_JUCE_PIP_METADATA
  36. *******************************************************************************/
  37. #pragma once
  38. #include "../Assets/DemoUtilities.h"
  39. /*
  40. To finish the setup of this demo, do the following:
  41. 1. Download google_services.json from your Firebase project.
  42. 2. Update "Remote Notifications Config File" path in Android exporter (this can be different for debug and release)
  43. to point to that json file.
  44. 3. Add image and sound resources by adding the following to "Extra Android Raw Resources" in Projucer:
  45. ../../Assets/Notifications/images/ic_stat_name.png
  46. ../../Assets/Notifications/images/ic_stat_name2.png
  47. ../../Assets/Notifications/images/ic_stat_name3.png
  48. ../../Assets/Notifications/images/ic_stat_name4.png
  49. ../../Assets/Notifications/images/ic_stat_name5.png
  50. ../../Assets/Notifications/images/ic_stat_name6.png
  51. ../../Assets/Notifications/images/ic_stat_name7.png
  52. ../../Assets/Notifications/images/ic_stat_name8.png
  53. ../../Assets/Notifications/images/ic_stat_name9.png
  54. ../../Assets/Notifications/images/ic_stat_name10.png
  55. ../../Assets/Notifications/sounds/demonstrative.mp3
  56. ../../Assets/Notifications/sounds/isntit.mp3
  57. ../../Assets/Notifications/sounds/jinglebellssms.mp3
  58. ../../Assets/Notifications/sounds/served.mp3
  59. ../../Assets/Notifications/sounds/solemn.mp3
  60. 4. Set "Remote Notifications" to enabled in Projucer Android exporter.
  61. To verify that remote notifications are configured properly, go to Remote tab in the demo and press "GetDeviceToken"
  62. button, a dialog with your token (also printed to console in debug build) should show up.
  63. The following steps are only necessary if you have a custom activity defined:
  64. 5. Ensure that its launchMode is set to "singleTop" or "singleTask" in Android manifest. This is the default behaviour
  65. in JUCE so you only need to do it if you have custom Android manifest content. You can do it from Projucer by
  66. ensuring that "Custom Manifest XML Content" contains:
  67. <manifest>
  68. <application>
  69. <activity android:launchMode="singleTask">
  70. </activity>
  71. </application>
  72. </manifest>
  73. 6. Ensure that you override onNewIntent() function in the same way as it is done in JuceActivity.java:
  74. package com.rmsl.juce;
  75. import android.app.Activity;
  76. import android.content.Intent;
  77. //==============================================================================
  78. public class JuceActivity extends Activity
  79. {
  80. //==============================================================================
  81. private native void appNewIntent (Intent intent);
  82. @Override
  83. protected void onNewIntent (Intent intent)
  84. {
  85. super.onNewIntent(intent);
  86. setIntent(intent);
  87. appNewIntent (intent);
  88. }
  89. }
  90. */
  91. //==============================================================================
  92. class PushNotificationsDemo : public Component,
  93. private ChangeListener,
  94. private ComponentListener,
  95. private PushNotifications::Listener
  96. {
  97. public:
  98. //==============================================================================
  99. PushNotificationsDemo()
  100. {
  101. setupControls();
  102. distributeControls();
  103. #if JUCE_PUSH_NOTIFICATIONS
  104. addAndMakeVisible (headerLabel);
  105. addAndMakeVisible (mainTabs);
  106. addAndMakeVisible (sendButton);
  107. #else
  108. addAndMakeVisible (notAvailableYetLabel);
  109. #endif
  110. headerLabel .setJustificationType (Justification::centred);
  111. notAvailableYetLabel.setJustificationType (Justification::centred);
  112. #if JUCE_MAC
  113. StringArray tabNames { "Params1", "Params2", "Params3", "Params4" };
  114. #else
  115. StringArray tabNames { "Req. params", "Opt. params1", "Opt. params2", "Opt. params3" };
  116. #endif
  117. auto colour = getLookAndFeel().findColour (ResizableWindow::backgroundColourId);
  118. localNotificationsTabs.addTab (tabNames[0], colour, &paramsOneView, false);
  119. localNotificationsTabs.addTab (tabNames[1], colour, &paramsTwoView, false);
  120. #if JUCE_ANDROID
  121. localNotificationsTabs.addTab (tabNames[2], colour, &paramsThreeView, false);
  122. localNotificationsTabs.addTab (tabNames[3], colour, &paramsFourView, false);
  123. #endif
  124. localNotificationsTabs.addTab ("Aux. actions", colour, &auxActionsView, false);
  125. mainTabs.addTab ("Local", colour, &localNotificationsTabs, false);
  126. mainTabs.addTab ("Remote", colour, &remoteView, false);
  127. auto userArea = Desktop::getInstance().getDisplays().getPrimaryDisplay()->userArea;
  128. #if JUCE_ANDROID || JUCE_IOS
  129. setSize (userArea.getWidth(), userArea.getHeight());
  130. #else
  131. setSize (userArea.getWidth() / 2, userArea.getHeight() / 2);
  132. #endif
  133. sendButton.onClick = [this] { sendLocalNotification(); };
  134. auxActionsView.getDeliveredNotificationsButton .onClick = []
  135. { PushNotifications::getInstance()->getDeliveredNotifications(); };
  136. auxActionsView.removeDeliveredNotifWithIdButton.onClick = [this]
  137. { PushNotifications::getInstance()->removeDeliveredNotification (auxActionsView.deliveredNotifIdentifier.getText()); };
  138. auxActionsView.removeAllDeliveredNotifsButton .onClick = []
  139. { PushNotifications::getInstance()->removeAllDeliveredNotifications(); };
  140. #if JUCE_IOS || JUCE_MAC
  141. auxActionsView.getPendingNotificationsButton .onClick = []
  142. { PushNotifications::getInstance()->getPendingLocalNotifications(); };
  143. auxActionsView.removePendingNotifWithIdButton.onClick = [this]
  144. { PushNotifications::getInstance()->removePendingLocalNotification (auxActionsView.pendingNotifIdentifier.getText()); };
  145. auxActionsView.removeAllPendingNotifsButton .onClick = []
  146. { PushNotifications::getInstance()->removeAllPendingLocalNotifications(); };
  147. #endif
  148. remoteView.getDeviceTokenButton.onClick = []
  149. {
  150. String token = PushNotifications::getInstance()->getDeviceToken();
  151. DBG ("token = " + token);
  152. if (token.isEmpty())
  153. showRemoteInstructions();
  154. else
  155. NativeMessageBox::showAsync (MessageBoxOptions()
  156. .withIconType (MessageBoxIconType::InfoIcon)
  157. .withTitle ("Device token")
  158. .withMessage (token)
  159. .withButton ("OK"),
  160. nullptr);
  161. };
  162. #if JUCE_ANDROID
  163. remoteView.sendRemoteMessageButton.onClick = []
  164. {
  165. StringPairArray data;
  166. data.set ("key1", "value1");
  167. data.set ("key2", "value2");
  168. static int id = 100;
  169. PushNotifications::getInstance()->sendUpstreamMessage ("872047750958",
  170. "com.juce.pushnotificationsdemo",
  171. String (id++),
  172. "standardType",
  173. 3600,
  174. data);
  175. };
  176. remoteView.subscribeToSportsButton .onClick = []
  177. { PushNotifications::getInstance()->subscribeToTopic ("sports"); };
  178. remoteView.unsubscribeFromSportsButton.onClick = []
  179. { PushNotifications::getInstance()->unsubscribeFromTopic ("sports"); };
  180. #endif
  181. paramControls.accentColourButton.onClick = [this] { setupAccentColour(); };
  182. paramControls.ledColourButton .onClick = [this] { setupLedColour(); };
  183. jassert (PushNotifications::getInstance()->areNotificationsEnabled());
  184. PushNotifications::getInstance()->addListener (this);
  185. #if JUCE_IOS || JUCE_MAC
  186. paramControls.fireInComboBox.onChange = [this] { delayNotification(); };
  187. PushNotifications::getInstance()->requestPermissionsWithSettings (getNotificationSettings());
  188. #elif JUCE_ANDROID
  189. PushNotifications::ChannelGroup cg { "demoGroup", "demo group" };
  190. PushNotifications::getInstance()->setupChannels ({ { cg } }, getAndroidChannels());
  191. #endif
  192. #if JUCE_IOS || JUCE_ANDROID
  193. setPortraitOrientationEnabled (true);
  194. #endif
  195. }
  196. ~PushNotificationsDemo() override
  197. {
  198. PushNotifications::getInstance()->removeListener (this);
  199. #if JUCE_IOS || JUCE_ANDROID
  200. setPortraitOrientationEnabled (false);
  201. #endif
  202. }
  203. void setPortraitOrientationEnabled (bool shouldBeEnabled)
  204. {
  205. auto allowedOrientations = Desktop::getInstance().getOrientationsEnabled();
  206. if (shouldBeEnabled)
  207. allowedOrientations |= Desktop::upright;
  208. else
  209. allowedOrientations &= ~Desktop::upright;
  210. Desktop::getInstance().setOrientationsEnabled (allowedOrientations);
  211. }
  212. void paint (Graphics& g) override
  213. {
  214. g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
  215. }
  216. void resized() override
  217. {
  218. auto bounds = getLocalBounds().reduced (getWidth() / 20, getHeight() / 40);
  219. headerLabel.setBounds (bounds.removeFromTop (bounds.proportionOfHeight (0.1f)));
  220. mainTabs .setBounds (bounds.removeFromTop (bounds.proportionOfHeight (0.8f)));
  221. sendButton .setBounds (bounds);
  222. notAvailableYetLabel.setBounds (getLocalBounds());
  223. }
  224. private:
  225. void delayNotification()
  226. {
  227. auto repeatsAllowed = paramControls.fireInComboBox.getSelectedItemIndex() >= 6;
  228. paramControls.repeatButton.setEnabled (repeatsAllowed);
  229. if (! repeatsAllowed)
  230. paramControls.repeatButton.setToggleState (false, NotificationType::sendNotification);
  231. }
  232. void sendLocalNotification()
  233. {
  234. PushNotifications::Notification n;
  235. fillRequiredParams (n);
  236. fillOptionalParamsOne (n);
  237. #if JUCE_ANDROID
  238. fillOptionalParamsTwo (n);
  239. fillOptionalParamsThree (n);
  240. #endif
  241. if (! n.isValid())
  242. {
  243. #if JUCE_IOS
  244. String requiredFields = "identifier (from iOS 10), title, body and category";
  245. #elif JUCE_ANDROID
  246. String requiredFields = "channel ID (from Android O), title, body and icon";
  247. #else
  248. String requiredFields = "all required fields";
  249. #endif
  250. NativeMessageBox::showAsync (MessageBoxOptions()
  251. .withIconType (MessageBoxIconType::InfoIcon)
  252. .withTitle ("Incorrect notifications setup")
  253. .withMessage ("Please make sure that " + requiredFields + " are set.")
  254. .withButton ("OK"),
  255. nullptr);
  256. return;
  257. }
  258. PushNotifications::getInstance()->sendLocalNotification (n);
  259. }
  260. void fillRequiredParams (PushNotifications::Notification& n)
  261. {
  262. n.identifier = paramControls.identifierEditor.getText();
  263. n.title = paramControls.titleEditor .getText();
  264. n.body = paramControls.bodyEditor .getText();
  265. #if JUCE_IOS
  266. n.category = paramControls.categoryComboBox.getText();
  267. #elif JUCE_ANDROID || JUCE_MAC
  268. #if JUCE_MAC
  269. String prefix = "Notifications/images/";
  270. String extension = ".png";
  271. #else
  272. String prefix;
  273. String extension;
  274. #endif
  275. if (paramControls.iconComboBox.getSelectedItemIndex() == 0)
  276. n.icon = prefix + "ic_stat_name" + extension;
  277. else if (paramControls.iconComboBox.getSelectedItemIndex() == 1)
  278. n.icon = prefix + "ic_stat_name2" + extension;
  279. else if (paramControls.iconComboBox.getSelectedItemIndex() == 2)
  280. n.icon = prefix + "ic_stat_name3" + extension;
  281. else if (paramControls.iconComboBox.getSelectedItemIndex() == 3)
  282. n.icon = prefix + "ic_stat_name4" + extension;
  283. else if (paramControls.iconComboBox.getSelectedItemIndex() == 4)
  284. n.icon = prefix + "ic_stat_name5" + extension;
  285. #endif
  286. #if JUCE_ANDROID
  287. // Note: this is not strictly speaking required param, just doing it here because it is the fastest way!
  288. n.publicVersion.reset (new PushNotifications::Notification());
  289. n.publicVersion->identifier = "blahblahblah";
  290. n.publicVersion->title = "Public title!";
  291. n.publicVersion->body = "Public body!";
  292. n.publicVersion->icon = n.icon;
  293. n.channelId = String (paramControls.channelIdComboBox.getSelectedItemIndex() + 1);
  294. #endif
  295. }
  296. void fillOptionalParamsOne (PushNotifications::Notification& n)
  297. {
  298. n.subtitle = paramControls.subtitleEditor.getText();
  299. n.badgeNumber = paramControls.badgeNumberComboBox.getSelectedItemIndex();
  300. if (paramControls.soundToPlayComboBox.getSelectedItemIndex() > 0)
  301. n.soundToPlay = URL (paramControls.soundToPlayComboBox.getItemText (paramControls.soundToPlayComboBox.getSelectedItemIndex()));
  302. n.properties = JSON::parse (paramControls.propertiesEditor.getText());
  303. #if JUCE_IOS || JUCE_MAC
  304. n.triggerIntervalSec = double (paramControls.fireInComboBox.getSelectedItemIndex() * 10);
  305. n.repeat = paramControls.repeatButton.getToggleState();
  306. #elif JUCE_ANDROID
  307. if (paramControls.largeIconComboBox.getSelectedItemIndex() == 1)
  308. n.largeIcon = getImageFromAssets ("Notifications/images/ic_stat_name6.png");
  309. else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 2)
  310. n.largeIcon = getImageFromAssets ("Notifications/images/ic_stat_name7.png");
  311. else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 3)
  312. n.largeIcon = getImageFromAssets ("Notifications/images/ic_stat_name8.png");
  313. else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 4)
  314. n.largeIcon = getImageFromAssets ("Notifications/images/ic_stat_name9.png");
  315. else if (paramControls.largeIconComboBox.getSelectedItemIndex() == 5)
  316. n.largeIcon = getImageFromAssets ("Notifications/images/ic_stat_name10.png");
  317. n.badgeIconType = (PushNotifications::Notification::BadgeIconType) paramControls.badgeIconComboBox.getSelectedItemIndex();
  318. n.tickerText = paramControls.tickerTextEditor.getText();
  319. n.shouldAutoCancel = paramControls.autoCancelButton .getToggleState();
  320. n.alertOnlyOnce = paramControls.alertOnlyOnceButton.getToggleState();
  321. #endif
  322. #if JUCE_ANDROID || JUCE_MAC
  323. if (paramControls.actionsComboBox.getSelectedItemIndex() == 1)
  324. {
  325. PushNotifications::Notification::Action a, a2;
  326. a .style = PushNotifications::Notification::Action::button;
  327. a2.style = PushNotifications::Notification::Action::button;
  328. a .title = a .identifier = "Ok";
  329. a2.title = a2.identifier = "Cancel";
  330. n.actions.add (a);
  331. n.actions.add (a2);
  332. }
  333. else if (paramControls.actionsComboBox.getSelectedItemIndex() == 2)
  334. {
  335. PushNotifications::Notification::Action a, a2;
  336. a .title = a .identifier = "Input Text Here";
  337. a2.title = a2.identifier = "No";
  338. a .style = PushNotifications::Notification::Action::text;
  339. a2.style = PushNotifications::Notification::Action::button;
  340. a .icon = "ic_stat_name4";
  341. a2.icon = "ic_stat_name5";
  342. a.textInputPlaceholder = "placeholder text ...";
  343. n.actions.add (a);
  344. n.actions.add (a2);
  345. }
  346. else if (paramControls.actionsComboBox.getSelectedItemIndex() == 3)
  347. {
  348. PushNotifications::Notification::Action a, a2;
  349. a .title = a .identifier = "Ok";
  350. a2.title = a2.identifier = "Cancel";
  351. a .style = PushNotifications::Notification::Action::button;
  352. a2.style = PushNotifications::Notification::Action::button;
  353. a .icon = "ic_stat_name4";
  354. a2.icon = "ic_stat_name5";
  355. n.actions.add (a);
  356. n.actions.add (a2);
  357. }
  358. else if (paramControls.actionsComboBox.getSelectedItemIndex() == 4)
  359. {
  360. PushNotifications::Notification::Action a, a2;
  361. a .title = a .identifier = "Input Text Here";
  362. a2.title = a2.identifier = "No";
  363. a .style = PushNotifications::Notification::Action::text;
  364. a2.style = PushNotifications::Notification::Action::button;
  365. a .icon = "ic_stat_name4";
  366. a2.icon = "ic_stat_name5";
  367. a.textInputPlaceholder = "placeholder text ...";
  368. a.allowedResponses.add ("Response 1");
  369. a.allowedResponses.add ("Response 2");
  370. a.allowedResponses.add ("Response 3");
  371. n.actions.add (a);
  372. n.actions.add (a2);
  373. }
  374. #endif
  375. }
  376. void fillOptionalParamsTwo (PushNotifications::Notification& n)
  377. {
  378. using Notification = PushNotifications::Notification;
  379. Notification::Progress progress;
  380. progress.max = paramControls.progressMaxComboBox .getSelectedItemIndex() * 10;
  381. progress.current = paramControls.progressCurrentComboBox.getSelectedItemIndex() * 10;
  382. progress.indeterminate = paramControls.progressIndeterminateButton.getToggleState();
  383. n.progress = progress;
  384. n.person = paramControls.personEditor.getText();
  385. n.type = Notification::Type (paramControls.categoryComboBox .getSelectedItemIndex());
  386. n.priority = Notification::Priority (paramControls.priorityComboBox .getSelectedItemIndex() - 2);
  387. n.lockScreenAppearance = Notification::LockScreenAppearance (paramControls.lockScreenVisibilityComboBox.getSelectedItemIndex() - 1);
  388. n.groupId = paramControls.groupIdEditor.getText();
  389. n.groupSortKey = paramControls.sortKeyEditor.getText();
  390. n.groupSummary = paramControls.groupSummaryButton.getToggleState();
  391. n.groupAlertBehaviour = Notification::GroupAlertBehaviour (paramControls.groupAlertBehaviourComboBox.getSelectedItemIndex());
  392. }
  393. void fillOptionalParamsThree (PushNotifications::Notification& n)
  394. {
  395. n.accentColour = paramControls.accentColourButton.findColour (TextButton::buttonColourId, false);
  396. n.ledColour = paramControls.ledColourButton .findColour (TextButton::buttonColourId, false);
  397. using Notification = PushNotifications::Notification;
  398. Notification::LedBlinkPattern ledBlinkPattern;
  399. ledBlinkPattern.msToBeOn = paramControls.ledMsToBeOnComboBox .getSelectedItemIndex() * 200;
  400. ledBlinkPattern.msToBeOff = paramControls.ledMsToBeOffComboBox.getSelectedItemIndex() * 200;
  401. n.ledBlinkPattern = ledBlinkPattern;
  402. Array<int> vibrationPattern;
  403. if (paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() > 0 &&
  404. paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() > 0)
  405. {
  406. vibrationPattern.add (paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
  407. vibrationPattern.add (paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
  408. vibrationPattern.add (2 * paramControls.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
  409. vibrationPattern.add (2 * paramControls.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
  410. }
  411. n.vibrationPattern = vibrationPattern;
  412. n.localOnly = paramControls.localOnlyButton.getToggleState();
  413. n.ongoing = paramControls.ongoingButton.getToggleState();
  414. n.timestampVisibility = Notification::TimestampVisibility (paramControls.timestampVisibilityComboBox.getSelectedItemIndex());
  415. if (paramControls.timeoutAfterComboBox.getSelectedItemIndex() > 0)
  416. {
  417. auto index = paramControls.timeoutAfterComboBox.getSelectedItemIndex();
  418. n.timeoutAfterMs = index * 1000 + 4000;
  419. }
  420. }
  421. void setupAccentColour()
  422. {
  423. auto accentColourSelector = std::make_unique<ColourSelector>();
  424. accentColourSelector->setName ("accent colour");
  425. accentColourSelector->setCurrentColour (paramControls.accentColourButton.findColour (TextButton::buttonColourId));
  426. accentColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  427. accentColourSelector->setSize (200, 200);
  428. accentColourSelector->addComponentListener (this);
  429. accentColourSelector->addChangeListener (this);
  430. paramControls.accentColourSelector = accentColourSelector.get();
  431. CallOutBox::launchAsynchronously (std::move (accentColourSelector), paramControls.accentColourButton.getScreenBounds(), nullptr);
  432. }
  433. void setupLedColour()
  434. {
  435. auto ledColourSelector = std::make_unique<ColourSelector>();
  436. ledColourSelector->setName ("led colour");
  437. ledColourSelector->setCurrentColour (paramControls.ledColourButton.findColour (TextButton::buttonColourId));
  438. ledColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  439. ledColourSelector->setSize (200, 200);
  440. ledColourSelector->addComponentListener (this);
  441. ledColourSelector->addChangeListener (this);
  442. paramControls.ledColourSelector = ledColourSelector.get();
  443. CallOutBox::launchAsynchronously (std::move (ledColourSelector), paramControls.accentColourButton.getScreenBounds(), nullptr);
  444. }
  445. void changeListenerCallback (ChangeBroadcaster* source) override
  446. {
  447. if (source == paramControls.accentColourSelector)
  448. {
  449. auto c = paramControls.accentColourSelector->getCurrentColour();
  450. paramControls.accentColourButton.setColour (TextButton::buttonColourId, c);
  451. }
  452. else if (source == paramControls.ledColourSelector)
  453. {
  454. auto c = paramControls.ledColourSelector->getCurrentColour();
  455. paramControls.ledColourButton.setColour (TextButton::buttonColourId, c);
  456. }
  457. }
  458. void componentBeingDeleted (Component& component) override
  459. {
  460. if (&component == paramControls.accentColourSelector)
  461. paramControls.accentColourSelector = nullptr;
  462. else if (&component == paramControls.ledColourSelector)
  463. paramControls.ledColourSelector = nullptr;
  464. }
  465. void handleNotification (bool isLocalNotification, const PushNotifications::Notification& n) override
  466. {
  467. ignoreUnused (isLocalNotification);
  468. NativeMessageBox::showAsync (MessageBoxOptions()
  469. .withIconType (MessageBoxIconType::InfoIcon)
  470. .withTitle ("Received notification")
  471. .withMessage ("ID: " + n.identifier
  472. + ", title: " + n.title
  473. + ", body: " + n.body)
  474. .withButton ("OK"),
  475. nullptr);
  476. }
  477. void handleNotificationAction (bool isLocalNotification,
  478. const PushNotifications::Notification& n,
  479. const juce::String& actionIdentifier,
  480. const juce::String& optionalResponse) override
  481. {
  482. ignoreUnused (isLocalNotification);
  483. NativeMessageBox::showAsync (MessageBoxOptions()
  484. .withIconType (MessageBoxIconType::InfoIcon)
  485. .withTitle ("Received notification action")
  486. .withMessage ("ID: " + n.identifier
  487. + ", title: " + n.title
  488. + ", body: " + n.body
  489. + ", action: " + actionIdentifier
  490. + ", optionalResponse: " + optionalResponse)
  491. .withButton ("OK"),
  492. nullptr);
  493. PushNotifications::getInstance()->removeDeliveredNotification (n.identifier);
  494. }
  495. void localNotificationDismissedByUser (const PushNotifications::Notification& n) override
  496. {
  497. NativeMessageBox::showAsync (MessageBoxOptions()
  498. .withIconType (MessageBoxIconType::InfoIcon)
  499. .withTitle ("Notification dismissed by a user")
  500. .withMessage ("ID: " + n.identifier
  501. + ", title: " + n.title
  502. + ", body: " + n.body)
  503. .withButton ("OK"),
  504. nullptr);
  505. }
  506. void deliveredNotificationsListReceived (const Array<PushNotifications::Notification>& notifs) override
  507. {
  508. String text = "Received notifications: ";
  509. for (auto& n : notifs)
  510. text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
  511. NativeMessageBox::showAsync (MessageBoxOptions()
  512. .withIconType (MessageBoxIconType::InfoIcon)
  513. .withTitle ("Received notification list")
  514. .withMessage (text)
  515. .withButton ("OK"),
  516. nullptr);
  517. }
  518. void pendingLocalNotificationsListReceived (const Array<PushNotifications::Notification>& notifs) override
  519. {
  520. String text = "Pending notifications: ";
  521. for (auto& n : notifs)
  522. text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
  523. NativeMessageBox::showAsync (MessageBoxOptions()
  524. .withIconType (MessageBoxIconType::InfoIcon)
  525. .withTitle ("Pending notification list")
  526. .withMessage (text)
  527. .withButton ("OK"),
  528. nullptr);
  529. }
  530. void deviceTokenRefreshed (const String& token) override
  531. {
  532. NativeMessageBox::showAsync (MessageBoxOptions()
  533. .withIconType (MessageBoxIconType::InfoIcon)
  534. .withTitle ("Device token refreshed")
  535. .withMessage (token)
  536. .withButton ("OK"),
  537. nullptr);
  538. }
  539. #if JUCE_ANDROID
  540. void remoteNotificationsDeleted() override
  541. {
  542. NativeMessageBox::showAsync (MessageBoxOptions()
  543. .withIconType (MessageBoxIconType::InfoIcon)
  544. .withTitle ("Remote notifications deleted")
  545. .withMessage ("Some of the pending messages were removed!")
  546. .withButton ("OK"),
  547. nullptr);
  548. }
  549. void upstreamMessageSent (const String& messageId) override
  550. {
  551. NativeMessageBox::showAsync (MessageBoxOptions()
  552. .withIconType (MessageBoxIconType::InfoIcon)
  553. .withTitle ("Upstream message sent")
  554. .withMessage ("Message id: " + messageId)
  555. .withButton ("OK"),
  556. nullptr);
  557. }
  558. void upstreamMessageSendingError (const String& messageId, const String& error) override
  559. {
  560. NativeMessageBox::showAsync (MessageBoxOptions()
  561. .withIconType (MessageBoxIconType::InfoIcon)
  562. .withTitle ("Upstream message sending error")
  563. .withMessage ("Message id: " + messageId
  564. + "\nerror: " + error)
  565. .withButton ("OK"),
  566. nullptr);
  567. }
  568. static Array<PushNotifications::Channel> getAndroidChannels()
  569. {
  570. using Channel = PushNotifications::Channel;
  571. Channel ch1, ch2, ch3;
  572. ch1.identifier = "1";
  573. ch1.name = "HighImportance";
  574. ch1.importance = PushNotifications::Channel::max;
  575. ch1.lockScreenAppearance = PushNotifications::Notification::showCompletely;
  576. ch1.description = "High Priority Channel for important stuff";
  577. ch1.groupId = "demoGroup";
  578. ch1.ledColour = Colours::red;
  579. ch1.bypassDoNotDisturb = true;
  580. ch1.canShowBadge = true;
  581. ch1.enableLights = true;
  582. ch1.enableVibration = true;
  583. ch1.soundToPlay = URL ("demonstrative");
  584. ch1.vibrationPattern = { 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
  585. ch2.identifier = "2";
  586. ch2.name = "MediumImportance";
  587. ch2.importance = PushNotifications::Channel::normal;
  588. ch2.lockScreenAppearance = PushNotifications::Notification::showPartially;
  589. ch2.description = "Medium Priority Channel for standard stuff";
  590. ch2.groupId = "demoGroup";
  591. ch2.ledColour = Colours::yellow;
  592. ch2.canShowBadge = true;
  593. ch2.enableLights = true;
  594. ch2.enableVibration = true;
  595. ch2.soundToPlay = URL ("default_os_sound");
  596. ch2.vibrationPattern = { 1000, 1000 };
  597. ch3.identifier = "3";
  598. ch3.name = "LowImportance";
  599. ch3.importance = PushNotifications::Channel::min;
  600. ch3.lockScreenAppearance = PushNotifications::Notification::dontShow;
  601. ch3.description = "Low Priority Channel for silly stuff";
  602. ch3.groupId = "demoGroup";
  603. return { ch1, ch2, ch3 };
  604. }
  605. #elif JUCE_IOS || JUCE_MAC
  606. static PushNotifications::Settings getNotificationSettings()
  607. {
  608. PushNotifications::Settings settings;
  609. settings.allowAlert = true;
  610. settings.allowBadge = true;
  611. settings.allowSound = true;
  612. #if JUCE_IOS
  613. using Action = PushNotifications::Settings::Action;
  614. using Category = PushNotifications::Settings::Category;
  615. Action okAction;
  616. okAction.identifier = "okAction";
  617. okAction.title = "OK!";
  618. okAction.style = Action::button;
  619. okAction.triggerInBackground = true;
  620. Action cancelAction;
  621. cancelAction.identifier = "cancelAction";
  622. cancelAction.title = "Cancel";
  623. cancelAction.style = Action::button;
  624. cancelAction.triggerInBackground = true;
  625. cancelAction.destructive = true;
  626. Action textAction;
  627. textAction.identifier = "textAction";
  628. textAction.title = "Enter text";
  629. textAction.style = Action::text;
  630. textAction.triggerInBackground = true;
  631. textAction.destructive = false;
  632. textAction.textInputButtonText = "Ok";
  633. textAction.textInputPlaceholder = "Enter text...";
  634. Category okCategory;
  635. okCategory.identifier = "okCategory";
  636. okCategory.actions = { okAction };
  637. Category okCancelCategory;
  638. okCancelCategory.identifier = "okCancelCategory";
  639. okCancelCategory.actions = { okAction, cancelAction };
  640. Category textCategory;
  641. textCategory.identifier = "textCategory";
  642. textCategory.actions = { textAction };
  643. textCategory.sendDismissAction = true;
  644. settings.categories = { okCategory, okCancelCategory, textCategory };
  645. #endif
  646. return settings;
  647. }
  648. #endif
  649. struct RowComponent : public Component
  650. {
  651. RowComponent (Label& l, Component& c, int u = 1)
  652. : label (l),
  653. editor (c),
  654. rowUnits (u)
  655. {
  656. addAndMakeVisible (label);
  657. addAndMakeVisible (editor);
  658. }
  659. void resized() override
  660. {
  661. auto bounds = getLocalBounds();
  662. label .setBounds (bounds.removeFromLeft (getWidth() / 3));
  663. editor.setBounds (bounds);
  664. }
  665. Label& label;
  666. Component& editor;
  667. int rowUnits;
  668. };
  669. struct ParamControls
  670. {
  671. Label identifierLabel { "identifierLabel", "Identifier" };
  672. TextEditor identifierEditor;
  673. Label titleLabel { "titleLabel", "Title" };
  674. TextEditor titleEditor;
  675. Label bodyLabel { "bodyLabel", "Body" };
  676. TextEditor bodyEditor;
  677. Label categoryLabel { "categoryLabel", "Category" };
  678. ComboBox categoryComboBox;
  679. Label channelIdLabel { "channelIdLabel", "Channel ID" };
  680. ComboBox channelIdComboBox;
  681. Label iconLabel { "iconLabel", "Icon" };
  682. ComboBox iconComboBox;
  683. Label subtitleLabel { "subtitleLabel", "Subtitle" };
  684. TextEditor subtitleEditor;
  685. Label badgeNumberLabel { "badgeNumberLabel", "BadgeNumber" };
  686. ComboBox badgeNumberComboBox;
  687. Label soundToPlayLabel { "soundToPlayLabel", "SoundToPlay" };
  688. ComboBox soundToPlayComboBox;
  689. Label propertiesLabel { "propertiesLabel", "Properties" };
  690. TextEditor propertiesEditor;
  691. Label fireInLabel { "fireInLabel", "Fire in" };
  692. ComboBox fireInComboBox;
  693. Label repeatLabel { "repeatLabel", "Repeat" };
  694. ToggleButton repeatButton;
  695. Label largeIconLabel { "largeIconLabel", "Large Icon" };
  696. ComboBox largeIconComboBox;
  697. Label badgeIconLabel { "badgeIconLabel", "Badge Icon" };
  698. ComboBox badgeIconComboBox;
  699. Label tickerTextLabel { "tickerTextLabel", "Ticker Text" };
  700. TextEditor tickerTextEditor;
  701. Label autoCancelLabel { "autoCancelLabel", "AutoCancel" };
  702. ToggleButton autoCancelButton;
  703. Label alertOnlyOnceLabel { "alertOnlyOnceLabel", "AlertOnlyOnce" };
  704. ToggleButton alertOnlyOnceButton;
  705. Label actionsLabel { "actionsLabel", "Actions" };
  706. ComboBox actionsComboBox;
  707. Label progressMaxLabel { "progressMaxLabel", "ProgressMax" };
  708. ComboBox progressMaxComboBox;
  709. Label progressCurrentLabel { "progressCurrentLabel", "ProgressCurrent" };
  710. ComboBox progressCurrentComboBox;
  711. Label progressIndeterminateLabel { "progressIndeterminateLabel", "ProgressIndeterminate" };
  712. ToggleButton progressIndeterminateButton;
  713. Label notifCategoryLabel { "notifCategoryLabel", "Category" };
  714. ComboBox notifCategoryComboBox;
  715. Label priorityLabel { "priorityLabel", "Priority" };
  716. ComboBox priorityComboBox;
  717. Label personLabel { "personLabel", "Person" };
  718. TextEditor personEditor;
  719. Label lockScreenVisibilityLabel { "lockScreenVisibilityLabel", "LockScreenVisibility" };
  720. ComboBox lockScreenVisibilityComboBox;
  721. Label groupIdLabel { "groupIdLabel", "GroupID" };
  722. TextEditor groupIdEditor;
  723. Label sortKeyLabel { "sortKeyLabel", "SortKey" };
  724. TextEditor sortKeyEditor;
  725. Label groupSummaryLabel { "groupSummaryLabel", "GroupSummary" };
  726. ToggleButton groupSummaryButton;
  727. Label groupAlertBehaviourLabel { "groupAlertBehaviourLabel", "GroupAlertBehaviour" };
  728. ComboBox groupAlertBehaviourComboBox;
  729. Label accentColourLabel { "accentColourLabel", "AccentColour" };
  730. TextButton accentColourButton;
  731. Label ledColourLabel { "ledColourLabel", "LedColour" };
  732. TextButton ledColourButton;
  733. Label ledMsToBeOnLabel { "ledMsToBeOnLabel", "LedMsToBeOn" };
  734. ComboBox ledMsToBeOnComboBox;
  735. Label ledMsToBeOffLabel { "ledMsToBeOffLabel", "LedMsToBeOff" };
  736. ComboBox ledMsToBeOffComboBox;
  737. Label vibratorMsToBeOnLabel { "vibratorMsToBeOnLabel", "VibrationMsToBeOn" };
  738. ComboBox vibratorMsToBeOnComboBox;
  739. Label vibratorMsToBeOffLabel { "vibratorMsToBeOffLabel", "VibrationMsToBeOff" };
  740. ComboBox vibratorMsToBeOffComboBox;
  741. Label localOnlyLabel { "localOnlyLabel", "LocalOnly" };
  742. ToggleButton localOnlyButton;
  743. Label ongoingLabel { "ongoingLabel", "Ongoing" };
  744. ToggleButton ongoingButton;
  745. Label timestampVisibilityLabel { "timestampVisibilityLabel", "TimestampMode" };
  746. ComboBox timestampVisibilityComboBox;
  747. Label timeoutAfterLabel { "timeoutAfterLabel", "Timeout After Ms" };
  748. ComboBox timeoutAfterComboBox;
  749. ColourSelector* accentColourSelector = nullptr;
  750. ColourSelector* ledColourSelector = nullptr;
  751. };
  752. void setupControls()
  753. {
  754. auto& pc = paramControls;
  755. StringArray categories { "okCategory", "okCancelCategory", "textCategory" };
  756. for (auto& c : categories)
  757. pc.categoryComboBox.addItem (c, pc.categoryComboBox.getNumItems() + 1);
  758. pc.categoryComboBox.setSelectedItemIndex (0);
  759. for (auto i = 1; i <= 3; ++i)
  760. pc.channelIdComboBox.addItem (String (i), i);
  761. pc.channelIdComboBox.setSelectedItemIndex (0);
  762. for (auto i = 0; i < 5; ++i)
  763. pc.iconComboBox.addItem ("icon" + String (i + 1), i + 1);
  764. pc.iconComboBox.setSelectedItemIndex (0);
  765. #if JUCE_MAC
  766. pc.iconComboBox.addItem ("none", 100);
  767. #endif
  768. pc.fireInComboBox.addItem ("Now", 1);
  769. for (auto i = 1; i < 11; ++i)
  770. pc.fireInComboBox.addItem (String (10 * i) + "seconds", i + 1);
  771. pc.fireInComboBox.setSelectedItemIndex (0);
  772. pc.largeIconComboBox.addItem ("none", 1);
  773. for (auto i = 1; i < 5; ++i)
  774. pc.largeIconComboBox.addItem ("icon" + String (i), i + 1);
  775. pc.largeIconComboBox.setSelectedItemIndex (0);
  776. pc.badgeIconComboBox.addItem ("none", 1);
  777. pc.badgeIconComboBox.addItem ("small", 2);
  778. pc.badgeIconComboBox.addItem ("large", 3);
  779. pc.badgeIconComboBox.setSelectedItemIndex (2);
  780. pc.actionsComboBox.addItem ("none", 1);
  781. pc.actionsComboBox.addItem ("ok-cancel", 2);
  782. pc.actionsComboBox.addItem ("text-input", 3);
  783. #if JUCE_ANDROID
  784. pc.actionsComboBox.addItem ("ok-cancel-icons", 4);
  785. pc.actionsComboBox.addItem ("text-input-limited_responses", 5);
  786. #endif
  787. pc.actionsComboBox.setSelectedItemIndex (0);
  788. for (auto i = 0; i < 7; ++i)
  789. pc.badgeNumberComboBox.addItem (String (i), i + 1);
  790. pc.badgeNumberComboBox.setSelectedItemIndex (0);
  791. #if JUCE_IOS
  792. String prefix = "Notifications/sounds/";
  793. String extension = ".caf";
  794. #else
  795. String prefix;
  796. String extension;
  797. #endif
  798. pc.soundToPlayComboBox.addItem ("none", 1);
  799. pc.soundToPlayComboBox.addItem ("default_os_sound", 2);
  800. pc.soundToPlayComboBox.addItem (prefix + "demonstrative" + extension, 3);
  801. pc.soundToPlayComboBox.addItem (prefix + "isntit" + extension, 4);
  802. pc.soundToPlayComboBox.addItem (prefix + "jinglebellssms" + extension, 5);
  803. pc.soundToPlayComboBox.addItem (prefix + "served" + extension, 6);
  804. pc.soundToPlayComboBox.addItem (prefix + "solemn" + extension, 7);
  805. pc.soundToPlayComboBox.setSelectedItemIndex (1);
  806. for (auto i = 0; i < 11; ++i)
  807. {
  808. pc.progressMaxComboBox .addItem (String (i * 10) + "%", i + 1);
  809. pc.progressCurrentComboBox.addItem (String (i * 10) + "%", i + 1);
  810. }
  811. pc.progressMaxComboBox .setSelectedItemIndex (0);
  812. pc.progressCurrentComboBox.setSelectedItemIndex (0);
  813. pc.notifCategoryComboBox.addItem ("unspecified", 1);
  814. pc.notifCategoryComboBox.addItem ("alarm", 2);
  815. pc.notifCategoryComboBox.addItem ("call", 3);
  816. pc.notifCategoryComboBox.addItem ("email", 4);
  817. pc.notifCategoryComboBox.addItem ("error", 5);
  818. pc.notifCategoryComboBox.addItem ("event", 6);
  819. pc.notifCategoryComboBox.addItem ("message", 7);
  820. pc.notifCategoryComboBox.addItem ("progress", 8);
  821. pc.notifCategoryComboBox.addItem ("promo", 9);
  822. pc.notifCategoryComboBox.addItem ("recommendation", 10);
  823. pc.notifCategoryComboBox.addItem ("reminder", 11);
  824. pc.notifCategoryComboBox.addItem ("service", 12);
  825. pc.notifCategoryComboBox.addItem ("social", 13);
  826. pc.notifCategoryComboBox.addItem ("status", 14);
  827. pc.notifCategoryComboBox.addItem ("system", 15);
  828. pc.notifCategoryComboBox.addItem ("transport", 16);
  829. pc.notifCategoryComboBox.setSelectedItemIndex (0);
  830. for (auto i = -2; i < 3; ++i)
  831. pc.priorityComboBox.addItem (String (i), i + 3);
  832. pc.priorityComboBox.setSelectedItemIndex (2);
  833. pc.lockScreenVisibilityComboBox.addItem ("don't show", 1);
  834. pc.lockScreenVisibilityComboBox.addItem ("show partially", 2);
  835. pc.lockScreenVisibilityComboBox.addItem ("show completely", 3);
  836. pc.lockScreenVisibilityComboBox.setSelectedItemIndex (1);
  837. pc.groupAlertBehaviourComboBox.addItem ("alert all", 1);
  838. pc.groupAlertBehaviourComboBox.addItem ("alert summary", 2);
  839. pc.groupAlertBehaviourComboBox.addItem ("alert children", 3);
  840. pc.groupAlertBehaviourComboBox.setSelectedItemIndex (0);
  841. pc.timeoutAfterComboBox.addItem ("No timeout", 1);
  842. for (auto i = 0; i < 10; ++i)
  843. {
  844. pc.ledMsToBeOnComboBox .addItem (String (i * 200) + "ms", i + 1);
  845. pc.ledMsToBeOffComboBox .addItem (String (i * 200) + "ms", i + 1);
  846. pc.vibratorMsToBeOnComboBox .addItem (String (i * 500) + "ms", i + 1);
  847. pc.vibratorMsToBeOffComboBox.addItem (String (i * 500) + "ms", i + 1);
  848. pc.timeoutAfterComboBox .addItem (String (5000 + 1000 * i) + "ms", i + 2);
  849. }
  850. pc.ledMsToBeOnComboBox .setSelectedItemIndex (5);
  851. pc.ledMsToBeOffComboBox .setSelectedItemIndex (5);
  852. pc.vibratorMsToBeOnComboBox .setSelectedItemIndex (0);
  853. pc.vibratorMsToBeOffComboBox.setSelectedItemIndex (0);
  854. pc.timeoutAfterComboBox .setSelectedItemIndex (0);
  855. pc.timestampVisibilityComboBox.addItem ("off", 1);
  856. pc.timestampVisibilityComboBox.addItem ("on", 2);
  857. pc.timestampVisibilityComboBox.addItem ("chronometer", 3);
  858. pc.timestampVisibilityComboBox.addItem ("count down", 4);
  859. pc.timestampVisibilityComboBox.setSelectedItemIndex (1);
  860. }
  861. void distributeControls()
  862. {
  863. auto& pc = paramControls;
  864. paramsOneView .addRowComponent (new RowComponent (pc.identifierLabel, pc.identifierEditor));
  865. paramsOneView .addRowComponent (new RowComponent (pc.titleLabel, pc.titleEditor));
  866. paramsOneView .addRowComponent (new RowComponent (pc.bodyLabel, pc.bodyEditor, 4));
  867. #if JUCE_IOS
  868. paramsOneView .addRowComponent (new RowComponent (pc.categoryLabel, pc.categoryComboBox));
  869. #elif JUCE_ANDROID
  870. paramsOneView .addRowComponent (new RowComponent (pc.channelIdLabel, pc.channelIdComboBox));
  871. #endif
  872. #if JUCE_ANDROID || JUCE_MAC
  873. paramsOneView .addRowComponent (new RowComponent (pc.iconLabel, pc.iconComboBox));
  874. #endif
  875. paramsTwoView .addRowComponent (new RowComponent (pc.subtitleLabel, pc.subtitleEditor));
  876. #if ! JUCE_MAC
  877. paramsTwoView .addRowComponent (new RowComponent (pc.badgeNumberLabel, pc.badgeNumberComboBox));
  878. #endif
  879. paramsTwoView .addRowComponent (new RowComponent (pc.soundToPlayLabel, pc.soundToPlayComboBox));
  880. paramsTwoView .addRowComponent (new RowComponent (pc.propertiesLabel, pc.propertiesEditor, 3));
  881. #if JUCE_IOS || JUCE_MAC
  882. paramsTwoView .addRowComponent (new RowComponent (pc.fireInLabel, pc.fireInComboBox));
  883. paramsTwoView .addRowComponent (new RowComponent (pc.repeatLabel, pc.repeatButton));
  884. #elif JUCE_ANDROID
  885. paramsTwoView .addRowComponent (new RowComponent (pc.largeIconLabel, pc.largeIconComboBox));
  886. paramsTwoView .addRowComponent (new RowComponent (pc.badgeIconLabel, pc.badgeIconComboBox));
  887. paramsTwoView .addRowComponent (new RowComponent (pc.tickerTextLabel, pc.tickerTextEditor));
  888. paramsTwoView .addRowComponent (new RowComponent (pc.autoCancelLabel, pc.autoCancelButton));
  889. paramsTwoView .addRowComponent (new RowComponent (pc.alertOnlyOnceLabel, pc.alertOnlyOnceButton));
  890. #endif
  891. #if JUCE_ANDROID || JUCE_MAC
  892. paramsTwoView .addRowComponent (new RowComponent (pc.actionsLabel, pc.actionsComboBox));
  893. #endif
  894. #if JUCE_ANDROID
  895. paramsThreeView.addRowComponent (new RowComponent (pc.progressMaxLabel, pc.progressMaxComboBox));
  896. paramsThreeView.addRowComponent (new RowComponent (pc.progressCurrentLabel, pc.progressCurrentComboBox));
  897. paramsThreeView.addRowComponent (new RowComponent (pc.progressIndeterminateLabel, pc.progressIndeterminateButton));
  898. paramsThreeView.addRowComponent (new RowComponent (pc.categoryLabel, pc.categoryComboBox));
  899. paramsThreeView.addRowComponent (new RowComponent (pc.priorityLabel, pc.priorityComboBox));
  900. paramsThreeView.addRowComponent (new RowComponent (pc.personLabel, pc.personEditor));
  901. paramsThreeView.addRowComponent (new RowComponent (pc.lockScreenVisibilityLabel, pc.lockScreenVisibilityComboBox));
  902. paramsThreeView.addRowComponent (new RowComponent (pc.groupIdLabel, pc.groupIdEditor));
  903. paramsThreeView.addRowComponent (new RowComponent (pc.sortKeyLabel, pc.sortKeyEditor));
  904. paramsThreeView.addRowComponent (new RowComponent (pc.groupSummaryLabel, pc.groupSummaryButton));
  905. paramsThreeView.addRowComponent (new RowComponent (pc.groupAlertBehaviourLabel, pc.groupAlertBehaviourComboBox));
  906. paramsFourView .addRowComponent (new RowComponent (pc.accentColourLabel, pc.accentColourButton));
  907. paramsFourView .addRowComponent (new RowComponent (pc.ledColourLabel, pc.ledColourButton));
  908. paramsFourView .addRowComponent (new RowComponent (pc.ledMsToBeOffLabel, pc.ledMsToBeOffComboBox));
  909. paramsFourView .addRowComponent (new RowComponent (pc.ledMsToBeOnLabel, pc.ledMsToBeOnComboBox));
  910. paramsFourView .addRowComponent (new RowComponent (pc.vibratorMsToBeOffLabel, pc.vibratorMsToBeOffComboBox));
  911. paramsFourView .addRowComponent (new RowComponent (pc.vibratorMsToBeOnLabel, pc.vibratorMsToBeOnComboBox));
  912. paramsFourView .addRowComponent (new RowComponent (pc.localOnlyLabel, pc.localOnlyButton));
  913. paramsFourView .addRowComponent (new RowComponent (pc.ongoingLabel, pc.ongoingButton));
  914. paramsFourView .addRowComponent (new RowComponent (pc.timestampVisibilityLabel, pc.timestampVisibilityComboBox));
  915. paramsFourView .addRowComponent (new RowComponent (pc.timeoutAfterLabel, pc.timeoutAfterComboBox));
  916. #endif
  917. }
  918. struct ParamsView : public Component
  919. {
  920. ParamsView()
  921. {
  922. // For now, to be able to dismiss mobile keyboard.
  923. setWantsKeyboardFocus (true);
  924. }
  925. void addRowComponent (RowComponent* rc)
  926. {
  927. rowComponents.add (rc);
  928. addAndMakeVisible (rc);
  929. }
  930. void resized() override
  931. {
  932. auto totalRowUnits = 0;
  933. for (auto* rc : rowComponents)
  934. totalRowUnits += rc->rowUnits;
  935. auto rowHeight = getHeight() / totalRowUnits;
  936. auto bounds = getLocalBounds();
  937. for (auto* rc : rowComponents)
  938. rc->setBounds (bounds.removeFromTop (rc->rowUnits * rowHeight));
  939. auto* last = rowComponents[rowComponents.size() - 1];
  940. last->setBounds (last->getBounds().withHeight (getHeight() - last->getY()));
  941. }
  942. private:
  943. OwnedArray<RowComponent> rowComponents;
  944. };
  945. struct AuxActionsView : public Component
  946. {
  947. AuxActionsView()
  948. {
  949. addAndMakeVisible (getDeliveredNotificationsButton);
  950. addAndMakeVisible (removeDeliveredNotifWithIdButton);
  951. addAndMakeVisible (deliveredNotifIdentifier);
  952. addAndMakeVisible (removeAllDeliveredNotifsButton);
  953. #if JUCE_IOS || JUCE_MAC
  954. addAndMakeVisible (getPendingNotificationsButton);
  955. addAndMakeVisible (removePendingNotifWithIdButton);
  956. addAndMakeVisible (pendingNotifIdentifier);
  957. addAndMakeVisible (removeAllPendingNotifsButton);
  958. #endif
  959. // For now, to be able to dismiss mobile keyboard.
  960. setWantsKeyboardFocus (true);
  961. }
  962. void resized() override
  963. {
  964. auto columnWidth = getWidth();
  965. auto rowHeight = getHeight() / 6;
  966. auto bounds = getLocalBounds();
  967. getDeliveredNotificationsButton .setBounds (bounds.removeFromTop (rowHeight));
  968. auto rowBounds = bounds.removeFromTop (rowHeight);
  969. removeDeliveredNotifWithIdButton.setBounds (rowBounds.removeFromLeft (columnWidth / 2));
  970. deliveredNotifIdentifier .setBounds (rowBounds);
  971. removeAllDeliveredNotifsButton .setBounds (bounds.removeFromTop (rowHeight));
  972. #if JUCE_IOS || JUCE_MAC
  973. getPendingNotificationsButton .setBounds (bounds.removeFromTop (rowHeight));
  974. rowBounds = bounds.removeFromTop (rowHeight);
  975. removePendingNotifWithIdButton.setBounds (rowBounds.removeFromLeft (columnWidth / 2));
  976. pendingNotifIdentifier .setBounds (rowBounds);
  977. removeAllPendingNotifsButton .setBounds (bounds.removeFromTop (rowHeight));
  978. #endif
  979. }
  980. TextButton getDeliveredNotificationsButton { "Get Delivered Notifications" };
  981. TextButton removeDeliveredNotifWithIdButton { "Remove Delivered Notif With ID:" };
  982. TextEditor deliveredNotifIdentifier;
  983. TextButton removeAllDeliveredNotifsButton { "Remove All Delivered Notifs" };
  984. TextButton getPendingNotificationsButton { "Get Pending Notifications" };
  985. TextButton removePendingNotifWithIdButton { "Remove Pending Notif With ID:" };
  986. TextEditor pendingNotifIdentifier;
  987. TextButton removeAllPendingNotifsButton { "Remove All Pending Notifs" };
  988. };
  989. struct RemoteView : public Component
  990. {
  991. RemoteView()
  992. {
  993. addAndMakeVisible (getDeviceTokenButton);
  994. #if JUCE_ANDROID
  995. addAndMakeVisible (sendRemoteMessageButton);
  996. addAndMakeVisible (subscribeToSportsButton);
  997. addAndMakeVisible (unsubscribeFromSportsButton);
  998. #endif
  999. }
  1000. void resized()
  1001. {
  1002. auto rowSize = getHeight () / 10;
  1003. auto bounds = getLocalBounds().reduced (getWidth() / 10, getHeight() / 10);
  1004. bounds.removeFromTop (2 * rowSize);
  1005. getDeviceTokenButton .setBounds (bounds.removeFromTop (rowSize));
  1006. sendRemoteMessageButton .setBounds (bounds.removeFromTop (rowSize));
  1007. subscribeToSportsButton .setBounds (bounds.removeFromTop (rowSize));
  1008. unsubscribeFromSportsButton.setBounds (bounds.removeFromTop (rowSize));
  1009. }
  1010. TextButton getDeviceTokenButton { "GetDeviceToken" };
  1011. TextButton sendRemoteMessageButton { "SendRemoteMessage" };
  1012. TextButton subscribeToSportsButton { "SubscribeToSports" };
  1013. TextButton unsubscribeFromSportsButton { "UnsubscribeFromSports" };
  1014. };
  1015. struct DemoTabbedComponent : public TabbedComponent
  1016. {
  1017. explicit DemoTabbedComponent (TabbedButtonBar::Orientation orientation)
  1018. : TabbedComponent (orientation)
  1019. {
  1020. }
  1021. void currentTabChanged (int, const String& newCurrentTabName) override
  1022. {
  1023. if (! showedRemoteInstructions && newCurrentTabName == "Remote")
  1024. {
  1025. PushNotificationsDemo::showRemoteInstructions();
  1026. showedRemoteInstructions = true;
  1027. }
  1028. }
  1029. private:
  1030. bool showedRemoteInstructions = false;
  1031. };
  1032. static void showRemoteInstructions()
  1033. {
  1034. #if JUCE_IOS || JUCE_MAC
  1035. NativeMessageBox::showAsync (MessageBoxOptions()
  1036. .withIconType (MessageBoxIconType::InfoIcon)
  1037. .withTitle ("Remote Notifications instructions")
  1038. .withMessage ("In order to be able to test remote notifications "
  1039. "ensure that the app is signed and that you register "
  1040. "the bundle ID for remote notifications in "
  1041. "Apple Developer Center.")
  1042. .withButton ("OK"),
  1043. nullptr);
  1044. #endif
  1045. }
  1046. Label headerLabel { "headerLabel", "Push Notifications Demo" };
  1047. ParamControls paramControls;
  1048. ParamsView paramsOneView, paramsTwoView, paramsThreeView, paramsFourView;
  1049. AuxActionsView auxActionsView;
  1050. TabbedComponent localNotificationsTabs { TabbedButtonBar::TabsAtTop };
  1051. RemoteView remoteView;
  1052. DemoTabbedComponent mainTabs { TabbedButtonBar::TabsAtTop };
  1053. TextButton sendButton { "Send!" };
  1054. Label notAvailableYetLabel { "notAvailableYetLabel",
  1055. "Push Notifications feature is not available on this platform yet!" };
  1056. //==============================================================================
  1057. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PushNotificationsDemo)
  1058. };