Exemplo n.º 1
0
  private void checkAlarm(Context context) {
    Date now = new Date();

    String dt = SharedValues.sdf.format(now);
    // String t = SharedValues.sdf_everyday.format(now);

    DateTimeItem dti = new DateTimeItem(dt, false);
    // DateTimeItem ti = new DateTimeItem(t, false);

    ArrayList<DateTimeItem> dtl = SharedValues.getDateTimeList(context, SharedValues.KEY_ONETIME);
    // ArrayList<DateTimeItem> tl = SharedValues.getDateTimeList(context,
    // SharedValues.KEY_EVERYDAY);

    for (int i = 0; i < dtl.size(); i++) {
      if (dtl.get(i).getDateTime().compareTo(dti.getDateTime()) < 0) {
        SharedValues.removeDateTime(context, SharedValues.KEY_ONETIME, dtl.get(i));
      }
      if (dtl.get(i).getDateTime().equals(dti.getDateTime())) {
        SharedValues.setEnableLocation(context, false);
        SwitchTaskForService task = new SwitchTaskForService(context, dtl.get(i).getState());
        SharedValues.removeDateTime(context, SharedValues.KEY_ONETIME, dtl.get(i));
        task.execute();
        break;
      }
    }
    // 0.0018783317

    /*for (int i = 0; i < tl.size(); i++) {
    	if (tl.get(i).getDateTime().equals(ti.getDateTime())) {
    		SwitchTaskForService task = new SwitchTaskForService(context, tl.get(i).getState());
    		task.execute();
    		break;
    	}
    }*/
  }
Exemplo n.º 2
0
  private void checkGPS(Context context, final boolean forceClose) {
    GPSTracker gpsTracker = new GPSTracker(context);
    if (gpsTracker.canGetLocation()) {
      boolean enable = SharedValues.getEnableLocation(context);
      double offRange = SharedValues.getOffRange(context);
      double lat = SharedValues.getLat(context);
      double lng = SharedValues.getLng(context);

      Log.d(
          "locationn",
          "setting is: " + enable + " offRange: " + offRange + " lat: " + lat + " lng: " + lng);
      if (enable && offRange != 0 && lat != 0 && lng != 0) {
        double distance =
            calculateDistance(lat, lng, gpsTracker.getLatitude(), gpsTracker.getLongitude());
        Log.d(
            "locationn",
            "getting lat: " + gpsTracker.getLatitude() + " lng: " + gpsTracker.getLongitude());
        Log.d("locationn", "getting distance: " + distance);

        if (distance >= offRange) {
          Log.d("locationn", "distance >= offRange");
          SwitchCloseTask task = new SwitchCloseTask(context);
          task.execute();
        }
      }
    }
  }