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

Commit e55413e9 authored by Robyn Coultas's avatar Robyn Coultas
Browse files

timer cleanup

This change ensures the buttons are visible at the right times and
overloads return values from BaseAdapter to simplify the code.
(This cleanup was once part of c/255295 which was abandonded.)

Change-Id: Ic35e70d4045e28c74f30e156975151fde5c57a9f
parent ce9b1067
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class TimerFragment extends DeskClockFragment
        }

        @Override
        public Object getItem(int p) {
        public TimerObj getItem(int p) {
            return mTimers.get(p);
        }

@@ -358,10 +358,10 @@ public class TimerFragment extends DeskClockFragment
            boolean toggle = mVisible != visible;
            mVisible = visible;
            for (int i = 0; i < mAdapter.getCount(); i ++) {
                TimerObj t = (TimerObj) mAdapter.getItem(i);
                TimerObj t = mAdapter.getItem(i);
                if (t.mState == TimerObj.STATE_RUNNING || t.mState == TimerObj.STATE_TIMESUP) {
                    long timeLeft = t.updateTimeLeft(false);
                    if ((TimerListItem)(t.mView) != null) {
                    if (t.mView != null) {
                        ((TimerListItem)(t.mView)).setTime(timeLeft, false);
                    }
                }
@@ -369,13 +369,13 @@ public class TimerFragment extends DeskClockFragment
                        && t.mState != TimerObj.STATE_RESTART) {
                    t.mState = TimerObj.STATE_TIMESUP;
                    TimerFragment.this.setTimerButtons(t);
                    if ((TimerListItem)(t.mView) != null) {
                    if (t.mView != null) {
                        ((TimerListItem)(t.mView)).timesUp();
                    }
                }

                // The blinking
                if (toggle && (TimerListItem)(t.mView) != null) {
                if (toggle && t.mView != null) {
                    if (t.mState == TimerObj.STATE_TIMESUP) {
                        ((TimerListItem)(t.mView)).setCircleBlink(mVisible);
                    }
@@ -614,7 +614,7 @@ public class TimerFragment extends DeskClockFragment
        // then removed them one by one
        LinkedList<TimerObj> timesupTimers = new LinkedList<TimerObj>();
        for (int i = 0; i  < mAdapter.getCount(); i ++) {
            TimerObj timerObj = (TimerObj) mAdapter.getItem(i);
            TimerObj timerObj = mAdapter.getItem(i);
            if (timerObj.mState == TimerObj.STATE_TIMESUP) {
                timesupTimers.addFirst(timerObj);
                notifyChange = true;
@@ -852,10 +852,9 @@ public class TimerFragment extends DeskClockFragment
    }

    public void setLabel(TimerObj timer, String label) {
        ((TimerObj) mAdapter.getItem(
                mAdapter.findTimerPositionById(timer.mTimerId))).mLabel = label;
        mAdapter.getItem(mAdapter.findTimerPositionById(timer.mTimerId)).mLabel = label;
        if (timer.mState == TimerObj.STATE_TIMESUP) {
            // Timer is in timesup mode.
            // Timer is in times-up mode.
            TimerReceiver.showExpiredAlarmNotification(
                    getActivity().getApplicationContext(), timer);
        }
@@ -877,6 +876,7 @@ public class TimerFragment extends DeskClockFragment
                plusOne.setVisibility(View.VISIBLE);
                plusOne.setContentDescription(r.getString(R.string.timer_plus_one));
                plusOne.setImageResource(R.drawable.ic_plusone);
                stop.setVisibility(View.VISIBLE);
                stop.setContentDescription(r.getString(R.string.timer_stop));
                stop.setText(R.string.timer_stop);
                stop.setTextColor(getResources().getColor(R.color.clock_white));
@@ -886,6 +886,7 @@ public class TimerFragment extends DeskClockFragment
                plusOne.setVisibility(View.VISIBLE);
                plusOne.setContentDescription(r.getString(R.string.timer_reset));
                plusOne.setImageResource(R.drawable.ic_reset);
                stop.setVisibility(View.VISIBLE);
                stop.setContentDescription(r.getString(R.string.timer_start));
                stop.setText(R.string.timer_start);
                stop.setTextColor(getResources().getColor(R.color.clock_white));
@@ -893,8 +894,11 @@ public class TimerFragment extends DeskClockFragment
                break;
            case TimerObj.STATE_TIMESUP:
                plusOne.setVisibility(View.VISIBLE);
                plusOne.setContentDescription(r.getString(R.string.timer_plus_one));
                plusOne.setImageResource(R.drawable.ic_plusone);
                stop.setVisibility(View.VISIBLE);
                stop.setContentDescription(r.getString(R.string.timer_stop));
                stop.setText(R.string.timer_stop);
                stop.setTextColor(getResources().getColor(R.color.clock_white));
                countingTimerView.setVirtualButtonEnabled(true);
                break;
+8 −5
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.deskclock.timer;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageButton;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.android.deskclock.CircleTimerView;
@@ -73,6 +73,8 @@ public class TimerListItem extends LinearLayout {
    public void pause() {
        mCircleView.pauseIntervalAnimation();
        mTimerText.redTimeStr(false, true);
        mTimerText.showTime(true);
        mCircleView.setVisibility(VISIBLE);
    }

    public void stop() {
@@ -118,10 +120,11 @@ public class TimerListItem extends LinearLayout {
    // Used by animator to animate the size of a timer
    @SuppressWarnings("unused")
    public void setAnimatedHeight(int height) {
        getLayoutParams().height = height;
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams != null) {
            layoutParams.height = height;
            requestLayout();
        }


    }

}