From 0b2bd8d11d6947a6ce71db0691ba341aec7a2964 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Tue, 30 Oct 2012 15:32:27 -0700 Subject: [PATCH] New widget picker for keyguard widgets New layout for widget picker is still not up to final design, but this change prepares all the backend work Also, remove use of features filter from the picker, since this is being removed from the API Change-Id: I9b332e22cf34b98c20c720602c920d28aed01d6c --- AndroidManifest.xml | 12 + .../appwidget_item_bg_normal.9.png | Bin 0 -> 468 bytes .../appwidget_item_bg_pressed.9.png | Bin 0 -> 553 bytes .../appwidget_item_bg_normal.9.png | Bin 0 -> 332 bytes .../appwidget_item_bg_pressed.9.png | Bin 0 -> 394 bytes .../appwidget_item_bg_normal.9.png | Bin 0 -> 591 bytes .../appwidget_item_bg_pressed.9.png | Bin 0 -> 737 bytes res/drawable/appwidget_item_bg.xml | 23 + res/layout/keyguard_appwidget_item.xml | 35 ++ res/layout/keyguard_appwidget_pick_layout.xml | 27 + res/values/strings.xml | 9 - res/xml/security_settings_biometric_weak.xml | 6 - res/xml/security_settings_chooser.xml | 6 - res/xml/security_settings_password.xml | 6 - res/xml/security_settings_pattern.xml | 6 - res/xml/security_settings_pin.xml | 6 - src/com/android/settings/ActivityPicker.java | 8 +- src/com/android/settings/AppWidgetLoader.java | 182 ++++++ .../settings/AppWidgetPickActivity.java | 249 ++------ .../KeyguardAppWidgetPickActivity.java | 579 ++++++++++++++++++ .../android/settings/SecuritySettings.java | 131 ---- 21 files changed, 925 insertions(+), 360 deletions(-) create mode 100644 res/drawable-hdpi/appwidget_item_bg_normal.9.png create mode 100644 res/drawable-hdpi/appwidget_item_bg_pressed.9.png create mode 100644 res/drawable-mdpi/appwidget_item_bg_normal.9.png create mode 100644 res/drawable-mdpi/appwidget_item_bg_pressed.9.png create mode 100644 res/drawable-xhdpi/appwidget_item_bg_normal.9.png create mode 100644 res/drawable-xhdpi/appwidget_item_bg_pressed.9.png create mode 100644 res/drawable/appwidget_item_bg.xml create mode 100755 res/layout/keyguard_appwidget_item.xml create mode 100644 res/layout/keyguard_appwidget_pick_layout.xml create mode 100644 src/com/android/settings/AppWidgetLoader.java create mode 100644 src/com/android/settings/KeyguardAppWidgetPickActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a11a9482d06..f2e51a1f447 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1315,6 +1315,18 @@ + + + + + + + + diff --git a/res/drawable-hdpi/appwidget_item_bg_normal.9.png b/res/drawable-hdpi/appwidget_item_bg_normal.9.png new file mode 100644 index 0000000000000000000000000000000000000000..baff85873eb6971d653d99aa4021b6351f2dd153 GIT binary patch literal 468 zcmV;_0W1EAP)9z1=HK#9@N*noAWkL-7)NFp6rxF6j^_XvdVwgmz|t@2a`$@gd+lBNiinUB zS-W<-F@5fw^eA^=GMSiCsdTH9ssn|L^2|i!Wjr1~mdjRC0k_AQ#95askbTuISJLM>kPsM+ zMlu)-ig6rgE)hkM>i7FaciioIPogNgs?}-)K`=AMh*IfXM1<*dTIhDWeyi2;d%fN( z5H6?h-PMgT=C0Xn)*Fq+XQfgJ$$;T-SZuf3ey7uUw$?rXvz6bb@&cd%Tmt8$KPAGV z%kHyi$*1d++ZOkLQ^2H5z9I&`0Q+0u!BHZDv(fh5r2Zrm5xxPwbbly0geVLE0000< KMNUMnLSTZx6UzSp literal 0 HcmV?d00001 diff --git a/res/drawable-hdpi/appwidget_item_bg_pressed.9.png b/res/drawable-hdpi/appwidget_item_bg_pressed.9.png new file mode 100644 index 0000000000000000000000000000000000000000..7ec33dd207693d4e65aee1fd5436986bcc743a37 GIT binary patch literal 553 zcmV+^0@nSBP)3;hB@!fT5N^05U({8l$^SuAQebJ9%Yojs*1iq)%R+m3KS@1Nlo1V)G2#(G=n~{+? zwzdpz0JJgk>u*mldb|bpfOx8a+Kcs-?v)NuUg`To8!KAJAy5Z8Qw7NNFhKrmOXowf z@BMUW!UH0Jaw=d9HIn73QGy`O3NY=#6BW2EK~?-250La{aqEHE0$_ANJg5LS-1!9D zmEV<$oF;VVfyvOL31@UdH~jfc=xi(G?u6BvaID}D>VbdM)qO5kdl=by9{6*jxz@B>KP2k=VvHL5=P5A67$s59r`n3nVCL-Jbj^+0mAg&#V00000NkvXXu0mjfJoft4 literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/appwidget_item_bg_normal.9.png b/res/drawable-mdpi/appwidget_item_bg_normal.9.png new file mode 100644 index 0000000000000000000000000000000000000000..976083fdf9090ad4a0a8e9bbd31bcc67cf1f6ad8 GIT binary patch literal 332 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H1|*Mc$*~4fEX7WqAsj$Z!;#Vf4nJ zaCd?*qxs3xYk`9AJY5_^EPCHg+30uJK%i~E_ePhO5zEeayi_*$pitRk6E?4TXk<4|6~*2?J=K$)gY90hn%c%L}>W(65|$z zz)a(`nE4{9$DQ>aaQ~Q-U@0|~V_wO*`Vyw?xzc;Sn;*U$vqXUD-tW>k-Syj@Lqlh8 z(%J4BSkrN4^@N!hP0lV`_qzN+@t6PS_OZTeugrVPTfzG6!0j`0N;+o>%KpCcj`Poy a=h9D@g4BO$OqmAsIfJLGpUXO@geCynfQ8=x literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/appwidget_item_bg_pressed.9.png b/res/drawable-mdpi/appwidget_item_bg_pressed.9.png new file mode 100644 index 0000000000000000000000000000000000000000..8f340d3551de82288633d23f364e0005704f7ad5 GIT binary patch literal 394 zcmV;50d@X~P)zl)FmAKoo|*$wqgBm$k69 zva+}E5ws9|58ps-d40AajGynN# zkVJ)0+J4_ujrmW)%ntTWE_Np3IG)&k707(Y89Iie)BWwMbV}~bdguP>^>FwR&j|(9 zPG`C+o_hdX0~R0yyK5VZZ=+}-e}{4*#Na*b13e(ffi;euq?$Fz0ErW_WS7J~1_{YF z0NdQq&82fWL|(9 oU{Errei%s@Gc`t29whJK6HOzIFFETn9RL6T07*qoM6N<$f{3f58vpM zw1P*NS$E$z;JtVeo}nv*)CCf(V2h9{5gJNTMu_P+$>}1~MIED7Z4491pOj5}`(pbz z@&Pl$0<1m%*O?thhoe-4>E(XEe^#&8-xJYC0IvXemOT;xu~O<&9LGVs-A=V~CQ~aZ zWe315@`(NV*pW>Lz?BfLqz^#gL9n?f`}T&lF8z)*ePPA;CXxTW?vZ<7)@oxXr zsML&Bf`aI;o8YBxp{K?zh=yUvi^ZZA$FVWpW0NR~Xg;6UOl78}&!*F9ZL`_L7Nknfuoz6qI+buLKlhtZfTd&vtXf#q`7={3pUgy*_y$0|O zzy|==$aAE&wgCh94j=;X8F?n}POo$-VD6BA6(N^=3A>_u002ovPDHLkV1i?w1p5F0 literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/appwidget_item_bg_pressed.9.png b/res/drawable-xhdpi/appwidget_item_bg_pressed.9.png new file mode 100644 index 0000000000000000000000000000000000000000..3871689ef23cc70d5b6faeb5b3d3caa6c8791d98 GIT binary patch literal 737 zcmV<70v`Q|P)c#gMl%#X$@hZxG~qf7h?g`FWDYJNt%R+%v$3J0{IjQ zif789HzttL8jmR1WUYE+O!c6)Vy;IVku@d?;?Yt2jZ3+Zb3Mkr;?~yCi;RC}T~Tsk z=!;Z95K;K9sH3QG^jzL|PlrhzJ>)x6ax$uttt?dhI$E{uusAA*dFrK@Dh#S<_=4c4 znAFtm$&;fKhdwvoS1Fw$^mq#W^pi>b=aY$1e)^hBllReaLRXcaV@%OU$17Y(IUOP_ zZs$*BY^NM!>bIwhFzXpP>S=R#adLFxKDx81C5ba?jfgOst=ueC3=XvIlx@#sIN0lw zYK4*Vw_{g_5lDvtai@dD*P^2W^yTyVI!m|jb8B^puqK3&+iyFW4oG#t_O~BwZM+4N ze+dQ9{QkN@a?mDF^EBp~G_SUt3LW(N40kCi{e^qT?0~Ue1zydIT0{5&C zpac8?-T~V{w@9k0`Y!oXMdTvexD~ojF7_9euwTLjl!%~IdEEODa|Fi(i3ooIdD%ci T(ah8y00000NkvXXu0mjfefv*& literal 0 HcmV?d00001 diff --git a/res/drawable/appwidget_item_bg.xml b/res/drawable/appwidget_item_bg.xml new file mode 100644 index 00000000000..b9de6d4c203 --- /dev/null +++ b/res/drawable/appwidget_item_bg.xml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/res/layout/keyguard_appwidget_item.xml b/res/layout/keyguard_appwidget_item.xml new file mode 100755 index 00000000000..7280098f1b1 --- /dev/null +++ b/res/layout/keyguard_appwidget_item.xml @@ -0,0 +1,35 @@ + + + + + + diff --git a/res/layout/keyguard_appwidget_pick_layout.xml b/res/layout/keyguard_appwidget_pick_layout.xml new file mode 100644 index 00000000000..feb85a56a45 --- /dev/null +++ b/res/layout/keyguard_appwidget_pick_layout.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 2248c23697f..d6abe94d61f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -808,15 +808,6 @@ Screen lock - - Add widget - - - None - - - Clock - Change lock screen diff --git a/res/xml/security_settings_biometric_weak.xml b/res/xml/security_settings_biometric_weak.xml index 489a200b236..c830e6fa870 100644 --- a/res/xml/security_settings_biometric_weak.xml +++ b/res/xml/security_settings_biometric_weak.xml @@ -51,12 +51,6 @@ android:key="power_button_instantly_locks" android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/> - - - - - - - - - - { + private static final String TAG = "AppWidgetAdapter"; + private static final boolean LOGD = AppWidgetPickActivity.LOGD; + + private Context mContext; + private AppWidgetManager mAppWidgetManager; + ItemConstructor mItemConstructor; + + interface LabelledItem { + CharSequence getLabel(); + } + + public AppWidgetLoader(Context context, AppWidgetManager appWidgetManager, + ItemConstructor itemConstructor) { + mContext = context; + mAppWidgetManager = appWidgetManager; + mItemConstructor = itemConstructor; + } + + /** + * Create list entries for any custom widgets requested through + * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}. + */ + void putCustomAppWidgets(List items, Intent intent) { + // get and validate the extras they gave us + ArrayList customInfo = null; + ArrayList customExtras = null; + try_custom_items: { + customInfo = intent.getParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_INFO); + if (customInfo == null || customInfo.size() == 0) { + Log.i(TAG, "EXTRA_CUSTOM_INFO not present."); + break try_custom_items; + } + + int customInfoSize = customInfo.size(); + for (int i=0; i appWidgets, + List customExtras, List items, int categoryFilter, + boolean ignoreFilter) { + if (appWidgets == null) return; + final int size = appWidgets.size(); + for (int i = 0; i < size; i++) { + AppWidgetProviderInfo info = appWidgets.get(i); + + // We remove any widgets whose category isn't included in the filter + if (!ignoreFilter && (info.widgetCategory & categoryFilter) == 0) { + continue; + } + + Item item = mItemConstructor.createItem(mContext, info, + customExtras != null ? customExtras.get(i) : null); + + items.add(item); + } + } + + public interface ItemConstructor { + Item createItem(Context context, AppWidgetProviderInfo info, Bundle extras); + } + + + /** + * Build and return list of items to be shown in dialog. This will mix both + * installed {@link AppWidgetProviderInfo} and those provided through + * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically. + */ + protected List getItems(Intent intent) { + boolean sortCustomAppWidgets = + intent.getBooleanExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, true); + + List items = new ArrayList(); + + // Default category is home screen + int categoryFilter = intent.getIntExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER, + AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN); + + putInstalledAppWidgets(items, categoryFilter); + + // Sort all items together by label + if (sortCustomAppWidgets) { + putCustomAppWidgets(items, intent); + } + Collections.sort(items, new Comparator() { + Collator mCollator = Collator.getInstance(); + + public int compare(Item lhs, Item rhs) { + return mCollator.compare(lhs.getLabel(), rhs.getLabel()); + } + }); + if (!sortCustomAppWidgets) { + List customItems = new ArrayList(); + putCustomAppWidgets(customItems, intent); + items.addAll(customItems); + } + return items; + } + + /** + * Create list entries for installed {@link AppWidgetProviderInfo} widgets. + */ + void putInstalledAppWidgets(List items, int categoryFilter) { + List installed = mAppWidgetManager.getInstalledProviders(); + putAppWidgetItems(installed, null, items, categoryFilter, false); + } +} diff --git a/src/com/android/settings/AppWidgetPickActivity.java b/src/com/android/settings/AppWidgetPickActivity.java index 953d10c3f3f..2bd62c0a1cc 100644 --- a/src/com/android/settings/AppWidgetPickActivity.java +++ b/src/com/android/settings/AppWidgetPickActivity.java @@ -18,6 +18,7 @@ package com.android.settings; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProviderInfo; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; @@ -25,15 +26,11 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.os.Parcelable; -import android.os.SystemProperties; import android.util.DisplayMetrics; import android.util.Log; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; +import com.android.settings.ActivityPicker.PickAdapter; + import java.util.List; /** @@ -46,12 +43,11 @@ import java.util.List; * will bind it to the given {@link AppWidgetManager#EXTRA_APPWIDGET_ID}, * otherwise it will return the requested extras. */ -public class AppWidgetPickActivity extends ActivityPicker { +public class AppWidgetPickActivity extends ActivityPicker + implements AppWidgetLoader.ItemConstructor{ private static final String TAG = "AppWidgetPickActivity"; - private static final boolean LOGD = false; + static final boolean LOGD = false; - private PackageManager mPackageManager; - private AppWidgetManager mAppWidgetManager; List mItems; /** @@ -59,15 +55,16 @@ public class AppWidgetPickActivity extends ActivityPicker { * activity is binding. */ private int mAppWidgetId; - - // Enable testing launcher widgets in keyguard. For testing purposes only. - private final boolean mIgnoreFilter = false || SystemProperties.getBoolean( - "ro.keyguard_ignore_filter", false); + private AppWidgetLoader mAppWidgetLoader; + private AppWidgetManager mAppWidgetManager; + private PackageManager mPackageManager; @Override public void onCreate(Bundle icicle) { mPackageManager = getPackageManager(); mAppWidgetManager = AppWidgetManager.getInstance(this); + mAppWidgetLoader = new AppWidgetLoader + (this, mAppWidgetManager, this); super.onCreate(icicle); @@ -85,69 +82,69 @@ public class AppWidgetPickActivity extends ActivityPicker { } /** - * Create list entries for any custom widgets requested through - * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}. + * Build and return list of items to be shown in dialog. This will mix both + * installed {@link AppWidgetProviderInfo} and those provided through + * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically. */ - void putCustomAppWidgets(List items) { - final Bundle extras = getIntent().getExtras(); - - // get and validate the extras they gave us - ArrayList customInfo = null; - ArrayList customExtras = null; - try_custom_items: { - customInfo = extras.getParcelableArrayList(AppWidgetManager.EXTRA_CUSTOM_INFO); - if (customInfo == null || customInfo.size() == 0) { - Log.i(TAG, "EXTRA_CUSTOM_INFO not present."); - break try_custom_items; - } + @Override + protected List getItems() { + mItems = mAppWidgetLoader.getItems(getIntent()); + return mItems; + } - int customInfoSize = customInfo.size(); - for (int i=0; i appWidgets, - List customExtras, List items, int categoryFilter, - int featuresFilter, boolean ignoreFilters) { - if (appWidgets == null) return; - final int size = appWidgets.size(); - for (int i = 0; i < size; i++) { - AppWidgetProviderInfo info = appWidgets.get(i); - - // We remove any widgets whose category isn't included in the filter - if (!ignoreFilters && (info.widgetCategory & categoryFilter) == 0) { - continue; - } - - // We remove any widgets who don't have all the features in the features filter - if (!ignoreFilters && (info.widgetFeatures & featuresFilter) != featuresFilter) { - continue; - } - - CharSequence label = info.label; - Drawable icon = null; - - if (info.icon != 0) { - try { - final Resources res = getResources(); - final int density = res.getDisplayMetrics().densityDpi; - int iconDensity; - switch (density) { - case DisplayMetrics.DENSITY_MEDIUM: - iconDensity = DisplayMetrics.DENSITY_LOW; - case DisplayMetrics.DENSITY_TV: - iconDensity = DisplayMetrics.DENSITY_MEDIUM; - case DisplayMetrics.DENSITY_HIGH: - iconDensity = DisplayMetrics.DENSITY_MEDIUM; - case DisplayMetrics.DENSITY_XHIGH: - iconDensity = DisplayMetrics.DENSITY_HIGH; - case DisplayMetrics.DENSITY_XXHIGH: - iconDensity = DisplayMetrics.DENSITY_XHIGH; - default: - // The density is some abnormal value. Return some other - // abnormal value that is a reasonable scaling of it. - iconDensity = (int)((density*0.75f)+.5f); - } - Resources packageResources = mPackageManager. - getResourcesForApplication(info.provider.getPackageName()); - icon = packageResources.getDrawableForDensity(info.icon, iconDensity); - } catch (NameNotFoundException e) { - Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) - + " for provider: " + info.provider); - } - if (icon == null) { - Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) - + " for provider: " + info.provider); - } - } - - PickAdapter.Item item = new PickAdapter.Item(this, label, icon); - - item.packageName = info.provider.getPackageName(); - item.className = info.provider.getClassName(); - - if (customExtras != null) { - item.extras = customExtras.get(i); - } - - items.add(item); - } - } - - /** - * Build and return list of items to be shown in dialog. This will mix both - * installed {@link AppWidgetProviderInfo} and those provided through - * {@link AppWidgetManager#EXTRA_CUSTOM_INFO}, sorting them alphabetically. - */ - @Override - protected List getItems() { - final Intent intent = getIntent(); - boolean sortCustomAppWidgets = - intent.getBooleanExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, true); - - List items = new ArrayList(); - - int categoryFilter = AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN; - if (intent.getExtras().containsKey(AppWidgetManager.EXTRA_CATEGORY_FILTER)) { - categoryFilter = intent.getExtras().getInt(AppWidgetManager.EXTRA_CATEGORY_FILTER); - } - - // If not specified, we don't filter on any specific - int featuresFilter = AppWidgetProviderInfo.WIDGET_FEATURES_NONE; - if (intent.getExtras().containsKey(AppWidgetManager.EXTRA_FEATURES_FILTER)) { - featuresFilter = intent.getExtras().getInt(AppWidgetManager.EXTRA_FEATURES_FILTER); - } - - putInstalledAppWidgets(items, categoryFilter, featuresFilter); - - // Sort all items together by label - if (sortCustomAppWidgets) { - putCustomAppWidgets(items); - } - Collections.sort(items, new Comparator() { - Collator mCollator = Collator.getInstance(); - - public int compare(PickAdapter.Item lhs, PickAdapter.Item rhs) { - return mCollator.compare(lhs.label, rhs.label); - } - }); - if (!sortCustomAppWidgets) { - List customItems = new ArrayList(); - putCustomAppWidgets(customItems); - items.addAll(customItems); - } - mItems = items; - return items; - } - - /** - * Create list entries for installed {@link AppWidgetProviderInfo} widgets. - */ - void putInstalledAppWidgets(List items, int categoryFilter, int featuresFilter) { - List installed = mAppWidgetManager.getInstalledProviders(); - putAppWidgetItems(installed, null, items, categoryFilter, featuresFilter, mIgnoreFilter ); - } /** * Convenience method for setting the result code and intent. This method diff --git a/src/com/android/settings/KeyguardAppWidgetPickActivity.java b/src/com/android/settings/KeyguardAppWidgetPickActivity.java new file mode 100644 index 00000000000..0afc5b253ce --- /dev/null +++ b/src/com/android/settings/KeyguardAppWidgetPickActivity.java @@ -0,0 +1,579 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import android.app.Activity; +import android.appwidget.AppWidgetHost; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProviderInfo; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.PaintFlagsDrawFilter; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.PaintDrawable; +import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.IWindowManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.GridView; +import android.widget.TextView; +import android.widget.Toast; + +import com.android.internal.widget.LockPatternUtils; + +import java.util.List; + +/** + * Displays a list of {@link AppWidgetProviderInfo} widgets, along with any + * injected special widgets specified through + * {@link AppWidgetManager#EXTRA_CUSTOM_INFO} and + * {@link AppWidgetManager#EXTRA_CUSTOM_EXTRAS}. + *

