예제 #1
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");
    }
  }
    /**
     * Constructor.
     *
     * <p>Automatically sets the when field to {@link System#currentTimeMillis()
     * System.currentTimeMillis()} and the audio stream to the {@link Notification#STREAM_DEFAULT}.
     *
     * @param context A {@link Context} that will be used to construct the RemoteViews. The Context
     *     will not be held past the lifetime of this Builder object.
     */
    public Builder(Context context) {
      mContext = context;

      // Set defaults to match the defaults of a Notification
      mNotification.when = System.currentTimeMillis();
      mNotification.audioStreamType = Notification.STREAM_DEFAULT;
      mPriority = PRIORITY_DEFAULT;
    }
 {
     mShowWhen = true;
     mActions = new ArrayList();
     mLocalOnly = false;
     mColor = 0;
     mVisibility = 0;
     mNotification = new Notification();
     mContext = context;
     mNotification.when = System.currentTimeMillis();
     mNotification.audioStreamType = -1;
     mPriority = 0;
     mPeople = new ArrayList();
 }
 private void showNotify() {
   NotificationManager manager =
       (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification notification = new Notification();
   notification.icon = R.drawable.notify_icon;
   notification.tickerText = "天天价会员特权";
   notification.defaults = Notification.DEFAULT_SOUND;
   notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;
   notification.flags = Notification.FLAG_AUTO_CANCEL;
   Intent intent = new Intent(this, Member_Aty.class);
   PendingIntent pendingIntent =
       PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
   notification.setLatestEventInfo(this, "天天价会员特权", "点击查看详情", pendingIntent);
   manager.notify(10, 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);
  }
예제 #6
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();
  }
 public mNotification setSound(Uri uri, int i)
 {
     mNotification.sound = uri;
     mNotification.audioStreamType = i;
     return this;
 }
 public mSortKey setSound(Uri uri)
 {
     mNotification.sound = uri;
     mNotification.audioStreamType = -1;
     return this;
 }
예제 #9
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
      }
    }
  }