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.

1210 lines
55KB

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