2 * This is a modified version of a class from the Android Open Source Project.
3 * The original copyright and license information follows.
5 * Copyright (C) 2008 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package com.blahti.drag;
22 import android.content.Context;
23 import android.graphics.Rect;
24 import android.util.AttributeSet;
25 import android.view.MotionEvent;
26 import android.view.KeyEvent;
27 import android.view.View;
30 * A ViewGroup that coordinates dragging across its descendants.
32 * <p> This class used DragLayer in the Android Launcher activity as a model.
33 * It is a bit different in several respects:
34 * (1) It extends MyAbsoluteLayout rather than FrameLayout; (2) it implements DragSource and DropTarget methods
35 * that were done in a separate Workspace class in the Launcher.
37 public class DragLayer extends MyAbsoluteLayout implements DragSource, DropTarget {
38 private DragController mDragController;
40 public DragLayer (Context context, AttributeSet attrs) {
41 super(context, attrs);
44 public boolean dispatchKeyEvent(KeyEvent event) {
45 return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
48 public boolean onInterceptTouchEvent(MotionEvent ev) {
49 return mDragController.onInterceptTouchEvent(ev);
52 public boolean onTouchEvent(MotionEvent ev) {
53 return mDragController.onTouchEvent(ev);
56 public boolean dispatchUnhandledMove(View focused, int direction) {
57 return mDragController.dispatchUnhandledMove(focused, direction);
60 // Interfaces of DragSource
62 public boolean allowDrag() {
66 public void setDragController(DragController controller) {
67 mDragController = controller;
70 public void onDropCompleted(View target, boolean success) {
73 // Interfaces of DropTarget
75 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) {
76 final View v = (View)dragInfo;
77 final int w = v.getWidth();
78 final int h = v.getHeight();
79 final int left = x - xOffset;
80 final int top = y - yOffset;
81 final DragLayer.LayoutParams lp = new DragLayer.LayoutParams (w, h, left, top);
82 updateViewLayout(v, lp);
85 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) {
88 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) {
91 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) {
94 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) {
98 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo, Rect recycle) {