Home | History | Annotate | Download | only in launcher2
      1 package com.android.launcher2;
      2 
      3 import android.content.Context;
      4 import android.graphics.Rect;
      5 import android.util.AttributeSet;
      6 import android.util.Log;
      7 import android.view.LayoutInflater;
      8 import android.view.View;
      9 import android.widget.ArrayAdapter;
     10 
     11 import com.android.launcher.R;
     12 
     13 /**
     14  * Folder which contains applications or shortcuts chosen by the user.
     15  *
     16  */
     17 public class UserFolder extends Folder implements DropTarget {
     18     private static final String TAG = "Launcher.UserFolder";
     19 
     20     public UserFolder(Context context, AttributeSet attrs) {
     21         super(context, attrs);
     22     }
     23 
     24     /**
     25      * Creates a new UserFolder, inflated from R.layout.user_folder.
     26      *
     27      * @param context The application's context.
     28      *
     29      * @return A new UserFolder.
     30      */
     31     static UserFolder fromXml(Context context) {
     32         return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
     33     }
     34 
     35     public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
     36             DragView dragView, Object dragInfo) {
     37         final ItemInfo item = (ItemInfo) dragInfo;
     38         final int itemType = item.itemType;
     39         return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
     40                     itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
     41                 && item.container != mInfo.id;
     42     }
     43 
     44     public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
     45             DragView dragView, Object dragInfo, Rect recycle) {
     46         return null;
     47     }
     48 
     49     public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
     50             DragView dragView, Object dragInfo) {
     51         ShortcutInfo item;
     52         if (dragInfo instanceof ApplicationInfo) {
     53             // Came from all apps -- make a copy
     54             item = ((ApplicationInfo)dragInfo).makeShortcut();
     55         } else {
     56             item = (ShortcutInfo)dragInfo;
     57         }
     58         ((ShortcutsAdapter)mContent.getAdapter()).add(item);
     59         LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
     60     }
     61 
     62     public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
     63             DragView dragView, Object dragInfo) {
     64     }
     65 
     66     public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
     67             DragView dragView, Object dragInfo) {
     68     }
     69 
     70     public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
     71             DragView dragView, Object dragInfo) {
     72     }
     73 
     74     @Override
     75     public void onDropCompleted(View target, boolean success) {
     76         if (success) {
     77             ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
     78             adapter.remove(mDragItem);
     79         }
     80     }
     81 
     82     void bind(FolderInfo info) {
     83         super.bind(info);
     84         setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
     85     }
     86 
     87     // When the folder opens, we need to refresh the GridView's selection by
     88     // forcing a layout
     89     @Override
     90     void onOpen() {
     91         super.onOpen();
     92         requestFocus();
     93     }
     94 }
     95