diff options
author | Mike Cleron <mcleron@google.com> | 2009-10-30 16:36:56 -0700 |
---|---|---|
committer | Mike Cleron <mcleron@google.com> | 2009-10-30 16:36:56 -0700 |
commit | b87bd16c8e3f88a9ba78ed00c9f150b38dc39f33 (patch) | |
tree | bf16f6b3f5ad124d675f03c53c1b90feec36cb96 /src/com/android/launcher2/LauncherProvider.java | |
parent | c85147968fa0e1aee86aa88c01a325269b6f907b (diff) | |
download | packages_apps_trebuchet-b87bd16c8e3f88a9ba78ed00c9f150b38dc39f33.zip packages_apps_trebuchet-b87bd16c8e3f88a9ba78ed00c9f150b38dc39f33.tar.gz packages_apps_trebuchet-b87bd16c8e3f88a9ba78ed00c9f150b38dc39f33.tar.bz2 |
More capabilities for default home configuration
Added support for adding appwidgets beyond clock and search to the
intital configuration. Also pulled in a previous change in Launcher that
allowed http shortcuts. New syntax looks like this in
default_workspace.xml:
<appwidget
launcher:packageName="com.android.settings"
launcher:className="com.android.settings.widget.SettingsAppWidgetProvider"
launcher:screen="0"
launcher:x="0"
launcher:y="2"
launcher:spanX="4"
launcher:spanY="1" />
<shortcut
launcher:packageName="com.android.settings"
launcher:icon="@drawable/ic_launcher_appwidget"
launcher:title="@string/group_folder"
launcher:uri="http://www.nytimes.com"
launcher:screen="2"
launcher:x="2"
launcher:y="2" />
Diffstat (limited to 'src/com/android/launcher2/LauncherProvider.java')
-rw-r--r-- | src/com/android/launcher2/LauncherProvider.java | 96 |
1 files changed, 91 insertions, 5 deletions
diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java index dff72a2..9226c22 100644 --- a/src/com/android/launcher2/LauncherProvider.java +++ b/src/com/android/launcher2/LauncherProvider.java @@ -17,6 +17,7 @@ package com.android.launcher2; import android.appwidget.AppWidgetHost; +import android.appwidget.AppWidgetManager; import android.content.ContentProvider; import android.content.Context; import android.content.ContentValues; @@ -24,6 +25,7 @@ import android.content.Intent; import android.content.ComponentName; import android.content.ContentUris; import android.content.ContentResolver; +import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.content.res.TypedArray; import android.content.pm.PackageManager; @@ -42,6 +44,7 @@ import android.os.*; import android.provider.Settings; import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import org.xmlpull.v1.XmlPullParserException; @@ -175,7 +178,9 @@ public class LauncherProvider extends ContentProvider { private static final String TAG_FAVORITE = "favorite"; private static final String TAG_CLOCK = "clock"; private static final String TAG_SEARCH = "search"; - + private static final String TAG_APPWIDGET = "appwidget"; + private static final String TAG_SHORTCUT = "shortcut"; + private final Context mContext; private final AppWidgetHost mAppWidgetHost; @@ -531,11 +536,15 @@ public class LauncherProvider extends ContentProvider { a.getString(R.styleable.Favorite_y)); if (TAG_FAVORITE.equals(name)) { - added = addShortcut(db, values, a, packageManager, intent); + added = addAppShortcut(db, values, a, packageManager, intent); } else if (TAG_SEARCH.equals(name)) { added = addSearchWidget(db, values); } else if (TAG_CLOCK.equals(name)) { added = addClockWidget(db, values); + } else if (TAG_APPWIDGET.equals(name)) { + added = addAppWidget(db, values, a); + } else if (TAG_SHORTCUT.equals(name)) { + added = addUriShortcut(db, values, a); } if (added) i++; @@ -551,7 +560,7 @@ public class LauncherProvider extends ContentProvider { return i; } - private boolean addShortcut(SQLiteDatabase db, ContentValues values, TypedArray a, + private boolean addAppShortcut(SQLiteDatabase db, ContentValues values, TypedArray a, PackageManager packageManager, Intent intent) { ActivityInfo info; @@ -597,7 +606,7 @@ public class LauncherProvider extends ContentProvider { "com.android.alarmclock.AnalogAppWidgetProvider")); boolean allocatedAppWidgets = false; - + // Try binding to an analog clock widget try { int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); @@ -620,8 +629,85 @@ public class LauncherProvider extends ContentProvider { return allocatedAppWidgets; } - } + + private boolean addAppWidget(SQLiteDatabase db, ContentValues values, TypedArray a) { + final int[] bindSources = new int[] { + Favorites.ITEM_TYPE_APPWIDGET, + }; + + String packageName = a.getString(R.styleable.Favorite_packageName); + String className = a.getString(R.styleable.Favorite_className); + + if (packageName == null || className == null) { + return false; + } + + ComponentName cn = new ComponentName(packageName, className); + + final ArrayList<ComponentName> bindTargets = new ArrayList<ComponentName>(); + bindTargets.add(cn); + boolean allocatedAppWidgets = false; + final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); + + try { + int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); + + values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET); + values.put(Favorites.SPANX, a.getString(R.styleable.Favorite_spanX)); + values.put(Favorites.SPANY, a.getString(R.styleable.Favorite_spanY)); + values.put(Favorites.APPWIDGET_ID, appWidgetId); + db.insert(TABLE_FAVORITES, null, values); + + allocatedAppWidgets = true; + + appWidgetManager.bindAppWidgetId(appWidgetId, cn); + } catch (RuntimeException ex) { + Log.e(LOG_TAG, "Problem allocating appWidgetId", ex); + } + + return allocatedAppWidgets; + } + + private boolean addUriShortcut(SQLiteDatabase db, ContentValues values, + TypedArray a) { + Resources r = mContext.getResources(); + + final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0); + final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0); + + Intent intent = null; + String uri = null; + try { + uri = a.getString(R.styleable.Favorite_uri); + intent = Intent.parseUri(uri, 0); + } catch (URISyntaxException e) { + Log.w(LauncherModel.TAG, "Shortcut has malformed uri: " + uri); + return false; // Oh well + } + + if (iconResId == 0 || titleResId == 0) { + Log.w(LauncherModel.TAG, + "Shortcut is missing title or icon resource ID"); + return false; + } + + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + values.put(Favorites.INTENT, intent.toUri(0)); + values.put(Favorites.TITLE, r.getString(titleResId)); + values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_SHORTCUT); + values.put(Favorites.SPANX, 1); + values.put(Favorites.SPANY, 1); + values.put(Favorites.ICON_TYPE, Favorites.ICON_TYPE_RESOURCE); + values.put(Favorites.ICON_PACKAGE, mContext.getPackageName()); + values.put(Favorites.ICON_RESOURCE, r.getResourceName(iconResId)); + + db.insert(TABLE_FAVORITES, null, values); + + return true; + } + } + /** * Build a query string that will match any row where the column matches * anything in the values list. |