blob: 71cd9524a342eccb75fdf5af057b4043958f6af8 [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
Joe Onorato00acb122009-08-04 16:04:30 -040033 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 private Launcher mLauncher;
Joe Onorato00acb122009-08-04 16:04:30 -040035 private boolean mDraw = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036
37 public AllAppsGridView(Context context) {
38 super(context);
39 }
40
41 public AllAppsGridView(Context context, AttributeSet attrs) {
42 this(context, attrs, com.android.internal.R.attr.gridViewStyle);
43 }
44
45 public AllAppsGridView(Context context, AttributeSet attrs, int defStyle) {
46 super(context, attrs, defStyle);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047 }
48
49 @Override
50 protected void onFinishInflate() {
51 setOnItemClickListener(this);
52 setOnItemLongClickListener(this);
53 }
54
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055 public void onItemClick(AdapterView parent, View v, int position, long id) {
56 ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
57 mLauncher.startActivitySafely(app.intent);
58 }
59
60 public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
61 if (!view.isInTouchMode()) {
62 return false;
63 }
64
65 ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
66 app = new ApplicationInfo(app);
67
Joe Onorato00acb122009-08-04 16:04:30 -040068 mDragController.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsfd22dac2009-09-20 17:24:16 -070069 mLauncher.closeAllApps();
Joe Onorato00acb122009-08-04 16:04:30 -040070 mDraw = false;
71 invalidate();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072 return true;
73 }
74
Joe Onorato00acb122009-08-04 16:04:30 -040075 @Override
76 protected void dispatchDraw(Canvas canvas) {
77 if (mDraw) {
78 super.dispatchDraw(canvas);
79 }
80 }
81
82 public void setDragController(DragController dragController) {
83 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084 }
85
86 public void onDropCompleted(View target, boolean success) {
Jason Samsfd22dac2009-09-20 17:24:16 -070087 mLauncher.closeAllApps();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088 }
89
90 void setLauncher(Launcher launcher) {
91 mLauncher = launcher;
92 }
Joe Onorato00acb122009-08-04 16:04:30 -040093
94 void onPrepareDialog() {
95 mDraw = true;
96 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097}