summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-01-11 10:55:32 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-01-11 10:56:40 -0800
commitab82e35a59fc8ebb771c4e69343d1041542a4b83 (patch)
treeee52bb2b02f01b552ed2c66ab86c682fb36b403c /policy
parent3fef446a149408378a4cb93a4773bec778f6161d (diff)
parent06c5f8a768bcd4f7b6441f7525bd5c639399fc76 (diff)
downloadframeworks_base-ab82e35a59fc8ebb771c4e69343d1041542a4b83.zip
frameworks_base-ab82e35a59fc8ebb771c4e69343d1041542a4b83.tar.gz
frameworks_base-ab82e35a59fc8ebb771c4e69343d1041542a4b83.tar.bz2
Merge "Examine widget hierarchy to find clocks."
Diffstat (limited to 'policy')
-rw-r--r--policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java66
1 files changed, 63 insertions, 3 deletions
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
index b4fe0c7..ad5e257 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
@@ -27,6 +27,7 @@ import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
+import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.Gravity;
@@ -38,10 +39,12 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
+import android.widget.TextClock;
import com.android.internal.widget.LockPatternUtils;
import java.util.ArrayList;
+import java.util.TimeZone;
public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwitchListener,
OnLongClickListener, ChallengeLayout.OnBouncerStateChangedListener {
@@ -51,6 +54,9 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
protected static float OVERSCROLL_MAX_ROTATION = 30;
private static final boolean PERFORM_OVERSCROLL_ROTATION = true;
+ private static final int FLAG_HAS_LOCAL_HOUR = 0x1;
+ private static final int FLAG_HAS_LOCAL_MINUTE = 0x2;
+
protected KeyguardViewStateManager mViewStateManager;
private LockPatternUtils mLockPatternUtils;
@@ -131,16 +137,21 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
@Override
public void onPageSwitched(View newPage, int newPageIndex) {
- boolean showingStatusWidget = false;
+ boolean showingClock = false;
if (newPage instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) newPage;
if (vg.getChildAt(0) instanceof KeyguardStatusView) {
- showingStatusWidget = true;
+ showingClock = true;
}
}
+ if (newPage != null &&
+ findClockInHierarchy(newPage) == (FLAG_HAS_LOCAL_HOUR | FLAG_HAS_LOCAL_MINUTE)) {
+ showingClock = true;
+ }
+
// Disable the status bar clock if we're showing the default status widget
- if (showingStatusWidget) {
+ if (showingClock) {
setSystemUiVisibility(getSystemUiVisibility() | View.STATUS_BAR_DISABLE_CLOCK);
} else {
setSystemUiVisibility(getSystemUiVisibility() & ~View.STATUS_BAR_DISABLE_CLOCK);
@@ -857,4 +868,53 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
protected boolean shouldSetTopAlignedPivotForWidget(int childIndex) {
return !isCameraPage(childIndex) && super.shouldSetTopAlignedPivotForWidget(childIndex);
}
+
+ /**
+ * Search given {@link View} hierarchy for {@link TextClock} instances that
+ * show various time components. Returns combination of
+ * {@link #FLAG_HAS_LOCAL_HOUR} and {@link #FLAG_HAS_LOCAL_MINUTE}.
+ */
+ private static int findClockInHierarchy(View view) {
+ if (view instanceof TextClock) {
+ return getClockFlags((TextClock) view);
+ } else if (view instanceof ViewGroup) {
+ int flags = 0;
+ final ViewGroup group = (ViewGroup) view;
+ final int size = group.getChildCount();
+ for (int i = 0; i < size; i++) {
+ flags |= findClockInHierarchy(group.getChildAt(i));
+ }
+ return flags;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Return combination of {@link #FLAG_HAS_LOCAL_HOUR} and
+ * {@link #FLAG_HAS_LOCAL_MINUTE} describing the time represented described
+ * by the given {@link TextClock}.
+ */
+ private static int getClockFlags(TextClock clock) {
+ int flags = 0;
+
+ final String timeZone = clock.getTimeZone();
+ if (timeZone != null && !TimeZone.getDefault().equals(TimeZone.getTimeZone(timeZone))) {
+ // Ignore clocks showing another timezone
+ return 0;
+ }
+
+ final CharSequence format = clock.getFormat();
+ final char hour = clock.is24HourModeEnabled() ? DateFormat.HOUR_OF_DAY
+ : DateFormat.HOUR;
+
+ if (DateFormat.hasDesignator(format, hour)) {
+ flags |= FLAG_HAS_LOCAL_HOUR;
+ }
+ if (DateFormat.hasDesignator(format, DateFormat.MINUTE)) {
+ flags |= FLAG_HAS_LOCAL_MINUTE;
+ }
+
+ return flags;
+ }
}