Add support for changing status widget on security screen
Change-Id: I080fd89eb84445604c602b6e807b55153a7ee129
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index cc9abff..66738a1 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3219,8 +3219,8 @@
* Id of the time appwidget on the lockscreen, or -1 if none
* @hide
*/
- public static final String LOCK_SCREEN_CLOCK_APPWIDGET_ID =
- "lock_screen_clock_appwidget_id";
+ public static final String LOCK_SCREEN_STATUS_APPWIDGET_ID =
+ "lock_screen_status_appwidget_id";
/**
* Id of the user-selected appwidget on the lockscreen, or -1 if none
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 8756950..f3bef08 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -1044,6 +1044,17 @@
return new int[] { appWidgetId };
}
+ public int getStatusWidget() {
+ int appWidgetId = -1;
+ String appWidgetIdString = Settings.Secure.getString(
+ mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID);
+ if (appWidgetIdString != null) {
+ appWidgetId = (int) Integer.decode(appWidgetIdString);
+ }
+
+ return appWidgetId;
+ }
+
private long getLong(String secureSettingKey, long defaultValue) {
try {
return getLockSettings().getLong(secureSettingKey, defaultValue,
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
index bbd07a3..3f74eff 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
@@ -33,7 +33,6 @@
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Looper;
-import android.os.UserHandle;
import android.os.UserManager;
import android.util.AttributeSet;
import android.util.Log;
@@ -42,6 +41,7 @@
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.RemoteViews.OnClickHandler;
@@ -691,6 +691,23 @@
}
inflateAndAddUserSelectorWidgetIfNecessary();
+ // Add status widget
+ int statusWidgetId = mLockPatternUtils.getStatusWidget();
+ if (statusWidgetId != -1) {
+ addWidget(statusWidgetId);
+ View newStatusWidget = mAppWidgetContainer.getChildAt(
+ mAppWidgetContainer.getChildCount() - 1);
+
+ int oldStatusWidgetPosition = getWidgetPosition(R.id.keyguard_status_view);
+ mAppWidgetContainer.removeViewAt(oldStatusWidgetPosition);
+
+ // Re-add new status widget at position of old one
+ mAppWidgetContainer.removeView(newStatusWidget);
+ newStatusWidget.setId(R.id.keyguard_status_view);
+ mAppWidgetContainer.addView(newStatusWidget, oldStatusWidgetPosition);
+ }
+
+ // Add user-selected widget
final int[] widgets = mLockPatternUtils.getUserDefinedWidgets();
for (int i = 0; i < widgets.length; i++) {
if (widgets[i] != -1) {