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.content.Context; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame^] | 20 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.util.AttributeSet; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | import android.view.KeyEvent; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 23 | import android.view.MotionEvent; |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 24 | import android.view.View; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.widget.FrameLayout; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame^] | 26 | import android.widget.ImageView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 29 | * A ViewGroup that coordinates dragging across its descendants |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | */ |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 31 | public class DragLayer extends FrameLayout { |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame^] | 32 | private DragController mDragController; |
| 33 | private int[] mTmpXY = new int[2]; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Used to create a new DragLayer from XML. |
| 37 | * |
| 38 | * @param context The application's context. |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 39 | * @param attrs The attributes set containing the Workspace's customization values. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | */ |
| 41 | public DragLayer(Context context, AttributeSet attrs) { |
| 42 | super(context, attrs); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 45 | public void setDragController(DragController controller) { |
| 46 | mDragController = controller; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 48 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | @Override |
| 50 | public boolean dispatchKeyEvent(KeyEvent event) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 51 | return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 56 | return mDragController.onInterceptTouchEvent(ev); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean onTouchEvent(MotionEvent ev) { |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 61 | return mDragController.onTouchEvent(ev); |
Romain Guy | 91a9c96 | 2009-06-12 13:52:17 -0700 | [diff] [blame] | 62 | } |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 63 | |
| 64 | @Override |
| 65 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 66 | return mDragController.dispatchUnhandledMove(focused, direction); |
| 67 | } |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame^] | 68 | |
| 69 | public View createDragView(Bitmap b, int xPos, int yPos) { |
| 70 | ImageView imageView = new ImageView(mContext); |
| 71 | imageView.setImageBitmap(b); |
| 72 | imageView.setX(xPos); |
| 73 | imageView.setY(yPos); |
| 74 | addView(imageView, b.getWidth(), b.getHeight()); |
| 75 | |
| 76 | return imageView; |
| 77 | } |
| 78 | |
| 79 | public View createDragView(View v) { |
| 80 | v.getLocationOnScreen(mTmpXY); |
| 81 | return createDragView(mDragController.getViewBitmap(v), mTmpXY[0], mTmpXY[1]); |
| 82 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | } |