Number buttons clickable
This commit is contained in:
parent
16dc0b94d7
commit
2ef36ea05f
@ -18,7 +18,6 @@ package com.philliphsu.clock2.editalarm;
|
|||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.app.ActionBar.LayoutParams;
|
import android.app.ActionBar.LayoutParams;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.GridLayout;
|
import android.support.v7.widget.GridLayout;
|
||||||
@ -142,7 +141,7 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
return R.layout.dialog_time_picker_number_grid;
|
return R.layout.dialog_time_picker_number_grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTextsOnChildViews() {
|
private void setNumberTexts() {
|
||||||
if (mCurrentIndex != HOUR_INDEX && mCurrentIndex != MINUTE_INDEX) {
|
if (mCurrentIndex != HOUR_INDEX && mCurrentIndex != MINUTE_INDEX) {
|
||||||
Log.e(TAG, "TimePicker does not support view at index "+mCurrentIndex);
|
Log.e(TAG, "TimePicker does not support view at index "+mCurrentIndex);
|
||||||
return;
|
return;
|
||||||
@ -152,23 +151,25 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
for (int i = 0; i < mGridLayout.getChildCount(); i++) {
|
for (int i = 0; i < mGridLayout.getChildCount(); i++) {
|
||||||
View v = mGridLayout.getChildAt(i);
|
View v = mGridLayout.getChildAt(i);
|
||||||
if (mCurrentIndex == MINUTE_INDEX || mCurrentIndex == HOUR_INDEX && !mIs24HourMode) {
|
if (mCurrentIndex == MINUTE_INDEX || mCurrentIndex == HOUR_INDEX && !mIs24HourMode) {
|
||||||
|
if (!(v instanceof TextView))
|
||||||
|
return; // Reached the ImageButtons
|
||||||
TextView tv = (TextView) v;
|
TextView tv = (TextView) v;
|
||||||
tv.setText(mCurrentIndex == MINUTE_INDEX
|
tv.setText(mCurrentIndex == MINUTE_INDEX
|
||||||
? String.format("%02d", MINUTES[i])
|
? String.format("%02d", MINUTES[i])
|
||||||
: String.valueOf(HOURS_12[i]));
|
: String.valueOf(HOURS_12[i]));
|
||||||
} else if (mCurrentIndex == HOUR_INDEX && mIs24HourMode) {
|
} else if (mCurrentIndex == HOUR_INDEX && mIs24HourMode) {
|
||||||
TwentyFourHourGridItem item = (TwentyFourHourGridItem) v;
|
TwentyFourHourGridItem item = (TwentyFourHourGridItem) v;
|
||||||
String s1 = String.format("%02d", HOURS_24_HALF_DAY_1[i]);
|
String s1 = String.format("%02d", HOURS_24_HALF_DAY_1[i]);
|
||||||
String s2 = String.valueOf(HOURS_24_HALF_DAY_2[i]);
|
String s2 = String.valueOf(HOURS_24_HALF_DAY_2[i]);
|
||||||
if (mSelectedHalfDay == HALF_DAY_1) {
|
if (mSelectedHalfDay == HALF_DAY_1) {
|
||||||
item.setPrimaryText(s1);
|
item.setPrimaryText(s1);
|
||||||
item.setSecondaryText(s2);
|
item.setSecondaryText(s2);
|
||||||
} else if (mSelectedHalfDay == HALF_DAY_2) {
|
} else if (mSelectedHalfDay == HALF_DAY_2) {
|
||||||
item.setPrimaryText(s2);
|
item.setPrimaryText(s2);
|
||||||
item.setSecondaryText(s1);
|
item.setSecondaryText(s1);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "mSelectedHalfDay = " + mSelectedHalfDay + "?");
|
Log.e(TAG, "mSelectedHalfDay = " + mSelectedHalfDay + "?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,14 +191,19 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
mGridLayout.removeAllViews();
|
mGridLayout.removeAllViews();
|
||||||
int layout = index == HOUR_INDEX ? R.layout.content_24h_number_grid : R.layout.content_number_grid;
|
int layout = index == HOUR_INDEX ? R.layout.content_24h_number_grid : R.layout.content_number_grid;
|
||||||
View.inflate(getActivity(), layout, mGridLayout);
|
View.inflate(getActivity(), layout, mGridLayout);
|
||||||
setTextsOnChildViews(); // TOneverDO: call after inflating minute tuner buttons
|
|
||||||
|
// TOneverDO: call after inflating minute tuner buttons
|
||||||
|
setNumberTexts();
|
||||||
|
setClickListenersOnButtons();
|
||||||
|
//end TOneverDO
|
||||||
} else {
|
} else {
|
||||||
if (index == HOUR_INDEX) {
|
if (index == HOUR_INDEX) {
|
||||||
// Remove the minute tuners
|
// Remove the minute tuners
|
||||||
mGridLayout.removeViews(mGridLayout.getChildCount() - 2, 2);
|
mGridLayout.removeViews(mGridLayout.getChildCount() - 2, 2);
|
||||||
}
|
}
|
||||||
// We can reuse the existing child Views, just change the texts.
|
// We can reuse the existing child Views, just change the texts.
|
||||||
setTextsOnChildViews();
|
// They already have the click listener set.
|
||||||
|
setNumberTexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == MINUTE_INDEX) {
|
if (index == MINUTE_INDEX) {
|
||||||
@ -206,6 +212,29 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setClickListenersOnButtons() {
|
||||||
|
for (int i = 0; i < mGridLayout.getChildCount(); i++) {
|
||||||
|
// TODO: Consider leaving out the minute tuner buttons
|
||||||
|
mGridLayout.getChildAt(i).setOnClickListener(mOnNumberClickListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final OnClickListener mOnNumberClickListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
String number;
|
||||||
|
if (v instanceof TextView) {
|
||||||
|
number = ((TextView) v).getText().toString();
|
||||||
|
} else if (v instanceof TwentyFourHourGridItem) {
|
||||||
|
number = ((TwentyFourHourGridItem) v).getPrimaryText().toString();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "TimePicker does not support button type " + v.getClass().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onValueSelected(mCurrentIndex, Integer.parseInt(number), true);
|
||||||
|
}
|
||||||
|
};
|
||||||
// =============================================================================================
|
// =============================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,10 +260,10 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
// Empty constructor required for dialog fragment.
|
// Empty constructor required for dialog fragment.
|
||||||
}
|
}
|
||||||
|
|
||||||
public NumberGridTimePickerDialogV2(Context context, int theme, OnTimeSetListener callback,
|
// public NumberGridTimePickerDialogV2(Context context, int theme, OnTimeSetListener callback,
|
||||||
int hourOfDay, int minute, boolean is24HourMode) {
|
// int hourOfDay, int minute, boolean is24HourMode) {
|
||||||
// Empty constructor required for dialog fragment.
|
// // Empty constructor required for dialog fragment.
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static NumberGridTimePickerDialogV2 newInstance(OnTimeSetListener callback,
|
public static NumberGridTimePickerDialogV2 newInstance(OnTimeSetListener callback,
|
||||||
int hourOfDay, int minute, boolean is24HourMode) {
|
int hourOfDay, int minute, boolean is24HourMode) {
|
||||||
@ -309,18 +338,18 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
//TODO: Delete getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
// getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
// View view = inflater.inflate(R.layout.time_picker_dialog, null);
|
// View view = inflater.inflate(R.layout.time_picker_dialog, null);
|
||||||
// KeyboardListener keyboardListener = new KeyboardListener();
|
// KeyboardListener keyboardListener = new KeyboardListener();
|
||||||
// view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);
|
// view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);
|
||||||
|
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
// Inflate the child views into the grid
|
// Inflate the buttons into the grid
|
||||||
View.inflate(getActivity(),
|
int layout = mIs24HourMode ? R.layout.content_24h_number_grid : R.layout.content_number_grid;
|
||||||
mIs24HourMode ? R.layout.content_24h_number_grid : R.layout.content_number_grid,
|
View.inflate(getActivity(), layout, mGridLayout);
|
||||||
mGridLayout);
|
setNumberTexts();
|
||||||
setTextsOnChildViews();
|
setClickListenersOnButtons();
|
||||||
|
|
||||||
if (mCurrentIndex == MINUTE_INDEX) {
|
if (mCurrentIndex == MINUTE_INDEX) {
|
||||||
// Add the minute tuner buttons as well
|
// Add the minute tuner buttons as well
|
||||||
@ -523,30 +552,30 @@ public class NumberGridTimePickerDialogV2 extends BaseTimePickerDialog /*DialogF
|
|||||||
// * Called by the picker for updating the header display.
|
// * Called by the picker for updating the header display.
|
||||||
// */
|
// */
|
||||||
// @Override
|
// @Override
|
||||||
// public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) {
|
public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) {
|
||||||
// if (pickerIndex == HOUR_INDEX) {
|
if (pickerIndex == HOUR_INDEX) {
|
||||||
// setHour(newValue, false);
|
setHour(newValue, false);
|
||||||
// String announcement = String.format("%d", newValue);
|
String announcement = String.format("%d", newValue);
|
||||||
// if (mAllowAutoAdvance && autoAdvance) {
|
if (mAllowAutoAdvance && autoAdvance) {
|
||||||
// setCurrentItemShowing(MINUTE_INDEX, true, true, false);
|
setCurrentItemShowing(MINUTE_INDEX, true, true, false);
|
||||||
// announcement += ". " + mSelectMinutes;
|
announcement += ". " + mSelectMinutes;
|
||||||
// } else {
|
} else {
|
||||||
// mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue);
|
// mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// Utils.tryAccessibilityAnnounce(mTimePicker, announcement);
|
// Utils.tryAccessibilityAnnounce(mTimePicker, announcement);
|
||||||
// } else if (pickerIndex == MINUTE_INDEX){
|
} else if (pickerIndex == MINUTE_INDEX){
|
||||||
// setMinute(newValue);
|
setMinute(newValue);
|
||||||
// mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue);
|
// mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue);
|
||||||
// } else if (pickerIndex == AMPM_INDEX) {
|
} else if (pickerIndex == AMPM_INDEX) {
|
||||||
// updateAmPmDisplay(newValue);
|
updateAmPmDisplay(newValue);
|
||||||
// } else if (pickerIndex == ENABLE_PICKER_INDEX) {
|
} else if (pickerIndex == ENABLE_PICKER_INDEX) {
|
||||||
// if (!isTypedTimeFullyLegal()) {
|
if (!isTypedTimeFullyLegal()) {
|
||||||
// mTypedTimes.clear();
|
mTypedTimes.clear();
|
||||||
// }
|
}
|
||||||
// finishKbMode(true);
|
// finishKbMode(true);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
private void setHour(int value, boolean announce) {
|
private void setHour(int value, boolean announce) {
|
||||||
String format;
|
String format;
|
||||||
|
|||||||
@ -38,10 +38,18 @@ public class TwentyFourHourGridItem extends LinearLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CharSequence getPrimaryText() {
|
||||||
|
return mPrimaryText.getText();
|
||||||
|
}
|
||||||
|
|
||||||
public void setPrimaryText(CharSequence text) {
|
public void setPrimaryText(CharSequence text) {
|
||||||
mPrimaryText.setText(text);
|
mPrimaryText.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CharSequence getSecondaryText() {
|
||||||
|
return mSecondaryText.getText();
|
||||||
|
}
|
||||||
|
|
||||||
public void setSecondaryText(CharSequence text) {
|
public void setSecondaryText(CharSequence text) {
|
||||||
mSecondaryText.setText(text);
|
mSecondaryText.setText(text);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<!-- TODO: Use fixed width and height -->
|
<!-- TODO: Use fixed width and height -->
|
||||||
<!-- TODO: Add these views to the number grid-->
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user