diff options
author | nebkat <nebkat@teamhacksung.org> | 2012-04-18 16:30:22 +0100 |
---|---|---|
committer | nebkat <nebkat@teamhacksung.org> | 2012-12-24 10:08:35 +0000 |
commit | 8ef4f37b141f5e48bb5a63fc401d6ea9fbd9a8b1 (patch) | |
tree | 1b483fd4302a940c10c2bc19e5b7f4c6e66c036d | |
parent | fff81cad6963dfa977fa8063efa3d29797d9d8c2 (diff) | |
download | packages_apps_trebuchet-8ef4f37b141f5e48bb5a63fc401d6ea9fbd9a8b1.zip packages_apps_trebuchet-8ef4f37b141f5e48bb5a63fc401d6ea9fbd9a8b1.tar.gz packages_apps_trebuchet-8ef4f37b141f5e48bb5a63fc401d6ea9fbd9a8b1.tar.bz2 |
Launcher: Long-press Menu
Conflicts:
src/com/cyanogenmod/trebuchet/AppWidgetResizeFrame.java
src/com/cyanogenmod/trebuchet/Launcher.java
src/com/cyanogenmod/trebuchet/LauncherAction.java
Change-Id: I97ab3364971c0c467d5a7d444ec268eee99b985d
-rw-r--r-- | res/drawable-hdpi/ic_launcher_application.png | bin | 0 -> 3966 bytes | |||
-rw-r--r-- | res/drawable-hdpi/ic_launcher_appwidget.png | bin | 0 -> 7240 bytes | |||
-rw-r--r-- | res/drawable-hdpi/ic_launcher_shortcut.png | bin | 0 -> 5026 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_launcher_application.png | bin | 0 -> 2898 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_launcher_appwidget.png | bin | 0 -> 3549 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_launcher_shortcut.png | bin | 0 -> 3146 bytes | |||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/AddAdapter.java | 23 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Launcher.java | 263 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherAction.java | 75 |
10 files changed, 321 insertions, 42 deletions
diff --git a/res/drawable-hdpi/ic_launcher_application.png b/res/drawable-hdpi/ic_launcher_application.png Binary files differnew file mode 100644 index 0000000..882eb14 --- /dev/null +++ b/res/drawable-hdpi/ic_launcher_application.png diff --git a/res/drawable-hdpi/ic_launcher_appwidget.png b/res/drawable-hdpi/ic_launcher_appwidget.png Binary files differnew file mode 100644 index 0000000..3dc8b20 --- /dev/null +++ b/res/drawable-hdpi/ic_launcher_appwidget.png diff --git a/res/drawable-hdpi/ic_launcher_shortcut.png b/res/drawable-hdpi/ic_launcher_shortcut.png Binary files differnew file mode 100644 index 0000000..93ab2df --- /dev/null +++ b/res/drawable-hdpi/ic_launcher_shortcut.png diff --git a/res/drawable-mdpi/ic_launcher_application.png b/res/drawable-mdpi/ic_launcher_application.png Binary files differnew file mode 100644 index 0000000..d7ff417 --- /dev/null +++ b/res/drawable-mdpi/ic_launcher_application.png diff --git a/res/drawable-mdpi/ic_launcher_appwidget.png b/res/drawable-mdpi/ic_launcher_appwidget.png Binary files differnew file mode 100644 index 0000000..e9371d2 --- /dev/null +++ b/res/drawable-mdpi/ic_launcher_appwidget.png diff --git a/res/drawable-mdpi/ic_launcher_shortcut.png b/res/drawable-mdpi/ic_launcher_shortcut.png Binary files differnew file mode 100644 index 0000000..05bc055 --- /dev/null +++ b/res/drawable-mdpi/ic_launcher_shortcut.png diff --git a/res/values/strings.xml b/res/values/strings.xml index a182d65..d23b861 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -85,6 +85,8 @@ s --> <string name="group_shortcuts">Shortcuts</string> <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all widgets/gadgets --> <string name="group_widgets">Widgets</string> + <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all launcher actions --> + <string name="group_actions">Actions</string> <!-- Options in "Add to Home" dialog box; Title of the group containing the list of apps that can set the wallpaper--> <string name="group_wallpapers">Wallpapers</string> <!-- Error message when user has filled all their home screens --> diff --git a/src/com/cyanogenmod/trebuchet/AddAdapter.java b/src/com/cyanogenmod/trebuchet/AddAdapter.java index 5a3d43d..a8c5930 100644 --- a/src/com/cyanogenmod/trebuchet/AddAdapter.java +++ b/src/com/cyanogenmod/trebuchet/AddAdapter.java @@ -38,10 +38,11 @@ public class AddAdapter extends BaseAdapter { private final ArrayList<ListItem> mItems = new ArrayList<ListItem>(); - public static final int ITEM_SHORTCUT = 0; - public static final int ITEM_APPWIDGET = 1; - public static final int ITEM_APPLICATION = 2; - public static final int ITEM_WALLPAPER = 3; + public static final int ITEM_APPLICATION = 0; + public static final int ITEM_SHORTCUT = 1; + public static final int ITEM_APPWIDGET = 2; + public static final int ITEM_ACTION = 3; + public static final int ITEM_WALLPAPER = 4; /** * Specific item in our list. @@ -61,7 +62,7 @@ public class AddAdapter extends BaseAdapter { this.actionTag = actionTag; } } - + public AddAdapter(Launcher launcher) { super(); @@ -70,6 +71,18 @@ public class AddAdapter extends BaseAdapter { // Create default actions Resources res = launcher.getResources(); + mItems.add(new ListItem(res, R.string.group_applications, + R.drawable.ic_launcher_application, ITEM_APPLICATION)); + + mItems.add(new ListItem(res, R.string.group_shortcuts, + R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT)); + + mItems.add(new ListItem(res, R.string.group_widgets, + R.drawable.ic_launcher_appwidget, ITEM_APPWIDGET)); + + mItems.add(new ListItem(res, R.string.group_actions, + R.drawable.ic_launcher_home, ITEM_ACTION)); + mItems.add(new ListItem(res, R.string.group_wallpapers, R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER)); } diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index 5446740..14274f3 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -30,6 +30,7 @@ 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; @@ -43,6 +44,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.content.Intent.ShortcutIconResource; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; @@ -154,6 +156,9 @@ public final class Launcher extends Activity 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 FORCE_ENABLE_ROTATION_PROPERTY = "debug.force_enable_rotation"; static final String DUMP_STATE_PROPERTY = "debug.dumpstate"; @@ -627,6 +632,10 @@ 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); @@ -657,24 +666,8 @@ 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. @@ -1827,6 +1820,26 @@ 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) { @@ -1955,21 +1968,7 @@ public final class Launcher extends Activity } void processShortcut(Intent intent) { - // 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); - } + startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT); } void processWallpaper(Intent intent) { @@ -2537,7 +2536,7 @@ public final class Launcher extends Activity // User long pressed on empty space mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); - startWallpaper(); + showAddDialog(longClickCellInfo); } else { if (!(itemUnderLongClick instanceof Folder)) { // User long pressed on an item @@ -2578,6 +2577,60 @@ 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); @@ -3466,6 +3519,150 @@ 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(); + + LauncherActionInfo item = (LauncherActionInfo) 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 { @@ -3835,6 +4032,8 @@ 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); diff --git a/src/com/cyanogenmod/trebuchet/LauncherAction.java b/src/com/cyanogenmod/trebuchet/LauncherAction.java index 04f9bdf..1d460c6 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherAction.java +++ b/src/com/cyanogenmod/trebuchet/LauncherAction.java @@ -2,6 +2,12 @@ package com.cyanogenmod.trebuchet; import android.content.Context; import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; import java.util.ArrayList; import java.util.List; @@ -39,12 +45,71 @@ public class LauncherAction { final Resources res = context.getResources(); - LauncherActionInfo allAppsAction = new LauncherActionInfo(); - allAppsAction.action = Action.AllApps; - allAppsAction.drawable = Action.getDrawable(Action.AllApps); - allAppsAction.title = res.getString(Action.getString(Action.AllApps)); - actions.add(allAppsAction); + for (Action action : Action.values()) { + LauncherActionInfo info = new LauncherActionInfo(); + info.action = action; + info.drawable = Action.getDrawable(action); + info.title = res.getString(Action.getString(action)); + actions.add(info); + } return actions; } + + public static class AddAdapter extends BaseAdapter { + + private class LauncherActionInfoItem extends LauncherActionInfo { + public Drawable drawable; + public LauncherActionInfoItem(LauncherActionInfo info, Resources res) { + action = info.action; + drawable = res.getDrawable(info.drawable); + title = info.title; + } + } + + private final LayoutInflater mInflater; + + private final List<LauncherActionInfoItem> mItems = new ArrayList<LauncherActionInfoItem>(); + + public AddAdapter(Launcher launcher) { + super(); + + mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + // Create default actions + Resources res = launcher.getResources(); + + List<LauncherActionInfo> items = LauncherAction.getAllActions(launcher); + for (LauncherActionInfo item : items) { + mItems.add(new LauncherActionInfoItem(item, res)); + } + } + + public View getView(int position, View convertView, ViewGroup parent) { + LauncherActionInfoItem item = (LauncherActionInfoItem) getItem(position); + + if (convertView == null) { + convertView = mInflater.inflate(R.layout.add_list_item, parent, false); + } + + TextView textView = (TextView) convertView; + textView.setTag(item); + textView.setText(item.title); + textView.setCompoundDrawablesWithIntrinsicBounds(item.drawable, null, null, null); + + return convertView; + } + + public int getCount() { + return mItems.size(); + } + + public Object getItem(int position) { + return mItems.get(position); + } + + public long getItemId(int position) { + return position; + } + } } |