summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-05-01 10:19:14 -0700
committerWinson Chung <winsonc@google.com>2012-05-01 10:59:59 -0700
commitb3302aee121b46f97aa7afc7e5e2f58f3309aa9b (patch)
treedf2742714e7673f711d22be3973bd45ca0afc713
parentd7c28056d3fc462f42b508026154d6d8fee5606b (diff)
downloadandroid_packages_apps_Trebuchet-b3302aee121b46f97aa7afc7e5e2f58f3309aa9b.tar.gz
android_packages_apps_Trebuchet-b3302aee121b46f97aa7afc7e5e2f58f3309aa9b.tar.bz2
android_packages_apps_Trebuchet-b3302aee121b46f97aa7afc7e5e2f58f3309aa9b.zip
Sending broadcast for pre-configuring default workspace widgets.
Change-Id: I3c5598b9a2cec6cdcc96015645018b0a6e44a2fc
-rw-r--r--res/values/attrs.xml4
-rw-r--r--src/com/android/launcher2/Launcher.java28
-rw-r--r--src/com/android/launcher2/LauncherProvider.java54
3 files changed, 51 insertions, 35 deletions
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 9ed824b44..cd939db0f 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -171,4 +171,8 @@
<attr name="title" format="reference" />
<attr name="uri" format="string" />
</declare-styleable>
+ <declare-styleable name="Extra">
+ <attr name="key" format="string" />
+ <attr name="value" format="string" />
+ </declare-styleable>
</resources>
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 028a4515a..93f3782de 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1534,34 +1534,6 @@ public final class Launcher extends Activity
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.setComponent(appWidget.configure);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- if (info != null) {
- if (info.mimeType != null && !info.mimeType.isEmpty()) {
- intent.putExtra(InstallWidgetReceiver.
- EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
-
- final String mimeType = info.mimeType;
- final ClipData clipData = (ClipData) info.configurationData;
- final ClipDescription clipDesc = clipData.getDescription();
- for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
- if (clipDesc.getMimeType(i).equals(mimeType)) {
- final ClipData.Item item = clipData.getItemAt(i);
- final CharSequence stringData = item.getText();
- final Uri uriData = item.getUri();
- final Intent intentData = item.getIntent();
- final String key = InstallWidgetReceiver.
- EXTRA_APPWIDGET_CONFIGURATION_DATA;
- if (uriData != null) {
- intent.putExtra(key, uriData);
- } else if (intentData != null) {
- intent.putExtra(key, intentData);
- } else if (stringData != null) {
- intent.putExtra(key, stringData);
- }
- break;
- }
- }
- }
- }
startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
mWidgetBeingBoundOrConfigured = info;
} else {
diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java
index 297c097e9..5e572a575 100644
--- a/src/com/android/launcher2/LauncherProvider.java
+++ b/src/com/android/launcher2/LauncherProvider.java
@@ -42,6 +42,7 @@ import android.database.sqlite.SQLiteStatement;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -74,6 +75,9 @@ public class LauncherProvider extends ContentProvider {
static final String DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED =
"DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED";
+ private static final String ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE =
+ "com.android.launcher.action.APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE";
+
/**
* {@link Uri} triggered at any registered {@link android.database.ContentObserver} when
* {@link AppWidgetHost#deleteHost()} is called during database creation.
@@ -219,6 +223,7 @@ public class LauncherProvider extends ContentProvider {
private static final String TAG_APPWIDGET = "appwidget";
private static final String TAG_SHORTCUT = "shortcut";
private static final String TAG_FOLDER = "folder";
+ private static final String TAG_EXTRA = "extra";
private final Context mContext;
private final AppWidgetHost mAppWidgetHost;
@@ -820,7 +825,7 @@ public class LauncherProvider extends ContentProvider {
} else if (TAG_CLOCK.equals(name)) {
added = addClockWidget(db, values);
} else if (TAG_APPWIDGET.equals(name)) {
- added = addAppWidget(db, values, a, packageManager);
+ added = addAppWidget(parser, attrs, type, db, values, a, packageManager);
} else if (TAG_SHORTCUT.equals(name)) {
long id = addUriShortcut(db, values, a);
added = id >= 0;
@@ -972,17 +977,18 @@ public class LauncherProvider extends ContentProvider {
private boolean addSearchWidget(SQLiteDatabase db, ContentValues values) {
ComponentName cn = getSearchWidgetProvider();
- return addAppWidget(db, values, cn, 4, 1);
+ return addAppWidget(db, values, cn, 4, 1, null);
}
private boolean addClockWidget(SQLiteDatabase db, ContentValues values) {
ComponentName cn = new ComponentName("com.android.alarmclock",
"com.android.alarmclock.AnalogAppWidgetProvider");
- return addAppWidget(db, values, cn, 2, 2);
+ return addAppWidget(db, values, cn, 2, 2, null);
}
- private boolean addAppWidget(SQLiteDatabase db, ContentValues values, TypedArray a,
- PackageManager packageManager) {
+ private boolean addAppWidget(XmlResourceParser parser, AttributeSet attrs, int type,
+ SQLiteDatabase db, ContentValues values, TypedArray a,
+ PackageManager packageManager) throws XmlPullParserException, IOException {
String packageName = a.getString(R.styleable.Favorite_packageName);
String className = a.getString(R.styleable.Favorite_className);
@@ -1009,14 +1015,39 @@ public class LauncherProvider extends ContentProvider {
if (hasPackage) {
int spanX = a.getInt(R.styleable.Favorite_spanX, 0);
int spanY = a.getInt(R.styleable.Favorite_spanY, 0);
- return addAppWidget(db, values, cn, spanX, spanY);
+
+ // Read the extras
+ Bundle extras = new Bundle();
+ int widgetDepth = parser.getDepth();
+ while ((type = parser.next()) != XmlPullParser.END_TAG ||
+ parser.getDepth() > widgetDepth) {
+ if (type != XmlPullParser.START_TAG) {
+ continue;
+ }
+
+ TypedArray ar = mContext.obtainStyledAttributes(attrs, R.styleable.Extra);
+ if (TAG_EXTRA.equals(parser.getName())) {
+ String key = ar.getString(R.styleable.Extra_key);
+ String value = ar.getString(R.styleable.Extra_value);
+ if (key != null && value != null) {
+ extras.putString(key, value);
+ } else {
+ throw new RuntimeException("Widget extras must have a key and value");
+ }
+ } else {
+ throw new RuntimeException("Widgets can contain only extras");
+ }
+ ar.recycle();
+ }
+
+ return addAppWidget(db, values, cn, spanX, spanY, extras);
}
return false;
}
private boolean addAppWidget(SQLiteDatabase db, ContentValues values, ComponentName cn,
- int spanX, int spanY) {
+ int spanX, int spanY, Bundle extras) {
boolean allocatedAppWidgets = false;
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
@@ -1034,6 +1065,15 @@ public class LauncherProvider extends ContentProvider {
// TODO: need to check return value
appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn);
+
+ // Send a broadcast to configure the widget
+ if (extras != null && !extras.isEmpty()) {
+ Intent intent = new Intent(ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE);
+ intent.setComponent(cn);
+ intent.putExtras(extras);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+ mContext.sendBroadcast(intent);
+ }
} catch (RuntimeException ex) {
Log.e(TAG, "Problem allocating appWidgetId", ex);
}