Adding support for drag and drop of folders and shortcuts.

also:
- Long press on empty space on workspace now brings up customization tray
- Fixed: while dragging, items appeared to be dropping on folders two cells to the right
- Fixed: Disabling drops on folders when the workspace is shrunken
- Fixed: account for scaling of dragged items when checking if they overlap
          with shrunken workspace screens
- Making folder icons dimmable to match shortcuts and widgets
- When deciding with shrunken workspace screen we're dragging to, we now use the closest screen rather than the one that has been overlapped the most
- Refactored drag/add mechanism, removing array of occupied cells from CellInfo
- Removed dead code/variables
This commit is contained in:
Michael Jurka
2010-09-17 15:00:07 -07:00
parent 513b8c94fb
commit 0280c3be4d
17 changed files with 659 additions and 605 deletions

View File

@@ -16,10 +16,7 @@
package com.android.launcher2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.android.launcher.R;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -28,13 +25,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.provider.LiveFolders;
@@ -44,12 +40,14 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class CustomizePagedView extends PagedView
implements View.OnLongClickListener, View.OnClickListener,
@@ -354,6 +352,7 @@ public class CustomizePagedView extends PagedView
}
final View animView = v;
PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
switch (mCustomizationType) {
case WidgetCustomization:
// Get the icon as the drag representation
@@ -365,58 +364,35 @@ public class CustomizePagedView extends PagedView
icon.draw(c);
AppWidgetProviderInfo appWidgetInfo = (AppWidgetProviderInfo) v.getTag();
LauncherAppWidgetInfo dragInfo = new LauncherAppWidgetInfo(appWidgetInfo.provider);
dragInfo.minWidth = appWidgetInfo.minWidth;
dragInfo.minHeight = appWidgetInfo.minHeight;
mDragController.startDrag(v, b, this, dragInfo, DragController.DRAG_ACTION_COPY, null);
createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
createItemInfo.componentName = appWidgetInfo.provider;
mDragController.startDrag(v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY, null);
// Cleanup the icon
b.recycle();
return true;
case FolderCustomization:
// animate some feedback to the long press
animateClickFeedback(v, new Runnable() {
@Override
public void run() {
// add the folder
ResolveInfo resolveInfo = (ResolveInfo) animView.getTag();
Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
if (resolveInfo.labelRes == R.string.group_folder) {
// Create app shortcuts is a special built-in case of shortcuts
createFolderIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getContext().getString(R.string.group_folder));
} else {
ComponentName name = new ComponentName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
createFolderIntent.setComponent(name);
}
mLauncher.prepareAddItemFromHomeCustomizationDrawer();
mLauncher.addLiveFolder(createFolderIntent);
}
});
ResolveInfo resolveInfo = (ResolveInfo) animView.getTag();
if (resolveInfo.labelRes == R.string.group_folder) {
UserFolderInfo folderInfo = new UserFolderInfo();
folderInfo.title = getResources().getText(R.string.folder_name);
mDragController.startDrag(
v, this, folderInfo, DragController.DRAG_ACTION_COPY, null);
} else {
createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER;
createItemInfo.componentName = new ComponentName(
resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
mDragController.startDrag(
v, this, createItemInfo, DragController.DRAG_ACTION_COPY, null);
}
return true;
case ShortcutCustomization:
// animate some feedback to the long press
animateClickFeedback(v, new Runnable() {
@Override
public void run() {
// add the shortcut
ResolveInfo info = (ResolveInfo) animView.getTag();
Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
if (info.labelRes == R.string.group_applications) {
// Create app shortcuts is a special built-in case of shortcuts
createShortcutIntent.putExtra(
Intent.EXTRA_SHORTCUT_NAME,getContext().getString(
R.string.group_applications));
} else {
ComponentName name = new ComponentName(info.activityInfo.packageName,
info.activityInfo.name);
createShortcutIntent.setComponent(name);
}
mLauncher.prepareAddItemFromHomeCustomizationDrawer();
mLauncher.processShortcut(createShortcutIntent);
}
});
ResolveInfo info = (ResolveInfo) animView.getTag();
createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
createItemInfo.componentName = new ComponentName(
info.activityInfo.packageName, info.activityInfo.name);
mDragController.startDrag(
v, this, createItemInfo, DragController.DRAG_ACTION_COPY, null);
return true;
case ApplicationCustomization:
// Pick up the application for dropping