Created NumberGrid time picker
This commit is contained in:
@@ -321,7 +321,8 @@ public class EditAlarmActivity extends BaseActivity implements
|
||||
// If we keep a reference to the dialog, we keep its previous state as well.
|
||||
// So the next time we call show() on it, the input field will show the
|
||||
// last inputted time.
|
||||
NumpadTimePickerDialog.newInstance(this).show(getSupportFragmentManager(), TAG_TIME_PICKER);
|
||||
// NumpadTimePickerDialog.newInstance(this).show(getSupportFragmentManager(), TAG_TIME_PICKER);
|
||||
NumberGridTimePickerDialog.newInstance().show(getSupportFragmentManager(), TAG_TIME_PICKER);
|
||||
}
|
||||
|
||||
private void setWeekDaysText() {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 7/21/2016.
|
||||
*/
|
||||
public class NumberGrid extends GridLayout {
|
||||
private static final String TAG = "NumberGrid";
|
||||
private static final int COLUMNS = 3;
|
||||
|
||||
// private CircularIndicatorSetter mIndicatorSetter;
|
||||
private OnNumberSelectedListener mSelectionListener;
|
||||
// TODO: Since we plan to dynamically clear and inflate children into this
|
||||
// parent to represent "pages", this seems useless? Since each page has at
|
||||
// most one selection, and at any given time, this GridLayout can only show
|
||||
// one page at a time. Instead, when the onNumberSelected() is fired, the
|
||||
// hosting dialog should keep a reference to the returned number. It is up
|
||||
// to the dialog to deduce what time field the number represents, probably
|
||||
// with an int flag that indicates what "page" this GridLayout is displaying.
|
||||
private int mSelection;
|
||||
|
||||
public interface OnNumberSelectedListener {
|
||||
void onNumberSelected(int number);
|
||||
}
|
||||
|
||||
public NumberGrid(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public NumberGrid(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setOnNumberSelectedListener(OnNumberSelectedListener onNumberSelectedListener) {
|
||||
mSelectionListener = onNumberSelectedListener;
|
||||
}
|
||||
|
||||
// /*package*/ void setTheme(Context context, boolean themeDark) {
|
||||
// for (int i = 0; i < getChildCount(); i++) {
|
||||
// View view = getChildAt(i);
|
||||
// if (view instanceof TextViewWithCircularIndicator) {
|
||||
// TextViewWithCircularIndicator text = (TextViewWithCircularIndicator) getChildAt(i);
|
||||
// text.setTheme(context, themeDark);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public int getSelection() {
|
||||
return mSelection;
|
||||
}
|
||||
|
||||
public void setSelection(int value) {
|
||||
mSelection = value;
|
||||
// for (int i = 0; i < getChildCount(); i++) {
|
||||
// View v = getChildAt(i);
|
||||
// if (v instanceof TextViewWithCircularIndicator) {
|
||||
// TextViewWithCircularIndicator text = (TextViewWithCircularIndicator) v;
|
||||
// // parseInt() strips out leading zeroes
|
||||
// int num = Integer.parseInt(text.getText().toString());
|
||||
// if (value == num) {
|
||||
// mIndicatorSetter.setIndicator(text);
|
||||
// break;
|
||||
// }
|
||||
// } else {
|
||||
// // We have reached a non-numeric button, i.e. the minute tuners, unless you have
|
||||
// // other non-numeric buttons as well. This means we iterated through all numeric
|
||||
// // buttons, but this value is not one of the preset values.
|
||||
// // Clear the indicator from the default selection.
|
||||
// mIndicatorSetter.setIndicator(null);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Final because this is implemented for the grid of numbers. If subclasses need their own
|
||||
* click listeners for non-numeric buttons, they should set new OnClickListeners on those buttons.
|
||||
*/
|
||||
// @Override
|
||||
// public final void onClick(View v) {
|
||||
// TextViewWithCircularIndicator view = (TextViewWithCircularIndicator) v;
|
||||
// String text = view.getText().toString();
|
||||
// int number = Integer.parseInt(text);
|
||||
// mSelection = number;
|
||||
// fireOnNumberSelectedEvent(number);
|
||||
// mIndicatorSetter.setIndicator(view);
|
||||
// }
|
||||
|
||||
protected void fireOnNumberSelectedEvent(int number) {
|
||||
if (mSelectionListener != null)
|
||||
mSelectionListener.onNumberSelected(number);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// setAlignmentMode(ALIGN_BOUNDS);
|
||||
setColumnCount(COLUMNS);
|
||||
// When we initialize, display the hour values "page".
|
||||
int layout = DateFormat.is24HourFormat(getContext())
|
||||
? R.layout.content_24h_number_grid
|
||||
: R.layout.content_12h_number_grid;
|
||||
inflate(getContext(), layout, this);
|
||||
// ButterKnife.bind(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 7/21/2016.
|
||||
*
|
||||
* AppCompat-themed AlertDialog.
|
||||
*/
|
||||
public class NumberGridTimePickerDialog extends DialogFragment {
|
||||
|
||||
public static NumberGridTimePickerDialog newInstance() {
|
||||
return new NumberGridTimePickerDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
// Use an AlertDialog to display footer buttons, rather than
|
||||
// re-invent them in our layout.
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setView(R.layout.dialog_time_picker_number_grid)
|
||||
// The action strings are already defined and localized by the system!
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
// return super.onCreateDialog(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 7/21/2016.
|
||||
*/
|
||||
public class TwentyFourHourGridItem extends LinearLayout {
|
||||
|
||||
@Bind(R.id.primary) TextView mPrimaryText;
|
||||
@Bind(R.id.secondary) TextView mSecondaryText;
|
||||
|
||||
public TwentyFourHourGridItem(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public TwentyFourHourGridItem(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
|
||||
R.styleable.TwentyFourHourGridItem, 0, 0);
|
||||
try {
|
||||
setPrimaryText(a.getString(R.styleable.TwentyFourHourGridItem_primaryText));
|
||||
setSecondaryText(a.getString(R.styleable.TwentyFourHourGridItem_secondaryText));
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrimaryText(CharSequence text) {
|
||||
mPrimaryText.setText(text);
|
||||
}
|
||||
|
||||
public void setSecondaryText(CharSequence text) {
|
||||
mSecondaryText.setText(text);
|
||||
}
|
||||
|
||||
public void swapTexts() {
|
||||
CharSequence primary = mPrimaryText.getText();
|
||||
setPrimaryText(mSecondaryText.getText());
|
||||
setSecondaryText(primary);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setOrientation(VERTICAL);
|
||||
setGravity(Gravity.CENTER);
|
||||
inflate(getContext(), R.layout.element_24h_number_grid, this);
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user