The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.widget.GridView; |
| 20 | import android.widget.AdapterView; |
| 21 | import android.content.Context; |
| 22 | import android.content.res.TypedArray; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
| 25 | import android.graphics.BitmapFactory; |
| 26 | import android.graphics.Bitmap; |
| 27 | import android.graphics.Paint; |
| 28 | import android.graphics.Canvas; |
| 29 | |
| 30 | public class AllAppsGridView extends GridView implements AdapterView.OnItemClickListener, |
| 31 | AdapterView.OnItemLongClickListener, DragSource { |
| 32 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 33 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | private Launcher mLauncher; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 35 | private boolean mDraw = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | |
| 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected void onFinishInflate() { |
| 51 | setOnItemClickListener(this); |
| 52 | setOnItemLongClickListener(this); |
| 53 | } |
| 54 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 68 | mDragController.startDrag(view, this, app, DragController.DRAG_ACTION_COPY); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 69 | mLauncher.closeAllApps(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 70 | mDraw = false; |
| 71 | invalidate(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | return true; |
| 73 | } |
| 74 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 75 | @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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | public void onDropCompleted(View target, boolean success) { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 87 | mLauncher.closeAllApps(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void setLauncher(Launcher launcher) { |
| 91 | mLauncher = launcher; |
| 92 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 93 | |
| 94 | void onPrepareDialog() { |
| 95 | mDraw = true; |
| 96 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | } |