blob: cca9ed2ef351815b3dd561fe27533326c6172ef0 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.widget.GridView;
20import android.widget.AdapterView;
21import android.content.Context;
22import android.content.res.TypedArray;
23import android.util.AttributeSet;
24import android.view.View;
25import android.graphics.BitmapFactory;
26import android.graphics.Bitmap;
27import android.graphics.Paint;
28import android.graphics.Canvas;
29
30public class AllAppsGridView extends GridView implements AdapterView.OnItemClickListener,
31 AdapterView.OnItemLongClickListener, DragSource {
32
33 private DragController mDragger;
34 private Launcher mLauncher;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035
36 public AllAppsGridView(Context context) {
37 super(context);
38 }
39
40 public AllAppsGridView(Context context, AttributeSet attrs) {
41 this(context, attrs, com.android.internal.R.attr.gridViewStyle);
42 }
43
44 public AllAppsGridView(Context context, AttributeSet attrs, int defStyle) {
45 super(context, attrs, defStyle);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046 }
47
48 @Override
49 protected void onFinishInflate() {
50 setOnItemClickListener(this);
51 setOnItemLongClickListener(this);
52 }
53
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054 public void onItemClick(AdapterView parent, View v, int position, long id) {
55 ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
56 mLauncher.startActivitySafely(app.intent);
57 }
58
59 public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
60 if (!view.isInTouchMode()) {
61 return false;
62 }
63
64 ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
65 app = new ApplicationInfo(app);
66
67 mDragger.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
68 mLauncher.closeAllApplications();
69
70 return true;
71 }
72
73 public void setDragger(DragController dragger) {
74 mDragger = dragger;
75 }
76
77 public void onDropCompleted(View target, boolean success) {
78 }
79
80 void setLauncher(Launcher launcher) {
81 mLauncher = launcher;
82 }
83}