Skip to content

Commit 20c41d5

Browse files
committed
Add support for changing status widget on security screen
Change-Id: I080fd89eb84445604c602b6e807b55153a7ee129
1 parent d86077c commit 20c41d5

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

core/java/android/provider/Settings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,8 +3219,8 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
32193219
* Id of the time appwidget on the lockscreen, or -1 if none
32203220
* @hide
32213221
*/
3222-
public static final String LOCK_SCREEN_CLOCK_APPWIDGET_ID =
3223-
"lock_screen_clock_appwidget_id";
3222+
public static final String LOCK_SCREEN_STATUS_APPWIDGET_ID =
3223+
"lock_screen_status_appwidget_id";
32243224

32253225
/**
32263226
* Id of the user-selected appwidget on the lockscreen, or -1 if none

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,17 @@ public int[] getUserDefinedWidgets() {
10441044
return new int[] { appWidgetId };
10451045
}
10461046

1047+
public int getStatusWidget() {
1048+
int appWidgetId = -1;
1049+
String appWidgetIdString = Settings.Secure.getString(
1050+
mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID);
1051+
if (appWidgetIdString != null) {
1052+
appWidgetId = (int) Integer.decode(appWidgetIdString);
1053+
}
1054+
1055+
return appWidgetId;
1056+
}
1057+
10471058
private long getLong(String secureSettingKey, long defaultValue) {
10481059
try {
10491060
return getLockSettings().getLong(secureSettingKey, defaultValue,

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.graphics.Canvas;
3434
import android.graphics.Rect;
3535
import android.os.Looper;
36-
import android.os.UserHandle;
3736
import android.os.UserManager;
3837
import android.util.AttributeSet;
3938
import android.util.Log;
@@ -42,6 +41,7 @@
4241
import android.view.LayoutInflater;
4342
import android.view.MotionEvent;
4443
import android.view.View;
44+
import android.view.ViewGroup;
4545
import android.view.WindowManager;
4646
import android.view.animation.AnimationUtils;
4747
import android.widget.RemoteViews.OnClickHandler;
@@ -691,6 +691,23 @@ private void maybePopulateWidgets() {
691691
}
692692
inflateAndAddUserSelectorWidgetIfNecessary();
693693

694+
// Add status widget
695+
int statusWidgetId = mLockPatternUtils.getStatusWidget();
696+
if (statusWidgetId != -1) {
697+
addWidget(statusWidgetId);
698+
View newStatusWidget = mAppWidgetContainer.getChildAt(
699+
mAppWidgetContainer.getChildCount() - 1);
700+
701+
int oldStatusWidgetPosition = getWidgetPosition(R.id.keyguard_status_view);
702+
mAppWidgetContainer.removeViewAt(oldStatusWidgetPosition);
703+
704+
// Re-add new status widget at position of old one
705+
mAppWidgetContainer.removeView(newStatusWidget);
706+
newStatusWidget.setId(R.id.keyguard_status_view);
707+
mAppWidgetContainer.addView(newStatusWidget, oldStatusWidgetPosition);
708+
}
709+
710+
// Add user-selected widget
694711
final int[] widgets = mLockPatternUtils.getUserDefinedWidgets();
695712
for (int i = 0; i < widgets.length; i++) {
696713
if (widgets[i] != -1) {

0 commit comments

Comments
 (0)