Пример #1
0
 private void init(long length) {
   /* TODO: mTimerId must avoid StopwatchService.NOTIFICATION_ID,
    * TimerReceiver.IN_USE_NOTIFICATION_ID, and alarm ID's (which seem to be 1, 2, ..)
    */
   mTimerId = (int) Utils.getTimeNow();
   mStartTime = Utils.getTimeNow();
   mTimeLeft = mOriginalLength = mSetupLength = length;
   mLabel = "";
 }
Пример #2
0
 public long updateTimeLeft(boolean forceUpdate) {
   if (isTicking() || forceUpdate) {
     long millis = Utils.getTimeNow();
     mTimeLeft = mOriginalLength - (millis - mStartTime);
   }
   return mTimeLeft;
 }
 public void loadCitiesDb(Context context) {
   mCitiesDb.clear();
   // Read the cities DB so that the names and timezones will be taken from the DB
   // and not from the selected list so that change of locale or changes in the DB will
   // be reflected.
   CityObj[] cities = Utils.loadCitiesDataBase(context);
   if (cities != null) {
     for (int i = 0; i < cities.length; i++) {
       mCitiesDb.put(cities[i].mCityId, cities[i]);
     }
   }
 }
Пример #4
0
    @Override
    public void scheduleInstanceStateChange(
        Context context, Calendar time, AlarmInstance instance, int newState) {
      final long timeInMillis = time.getTimeInMillis();
      LogUtils.v(
          "Scheduling state change %d to instance %d at %s (%d)",
          newState, instance.mId, AlarmUtils.getFormattedTime(context, time), timeInMillis);
      final Intent stateChangeIntent =
          createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, newState);
      // Treat alarm state change as high priority, use foreground broadcasts
      stateChangeIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
      PendingIntent pendingIntent =
          PendingIntent.getBroadcast(
              context, instance.hashCode(), stateChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      if (Utils.isKitKatOrLater()) {
        am.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
      } else {
        am.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
      }
    }
  private void updateView(View clock, CityObj cityObj) {
    View nameLayout = clock.findViewById(R.id.city_name_layout);
    TextView name = (TextView) (nameLayout.findViewById(R.id.city_name));
    TextView dayOfWeek = (TextView) (nameLayout.findViewById(R.id.city_day));
    DigitalClock dclock = (DigitalClock) (clock.findViewById(R.id.digital_clock));
    AnalogClock aclock = (AnalogClock) (clock.findViewById(R.id.analog_clock));

    if (mClockStyle.equals("analog")) {
      dclock.setVisibility(View.GONE);
      aclock.setVisibility(View.VISIBLE);
      aclock.setTimeZone(cityObj.mTimeZone);
      aclock.enableSeconds(false);
    } else {
      dclock.setVisibility(View.VISIBLE);
      aclock.setVisibility(View.GONE);
      dclock.setTimeZone(cityObj.mTimeZone);
    }
    CityObj cityInDb = mCitiesDb.get(cityObj.mCityId);
    // Home city or city not in DB , use data from the save selected cities list
    name.setText(Utils.getCityName(cityObj, cityInDb));

    final Calendar now = Calendar.getInstance();
    now.setTimeZone(TimeZone.getDefault());
    int myDayOfWeek = now.get(Calendar.DAY_OF_WEEK);
    // Get timezone from cities DB if available
    String cityTZ = (cityInDb != null) ? cityInDb.mTimeZone : cityObj.mTimeZone;
    now.setTimeZone(TimeZone.getTimeZone(cityTZ));
    int cityDayOfWeek = now.get(Calendar.DAY_OF_WEEK);
    if (myDayOfWeek != cityDayOfWeek) {
      dayOfWeek.setText(
          mContext.getString(
              R.string.world_day_of_week_label,
              now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())));
      dayOfWeek.setVisibility(View.VISIBLE);
    } else {
      dayOfWeek.setVisibility(View.GONE);
    }
  }
Пример #6
0
 public void addTime(long time) {
   mTimeLeft = mOriginalLength - (Utils.getTimeNow() - mStartTime);
   if (mTimeLeft < MAX_TIMER_LENGTH - time) {
     mOriginalLength += time;
   }
 }
 public void setFormat(int amPmFontSize) {
   setFormat12Hour(Utils.get12ModeFormat(amPmFontSize));
   setFormat24Hour(Utils.get24ModeFormat());
 }