5f44542560
- Fix 3453751: Moon landing on canceled drag from customize - Fix 3453595: Use home screen "consume" animation when dragging and dropping Change-Id: Ia6a83c2d7a8f24c3ce02811547a35a7022d245f6
97 lines
3.0 KiB
Java
97 lines
3.0 KiB
Java
package com.android.launcher2;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
|
|
import com.android.launcher.R;
|
|
|
|
/**
|
|
* Folder which contains applications or shortcuts chosen by the user.
|
|
*
|
|
*/
|
|
public class UserFolder extends Folder implements DropTarget {
|
|
private static final String TAG = "Launcher.UserFolder";
|
|
|
|
public UserFolder(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
}
|
|
|
|
/**
|
|
* Creates a new UserFolder, inflated from R.layout.user_folder.
|
|
*
|
|
* @param context The application's context.
|
|
*
|
|
* @return A new UserFolder.
|
|
*/
|
|
static UserFolder fromXml(Context context) {
|
|
return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
|
|
}
|
|
|
|
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
final ItemInfo item = (ItemInfo) dragInfo;
|
|
final int itemType = item.itemType;
|
|
return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
|
|
itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
|
|
&& item.container != mInfo.id;
|
|
}
|
|
|
|
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
ShortcutInfo item;
|
|
if (dragInfo instanceof ApplicationInfo) {
|
|
// Came from all apps -- make a copy
|
|
item = ((ApplicationInfo)dragInfo).makeShortcut();
|
|
} else {
|
|
item = (ShortcutInfo)dragInfo;
|
|
}
|
|
((ShortcutsAdapter)mContent.getAdapter()).add(item);
|
|
LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
|
|
}
|
|
|
|
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
}
|
|
|
|
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
}
|
|
|
|
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
}
|
|
|
|
@Override
|
|
public void onDropCompleted(View target, Object dragInfo, boolean success) {
|
|
if (success) {
|
|
ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
|
|
adapter.remove(mDragItem);
|
|
}
|
|
}
|
|
|
|
public boolean isDropEnabled() {
|
|
return true;
|
|
}
|
|
|
|
void bind(FolderInfo info) {
|
|
super.bind(info);
|
|
setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
|
|
}
|
|
|
|
// When the folder opens, we need to refresh the GridView's selection by
|
|
// forcing a layout
|
|
@Override
|
|
void onOpen() {
|
|
super.onOpen();
|
|
requestFocus();
|
|
}
|
|
|
|
@Override
|
|
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
|
|
DragView dragView, Object dragInfo) {
|
|
return null;
|
|
}
|
|
}
|