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.

384 lines
15KB

  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. #pragma once
  20. #include "../JuceLibraryCode/JuceHeader.h"
  21. //==============================================================================
  22. class MainContentComponent : public Component,
  23. private Button::Listener,
  24. private ComboBox::Listener,
  25. private ChangeListener,
  26. private ComponentListener,
  27. private PushNotifications::Listener
  28. {
  29. public:
  30. //==============================================================================
  31. MainContentComponent();
  32. ~MainContentComponent();
  33. void paint (Graphics&) override;
  34. void resized() override;
  35. private:
  36. void buttonClicked (Button*) override;
  37. void comboBoxChanged (ComboBox* comboBoxThatHasChanged) override;
  38. void sendLocalNotification();
  39. void fillRequiredParams (PushNotifications::Notification& n);
  40. void fillOptionalParamsOne (PushNotifications::Notification& n);
  41. void fillOptionalParamsTwo (PushNotifications::Notification& n);
  42. void fillOptionalParamsThree (PushNotifications::Notification& n);
  43. void setupAccentColour();
  44. void setupLedColour();
  45. void getDeliveredNotifications();
  46. void changeListenerCallback (ChangeBroadcaster* source) override;
  47. void componentBeingDeleted (Component& component) override;
  48. void handleNotification (bool isLocalNotification, const PushNotifications::Notification& n) override;
  49. void handleNotificationAction (bool isLocalNotification,
  50. const PushNotifications::Notification& n,
  51. const juce::String& actionIdentifier,
  52. const juce::String& optionalResponse) override;
  53. void localNotificationDismissedByUser (const PushNotifications::Notification& n) override;
  54. void deliveredNotificationsListReceived (const Array<PushNotifications::Notification>&) override;
  55. void pendingLocalNotificationsListReceived (const Array<PushNotifications::Notification>&) override;
  56. void deviceTokenRefreshed (const String& token) override;
  57. #if JUCE_ANDROID
  58. void remoteNotificationsDeleted() override;
  59. void upstreamMessageSent (const String& messageId) override;
  60. void upstreamMessageSendingError (const String& messageId, const String& error) override;
  61. static Array<PushNotifications::Channel> getAndroidChannels();
  62. #elif JUCE_IOS || JUCE_MAC
  63. static PushNotifications::Settings getNotificationSettings();
  64. #endif
  65. struct RowComponent : public Component
  66. {
  67. RowComponent (Label& l, Component& c, int u = 1)
  68. : label (l),
  69. editor (c),
  70. rowUnits (u)
  71. {
  72. addAndMakeVisible (label);
  73. addAndMakeVisible (editor);
  74. }
  75. void resized() override
  76. {
  77. auto bounds = getLocalBounds();
  78. label .setBounds (bounds.removeFromLeft (getWidth() / 3));
  79. editor.setBounds (bounds);
  80. }
  81. Label& label;
  82. Component& editor;
  83. int rowUnits;
  84. };
  85. struct ParamControls
  86. {
  87. Label identifierLabel { "identifierLabel", "Identifier" };
  88. TextEditor identifierEditor;
  89. Label titleLabel { "titleLabel", "Title" };
  90. TextEditor titleEditor;
  91. Label bodyLabel { "bodyLabel", "Body" };
  92. TextEditor bodyEditor;
  93. Label categoryLabel { "categoryLabel", "Category" };
  94. ComboBox categoryComboBox;
  95. Label channelIdLabel { "channelIdLabel", "Channel ID" };
  96. ComboBox channelIdComboBox;
  97. Label iconLabel { "iconLabel", "Icon" };
  98. ComboBox iconComboBox;
  99. Label subtitleLabel { "subtitleLabel", "Subtitle" };
  100. TextEditor subtitleEditor;
  101. Label badgeNumberLabel { "badgeNumberLabel", "BadgeNumber" };
  102. ComboBox badgeNumberComboBox;
  103. Label soundToPlayLabel { "soundToPlayLabel", "SoundToPlay" };
  104. ComboBox soundToPlayComboBox;
  105. Label propertiesLabel { "propertiesLabel", "Properties" };
  106. TextEditor propertiesEditor;
  107. Label fireInLabel { "fireInLabel", "Fire in" };
  108. ComboBox fireInComboBox;
  109. Label repeatLabel { "repeatLabel", "Repeat" };
  110. ToggleButton repeatButton;
  111. Label largeIconLabel { "largeIconLabel", "Large Icon" };
  112. ComboBox largeIconComboBox;
  113. Label badgeIconLabel { "badgeIconLabel", "Badge Icon" };
  114. ComboBox badgeIconComboBox;
  115. Label tickerTextLabel { "tickerTextLabel", "Ticker Text" };
  116. TextEditor tickerTextEditor;
  117. Label autoCancelLabel { "autoCancelLabel", "AutoCancel" };
  118. ToggleButton autoCancelButton;
  119. Label alertOnlyOnceLabel { "alertOnlyOnceLabel", "AlertOnlyOnce" };
  120. ToggleButton alertOnlyOnceButton;
  121. Label actionsLabel { "actionsLabel", "Actions" };
  122. ComboBox actionsComboBox;
  123. Label progressMaxLabel { "progressMaxLabel", "ProgressMax" };
  124. ComboBox progressMaxComboBox;
  125. Label progressCurrentLabel { "progressCurrentLabel", "ProgressCurrent" };
  126. ComboBox progressCurrentComboBox;
  127. Label progressIndeterminateLabel { "progressIndeterminateLabel", "ProgressIndeterminate" };
  128. ToggleButton progressIndeterminateButton;
  129. Label notifCategoryLabel { "notifCategoryLabel", "Category" };
  130. ComboBox notifCategoryComboBox;
  131. Label priorityLabel { "priorityLabel", "Priority" };
  132. ComboBox priorityComboBox;
  133. Label personLabel { "personLabel", "Person" };
  134. TextEditor personEditor;
  135. Label lockScreenVisibilityLabel { "lockScreenVisibilityLabel", "LockScreenVisibility" };
  136. ComboBox lockScreenVisibilityComboBox;
  137. Label groupIdLabel { "groupIdLabel", "GroupID" };
  138. TextEditor groupIdEditor;
  139. Label sortKeyLabel { "sortKeyLabel", "SortKey" };
  140. TextEditor sortKeyEditor;
  141. Label groupSummaryLabel { "groupSummaryLabel", "GroupSummary" };
  142. ToggleButton groupSummaryButton;
  143. Label groupAlertBehaviourLabel { "groupAlertBehaviourLabel", "GroupAlertBehaviour" };
  144. ComboBox groupAlertBehaviourComboBox;
  145. Label accentColourLabel { "accentColourLabel", "AccentColour" };
  146. TextButton accentColourButton;
  147. Label ledColourLabel { "ledColourLabel", "LedColour" };
  148. TextButton ledColourButton;
  149. Label ledMsToBeOnLabel { "ledMsToBeOnLabel", "LedMsToBeOn" };
  150. ComboBox ledMsToBeOnComboBox;
  151. Label ledMsToBeOffLabel { "ledMsToBeOffLabel", "LedMsToBeOff" };
  152. ComboBox ledMsToBeOffComboBox;
  153. Label vibratorMsToBeOnLabel { "vibratorMsToBeOnLabel", "VibrationMsToBeOn" };
  154. ComboBox vibratorMsToBeOnComboBox;
  155. Label vibratorMsToBeOffLabel { "vibratorMsToBeOffLabel", "VibrationMsToBeOff" };
  156. ComboBox vibratorMsToBeOffComboBox;
  157. Label localOnlyLabel { "localOnlyLabel", "LocalOnly" };
  158. ToggleButton localOnlyButton;
  159. Label ongoingLabel { "ongoingLabel", "Ongoing" };
  160. ToggleButton ongoingButton;
  161. Label timestampVisibilityLabel { "timestampVisibilityLabel", "TimestampMode" };
  162. ComboBox timestampVisibilityComboBox;
  163. Label timeoutAfterLabel { "timeoutAfterLabel", "Timeout After Ms" };
  164. ComboBox timeoutAfterComboBox;
  165. ColourSelector* accentColourSelector = nullptr;
  166. ColourSelector* ledColourSelector = nullptr;
  167. };
  168. void setupControls();
  169. void distributeControls();
  170. struct ParamsView : public Component
  171. {
  172. ParamsView()
  173. {
  174. // For now, to be able to dismiss mobile keyboard.
  175. setWantsKeyboardFocus (true);
  176. }
  177. void addRowComponent (RowComponent *rc)
  178. {
  179. rowComponents.add (rc);
  180. addAndMakeVisible (rc);
  181. }
  182. void resized() override
  183. {
  184. int totalRowUnits = 0;
  185. for (const auto &rc : rowComponents)
  186. totalRowUnits += rc->rowUnits;
  187. const int rowHeight = getHeight() / totalRowUnits;
  188. auto bounds = getLocalBounds();
  189. for (auto &rc : rowComponents)
  190. rc->setBounds (bounds.removeFromTop (rc->rowUnits * rowHeight));
  191. auto* last = rowComponents[rowComponents.size() - 1];
  192. last->setBounds (last->getBounds().withHeight (getHeight() - last->getY()));
  193. }
  194. private:
  195. OwnedArray<RowComponent> rowComponents;
  196. };
  197. struct AuxActionsView : public Component
  198. {
  199. AuxActionsView()
  200. {
  201. addAndMakeVisible (getDeliveredNotificationsButton);
  202. addAndMakeVisible (removeDeliveredNotifWithIdButton);
  203. addAndMakeVisible (deliveredNotifIdentifier);
  204. addAndMakeVisible (removeAllDeliveredNotifsButton);
  205. #if JUCE_IOS || JUCE_MAC
  206. addAndMakeVisible (getPendingNotificationsButton);
  207. addAndMakeVisible (removePendingNotifWithIdButton);
  208. addAndMakeVisible (pendingNotifIdentifier);
  209. addAndMakeVisible (removeAllPendingNotifsButton);
  210. #endif
  211. // For now, to be able to dismiss mobile keyboard.
  212. setWantsKeyboardFocus (true);
  213. }
  214. void resized() override
  215. {
  216. const int columnWidth = getWidth();
  217. const int rowHeight = getHeight() / 6;
  218. auto bounds = getLocalBounds();
  219. getDeliveredNotificationsButton .setBounds (bounds.removeFromTop (rowHeight));
  220. auto rowBounds = bounds.removeFromTop (rowHeight);
  221. removeDeliveredNotifWithIdButton.setBounds (rowBounds.removeFromLeft (columnWidth / 2));
  222. deliveredNotifIdentifier .setBounds (rowBounds);
  223. removeAllDeliveredNotifsButton .setBounds (bounds.removeFromTop (rowHeight));
  224. #if JUCE_IOS || JUCE_MAC
  225. getPendingNotificationsButton .setBounds (bounds.removeFromTop (rowHeight));
  226. rowBounds = bounds.removeFromTop (rowHeight);
  227. removePendingNotifWithIdButton.setBounds (rowBounds.removeFromLeft (columnWidth / 2));
  228. pendingNotifIdentifier .setBounds (rowBounds);
  229. removeAllPendingNotifsButton .setBounds (bounds.removeFromTop (rowHeight));
  230. #endif
  231. }
  232. TextButton getDeliveredNotificationsButton { "Get Delivered Notifications" };
  233. TextButton removeDeliveredNotifWithIdButton { "Remove Delivered Notif With ID:" };
  234. TextEditor deliveredNotifIdentifier;
  235. TextButton removeAllDeliveredNotifsButton { "Remove All Delivered Notifs" };
  236. TextButton getPendingNotificationsButton { "Get Pending Notifications" };
  237. TextButton removePendingNotifWithIdButton { "Remove Pending Notif With ID:" };
  238. TextEditor pendingNotifIdentifier;
  239. TextButton removeAllPendingNotifsButton { "Remove All Pending Notifs" };
  240. };
  241. struct RemoteView : public Component
  242. {
  243. RemoteView()
  244. {
  245. addAndMakeVisible (getDeviceTokenButton);
  246. #if JUCE_ANDROID
  247. addAndMakeVisible (sendRemoteMessageButton);
  248. addAndMakeVisible (subscribeToSportsButton);
  249. addAndMakeVisible (unsubscribeFromSportsButton);
  250. #endif
  251. }
  252. void resized()
  253. {
  254. const int rowSize = getHeight () / 10;
  255. auto bounds = getLocalBounds().reduced (getWidth() / 10, getHeight() / 10);
  256. bounds.removeFromTop (2 * rowSize);
  257. getDeviceTokenButton .setBounds (bounds.removeFromTop (rowSize));
  258. sendRemoteMessageButton .setBounds (bounds.removeFromTop (rowSize));
  259. subscribeToSportsButton .setBounds (bounds.removeFromTop (rowSize));
  260. unsubscribeFromSportsButton.setBounds (bounds.removeFromTop (rowSize));
  261. }
  262. TextButton getDeviceTokenButton { "GetDeviceToken" };
  263. TextButton sendRemoteMessageButton { "SendRemoteMessage" };
  264. TextButton subscribeToSportsButton { "SubscribeToSports" };
  265. TextButton unsubscribeFromSportsButton { "UnsubscribeFromSports" };
  266. };
  267. struct DemoTabbedComponent : public TabbedComponent
  268. {
  269. explicit DemoTabbedComponent (TabbedButtonBar::Orientation orientation)
  270. : TabbedComponent (orientation)
  271. {
  272. }
  273. void currentTabChanged (int, const String& newCurrentTabName) override
  274. {
  275. if (! showedRemoteInstructions && newCurrentTabName == "Remote")
  276. {
  277. MainContentComponent::showRemoteInstructions();
  278. showedRemoteInstructions = true;
  279. }
  280. }
  281. private:
  282. bool showedRemoteInstructions = false;
  283. };
  284. static void showRemoteInstructions()
  285. {
  286. #if JUCE_IOS || JUCE_MAC
  287. NativeMessageBox::showMessageBoxAsync (AlertWindow::InfoIcon,
  288. "Remote Notifications instructions",
  289. "In order to be able to test remote notifications "
  290. "ensure that the app is signed and that you register "
  291. "the bundle ID for remote notifications in "
  292. "Apple Developer Center.");
  293. #endif
  294. }
  295. Label headerLabel { "headerLabel", "Push Notifications Demo" };
  296. ParamControls paramControls;
  297. ParamsView paramsOneView;
  298. ParamsView paramsTwoView;
  299. ParamsView paramsThreeView;
  300. ParamsView paramsFourView;
  301. AuxActionsView auxActionsView;
  302. TabbedComponent localNotificationsTabs { TabbedButtonBar::TabsAtTop };
  303. RemoteView remoteView;
  304. DemoTabbedComponent mainTabs { TabbedButtonBar::TabsAtTop };
  305. TextButton sendButton { "Send!" };
  306. Label notAvailableYetLabel { "notAvailableYetLabel", "Push Notifications feature is not available on this platform yet!" };
  307. //==============================================================================
  308. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
  309. };