Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7c4dc56 authored by Isaac Katzenelson's avatar Isaac Katzenelson
Browse files

Fix delete after use implementation for timers

Bug: 10517026
Change-Id: I35f450dcfa379df92dbdfd997a351056e9233f41
parent 3ec2fabd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -449,7 +449,10 @@
    <string name="timer_delete">Delete</string>
    <!-- Describes the purpose of the button increase the remaining time on a timer by one minute. -->
    <string name="timer_plus_one">Add 1 Minute</string>
    <!-- Describes the purpose of the button to stop the timer. -->
    <string name="timer_stop">Stop</string>
    <!-- Describes the purpose of the button to stop and delete the timer. -->
    <string name="timer_done">Done</string>
    <!-- Describes the purpose of the button to return the timer to it's original starting value. -->
    <string name="timer_reset">Reset</string>
    <!-- Describes the purpose of the button to discard the current dialog values. Will also close the dialog if other time's exist -->
+12 −15
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.deskclock;

import static android.provider.AlarmClock.ACTION_SET_ALARM;
import static android.provider.AlarmClock.ACTION_SET_TIMER;
import static android.provider.AlarmClock.EXTRA_DELETE_AFTER_USE;
import static android.provider.AlarmClock.EXTRA_HOUR;
import static android.provider.AlarmClock.EXTRA_LENGTH;
import static android.provider.AlarmClock.EXTRA_MESSAGE;
@@ -139,12 +138,9 @@ public class HandleApiCalls extends Activity {
        if (label == null) {
            label = "";
        }
        final boolean deleteAfterUse = intent.getBooleanExtra(EXTRA_DELETE_AFTER_USE, false);

        TimerObj timer = null;
        // Do not delete existing timers by reusing them and deleting them after use
        if (!deleteAfterUse) {
            // Find an existing matching timer
        // Find an existing matching time
        final ArrayList<TimerObj> timers = new ArrayList<TimerObj>();
        TimerObj.getTimersFromSharedPrefs(prefs, timers);
        for (TimerObj t : timers) {
@@ -154,23 +150,24 @@ public class HandleApiCalls extends Activity {
                break;
            }
        }
        }

        boolean skipUi = intent.getBooleanExtra(EXTRA_SKIP_UI, false);
        if (timer == null) {
            // Use a new timer
            timer = new TimerObj(length, label);
            // Timers set without presenting UI to the user will be deleted after use
            timer.mDeleteAfterUse = skipUi;
        }

        timer.mState = TimerObj.STATE_RUNNING;
        timer.mStartTime = Utils.getTimeNow();
        timer.mDeleteAfterUse = deleteAfterUse;
        timer.writeToSharedPref(prefs);

        // Tell TimerReceiver that the timer was started
        sendBroadcast(new Intent().setAction(Timers.START_TIMER)
                .putExtra(Timers.TIMER_INTENT_EXTRA, timer.mTimerId));

        if (intent.getBooleanExtra(EXTRA_SKIP_UI, false)) {
        if (skipUi) {
            Utils.showInUseNotifications(this);
        } else {
            startActivity(new Intent(this, DeskClock.class)
+18 −9
Original line number Diff line number Diff line
@@ -806,6 +806,15 @@ public class TimerFragment extends DeskClockFragment
                updateTimersState(t, Timers.START_TIMER);
                break;
            case TimerObj.STATE_TIMESUP:
                if (t.mDeleteAfterUse) {
                    cancelTimerNotification(t.mTimerId);
                    animateTimerDeletion(t);
                    // Tell receiver the timer was deleted.
                    // It will stop all activity related to the
                    // timer
                    t.mState = TimerObj.STATE_DELETED;
                    updateTimersState(t, Timers.DELETE_TIMER);
                } else {
                    t.mState = TimerObj.STATE_DONE;
                    // Used in a context where the timer could be off-screen and without a view
                    if (t.mView != null) {
@@ -814,13 +823,6 @@ public class TimerFragment extends DeskClockFragment
                    updateTimersState(t, Timers.TIMER_DONE);
                    cancelTimerNotification(t.mTimerId);
                    updateTimesUpMode(t);
                if (t.mDeleteAfterUse) {
                    animateTimerDeletion(t);
                    // Tell receiver the timer was deleted.
                    // It will stop all activity related to the
                    // timer
                    t.mState = TimerObj.STATE_DELETED;
                    updateTimersState(t, Timers.DELETE_TIMER);
                }
                break;
            case TimerObj.STATE_DONE:
@@ -901,6 +903,10 @@ public class TimerFragment extends DeskClockFragment
        CountingTimerView countingTimerView = (CountingTimerView)
                t.mView.findViewById(R.id.timer_time_text);
        TextView stop = (TextView) t.mView.findViewById(R.id.timer_stop);
        ImageButton delete = (ImageButton) t.mView.findViewById(R.id.timer_delete);
        // Make sure the delete button is visible in case the view is recycled.
        delete.setVisibility(View.VISIBLE);

        Resources r = a.getResources();
        switch (t.mState) {
            case TimerObj.STATE_RUNNING:
@@ -929,8 +935,11 @@ public class TimerFragment extends DeskClockFragment
                plusOne.setImageResource(R.drawable.ic_plusone);
                stop.setVisibility(View.VISIBLE);
                stop.setContentDescription(r.getString(R.string.timer_stop));
                stop.setText(R.string.timer_stop);
                // If the timer is deleted after use , show "done" instead of "stop" on the button
                // and hide the delete button since pressing done will delete the timer
                stop.setText(t.mDeleteAfterUse ? R.string.timer_done : R.string.timer_stop);
                stop.setTextColor(getResources().getColor(R.color.clock_white));
                delete.setVisibility(t.mDeleteAfterUse ? View.INVISIBLE : View.VISIBLE);
                countingTimerView.setVirtualButtonEnabled(true);
                break;
            case TimerObj.STATE_DONE: