import android.app.Activity;
import android.app.AlertDialog;
-import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
mUserSelectedWidget = root.findPreference(KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET);
if (mUserSelectedWidget != null) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
- int appWidgetId = -1;
- String appWidgetIdString = Settings.Secure.getString(
- getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
- if (appWidgetIdString != null) {;
- appWidgetId = (int) Integer.decode(appWidgetIdString);
- }
+ int appWidgetId = getUserSelectedAppWidgetId();
if (appWidgetId == -1) {
mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_none));
} else {
return root;
}
+ private int getUserSelectedAppWidgetId() {
+ int appWidgetId = -1;
+ String appWidgetIdString = Settings.Secure.getString(
+ getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
+ if (appWidgetIdString != null) {;
+ appWidgetId = (int) Integer.decode(appWidgetIdString);
+ }
+ return appWidgetId;
+ }
+
private boolean isNonMarketAppsAllowed() {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
} else {
// Otherwise just add it
if (noWidget) {
+ // If we selected "none", delete the allocated id
+ AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
+ } else {
+ onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
}
- onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
}
- } else if (requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) {
+ } else if (
+ requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) {
+ // If a widget existed before, delete it
+ int oldAppWidgetId = getUserSelectedAppWidgetId();
+ if (oldAppWidgetId != -1) {
+ AppWidgetHost.deleteAppWidgetIdForHost(oldAppWidgetId);
+ }
Settings.Secure.putString(getContentResolver(),
Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
Integer.toString(appWidgetId));
-
} else {
AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
}