Example #1
0
  /**
   * Scroll to alarm with given alarm id.
   *
   * @param alarmId The alarm id to scroll to.
   */
  private void scrollToAlarm(int alarmId) {
    for (int i = 0; i < mAdapter.getCount(); i++) {
      long id = mAdapter.getItemId(i);
      if (id == alarmId) {
        mAdapter.setNewAlarm(alarmId);
        mAlarmsList.smoothScrollToPositionFromTop(i, 0);

        final int firstPositionId = mAlarmsList.getFirstVisiblePosition();
        final int childId = i - firstPositionId;

        final View view = mAlarmsList.getChildAt(childId);
        mAdapter.getView(i, view, mAlarmsList);
        break;
      }
    }
  }
Example #2
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);
    }
  }