summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/trebuchet/Launcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/cyanogenmod/trebuchet/Launcher.java')
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java416
1 files changed, 55 insertions, 361 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index 951fbe4f3..a65d4cf6a 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -30,7 +30,6 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.SearchManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
@@ -56,7 +55,6 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
@@ -150,14 +148,9 @@ public final class Launcher extends Activity
static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
- static final String ACTION_LAUNCHER = "com.cyanogenmod.trebuchet.LAUNCHER_ACTION";
-
static final int MAX_SCREEN_COUNT = 7;
static final int DEFAULT_SCREEN = 2;
- static final int DIALOG_CREATE_SHORTCUT = 1;
- static final int DIALOG_CREATE_ACTION = 2;
-
private static final String PREFERENCES = "launcher.preferences";
static final String DUMP_STATE_PROPERTY = "debug.dumpstate";
@@ -613,10 +606,6 @@ public final class Launcher extends Activity
args.cellY);
result = true;
break;
- case REQUEST_PICK_APPWIDGET:
- addAppWidgetFromPick(args.intent, args.container, args.screen);
- // Don't remove pending add info
- return false;
case REQUEST_CREATE_APPWIDGET:
int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
@@ -647,8 +636,24 @@ public final class Launcher extends Activity
return;
}
boolean delayExitSpringLoadedMode = false;
+ boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
+ requestCode == REQUEST_CREATE_APPWIDGET);
mWaitingForResult = false;
+ // We have special handling for widgets
+ if (isWidgetDrop) {
+ int appWidgetId = data != null ?
+ data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
+ if (appWidgetId < 0) {
+ Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
+ "widget configuration activity.");
+ completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
+ } else {
+ completeTwoStageWidgetDrop(resultCode, appWidgetId);
+ }
+ return;
+ }
+
// The pattern used here is that a user PICKs a specific application,
// which, depending on the target, might need to CREATE the actual target.
@@ -1222,63 +1227,6 @@ public final class Launcher extends Activity
resetAddInfo();
}
- private void addAction(LauncherAction.Action action) {
- int[] cellXY = mPendingAddInfo.dropPos;
- int cellX = mPendingAddInfo.cellX;
- int cellY = mPendingAddInfo.cellY;
- long container = mPendingAddInfo.container;
- int screen = mPendingAddInfo.screen;
- CellLayout layout = getCellLayout(container, screen);
-
- boolean foundCellSpan;
-
- LauncherActionInfo info = new LauncherActionInfo();
- info.action = action;
- info.title = getResources().getString(action.getString());
- info.setIcon(((BitmapDrawable)getResources().getDrawable(action.getDrawable())).getBitmap());
-
- final View view = createShortcut(info);
-
- if (cellX >= 0 && cellY >= 0) {
- if (cellXY == null) {
- cellXY = new int[2];
- }
- cellXY[0] = cellX;
- cellXY[1] = cellY;
-
- foundCellSpan = true;
-
- // If appropriate, either create a folder or add to an existing folder
- if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
- true, null,null)) {
- return;
- }
- DragObject dragObject = new DragObject();
- dragObject.dragInfo = info;
- if (mWorkspace.addToExistingFolderIfNecessary(layout, cellXY, 0, dragObject,
- true)) {
- return;
- }
- } else if (cellXY != null) {
- // when dragging and dropping, just find the closest free spot
- int[] result = layout.findNearestVacantArea(cellXY[0], cellXY[1], 1, 1, cellXY);
- foundCellSpan = (result != null);
- } else {
- foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
- }
-
- if (!foundCellSpan) {
- showOutOfSpaceMessage(isHotseatLayout(layout));
- } else if (cellXY != null) {
- LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
-
- if (!mRestoring) {
- mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
- isWorkspaceLocked());
- }
- }
- }
-
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -1511,18 +1459,6 @@ public final class Launcher extends Activity
processIntent.run();
}
- } else if (ACTION_LAUNCHER.equals(intent.getAction())) {
- Bundle extras = intent.getExtras();
- if (extras == null) {
- return;
- }
- String actionString = extras.getString(Intent.EXTRA_TEXT);
- LauncherAction.Action action = LauncherAction.Action.valueOf(actionString);
- switch (action) {
- case AllApps:
- showAllApps(true);
- break;
- }
}
}
@@ -1792,26 +1728,6 @@ public final class Launcher extends Activity
mPendingAddInfo.dropPos = null;
}
- void addAppWidgetFromPick(Intent data, long container, int screen) {
- resetAddInfo();
- mPendingAddInfo.container = container;
- mPendingAddInfo.screen = screen;
-
- int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
- if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
- Log.e(TAG, "Invalid appWidgetId sent");
- return;
- }
-
- AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
-
- PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(appWidget, null, null);
- createItemInfo.container = container;
- createItemInfo.screen = screen;
-
- addAppWidgetImpl(appWidgetId, createItemInfo, null, appWidget);
- }
-
void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
AppWidgetProviderInfo appWidgetInfo) {
if (appWidgetInfo.configure != null) {
@@ -1832,30 +1748,6 @@ public final class Launcher extends Activity
}
/**
- * Process action from drop.
- *
- * @param action The launcher action
- * @param screen The screen where it should be added
- * @param cell The cell it should be added to, optional
- * @param position The location on the screen where it was dropped, optional
- */
- void processActionFromDrop(LauncherAction.Action action, long container, int screen,
- int[] cell, int[] loc) {
- resetAddInfo();
- mPendingAddInfo.container = container;
- mPendingAddInfo.screen = screen;
- mPendingAddInfo.dropPos = loc;
-
- if (cell != null) {
- mPendingAddInfo.cellX = cell[0];
- mPendingAddInfo.cellY = cell[1];
- }
-
- addAction(action);
- exitSpringLoadedDragModeDelayed(true, true, null);
- }
-
- /**
* Process a shortcut drop.
*
* @param componentName The name of the component
@@ -1940,7 +1832,21 @@ public final class Launcher extends Activity
}
void processShortcut(Intent intent) {
- startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
+ // Handle case where user selected "Applications"
+ String applicationName = getResources().getString(R.string.group_applications);
+ String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+
+ if (applicationName != null && applicationName.equals(shortcutName)) {
+ 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);
+ pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
+ startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
+ } else {
+ startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
+ }
}
void processWallpaper(Intent intent) {
@@ -2058,26 +1964,23 @@ public final class Launcher extends Activity
}
Object tag = v.getTag();
- if (tag instanceof LauncherActionInfo) {
- LauncherAction.Action action = ((LauncherActionInfo) tag).action;
- switch (action) {
- case AllApps:
- showAllApps(true);
- break;
- }
- } else if (tag instanceof ShortcutInfo) {
- // Open shortcut
- final Intent intent = ((ShortcutInfo) tag).intent;
- int[] pos = new int[2];
- v.getLocationOnScreen(pos);
- intent.setSourceBounds(new Rect(pos[0], pos[1],
- pos[0] + v.getWidth(), pos[1] + v.getHeight()));
-
- boolean success = startActivitySafely(v, intent, tag);
-
- if (success && v instanceof BubbleTextView) {
- mWaitingForResume = (BubbleTextView) v;
- mWaitingForResume.setStayPressed(true);
+ if (tag instanceof ShortcutInfo) {
+ if (((ShortcutInfo) tag).itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) {
+ showAllApps(true);
+ } else {
+ // Open shortcut
+ final Intent intent = ((ShortcutInfo) tag).intent;
+ int[] pos = new int[2];
+ v.getLocationOnScreen(pos);
+ intent.setSourceBounds(new Rect(pos[0], pos[1],
+ pos[0] + v.getWidth(), pos[1] + v.getHeight()));
+
+ boolean success = startActivitySafely(v, intent, tag);
+
+ if (success && v instanceof BubbleTextView) {
+ mWaitingForResume = (BubbleTextView) v;
+ mWaitingForResume.setStayPressed(true);
+ }
}
} else if (tag instanceof FolderInfo) {
if (v instanceof FolderIcon) {
@@ -2091,14 +1994,10 @@ public final class Launcher extends Activity
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Object tag = v.getTag();
- if (tag instanceof LauncherActionInfo) {
- LauncherAction.Action action = ((LauncherActionInfo) tag).action;
- switch (action) {
- case AllApps:
- v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
- HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
- break;
- }
+ if (tag instanceof ShortcutInfo &&
+ ((ShortcutInfo)tag).itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) {
+ v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
+ HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
}
}
return false;
@@ -2502,7 +2401,7 @@ public final class Launcher extends Activity
// User long pressed on empty space
mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
- showAddDialog(longClickCellInfo);
+ startWallpaper();
} else {
if (!(itemUnderLongClick instanceof Folder)) {
// User long pressed on an item
@@ -2543,60 +2442,6 @@ public final class Launcher extends Activity
return mWorkspace;
}
- @Override
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DIALOG_CREATE_SHORTCUT:
- return new CreateShortcut().createDialog();
- case DIALOG_CREATE_ACTION:
- return new CreateAction().createDialog();
- }
-
- return super.onCreateDialog(id);
- }
-
- @Override
- protected void onPrepareDialog(int id, Dialog dialog) {
- switch (id) {
- case DIALOG_CREATE_SHORTCUT:
- break;
- case DIALOG_CREATE_ACTION:
- break;
- }
- }
-
- private void showAddDialog(CellLayout.CellInfo cell) {
- resetAddInfo();
- mPendingAddInfo.container = cell.container;
- mPendingAddInfo.screen = cell.screen;
- mPendingAddInfo.cellX = cell.cellX;
- mPendingAddInfo.cellY = cell.cellY;
- mWaitingForResult = true;
- showDialog(DIALOG_CREATE_SHORTCUT);
- }
-
- void pickApplication() {
- 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);
- pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
- startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
- }
-
- private void pickShortcut() {
- Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
- pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
- pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
-
- startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
- }
-
- private void pickAction() {
- showDialog(DIALOG_CREATE_ACTION);
- }
-
// Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
public boolean isAllAppsVisible() {
return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
@@ -3497,150 +3342,6 @@ public final class Launcher extends Activity
}
/**
- * Displays the shortcut creation dialog and launches, if necessary, the
- * appropriate activity.
- */
- private class CreateShortcut implements DialogInterface.OnClickListener,
- DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
- DialogInterface.OnShowListener {
-
- private AddAdapter mAdapter;
-
- Dialog createDialog() {
- mAdapter = new AddAdapter(Launcher.this);
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
- AlertDialog.THEME_HOLO_DARK);
- builder.setAdapter(mAdapter, this);
-
- AlertDialog dialog = builder.create();
- dialog.setOnCancelListener(this);
- dialog.setOnDismissListener(this);
- dialog.setOnShowListener(this);
-
- return dialog;
- }
-
- public void onCancel(DialogInterface dialog) {
- mWaitingForResult = false;
- cleanup();
- }
-
- public void onDismiss(DialogInterface dialog) {
- mWaitingForResult = false;
- cleanup();
- }
-
- private void cleanup() {
- try {
- dismissDialog(DIALOG_CREATE_SHORTCUT);
- } catch (Exception e) {
- // An exception is thrown if the dialog is not visible, which is fine
- }
- }
-
- /**
- * Handle the action clicked in the "Add to home" dialog.
- */
- public void onClick(DialogInterface dialog, int which) {
- cleanup();
-
- AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
- switch (item.actionTag) {
- case AddAdapter.ITEM_APPLICATION: {
- pickApplication();
- break;
- }
- case AddAdapter.ITEM_SHORTCUT: {
- pickShortcut();
- break;
- }
- case AddAdapter.ITEM_ACTION: {
- pickAction();
- break;
- }
- case AddAdapter.ITEM_APPWIDGET: {
- int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
-
- String intent = AppWidgetManager.ACTION_APPWIDGET_PICK;
- Intent pickIntent = new Intent(intent);
- pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
-
- // start the pick activity
- startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
- break;
- }
- case AddAdapter.ITEM_WALLPAPER: {
- startWallpaper();
- break;
- }
- }
- }
-
- public void onShow(DialogInterface dialog) {
- mWaitingForResult = true;
- }
- }
-
- /**
- * Displays the shortcut creation dialog and launches, if necessary, the
- * appropriate activity.
- */
- private class CreateAction implements DialogInterface.OnClickListener,
- DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
- DialogInterface.OnShowListener {
-
- private LauncherAction.AddAdapter mAdapter;
-
- Dialog createDialog() {
- mAdapter = new LauncherAction.AddAdapter(Launcher.this);
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
- AlertDialog.THEME_HOLO_DARK);
- builder.setAdapter(mAdapter, this);
-
- AlertDialog dialog = builder.create();
- dialog.setOnCancelListener(this);
- dialog.setOnDismissListener(this);
- dialog.setOnShowListener(this);
-
- return dialog;
- }
-
- public void onCancel(DialogInterface dialog) {
- mWaitingForResult = false;
- cleanup();
- }
-
- public void onDismiss(DialogInterface dialog) {
- mWaitingForResult = false;
- cleanup();
- }
-
- private void cleanup() {
- try {
- dismissDialog(DIALOG_CREATE_ACTION);
- } catch (Exception e) {
- // An exception is thrown if the dialog is not visible, which is fine
- }
- }
-
- /**
- * Handle the action clicked in the "Add to home" dialog.
- */
- public void onClick(DialogInterface dialog, int which) {
- cleanup();
-
- LauncherAction.AddAdapter.ItemInfo item = (LauncherAction.AddAdapter.ItemInfo) mAdapter.getItem(which);
- addAction(item.action);
- }
-
- public void onShow(DialogInterface dialog) {
- mWaitingForResult = true;
- }
- }
-
- /**
* Receives notifications when system dialogs are to be closed.
*/
private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
@@ -3747,8 +3448,9 @@ public final class Launcher extends Activity
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+ case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS:
ShortcutInfo info = (ShortcutInfo) item;
- String uri = info.intent.toUri(0);
+ String uri = info.intent != null ? info.intent.toUri(0) : null;
View shortcut = createShortcut(info);
workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
item.cellY, 1, 1, false);
@@ -3769,12 +3471,6 @@ public final class Launcher extends Activity
}
}
break;
- case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION:
- LauncherActionInfo launcherActionInfo = (LauncherActionInfo) item;
- View launcherAction = createShortcut(launcherActionInfo);
- workspace.addInScreen(launcherAction, item.container, item.screen, item.cellX,
- item.cellY, 1, 1, false);
- break;
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
(ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
@@ -4019,8 +3715,6 @@ public final class Launcher extends Activity
*/
public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
setLoadOnResume();
- removeDialog(DIALOG_CREATE_SHORTCUT);
- removeDialog(DIALOG_CREATE_ACTION);
if (mAppsCustomizeContent != null) {
mAppsCustomizeContent.addApps(apps);