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.

1122 lines
52KB

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