savepoint to revert back to
This commit is contained in:
parent
a8f3fafafa
commit
249a2c76f9
@ -2,11 +2,11 @@ package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
@ -14,6 +14,8 @@ import java.util.Arrays;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 7/12/2016.
|
||||
@ -35,6 +37,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
@Bind({ R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
|
||||
R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine })
|
||||
Button[] mButtons;
|
||||
@Bind(R.id.backspace) ImageButton mBackspace;
|
||||
|
||||
/**
|
||||
* Informs clients how to output the digits inputted into this numpad.
|
||||
@ -68,12 +71,6 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
*/
|
||||
public abstract int capacity();
|
||||
|
||||
/**
|
||||
* @return the layout resource that defines the children for this numpad
|
||||
*/
|
||||
@LayoutRes
|
||||
protected abstract int contentLayout();
|
||||
|
||||
public final void setOnInputChangeListener(OnInputChangeListener onInputChangeListener) {
|
||||
mOnInputChangeListener = onInputChangeListener;
|
||||
}
|
||||
@ -95,6 +92,10 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
mButtons[i].setEnabled(i >= lowerLimitInclusive && i < upperLimitExclusive);
|
||||
}
|
||||
|
||||
protected final void setBackspaceEnabled(boolean enabled) {
|
||||
mBackspace.setEnabled(enabled);
|
||||
}
|
||||
|
||||
protected final int valueAt(int index) {
|
||||
return mInput[index];
|
||||
}
|
||||
@ -130,6 +131,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
return currentInput;
|
||||
}
|
||||
|
||||
@OnClick(R.id.backspace)
|
||||
public void delete() {
|
||||
/*
|
||||
if (mCount - 1 >= 0) {
|
||||
@ -150,6 +152,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
}
|
||||
}
|
||||
|
||||
@OnLongClick(R.id.backspace)
|
||||
public boolean clear() {
|
||||
Arrays.fill(mInput, UNMODIFIED);
|
||||
mCount = 0;
|
||||
@ -235,7 +238,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
|
||||
private void init() {
|
||||
setAlignmentMode(ALIGN_BOUNDS);
|
||||
setColumnCount(COLUMNS);
|
||||
View.inflate(getContext(), contentLayout(), this);
|
||||
View.inflate(getContext(), R.layout.content_grid_layout_numpad, this);
|
||||
ButterKnife.bind(this);
|
||||
for (Button b : mButtons)
|
||||
b.setOnClickListener(this);
|
||||
|
||||
@ -5,8 +5,8 @@ import android.support.annotation.IntDef;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
@ -15,10 +15,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.util.Calendar;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 7/12/2016.
|
||||
*/
|
||||
@ -49,10 +45,8 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
private int mAmPmState = UNSPECIFIED;
|
||||
private final StringBuilder mFormattedInput = new StringBuilder(MAX_CHARS);
|
||||
|
||||
@Bind({ R.id.leftAlt, R.id.rightAlt })
|
||||
Button[] mAltButtons;
|
||||
@Bind(R.id.fab) FloatingActionButton mFab;
|
||||
@Bind(R.id.backspace) ImageButton mBackspace;
|
||||
private Button[] mAltButtons;
|
||||
private FloatingActionButton mFab;
|
||||
|
||||
/**
|
||||
* Provides additional APIs to configure clients' display output.
|
||||
@ -80,11 +74,6 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
return MAX_DIGITS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int contentLayout() {
|
||||
return R.layout.content_numpad_time_picker;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable(int lowerLimitInclusive, int upperLimitExclusive) {
|
||||
super.enable(lowerLimitInclusive, upperLimitExclusive);
|
||||
@ -121,7 +110,6 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnClick(R.id.backspace)
|
||||
public void delete() {
|
||||
int len = mFormattedInput.length();
|
||||
if (!is24HourFormat() && mAmPmState != UNSPECIFIED) {
|
||||
@ -138,12 +126,6 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnLongClick(R.id.backspace)
|
||||
public boolean clear() {
|
||||
return super.clear();
|
||||
}
|
||||
|
||||
/** Returns the hour of day (0-23) regardless of clock system */
|
||||
@Override
|
||||
public int hourOfDay() {
|
||||
@ -247,7 +229,8 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
|
||||
mAmPmState = amPmState;
|
||||
if (mAmPmState != HRS_24) {
|
||||
onAltButtonClick(mAmPmState == AM ? mAltButtons[0] : mAltButtons[1]);
|
||||
// TODO: Verify this fires without performing any physical click.
|
||||
mAltButtonClickListener.onClick(mAmPmState == AM ? mAltButtons[0] : mAltButtons[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,6 +242,19 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
mFab.setOnClickListener(fabClickListener);
|
||||
}
|
||||
|
||||
public void setAltButtons(Button leftAlt, Button rightAlt) {
|
||||
// TODO: WeakReference?
|
||||
mAltButtons[0] = leftAlt;
|
||||
mAltButtons[1] = rightAlt;
|
||||
leftAlt.setOnClickListener(mAltButtonClickListener);
|
||||
rightAlt.setOnClickListener(mAltButtonClickListener);
|
||||
}
|
||||
|
||||
public void setFab(FloatingActionButton fab) {
|
||||
// TODO: WeakReference?
|
||||
mFab = fab;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (is24HourFormat()) {
|
||||
mAltButtons[0].setText(R.string.left_alt_24hr);
|
||||
@ -271,11 +267,14 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
updateNumpadStates();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.leftAlt, R.id.rightAlt })
|
||||
void onAltButtonClick(Button altBtn) {
|
||||
if (mAltButtons[0] != altBtn && mAltButtons[1] != altBtn)
|
||||
private OnClickListener mAltButtonClickListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mAltButtons[0] != view && mAltButtons[1] != view)
|
||||
throw new IllegalArgumentException("Not called with one of the alt buttons");
|
||||
|
||||
Button altBtn = (Button) view;
|
||||
|
||||
// Manually insert special characters for 12-hour clock
|
||||
if (!is24HourFormat()) {
|
||||
if (count() <= 2) {
|
||||
@ -285,8 +284,10 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
// text is AM or PM, so include space before
|
||||
mFormattedInput.append(' ').append(altBtn.getText());
|
||||
mAmPmState = mAltButtons[0] == altBtn ? AM : PM;
|
||||
// Digits will be shown for you on insert, but not AM/PM
|
||||
/*TOneverDO: remove super*/super.onDigitInserted(mFormattedInput.toString());
|
||||
// Digits will be shown for you on insert, but not AM/PM, so update.
|
||||
// "Qualified super" syntax, similar to qualified this.
|
||||
NumpadTimePicker.super/*TOneverDO: remove super*/
|
||||
.onDigitInserted(mFormattedInput.toString());
|
||||
} else {
|
||||
CharSequence text = altBtn.getText();
|
||||
int[] digits = new int[text.length() - 1];
|
||||
@ -305,6 +306,7 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
|
||||
updateNumpadStates();
|
||||
}
|
||||
};
|
||||
|
||||
private boolean is24HourFormat() {
|
||||
return DateFormat.is24HourFormat(getContext());
|
||||
@ -392,10 +394,12 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
||||
}
|
||||
|
||||
private void updateBackspaceState() {
|
||||
mBackspace.setEnabled(count() > 0);
|
||||
setBackspaceEnabled(count() > 0);
|
||||
}
|
||||
|
||||
private void updateAltButtonStates() {
|
||||
if (mAltButtons == null || mAltButtons[0] == null || mAltButtons[1] == null)
|
||||
return;
|
||||
if (count() == 0) {
|
||||
// No input, no access!
|
||||
mAltButtons[0].setEnabled(false);
|
||||
|
||||
@ -142,13 +142,6 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@OnClick(R.id.cancel)
|
||||
void cancel() {
|
||||
dismiss();
|
||||
}
|
||||
*/
|
||||
|
||||
private void updateInputText(String inputText) {
|
||||
TimeTextUtils.setText(inputText, mInputField);
|
||||
// Move the cursor
|
||||
|
||||
@ -51,4 +51,11 @@
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
grid:layout_column="1"
|
||||
android:text="0"/>
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/backspace"
|
||||
android:src="@drawable/ic_backspace_24dp"
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
grid:layout_column="2"/>
|
||||
</merge>
|
||||
@ -4,34 +4,4 @@
|
||||
|
||||
<include layout="@layout/content_grid_layout_numpad"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/leftAlt"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
app:layout_column="0"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/rightAlt"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
app:layout_column="2"/>
|
||||
|
||||
<!-- Used to properly position the FAB -->
|
||||
<FrameLayout
|
||||
android:layout_height="56dp"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_column="1">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_done_24dp"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/backspace"
|
||||
android:src="@drawable/ic_backspace_24dp"
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
app:layout_column="2"/>
|
||||
</merge>
|
||||
@ -1,6 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- TOneverDO: Use LinearLayout, because it doesn't obey LWM -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_vertical_space"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_vertical_space">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
@ -22,10 +31,52 @@
|
||||
<com.philliphsu.clock2.editalarm.NumpadTimePicker
|
||||
android:id="@+id/number_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/numpad_height"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_vertical_space"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_vertical_space"/>
|
||||
android:layout_height="@dimen/numpad_height"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/alt_buttons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/leftAlt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/GridLayoutNumpadButton"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/rightAlt"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_done_24dp"
|
||||
android:layout_gravity="center"
|
||||
app:layout_anchor="@id/alt_buttons"
|
||||
app:layout_anchorGravity="center"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
Loading…
Reference in New Issue
Block a user