Replaced all stray RelativeSizeSpans with usages of TimeTextUtils
This commit is contained in:
parent
ec3a75f8d2
commit
abd2d55aa9
@ -2,10 +2,7 @@ package com.philliphsu.clock2.alarms;
|
|||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.text.style.RelativeSizeSpan;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -17,6 +14,7 @@ import com.philliphsu.clock2.BaseViewHolder;
|
|||||||
import com.philliphsu.clock2.DaysOfWeek;
|
import com.philliphsu.clock2.DaysOfWeek;
|
||||||
import com.philliphsu.clock2.OnListItemInteractionListener;
|
import com.philliphsu.clock2.OnListItemInteractionListener;
|
||||||
import com.philliphsu.clock2.R;
|
import com.philliphsu.clock2.R;
|
||||||
|
import com.philliphsu.clock2.editalarm.TimeTextUtils;
|
||||||
import com.philliphsu.clock2.model.AlarmsRepository;
|
import com.philliphsu.clock2.model.AlarmsRepository;
|
||||||
import com.philliphsu.clock2.util.AlarmController;
|
import com.philliphsu.clock2.util.AlarmController;
|
||||||
import com.philliphsu.clock2.util.AlarmUtils;
|
import com.philliphsu.clock2.util.AlarmUtils;
|
||||||
@ -37,8 +35,6 @@ import static com.philliphsu.clock2.util.DateFormatUtils.formatTime;
|
|||||||
* Created by Phillip Hsu on 5/31/2016.
|
* Created by Phillip Hsu on 5/31/2016.
|
||||||
*/
|
*/
|
||||||
public class AlarmViewHolder extends BaseViewHolder<Alarm> implements AlarmCountdown.OnTickListener {
|
public class AlarmViewHolder extends BaseViewHolder<Alarm> implements AlarmCountdown.OnTickListener {
|
||||||
private static final RelativeSizeSpan AMPM_SIZE_SPAN = new RelativeSizeSpan(0.5f);
|
|
||||||
|
|
||||||
private final AlarmController mAlarmController;
|
private final AlarmController mAlarmController;
|
||||||
|
|
||||||
@Bind(R.id.time) TextView mTime;
|
@Bind(R.id.time) TextView mTime;
|
||||||
@ -154,10 +150,7 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> implements AlarmCount
|
|||||||
if (DateFormat.is24HourFormat(getContext())) {
|
if (DateFormat.is24HourFormat(getContext())) {
|
||||||
mTime.setText(time);
|
mTime.setText(time);
|
||||||
} else {
|
} else {
|
||||||
// No way around having to construct this on binding
|
TimeTextUtils.setText(time, mTime);
|
||||||
SpannableString s = new SpannableString(time);
|
|
||||||
s.setSpan(AMPM_SIZE_SPAN, time.indexOf(" "), time.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
mTime.setText(s, TextView.BufferType.SPANNABLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,7 @@ import android.support.v4.app.LoaderManager;
|
|||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.text.style.RelativeSizeSpan;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -68,11 +65,11 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
LoaderManager.LoaderCallbacks<Alarm>,
|
LoaderManager.LoaderCallbacks<Alarm>,
|
||||||
NumpadTimePicker.OnTimeSetListener {
|
NumpadTimePicker.OnTimeSetListener {
|
||||||
private static final String TAG = "EditAlarmActivity";
|
private static final String TAG = "EditAlarmActivity";
|
||||||
|
private static final String TAG_TIME_PICKER = "time_picker";
|
||||||
|
|
||||||
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
||||||
public static final String EXTRA_MODIFIED_ALARM = "com.philliphsu.clock2.editalarm.extra.MODIFIED_ALARM";
|
public static final String EXTRA_MODIFIED_ALARM = "com.philliphsu.clock2.editalarm.extra.MODIFIED_ALARM";
|
||||||
public static final String EXTRA_IS_DELETING = "com.philliphsu.clock2.editalarm.extra.IS_DELETING";
|
public static final String EXTRA_IS_DELETING = "com.philliphsu.clock2.editalarm.extra.IS_DELETING";
|
||||||
private static final RelativeSizeSpan AMPM_SIZE_SPAN = new RelativeSizeSpan(0.5f);
|
|
||||||
private static final String TAG_TIME_PICKER = "time_picker";
|
|
||||||
|
|
||||||
private static final String KEY_INPUT_TIME = "input_time";
|
private static final String KEY_INPUT_TIME = "input_time";
|
||||||
private static final String KEY_ENABLED = "enabled";
|
private static final String KEY_ENABLED = "enabled";
|
||||||
@ -87,8 +84,8 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
private long mOldAlarmId;
|
private long mOldAlarmId;
|
||||||
private Uri mSelectedRingtoneUri;
|
private Uri mSelectedRingtoneUri;
|
||||||
private Alarm mOldAlarm;
|
private Alarm mOldAlarm;
|
||||||
private int mSelectedHourOfDay = -1;
|
private int mSelectedHourOfDay;
|
||||||
private int mSelctedMinute = -1;
|
private int mSelectedMinute;
|
||||||
|
|
||||||
// If we keep a reference to the dialog, we keep its previous state as well.
|
// If we keep a reference to the dialog, we keep its previous state as well.
|
||||||
// So the next time we call show() on this, the input field will show the
|
// So the next time we call show() on this, the input field will show the
|
||||||
@ -106,12 +103,12 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
@Bind(R.id.label) EditText mLabel;
|
@Bind(R.id.label) EditText mLabel;
|
||||||
@Bind(R.id.ringtone) Button mRingtone;
|
@Bind(R.id.ringtone) Button mRingtone;
|
||||||
@Bind(R.id.vibrate) CheckBox mVibrate;
|
@Bind(R.id.vibrate) CheckBox mVibrate;
|
||||||
@Bind(R.id.numpad) AlarmNumpad mNumpad;
|
@Deprecated @Bind(R.id.numpad) AlarmNumpad mNumpad;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) {
|
public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) {
|
||||||
mSelectedHourOfDay = hourOfDay;
|
mSelectedHourOfDay = hourOfDay;
|
||||||
mSelctedMinute = minute;
|
mSelectedMinute = minute;
|
||||||
showTimeText(DateFormatUtils.formatTime(this, hourOfDay, minute));
|
showTimeText(DateFormatUtils.formatTime(this, hourOfDay, minute));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +117,8 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setWeekDaysText();
|
setWeekDaysText();
|
||||||
|
|
||||||
// Are we recreating this Activity because of a rotation? If so, try finding
|
// Are we recreating this Activity because of a rotation?
|
||||||
// the time picker in our backstack.
|
// If so, try finding the time picker in our backstack.
|
||||||
NumpadTimePickerDialog picker = (NumpadTimePickerDialog)
|
NumpadTimePickerDialog picker = (NumpadTimePickerDialog)
|
||||||
getSupportFragmentManager().findFragmentByTag(TAG_TIME_PICKER);
|
getSupportFragmentManager().findFragmentByTag(TAG_TIME_PICKER);
|
||||||
if (picker != null) {
|
if (picker != null) {
|
||||||
@ -329,20 +326,9 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
|
|
||||||
@OnClick(R.id.save)
|
@OnClick(R.id.save)
|
||||||
void save() {
|
void save() {
|
||||||
int hour;
|
|
||||||
int minutes;
|
|
||||||
try {
|
|
||||||
// TODO: Privatize accessor methods
|
|
||||||
hour = getHour();
|
|
||||||
minutes = getMinutes();
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
Log.e(TAG, e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Alarm alarm = Alarm.builder()
|
Alarm alarm = Alarm.builder()
|
||||||
.hour(hour)
|
.hour(mSelectedHourOfDay)
|
||||||
.minutes(minutes)
|
.minutes(mSelectedMinute)
|
||||||
.ringtone(getRingtone())
|
.ringtone(getRingtone())
|
||||||
.label(getLabel())
|
.label(getLabel())
|
||||||
.vibrates(vibrates())
|
.vibrates(vibrates())
|
||||||
@ -577,32 +563,21 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void setTimeTextHint() {
|
public void setTimeTextHint() {
|
||||||
if (DateFormat.is24HourFormat(this)) {
|
if (DateFormat.is24HourFormat(this)) {
|
||||||
mTimeText.setHint(R.string.default_alarm_time_24h);
|
mTimeText.setText(R.string.default_alarm_time_24h);
|
||||||
} else {
|
} else {
|
||||||
SpannableString s = new SpannableString(getString(R.string.default_alarm_time_12h));
|
showTimeText(getString(R.string.default_alarm_time_12h));
|
||||||
// Since we know the string's contents, we can pass in a hardcoded range
|
|
||||||
s.setSpan(AMPM_SIZE_SPAN, 5, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
mTimeText.setHint(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showTimeText(String formattedInput) {
|
public void showTimeText(String formattedInput) {
|
||||||
if (formattedInput.contains("AM") || formattedInput.contains("PM")) {
|
TimeTextUtils.setText(formattedInput, mTimeText);
|
||||||
SpannableString s = new SpannableString(formattedInput);
|
|
||||||
s.setSpan(AMPM_SIZE_SPAN, formattedInput.indexOf(" "), formattedInput.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
mTimeText.setText(s, TextView.BufferType.SPANNABLE);
|
|
||||||
} else {
|
|
||||||
mTimeText.setText(formattedInput);
|
|
||||||
}
|
|
||||||
//TODO:delete mTimeText.setSelection(mTimeText.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // TODO: Remove
|
@Deprecated // TODO: Remove
|
||||||
@Override
|
@Override
|
||||||
public void showTimeTextPostBackspace(String newStr) {
|
public void showTimeTextPostBackspace(String newStr) {
|
||||||
mTimeText.setText(newStr);
|
mTimeText.setText(newStr);
|
||||||
//TODO:delete mTimeText.setSelection(mTimeText.length());
|
|
||||||
if (!mNumpad.checkTimeValid() && mSwitch.isChecked()) {
|
if (!mNumpad.checkTimeValid() && mSwitch.isChecked()) {
|
||||||
mSwitch.setChecked(false);
|
mSwitch.setChecked(false);
|
||||||
}
|
}
|
||||||
@ -689,6 +664,7 @@ public class EditAlarmActivity extends BaseActivity implements
|
|||||||
// TODO default values
|
// TODO default values
|
||||||
showTimeTextFocused(true);
|
showTimeTextFocused(true);
|
||||||
showRingtone(""); // gets default ringtone
|
showRingtone(""); // gets default ringtone
|
||||||
|
showEnabled(true);
|
||||||
//showNumpad(true);
|
//showNumpad(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,17 +7,12 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Phillip Hsu on 7/16/2016.
|
* Created by Phillip Hsu on 7/16/2016.
|
||||||
*
|
|
||||||
* Utility for accessing the RelativeSizeSpan suitable for changing the
|
|
||||||
* size of the AM/PM label in a TextView.
|
|
||||||
*
|
|
||||||
* TODO: Rename to something like TwelveHourTimeTextUtils
|
|
||||||
*/
|
*/
|
||||||
public class TimeTextUtils {
|
public class TimeTextUtils {
|
||||||
|
|
||||||
private TimeTextUtils() {}
|
private TimeTextUtils() {}
|
||||||
|
|
||||||
public static final RelativeSizeSpan AMPM_SIZE_SPAN = new RelativeSizeSpan(0.5f);
|
private static final RelativeSizeSpan AMPM_SIZE_SPAN = new RelativeSizeSpan(0.5f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the given String on the TextView.
|
* Sets the given String on the TextView.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user