diff options
author | nebkat <nebkat@teamhacksung.org> | 2012-12-26 13:01:07 +0000 |
---|---|---|
committer | nebkat <nebkat@teamhacksung.org> | 2012-12-26 13:38:33 +0000 |
commit | 8fb7b9eadd45959d2c3aca9a1bb910ca875cc593 (patch) | |
tree | a652102d46137188697b4e225d6312f432026c92 /src | |
parent | 8fb6e3e975674d6960dc370ce0d2c7dd80b50117 (diff) | |
download | android_packages_apps_Trebuchet-8fb7b9eadd45959d2c3aca9a1bb910ca875cc593.tar.gz android_packages_apps_Trebuchet-8fb7b9eadd45959d2c3aca9a1bb910ca875cc593.tar.bz2 android_packages_apps_Trebuchet-8fb7b9eadd45959d2c3aca9a1bb910ca875cc593.zip |
LauncherActions: Don't use magic intents
Change-Id: I5ee3fbc9b1cdc63407def751bb7639cb54bdb7c3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java | 29 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/DeleteDropTarget.java | 11 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Launcher.java | 70 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherAction.java | 39 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherActionInfo.java | 22 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherModel.java | 90 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherProvider.java | 57 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherSettings.java | 28 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/PagedViewWidget.java | 8 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Workspace.java | 6 |
10 files changed, 233 insertions, 127 deletions
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java index 7d5346ff0..127f28fed 100644 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java @@ -354,7 +354,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Preferences private boolean mJoinWidgetsApps; - private boolean mShowScrollingIndicator; private boolean mFadeScrollingIndicator; private int mScrollingIndicatorPosition; @@ -386,7 +385,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mTransitionEffect = PreferencesProvider.Interface.Drawer.Scrolling.getTransitionEffect( resources.getString(R.string.config_drawerDefaultTransitionEffect)); mFadeInAdjacentScreens = PreferencesProvider.Interface.Drawer.Scrolling.getFadeInAdjacentScreens(); - mShowScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getShowScrollingIndicator(); + boolean showScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getShowScrollingIndicator(); mFadeScrollingIndicator = PreferencesProvider.Interface.Drawer.Indicator.getFadeScrollingIndicator(); mScrollingIndicatorPosition = PreferencesProvider.Interface.Drawer.Indicator.getScrollingIndicatorPosition(); @@ -396,7 +395,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } - if (!mShowScrollingIndicator) { + if (!showScrollingIndicator) { disableScrollingIndicator(); } @@ -647,7 +646,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen AppWidgetManager.getInstance(mLauncher).getInstalledProviders(); Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0); - List<LauncherActionInfo> launcherActions = LauncherAction.getAllActions(mLauncher); + List<LauncherAction.Action> launcherActions = LauncherAction.getAllActions(); for (AppWidgetProviderInfo widget : widgets) { if (widget.minWidth > 0 && widget.minHeight > 0) { // Ensure that all widgets we show can be added on a workspace of this size @@ -670,7 +669,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgets.addAll(shortcuts); mWidgets.addAll(launcherActions); Collections.sort(mWidgets, - new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager)); + new LauncherModel.WidgetAndShortcutNameComparator(mLauncher, mPackageManager)); updatePageCounts(); invalidateOnDataChange(); } @@ -1435,7 +1434,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen return preview; } - private Bitmap getShortcutPreview(LauncherActionInfo info) { + private Bitmap getShortcutPreview(LauncherAction.Action info) { int offset = 0; int bitmapSize = mAppIconSize; Bitmap preview = Bitmap.createBitmap(bitmapSize, bitmapSize, Config.ARGB_8888); @@ -1443,7 +1442,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen final Resources res = getContext().getResources(); // Render the icon - Drawable icon = res.getDrawable(info.drawable); + Drawable icon = res.getDrawable(info.getDrawable()); renderDrawableToBitmap(icon, preview, offset, offset, mAppIconSize, mAppIconSize); return preview; } @@ -1621,13 +1620,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen info.activityInfo.name); widget.applyFromResolveInfo(mPackageManager, info); widget.setTag(createItemInfo); - } else if (rawInfo instanceof LauncherActionInfo) { + } else if (rawInfo instanceof LauncherAction.Action) { // Fill in the actions information - LauncherActionInfo info = (LauncherActionInfo) rawInfo; + LauncherAction.Action info = (LauncherAction.Action) rawInfo; createItemInfo = new PendingAddActionInfo(); - ((PendingAddActionInfo)createItemInfo).action = info.action; - createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; - widget.applyFromLauncherActionInfo(info); + ((PendingAddActionInfo)createItemInfo).action = info; + createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION; + widget.applyFromLauncherAction(info); widget.setTag(createItemInfo); } widget.setOnClickListener(this); @@ -1715,8 +1714,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Fill in the shortcuts information ResolveInfo info = (ResolveInfo) item; images.add(getShortcutPreview(info, data.maxImageWidth, data.maxImageHeight)); - } else if (item instanceof LauncherActionInfo) { - LauncherActionInfo info = (LauncherActionInfo) item; + } else if (item instanceof LauncherAction.Action) { + LauncherAction.Action info = (LauncherAction.Action) item; images.add(getShortcutPreview(info)); } } @@ -1737,7 +1736,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i); if (widget != null) { Bitmap preview = data.generatedImages.get(i); - widget.applyPreview(new FastBitmapDrawable(preview), i); + widget.applyPreview(new FastBitmapDrawable(preview)); } } diff --git a/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java b/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java index 55381d4c2..3a1e94e6d 100644 --- a/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java +++ b/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java @@ -113,6 +113,7 @@ public class DeleteDropTarget extends ButtonDropTarget { switch (addInfo.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: return true; } } @@ -159,10 +160,12 @@ public class DeleteDropTarget extends ButtonDropTarget { } else if (isWorkspaceOrFolderApplication(source, info)) { ShortcutInfo shortcutInfo = (ShortcutInfo) info; PackageManager pm = getContext().getPackageManager(); - ResolveInfo resolveInfo = pm.resolveActivity(shortcutInfo.intent, 0); - if (resolveInfo != null && (resolveInfo.activityInfo.applicationInfo.flags & - android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { - isUninstall = true; + if (shortcutInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION) { + ResolveInfo resolveInfo = pm.resolveActivity(shortcutInfo.intent, 0); + if (resolveInfo != null && (resolveInfo.activityInfo.applicationInfo.flags & + android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { + isUninstall = true; + } } } diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index 023ab564c..fd634f3f0 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -56,6 +56,7 @@ 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; @@ -651,7 +652,7 @@ public final class Launcher extends Activity // 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 && mPendingAddInfo.container != ItemInfo.NO_ID) { + if (resultCode == RESULT_OK && mPendingAddInfo.container != com.cyanogenmod.trebuchet.ItemInfo.NO_ID) { final PendingAddArguments args = new PendingAddArguments(); args.requestCode = requestCode; args.intent = data; @@ -867,7 +868,7 @@ public final class Launcher extends Activity final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); - if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { + if (pendingAddContainer != com.cyanogenmod.trebuchet.ItemInfo.NO_ID && pendingAddScreen > -1) { mPendingAddInfo.container = pendingAddContainer; mPendingAddInfo.screen = pendingAddScreen; mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); @@ -1008,6 +1009,7 @@ public final class Launcher extends Activity favorite.setTextVisible(false); } favorite.setOnClickListener(this); + favorite.setOnTouchListener(this); return favorite; } @@ -1035,7 +1037,7 @@ public final class Launcher extends Activity if (info != null) { info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); - info.container = ItemInfo.NO_ID; + info.container = com.cyanogenmod.trebuchet.ItemInfo.NO_ID; mWorkspace.addApplicationShortcut(info, layout, container, screen, isWorkspaceLocked(), cellX, cellY); } else { @@ -1228,12 +1230,11 @@ public final class Launcher extends Activity boolean foundCellSpan; - Intent data = createActionIntent(action); + LauncherActionInfo info = new LauncherActionInfo(); + info.action = action; + info.title = getResources().getString(action.getString()); + info.setIcon(((BitmapDrawable)getResources().getDrawable(action.getDrawable())).getBitmap()); - ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); - if (info == null) { - return; - } final View view = createShortcut(info); if (cellX >= 0 && cellY >= 0) { @@ -1276,20 +1277,6 @@ public final class Launcher extends Activity } } - private Intent createActionIntent(LauncherAction.Action action) { - Intent data = new Intent(Intent.ACTION_MAIN); - Intent intent = new Intent(ACTION_LAUNCHER); - intent.addCategory(Intent.CATEGORY_HOME); - intent.setClassName(this, this.getClass().getName()); - intent.putExtra(Intent.EXTRA_TEXT, action.toString()); - data.putExtra(Intent.EXTRA_SHORTCUT_NAME, - getResources().getString(LauncherAction.Action.getString(action))); - data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); - data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, - Intent.ShortcutIconResource.fromContext(this, LauncherAction.Action.getDrawable(action))); - return data; - } - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -1301,7 +1288,7 @@ public final class Launcher extends Activity // Reset AllApps to its initial state only if we are not in the middle of // processing a multi-step drop - if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { + if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == com.cyanogenmod.trebuchet.ItemInfo.NO_ID) { mAppsCustomizeTabHost.reset(); showWorkspace(false); } @@ -1555,7 +1542,7 @@ public final class Launcher extends Activity // this state is reflected. closeFolder(); - if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 && + if (mPendingAddInfo.container != com.cyanogenmod.trebuchet.ItemInfo.NO_ID && mPendingAddInfo.screen > -1 && mWaitingForResult) { outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen); @@ -1786,7 +1773,7 @@ public final class Launcher extends Activity } private void resetAddInfo() { - mPendingAddInfo.container = ItemInfo.NO_ID; + mPendingAddInfo.container = com.cyanogenmod.trebuchet.ItemInfo.NO_ID; mPendingAddInfo.screen = -1; mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; @@ -2060,7 +2047,14 @@ public final class Launcher extends Activity } Object tag = v.getTag(); - if (tag instanceof ShortcutInfo) { + 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]; @@ -2082,10 +2076,20 @@ public final class Launcher extends Activity } } + @Override public boolean onTouch(View v, MotionEvent event) { - // this is an intercepted event being forwarded from mWorkspace; - // clicking anywhere on the workspace causes the customization drawer to slide down - showWorkspace(true); + 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; + } + } + } return false; } @@ -3579,7 +3583,7 @@ public final class Launcher extends Activity public void onClick(DialogInterface dialog, int which) { cleanup(); - LauncherActionInfo item = (LauncherActionInfo) mAdapter.getItem(which); + LauncherAction.AddAdapter.ItemInfo item = (LauncherAction.AddAdapter.ItemInfo) mAdapter.getItem(which); addAction(item.action); } @@ -3717,6 +3721,12 @@ 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()), diff --git a/src/com/cyanogenmod/trebuchet/LauncherAction.java b/src/com/cyanogenmod/trebuchet/LauncherAction.java index 1d460c687..3ccfc3f0f 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherAction.java +++ b/src/com/cyanogenmod/trebuchet/LauncherAction.java @@ -10,6 +10,7 @@ import android.widget.BaseAdapter; import android.widget.TextView; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class LauncherAction { @@ -40,36 +41,26 @@ public class LauncherAction { } } - public static List<LauncherActionInfo> getAllActions(Context context) { - List<LauncherActionInfo> actions = new ArrayList<LauncherActionInfo>(); - - final Resources res = context.getResources(); - - 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 List<Action> getAllActions() { + return Arrays.asList(Action.values()); } public static class AddAdapter extends BaseAdapter { - private class LauncherActionInfoItem extends LauncherActionInfo { + public class ItemInfo { + public Action action; public Drawable drawable; - public LauncherActionInfoItem(LauncherActionInfo info, Resources res) { - action = info.action; - drawable = res.getDrawable(info.drawable); - title = info.title; + public String title; + public ItemInfo(Action info, Resources res) { + action = info; + drawable = res.getDrawable(info.getDrawable()); + title = res.getString(info.getString()); } } private final LayoutInflater mInflater; - private final List<LauncherActionInfoItem> mItems = new ArrayList<LauncherActionInfoItem>(); + private final List<ItemInfo> mItems = new ArrayList<ItemInfo>(); public AddAdapter(Launcher launcher) { super(); @@ -79,14 +70,14 @@ public class LauncherAction { // Create default actions Resources res = launcher.getResources(); - List<LauncherActionInfo> items = LauncherAction.getAllActions(launcher); - for (LauncherActionInfo item : items) { - mItems.add(new LauncherActionInfoItem(item, res)); + List<Action> items = LauncherAction.getAllActions(); + for (Action item : items) { + mItems.add(new ItemInfo(item, res)); } } public View getView(int position, View convertView, ViewGroup parent) { - LauncherActionInfoItem item = (LauncherActionInfoItem) getItem(position); + ItemInfo item = (ItemInfo) getItem(position); if (convertView == null) { convertView = mInflater.inflate(R.layout.add_list_item, parent, false); diff --git a/src/com/cyanogenmod/trebuchet/LauncherActionInfo.java b/src/com/cyanogenmod/trebuchet/LauncherActionInfo.java index f808ebe84..034c2ebff 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherActionInfo.java +++ b/src/com/cyanogenmod/trebuchet/LauncherActionInfo.java @@ -1,19 +1,23 @@ package com.cyanogenmod.trebuchet; -class LauncherActionInfo { +import android.content.ContentValues; + +class LauncherActionInfo extends ShortcutInfo { /* * The launcher action */ LauncherAction.Action action; - /* - * The drawable for the launcher action - */ - int drawable; + LauncherActionInfo() { + itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_LAUNCHER_ACTION; + } - /* - * The title for the launcher action - */ - String title; + @Override + void onAddToDatabase(ContentValues values) { + super.onAddToDatabase(values); + + String actionText = action != null ? action.name() : null; + values.put(LauncherSettings.Favorites.LAUNCHER_ACTION, actionText); + } } diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index fdcaba170..34891639f 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -345,6 +345,7 @@ public class LauncherModel extends BroadcastReceiver { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: if (!sBgWorkspaceItems.contains(modelItem)) { sBgWorkspaceItems.add(modelItem); } @@ -577,6 +578,7 @@ public class LauncherModel extends BroadcastReceiver { // Fall through case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { sBgWorkspaceItems.add(item); @@ -663,6 +665,7 @@ public class LauncherModel extends BroadcastReceiver { break; case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: sBgWorkspaceItems.remove(item); break; case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: @@ -1246,6 +1249,8 @@ public class LauncherModel extends BroadcastReceiver { (LauncherSettings.Favorites.SPANX); final int spanYIndex = c.getColumnIndexOrThrow( LauncherSettings.Favorites.SPANY); + final int actionIndex = c.getColumnIndexOrThrow( + LauncherSettings.Favorites.LAUNCHER_ACTION); //final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI); //final int displayModeIndex = c.getColumnIndexOrThrow( // LauncherSettings.Favorites.DISPLAY_MODE); @@ -1255,7 +1260,7 @@ public class LauncherModel extends BroadcastReceiver { LauncherAppWidgetInfo appWidgetInfo; int container; long id; - Intent intent; + Intent intent = null; while (!mStopped && c.moveToNext()) { try { @@ -1271,10 +1276,12 @@ public class LauncherModel extends BroadcastReceiver { continue; } + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: + if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { info = getShortcutInfo(manager, intent, context, c, iconIndex, titleIndex, mLabelCache); - } else { + } else if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { info = getShortcutInfo(c, context, iconTypeIndex, iconPackageIndex, iconResourceIndex, iconIndex, titleIndex); @@ -1290,6 +1297,10 @@ public class LauncherModel extends BroadcastReceiver { Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } + } else { + info = getLauncherActionInfo(c, context, iconTypeIndex, + iconPackageIndex, iconResourceIndex, iconIndex, + titleIndex, actionIndex); } if (info != null) { @@ -2189,6 +2200,67 @@ public class LauncherModel extends BroadcastReceiver { return info; } + /** + * Make an ShortcutInfo object for a shortcut that isn't an application. + */ + private LauncherActionInfo getLauncherActionInfo(Cursor c, Context context, + int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex, + int titleIndex, int actionIndex) { + + Bitmap icon = null; + final LauncherActionInfo info = new LauncherActionInfo(); + + info.title = c.getString(titleIndex); + info.action = LauncherAction.Action.valueOf(c.getString(actionIndex)); + + int iconType = c.getInt(iconTypeIndex); + switch (iconType) { + case LauncherSettings.Favorites.ICON_TYPE_RESOURCE: + String packageName = c.getString(iconPackageIndex); + String resourceName = c.getString(iconResourceIndex); + PackageManager packageManager = context.getPackageManager(); + info.customIcon = false; + // the resource + try { + Resources resources = packageManager.getResourcesForApplication(packageName); + if (resources != null) { + final int id = resources.getIdentifier(resourceName, null, null); + icon = Utilities.createIconBitmap( + mIconCache.getFullResIcon(resources, id), context); + } + } catch (Exception e) { + // drop this. we have other places to look for icons + } + // the db + if (icon == null) { + icon = getIconFromCursor(c, iconIndex, context); + } + // the fallback icon + if (icon == null) { + icon = getFallbackIcon(); + info.usingFallbackIcon = true; + } + break; + case LauncherSettings.Favorites.ICON_TYPE_BITMAP: + icon = getIconFromCursor(c, iconIndex, context); + if (icon == null) { + icon = getFallbackIcon(); + info.customIcon = false; + info.usingFallbackIcon = true; + } else { + info.customIcon = true; + } + break; + default: + icon = getFallbackIcon(); + info.usingFallbackIcon = true; + info.customIcon = false; + break; + } + info.setIcon(icon); + return info; + } + Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; @@ -2397,15 +2469,17 @@ public class LauncherModel extends BroadcastReceiver { } public static class WidgetAndShortcutNameComparator implements Comparator<Object> { private Collator mCollator; + private Context mContext; private PackageManager mPackageManager; private HashMap<Object, String> mLabelCache; - WidgetAndShortcutNameComparator(PackageManager pm) { + WidgetAndShortcutNameComparator(Context context, PackageManager pm) { + mContext = context; mPackageManager = pm; mLabelCache = new HashMap<Object, String>(); mCollator = Collator.getInstance(); } public final int compare(Object a, Object b) { - String labelA, labelB; + String labelA = "", labelB = ""; if (mLabelCache.containsKey(a)) { labelA = mLabelCache.get(a); } else { @@ -2413,8 +2487,8 @@ public class LauncherModel extends BroadcastReceiver { labelA = ((AppWidgetProviderInfo) a).label; } else if (a instanceof ResolveInfo) { labelA = ((ResolveInfo) a).loadLabel(mPackageManager).toString(); - } else { - labelA = ((LauncherActionInfo) a).title; + } else if (a instanceof LauncherAction.Action) { + labelA = mContext.getResources().getString(((LauncherAction.Action) a).getString()); } mLabelCache.put(a, labelA); } @@ -2425,8 +2499,8 @@ public class LauncherModel extends BroadcastReceiver { labelB = ((AppWidgetProviderInfo) b).label; } else if (b instanceof ResolveInfo) { labelB = ((ResolveInfo) b).loadLabel(mPackageManager).toString(); - } else { - labelB = ((LauncherActionInfo) b).title; + } else if (b instanceof LauncherAction.Action) { + labelB = mContext.getResources().getString(((LauncherAction.Action) b).getString()); } mLabelCache.put(b, labelB); } diff --git a/src/com/cyanogenmod/trebuchet/LauncherProvider.java b/src/com/cyanogenmod/trebuchet/LauncherProvider.java index 45ae99c85..0f814a477 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherProvider.java +++ b/src/com/cyanogenmod/trebuchet/LauncherProvider.java @@ -65,7 +65,7 @@ public class LauncherProvider extends ContentProvider { private static final String DATABASE_NAME = "launcher.db"; - private static final int DATABASE_VERSION = 13; + private static final int DATABASE_VERSION = 14; static final String AUTHORITY = "com.cyanogenmod.trebuchet.settings"; @@ -121,8 +121,7 @@ public class LauncherProvider extends ContentProvider { return result; } - private static long dbInsertAndCheck(DatabaseHelper helper, - SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) { + private static long dbInsertAndCheck(SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) { if (!values.containsKey(LauncherSettings.Favorites._ID)) { throw new RuntimeException("Error: attempting to add item without specifying an id"); } @@ -140,7 +139,7 @@ public class LauncherProvider extends ContentProvider { SqlArguments args = new SqlArguments(uri); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); - final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues); + final long rowId = dbInsertAndCheck(db, args.table, null, initialValues); if (rowId <= 0) return null; uri = ContentUris.withAppendedId(uri, rowId); @@ -157,7 +156,7 @@ public class LauncherProvider extends ContentProvider { db.beginTransaction(); try { for (ContentValues value : values) { - if (dbInsertAndCheck(mOpenHelper, db, args.table, null, value) < 0) { + if (dbInsertAndCheck(db, args.table, null, value) < 0) { return 0; } } @@ -235,6 +234,7 @@ public class LauncherProvider extends ContentProvider { private static final String TAG_SEARCH = "search"; private static final String TAG_APPWIDGET = "appwidget"; private static final String TAG_SHORTCUT = "shortcut"; + private static final String TAG_ACTION = "action"; private static final String TAG_FOLDER = "folder"; private static final String TAG_EXTRA = "extra"; @@ -289,7 +289,8 @@ public class LauncherProvider extends ContentProvider { "iconResource TEXT," + "icon BLOB," + "uri TEXT," + - "displayMode INTEGER" + + "displayMode INTEGER," + + "action TEXT" + ");"); // Database was just created, so wipe any previous widgets @@ -364,6 +365,7 @@ public class LauncherProvider extends ContentProvider { final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI); final int displayModeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.DISPLAY_MODE); + final int actionIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.LAUNCHER_ACTION); ContentValues[] rows = new ContentValues[c.getCount()]; int i = 0; @@ -384,6 +386,7 @@ public class LauncherProvider extends ContentProvider { values.put(LauncherSettings.Favorites.CELLY, c.getInt(cellYIndex)); values.put(LauncherSettings.Favorites.URI, c.getString(uriIndex)); values.put(LauncherSettings.Favorites.DISPLAY_MODE, c.getInt(displayModeIndex)); + values.put(LauncherSettings.Favorites.LAUNCHER_ACTION, c.getString(actionIndex)); rows[i++] = values; } @@ -392,7 +395,7 @@ public class LauncherProvider extends ContentProvider { try { int numValues = rows.length; for (i = 0; i < numValues; i++) { - if (dbInsertAndCheck(this, db, TABLE_FAVORITES, null, rows[i]) < 0) { + if (dbInsertAndCheck(db, TABLE_FAVORITES, null, rows[i]) < 0) { return 0; } else { total++; @@ -489,8 +492,9 @@ public class LauncherProvider extends ContentProvider { version = 12; } - if (version < 13) { + if (version < 14) { db.delete(TABLE_FAVORITES, Favorites.CONTAINER + "=?", new String[] { Integer.toString(Favorites.CONTAINER_HOTSEAT) }); + db.execSQL("ALTER TABLE favorites ADD COLUMN action TEXT;"); // The max id is not yet set at this point (onUpgrade is triggered in the ctor // before it gets a change to get set, so we need to read it here when we use it) @@ -500,7 +504,7 @@ public class LauncherProvider extends ContentProvider { // Add default hotseat icons loadFavorites(db, R.xml.update_workspace); - version = 13; + version = 14; } if (version != DATABASE_VERSION) { @@ -849,6 +853,9 @@ public class LauncherProvider extends ContentProvider { added = addClockWidget(db, values); } else if (TAG_APPWIDGET.equals(name)) { added = addAppWidget(parser, attrs, db, values, a, packageManager); + } else if (TAG_ACTION.equals(name)) { + long id = addLauncherAction(db, values, a); + added = id >= 0; } else if (TAG_SHORTCUT.equals(name)) { long id = addUriShortcut(db, values, a); added = id >= 0; @@ -949,7 +956,7 @@ public class LauncherProvider extends ContentProvider { values.put(Favorites.SPANX, 1); values.put(Favorites.SPANY, 1); values.put(Favorites._ID, generateNewId()); - if (dbInsertAndCheck(this, db, TABLE_FAVORITES, null, values) < 0) { + if (dbInsertAndCheck(db, TABLE_FAVORITES, null, values) < 0) { return -1; } } catch (PackageManager.NameNotFoundException e) { @@ -965,7 +972,7 @@ public class LauncherProvider extends ContentProvider { values.put(Favorites.SPANY, 1); long id = generateNewId(); values.put(Favorites._ID, id); - if (dbInsertAndCheck(this, db, TABLE_FAVORITES, null, values) <= 0) { + if (dbInsertAndCheck(db, TABLE_FAVORITES, null, values) <= 0) { return -1; } else { return id; @@ -1082,7 +1089,7 @@ public class LauncherProvider extends ContentProvider { values.put(Favorites.SPANY, spanY); values.put(Favorites.APPWIDGET_ID, appWidgetId); values.put(Favorites._ID, generateNewId()); - dbInsertAndCheck(this, db, TABLE_FAVORITES, null, values); + dbInsertAndCheck(db, TABLE_FAVORITES, null, values); allocatedAppWidgets = true; @@ -1104,6 +1111,30 @@ public class LauncherProvider extends ContentProvider { return allocatedAppWidgets; } + private long addLauncherAction(SQLiteDatabase db, ContentValues values, + TypedArray a) { + Resources r = mContext.getResources(); + + String actionText = a.getString(R.styleable.Favorite_action); + LauncherAction.Action action = LauncherAction.Action.valueOf(actionText); + + long id = generateNewId(); + values.put(Favorites.TITLE, r.getString(action.getString())); + values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_LAUNCHER_ACTION); + 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(action.getDrawable())); + values.put(LauncherSettings.Favorites.LAUNCHER_ACTION, actionText); + values.put(Favorites._ID, id); + + if (dbInsertAndCheck(db, TABLE_FAVORITES, null, values) < 0) { + return -1; + } + return id; + } + private long addUriShortcut(SQLiteDatabase db, ContentValues values, TypedArray a) { Resources r = mContext.getResources(); @@ -1138,7 +1169,7 @@ public class LauncherProvider extends ContentProvider { values.put(Favorites.ICON_RESOURCE, r.getResourceName(iconResId)); values.put(Favorites._ID, id); - if (dbInsertAndCheck(this, db, TABLE_FAVORITES, null, values) < 0) { + if (dbInsertAndCheck(db, TABLE_FAVORITES, null, values) < 0) { return -1; } return id; diff --git a/src/com/cyanogenmod/trebuchet/LauncherSettings.java b/src/com/cyanogenmod/trebuchet/LauncherSettings.java index 361dd69a0..d41ce7141 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherSettings.java +++ b/src/com/cyanogenmod/trebuchet/LauncherSettings.java @@ -56,6 +56,11 @@ class LauncherSettings { static final int ITEM_TYPE_SHORTCUT = 1; /** + * The gesture is a launcher action + */ + static final int ITEM_TYPE_LAUNCHER_ACTION = 3; + + /** * The icon type. * <P>Type: INTEGER</P> */ @@ -173,15 +178,6 @@ class LauncherSettings { static final int ITEM_TYPE_FOLDER = 2; /** - * The favorite is a live folder - * - * Note: live folders can no longer be added to Launcher, and any live folders which - * exist within the launcher database will be ignored when loading. That said, these - * entries in the database may still exist, and are not automatically stripped. - */ - static final int ITEM_TYPE_LIVE_FOLDER = 3; - - /** * The favorite is a widget */ static final int ITEM_TYPE_APPWIDGET = 4; @@ -207,15 +203,6 @@ class LauncherSettings { * <P>Type: INTEGER</P> */ static final String APPWIDGET_ID = "appWidgetId"; - - /** - * Indicates whether this favorite is an application-created shortcut or not. - * If the value is 0, the favorite is not an application-created shortcut, if the - * value is 1, it is an application-created shortcut. - * <P>Type: INTEGER</P> - */ - @Deprecated - static final String IS_SHORTCUT = "isShortcut"; /** * The URI associated with the favorite. It is used, for instance, by @@ -232,5 +219,10 @@ class LauncherSettings { * @see android.provider.LiveFolders#DISPLAY_MODE_LIST */ static final String DISPLAY_MODE = "displayMode"; + + /** + * The LauncherAction of a launcher action shortcut + */ + static final String LAUNCHER_ACTION = "action"; } } diff --git a/src/com/cyanogenmod/trebuchet/PagedViewWidget.java b/src/com/cyanogenmod/trebuchet/PagedViewWidget.java index b821b6f2d..ce52bb33b 100644 --- a/src/com/cyanogenmod/trebuchet/PagedViewWidget.java +++ b/src/com/cyanogenmod/trebuchet/PagedViewWidget.java @@ -127,12 +127,12 @@ public class PagedViewWidget extends LinearLayout { } } - public void applyFromLauncherActionInfo(LauncherActionInfo info) { + public void applyFromLauncherAction(LauncherAction.Action info) { mIsAppWidget = false; final ImageView image = (ImageView) findViewById(R.id.widget_preview); - image.setContentDescription(getContext().getResources().getString(info.action.getString())); + image.setContentDescription(getContext().getResources().getString(info.getString())); final TextView name = (TextView) findViewById(R.id.widget_name); - name.setText(info.title); + name.setText(getContext().getResources().getString(info.getString())); final TextView dims = (TextView) findViewById(R.id.widget_dims); if (dims != null) { dims.setText(String.format(mDimensionsFormatString, 1, 1)); @@ -147,7 +147,7 @@ public class PagedViewWidget extends LinearLayout { return maxSize; } - void applyPreview(FastBitmapDrawable preview, int index) { + void applyPreview(FastBitmapDrawable preview) { final PagedViewWidgetImageView image = (PagedViewWidgetImageView) findViewById(R.id.widget_preview); if (preview != null) { diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index 077cd5278..32062e61b 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -1715,8 +1715,8 @@ public class Workspace extends PagedView if (!mOverscrollTransformsDirty) { mOverscrollTransformsDirty = true; cl.setCameraDistance(mDensity * mCameraDistance); - cl.setPivotX(cl.getMeasuredWidth() * (index == 0 ? 0.75f : 0.25f)); cl.setPivotY(cl.getMeasuredHeight() * 0.5f); + cl.setPivotX(cl.getMeasuredWidth() * (index == 0 ? 0.75f : 0.25f)); cl.setOverscrollTransformsDirty(true); } } @@ -3654,6 +3654,7 @@ public class Workspace extends PagedView container, screen, mTargetCell, span, null); break; case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: if (pendingInfo instanceof PendingAddActionInfo) { mLauncher.processActionFromDrop(((PendingAddActionInfo)pendingInfo).action, container, screen, mTargetCell, null); @@ -3691,6 +3692,7 @@ public class Workspace extends PagedView switch (info.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_LAUNCHER_ACTION: if (info.container == NO_ID && info instanceof ApplicationInfo) { // Came from all apps -- make a copy info = new ShortcutInfo((ApplicationInfo) info); @@ -3821,7 +3823,7 @@ public class Workspace extends PagedView int[] finalPos = new int[2]; float scaleXY[] = new float[2]; - boolean scalePreview = !(info instanceof PendingAddShortcutInfo); + boolean scalePreview = !(info instanceof PendingAddShortcutInfo || info instanceof PendingAddActionInfo); getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, external, scalePreview); |