private void initializeReceiverData(long receiverId) {
    if (receiverId == -1) {
      // init blank
      brandListView.setItemChecked(0, true);
      updateModelList(brandListView.getSelectedItem().toString());

      modelListView.setItemChecked(0, true);
    } else {
      try {
        // init existing receiver
        final Receiver receiver = DatabaseHandler.getReceiver(receiverId);

        int brandPosition = brandNamesAdapter.getPosition(receiver.getBrand().getName());
        brandListView.setItemChecked(brandPosition, true);
        brandListView.smoothScrollToPosition(brandPosition);
        updateModelList(receiver.getBrand().getName());

        int modelPosition = modelNamesAdapter.getPosition(receiver.getModel());
        modelListView.setItemChecked(modelPosition, true);
        modelListView.smoothScrollToPosition(modelPosition);

      } catch (Exception e) {
        StatusMessageHandler.showErrorMessage(getActivity(), e);
      }
    }
  }
コード例 #2
0
  private void parseActionIntent(Context context, Intent intent) {
    try {
      long id = Long.valueOf(intent.getData().getHost());
      Timer timer = DatabaseHandler.getTimer(id);

      Calendar currentTime = Calendar.getInstance();
      if (Build.VERSION.SDK_INT < 19) {
        int currentHour = currentTime.get(Calendar.HOUR_OF_DAY);
        int executionHour = timer.getExecutionTime().get(Calendar.HOUR_OF_DAY);
        if (currentHour != executionHour) {
          Log.d(
              this,
              "Timer hour doesnt match: "
                  + currentHour
                  + " != "
                  + timer.getExecutionTime().get(Calendar.HOUR_OF_DAY));
          return;
        }

        int currentMinute = currentTime.get(Calendar.MINUTE);
        int executionMinute = timer.getExecutionTime().get(Calendar.MINUTE);
        if (!(currentMinute >= executionMinute && currentMinute <= executionMinute + 3)) {
          Log.d(
              this,
              "Timer minute not in valid range: currentMinute: "
                  + currentMinute
                  + " ; executionMinute: "
                  + executionMinute);
          return;
        }
      }

      Log.d(this, "executing timer...");
      switch (timer.getExecutionType()) {
        case Timer.EXECUTION_TYPE_WEEKDAY:
          WeekdayTimer weekdayTimer = (WeekdayTimer) timer;

          if (weekdayTimer.containsExecutionDay(currentTime.get(Calendar.DAY_OF_WEEK))) {
            ActionHandler.execute(context, timer);
          } else {
            Log.d(this, "timer executionDays doesn't contain current day, not executing timer");
          }
          break;
        case Timer.EXECUTION_TYPE_INTERVAL:
          ActionHandler.execute(context, timer);
          break;
        default:
          Log.e(this, "Unknown Timer executionType: " + timer.getExecutionType());
          break;
      }

    } catch (Exception e) {
      StatusMessageHandler.showErrorMessage(context, e);
    }

    reinitializeAlarms(context);
  }
コード例 #3
0
 private void reinitializeAlarms(Context context) {
   try {
     for (Timer timer : DatabaseHandler.getAllTimers(true)) {
       AlarmHandler.cancelAlarm(context, timer);
       AlarmHandler.createAlarm(context, timer);
     }
   } catch (Exception e) {
     StatusMessageHandler.showErrorMessage(context, e);
   }
 }