コード例 #1
0
 private void hideUndoBar(boolean animate, MotionEvent event) {
   if (mUndoBar != null) {
     if (event != null && mUndoBar.isEventInToastBar(event)) {
       // Avoid touches inside the undo bar.
       return;
     }
     mUndoBar.hide(animate);
   }
   mDeletedAlarm = null;
   mUndoShowing = false;
 }
コード例 #2
0
  private void asyncDeleteAlarm(final Alarm alarm) {
    final AsyncTask<Alarm, Void, Void> deleteTask =
        new AsyncTask<Alarm, Void, Void>() {

          @Override
          protected Void doInBackground(Alarm... alarms) {
            for (final Alarm alarm : alarms) {
              Alarms.deleteAlarm(AlarmClock.this, alarm.id);
            }
            return null;
          }
        };
    mDeletedAlarm = alarm;
    mUndoShowing = true;
    deleteTask.execute(alarm);
    mUndoBar.show(
        new ActionableToastBar.ActionClickedListener() {
          @Override
          public void onActionClicked() {
            asyncAddAlarm(alarm, false);
            mDeletedAlarm = null;
            mUndoShowing = false;
          }
        },
        0,
        getResources().getString(R.string.alarm_deleted),
        true,
        R.string.alarm_undo,
        true);
  }
コード例 #3
0
  private void initialize(Bundle savedState) {
    setContentView(R.layout.alarm_clock);
    int[] expandedIds = null;
    int[] repeatCheckedIds = null;
    int[] selectedAlarms = null;
    Bundle previousDayMap = null;
    if (savedState != null) {
      expandedIds = savedState.getIntArray(KEY_EXPANDED_IDS);
      repeatCheckedIds = savedState.getIntArray(KEY_REPEAT_CHECKED_IDS);
      mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE);
      mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM);
      mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING);
      selectedAlarms = savedState.getIntArray(KEY_SELECTED_ALARMS);
      previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP);
      mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM);
      mInDeleteConfirmation = savedState.getBoolean(KEY_DELETE_CONFIRMATION, false);
    }

    mAlarmsList = (SwipeableListView) findViewById(R.id.alarms_list);
    mAdapter =
        new AlarmItemAdapter(
            this, expandedIds, repeatCheckedIds, selectedAlarms, previousDayMap, mAlarmsList);
    mAdapter.setLongClickListener(this);

    if (mRingtoneTitleCache == null) {
      mRingtoneTitleCache = new Bundle();
    }

    mAlarmsList.setAdapter(mAdapter);
    mAlarmsList.setVerticalScrollBarEnabled(true);
    mAlarmsList.enableSwipe(true);
    mAlarmsList.setOnCreateContextMenuListener(this);
    mAlarmsList.setOnItemSwipeListener(
        new SwipeableListView.OnItemSwipeListener() {
          @Override
          public void onSwipe(View view) {
            final AlarmItemAdapter.ItemHolder itemHolder =
                (AlarmItemAdapter.ItemHolder) view.getTag();
            mAdapter.removeSelectedId(itemHolder.alarm.id);
            updateActionMode();
            asyncDeleteAlarm(itemHolder.alarm);
          }
        });
    mAlarmsList.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent event) {
            hideUndoBar(true, event);
            return false;
          }
        });

    mUndoBar = (ActionableToastBar) findViewById(R.id.undo_bar);

    if (mUndoShowing) {
      mUndoBar.show(
          new ActionableToastBar.ActionClickedListener() {
            @Override
            public void onActionClicked() {
              asyncAddAlarm(mDeletedAlarm, false);
              mDeletedAlarm = null;
              mUndoShowing = false;
            }
          },
          0,
          getResources().getString(R.string.alarm_deleted),
          true,
          R.string.alarm_undo,
          true);
    }

    // Show action mode if needed
    int selectedNum = mAdapter.getSelectedItemsNum();
    if (selectedNum > 0) {
      mActionMode = startActionMode(this);
      setActionModeTitle(selectedNum);
    }
  }