Merge "Sending broadcast for pre-configuring default workspace widgets." into jb-dev
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -1541,34 +1541,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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user