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.

629 lines
27KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "MainComponent.h"
  20. //==============================================================================
  21. MainContentComponent::MainContentComponent()
  22. {
  23. #if JUCE_ANDROID || JUCE_IOS
  24. addAndMakeVisible (headerLabel);
  25. addAndMakeVisible (mainTabs);
  26. addAndMakeVisible (sendButton);
  27. #else
  28. addAndMakeVisible (notAvailableYetLabel);
  29. #endif
  30. headerLabel.setJustificationType (Justification::centred);
  31. notAvailableYetLabel.setJustificationType (Justification::centred);
  32. const auto colour = getLookAndFeel().findColour (ResizableWindow::backgroundColourId);
  33. localNotificationsTabs.addTab ("Req. params", colour, &requiredParamsView, false);
  34. localNotificationsTabs.addTab ("Opt. params1", colour, &optionalParamsOneView, false);
  35. #if JUCE_ANDROID
  36. localNotificationsTabs.addTab ("Opt. params2", colour, &optionalParamsTwoView, false);
  37. localNotificationsTabs.addTab ("Opt. params3", colour, &optionalParamsThreeView, false);
  38. #endif
  39. localNotificationsTabs.addTab ("Aux. actions", colour, &auxActionsView, false);
  40. mainTabs.addTab ("Local", colour, &localNotificationsTabs, false);
  41. mainTabs.addTab ("Remote", colour, &remoteView, false);
  42. const auto userArea = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
  43. #if JUCE_ANDROID || JUCE_IOS
  44. setSize (userArea.getWidth(), userArea.getHeight());
  45. #else
  46. setSize (userArea.getWidth() / 2, userArea.getHeight() / 2);
  47. #endif
  48. sendButton.addListener (this);
  49. auxActionsView.getDeliveredNotificationsButton .addListener (this);
  50. auxActionsView.removeDeliveredNotifWithIdButton.addListener (this);
  51. auxActionsView.removeAllDeliveredNotifsButton .addListener (this);
  52. #if JUCE_IOS
  53. auxActionsView.getPendingNotificationsButton .addListener (this);
  54. auxActionsView.removePendingNotifWithIdButton.addListener (this);
  55. auxActionsView.removeAllPendingNotifsButton .addListener (this);
  56. #endif
  57. remoteView.getDeviceTokenButton .addListener (this);
  58. remoteView.sendRemoteMessageButton .addListener (this);
  59. remoteView.subscribeToSportsButton .addListener (this);
  60. remoteView.unsubscribeFromSportsButton.addListener (this);
  61. optionalParamsThreeView.accentColourButton.addListener (this);
  62. optionalParamsThreeView.ledColourButton .addListener (this);
  63. jassert (PushNotifications::getInstance()->areNotificationsEnabled());
  64. PushNotifications::getInstance()->addListener (this);
  65. #if JUCE_IOS
  66. optionalParamsOneView.fireInComboBox.addListener (this);
  67. PushNotifications::getInstance()->requestPermissionsWithSettings (getIosSettings());
  68. #elif JUCE_ANDROID
  69. PushNotifications::ChannelGroup cg { "demoGroup", "demo group" };
  70. PushNotifications::getInstance()->setupChannels ({{ cg }}, getAndroidChannels());
  71. #endif
  72. }
  73. MainContentComponent::~MainContentComponent()
  74. {
  75. PushNotifications::getInstance()->removeListener (this);
  76. }
  77. void MainContentComponent::paint (Graphics& g)
  78. {
  79. g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
  80. }
  81. void MainContentComponent::resized()
  82. {
  83. auto bounds = getLocalBounds().reduced (getWidth() / 20, getHeight() / 40);
  84. headerLabel.setBounds (bounds.removeFromTop (bounds.proportionOfHeight (0.1f)));
  85. mainTabs.setBounds (bounds.removeFromTop (bounds.proportionOfHeight (0.8f)));
  86. sendButton.setBounds (bounds);
  87. notAvailableYetLabel.setBounds (getLocalBounds());
  88. }
  89. void MainContentComponent::buttonClicked (Button* b)
  90. {
  91. if (b == &sendButton)
  92. sendLocalNotification();
  93. else if (b == &optionalParamsThreeView.accentColourButton)
  94. setupAccentColour();
  95. else if (b == &optionalParamsThreeView.ledColourButton)
  96. setupLedColour();
  97. else if (b == &auxActionsView.getDeliveredNotificationsButton)
  98. getDeliveredNotifications();
  99. else if (b == &auxActionsView.removeDeliveredNotifWithIdButton)
  100. PushNotifications::getInstance()->removeDeliveredNotification (auxActionsView.deliveredNotifIdentifier.getText());
  101. else if (b == &auxActionsView.removeAllDeliveredNotifsButton)
  102. PushNotifications::getInstance()->removeAllDeliveredNotifications();
  103. #if JUCE_IOS
  104. else if (b == &auxActionsView.getPendingNotificationsButton)
  105. PushNotifications::getInstance()->getPendingLocalNotifications();
  106. else if (b == &auxActionsView.removePendingNotifWithIdButton)
  107. PushNotifications::getInstance()->removePendingLocalNotification (auxActionsView.pendingNotifIdentifier.getText());
  108. else if (b == &auxActionsView.removeAllPendingNotifsButton)
  109. PushNotifications::getInstance()->removeAllPendingLocalNotifications();
  110. #endif
  111. else if (b == &remoteView.getDeviceTokenButton)
  112. {
  113. String token = PushNotifications::getInstance()->getDeviceToken();
  114. DBG ("token = " + token);
  115. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon, "Device token", token);
  116. }
  117. #if JUCE_ANDROID
  118. else if (b == &remoteView.sendRemoteMessageButton)
  119. {
  120. StringPairArray data;
  121. data.set ("key1", "value1");
  122. data.set ("key2", "value2");
  123. static int id = 100;
  124. PushNotifications::getInstance()->sendUpstreamMessage ("872047750958",
  125. "com.juce.pushnotificationsdemo",
  126. String (id++),
  127. "standardType",
  128. 3600,
  129. data);
  130. }
  131. else if (b == &remoteView.subscribeToSportsButton)
  132. {
  133. PushNotifications::getInstance()->subscribeToTopic ("sports");
  134. }
  135. else if (b == &remoteView.unsubscribeFromSportsButton)
  136. {
  137. PushNotifications::getInstance()->unsubscribeFromTopic ("sports");
  138. }
  139. #endif
  140. }
  141. void MainContentComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  142. {
  143. #if JUCE_IOS
  144. if (comboBoxThatHasChanged == &optionalParamsOneView.fireInComboBox)
  145. {
  146. const bool repeatsAllowed = optionalParamsOneView.fireInComboBox.getSelectedItemIndex() >= 6;
  147. optionalParamsOneView.repeatButton.setEnabled (repeatsAllowed);
  148. if (! repeatsAllowed)
  149. optionalParamsOneView.repeatButton.setToggleState (false, NotificationType::sendNotification);
  150. }
  151. #else
  152. ignoreUnused (comboBoxThatHasChanged);
  153. #endif
  154. }
  155. void MainContentComponent::sendLocalNotification()
  156. {
  157. PushNotifications::Notification n;
  158. fillRequiredParams (n);
  159. fillOptionalParamsOne (n);
  160. #if JUCE_ANDROID
  161. fillOptionalParamsTwo (n);
  162. fillOptionalParamsThree (n);
  163. #endif
  164. if (! n.isValid())
  165. {
  166. #if JUCE_IOS
  167. String requiredFields = "identifier (from iOS 10), title, body and category";
  168. #elif JUCE_ANDROID
  169. String requiredFields = "channel ID (from Android O), title, body and icon";
  170. #else
  171. String requiredFields = "all required fields";
  172. #endif
  173. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  174. "Incorrect notifications setup",
  175. "Please make sure that "
  176. + requiredFields + " are set.");
  177. return;
  178. }
  179. PushNotifications::getInstance()->sendLocalNotification (n);
  180. }
  181. void MainContentComponent::fillRequiredParams (PushNotifications::Notification& n)
  182. {
  183. n.identifier = requiredParamsView.identifierEditor.getText();
  184. n.title = requiredParamsView.titleEditor.getText();
  185. n.body = requiredParamsView.bodyEditor.getText();
  186. #if JUCE_IOS
  187. n.category = requiredParamsView.categories[requiredParamsView.categoryComboBox.getSelectedItemIndex()];
  188. #elif JUCE_ANDROID
  189. if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 0)
  190. n.icon = "ic_stat_name";
  191. else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 1)
  192. n.icon = "ic_stat_name2";
  193. else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 2)
  194. n.icon = "ic_stat_name3";
  195. else if (requiredParamsView.iconComboBox.getSelectedItemIndex() == 3)
  196. n.icon = "ic_stat_name4";
  197. else
  198. n.icon = "ic_stat_name5";
  199. // Note: this is not strictly speaking required param, just doing it here because it is the fastest way!
  200. n.publicVersion = new PushNotifications::Notification();
  201. n.publicVersion->identifier = "blahblahblah";
  202. n.publicVersion->title = "Public title!";
  203. n.publicVersion->body = "Public body!";
  204. n.publicVersion->icon = n.icon;
  205. #if __ANDROID_API__ >= 26
  206. n.channelId = String (requiredParamsView.channelIdComboBox.getSelectedItemIndex() + 1);
  207. #endif
  208. #endif
  209. }
  210. void MainContentComponent::fillOptionalParamsOne (PushNotifications::Notification& n)
  211. {
  212. n.subtitle = optionalParamsOneView.subtitleEditor.getText();
  213. n.badgeNumber = optionalParamsOneView.badgeNumberComboBox.getSelectedItemIndex();
  214. if (optionalParamsOneView.soundToPlayComboBox.getSelectedItemIndex() > 0)
  215. n.soundToPlay = URL (optionalParamsOneView.soundToPlayComboBox.getItemText (optionalParamsOneView.soundToPlayComboBox.getSelectedItemIndex()));
  216. n.properties = JSON::parse (optionalParamsOneView.propertiesEditor.getText());
  217. #if JUCE_IOS
  218. n.triggerIntervalSec = double (optionalParamsOneView.fireInComboBox.getSelectedItemIndex() * 10);
  219. n.repeat = optionalParamsOneView.repeatButton.getToggleState();
  220. #elif JUCE_ANDROID
  221. if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 1)
  222. n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name6_png, BinaryData::ic_stat_name6_pngSize);
  223. else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 2)
  224. n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name7_png, BinaryData::ic_stat_name7_pngSize);
  225. else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 3)
  226. n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name8_png, BinaryData::ic_stat_name8_pngSize);
  227. else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 4)
  228. n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name9_png, BinaryData::ic_stat_name9_pngSize);
  229. else if (optionalParamsOneView.largeIconComboBox.getSelectedItemIndex() == 5)
  230. n.largeIcon = ImageFileFormat::loadFrom (BinaryData::ic_stat_name10_png, BinaryData::ic_stat_name10_pngSize);
  231. n.badgeIconType = (PushNotifications::Notification::BadgeIconType) optionalParamsOneView.badgeIconComboBox.getSelectedItemIndex();
  232. n.tickerText = optionalParamsOneView.tickerTextEditor.getText();
  233. n.shouldAutoCancel = optionalParamsOneView.autoCancelButton.getToggleState();
  234. n.alertOnlyOnce = optionalParamsOneView.alertOnlyOnceButton.getToggleState();
  235. if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 1)
  236. {
  237. PushNotifications::Notification::Action a, a2;
  238. a .style = PushNotifications::Notification::Action::button;
  239. a2.style = PushNotifications::Notification::Action::button;
  240. a .title = "Ok";
  241. a2.title = "Cancel";
  242. n.actions.add (a);
  243. n.actions.add (a2);
  244. }
  245. else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 2)
  246. {
  247. PushNotifications::Notification::Action a, a2;
  248. a .title = "Ok";
  249. a2.title = "Cancel";
  250. a .style = PushNotifications::Notification::Action::button;
  251. a2.style = PushNotifications::Notification::Action::button;
  252. a .icon = "ic_stat_name4";
  253. a2.icon = "ic_stat_name5";
  254. n.actions.add (a);
  255. n.actions.add (a2);
  256. }
  257. else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 3)
  258. {
  259. PushNotifications::Notification::Action a, a2;
  260. a .title = "Input Text Here";
  261. a2.title = "No";
  262. a .style = PushNotifications::Notification::Action::text;
  263. a2.style = PushNotifications::Notification::Action::button;
  264. a .icon = "ic_stat_name4";
  265. a2.icon = "ic_stat_name5";
  266. a.textInputPlaceholder = "placeholder text ...";
  267. n.actions.add (a);
  268. n.actions.add (a2);
  269. }
  270. else if (optionalParamsOneView.actionsComboBox.getSelectedItemIndex() == 4)
  271. {
  272. PushNotifications::Notification::Action a, a2;
  273. a .title = "Input Text Here";
  274. a2.title = "No";
  275. a .style = PushNotifications::Notification::Action::text;
  276. a2.style = PushNotifications::Notification::Action::button;
  277. a .icon = "ic_stat_name4";
  278. a2.icon = "ic_stat_name5";
  279. a.textInputPlaceholder = "placeholder text ...";
  280. a.allowedResponses.add ("Response 1");
  281. a.allowedResponses.add ("Response 2");
  282. a.allowedResponses.add ("Response 3");
  283. n.actions.add (a);
  284. n.actions.add (a2);
  285. }
  286. #endif
  287. }
  288. void MainContentComponent::fillOptionalParamsTwo (PushNotifications::Notification& n)
  289. {
  290. using Notification = PushNotifications::Notification;
  291. Notification::Progress progress;
  292. progress.max = optionalParamsTwoView.progressMaxComboBox.getSelectedItemIndex() * 10;
  293. progress.current = optionalParamsTwoView.progressCurrentComboBox.getSelectedItemIndex() * 10;
  294. progress.indeterminate = optionalParamsTwoView.progressIndeterminateButton.getToggleState();
  295. n.progress = progress;
  296. n.person = optionalParamsTwoView.personEditor.getText();
  297. n.type = Notification::Type (optionalParamsTwoView.categoryComboBox.getSelectedItemIndex());
  298. n.priority = Notification::Priority (optionalParamsTwoView.priorityComboBox.getSelectedItemIndex() - 2);
  299. n.lockScreenAppearance = Notification::LockScreenAppearance (optionalParamsTwoView.lockScreenVisibilityComboBox.getSelectedItemIndex() - 1);
  300. n.groupId = optionalParamsTwoView.groupIdEditor.getText();
  301. n.groupSortKey = optionalParamsTwoView.sortKeyEditor.getText();
  302. n.groupSummary = optionalParamsTwoView.groupSummaryButton.getToggleState();
  303. n.groupAlertBehaviour = Notification::GroupAlertBehaviour (optionalParamsTwoView.groupAlertBehaviourComboBox.getSelectedItemIndex());
  304. }
  305. void MainContentComponent::fillOptionalParamsThree (PushNotifications::Notification& n)
  306. {
  307. n.accentColour = optionalParamsThreeView.accentColourButton.findColour (TextButton::buttonColourId, false);
  308. n.ledColour = optionalParamsThreeView.ledColourButton .findColour (TextButton::buttonColourId, false);
  309. using Notification = PushNotifications::Notification;
  310. Notification::LedBlinkPattern ledBlinkPattern;
  311. ledBlinkPattern.msToBeOn = optionalParamsThreeView.ledMsToBeOnComboBox .getSelectedItemIndex() * 200;
  312. ledBlinkPattern.msToBeOff = optionalParamsThreeView.ledMsToBeOffComboBox.getSelectedItemIndex() * 200;
  313. n.ledBlinkPattern = ledBlinkPattern;
  314. Array<int> vibrationPattern;
  315. if (optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() > 0 &&
  316. optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() > 0)
  317. {
  318. vibrationPattern.add (optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
  319. vibrationPattern.add (optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
  320. vibrationPattern.add (2 * optionalParamsThreeView.vibratorMsToBeOffComboBox.getSelectedItemIndex() * 500);
  321. vibrationPattern.add (2 * optionalParamsThreeView.vibratorMsToBeOnComboBox .getSelectedItemIndex() * 500);
  322. }
  323. n.vibrationPattern = vibrationPattern;
  324. n.localOnly = optionalParamsThreeView.localOnlyButton.getToggleState();
  325. n.ongoing = optionalParamsThreeView.ongoingButton.getToggleState();
  326. n.timestampVisibility = Notification::TimestampVisibility (optionalParamsThreeView.timestampVisibilityComboBox.getSelectedItemIndex());
  327. if (optionalParamsThreeView.timeoutAfterComboBox.getSelectedItemIndex() > 0)
  328. {
  329. auto index = optionalParamsThreeView.timeoutAfterComboBox.getSelectedItemIndex();
  330. n.timeoutAfterMs = index * 1000 + 4000;
  331. }
  332. }
  333. void MainContentComponent::setupAccentColour()
  334. {
  335. optionalParamsThreeView.accentColourSelector = new ColourSelector();
  336. optionalParamsThreeView.accentColourSelector->setName ("accent colour");
  337. optionalParamsThreeView.accentColourSelector->setCurrentColour (optionalParamsThreeView.accentColourButton.findColour (TextButton::buttonColourId));
  338. optionalParamsThreeView.accentColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  339. optionalParamsThreeView.accentColourSelector->setSize (200, 200);
  340. optionalParamsThreeView.accentColourSelector->addComponentListener (this);
  341. optionalParamsThreeView.accentColourSelector->addChangeListener (this);
  342. CallOutBox::launchAsynchronously (optionalParamsThreeView.accentColourSelector, optionalParamsThreeView.accentColourButton.getScreenBounds(), nullptr);
  343. }
  344. void MainContentComponent::setupLedColour()
  345. {
  346. optionalParamsThreeView.ledColourSelector = new ColourSelector();
  347. optionalParamsThreeView.ledColourSelector->setName ("led colour");
  348. optionalParamsThreeView.ledColourSelector->setCurrentColour (optionalParamsThreeView.ledColourButton.findColour (TextButton::buttonColourId));
  349. optionalParamsThreeView.ledColourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  350. optionalParamsThreeView.ledColourSelector->setSize (200, 200);
  351. optionalParamsThreeView.ledColourSelector->addComponentListener (this);
  352. optionalParamsThreeView.ledColourSelector->addChangeListener (this);
  353. CallOutBox::launchAsynchronously (optionalParamsThreeView.ledColourSelector, optionalParamsThreeView.accentColourButton.getScreenBounds(), nullptr);
  354. }
  355. void MainContentComponent::changeListenerCallback (ChangeBroadcaster* source)
  356. {
  357. if (source == optionalParamsThreeView.accentColourSelector)
  358. {
  359. Colour c = optionalParamsThreeView.accentColourSelector->getCurrentColour();
  360. optionalParamsThreeView.accentColourButton.setColour (TextButton::buttonColourId, c);
  361. }
  362. else if (source == optionalParamsThreeView.ledColourSelector)
  363. {
  364. Colour c = optionalParamsThreeView.ledColourSelector->getCurrentColour();
  365. optionalParamsThreeView.ledColourButton.setColour (TextButton::buttonColourId, c);
  366. }
  367. }
  368. void MainContentComponent::componentBeingDeleted (Component& component)
  369. {
  370. if (&component == optionalParamsThreeView.accentColourSelector)
  371. optionalParamsThreeView.accentColourSelector = nullptr;
  372. else if (&component == optionalParamsThreeView.ledColourSelector)
  373. optionalParamsThreeView.ledColourSelector = nullptr;
  374. }
  375. void MainContentComponent::handleNotification (bool isLocalNotification, const PushNotifications::Notification& n)
  376. {
  377. ignoreUnused (isLocalNotification);
  378. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  379. "Received notification",
  380. "ID: " + n.identifier
  381. + ", title: " + n.title
  382. + ", body: " + n.body);
  383. }
  384. void MainContentComponent::handleNotificationAction (bool isLocalNotification,
  385. const PushNotifications::Notification& n,
  386. const String& actionIdentifier,
  387. const String& optionalResponse)
  388. {
  389. ignoreUnused (isLocalNotification);
  390. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  391. "Received notification action",
  392. "ID: " + n.identifier
  393. + ", title: " + n.title
  394. + ", body: " + n.body
  395. + ", action: " + actionIdentifier
  396. + ", optionalResponse: " + optionalResponse);
  397. PushNotifications::getInstance()->removeDeliveredNotification (n.identifier);
  398. }
  399. void MainContentComponent::localNotificationDismissedByUser (const PushNotifications::Notification& n)
  400. {
  401. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  402. "Notification dismissed by a user",
  403. "ID: " + n.identifier
  404. + ", title: " + n.title
  405. + ", body: " + n.body);
  406. }
  407. void MainContentComponent::getDeliveredNotifications()
  408. {
  409. PushNotifications::getInstance()->getDeliveredNotifications();
  410. }
  411. void MainContentComponent::deliveredNotificationsListReceived (const Array<PushNotifications::Notification>& notifs)
  412. {
  413. String text = "Received notifications: ";
  414. for (const auto& n : notifs)
  415. text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
  416. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon, "Received notification list", text);
  417. }
  418. void MainContentComponent::pendingLocalNotificationsListReceived (const Array<PushNotifications::Notification>& notifs)
  419. {
  420. String text = "Pending notifications: ";
  421. for (const auto& n : notifs)
  422. text << "(" << n.identifier << ", " << n.title << ", " << n.body << "), ";
  423. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon, "Pending notification list", text);
  424. }
  425. void MainContentComponent::deviceTokenRefreshed (const String& token)
  426. {
  427. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  428. "Device token refreshed",
  429. token);
  430. }
  431. #if JUCE_ANDROID
  432. void MainContentComponent::remoteNotificationsDeleted()
  433. {
  434. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  435. "Remote notifications deleted",
  436. "Some of the pending messages were removed!");
  437. }
  438. void MainContentComponent::upstreamMessageSent (const String& messageId)
  439. {
  440. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  441. "Upstream message sent",
  442. "Message id: " + messageId);
  443. }
  444. void MainContentComponent::upstreamMessageSendingError (const String& messageId, const String& error)
  445. {
  446. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  447. "Upstream message sending error",
  448. "Message id: " + messageId
  449. + "\nerror: " + error);
  450. }
  451. Array<PushNotifications::Channel> MainContentComponent::getAndroidChannels()
  452. {
  453. using Channel = PushNotifications::Channel;
  454. Channel ch1, ch2, ch3;
  455. ch1.identifier = "1";
  456. ch1.name = "HighImportance";
  457. ch1.importance = PushNotifications::Channel::max;
  458. ch1.lockScreenAppearance = PushNotifications::Notification::showCompletely;
  459. ch1.description = "High Priority Channel for important stuff";
  460. ch1.groupId = "demoGroup";
  461. ch1.ledColour = Colours::red;
  462. ch1.bypassDoNotDisturb = true;
  463. ch1.canShowBadge = true;
  464. ch1.enableLights = true;
  465. ch1.enableVibration = true;
  466. ch1.soundToPlay = URL ("demonstrative");
  467. ch1.vibrationPattern = { 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
  468. ch2.identifier = "2";
  469. ch2.name = "MediumImportance";
  470. ch2.importance = PushNotifications::Channel::normal;
  471. ch2.lockScreenAppearance = PushNotifications::Notification::showPartially;
  472. ch2.description = "Medium Priority Channel for standard stuff";
  473. ch2.groupId = "demoGroup";
  474. ch2.ledColour = Colours::yellow;
  475. ch2.canShowBadge = true;
  476. ch2.enableLights = true;
  477. ch2.enableVibration = true;
  478. ch2.soundToPlay = URL ("default_os_sound");
  479. ch2.vibrationPattern = { 1000, 1000 };
  480. ch3.identifier = "3";
  481. ch3.name = "LowImportance";
  482. ch3.importance = PushNotifications::Channel::min;
  483. ch3.lockScreenAppearance = PushNotifications::Notification::dontShow;
  484. ch3.description = "Low Priority Channel for silly stuff";
  485. ch3.groupId = "demoGroup";
  486. return { ch1, ch2, ch3 };
  487. }
  488. #elif JUCE_IOS
  489. PushNotifications::Settings MainContentComponent::getIosSettings()
  490. {
  491. using Action = PushNotifications::Settings::Action;
  492. using Category = PushNotifications::Settings::Category;
  493. Action okAction;
  494. okAction.identifier = "okAction";
  495. okAction.title = "OK!";
  496. okAction.style = Action::button;
  497. okAction.triggerInBackground = true;
  498. Action cancelAction;
  499. cancelAction.identifier = "cancelAction";
  500. cancelAction.title = "Cancel";
  501. cancelAction.style = Action::button;
  502. cancelAction.triggerInBackground = true;
  503. cancelAction.destructive = true;
  504. Action textAction;
  505. textAction.identifier = "textAction";
  506. textAction.title = "Enter text";
  507. textAction.style = Action::text;
  508. textAction.triggerInBackground = true;
  509. textAction.destructive = false;
  510. textAction.textInputButtonText = "Ok";
  511. textAction.textInputPlaceholder = "Enter text...";
  512. Category okCategory;
  513. okCategory.identifier = "okCategory";
  514. okCategory.actions = { okAction };
  515. Category okCancelCategory;
  516. okCancelCategory.identifier = "okCancelCategory";
  517. okCancelCategory.actions = { okAction, cancelAction };
  518. Category textCategory;
  519. textCategory.identifier = "textCategory";
  520. textCategory.actions = { textAction };
  521. textCategory.sendDismissAction = true;
  522. PushNotifications::Settings settings;
  523. settings.allowAlert = true;
  524. settings.allowBadge = true;
  525. settings.allowSound = true;
  526. settings.categories = { okCategory, okCancelCategory, textCategory };
  527. return settings;
  528. }
  529. #endif