+ * When an installed {@link AppWidgetProviderInfo} is selected, this activity + * will bind it to the given {@link AppWidgetManager#EXTRA_APPWIDGET_ID}, + * otherwise it will return the requested extras. + */ +public class KeyguardAppWidgetPickActivity extends Activity + implements GridView.OnItemClickListener, + AppWidgetLoader.ItemConstructor { + private static final String TAG = "KeyguardAppWidgetPickActivity"; + private static final int REQUEST_PICK_APPWIDGET = 126; + private static final int REQUEST_CREATE_APPWIDGET = 127; + + private AppWidgetLoader mAppWidgetLoader; + private List mItems; + private GridView mGridView; + private AppWidgetManager mAppWidgetManager; + private int mAppWidgetId; + // Might make it possible to make this be false in future + private boolean mAddingToKeyguard = true; + private Intent mResultData; + private LockPatternUtils mLockPatternUtils; + private boolean mSuccess; + + @Override + protected void onCreate(Bundle savedInstanceState) { + setContentView(R.layout.keyguard_appwidget_pick_layout); + super.onCreate(savedInstanceState); + + // Set default return data + setResultData(RESULT_CANCELED, null); + + // Read the appWidgetId passed our direction, otherwise bail if not found + final Intent intent = getIntent(); + if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { + mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } else { + finish(); + } + + mGridView = (GridView) findViewById(R.id.widget_list); + mAppWidgetManager = AppWidgetManager.getInstance(this); + mAppWidgetLoader = new AppWidgetLoader(this, mAppWidgetManager, this); + mItems = mAppWidgetLoader.getItems(getIntent()); + AppWidgetAdapter adapter = new AppWidgetAdapter(this, mItems); + mGridView.setAdapter(adapter); + mGridView.setOnItemClickListener(this); + + mLockPatternUtils = new LockPatternUtils(this); // TEMP-- we want to delete this + } + + /** + * Convenience method for setting the result code and intent. This method + * correctly injects the {@link AppWidgetManager#EXTRA_APPWIDGET_ID} that + * most hosts expect returned. + */ + void setResultData(int code, Intent intent) { + Intent result = intent != null ? intent : new Intent(); + result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); + mResultData = result; + setResult(code, result); + } + + private static class EmptyDrawable extends Drawable { + private final int mWidth; + private final int mHeight; + + EmptyDrawable(int width, int height) { + mWidth = width; + mHeight = height; + } + + @Override + public int getIntrinsicWidth() { + return mWidth; + } + + @Override + public int getIntrinsicHeight() { + return mHeight; + } + + @Override + public int getMinimumWidth() { + return mWidth; + } + + @Override + public int getMinimumHeight() { + return mHeight; + } + + @Override + public void draw(Canvas canvas) { + } + + @Override + public void setAlpha(int alpha) { + } + + @Override + public void setColorFilter(ColorFilter cf) { + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + } + + /** + * Utility class to resize icons to match default icon size. Code is mostly + * borrowed from Launcher. + */ + private static class IconResizer { + private final int mIconWidth; + private final int mIconHeight; + + private final DisplayMetrics mMetrics; + private final Rect mOldBounds = new Rect(); + private final Canvas mCanvas = new Canvas(); + + public IconResizer(int width, int height, DisplayMetrics metrics) { + mCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, + Paint.FILTER_BITMAP_FLAG)); + + mMetrics = metrics; + mIconWidth = width; + mIconHeight = height; + } + + /** + * Returns a Drawable representing the thumbnail of the specified Drawable. + * The size of the thumbnail is defined by the dimension + * android.R.dimen.launcher_application_icon_size. + * + * This method is not thread-safe and should be invoked on the UI thread only. + * + * @param icon The icon to get a thumbnail of. + * + * @return A thumbnail for the specified icon or the icon itself if the + * thumbnail could not be created. + */ + public Drawable createIconThumbnail(Drawable icon) { + int width = mIconWidth; + int height = mIconHeight; + + if (icon == null) { + return new EmptyDrawable(width, height); + } + + try { + if (icon instanceof PaintDrawable) { + PaintDrawable painter = (PaintDrawable) icon; + painter.setIntrinsicWidth(width); + painter.setIntrinsicHeight(height); + } else if (icon instanceof BitmapDrawable) { + // Ensure the bitmap has a density. + BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; + Bitmap bitmap = bitmapDrawable.getBitmap(); + if (bitmap.getDensity() == Bitmap.DENSITY_NONE) { + bitmapDrawable.setTargetDensity(mMetrics); + } + } + int iconWidth = icon.getIntrinsicWidth(); + int iconHeight = icon.getIntrinsicHeight(); + + if (iconWidth > 0 && iconHeight > 0) { + if (width < iconWidth || height < iconHeight) { + final float ratio = (float) iconWidth / iconHeight; + + if (iconWidth > iconHeight) { + height = (int) (width / ratio); + } else if (iconHeight > iconWidth) { + width = (int) (height * ratio); + } + + final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ? + Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; + final Bitmap thumb = Bitmap.createBitmap(mIconWidth, mIconHeight, c); + final Canvas canvas = mCanvas; + canvas.setBitmap(thumb); + // Copy the old bounds to restore them later + // If we were to do oldBounds = icon.getBounds(), + // the call to setBounds() that follows would + // change the same instance and we would lose the + // old bounds + mOldBounds.set(icon.getBounds()); + final int x = (mIconWidth - width) / 2; + final int y = (mIconHeight - height) / 2; + icon.setBounds(x, y, x + width, y + height); + icon.draw(canvas); + icon.setBounds(mOldBounds); + //noinspection deprecation + icon = new BitmapDrawable(thumb); + ((BitmapDrawable) icon).setTargetDensity(mMetrics); + canvas.setBitmap(null); + } else if (iconWidth < width && iconHeight < height) { + final Bitmap.Config c = Bitmap.Config.ARGB_8888; + final Bitmap thumb = Bitmap.createBitmap(mIconWidth, mIconHeight, c); + final Canvas canvas = mCanvas; + canvas.setBitmap(thumb); + mOldBounds.set(icon.getBounds()); + final int x = (width - iconWidth) / 2; + final int y = (height - iconHeight) / 2; + icon.setBounds(x, y, x + iconWidth, y + iconHeight); + icon.draw(canvas); + icon.setBounds(mOldBounds); + //noinspection deprecation + icon = new BitmapDrawable(thumb); + ((BitmapDrawable) icon).setTargetDensity(mMetrics); + canvas.setBitmap(null); + } + } + + } catch (Throwable t) { + icon = new EmptyDrawable(width, height); + } + + return icon; + } + } + + /** + * Item that appears in the AppWidget picker grid. + */ + public static class Item implements AppWidgetLoader.LabelledItem { + protected static IconResizer sResizer; + + protected IconResizer getResizer(Context context) { + if (sResizer == null) { + final Resources resources = context.getResources(); + int size = (int) resources.getDimension(android.R.dimen.app_icon_size); + sResizer = new IconResizer(size, size, resources.getDisplayMetrics()); + } + return sResizer; + } + CharSequence label; + Drawable icon; + String packageName; + String className; + Bundle extras; + + /** + * Create a list item from given label and icon. + */ + Item(Context context, CharSequence label, Drawable icon) { + this.label = label; + this.icon = getResizer(context).createIconThumbnail(icon); + } + + /** + * Create a list item and fill it with details from the given + * {@link ResolveInfo} object. + */ + Item(Context context, PackageManager pm, ResolveInfo resolveInfo) { + label = resolveInfo.loadLabel(pm); + if (label == null && resolveInfo.activityInfo != null) { + label = resolveInfo.activityInfo.name; + } + + icon = getResizer(context).createIconThumbnail(resolveInfo.loadIcon(pm)); + packageName = resolveInfo.activityInfo.applicationInfo.packageName; + className = resolveInfo.activityInfo.name; + } + + /** + * Build the {@link Intent} described by this item. If this item + * can't create a valid {@link android.content.ComponentName}, it will return + * {@link Intent#ACTION_CREATE_SHORTCUT} filled with the item label. + */ + Intent getIntent() { + Intent intent = new Intent(); + if (packageName != null && className != null) { + // Valid package and class, so fill details as normal intent + intent.setClassName(packageName, className); + if (extras != null) { + intent.putExtras(extras); + } + } else { + // No valid package or class, so treat as shortcut with label + intent.setAction(Intent.ACTION_CREATE_SHORTCUT); + intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label); + } + return intent; + } + + public CharSequence getLabel() { + return label; + } + } + + @Override + public Item createItem(Context context, AppWidgetProviderInfo info, Bundle extras) { + CharSequence label = info.label; + Drawable icon = null; + + if (info.icon != 0) { + try { + final Resources res = context.getResources(); + final int density = res.getDisplayMetrics().densityDpi; + int iconDensity; + switch (density) { + case DisplayMetrics.DENSITY_MEDIUM: + iconDensity = DisplayMetrics.DENSITY_LOW; + case DisplayMetrics.DENSITY_TV: + iconDensity = DisplayMetrics.DENSITY_MEDIUM; + case DisplayMetrics.DENSITY_HIGH: + iconDensity = DisplayMetrics.DENSITY_MEDIUM; + case DisplayMetrics.DENSITY_XHIGH: + iconDensity = DisplayMetrics.DENSITY_HIGH; + case DisplayMetrics.DENSITY_XXHIGH: + iconDensity = DisplayMetrics.DENSITY_XHIGH; + default: + // The density is some abnormal value. Return some other + // abnormal value that is a reasonable scaling of it. + iconDensity = (int)((density*0.75f)+.5f); + } + Resources packageResources = getPackageManager(). + getResourcesForApplication(info.provider.getPackageName()); + icon = packageResources.getDrawableForDensity(info.icon, iconDensity); + } catch (NameNotFoundException e) { + Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) + + " for provider: " + info.provider); + } + if (icon == null) { + Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) + + " for provider: " + info.provider); + } + } + + Item item = new Item(context, label, icon); + item.packageName = info.provider.getPackageName(); + item.className = info.provider.getClassName(); + item.extras = extras; + return item; + } + + protected static class AppWidgetAdapter extends BaseAdapter { + private final LayoutInflater mInflater; + private final List mItems; + + /** + * Create an adapter for the given items. + */ + public AppWidgetAdapter(Context context, List items) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mItems = items; + } + + /** + * {@inheritDoc} + */ + public int getCount() { + return mItems.size(); + } + + /** + * {@inheritDoc} + */ + public Object getItem(int position) { + return mItems.get(position); + } + + /** + * {@inheritDoc} + */ + public long getItemId(int position) { + return position; + } + + /** + * {@inheritDoc} + */ + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = mInflater.inflate(R.layout.keyguard_appwidget_item, parent, false); + } + + Item item = (Item) getItem(position); + TextView textView = (TextView) convertView.findViewById(R.id.icon_and_label); + textView.setText(item.label); + textView.setCompoundDrawablesWithIntrinsicBounds(item.icon, null, null, null); + + return convertView; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Item item = mItems.get(position); + Intent intent = item.getIntent(); + + int result; + if (item.extras != null) { + // If these extras are present it's because this entry is custom. + // Don't try to bind it, just pass it back to the app. + result = RESULT_OK; + setResultData(result, intent); + } else { + try { + Bundle options = null; + if (intent.getExtras() != null) { + options = intent.getExtras().getBundle( + AppWidgetManager.EXTRA_APPWIDGET_OPTIONS); + } + mAppWidgetManager.bindAppWidgetId(mAppWidgetId, intent.getComponent(), options); + result = RESULT_OK; + } catch (IllegalArgumentException e) { + // This is thrown if they're already bound, or otherwise somehow + // bogus. Set the result to canceled, and exit. The app *should* + // clean up at this point. We could pass the error along, but + // it's not clear that that's useful -- the widget will simply not + // appear. + result = RESULT_CANCELED; + } + setResultData(result, null); + } + if (mAddingToKeyguard) { + onActivityResult(REQUEST_PICK_APPWIDGET, result, mResultData); + } else { + finish(); + } + } + + protected void onDestroy() { + if (!mSuccess && mAddingToKeyguard && + mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { + AppWidgetHost.deleteAppWidgetIdForSystem(mAppWidgetId); + } + super.onDestroy(); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET) { + int appWidgetId = (data == null) ? -1 : data.getIntExtra( + AppWidgetManager.EXTRA_APPWIDGET_ID, -1); + if ((requestCode == REQUEST_PICK_APPWIDGET) && + resultCode == Activity.RESULT_OK) { + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); + boolean defaultWidget = + data.getBooleanExtra(LockPatternUtils.EXTRA_DEFAULT_WIDGET, false); + + AppWidgetProviderInfo appWidget = null; + if (!defaultWidget) { + appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId); + } + + if (!defaultWidget && appWidget.configure != null) { + // Launch over to configure widget, if needed + Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); + intent.setComponent(appWidget.configure); + intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + + startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); + } else { + // Otherwise just add it + if (defaultWidget) { + // If we selected "none", delete the allocated id + AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); + data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + LockPatternUtils.ID_DEFAULT_STATUS_WIDGET); + } + onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); + } + } else if (requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) { + mSuccess = true; + mLockPatternUtils.addAppWidget(appWidgetId, 0); + finishDelayedAndShowLockScreen(); + } else { + finishDelayedAndShowLockScreen(); + } + } + } + + private void finishDelayedAndShowLockScreen() { + IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE); + IWindowManager iWm = IWindowManager.Stub.asInterface(b); + try { + iWm.lockNow(null); + } catch (RemoteException e) { + } + + // Change background to all black + ViewGroup root = (ViewGroup) findViewById(R.id.layout_root); + root.setBackgroundColor(0xFF000000); + // Hide all children + final int childCount = root.getChildCount(); + for (int i = 0; i < childCount; i++) { + root.getChildAt(i).setVisibility(View.INVISIBLE); + } + mGridView.postDelayed(new Runnable() { + public void run() { + finish(); + } + }, 500); + } + + void startActivityForResultSafely(Intent intent, int requestCode) { + try { + startActivityForResult(intent, requestCode); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); + } catch (SecurityException e) { + Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); + Log.e(TAG, "Settings does not have the permission to launch " + intent, e); + } + } +} diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 7a5118bbb7a..22812b24118 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -22,20 +22,12 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; import android.app.Activity; import android.app.AlertDialog; import android.app.admin.DevicePolicyManager; -import android.appwidget.AppWidgetHost; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProviderInfo; -import android.content.ActivityNotFoundException; -import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; -import android.os.IBinder; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.UserHandle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; @@ -47,8 +39,6 @@ import android.provider.Settings; import android.security.KeyStore; import android.telephony.TelephonyManager; import android.util.Log; -import android.view.IWindowManager; -import android.widget.Toast; import com.android.internal.widget.LockPatternUtils; @@ -65,8 +55,6 @@ public class SecuritySettings extends SettingsPreferenceFragment // Lock Settings private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change"; - private static final String KEY_CHOOSE_LOCKSCREEN_WIDGET = - "choose_user_selected_lockscreen_widget"; private static final String KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING = "biometric_weak_improve_matching"; private static final String KEY_BIOMETRIC_WEAK_LIVELINESS = "biometric_weak_liveliness"; @@ -76,12 +64,9 @@ public class SecuritySettings extends SettingsPreferenceFragment private static final String KEY_DEVICE_ADMIN_CATEGORY = "device_admin_category"; private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings"; - private static final String EXTRA_DEFAULT_WIDGET = "com.android.settings.DEFAULT_WIDGET"; private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123; private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST = 124; private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF = 125; - private static final int REQUEST_PICK_APPWIDGET = 126; - private static final int REQUEST_CREATE_APPWIDGET = 127; // Misc Settings private static final String KEY_SIM_LOCK = "sim_lock"; @@ -421,68 +406,6 @@ public class SecuritySettings extends SettingsPreferenceFragment } } - void startActivityForResultSafely(Intent intent, int requestCode) { - try { - startActivityForResult(intent, requestCode); - } catch (ActivityNotFoundException e) { - Toast.makeText(getActivity(), R.string.activity_not_found, Toast.LENGTH_SHORT).show(); - } catch (SecurityException e) { - Toast.makeText(getActivity(), R.string.activity_not_found, Toast.LENGTH_SHORT).show(); - Log.e(TAG, "Settings does not have the permission to launch " + intent, e); - } - } - - private void launchPickActivityIntent(int featuresFilter, int defaultLabelId, int defaultIconId, - ComponentName defaultComponentName, String defaultTag, int widgetType) { - // Create intent to pick widget - Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); - - // Found in KeyguardHostView.java - final int KEYGUARD_HOST_ID = 0x4B455947; - int appWidgetId = AppWidgetHost.allocateAppWidgetIdForSystem(KEYGUARD_HOST_ID); - if (appWidgetId != -1) { - pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, false); - pickIntent.putExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER, - AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD); - if (featuresFilter != AppWidgetProviderInfo.WIDGET_FEATURES_NONE) { - pickIntent.putExtra(AppWidgetManager.EXTRA_FEATURES_FILTER, featuresFilter); - } - - // Add an entry for "none" to let someone select no widget - AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo(); - ArrayList extraInfos = new ArrayList(); - defaultInfo.label = getResources().getString(defaultLabelId); - defaultInfo.icon = defaultIconId; - defaultInfo.provider = defaultComponentName; - extraInfos.add(defaultInfo); - - ArrayList extraExtras = new ArrayList(); - Bundle b = new Bundle(); - b.putBoolean(defaultTag, true); - extraExtras.add(b); - - // Launch the widget picker - pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos); - pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras); - pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent()); - startActivityForResult(pickIntent, widgetType); - } else { - Log.e(TAG, "Unable to allocate an AppWidget id in lock screen"); - } - } - - private Intent getBaseIntent() { - Intent baseIntent = new Intent(Intent.ACTION_MAIN, null); - baseIntent.addCategory(Intent.CATEGORY_DEFAULT); - - Bundle options = new Bundle(); - options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, - AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD); - baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); - return baseIntent; - } - @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); @@ -491,18 +414,6 @@ public class SecuritySettings extends SettingsPreferenceFragment if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) { startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", SET_OR_CHANGE_LOCK_METHOD_REQUEST, null); - } else if (KEY_CHOOSE_LOCKSCREEN_WIDGET.equals(key)) { - int defaultIconId; - ComponentName clock = new ComponentName( - "com.google.android.deskclock", "com.android.deskclock.DeskClock"); - try { - defaultIconId = getActivity().getPackageManager().getActivityInfo(clock, 0).icon; - } catch (PackageManager.NameNotFoundException e) { - defaultIconId = 0; - } - launchPickActivityIntent(AppWidgetProviderInfo.WIDGET_FEATURES_NONE, - R.string.widget_default, defaultIconId, clock, EXTRA_DEFAULT_WIDGET, - REQUEST_PICK_APPWIDGET); } else if (KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING.equals(key)) { ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this.getActivity(), this); @@ -583,48 +494,6 @@ 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) { - int appWidgetId = (data == null) ? -1 : data.getIntExtra( - AppWidgetManager.EXTRA_APPWIDGET_ID, -1); - if ((requestCode == REQUEST_PICK_APPWIDGET) && - resultCode == Activity.RESULT_OK) { - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity()); - boolean defaultWidget = data.getBooleanExtra(EXTRA_DEFAULT_WIDGET, false); - - AppWidgetProviderInfo appWidget = null; - if (!defaultWidget) { - appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId); - } - - if (!defaultWidget && 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); - } else { - // Otherwise just add it - if (defaultWidget) { - // If we selected "none", delete the allocated id - AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); - data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, - LockPatternUtils.ID_DEFAULT_STATUS_WIDGET); - } - onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); - } - } else if (requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) { - mLockPatternUtils.addAppWidget(appWidgetId, 0); - - IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE); - IWindowManager iWm = IWindowManager.Stub.asInterface(b); - try { - iWm.lockNow(null); - } catch (RemoteException e) { - } - } else { - AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId); - } } createPreferenceHierarchy(); }