Methods Summary |
---|
private static int | getAmPmPartEndIndex(java.lang.String formatString)
boolean hasAmPm = false;
int length = formatString.length();
for (int i = length - 1; i >= 0; i--) {
char c = formatString.charAt(i);
boolean isAmPm = c == 'a";
boolean isWhitespace = Character.isWhitespace(c);
if (isAmPm) {
hasAmPm = true;
}
if (isAmPm || isWhitespace) {
continue;
}
if (i == length - 1) {
// First character was not AM/PM and not whitespace, so it's not ending with AM/PM.
return -1;
} else {
// If we have AM/PM at all, return last index, or -1 to indicate that it's not
// ending with AM/PM.
return hasAmPm ? i + 1 : -1;
}
}
// Only AM/PM and whitespaces? The whole string is AM/PM. Else: Only whitespaces in the
// string.
return hasAmPm ? 0 : -1;
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
filter.addAction(Intent.ACTION_USER_SWITCHED);
getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, null);
updatePatterns();
|
protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
getContext().unregisterReceiver(mIntentReceiver);
|
protected void | onFinishInflate()
super.onFinishInflate();
mTimeView = (TextClock) findViewById(R.id.time_view);
mAmPmView = (TextClock) findViewById(R.id.am_pm_view);
mTimeView.setShowCurrentUserTime(true);
mAmPmView.setShowCurrentUserTime(true);
|
private void | updatePatterns()
String formatString = DateFormat.getTimeFormatString(getContext(),
ActivityManager.getCurrentUser());
int index = getAmPmPartEndIndex(formatString);
String timeString;
String amPmString;
if (index == -1) {
timeString = formatString;
amPmString = "";
} else {
timeString = formatString.substring(0, index);
amPmString = formatString.substring(index);
}
mTimeView.setFormat12Hour(timeString);
mTimeView.setFormat24Hour(timeString);
mAmPmView.setFormat12Hour(amPmString);
mAmPmView.setFormat24Hour(amPmString);
|