From 091477b4dec614b9b0153ebe1444d2ae81ee1ab6 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 20 Sep 2012 19:03:35 -0700 Subject: Add support for changing status widget on security screen Change-Id: I68a8ce2ce03888a8decbe017d67634c6965f0a1a --- res/values/strings.xml | 8 +- res/xml/security_settings_biometric_weak.xml | 12 +++ res/xml/security_settings_chooser.xml | 6 ++ res/xml/security_settings_password.xml | 6 ++ res/xml/security_settings_pattern.xml | 7 ++ res/xml/security_settings_pin.xml | 8 ++ src/com/android/settings/SecuritySettings.java | 108 +++++++++++++++++++++---- 7 files changed, 138 insertions(+), 17 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 97c0726..5a0285f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -794,12 +794,18 @@ Screen lock + + Status widget + - Widget + Other widget None + + Default + Change lock screen diff --git a/res/xml/security_settings_biometric_weak.xml b/res/xml/security_settings_biometric_weak.xml index 6593f07..590eb95 100644 --- a/res/xml/security_settings_biometric_weak.xml +++ b/res/xml/security_settings_biometric_weak.xml @@ -27,6 +27,18 @@ android:persistent="false"/> + + + + diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index 98422ba..08428b0 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -27,6 +27,12 @@ android:persistent="false"/> + + + + + + + + + + + extraInfos = new ArrayList(); + noneInfo.label = getResources().getString(R.string.widget_default); + noneInfo.provider = new ComponentName("", ""); + extraInfos.add(noneInfo); + + ArrayList extraExtras = new ArrayList(); + Bundle b = new Bundle(); + b.putBoolean(EXTRA_DEFAULT_WIDGET, true); + extraExtras.add(b); + + // Launch the widget picker + pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos); + pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras); + startActivityForResult(pickIntent, REQUEST_PICK_STATUS_APPWIDGET); } else { Log.e(TAG, "Unable to allocate an AppWidget id in lock screen"); } @@ -567,44 +631,56 @@ public class SecuritySettings extends SettingsPreferenceFragment // is called by grabbing the value from lockPatternUtils. We can't set it here // because mBiometricWeakLiveliness could be null return; - } else if (requestCode == REQUEST_PICK_APPWIDGET || - requestCode == REQUEST_CREATE_APPWIDGET) { + } else if (requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_PICK_STATUS_APPWIDGET || + requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_CREATE_STATUS_APPWIDGET) { int appWidgetId = (data == null) ? -1 : data.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, -1); - if (requestCode == REQUEST_PICK_APPWIDGET && resultCode == Activity.RESULT_OK) { + if ((requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_PICK_STATUS_APPWIDGET) && + resultCode == Activity.RESULT_OK) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity()); - boolean noWidget = data.getBooleanExtra(EXTRA_NO_WIDGET, false); + boolean defaultOrNoWidget = data.getBooleanExtra(EXTRA_NO_WIDGET, false) || + data.getBooleanExtra(EXTRA_DEFAULT_WIDGET, false); AppWidgetProviderInfo appWidget = null; - if (!noWidget) { + if (!defaultOrNoWidget) { appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId); } - if (!noWidget && appWidget.configure != null) { + int newRequestCode = requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET ? + REQUEST_CREATE_USER_SELECTED_APPWIDGET : + REQUEST_CREATE_STATUS_APPWIDGET; + if (!defaultOrNoWidget && appWidget.configure != null) { // Launch over to configure widget, if needed Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); intent.setComponent(appWidget.configure); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); + startActivityForResultSafely(intent, newRequestCode); } else { // Otherwise just add it - if (noWidget) { + if (defaultOrNoWidget) { // If we selected "none", delete the allocated id AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); } - onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); + onActivityResult(newRequestCode, Activity.RESULT_OK, data); } - } else if ( - requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) { + } else if ((requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET || + requestCode == REQUEST_CREATE_STATUS_APPWIDGET) && + resultCode == Activity.RESULT_OK) { // If a widget existed before, delete it - int oldAppWidgetId = getUserSelectedAppWidgetId(); + int oldAppWidgetId = requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ? + getUserSelectedAppWidgetId() : getStatusAppWidgetId(); if (oldAppWidgetId != -1) { AppWidgetHost.deleteAppWidgetIdForSystem(oldAppWidgetId); } Settings.Secure.putString(getContentResolver(), - Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID, + (requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ? + Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID : + Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID), Integer.toString(appWidgetId)); } else { AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); -- cgit v1.1