예제 #1
1
  private void noticeNewBlog(Context context) {
    NotificationManager notiManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notiManager.cancel(Constants.NOTIFICATION_NEW_MICRO_BLOG); // 先清除上一次提醒;

    Intent intent = new Intent();
    // 粉丝
    if (entity.getContentType() == Skeleton.TYPE_MORE) {
      intent.setAction("com.shejiaomao.weibo.SOCIAL_GRAPH");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.putExtra("SOCIAL_GRAPH_TYPE", SocialGraphTask.TYPE_FOLLOWERS);
      intent.putExtra("USER", account.getUser());
    } else {
      intent.setAction("com.shejiaomao.weibo.MAIN");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    intent.putExtra("CONTENT_TYPE", entity.getContentType());
    intent.putExtra("ACCOUNT", account);

    Notification notification = new Notification();
    notification.icon = R.drawable.icon_notification;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.tickerText = entity.getTickerText();

    if (sheJiaoMao.isVibrateNotification()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (sheJiaoMao.isRingtoneNotification()) {
      if (StringUtil.isNotEmpty(sheJiaoMao.getRingtoneUri())) {
        notification.sound = Uri.parse(sheJiaoMao.getRingtoneUri());
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    if (sheJiaoMao.isFlashingLEDNotification()) {
      notification.ledARGB = Color.GREEN;
      notification.ledOffMS = 1000;
      notification.ledOnMS = 1000;
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    int requestCode = account.getAccountId().intValue() * 100 + entity.getContentType();
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(
        context, entity.getContentTitle(), entity.getContentText(), pendingIntent);

    notiManager.notify(requestCode, notification);
  }
 public mLargeIcon setLights(int i, int j, int k)
 {
     boolean flag = true;
     mNotification.ledARGB = i;
     mNotification.ledOnMS = j;
     mNotification.ledOffMS = k;
     Notification notification;
     if (mNotification.ledOnMS != 0 && mNotification.ledOffMS != 0)
     {
         i = 1;
     } else
     {
         i = 0;
     }
     notification = mNotification;
     j = mNotification.flags;
     if (i != 0)
     {
         i = ((flag) ? 1 : 0);
     } else
     {
         i = 0;
     }
     notification.flags = i | j & -2;
     return this;
 }
예제 #3
0
  @Override
  public void onCreate() {

    HunyDewZLogger.startTrace("fulfillerf");

    super.onCreate();

    fulfillerLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener fulfillerLocListener = new HunyDooLocationListener();

    // if (LocationManager.GPS_PROVIDER!=null)
    //   hdLocProvider = LocationManager.GPS_PROVIDER;

    Criteria hdCrit = new Criteria();
    hdCrit.setAccuracy(Criteria.ACCURACY_COARSE);
    hdLocProvider = fulfillerLocManager.getBestProvider(hdCrit, true);
    // ms  // meter
    fulfillerLocManager.requestLocationUpdates(hdLocProvider, 60000, 100, fulfillerLocListener);

    //	    Location currentLocation = fulfillerLocManager.getLastKnownLocation(hdLocProvider);

    // Instantiate the notification
    int iconReached =
        R.drawable.push_pin; // TBD - eventually this will be small size launcher Icon
    String textReachedLoca = getResources().getText(R.string.notiMesg).toString();
    long whenReached = System.currentTimeMillis();
    hdLocaReachedNotification = new Notification(iconReached, textReachedLoca, whenReached);

    hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
    hdLocaReachedNotification.defaults |= Notification.DEFAULT_LIGHTS;
    hdLocaReachedNotification.defaults |= Notification.DEFAULT_VIBRATE;
    hdLocaReachedNotification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

    // Repeat audio until the user responds
    hdLocaReachedNotification.flags |= Notification.FLAG_INSISTENT;

    // Flashing Lights
    hdLocaReachedNotification.ledARGB = 0xff00ff00;
    hdLocaReachedNotification.ledOnMS = 300;
    hdLocaReachedNotification.ledOffMS = 1000;
    hdLocaReachedNotification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // define the notification's expanded message and intent
    CharSequence contentTitle = getResources().getText(R.string.notiTitle);
    CharSequence contentText = getResources().getText(R.string.notiMesg);
    Intent notificationIntent = new Intent(this, HunyDewAAStartsHere.class);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    hdLocaReachedNotification.setLatestEventInfo(
        getApplicationContext(), contentTitle, contentText, contentIntent);

    // now start the service
    startFulfillerService();

    if (MAIN_ACTIVITY != null) {

      Log.i(getClass().getSimpleName(), "MyService Started");
    }
  }
예제 #4
0
  // send notification to Notification bar, open notification bar, will stay there,
  // but if any press, will clear all facebook notifications
  private void sendNotification(String title, String content) {
    WakeLock wl =
        pownermMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "SCREEN_BRIGHT_WAKE_LOCK");
    wl.acquire(10 * 1000);

    if (orm.getNotificationVibrate()) {
      final Vibrator vib =
          (android.os.Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
      vib.vibrate(2 * 1000);
    }

    Notification notification = new Notification();
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.ledARGB = 0xff00ff00;
    notification.ledOnMS = 500;
    notification.ledOffMS = 2000;

    if (orm.getNotificationVibrate()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }

    notification.defaults |= Notification.DEFAULT_SOUND;
    notify.notifyNotifications(
        title,
        content,
        R.drawable.facebook_logo,
        Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE,
        notification);
  }
  private void setNotification() {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon25;
    CharSequence tickerText = "Recording...";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    notification.ledARGB = 0xffff00ff;
    notification.ledOnMS = 300;
    notification.ledOffMS = 3000;
    notification.flags =
        notification.flags
            | Notification.FLAG_ONGOING_EVENT
            | Notification.FLAG_SHOW_LIGHTS
            | Notification.FLAG_INSISTENT
            | Notification.FLAG_NO_CLEAR;

    Context context = this;
    CharSequence contentTitle = "Cycle Atlanta - Recording";
    CharSequence contentText = "Tap to see your ongoing trip";
    Intent notificationIntent = new Intent(context, RecordingActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    final int RECORDING_ID = 1;
    mNotificationManager.notify(RECORDING_ID, notification);
  }
  public void remindUser() {
    soundpool.play(bikebell, 1.0f, 1.0f, 1, 0, 1.0f);

    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon25;
    long when = System.currentTimeMillis();
    int minutes = (int) (when - trip.startTime) / 60000;
    CharSequence tickerText = String.format("Still recording (%d min)", minutes);

    Notification notification = new Notification(icon, tickerText, when);
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0xffff00ff;
    notification.ledOnMS = 300;
    notification.ledOffMS = 3000;

    Context context = this;
    CharSequence contentTitle = "Cycle Atlanta - Recording";
    CharSequence contentText = "Tap to see your ongoing trip";
    Intent notificationIntent = new Intent(context, RecordingActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    final int RECORDING_ID = 1;
    mNotificationManager.notify(RECORDING_ID, notification);
  }
  /** Show a notification informing the user when a deck is ready to be used */
  private void showNotification(String deckTitle, String deckFilename) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Resources res = getResources();

    // Set the icon, scrolling text and timestamp
    Notification notification =
        new Notification(
            R.drawable.anki, res.getString(R.string.download_finished), System.currentTimeMillis());

    String deckPath = mDestination + "/" + deckFilename + ".anki";
    //        Intent loadDeckIntent = StudyOptions.getLoadDeckIntent(this, deckPath);
    // The PendingIntent to launch our activity if the user selects this notification
    //        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, loadDeckIntent, 0);

    // Set the info for the views that show in the notification panel
    //        notification.setLatestEventInfo(this, deckTitle,
    // res.getString(R.string.deck_downloaded), contentIntent);

    // Clear the notification when the user selects it
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Vibrate
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    // Show a blue light
    notification.ledARGB = 0xff0000ff;
    notification.ledOnMS = 500;
    notification.ledOffMS = 1000;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // Send the notification
    Log.i(AnkiDroidApp.TAG, "Sending notification...");
    mNotificationManager.notify(getNextNotificationId(), notification);
  }
  public void onReceive(Context context, Intent intent) {

    int icon = android.R.drawable.alert_dark_frame;
    Notification notification = new Notification(icon, "things to do", System.currentTimeMillis());

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    boolean ringtoneActive = preferences.getBoolean("ringtone_active", false);
    String ringtone =
        preferences.getString("ringtone_selected", Settings.System.DEFAULT_RINGTONE_URI.toString());

    boolean ledActive = preferences.getBoolean("led_active", false);

    boolean vibrateActive = preferences.getBoolean("vibrate_active", false);

    Log.d("QuickReminder", "Ringtone is " + (ringtoneActive ? "active" : "not active"));

    if (ringtoneActive) {
      Log.d("QuickReminder", "Selected Ringtone: " + ringtone);
      notification.sound = Uri.parse(ringtone);
    }

    if (ledActive) {
      notification.ledOnMS = 1000;
      notification.ledOffMS = 1000;
      notification.ledARGB = Color.argb(0, 0, 100, 100);
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    if (vibrateActive) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }

    CharSequence contentTitle = "QuickReminder";

    CharSequence contentText = intent.getExtras().getString("taskname");
    long taskNotificationId = intent.getExtras().getLong("taskid");

    Log.d("QuickReminder", "Creating notification with id " + (int) taskNotificationId);

    Intent notificationIntent = new Intent(context, QuickReminderActivity.class);
    notificationIntent.putExtra("tasknotificationid", taskNotificationId);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.setData(Uri.parse("quickReminder://" + taskNotificationId));

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify((int) taskNotificationId, notification);
  }
  /**
   * Handles the data returned by UnreadPmCount
   *
   * @param obj
   * @throws Exception
   */
  public void handleUnreadPMData(JSONObject obj) throws Exception {
    int messageCount = obj.getInt("unreadpmcount");

    if (messageCount > 0) {
      NotificationManager manager;
      Notification note;
      PendingIntent pendingIntent;
      Intent intent;

      // Get the notification manager system service
      manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

      // Create a new notification
      note = new Notification(R.drawable.icon, "New SoFurry PM(s)", System.currentTimeMillis());

      // Create the Intent and wrap it in a PendingIntent
      //            intent = new Intent(this, ListPMActivity.class);
      intent = new Intent(this, SFBrowsePMActivity.class);

      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

      String message = "You have " + messageCount + " new unread message";
      if (messageCount > 1) message += "s";

      message += ".";
      // Set some settings for the notification
      note.setLatestEventInfo(this, "SoFurry PM", message, pendingIntent);

      note.vibrate = AppConstants.VIBRATE_PM_INCOMING;
      note.ledARGB = 0x0000FFFF; // Cyan
      note.ledOffMS = 1500;
      note.ledOnMS = 500;
      note.number = messageCount;
      note.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

      // Fire off the notification
      manager.notify(AppConstants.NOTIFICATION_ID_PM, note);
    }

    // Set timestamp of when we last checked, for incremental message checks
    PmNotificationService.lastCheck_ = (System.currentTimeMillis() / 1000);
    prefs
        .edit()
        .putLong(AppConstants.PREFERENCE_LAST_PM_CHECK_TIME, PmNotificationService.lastCheck_)
        .commit();
  }
  private Notification createNotification(String text) {
    Notification notification = new Notification();

    notification.icon = R.drawable.logo;
    notification.when = System.currentTimeMillis();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.ledARGB = Color.WHITE;
    notification.ledOnMS = 1500;
    notification.ledOffMS = 1500;
    notification.tickerText = text;

    return notification;
  }
예제 #11
0
  private void showError(String tickerText, String title, String description) {
    Notification callFailed =
        new Notification(R.drawable.statusicon_error, tickerText, System.currentTimeMillis());
    Intent intent = new Intent(myContext, CancelCallback.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent settings =
        PendingIntent.getActivity(myContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    callFailed.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    callFailed.ledARGB = 0xFFFF0000;
    callFailed.ledOffMS = 100;
    callFailed.ledOnMS = 100;
    callFailed.vibrate = new long[] {250, 250, 250, 250, 250, 250};
    callFailed.setLatestEventInfo(myContext, title, description, settings);

    NotificationManager mgr =
        (NotificationManager) myContext.getSystemService(Activity.NOTIFICATION_SERVICE);
    if (mgr != null) {
      mgr.notify(GVCallback.Notification.CALL.hashCode(), callFailed);
    }
  }
  private void sendNotification(String msg, Context context) {
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    // notification = new
    // Notification.Builder(context).setContentTitle("Reminder").setContentText(msg).setSmallIcon(android.R.drawable.stat_sys_warning).build();   // required api 11
    // notification.icon = android.R.drawable.stat_notify_sync;
    notification.icon = android.R.drawable.stat_sys_warning;
    notification.tickerText = "Reminder";
    notification.when = System.currentTimeMillis();
    // notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    //  notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.vibrate = new long[]{100, 500, 100, 500, 100};

    // #ff1900 (dark orange)
    // #ff3300 (web-safe orange)
    // #ff2d00 (medium orange)
    // #ff4000 (medium orange)
    // #ff5300 (light orange)
    notification.ledARGB = Color.parseColor("#FF4000");
    notification.ledOffMS = 50;
    notification.ledOnMS = 500;

    // Intent intent = new Intent(this, MainActivity.class);
    notification.setLatestEventInfo(
        context, "Reminder", msg, PendingIntent.getActivity(context, 0, new Intent(), 0));
    // PendingIntent.getActivity(context, 0, null, 0));
    // PendingIntent.getActivity(this, 1, intent, 0));
    mNotificationManager.notify("test" + System.currentTimeMillis(), 100, notification);

    // Vibrate - phone may vibrate on notification even if vibrate not set in app
    if (isVibrateSet(context)) {
      Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
      vibrator.vibrate(1000);
    }
  }
 /** Issues a notification to inform the user that server has sent a message. */
 private void generateNotification(Context context, String message) {
   // System.out.println("this is message " + message);
   // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
   int icon = R.drawable.ic_launcher;
   long when = System.currentTimeMillis();
   NotificationManager notificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification notification = new Notification(icon, message, when);
   String title = context.getString(R.string.app_name);
   Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
   notificationIntent.putExtra("fromNotification", "notification");
   // set intent so it does not start a new activity
   notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
   PendingIntent intent =
       PendingIntent.getActivity(
           context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   notification.setLatestEventInfo(context, title, message, intent);
   notification.flags |= Notification.FLAG_AUTO_CANCEL;
   System.out.println("notification====>" + message);
   notification.defaults |= Notification.DEFAULT_SOUND;
   notification.defaults |= Notification.DEFAULT_VIBRATE;
   // notification.defaults |= Notification.DEFAULT_LIGHTS;
   notification.flags |= Notification.FLAG_SHOW_LIGHTS;
   notification.ledARGB = 0x00000000;
   notification.ledOnMS = 0;
   notification.ledOffMS = 0;
   notificationManager.notify(0, notification);
   PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
   PowerManager.WakeLock wakeLock =
       pm.newWakeLock(
           PowerManager.FULL_WAKE_LOCK
               | PowerManager.ACQUIRE_CAUSES_WAKEUP
               | PowerManager.ON_AFTER_RELEASE,
           "WakeLock");
   wakeLock.acquire();
   wakeLock.release();
 }
  private void createNotification(CharSequence text) {
    NotificationManager mNotificationManager =
        (NotificationManager)
            ApplicationContextProvider.getContext()
                .getSystemService(ApplicationContextProvider.getContext().NOTIFICATION_SERVICE);
    android.app.Notification notification =
        new android.app.Notification(
            R.drawable.logo_circle_notify, text, System.currentTimeMillis());
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            ApplicationContextProvider.getContext(),
            0,
            new Intent(ApplicationContextProvider.getContext(), MyActivity.class),
            0);
    notification.setLatestEventInfo(
        ApplicationContextProvider.getContext(), "خبرفوری", text, contentIntent);

    notification.ledARGB = 0xFFFF0000; // Red
    notification.flags = android.app.Notification.FLAG_SHOW_LIGHTS;
    notification.ledOnMS = 1000;
    notification.ledOffMS = 500;

    mNotificationManager.notify(NOTIFICATION_ID, notification);
  }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "writeToParcel",
        args = {android.os.Parcel.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "Notification",
        args = {android.os.Parcel.class})
  })
  public void testWriteToParcel() {
    mNotification = new Notification();
    mNotification.icon = 0;
    mNotification.number = 1;
    final Intent intent = new Intent();
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    mNotification.contentIntent = pendingIntent;
    final Intent deleteIntent = new Intent();
    final PendingIntent delPendingIntent = PendingIntent.getBroadcast(mContext, 0, deleteIntent, 0);
    mNotification.deleteIntent = delPendingIntent;
    mNotification.tickerText = TICKER_TEXT;

    final RemoteViews contentView =
        new RemoteViews(
            mContext.getPackageName(),
            com.android.internal.R.layout.status_bar_latest_event_content);
    mNotification.contentView = contentView;
    mNotification.defaults = 0;
    mNotification.flags = 0;
    final Uri uri = Uri.parse(URI_STRING);
    mNotification.sound = uri;
    mNotification.audioStreamType = 0;
    final long[] longArray = {1l, 2l, 3l};
    mNotification.vibrate = longArray;
    mNotification.ledARGB = 0;
    mNotification.ledOnMS = 0;
    mNotification.ledOffMS = 0;
    mNotification.iconLevel = 0;
    Parcel parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    // Test Notification(Parcel)
    Notification result = new Notification(parcel);
    assertEquals(mNotification.icon, result.icon);
    assertEquals(mNotification.when, result.when);
    assertEquals(mNotification.number, result.number);
    assertNotNull(result.contentIntent);
    assertNotNull(result.deleteIntent);
    assertEquals(mNotification.tickerText, result.tickerText);
    assertNotNull(result.contentView);
    assertEquals(mNotification.defaults, result.defaults);
    assertEquals(mNotification.flags, result.flags);
    assertNotNull(result.sound);
    assertEquals(mNotification.audioStreamType, result.audioStreamType);
    assertEquals(mNotification.vibrate[0], result.vibrate[0]);
    assertEquals(mNotification.vibrate[1], result.vibrate[1]);
    assertEquals(mNotification.vibrate[2], result.vibrate[2]);
    assertEquals(mNotification.ledARGB, result.ledARGB);
    assertEquals(mNotification.ledOnMS, result.ledOnMS);
    assertEquals(mNotification.ledOffMS, result.ledOffMS);
    assertEquals(mNotification.iconLevel, result.iconLevel);

    mNotification.contentIntent = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.contentIntent);

    mNotification.deleteIntent = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.deleteIntent);

    mNotification.tickerText = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.tickerText);

    mNotification.contentView = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.contentView);

    mNotification.sound = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.sound);
  }
예제 #16
0
  /**
   * Shows an Astrid notification. Pulls in ring tone and quiet hour settings from preferences. You
   * can make it say anything you like.
   *
   * @param ringTimes number of times to ring (-1 = nonstop)
   */
  public static void showNotification(
      int notificationId, Intent intent, int type, String title, String text, int ringTimes) {
    Context context = ContextManager.getContext();
    if (notificationManager == null) notificationManager = new AndroidNotificationManager(context);

    // quiet hours? unless alarm clock
    boolean quietHours = false;
    int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
    int quietHoursEnd = Preferences.getIntegerFromString(R.string.p_rmd_quietEnd, -1);
    if (quietHoursStart != -1 && quietHoursEnd != -1 && ringTimes >= 0) {
      int hour = new Date().getHours();
      if (quietHoursStart <= quietHoursEnd) {
        if (hour >= quietHoursStart && hour < quietHoursEnd) quietHours = true;
      } else { // wrap across 24/hour boundary
        if (hour >= quietHoursStart || hour < quietHoursEnd) quietHours = true;
      }
    }

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // set up properties (name and icon) for the notification
    int icon;
    switch (Preferences.getIntegerFromString(R.string.p_rmd_icon, ICON_SET_ASTRID)) {
      case ICON_SET_PINK:
        icon = R.drawable.notif_pink_alarm;
        break;
      case ICON_SET_BORING:
        icon = R.drawable.notif_boring_alarm;
        break;
      default:
        icon = R.drawable.notif_astrid;
    }

    // create notification object
    Notification notification = new Notification(icon, text, System.currentTimeMillis());
    notification.setLatestEventInfo(context, title, text, pendingIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    if (Preferences.getBoolean(R.string.p_rmd_persistent, true)) {
      notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_SHOW_LIGHTS;
      notification.ledOffMS = 5000;
      notification.ledOnMS = 700;
      notification.ledARGB = Color.YELLOW;
    } else notification.defaults = Notification.DEFAULT_LIGHTS;

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    // detect call state
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int callState = tm.getCallState();

    boolean voiceReminder = Preferences.getBoolean(R.string.p_voiceRemindersEnabled, false);

    // if multi-ring is activated, set up the flags for insistent
    // notification, and increase the volume to full volume, so the user
    // will actually pay attention to the alarm
    if (ringTimes != 1 && (type != ReminderService.TYPE_RANDOM)) {
      notification.audioStreamType = AudioManager.STREAM_ALARM;
      audioManager.setStreamVolume(
          AudioManager.STREAM_ALARM, audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);

      // insistent rings until notification is disabled
      if (ringTimes < 0) {
        notification.flags |= Notification.FLAG_INSISTENT;
        voiceReminder = false;
      }

    } else {
      notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
    }

    // quiet hours = no sound
    if (quietHours || callState != TelephonyManager.CALL_STATE_IDLE) {
      notification.sound = null;
      voiceReminder = false;
    } else {
      String notificationPreference = Preferences.getStringValue(R.string.p_rmd_ringtone);
      if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
        notification.sound = null;
        voiceReminder = false;
      } else if (notificationPreference != null) {
        if (notificationPreference.length() > 0) {
          Uri notificationSound = Uri.parse(notificationPreference);
          notification.sound = notificationSound;
        } else {
          notification.sound = null;
        }
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    // quiet hours && ! due date or snooze = no vibrate
    if (quietHours && !(type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_SNOOZE)) {
      notification.vibrate = null;
    } else if (callState != TelephonyManager.CALL_STATE_IDLE) {
      notification.vibrate = null;
    } else {
      if (Preferences.getBoolean(R.string.p_rmd_vibrate, true)
          && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION)) {
        notification.vibrate = new long[] {0, 1000, 500, 1000, 500, 1000};
      } else {
        notification.vibrate = null;
      }
    }

    if (Constants.DEBUG)
      Log.w("Astrid", "Logging notification: " + text); // $NON-NLS-1$ //$NON-NLS-2$

    for (int i = 0; i < Math.max(ringTimes, 1); i++) {
      notificationManager.notify(notificationId, notification);
      AndroidUtilities.sleepDeep(500);
    }

    if (voiceReminder) {
      AndroidUtilities.sleepDeep(2000);
      for (int i = 0; i < 50; i++) {
        AndroidUtilities.sleepDeep(500);
        if (audioManager.getMode() != AudioManager.MODE_RINGTONE) break;
      }
      try {
        VoiceOutputService.getVoiceOutputInstance().queueSpeak(text);
      } catch (VerifyError e) {
        // unavailable
      }
    }
  }
예제 #17
0
  private void showNotification(int moodId, String text) {
    Log.d("Kupluk", "start showNotification()");
    Notification notification = new Notification(moodId, null, System.currentTimeMillis());
    // boolean useSound = true;
    // boolean useVibrate = false;
    // boolean useLed = false;

    mode = Pengaturan.getMode(this);
    char b = mode.charAt(0);
    Log.d("kupluk", "mode: " + b);
    switch (b) {
      case '0':
        {
          // notification.sound=
          // Uri.parse("file:///sdcard/notification/adzan.mp3");

          notification.sound = Uri.parse("android.resource://com.amiral.kupluk/" + R.raw.adzan);
          Log.d("Kupluk", "Suara diterima");
        }
        break;
      case '1':
        {
          notification.vibrate = new long[] {1000, 1000, 1000, 1000, 1000};
          // notification.defaults |= Notification.DEFAULT_VIBRATE;
          Log.d("Kupluk", "Getar diterima");
        }
        ;
        break;
      case '2':
        {
          // notification.ledARGB = 0xff00ff00;
          notification.ledARGB = Color.BLUE;
          notification.ledOnMS = 1500;
          notification.ledOffMS = 800;
          notification.flags |= Notification.FLAG_SHOW_LIGHTS;
          Log.d("Kupluk", "Lampu Diterima");
        }
        break;
    }

    /*
     * if (useSound) {
     *
     * } if (useVibrate) { notification.vibrate = new long[] {50, 250, 200,
     * 1200}; Log.d("Kupluk", "trigger vibrate notification"); } if (useLed)
     * { notification.ledARGB = 0xff00ff00; notification.ledOnMS = 1500;
     * notification.ledOffMS = 800; notification.flags |=
     * Notification.FLAG_SHOW_LIGHTS ; Log.d("Kupluk",
     * "trigger led notification"); }
     */

    // The PendingIntent to launch our activity if the user selects this
    // notification
    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, new Intent(this, KuplukMain.class), 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, "Kupluk - Remainder", text, contentIntent);

    // Send the notification.
    mNM.notify(NOTIF_ID, notification);
    Log.d("Kupluk", "end showNotification()");
  }
  // Checks the database then creates and pushes notifications and alerts to the android.
  public void showNotification() {
    String s;
    count = 0;

    // Load the shared preferences
    LoadPreferences();

    if (notifOn) {
      // Open the database adapter
      adapter.open();

      s = adapter.fetchAll(5);
      count = Integer.parseInt(s.substring(2));

      // BROKEN: fetch all of the items about to expire
      // l = new ArrayList <Item> (adapter.fetchAll());

      // Close the database adapter
      adapter.close();

      // If notifications are on
      if (count > 0) {
        Notification note =
            new Notification(R.drawable.icon, "Food Expiring", System.currentTimeMillis());

        PendingIntent in =
            PendingIntent.getActivity(this, 0, new Intent(this, PantryProtectorActivity.class), 0);

        note.icon = R.drawable.icon;
        note.tickerText = "Food Expiring";
        note.when = System.currentTimeMillis();
        note.number = count;
        note.flags |= Notification.FLAG_AUTO_CANCEL;

        // Add flashing to the notifications
        if (flashOn && s.charAt(1) == '1') {
          // add lights to notifications
          if (debug) Log.i("DEBUG", ">>>>> Flashing. >>>>>");
          note.flags |= Notification.FLAG_SHOW_LIGHTS;
          note.ledARGB = Color.CYAN;
          note.ledOnMS = 500;
          note.ledOffMS = 500;
        }

        // Add vibration to notifications
        if (vibrateOn && s.charAt(0) == '1') {
          // add vibration to notifications
          if (debug) Log.i("DEBUG", ">>>>> ViBrAtInG. >>>>>");
          note.vibrate = new long[] {100, 200, 200, 200, 200, 200, 1000, 200, 200, 200, 1000, 200};
        }

        note.setLatestEventInfo(
            this, "Items are about to expire!", count + " items are about to expire!", in);

        notifManager.notify(NOTIF_ID, note);
      }

      // Debug statement for checking proper data flow
      if (debug && (date.getHours() != mHour || date.getMinutes() != mMinute)) {
        System.out.println(
            "Original Schedule: "
                + date.getDay()
                + ","
                + date.getHours()
                + ":"
                + date.getMinutes());
        date = new Date();
        date.setHours(mHour);
        date.setMinutes(mMinute);
        timer.cancel();
        System.out.println(
            "Changed Schedule: " + date.getDay() + "," + date.getHours() + ":" + date.getMinutes());
        startschedule();
      }
    }
  }
예제 #19
0
  private void _getPositionUpdate() {

    double lat = 0.0, lon = 0.0;

    String latlonString;

    // Log.i(getClass().getSimpleName(), " In getPositionUpdate ");

    Location currentLocation = fulfillerLocManager.getLastKnownLocation(hdLocProvider);

    if (currentLocation != null) {
      lat = currentLocation.getLatitude();
      lon = currentLocation.getLongitude();

      latlonString = "\n>>Lat: " + lat + " Lon: " + lon;
    } else {

      latlonString = "\n!!Current location info not available!! ";
    }

    // Log.i(getClass().getSimpleName(), latlonString);

    if (currentLocation == null) {

      HunyDewZLogger.write(this, "_getPositionUpdate", "Current location info not available");

      return;
    }

    HunyDewZLogger.write(
        this,
        "_getPositionUpdate",
        latlonString + " >> prevLat: " + prevLat + " prevLon: " + prevLon);

    // before we do any processing disable the timer on the fulfiller service
    // shutdownFulfillerService();

    int iPrevCurrentLat = Double.compare(lat, prevLat);

    int iPrevCurrentLon = Double.compare(lon, prevLon);

    if ((iPrevCurrentLat == 0) && (iPrevCurrentLon == 0)) {
      // position has not changed since the last check so no
      // further processing is required so return
      return;
    }

    // if (hdDBAdapterLoca.isDirty()) {

    // hdDBAdapterLoca.open();

    // hdDBAdapterLoca.close();

    //	hdDBAdapterLoca.removeDirtyFlag();
    // }

    prevLat = lat;
    prevLon = lon;

    String currentLocaName = locaStore.getLocaName(lat, lon);
    String taskLocaName;
    if (currentLocaName != null) {

      Log.i(getClass().getSimpleName(), currentLocaName);

      HunyDewZLogger.write(
          getApplicationContext(), "_getPositionUpdate", "Known Location: " + currentLocaName);

      hdDBAdapterTask = new HunyDewDBAdapterTask(this);

      hdDBAdapterTask.open();

      hdTaskListCursor = hdDBAdapterTask.getAllHDTaskItemsCursor();

      while (hdTaskListCursor.moveToNext()) {

        taskLocaName = hdTaskListCursor.getString(hdDBAdapterTask.COL_TASK_LOCA_NAME);

        if (currentLocaName.equalsIgnoreCase(taskLocaName) == true) {

          String taskName = hdTaskListCursor.getString(hdDBAdapterTask.COL_TASK_NAME);

          Log.i(getClass().getSimpleName(), taskName);

          HunyDewZLogger.write(
              getApplicationContext(), "_getPositionUpdate", "Found Task: " + taskName);

          // now prepare the Notification
          // Get a reference to the Notification Manager

          String svcName = Context.NOTIFICATION_SERVICE;
          NotificationManager notiMgr = (NotificationManager) getSystemService(svcName);

          Context context = getApplication();
          String expandedText = taskName;
          String expandedTtitle = getResources().getText(R.string.atLoca) + taskLocaName;

          Intent startActivityIntent =
              new Intent(HunyDooFulfillerService.this, HunyDewAAStartsHere.class);

          PendingIntent launchIntent =
              PendingIntent.getActivity(context, 0, startActivityIntent, 0);

          boolean isDebugEmulator = HunyDewUtils.signedWithDebugKey(this, this.getClass());
          if (isDebugEmulator == false) {
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_LIGHTS;
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_VIBRATE;
            hdLocaReachedNotification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

            // Repeat audio until the user responds
            hdLocaReachedNotification.flags |= Notification.FLAG_INSISTENT;

            // Flashing Lights
            hdLocaReachedNotification.ledARGB = 0xff00ff00;
            hdLocaReachedNotification.ledOnMS = 300;
            hdLocaReachedNotification.ledOffMS = 1000;
            hdLocaReachedNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
          } else {
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
          }

          hdLocaReachedNotification.setLatestEventInfo(
              context, expandedTtitle, expandedText, launchIntent);

          hdLocaReachedNotification.when = java.lang.System.currentTimeMillis();

          notiMgr.notify(LOCA_REACHJED_NOTIFICATION_ID, hdLocaReachedNotification);

          HunyDewZLogger.write(
              getApplicationContext(), "_getPositionUpdate", expandedText + expandedTtitle);

          // Toast AALocaToast = Toast .makeText(getApplicationContext(), expandedTtitle,
          // Toast.LENGTH_LONG);

          // AALocaToast.setGravity(Gravity.TOP, 0, 0);

          // AALocaToast.show();

          break;
        }
      }

      hdDBAdapterTask.close();
    }

    // now that we have a location name verify if this name exists in the
    // TaskList

    // now that we are done with chores start it again
    // startFulfillerService();
  }
예제 #20
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (!Preferences.getBoolean(R.string.p_rmd_enabled, true)) return;

    DependencyInjectionService.getInstance().inject(this);

    int reengagementReminders = Preferences.getInt(ReengagementService.PREF_REENGAGEMENT_COUNT, 1);
    Preferences.setInt(ReengagementService.PREF_REENGAGEMENT_COUNT, reengagementReminders + 1);

    Intent notifIntent = new Intent(context, TaskListActivity.class);

    QueryTemplate template = new QueryTemplate().where(TaskCriteria.activeVisibleMine());
    String sql =
        SortHelper.adjustQueryForFlagsAndSort(template.toString(), 0, SortHelper.SORT_AUTO)
            + " LIMIT "
            + TASK_LIMIT; //$NON-NLS-1$

    boolean hasTasks = false;
    TodorooCursor<Task> tasks =
        taskService.query(
            Query.select(Task.ID).where(TaskCriteria.activeVisibleMine()).limit(TASK_LIMIT));
    try {
      hasTasks = tasks.getCount() > 0;
    } finally {
      tasks.close();
    }

    String title =
        Notifications.getRandomReminder(
            context.getResources().getStringArray(R.array.rmd_reengage_notif_titles));
    if (title.contains("%s")) { // $NON-NLS-1$
      String name = ""; // $NON-NLS-1$
      if (actFmPreferenceService.isLoggedIn()) {
        JSONObject thisUser = ActFmPreferenceService.thisUser();
        name = thisUser.optString("first_name"); // $NON-NLS-1$
        if (TextUtils.isEmpty(name)) name = thisUser.optString("name"); // $NON-NLS-1$
        if (TextUtils.isEmpty(name)) name = context.getString(R.string.rmd_reengage_name_default);
      }
      title = String.format(title, name);
    }

    String text =
        Notifications.getRandomReminder(
            context
                .getResources()
                .getStringArray(
                    hasTasks
                        ? R.array.rmd_reengage_dialog_options
                        : R.array.rmd_reengage_dialog_empty_options));

    FilterWithCustomIntent filter =
        new FilterWithCustomIntent(
            context.getString(R.string.rmd_NoA_filter),
            context.getString(R.string.rmd_NoA_filter),
            sql,
            null);
    filter.customTaskList = new ComponentName(context, ReengagementFragment.class);
    filter.customExtras = new Bundle();
    filter.customExtras.putString(ReengagementFragment.EXTRA_TEXT, text);

    notifIntent.setAction("NOTIFY_reengagement"); // $NON-NLS-1$
    notifIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
    notifIntent.putExtra(ReengagementFragment.EXTRA_TEXT, text);
    notifIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    notifIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_REENGAGEMENT);

    NotificationManager manager = new AndroidNotificationManager(context);
    Notification notification =
        new Notification(R.drawable.notif_astrid, text, System.currentTimeMillis());

    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(context, title, text, pendingIntent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    if (Preferences.getBoolean(R.string.p_rmd_persistent, true)) {
      notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_SHOW_LIGHTS;
      notification.ledOffMS = 5000;
      notification.ledOnMS = 700;
      notification.ledARGB = Color.YELLOW;
    } else {
      notification.defaults = Notification.DEFAULT_LIGHTS;
    }

    manager.notify(0, notification);
    Flags.set(Flags.REFRESH); // Forces a reload when app launches

    ReengagementService.scheduleReengagementAlarm(context);
  }