am c8dc8eb3: Merge "Use new keyguard appwidget picker" into jb-mr1-lockscreen-dev
* commit 'c8dc8eb3275a6d05e27824f322796e97e5e50e2f': Use new keyguard appwidget picker
This commit is contained in:
@@ -79,6 +79,13 @@ public class AppWidgetManager {
|
||||
*/
|
||||
public static final String ACTION_APPWIDGET_PICK = "android.appwidget.action.APPWIDGET_PICK";
|
||||
|
||||
/**
|
||||
* Similar to ACTION_APPWIDGET_PICK, but used from keyguard
|
||||
* @hide
|
||||
*/
|
||||
public static final String
|
||||
ACTION_KEYGUARD_APPWIDGET_PICK = "android.appwidget.action.KEYGUARD_APPWIDGET_PICK";
|
||||
|
||||
/**
|
||||
* Send this from your {@link AppWidgetHost} activity when you want to bind an AppWidget to
|
||||
* display and bindAppWidgetIdIfAllowed returns false.
|
||||
@@ -223,13 +230,6 @@ public class AppWidgetManager {
|
||||
*/
|
||||
public static final String EXTRA_CATEGORY_FILTER = "categoryFilter";
|
||||
|
||||
/**
|
||||
* An intent extra to pass to the AppWidget picker which allows the picker to filter
|
||||
* the list based on the {@link AppWidgetProviderInfo#widgetFeatures}.
|
||||
* @hide
|
||||
*/
|
||||
public static final String EXTRA_FEATURES_FILTER = "featuresFilter";
|
||||
|
||||
/**
|
||||
* An intent extra to pass to the AppWidget picker to specify whether or not to sort
|
||||
* the list of caller-specified extra AppWidgets along with the rest of the AppWidgets
|
||||
|
||||
@@ -129,6 +129,11 @@ public class LockPatternUtils {
|
||||
*/
|
||||
public static final int ID_DEFAULT_STATUS_WIDGET = -2;
|
||||
|
||||
/**
|
||||
* Intent extra that's used to tag the default widget when using the picker
|
||||
*/
|
||||
public static final String EXTRA_DEFAULT_WIDGET = "com.android.settings.DEFAULT_WIDGET";
|
||||
|
||||
protected final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently";
|
||||
protected final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline";
|
||||
protected final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen";
|
||||
|
||||
@@ -1901,6 +1901,13 @@
|
||||
android:description="@string/permdesc_bindGadget"
|
||||
android:protectionLevel="signature|system" />
|
||||
|
||||
<!-- Private permission, to restrict who can bring up a dialog to add a new
|
||||
keyguard widget
|
||||
@hide -->
|
||||
<permission android:name="android.permission.BIND_KEYGUARD_APPWIDGET"
|
||||
android:permissionGroup="android.permission-group.PERSONAL_INFO"
|
||||
android:protectionLevel="signature|system" />
|
||||
|
||||
<!-- Internal permission allowing an application to query/set which
|
||||
applications can bind AppWidgets.
|
||||
@hide -->
|
||||
|
||||
@@ -2065,6 +2065,15 @@
|
||||
<!-- This can be used in any application wanting to disable the text "Emergency number" -->
|
||||
<string name="emergency_call_dialog_number_for_display">Emergency number</string>
|
||||
|
||||
<!-- String to display if the clock status widget is selected (it is the default) [CHAR LIMIT=22] -->
|
||||
<string name="widget_default" msgid="8269383575996003796">Clock</string>
|
||||
|
||||
<!-- Package name for default widget [DO NOT TRANSLATE] -->
|
||||
<string name="widget_default_package_name">com.android.deskclock</string>
|
||||
|
||||
<!-- Class name for default widget [DO NOT TRANSLATE] -->
|
||||
<string name="widget_default_class_name">com.android.deskclock.DeskClock</string>
|
||||
|
||||
<!--
|
||||
*** touch based lock / unlock ***
|
||||
--> <skip />
|
||||
|
||||
@@ -479,6 +479,9 @@
|
||||
<java-symbol type="string" name="emailTypeOther" />
|
||||
<java-symbol type="string" name="emailTypeWork" />
|
||||
<java-symbol type="string" name="emergency_call_dialog_number_for_display" />
|
||||
<java-symbol type="string" name="widget_default" />
|
||||
<java-symbol type="string" name="widget_default_package_name" />
|
||||
<java-symbol type="string" name="widget_default_class_name" />
|
||||
<java-symbol type="string" name="emergency_calls_only" />
|
||||
<java-symbol type="string" name="enable_accessibility_canceled" />
|
||||
<java-symbol type="string" name="eventTypeAnniversary" />
|
||||
|
||||
@@ -25,19 +25,22 @@ import android.appwidget.AppWidgetHost;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
@@ -54,6 +57,7 @@ import com.android.internal.policy.impl.keyguard.KeyguardSecurityModel.SecurityM
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KeyguardHostView extends KeyguardViewBase {
|
||||
@@ -880,14 +884,22 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
mContext.startActivityAsUser(intent,
|
||||
new UserHandle(UserHandle.USER_CURRENT));
|
||||
int defaultIconId = 0;
|
||||
Resources res = KeyguardHostView.this.getContext().getResources();
|
||||
ComponentName clock = new ComponentName(
|
||||
res.getString(R.string.widget_default_package_name),
|
||||
res.getString(R.string.widget_default_class_name));
|
||||
try {
|
||||
ActivityInfo activityInfo =
|
||||
mContext.getPackageManager().getActivityInfo(clock, 0);
|
||||
if (activityInfo != null) {
|
||||
defaultIconId = activityInfo.icon;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
defaultIconId = 0;
|
||||
}
|
||||
launchPickActivityIntent(R.string.widget_default, defaultIconId, clock,
|
||||
LockPatternUtils.EXTRA_DEFAULT_WIDGET);
|
||||
}
|
||||
});
|
||||
mCallback.dismiss(false);
|
||||
@@ -898,6 +910,58 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
initializeTransportControl();
|
||||
}
|
||||
|
||||
private void launchPickActivityIntent(int defaultLabelId, int defaultIconId,
|
||||
ComponentName defaultComponentName, String defaultTag) {
|
||||
// Create intent to pick widget
|
||||
Intent pickIntent = new Intent(AppWidgetManager.ACTION_KEYGUARD_APPWIDGET_PICK);
|
||||
|
||||
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
|
||||
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);
|
||||
|
||||
// Add an custom entry for the default
|
||||
AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo();
|
||||
ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
|
||||
defaultInfo.label = getResources().getString(defaultLabelId);
|
||||
defaultInfo.icon = defaultIconId;
|
||||
defaultInfo.provider = defaultComponentName;
|
||||
extraInfos.add(defaultInfo);
|
||||
|
||||
ArrayList<Bundle> extraExtras = new ArrayList<Bundle>();
|
||||
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());
|
||||
pickIntent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
mContext.startActivityAsUser(pickIntent,
|
||||
new UserHandle(UserHandle.USER_CURRENT));
|
||||
} 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;
|
||||
}
|
||||
|
||||
private void removeTransportFromWidgetPager() {
|
||||
int page = getWidgetPosition(R.id.keyguard_transport_control);
|
||||
if (page != -1) {
|
||||
|
||||
Reference in New Issue
Block a user