Created TimeTextUtils

This commit is contained in:
Phillip Hsu 2016-07-16 14:37:41 -07:00
parent 140ce5505d
commit ec3a75f8d2
2 changed files with 40 additions and 1 deletions

View File

@ -160,7 +160,7 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
} }
private void updateInputText(String inputText) { private void updateInputText(String inputText) {
mInputField.setText(inputText); TimeTextUtils.setText(inputText, mInputField);
// Move the cursor // Move the cursor
mInputField.setSelection(mInputField.length()); mInputField.setSelection(mInputField.length());
if (mFocusGrabber.isFocused()) { if (mFocusGrabber.isFocused()) {

View File

@ -0,0 +1,39 @@
package com.philliphsu.clock2.editalarm;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.widget.TextView;
/**
* 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 {
private TimeTextUtils() {}
public static final RelativeSizeSpan AMPM_SIZE_SPAN = new RelativeSizeSpan(0.5f);
/**
* Sets the given String on the TextView.
* If the given String contains the "AM" or "PM" label,
* this first applies a size span on the label.
* @param textTime the time String that may contain "AM" or "PM"
* @param textView the TextView to display {@code textTime}
*/
public static void setText(String textTime, TextView textView) {
if (textTime.contains("AM") || textTime.contains("PM")) {
SpannableString s = new SpannableString(textTime);
s.setSpan(AMPM_SIZE_SPAN, textTime.indexOf(" "), textTime.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(s, TextView.BufferType.SPANNABLE);
} else {
textView.setText(textTime);
}
}
}