public static void createK9(Context context, String sender, String subject, String folder) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsK9NumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "email.bmp"); String description = "K9: " + sender; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "K9 mail", new String[] {sender, subject, folder}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, subject, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "K9 mail"), Protocol.createOled2lines(context, sender, subject), scroll, len, vibratePattern, description); } }
protected void notifyListeners(final int state, final IRefreshEvent event) { // Get a snapshot of the listeners so the list doesn't change while we're firing IRefreshSubscriberListener[] listenerArray; synchronized (listeners) { listenerArray = (IRefreshSubscriberListener[]) listeners.toArray(new IRefreshSubscriberListener[listeners.size()]); } // Notify each listener in a safe manner (i.e. so their exceptions don't kill us) for (int i = 0; i < listenerArray.length; i++) { IRefreshSubscriberListener listener = listenerArray[i]; Notification notification = new Notification() { @Override protected void notify(IRefreshSubscriberListener listener) { switch (state) { case STARTED: listener.refreshStarted(event); break; case DONE: listener.refreshDone(event); break; default: break; } } }; notification.run(listener); } }
public static void createGmail( Context context, String sender, String email, String subject, String snippet) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsGmailNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "gmail.bmp"); String description = "Gmail: " + sender; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Gmail", new String[] {sender, email, subject}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); Notification.addTextNotification( context, snippet, Notification.VibratePattern.NO_VIBRATE, Notification.getDefaultNotificationTimeout(context)); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, snippet, scroll); Notification.addOledNotification( context, Protocol.createOled2lines(context, "Gmail from " + sender, email), Protocol.createOled2lines(context, subject, snippet), scroll, len, vibratePattern, description); } }
/* package */ Notification processNotification(Notification notification) { switch (mSoundMode) { case OVERRIDE: notification.sound = mSoundOverride; break; case SUPPRESS: silenceNotification(notification); break; case DEFAULT: } switch (mVibrateMode) { case OVERRIDE: notification.defaults |= Notification.DEFAULT_VIBRATE; break; case SUPPRESS: suppressVibrate(notification); break; case DEFAULT: } switch (mLightsMode) { case OVERRIDE: notification.defaults |= Notification.DEFAULT_LIGHTS; break; case SUPPRESS: suppressLights(notification); break; case DEFAULT: } return notification; }
public static void createWinamp(Context context, String artist, String track, String album) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsMusicNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "winamp.bmp"); String description = "Winamp: " + track; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Winamp", new String[] {track, album, artist}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, track, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, artist), Protocol.createOled2lines(context, album, track), scroll, len, vibratePattern, description); } }
public static void createSmart( Context context, String title, String text, Bitmap icon, boolean sticky, VibratePattern vibratePattern) { if (icon == null) { icon = Utils.getBitmap(context, "notify.bmp"); } String description = "Smart: " + text; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap[] bitmaps; if (sticky) { bitmaps = smartNotify(context, icon, title, text); } else { bitmaps = new Bitmap[] {smartLines(context, icon, title, new String[] {text})}; } Notification.addBitmapNotification(context, bitmaps, vibratePattern, -1, description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, text, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, title), Protocol.createOled2lines(context, title, text), scroll, len, vibratePattern, description); } }
public final void handle(Notification nf) { if (Notification.isPreparedNotify(nf)) { if (this.prepared.compareAndSet(false, true)) { this.nStatus = NotificationStatus.PREPARE; prepared(); } } else if (Notification.isStartupNotify(nf)) { if ((this.nStatus == null) || (!NotificationStatus.PREPARE.equals(this.nStatus))) { throw new IllegalStateException("The NotificationListener is not Prepared"); } if (this.started.compareAndSet(false, true)) { this.nStatus = NotificationStatus.START; start(); } } else if (Notification.isStopNotify(nf)) { if (this.started.get()) { this.nStatus = NotificationStatus.STOP; stop(); } } else { if (!NotificationStatus.START.equals(this.nStatus)) { throw new IllegalStateException("Please class start method first[" + this.nStatus + "]"); } notify(nf); } }
public static void createNewVoicemail(Context context) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsVoicemailNumberBuzzes"); String description = "New Voicemail"; Bitmap icon = Utils.getBitmap(context, "voicemail.bmp"); if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Voicemail", new String[] {"You have", "new voicemail"}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "Voicemail"), Protocol.createOled2lines(context, "You have", "new voicemail"), null, 0, vibratePattern, description); } }
public static void createSMS(Context context, String number, String text) { String name = Utils.getContactNameFromNumber(context, number); VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsSMSNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "message.bmp"); String description = "SMS: " + name; if (MetaWatchService.watchType == WatchType.DIGITAL) { if (Preferences.stickyNotifications & !number.equals("Google Chat")) { Bitmap[] bitmaps = smartNotify(context, icon, name, text); Notification.addBitmapNotification(context, bitmaps, vibratePattern, -1, description); } else { Bitmap bitmap = smartLines(context, icon, "SMS from", new String[] {name}); Notification.addBitmapNotification(context, bitmap, vibratePattern, 4000, description); Notification.addTextNotification( context, text, Notification.VibratePattern.NO_VIBRATE, Notification.getDefaultNotificationTimeout(context)); } } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, text, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "SMS from"), Protocol.createOled2lines(context, name, text), scroll, len, vibratePattern, description); } }
/** * Custom View Notification * * @return Notification * @see CreateNotification */ private Notification setCustomViewNotification() { // Creates an explicit intent for an ResultActivity to receive. Intent resultIntent = new Intent(this, ResultActivity.class); // This ensures that the back button follows the recommended convention for the back key. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ResultActivity.class); // Adds the Intent that starts the Activity to the top of the stack. stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Create remote view and set bigContentView. RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote); expandedView.setTextViewText(R.id.text_view, "Neat logo!"); Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContentIntent(resultPendingIntent) .setContentTitle("Custom View") .build(); notification.bigContentView = expandedView; return notification; }
@Override public void step1() { txt = content.getValue().toString(); txt = txt.trim(); if (txt.length() < 5) { Notification.show( "Card not played.", "Your message is too short to be useful.", Notification.Type.ERROR_MESSAGE); doNotAdvanceSteps(); // come into step1 again next time return; } if (txt.length() > 140) { Notification.show( "Card not played.", "Only 140 characters please.", Notification.Type.ERROR_MESSAGE); doNotAdvanceSteps(); // come into step1 again next time return; } // Admins get to add cards under other names author = Mmowgli2UI.getGlobals().getUserTL(); if (author.isAdministrator()) adminSwitchAuthorsTL(event.getButton(), this); else run(); // does not need to suspend, so "continues" and executes step2 // in the same clicklistener thread }
public static void createMMS(Context context, String number) { String name = Utils.getContactNameFromNumber(context, number); VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsSMSNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "message.bmp"); String description = "MMS: " + name; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "MMS from", new String[] {name}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, name, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "MMS from"), Protocol.createOled2lines(context, name, ""), scroll, len, vibratePattern, description); } }
@Test public void testMaterialize1() { // null will cause onError to be triggered before "three" can be // returned final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three"); TestObserver NbpObserver = new TestObserver(); NbpObservable<Try<Optional<String>>> m = NbpObservable.create(o1).materialize(); m.subscribe(NbpObserver); try { o1.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } assertFalse(NbpObserver.onError); assertTrue(NbpObserver.onCompleted); assertEquals(3, NbpObserver.notifications.size()); assertEquals("one", NbpObserver.notifications.get(0).value().get()); assertTrue(Notification.isNext(NbpObserver.notifications.get(0))); assertEquals("two", Notification.getValue(NbpObserver.notifications.get(1))); assertTrue(Notification.isNext(NbpObserver.notifications.get(1))); assertEquals(NullPointerException.class, NbpObserver.notifications.get(2).error().getClass()); assertTrue(Notification.isError(NbpObserver.notifications.get(2))); }
public static void createNMA( Context context, String appName, String event, String desc, int prio, String url) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsNMANumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "notifymyandroid.bmp"); if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, appName, new String[] {event, desc}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), appName + ": " + event); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, desc, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, appName), Protocol.createOled2lines(context, event, desc), scroll, len, vibratePattern, appName + ": " + event); } }
public static void createOtherNotification( Context context, Bitmap icon, String appName, String notificationText, int buzzes) { VibratePattern vibratePattern; if (buzzes != -1) { vibratePattern = createVibratePatternFromBuzzes(buzzes); } else { vibratePattern = createVibratePatternFromPreference(context, "settingsOtherNotificationNumberBuzzes"); } if (icon == null) { icon = Utils.getBitmap(context, "notify.bmp"); } String description = appName; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, appName, new String[] {notificationText}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, notificationText, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, appName), Protocol.createOled2lines(context, "Notification", notificationText), scroll, len, vibratePattern, description); } }
public static void createGmailBlank(Context context, String recipient, int count) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsGmailNumberBuzzes"); String messages = count + " new " + (count == 1 ? "message" : "messages"); Bitmap icon = Utils.getBitmap(context, "gmail.bmp"); String description = "Gmail: unread " + count; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Gmail", new String[] {messages, recipient}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, recipient, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, " Gmail"), Protocol.createOled2lines(context, messages, recipient), scroll, len, vibratePattern, description); } }
public static void createTimezonechange(Context context) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsTimezoneNumberBuzzes"); TimeZone tz = TimeZone.getDefault(); Bitmap icon = Utils.getBitmap(context, "timezone.bmp"); String description = "Timezone Changed"; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines( context, icon, "Timezone", new String[] {"Timezone Changed", tz.getDisplayName()}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "Timezone"), Protocol.createOled1line(context, null, tz.getDisplayName()), null, 0, vibratePattern, description); } }
public static void createAlarm(Context context) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsAlarmNumberBuzzes"); final Calendar t = Calendar.getInstance(); final String currentTime = DateFormat.getTimeFormat(context).format(t.getTime()); Bitmap icon = Utils.getBitmap(context, "timer.bmp"); String description = "Alarm"; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Alarm", new String[] {currentTime}, FontCache.FontSize.LARGE); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "Alarm"), Protocol.createOled1line(context, null, currentTime), null, 0, vibratePattern, description); } }
public static void createCalendar(Context context, String text) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsCalendarNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "calendar.bmp"); String description = "Cal: " + text; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "Calendar", new String[] {text}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, text, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, " Calendar"), Protocol.createOled2lines(context, "Event Reminder:", text), scroll, len, vibratePattern, description); } }
public static void createTouchdownMail(Context context, String title, String ticker) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsTDNumberBuzzes"); Bitmap icon = Utils.getBitmap(context, "email.bmp"); String description = "TouchDown: " + title; if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines(context, icon, "TouchDown", new String[] {title, ticker}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { byte[] scroll = new byte[800]; int len = Protocol.createOled2linesLong(context, ticker, scroll); Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "TouchDown"), Protocol.createOled2lines(context, title, ticker), scroll, len, vibratePattern, description); } }
public static void createBatterylow(Context context) { VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsBatteryNumberBuzzes"); StringBuilder builder = new StringBuilder(); builder.append(Monitors.BatteryData.level); builder.append("%"); String description = "Battery low"; Bitmap icon = Utils.getBitmap(context, "batterylow.bmp"); if (MetaWatchService.watchType == WatchType.DIGITAL) { Bitmap bitmap = smartLines( context, icon, "Battery", new String[] {"Phone battery at", builder.toString()}); Notification.addBitmapNotification( context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description); } else { Notification.addOledNotification( context, Protocol.createOled1line(context, icon, "Warning!"), Protocol.createOled2lines(context, "Phone battery at", builder.toString()), null, 0, vibratePattern, description); } }
private void jButton5ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: Notification notification = new Notification(); notification.setUser(loginModel); notification.setVisible(true); this.dispose(); } // GEN-LAST:event_jButton5ActionPerformed
@Test public void twoNotificationsShouldNotBeEqualIfTheyWrapUnequalMessages() { Notification other = new Notification(notification.getMessage() + "Y", notification.getDetail()); assertNotEquals(notification, other); }
@Test public void aNotificationShouldBeEqualToTheOtherEvenTheirDetailsAreBithNull() { notification = new Notification(notification.getMessage(), null); Notification other = new Notification(notification.getMessage(), null); assertEquals(notification, other); }
@Test public void twoNotificationsShouldBeEqualIfTheyWrapEqualMessagesAndEqualDetails() { Notification other = new Notification(notification.getMessage(), notification.getDetail()); assertEquals(notification, other); assertThat(notification.hashCode(), is(equalTo(other.hashCode()))); }
/** * Sets {@link Notification#setThingID(Long)}. * * @param thing The thing that the notification refers to. * @return The builder. */ public B forThing(Thing thing) { if (thing == null) { notification.setThingID(null); return self(); } else { notification.setThingID(thing.getId()); return param("thing.name", thing.getName()); } }
@Test public void testSimpleJsonToNotification() throws IOException { String expectedContents = "Notification [event=null, filterId=e3c045ec-8028-48ce-9373-93e5b01c690c, filterName=Pester Michael about Critical events, notificationId=4ba705f6-690c-4877-b041-791b84e1e032]"; String s = readFile(NOTIFICATION_BASIC_JSON, Charset.defaultCharset()); ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally Notification notification = mapper.readValue(s, Notification.class); System.out.println("notification: " + notification); assertEquals("Notification output incorrect", expectedContents, notification.toString()); }
private Notification makeNotification(Properties p) { Notification notification = new Notification(); String id = p.getProperty("notificationID"); String description = p.getProperty("description"); notification.setId(Integer.parseInt(id)); notification.setMessage(description); notification.setRecipient(queryNotificationTo(Integer.parseInt(id))); Event event = queryNotificationEvent(Integer.parseInt(id)); notification.setEvent(event); return notification; }
public Notification build() { Notification notification = new Notification(); if (token != null) { notification.setToken(token); } else { throw new IllegalArgumentException("token is null!"); } notification.setPriority(priority); // TODO 这里是否把没有设置过期时间的通知都设置成无限的? notification.setExpirationDate(expirationDate); /** * * * <pre> * 因为这里有两种格式,一种是: * "aps" : { * "alert" : "You got your emails.", * "badge" : 9, * "sound" : "bingbong.aiff" * }, * * 另一种是: * "aps" : { * "alert" : { * "body" : "Bob wants to play poker", * "action-loc-key" : "PLAY" * }, * "badge" : 5, * }, * </pre> */ if (alert != null) { aps.put("alert", alert); } else { aps.put("alert", alertObject); } if (alert != null && !alertObject.isEmpty()) { logger.warn( "can not set alert and alertObject both!, https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW12"); } payload.put("aps", aps); byte[] bytes = payload.toString().getBytes(utf8); if (bytes.length > MAX_PAYLOAD_SIZE) { throw new IllegalArgumentException("payload.length >" + MAX_PAYLOAD_SIZE); } notification.setPayload(bytes); return notification; }
public void handleNotification(Notification notif, Object handback) { String type = notif.getType(); if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { GarbageCollectionNotificationInfo gcNotif = GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData()); String source = ((ObjectName) notif.getSource()).getCanonicalName(); synchronized (synchronizer) { if (listenerInvoked.get(source) == null) { listenerInvoked.put(((ObjectName) notif.getSource()).getCanonicalName(), gcNotif); count++; if (count >= number) { synchronizer.notify(); } } } } }