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

Commit d7c19ebe authored by Nicolai Ehemann's avatar Nicolai Ehemann Committed by Gerrit Code Review
Browse files

DeskClock: Add '00' and '30' buttons to timer setup; disable not currently applicable buttons

Change-Id: Ia96412e0036a4196f6ae80b4f4350430f4fdf334
parent a675845b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@
    <include layout="@layout/three_keys_view"
        android:id="@+id/third"/>

    <include layout="@layout/three_keys_view"
    <include layout="@layout/three_keys_view_ampm"
        android:id="@+id/fourth" />

    <View
+68 −18
Original line number Diff line number Diff line
@@ -86,13 +86,16 @@ public class TimerSetupView extends LinearLayout implements Button.OnClickListen
        mLeft = (Button)v4.findViewById(R.id.key_left);
        mNumbers[0] = (Button)v4.findViewById(R.id.key_middle);
        mRight = (Button)v4.findViewById(R.id.key_right);
        setLeftRightEnabled(false);

        for (int i = 0; i < 10; i++) {
            mNumbers[i].setOnClickListener(this);
            mNumbers [i].setText(String.format("%d",i));
            mNumbers [i].setTag(R.id.numbers_key,new Integer(i));
        }
        mLeft.setOnClickListener(this);
        mLeft.setText("00");
        mRight.setOnClickListener(this);
        mRight.setText("30");
        updateTime();
    }

@@ -114,11 +117,56 @@ public class TimerSetupView extends LinearLayout implements Button.OnClickListen
        }
    }

    public void updateZeroButton() {
        boolean enabled = (mInputPointer != -1 && mInputPointer != 4);
        if (mNumbers[0] != null) {
            mNumbers[0].setEnabled(enabled);
        }
    }

    public void updateDoubleZeroButton() {
        boolean enabled = (mInputPointer != -1 && mInputPointer < 3);
        if (mLeft != null) {
            mLeft.setEnabled(enabled);
        }
    }
    public void updateThirtyButton() {
        boolean enabled = mInputPointer < 3;
        if (mRight != null) {
            mRight.setEnabled(enabled);
        }
    }

    public void updateNumberButtons() {
        boolean enabled = mInputPointer != 4;
        for (int i = 1; i < 10; i++) {
            if (mNumbers[i] != null) {
                mNumbers[i].setEnabled(enabled);
            }
        }
    }

    public void updateButtons() {
        updateStartButton();
        updateDeleteButton();
        updateNumberButtons();
        updateZeroButton();
        updateDoubleZeroButton();
        updateThirtyButton();
    }

    @Override
    public void onClick(View v) {
        doOnClick(v);
        updateStartButton();
        updateDeleteButton();
        updateButtons();
    }

    protected void addDigit(Integer digit) {
        for (int i = mInputPointer; i >= 0; i--) {
            mInput[i+1] = mInput[i];
        }
        mInputPointer++;
        mInput [0] = digit;
    }

    protected void doOnClick(View v) {
@@ -131,11 +179,23 @@ public class TimerSetupView extends LinearLayout implements Button.OnClickListen
                return;
            }
            if (mInputPointer < mInputSize - 1) {
                for (int i = mInputPointer; i >= 0; i--) {
                    mInput[i+1] = mInput[i];
                addDigit(val);
                updateTime();
            }
                mInputPointer++;
                mInput [0] = val;
            return;
        }
        if (v == mLeft || v == mRight) {
            //pressing "00" as the first does nothing
            if (mInputPointer == -1 && v == mLeft) {
                return;
            }
            if (mInputPointer < mInputSize -2) {
                if (v == mLeft) {
                    addDigit(0);
                } else {
                    addDigit(3);
                }
                addDigit(0);
                updateTime();
            }
            return;
@@ -158,8 +218,7 @@ public class TimerSetupView extends LinearLayout implements Button.OnClickListen
    public boolean onLongClick(View v) {
        if (v == mDelete) {
            reset();
            updateStartButton();
            updateDeleteButton();
            updateButtons();
            return true;
        }
        return false;
@@ -198,13 +257,4 @@ public class TimerSetupView extends LinearLayout implements Button.OnClickListen
            updateTime();
        }
    }

    protected void setLeftRightEnabled(boolean enabled) {
        mLeft.setEnabled(enabled);
        mRight.setEnabled(enabled);
        if (!enabled) {
            mLeft.setContentDescription(null);
            mRight.setContentDescription(null);
        }
    }
}
+8 −9
Original line number Diff line number Diff line
@@ -665,8 +665,7 @@ public class TimerFragment extends DeskClockFragment
            mSeperator.setVisibility(View.VISIBLE);
            mCancel.setVisibility(View.VISIBLE);
        }
        mTimerSetup.updateStartButton();
        mTimerSetup.updateDeleteButton();
        mTimerSetup.updateButtons();
        mLastVisibleView = mNewTimerPage;
    }
    private void gotoTimersView() {