2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2012-04-04 12:47:08 -07:00
|
|
|
import android.content.Context;
|
2012-03-01 16:09:54 -08:00
|
|
|
import android.graphics.PointF;
|
2009-04-07 21:08:40 -07:00
|
|
|
import android.graphics.Rect;
|
2012-04-24 14:36:11 -07:00
|
|
|
import android.util.Log;
|
2009-04-07 21:08:40 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* Interface defining an object that can receive a drag.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public interface DropTarget {
|
2011-05-24 14:07:08 -07:00
|
|
|
|
2012-04-24 14:36:11 -07:00
|
|
|
public static final String TAG = "DropTarget";
|
|
|
|
|
|
2011-05-24 14:07:08 -07:00
|
|
|
class DragObject {
|
|
|
|
|
public int x = -1;
|
|
|
|
|
public int y = -1;
|
|
|
|
|
|
|
|
|
|
/** X offset from the upper-left corner of the cell to where we touched. */
|
|
|
|
|
public int xOffset = -1;
|
|
|
|
|
|
|
|
|
|
/** Y offset from the upper-left corner of the cell to where we touched. */
|
|
|
|
|
public int yOffset = -1;
|
|
|
|
|
|
2011-06-13 16:55:12 -07:00
|
|
|
/** This indicates whether a drag is in final stages, either drop or cancel. It
|
|
|
|
|
* differentiates onDragExit, since this is called when the drag is ending, above
|
|
|
|
|
* the current drag target, or when the drag moves off the current drag object.
|
|
|
|
|
*/
|
|
|
|
|
public boolean dragComplete = false;
|
|
|
|
|
|
2011-05-24 14:07:08 -07:00
|
|
|
/** The view that moves around while you drag. */
|
|
|
|
|
public DragView dragView = null;
|
|
|
|
|
|
|
|
|
|
/** The data associated with the object being dragged */
|
|
|
|
|
public Object dragInfo = null;
|
|
|
|
|
|
|
|
|
|
/** Where the drag originated */
|
|
|
|
|
public DragSource dragSource = null;
|
|
|
|
|
|
2011-07-08 15:34:52 -07:00
|
|
|
/** Post drag animation runnable */
|
|
|
|
|
public Runnable postAnimationRunnable = null;
|
|
|
|
|
|
2011-09-29 17:33:15 -07:00
|
|
|
/** Indicates that the drag operation was cancelled */
|
|
|
|
|
public boolean cancelled = false;
|
|
|
|
|
|
2012-02-13 18:29:29 -08:00
|
|
|
/** Defers removing the DragView from the DragLayer until after the drop animation. */
|
|
|
|
|
public boolean deferDragViewCleanupPostAnimation = true;
|
|
|
|
|
|
2011-05-24 14:07:08 -07:00
|
|
|
public DragObject() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-04 12:47:08 -07:00
|
|
|
public static class DragEnforcer implements DragController.DragListener {
|
|
|
|
|
int dragParity = 0;
|
|
|
|
|
|
|
|
|
|
public DragEnforcer(Context context) {
|
|
|
|
|
Launcher launcher = (Launcher) context;
|
|
|
|
|
launcher.getDragController().addDragListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onDragEnter() {
|
|
|
|
|
dragParity++;
|
|
|
|
|
if (dragParity != 1) {
|
2012-04-24 14:36:11 -07:00
|
|
|
Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
|
2012-04-04 12:47:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onDragExit() {
|
|
|
|
|
dragParity--;
|
|
|
|
|
if (dragParity != 0) {
|
2012-04-24 14:36:11 -07:00
|
|
|
Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
|
2012-04-04 12:47:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DragSource source, Object info, int dragAction) {
|
|
|
|
|
if (dragParity != 0) {
|
2012-04-24 14:36:11 -07:00
|
|
|
Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
|
2012-04-04 12:47:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragEnd() {
|
|
|
|
|
if (dragParity != 0) {
|
2012-04-24 14:36:11 -07:00
|
|
|
Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
|
2012-04-04 12:47:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-17 15:00:07 -07:00
|
|
|
/**
|
|
|
|
|
* Used to temporarily disable certain drop targets
|
|
|
|
|
*
|
|
|
|
|
* @return boolean specifying whether this drop target is currently enabled
|
|
|
|
|
*/
|
|
|
|
|
boolean isDropEnabled();
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle an object being dropped on the DropTarget
|
|
|
|
|
*
|
|
|
|
|
* @param source DragSource where the drag started
|
|
|
|
|
* @param x X coordinate of the drop location
|
|
|
|
|
* @param y Y coordinate of the drop location
|
2009-08-04 16:04:30 -04:00
|
|
|
* @param xOffset Horizontal offset with the object being dragged where the original
|
|
|
|
|
* touch happened
|
|
|
|
|
* @param yOffset Vertical offset with the object being dragged where the original
|
|
|
|
|
* touch happened
|
|
|
|
|
* @param dragView The DragView that's being dragged around on screen.
|
2009-03-03 19:32:27 -08:00
|
|
|
* @param dragInfo Data associated with the object being dragged
|
2013-07-03 08:23:13 -07:00
|
|
|
*
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2011-05-24 14:07:08 -07:00
|
|
|
void onDrop(DragObject dragObject);
|
|
|
|
|
|
|
|
|
|
void onDragEnter(DragObject dragObject);
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2011-05-24 14:07:08 -07:00
|
|
|
void onDragOver(DragObject dragObject);
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2011-05-24 14:07:08 -07:00
|
|
|
void onDragExit(DragObject dragObject);
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2012-03-01 16:09:54 -08:00
|
|
|
/**
|
|
|
|
|
* Handle an object being dropped as a result of flinging to delete and will be called in place
|
|
|
|
|
* of onDrop(). (This is only called on objects that are set as the DragController's
|
|
|
|
|
* fling-to-delete target.
|
|
|
|
|
*/
|
|
|
|
|
void onFlingToDelete(DragObject dragObject, int x, int y, PointF vec);
|
|
|
|
|
|
2010-07-13 17:50:32 -07:00
|
|
|
/**
|
|
|
|
|
* Allows a DropTarget to delegate drag and drop events to another object.
|
|
|
|
|
*
|
|
|
|
|
* Most subclasses will should just return null from this method.
|
|
|
|
|
*
|
|
|
|
|
* @param source DragSource where the drag started
|
|
|
|
|
* @param x X coordinate of the drop location
|
|
|
|
|
* @param y Y coordinate of the drop location
|
|
|
|
|
* @param xOffset Horizontal offset with the object being dragged where the original
|
|
|
|
|
* touch happened
|
|
|
|
|
* @param yOffset Vertical offset with the object being dragged where the original
|
|
|
|
|
* touch happened
|
|
|
|
|
* @param dragView The DragView that's being dragged around on screen.
|
|
|
|
|
* @param dragInfo Data associated with the object being dragged
|
|
|
|
|
*
|
|
|
|
|
* @return The DropTarget to delegate to, or null to not delegate to another object.
|
|
|
|
|
*/
|
2011-05-24 14:07:08 -07:00
|
|
|
DropTarget getDropTargetDelegate(DragObject dragObject);
|
2010-07-13 17:50:32 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2009-04-07 21:08:40 -07:00
|
|
|
* Check if a drop action can occur at, or near, the requested location.
|
2010-08-17 15:11:18 -07:00
|
|
|
* This will be called just before onDrop.
|
2009-04-07 21:08:40 -07:00
|
|
|
*
|
2009-03-03 19:32:27 -08:00
|
|
|
* @param source DragSource where the drag started
|
|
|
|
|
* @param x X coordinate of the drop location
|
|
|
|
|
* @param y Y coordinate of the drop location
|
2009-04-07 21:08:40 -07:00
|
|
|
* @param xOffset Horizontal offset with the object being dragged where the
|
|
|
|
|
* original touch happened
|
|
|
|
|
* @param yOffset Vertical offset with the object being dragged where the
|
|
|
|
|
* original touch happened
|
2009-08-04 16:04:30 -04:00
|
|
|
* @param dragView The DragView that's being dragged around on screen.
|
2009-03-03 19:32:27 -08:00
|
|
|
* @param dragInfo Data associated with the object being dragged
|
2009-04-07 21:08:40 -07:00
|
|
|
* @return True if the drop will be accepted, false otherwise.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2011-05-24 14:07:08 -07:00
|
|
|
boolean acceptDrop(DragObject dragObject);
|
2009-04-07 21:08:40 -07:00
|
|
|
|
2009-08-04 16:04:30 -04:00
|
|
|
// These methods are implemented in Views
|
|
|
|
|
void getHitRect(Rect outRect);
|
2011-07-07 16:38:18 -07:00
|
|
|
void getLocationInDragLayer(int[] loc);
|
2009-08-04 16:04:30 -04:00
|
|
|
int getLeft();
|
|
|
|
|
int getTop();
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|