Folder.java revision a9cf38f533d1e86269868f1e6a806ccffd4a78fc
131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/*
231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * you may not use this file except in compliance with the License.
631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * You may obtain a copy of the License at
731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
1031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * See the License for the specific language governing permissions and
1431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * limitations under the License.
1531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */
1631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
17a5902524d4403885eb4c50360bf3465c6be796efJoe Onoratopackage com.android.launcher2;
1831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
19df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport java.util.ArrayList;
20df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
21df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.Animator;
22df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.AnimatorListenerAdapter;
23df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.AnimatorSet;
24df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.ObjectAnimator;
25df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.PropertyValuesHolder;
26df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.ValueAnimator;
27df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.animation.ValueAnimator.AnimatorUpdateListener;
2831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.content.Context;
29fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guyimport android.graphics.Rect;
3031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.util.AttributeSet;
31df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.view.LayoutInflater;
3231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.view.View;
3331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.view.View.OnClickListener;
3431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.widget.AdapterView;
3531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.widget.Button;
3631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.widget.LinearLayout;
37df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohenimport android.widget.TextView;
3831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.widget.AdapterView.OnItemClickListener;
3931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectimport android.widget.AdapterView.OnItemLongClickListener;
4031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
41edcce099c98a6c40d10109ac092ab50f9d2668f3Romain Guyimport com.android.launcher.R;
42a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohenimport com.android.launcher2.FolderInfo.FolderListener;
43edcce099c98a6c40d10109ac092ab50f9d2668f3Romain Guy
4431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/**
4531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Represents a set of icons chosen by the user or generated by the system.
4631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */
4731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectpublic class Folder extends LinearLayout implements DragSource, OnItemLongClickListener,
48a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        OnItemClickListener, OnClickListener, View.OnLongClickListener, DropTarget, FolderListener {
4931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
5000acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato    protected DragController mDragController;
51df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
5231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    protected Launcher mLauncher;
5331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
5431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    protected Button mCloseButton;
55df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
5631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    protected FolderInfo mInfo;
5731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
5831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
5931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * Which item is being dragged
6031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
610589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato    protected ShortcutInfo mDragItem;
6231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
63df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private static final String TAG = "Launcher.Folder";
64df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
65df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    static final int STATE_NONE = -1;
66df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    static final int STATE_SMALL = 0;
67df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    static final int STATE_ANIMATING = 1;
68df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    static final int STATE_OPEN = 2;
69df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
70df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private int mExpandDuration;
71df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    protected CellLayout mContent;
72df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private final LayoutInflater mInflater;
73df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private final IconCache mIconCache;
74df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private int mState = STATE_NONE;
75a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    private int[] mDragItemPosition = new int[2];
76df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
7731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
7831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * Used to inflate the Workspace from XML.
7931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     *
8031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * @param context The application's context.
8131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * @param attrs The attribtues set containing the Workspace's customization values.
8231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
8331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public Folder(Context context, AttributeSet attrs) {
8431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        super(context, attrs);
8531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        setAlwaysDrawnWithCacheEnabled(false);
86df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mInflater = LayoutInflater.from(context);
87df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mIconCache = ((LauncherApplication)context.getApplicationContext()).getIconCache();
88df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mExpandDuration = getResources().getInteger(R.integer.config_folderAnimDuration);
8931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
9031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
9131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    @Override
9231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    protected void onFinishInflate() {
9331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        super.onFinishInflate();
9431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
95924423076381925909c4e3cb176fc16fe6d21462Joe Onorato        mCloseButton = (Button) findViewById(R.id.folder_close);
9631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mCloseButton.setOnClickListener(this);
9731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mCloseButton.setOnLongClickListener(this);
98df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mContent = (CellLayout) findViewById(R.id.folder_content);
9931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
10031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
10131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public void onItemClick(AdapterView parent, View v, int position, long id) {
1020589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato        ShortcutInfo app = (ShortcutInfo) parent.getItemAtPosition(position);
103fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guy        int[] pos = new int[2];
104fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guy        v.getLocationOnScreen(pos);
105fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guy        app.intent.setSourceBounds(new Rect(pos[0], pos[1],
106fb5411e98278d461b78aea0663d3e85f7a9e8a15Romain Guy                pos[0] + v.getWidth(), pos[1] + v.getHeight()));
107f984e853f253c76a7a636a094680bb01c4b8ffb8Joe Onorato        mLauncher.startActivitySafely(app.intent, app);
10831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
10931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
11031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public void onClick(View v) {
111df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        Object tag = v.getTag();
112df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (tag instanceof ShortcutInfo) {
113df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            // refactor this code from Folder
114df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            ShortcutInfo item = (ShortcutInfo) tag;
115df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            int[] pos = new int[2];
116df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            v.getLocationOnScreen(pos);
117df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item.intent.setSourceBounds(new Rect(pos[0], pos[1],
118df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                    pos[0] + v.getWidth(), pos[1] + v.getHeight()));
119df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.startActivitySafely(item.intent, item);
120df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        } else {
121df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.closeFolder(this);
122df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
12331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
12431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
12531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public boolean onLongClick(View v) {
126df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        Object tag = v.getTag();
127df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (tag instanceof ShortcutInfo) {
128df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen         // refactor this code from Folder
129df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            ShortcutInfo item = (ShortcutInfo) tag;
130df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            if (!v.isInTouchMode()) {
131df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                return false;
132df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
133df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
134df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.getWorkspace().onDragStartedWithItem(v);
135df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mDragController.startDrag(v, this, item, DragController.DRAG_ACTION_COPY);
136a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen            mDragItemPosition[0] = item.cellX;
137a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen            mDragItemPosition[1] = item.cellY;
138df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.closeFolder(this);
139df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mDragItem = item;
140df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        } else {
141df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.closeFolder(this);
142df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mLauncher.showRenameDialog(mInfo);
143df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
14431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        return true;
14531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
14631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
14731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
14831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        if (!view.isInTouchMode()) {
14931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project            return false;
15031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        }
15131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
1520589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato        ShortcutInfo app = (ShortcutInfo) parent.getItemAtPosition(position);
15331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
15400acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato        mDragController.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
15531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mLauncher.closeFolder(this);
15631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mDragItem = app;
15731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
15831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        return true;
15931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
16031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
16100acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato    public void setDragController(DragController dragController) {
16200acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato        mDragController = dragController;
16331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
16431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
165a669d79d0dcf034651ce305a8cd334272bec3374Patrick Dubroy    public void onDragViewVisible() {
166a669d79d0dcf034651ce305a8cd334272bec3374Patrick Dubroy    }
167a669d79d0dcf034651ce305a8cd334272bec3374Patrick Dubroy
16831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    void setLauncher(Launcher launcher) {
16931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mLauncher = launcher;
17031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
17131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
17231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
17331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     * @return the FolderInfo object associated with this folder
17431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
17531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    FolderInfo getInfo() {
17631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        return mInfo;
17731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
17831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
17931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    void onOpen() {
180df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        // When the folder opens, we need to refresh the GridView's selection by
181df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        // forcing a layout
182df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        // TODO: find out if this is still necessary
183df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mContent.requestLayout();
184df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        requestFocus();
18531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
18631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
18731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    void onClose() {
18831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        final Workspace workspace = mLauncher.getWorkspace();
1890142d49e1378a7155bcca1fb59965d9e73016dbcMichael Jurka        workspace.getChildAt(workspace.getCurrentPage()).requestFocus();
19031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
19131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
19231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    void bind(FolderInfo info) {
19331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mInfo = info;
19431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project        mCloseButton.setText(info.title);
195df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ArrayList<ShortcutInfo> children = info.contents;
196df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        for (int i = 0; i < children.size(); i++) {
197df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            ShortcutInfo child = (ShortcutInfo) children.get(i);
198df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            if ((child.cellX == -1 && child.cellY == -1) ||
199df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                    mContent.isOccupied(child.cellX, child.cellY)) {
200df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                findAndSetEmptyCells(child);
201df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
202df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            createAndAddShortcut((ShortcutInfo) children.get(i));
203df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
204a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        mInfo.addListener(this);
205df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
206df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
207df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    /**
208df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * Creates a new UserFolder, inflated from R.layout.user_folder.
209df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     *
210df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * @param context The application's context.
211df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     *
212df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * @return A new UserFolder.
213df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     */
214df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    static Folder fromXml(Context context) {
215df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
216df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
217df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
218df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    /**
219df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * This method is intended to make the UserFolder to be visually identical in size and position
220df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
221df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen     */
222df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    private void positionAndSizeAsIcon() {
223df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (!(getParent() instanceof CellLayoutChildren)) return;
224df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
225df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayoutChildren clc = (CellLayoutChildren) getParent();
226df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout cellLayout = (CellLayout) clc.getParent();
227df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
228df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        FolderIcon fi = (FolderIcon) cellLayout.getChildAt(mInfo.cellX, mInfo.cellY);
229df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams iconLp = (CellLayout.LayoutParams) fi.getLayoutParams();
230df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
231df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
232df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        lp.width = iconLp.width;
233df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        lp.height = iconLp.height;
234df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        lp.x = iconLp.x;
235df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        lp.y = iconLp.y;
236df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
237df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mContent.setAlpha(0f);
238df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mState = STATE_SMALL;
239df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
240df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
241df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void animateOpen() {
242df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (mState != STATE_SMALL) {
243df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            positionAndSizeAsIcon();
244df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
245df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (!(getParent() instanceof CellLayoutChildren)) return;
246df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
247df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
248df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
249df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayoutChildren clc = (CellLayoutChildren) getParent();
250df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout cellLayout = (CellLayout) clc.getParent();
251df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        Rect r = cellLayout.getContentRect(null);
252df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
253df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", r.width());
254df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", r.height());
255df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", 0);
256df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", 0);
257df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
258df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y);
259df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        oa.addUpdateListener(new AnimatorUpdateListener() {
260df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationUpdate(ValueAnimator animation) {
261df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                requestLayout();
262df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
263df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        });
264df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
265df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
266df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ObjectAnimator oaContentAlpha = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha);
267df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
268df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        AnimatorSet set = new AnimatorSet();
269df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.playTogether(oa, oaContentAlpha);
270df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.setDuration(mExpandDuration);
271df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.addListener(new AnimatorListenerAdapter() {
272df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            @Override
273df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationStart(Animator animation) {
274df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                mState = STATE_ANIMATING;
275df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
276df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            @Override
277df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationEnd(Animator animation) {
278df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                mState = STATE_SMALL;
279df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
280df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        });
281df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.start();
282df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
283df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
284df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void animateClosed() {
285df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (!(getParent() instanceof CellLayoutChildren)) return;
286df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
287df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayoutChildren clc = (CellLayoutChildren) getParent();
288df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        final CellLayout cellLayout = (CellLayout) clc.getParent();
289df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
290df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        FolderIcon fi = (FolderIcon) cellLayout.getChildAt(mInfo.cellX, mInfo.cellY);
291df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams iconLp = (CellLayout.LayoutParams) fi.getLayoutParams();
292df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
293df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
294df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", iconLp.width);
295df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", iconLp.height);
296df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder x = PropertyValuesHolder.ofInt("x",iconLp.x);
297df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", iconLp.y);
298df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
299df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y);
300df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        oa.addUpdateListener(new AnimatorUpdateListener() {
301df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationUpdate(ValueAnimator animation) {
302df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                requestLayout();
303df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
304df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        });
305df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
306df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
307df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ObjectAnimator oaContentAlpha = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha);
308df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
309df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        AnimatorSet set = new AnimatorSet();
310df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.playTogether(oa, oaContentAlpha);
311df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.setDuration(mExpandDuration);
312df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
313df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.addListener(new AnimatorListenerAdapter() {
314df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            @Override
315df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationEnd(Animator animation) {
316df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                cellLayout.removeViewWithoutMarkingCells(Folder.this);
317df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                mState = STATE_OPEN;
318df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
319df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            @Override
320df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            public void onAnimationStart(Animator animation) {
321df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                mState = STATE_ANIMATING;
322df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            }
323df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        });
324df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        set.start();
325df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
326df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
327df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    void notifyDataSetChanged() {
328df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        // recreate all the children if the data set changes under us. We may want to do this more
329df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        // intelligently (ie just removing the views that should no longer exist)
330df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mContent.removeAllViewsInLayout();
331df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        bind(mInfo);
332df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
333df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
334df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
335df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
336df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        final ItemInfo item = (ItemInfo) dragInfo;
337df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        final int itemType = item.itemType;
338df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
339df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                    itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
340df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                && item.container != mInfo.id;
341df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
342df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
343df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
344df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
345df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        ShortcutInfo item;
346df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (dragInfo instanceof ApplicationInfo) {
347df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            // Came from all apps -- make a copy
348df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item = ((ApplicationInfo)dragInfo).makeShortcut();
349df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item.spanX = 1;
350df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item.spanY = 1;
351df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        } else {
352df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item = (ShortcutInfo)dragInfo;
353df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
354df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        findAndSetEmptyCells(item);
355df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mInfo.add(item);
356df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        createAndAddShortcut(item);
357df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
358df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
359df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
360df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    protected boolean findAndSetEmptyCells(ShortcutInfo item) {
361df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        int[] emptyCell = new int[2];
362df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
363df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item.cellX = emptyCell[0];
364df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            item.cellY = emptyCell[1];
365df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            LauncherModel.addOrMoveItemInDatabase(
366df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                    mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
367df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            return true;
368df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        } else {
369df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            return false;
370df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
371df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
372df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
373df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    protected void createAndAddShortcut(ShortcutInfo item) {
374df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        final TextView textView =
375df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            (TextView) mInflater.inflate(R.layout.application_boxed, this, false);
376df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        textView.setCompoundDrawablesWithIntrinsicBounds(null,
377df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen                new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
378df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        textView.setText(item.title);
379df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        textView.setTag(item);
380df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
381df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        textView.setOnClickListener(this);
382df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        textView.setOnLongClickListener(this);
383df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
384df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        CellLayout.LayoutParams lp =
385df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
386df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        boolean insert = false;
387df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
388df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
389df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
390df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
391df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
392df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
393df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
394df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
395df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
396df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
397df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
398df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
399df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
400df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
401df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
402df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public void onDropCompleted(View target, Object dragInfo, boolean success) {
403df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        if (success) {
404df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            mInfo.remove(mDragItem);
405df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        }
406df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
407df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
408df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public boolean isDropEnabled() {
409df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        return true;
410df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    }
411df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen
412df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen    public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
413df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen            DragView dragView, Object dragInfo) {
414df2cc41acbfacd576f99483a4af1cda32ebd3d09Adam Cohen        return null;
41531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    }
416a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen
417a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    public void onAdd(ShortcutInfo item) {
418a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        if ((item.cellX == -1 && item.cellY == -1) ||
419a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen                mContent.isOccupied(item.cellX, item.cellY)) {
420a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen            findAndSetEmptyCells(item);
421a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        }
422a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        createAndAddShortcut(item);
423a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    }
424a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen
425a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    public int getItemCount() {
426a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        return mContent.getChildrenLayout().getChildCount();
427a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    }
428a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen
429a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    public View getItemAt(int index) {
430a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        return mContent.getChildrenLayout().getChildAt(index);
431a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    }
432a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen
433a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    public void onRemove(ShortcutInfo item) {
434a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        View v = mContent.getChildAt(mDragItemPosition[0], mDragItemPosition[1]);
435a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen        mContent.removeView(v);
436a9cf38f533d1e86269868f1e6a806ccffd4a78fcAdam Cohen    }
43731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project}
438