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 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);
   }
 }
 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);
   }
 }
 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 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 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);
   }
 }
 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 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 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 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 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);
   }
 }
 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);
   }
 }
  @Override
  public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();

    // add digital watch check

    if (action.equals("org.metawatch.manager.APPLICATION_UPDATE")) {
      // boolean dither = false;
      // if (intent.hasExtra("requires_dither"))
      //	dither = true;
      if (intent.hasExtra("array")) {
        int[] array = intent.getIntArrayExtra("array");
        Application.updateAppMode(context, array);
      } else if (intent.hasExtra("buffer")) {
        byte[] buffer = intent.getByteArrayExtra("buffer");
        Application.updateAppMode(context, buffer);
      }
      return;
    }

    if (action.equals("org.metawatch.manager.WIDGET_UPDATE")) {
      Log.d(MetaWatch.TAG, "WIDGET_UPDATE received");
      WidgetManager.getFromIntent(context, intent);
      return;
    }

    if (action.equals("org.metawatch.manager.APPLICATION_START")) {
      Application.startAppMode();
      return;
    }

    if (action.equals("org.metawatch.manager.APPLICATION_STOP")) {
      Application.stopAppMode(context);
      return;
    }

    if (action.equals("org.metawatch.manager.NOTIFICATION")) {

      /* Set up vibrate pattern. */
      VibratePattern vibrate = getVibratePatternFromIntent(intent);

      if (intent.hasExtra("oled1")
          || intent.hasExtra("oled1a")
          || intent.hasExtra("oled1b")
          || intent.hasExtra("oled2")
          || intent.hasExtra("oled2a")
          || intent.hasExtra("oled2b")) {

        byte[] line1 = Protocol.createOled1line(context, null, "");
        byte[] line2 = Protocol.createOled1line(context, null, "");
        byte[] scroll = null;
        int scrollLen = 0;
        if (intent.hasExtra("oled1")) {
          line1 = Protocol.createOled1line(context, null, intent.getStringExtra("oled1"));
        } else {
          if (intent.hasExtra("oled1a") || intent.hasExtra("oled1b")) {
            String oled1a = "";
            String oled1b = "";
            if (intent.hasExtra("oled1a")) {
              oled1a = intent.getStringExtra("oled1a");
            }
            if (intent.hasExtra("oled1b")) {
              oled1b = intent.getStringExtra("oled1b");
            }
            line1 = Protocol.createOled2lines(context, oled1a, oled1b);
          }
        }
        if (intent.hasExtra("oled2")) {
          line2 = Protocol.createOled1line(context, null, intent.getStringExtra("oled2"));
        } else {
          if (intent.hasExtra("oled2a") || intent.hasExtra("oled2b")) {
            String oled2a = "";
            String oled2b = "";
            if (intent.hasExtra("oled2a")) {
              oled2a = intent.getStringExtra("oled2a");
            }
            if (intent.hasExtra("oled2b")) {
              oled2b = intent.getStringExtra("oled2b");
            }
            scroll = new byte[800];
            scrollLen = Protocol.createOled2linesLong(context, oled2b, scroll);
            line2 = Protocol.createOled2lines(context, oled2a, oled2b);
          }
        }
        Notification.addOledNotification(context, line1, line2, scroll, scrollLen, vibrate);

      } else if (intent.hasExtra("text")) {
        String text = intent.getStringExtra("text");
        Notification.addTextNotification(
            context, text, vibrate, Notification.getDefaultNotificationTimeout(context));
        if (Preferences.logging)
          Log.d(
              MetaWatch.TAG,
              "ApiIntentReceiver.onReceive(): sending text notification; text='" + text + "'");
      } else if (intent.hasExtra("array")) {
        int[] array = intent.getIntArrayExtra("array");
        Notification.addArrayNotification(context, array, vibrate);
      } else if (intent.hasExtra("buffer")) {
        byte[] buffer = intent.getByteArrayExtra("buffer");
        Notification.addBufferNotification(context, buffer, vibrate);
      }
      return;
    }

    if (action.equals("org.metawatch.manager.VIBRATE")) {
      /* Set up vibrate pattern. */
      VibratePattern vibrate = getVibratePatternFromIntent(intent);

      if (vibrate.vibrate) Protocol.vibrate(vibrate.on, vibrate.off, vibrate.cycles);

      return;
    }
  }