Пример #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");
    }
  }
Пример #2
0
  /* (non-Javadoc)
   * @see android.app.Service#onDestroy()
   */
  @Override
  public void onDestroy() {

    super.onDestroy();

    shutdownFulfillerService();

    if (MAIN_ACTIVITY != null) {

      Log.i(getClass().getSimpleName(), "MyService Stopped");
    }

    // now that the timer has been canceled - stop the service
    stopSelf(fulfillerServiceStartID);

    HunyDewZLogger.stopTrace("fulfillerf");
  }
Пример #3
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();
  }