summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher/Launcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher/Launcher.java')
-rw-r--r--src/com/android/launcher/Launcher.java558
1 files changed, 347 insertions, 211 deletions
diff --git a/src/com/android/launcher/Launcher.java b/src/com/android/launcher/Launcher.java
index 465400b8d..293abe808 100644
--- a/src/com/android/launcher/Launcher.java
+++ b/src/com/android/launcher/Launcher.java
@@ -24,16 +24,21 @@ import android.app.SearchManager;
import android.app.StatusBarManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.database.ContentObserver;
+import android.gadget.GadgetInfo;
+import android.gadget.GadgetManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -64,16 +69,15 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnLongClickListener;
import android.view.inputmethod.InputMethodManager;
+import android.widget.AdapterView;
import android.widget.EditText;
-import android.widget.ExpandableListView;
-import android.widget.ImageView;
+import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.GridView;
+import android.widget.SlidingDrawer;
import android.app.IWallpaperService;
-import com.android.internal.widget.SlidingDrawer;
-
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -86,8 +90,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private static final boolean PROFILE_STARTUP = false;
private static final boolean DEBUG_USER_INTERFACE = false;
- private static final boolean REMOVE_SHORTCUT_ON_PACKAGE_REMOVE = false;
-
private static final int WALLPAPER_SCREENS_SPAN = 2;
private static final int MENU_GROUP_ADD = 1;
@@ -98,9 +100,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
private static final int REQUEST_CREATE_SHORTCUT = 1;
- private static final int REQUEST_CHOOSE_PHOTO = 2;
- private static final int REQUEST_UPDATE_PHOTO = 3;
private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
+ private static final int REQUEST_CREATE_GADGET = 5;
+ private static final int REQUEST_PICK_APPLICATION = 6;
+ private static final int REQUEST_PICK_SHORTCUT = 7;
+ private static final int REQUEST_PICK_LIVE_FOLDER = 8;
+ private static final int REQUEST_PICK_GADGET = 9;
static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
@@ -148,10 +153,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private static Bitmap sWallpaper;
- // Indicates whether the OpenGL pipeline was enabled, either through
- // USE_OPENGL_BY_DEFAULT or the system property launcher.opengl
- static boolean sOpenGlEnabled;
-
private static final Object sLock = new Object();
private static int sScreen = DEFAULT_SCREN;
@@ -164,7 +165,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private DragLayer mDragLayer;
private Workspace mWorkspace;
-
+
+ private GadgetManager mGadgetManager;
+ private LauncherGadgetHost mGadgetHost;
+
+ private static final int GADGET_HOST_ID = 1024;
+
private CellLayout.CellInfo mAddItemCellInfo;
private CellLayout.CellInfo mMenuAddInfo;
private final int[] mCellCoordinates = new int[2];
@@ -189,6 +195,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mInflater = getLayoutInflater();
+
+ mGadgetManager = GadgetManager.getInstance(this);
+ mGadgetHost = new LauncherGadgetHost(this, GADGET_HOST_ID);
+
+ // TODO: figure out if this is first launch and correctly clear GadgetHost database
if (PROFILE_STARTUP) {
android.os.Debug.startMethodTracing("/sdcard/launcher");
@@ -223,6 +234,18 @@ public final class Launcher extends Activity implements View.OnClickListener, On
Selection.setSelection(mDefaultKeySsb, 0);
}
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mGadgetHost.startListening();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mGadgetHost.stopListening();
+ }
+
private void checkForLocaleChange() {
final SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
final Configuration configuration = getResources().getConfiguration();
@@ -283,20 +306,42 @@ public final class Launcher extends Activity implements View.OnClickListener, On
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // The pattern used here is that a user PICKs a specific application,
+ // which, depending on the target, might need to CREATE the actual target.
+
+ // For example, the user would PICK_SHORTCUT for "Music playlist", and we
+ // launch over to the Music app to actually CREATE_SHORTCUT.
+
if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
switch (requestCode) {
+ case REQUEST_PICK_APPLICATION:
+ completeAddApplication(this, data, mAddItemCellInfo);
+ break;
+ case REQUEST_PICK_SHORTCUT:
+ addShortcut(data);
+ break;
case REQUEST_CREATE_SHORTCUT:
completeAddShortcut(data, mAddItemCellInfo, !mDesktopLocked);
break;
- case REQUEST_CHOOSE_PHOTO:
- completeAddPhotoFrame(data, mAddItemCellInfo);
- break;
- case REQUEST_UPDATE_PHOTO:
- completeUpdatePhotoFrame(data, mAddItemCellInfo);
+ case REQUEST_PICK_LIVE_FOLDER:
+ addLiveFolder(data);
break;
case REQUEST_CREATE_LIVE_FOLDER:
completeAddLiveFolder(data, mAddItemCellInfo, !mDesktopLocked);
break;
+ case REQUEST_PICK_GADGET:
+ addGadget(data);
+ break;
+ case REQUEST_CREATE_GADGET:
+ completeAddGadget(data, mAddItemCellInfo, !mDesktopLocked);
+ break;
+ }
+ } else if (requestCode == REQUEST_PICK_GADGET &&
+ resultCode == RESULT_CANCELED && data != null) {
+ // Clean up the gadgetId if we canceled
+ int gadgetId = data.getIntExtra(GadgetManager.EXTRA_GADGET_ID, -1);
+ if (gadgetId != -1) {
+ mGadgetHost.deleteGadgetId(gadgetId);
}
}
mWaitingForResult = false;
@@ -398,7 +443,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mRestoring = true;
}
-
boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
if (renameFolder) {
long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
@@ -439,10 +483,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
grid.setTextFilterEnabled(true);
grid.setDragger(dragLayer);
grid.setLauncher(this);
- if (sOpenGlEnabled) {
- grid.setScrollingCacheEnabled(false);
- grid.setFadingEdgeLength(0);
- }
workspace.setOnLongClickListener(this);
workspace.setDragger(dragLayer);
@@ -456,18 +496,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
dragLayer.setIgnoredDropTarget(grid);
dragLayer.setDragScoller(workspace);
dragLayer.setDragListener(deleteZone);
-
- if (DEBUG_USER_INTERFACE) {
- android.widget.Button finishButton = new android.widget.Button(this);
- finishButton.setText("Finish");
- workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
-
- finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
- public void onClick(View v) {
- finish();
- }
- });
- }
}
/**
@@ -507,11 +535,42 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return favorite;
}
- void addApplicationShortcut(ApplicationInfo info) {
- mAddItemCellInfo.screen = mWorkspace.getCurrentScreen();
- mWorkspace.addApplicationShortcut(info, mAddItemCellInfo);
- }
+ /**
+ * Add an application shortcut to the workspace.
+ *
+ * @param data The intent describing the application.
+ * @param cellInfo The position on screen where to create the shortcut.
+ */
+ void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
+ cellInfo.screen = mWorkspace.getCurrentScreen();
+ // Find details for this application
+ ComponentName component = data.getComponent();
+ PackageManager packageManager = context.getPackageManager();
+ ActivityInfo activityInfo = null;
+ try {
+ activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
+ }
+
+ if (activityInfo != null) {
+ ApplicationInfo itemInfo = new ApplicationInfo();
+
+ itemInfo.title = activityInfo.loadLabel(packageManager);
+ if (itemInfo.title == null) {
+ itemInfo.title = activityInfo.name;
+ }
+
+ itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ itemInfo.icon = activityInfo.loadIcon(packageManager);
+ itemInfo.container = ItemInfo.NO_ID;
+
+ mWorkspace.addApplicationShortcut(itemInfo, mAddItemCellInfo);
+ }
+ }
+
/**
* Add a shortcut to the workspace.
*
@@ -535,6 +594,74 @@ public final class Launcher extends Activity implements View.OnClickListener, On
}
}
+
+ /**
+ * Add a gadget to the workspace.
+ *
+ * @param data The intent describing the gadgetId.
+ * @param cellInfo The position on screen where to create the shortcut.
+ * @param insertAtFirst
+ */
+ private void completeAddGadget(Intent data, CellLayout.CellInfo cellInfo,
+ boolean insertAtFirst) {
+
+ Bundle extras = data.getExtras();
+ int gadgetId = extras.getInt(GadgetManager.EXTRA_GADGET_ID, -1);
+
+ Log.d(LOG_TAG, "dumping extras content="+extras.toString());
+
+ GadgetInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
+
+ // Calculate the grid spans needed to fit this gadget
+ CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
+ layout.rectToCell(gadgetInfo.minWidth, gadgetInfo.minHeight, cellInfo);
+
+ // Try finding open space on Launcher screen
+ final int[] xy = mCellCoordinates;
+ if (!findSlot(cellInfo, xy, cellInfo.spanX, cellInfo.spanY)) return;
+
+ // Build Launcher-specific Gadget info and save to database
+ LauncherGadgetInfo launcherInfo = new LauncherGadgetInfo(gadgetId);
+ launcherInfo.spanX = cellInfo.spanX;
+ launcherInfo.spanY = cellInfo.spanY;
+
+ LauncherModel.addItemToDatabase(this, launcherInfo,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
+
+ if (!mRestoring) {
+ sModel.addDesktopItem(launcherInfo);
+
+ // Perform actual inflation because we're live
+ launcherInfo.hostView = mGadgetHost.createView(this, gadgetId, gadgetInfo);
+
+ launcherInfo.hostView.setGadget(gadgetId, gadgetInfo);
+ launcherInfo.hostView.setTag(launcherInfo);
+
+ mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
+ launcherInfo.spanX, launcherInfo.spanY, insertAtFirst);
+ } else if (sModel.isDesktopLoaded()) {
+ sModel.addDesktopItem(launcherInfo);
+ }
+
+ // Request fresh update if we needed to config this gadget to
+ // remove the stale UPDATE from the initial bind
+ if (!extras.containsKey(SKIP_CONFIG) || true) {
+ // TODO: move this down into GadgetManager to prevent abuse? (anyone
+ // could force a specific gadget into the ground through flooding)
+ Log.d(LOG_TAG, "requesting new gadget update because we had a config step");
+ Intent intent = new Intent(GadgetManager.GADGET_UPDATE_ACTION);
+ intent.putExtra(GadgetManager.EXTRA_GADGET_IDS, new int[] { gadgetId });
+ intent.setComponent(gadgetInfo.provider);
+ sendBroadcast(intent);
+ }
+
+ }
+
+ public LauncherGadgetHost getGadgetHost() {
+ return mGadgetHost;
+ }
+
static ApplicationInfo addShortcut(Context context, Intent data,
CellLayout.CellInfo cellInfo, boolean notify) {
@@ -584,107 +711,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return info;
}
- /**
- * Add a PhotFrame to the workspace.
- *
- * @param data The intent describing the photo.
- * @param cellInfo The position on screen where to create the shortcut.
- */
- private void completeAddPhotoFrame(Intent data, CellLayout.CellInfo cellInfo) {
- final Bundle extras = data.getExtras();
- if (extras != null) {
- Bitmap photo = extras.getParcelable("data");
-
- Widget info = Widget.makePhotoFrame();
- info.photo = photo;
-
- final int[] xy = mCellCoordinates;
- if (!findSlot(cellInfo, xy, info.spanX, info.spanY)) return;
-
- LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
- mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
-
- if (!mRestoring) {
- sModel.addDesktopItem(info);
-
- final PhotoFrame view = (PhotoFrame) mInflater.inflate(info.layoutResource, null);
- view.setImageBitmap(photo);
- view.setTag(info);
-
- mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, info.spanY);
- } else if (sModel.isDesktopLoaded()) {
- sModel.addDesktopItem(info);
- }
- }
- }
-
- /**
- * Updates a workspace PhotoFrame.
- *
- * @param data The intent describing the photo.
- * @param cellInfo The position on screen of the PhotoFrame to update.
- */
- private void completeUpdatePhotoFrame(Intent data, CellLayout.CellInfo cellInfo) {
- final Bundle extras = data.getExtras();
- if (extras != null) {
- Widget info;
- Bitmap photo = extras.getParcelable("data");
-
- if (!mRestoring) {
- final CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
- final PhotoFrame view = (PhotoFrame) layout.findCell(cellInfo.cellX, cellInfo.cellY,
- cellInfo.spanX, cellInfo.spanY, null);
- view.setImageBitmap(photo);
- info = (Widget) view.getTag();
- } else {
- info = LauncherModel.getPhotoFrameInfo(this, cellInfo.screen,
- cellInfo.cellX, cellInfo.cellY);
- }
-
- info.photo = photo;
- LauncherModel.updateItemInDatabase(this, info);
- }
- }
-
- /**
- * Starts a new Intent to let the user update the PhotoFrame defined by the
- * specified Widget.
- *
- * @param widget The Widget info defining which PhotoFrame to update.
- */
- void updatePhotoFrame(Widget widget) {
- CellLayout.CellInfo info = new CellLayout.CellInfo();
- info.screen = widget.screen;
- info.cellX = widget.cellX;
- info.cellY = widget.cellY;
- info.spanX = widget.spanX;
- info.spanY = widget.spanY;
- mAddItemCellInfo = info;
-
- startActivityForResult(createPhotoPickIntent(), Launcher.REQUEST_UPDATE_PHOTO);
- }
-
- /**
- * Creates an Intent used to let the user pick a photo for a PhotoFrame.
- *
- * @return The Intent to pick a photo suited for a PhotoFrame.
- */
- private static Intent createPhotoPickIntent() {
- // TODO: Move this method to PhotoFrame?
- // TODO: get these values from constants somewhere
- // TODO: Adjust the PhotoFrame's image size to avoid on the fly scaling
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
- intent.setType("image/*");
- intent.putExtra("crop", "true");
- intent.putExtra("aspectX", 1);
- intent.putExtra("aspectY", 1);
- intent.putExtra("outputX", 192);
- intent.putExtra("outputY", 192);
- intent.putExtra("noFaceDetection", true);
- intent.putExtra("return-data", true);
- return intent;
- }
-
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -871,10 +897,51 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private void removeShortcutsForPackage(String packageName) {
if (packageName != null && packageName.length() > 0) {
- android.util.Log.d(LOG_TAG, packageName);
mWorkspace.removeShortcutsForPackage(packageName);
}
}
+
+ static final String SKIP_CONFIG = "skip_config";
+
+ void addGadget(Intent data) {
+ int gadgetId = data.getIntExtra(GadgetManager.EXTRA_GADGET_ID, -1);
+ GadgetInfo gadget = mGadgetManager.getGadgetInfo(gadgetId);
+
+ if (gadget.configure != null) {
+ // Launch over to configure gadget, if needed
+ Intent intent = new Intent(GadgetManager.GADGET_CONFIGURE_ACTION);
+ intent.setComponent(gadget.configure);
+ intent.putExtra(GadgetManager.EXTRA_GADGET_ID, gadgetId);
+
+ startActivityForResult(intent, REQUEST_CREATE_GADGET);
+ } else {
+ // Otherwise just add it
+ Log.d(LOG_TAG, "dumping extras content="+data.getExtras().toString());
+ data.putExtra(SKIP_CONFIG, true);
+ Log.d(LOG_TAG, "dumping extras content="+data.getExtras().toString());
+ onActivityResult(REQUEST_CREATE_GADGET, Activity.RESULT_OK, data);
+ }
+ }
+
+ void addSearch() {
+ final Widget info = Widget.makeSearch();
+ final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
+
+ final int[] xy = mCellCoordinates;
+ final int spanX = info.spanX;
+ final int spanY = info.spanY;
+
+ if (!findSlot(cellInfo, xy, spanX, spanY)) return;
+
+ sModel.addDesktopItem(info);
+ LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
+
+ final View view = mInflater.inflate(info.layoutResource, null);
+ view.setTag(info);
+
+ mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
+ }
void addShortcut(Intent intent) {
startActivityForResult(intent, REQUEST_CREATE_SHORTCUT);
@@ -964,39 +1031,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return info;
}
- void getPhotoForPhotoFrame() {
- startActivityForResult(createPhotoPickIntent(), REQUEST_CHOOSE_PHOTO);
- }
-
- void addClock() {
- final Widget info = Widget.makeClock();
- addWidget(info);
- }
-
- void addSearch() {
- final Widget info = Widget.makeSearch();
- addWidget(info);
- }
-
- private void addWidget(final Widget info) {
- final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
-
- final int[] xy = mCellCoordinates;
- final int spanX = info.spanX;
- final int spanY = info.spanY;
-
- if (!findSlot(cellInfo, xy, spanX, spanY)) return;
-
- sModel.addDesktopItem(info);
- LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
- mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
-
- final View view = mInflater.inflate(info.layoutResource, null);
- view.setTag(info);
-
- mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
- }
-
private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
boolean[] occupied = mSavedState != null ?
@@ -1136,6 +1170,18 @@ public final class Launcher extends Activity implements View.OnClickListener, On
for (int i = 0; i < count; i++) {
((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
}
+
+ if (DEBUG_USER_INTERFACE) {
+ android.widget.Button finishButton = new android.widget.Button(this);
+ finishButton.setText("Finish");
+ workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
+
+ finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ }
count = shortcuts.size();
@@ -1176,11 +1222,41 @@ public final class Launcher extends Activity implements View.OnClickListener, On
workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
!desktopLocked);
break;
- default:
+ case LauncherSettings.Favorites.ITEM_TYPE_GADGET:
+ final LauncherGadgetInfo launcherInfo = (LauncherGadgetInfo) item;
+
+ final int gadgetId = launcherInfo.gadgetId;
+ GadgetInfo gadgetInfo = mGadgetManager.getGadgetInfo(gadgetId);
+ launcherInfo.hostView = mGadgetHost.createView(this, gadgetId, gadgetInfo);
+
+ Log.d(LOG_TAG, "about to setGadget during desktop bind");
+ launcherInfo.hostView.setGadget(gadgetId, gadgetInfo);
+ launcherInfo.hostView.setTag(launcherInfo);
+
+ workspace.addInScreen(launcherInfo.hostView, item.screen, item.cellX,
+ item.cellY, item.spanX, item.spanY, !desktopLocked);
+
+ // Now that we've bound the item, request an update for it
+ if (gadgetInfo != null) {
+ if (gadgetInfo.provider != null) {
+ Intent intent = new Intent(GadgetManager.GADGET_UPDATE_ACTION);
+ intent.putExtra(GadgetManager.EXTRA_GADGET_IDS, new int[] { gadgetId });
+ intent.setComponent(gadgetInfo.provider);
+ sendBroadcast(intent);
+ }
+ }
+
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
+ final int screen = workspace.getCurrentScreen();
+ final View view = mInflater.inflate(R.layout.widget_search,
+ (ViewGroup) workspace.getChildAt(screen), false);
+
final Widget widget = (Widget) item;
- final View view = createWidget(mInflater, widget);
view.setTag(widget);
+
workspace.addWidget(view, widget, !desktopLocked);
+ break;
}
}
@@ -1226,17 +1302,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDrawer.unlock();
}
- private View createWidget(LayoutInflater inflater, Widget widget) {
- final Workspace workspace = mWorkspace;
- final int screen = workspace.getCurrentScreen();
- View v = inflater.inflate(widget.layoutResource,
- (ViewGroup) workspace.getChildAt(screen), false);
- if (widget.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME) {
- ((ImageView)v).setImageBitmap(widget.photo);
- }
- return v;
- }
-
DragController getDragController() {
return mDragLayer;
}
@@ -1263,6 +1328,11 @@ public final class Launcher extends Activity implements View.OnClickListener, On
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
+ } catch (SecurityException e) {
+ Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
+ Log.e(LOG_TAG, "Launcher does not have the permission to launch " + intent +
+ ". Make sure to create a MAIN intent-filter for the corresponding activity " +
+ "or use the exported attribute for this activity.", e);
}
}
@@ -1508,24 +1578,24 @@ public final class Launcher extends Activity implements View.OnClickListener, On
* Displays the shortcut creation dialog and launches, if necessary, the
* appropriate activity.
*/
- private class CreateShortcut implements ExpandableListView.OnChildClickListener,
- DialogInterface.OnCancelListener, ExpandableListView.OnGroupExpandListener {
+ private class CreateShortcut implements AdapterView.OnItemClickListener,
+ DialogInterface.OnCancelListener {
private AddAdapter mAdapter;
- private ExpandableListView mList;
-
+ private ListView mList;
+
Dialog createDialog() {
mWaitingForResult = true;
- mAdapter = new AddAdapter(Launcher.this, false);
+
+ mAdapter = new AddAdapter(Launcher.this);
final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
builder.setTitle(getString(R.string.menu_item_add_item));
builder.setIcon(0);
- mList = (ExpandableListView)
+ mList = (ListView)
View.inflate(Launcher.this, R.layout.create_shortcut_list, null);
mList.setAdapter(mAdapter);
- mList.setOnChildClickListener(this);
- mList.setOnGroupExpandListener(this);
+ mList.setOnItemClickListener(this);
builder.setView(mList);
builder.setInverseBackgroundForced(true);
@@ -1539,13 +1609,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return dialog;
}
- public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
- int childPosition, long id) {
- mAdapter.performAction(groupPosition, childPosition);
- cleanup();
- return true;
- }
-
public void onCancel(DialogInterface dialog) {
mWaitingForResult = false;
cleanup();
@@ -1556,10 +1619,76 @@ public final class Launcher extends Activity implements View.OnClickListener, On
dismissDialog(DIALOG_CREATE_SHORTCUT);
}
- public void onGroupExpand(int groupPosition) {
- long packged = ExpandableListView.getPackedPositionForGroup(groupPosition);
- int position = mList.getFlatListPosition(packged);
- mList.setSelectionFromTop(position, 0);
+ public void onItemClick(AdapterView parent, View view, int position, long id) {
+ // handle which item was clicked based on position
+ // this will launch off pick intent
+
+ Object tag = view.getTag();
+ if (tag instanceof AddAdapter.ListItem) {
+ AddAdapter.ListItem item = (AddAdapter.ListItem) tag;
+ cleanup();
+ switch (item.actionTag) {
+ case AddAdapter.ITEM_APPLICATION: {
+ Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
+ startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
+ break;
+ }
+
+ case AddAdapter.ITEM_SHORTCUT: {
+ Intent shortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT, shortcutIntent);
+ pickIntent.putExtra(Intent.EXTRA_TITLE,
+ getText(R.string.title_select_shortcut));
+ startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
+ break;
+ }
+
+ case AddAdapter.ITEM_SEARCH: {
+ addSearch();
+ break;
+ }
+
+ case AddAdapter.ITEM_GADGET: {
+ int gadgetId = Launcher.this.mGadgetHost.allocateGadgetId();
+
+ Intent pickIntent = new Intent(GadgetManager.GADGET_PICK_ACTION);
+ pickIntent.putExtra(GadgetManager.EXTRA_HOST_ID, GADGET_HOST_ID);
+ pickIntent.putExtra(GadgetManager.EXTRA_GADGET_ID, gadgetId);
+ startActivityForResult(pickIntent, REQUEST_PICK_GADGET);
+ break;
+ }
+
+ case AddAdapter.ITEM_LIVE_FOLDER: {
+ Intent liveFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT, liveFolderIntent);
+ pickIntent.putExtra(Intent.EXTRA_TITLE,
+ getText(R.string.title_select_live_folder));
+ startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
+ break;
+ }
+
+ case AddAdapter.ITEM_FOLDER: {
+ addFolder();
+ dismissDialog(DIALOG_CREATE_SHORTCUT);
+ break;
+ }
+
+ case AddAdapter.ITEM_WALLPAPER: {
+ startWallpaper();
+ break;
+ }
+
+ }
+
+ }
}
}
@@ -1569,13 +1698,20 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private class ApplicationsIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- //noinspection ConstantConditions
- if (REMOVE_SHORTCUT_ON_PACKAGE_REMOVE &&
- Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
- removeShortcutsForPackage(intent.getData().getSchemeSpecificPart());
+ boolean reloadWorkspace = false;
+ if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
+ if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
+ removeShortcutsForPackage(intent.getData().getSchemeSpecificPart());
+ } else {
+ reloadWorkspace = true;
+ }
}
removeDialog(DIALOG_CREATE_SHORTCUT);
- sModel.loadApplications(false, Launcher.this, false);
+ if (!reloadWorkspace) {
+ sModel.loadApplications(false, Launcher.this, false);
+ } else {
+ sModel.loadUserItems(false, Launcher.this, false, true);
+ }
}
}