blob: b418a793f15317f771fc33deb181febfcc7cda3b [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.content.Context;
Adam Cohen120980b2010-12-08 11:05:37 -080020import android.graphics.Bitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.util.AttributeSet;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022import android.view.KeyEvent;
Michael Jurka0e260592010-06-30 17:07:39 -070023import android.view.MotionEvent;
Romain Guyea3763c2010-01-11 18:02:04 -080024import android.view.View;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.widget.FrameLayout;
Adam Cohen120980b2010-12-08 11:05:37 -080026import android.widget.ImageView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027
28/**
Michael Jurka0e260592010-06-30 17:07:39 -070029 * A ViewGroup that coordinates dragging across its descendants
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030 */
Joe Onorato00acb122009-08-04 16:04:30 -040031public class DragLayer extends FrameLayout {
Adam Cohen120980b2010-12-08 11:05:37 -080032 private DragController mDragController;
33 private int[] mTmpXY = new int[2];
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034
35 /**
36 * Used to create a new DragLayer from XML.
37 *
38 * @param context The application's context.
Michael Jurka0e260592010-06-30 17:07:39 -070039 * @param attrs The attributes set containing the Workspace's customization values.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040 */
41 public DragLayer(Context context, AttributeSet attrs) {
42 super(context, attrs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043 }
44
Joe Onorato00acb122009-08-04 16:04:30 -040045 public void setDragController(DragController controller) {
46 mDragController = controller;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047 }
Joe Onorato00acb122009-08-04 16:04:30 -040048
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049 @Override
50 public boolean dispatchKeyEvent(KeyEvent event) {
Joe Onorato00acb122009-08-04 16:04:30 -040051 return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052 }
53
54 @Override
55 public boolean onInterceptTouchEvent(MotionEvent ev) {
Joe Onorato4db52312009-10-06 11:17:43 -070056 return mDragController.onInterceptTouchEvent(ev);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 }
58
59 @Override
60 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato4db52312009-10-06 11:17:43 -070061 return mDragController.onTouchEvent(ev);
Romain Guy91a9c962009-06-12 13:52:17 -070062 }
Romain Guyea3763c2010-01-11 18:02:04 -080063
64 @Override
65 public boolean dispatchUnhandledMove(View focused, int direction) {
66 return mDragController.dispatchUnhandledMove(focused, direction);
67 }
Adam Cohen120980b2010-12-08 11:05:37 -080068
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 Project31dd5032009-03-03 19:32:27 -080083}