Merge change I3134655d into eclair

* changes:
  More capabilities for default home configuration
This commit is contained in:
Android (Google) Code Review
2009-10-30 20:00:04 -04:00
2 changed files with 96 additions and 5 deletions
+5
View File
@@ -76,5 +76,10 @@
<attr name="screen" format="string" />
<attr name="x" format="string" />
<attr name="y" format="string" />
<attr name="spanX" format="string" />
<attr name="spanY" format="string" />
<attr name="icon" format="reference" />
<attr name="title" format="reference" />
<attr name="uri" format="string" />
</declare-styleable>
</resources>
@@ -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.