OSDN Git Service

a898c1a02990a08e95423e0bc9d12699189a3c5e
[android-x86/packages-apps-Launcher.git] / src / com / android / launcher / AllAppsGridView.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.launcher;
18
19 import android.widget.GridView;
20 import android.widget.AdapterView;
21 import android.content.Context;
22 import android.util.AttributeSet;
23 import android.view.View;
24
25 public class AllAppsGridView extends GridView implements AdapterView.OnItemClickListener,
26         AdapterView.OnItemLongClickListener, DragSource {
27
28     private DragController mDragger;
29     private Launcher mLauncher;
30
31     public AllAppsGridView(Context context) {
32         super(context);
33     }
34
35     public AllAppsGridView(Context context, AttributeSet attrs) {
36         super(context, attrs);
37     }
38
39     public AllAppsGridView(Context context, AttributeSet attrs, int defStyle) {
40         super(context, attrs, defStyle);
41     }
42
43     @Override
44     protected void onFinishInflate() {
45         setOnItemClickListener(this);
46         setOnItemLongClickListener(this);
47     }
48
49     public void onItemClick(AdapterView parent, View v, int position, long id) {
50         ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
51         mLauncher.startActivitySafely(app.intent);
52     }
53
54     public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
55         if (!view.isInTouchMode()) {
56             return false;
57         }
58
59         ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
60         app = new ApplicationInfo(app);
61
62         mDragger.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
63         mLauncher.closeAllApplications();
64
65         return true;
66     }
67
68     public void setDragger(DragController dragger) {
69         mDragger = dragger;
70     }
71
72     public void onDropCompleted(View target, boolean success) {
73     }
74
75     void setLauncher(Launcher launcher) {
76         mLauncher = launcher;
77     }
78 }