131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/*
231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * you may not use this file except in compliance with the License.
631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * You may obtain a copy of the License at
731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
1031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * See the License for the specific language governing permissions and
1431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * limitations under the License.
1531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */
1631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
17325dc23624160689e59fbac708cf6f222b20d025Daniel Sandlerpackage com.android.launcher3;
1831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
1970864289fba6daf07b8de98524cdfb765a62552dJeff Sharkeyimport android.graphics.Rect;
2070864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey
21e78e3d734b577c1ab6dc0738a83600374908ea52Sunny Goyalimport com.android.launcher3.accessibility.DragViewStateAnnouncer;
223dce5f3f507d0fbd27ab9c62ad66e0259abf22b3Sunny Goyalimport com.android.launcher3.dragndrop.DragOptions;
230f76b56865bd7b63bd21d53aaac47300396aa38fSunny Goyalimport com.android.launcher3.dragndrop.DragView;
24e78e3d734b577c1ab6dc0738a83600374908ea52Sunny Goyal
2531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/**
2631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Interface defining an object that can receive a drag.
2731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project *
2831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */
2931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectpublic interface DropTarget {
30cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
319eba1fd75e9fa6b0dc5cad9a4e817b3b167d2461Sunny Goyal    class DragObject {
32cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public int x = -1;
33cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public int y = -1;
34cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
35cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        /** X offset from the upper-left corner of the cell to where we touched.  */
36cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public int xOffset = -1;
37cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
38cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        /** Y offset from the upper-left corner of the cell to where we touched.  */
39cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public int yOffset = -1;
40cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
41bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen        /** This indicates whether a drag is in final stages, either drop or cancel. It
42bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen         * differentiates onDragExit, since this is called when the drag is ending, above
43bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen         * the current drag target, or when the drag moves off the current drag object.
44bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen         */
45bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen        public boolean dragComplete = false;
46bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen
47cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        /** The view that moves around while you drag.  */
48cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public DragView dragView = null;
49cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
5059a238095e82fd02355f4cb53abe01655a50b051Hyunyoung Song        /** The data associated with the object, after item is dropped. */
51aa8ef119f18864f4ab41c12f9c2ad6d7f643a0a9Sunny Goyal        public ItemInfo dragInfo = null;
52cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
5359a238095e82fd02355f4cb53abe01655a50b051Hyunyoung Song        /** The data associated with the object  being dragged */
5459a238095e82fd02355f4cb53abe01655a50b051Hyunyoung Song        public ItemInfo originalDragInfo = null;
5559a238095e82fd02355f4cb53abe01655a50b051Hyunyoung Song
56cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        /** Where the drag originated */
57cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public DragSource dragSource = null;
58cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
59c9735cff2e558aa3f3810e49c15ef13049b9429cAdam Cohen        /** The object is part of an accessible drag operation */
60c9735cff2e558aa3f3810e49c15ef13049b9429cAdam Cohen        public boolean accessibleDrag;
61c9735cff2e558aa3f3810e49c15ef13049b9429cAdam Cohen
6236cc09b07b19198f4ea886583cef462ade27192cAdam Cohen        /** Indicates that the drag operation was cancelled */
6336cc09b07b19198f4ea886583cef462ade27192cAdam Cohen        public boolean cancelled = false;
6436cc09b07b19198f4ea886583cef462ade27192cAdam Cohen
657bd1bbb509f9569fa18d6b4d33242679fd98bc9bWinson Chung        /** Defers removing the DragView from the DragLayer until after the drop animation. */
667bd1bbb509f9569fa18d6b4d33242679fd98bc9bWinson Chung        public boolean deferDragViewCleanupPostAnimation = true;
677bd1bbb509f9569fa18d6b4d33242679fd98bc9bWinson Chung
68e78e3d734b577c1ab6dc0738a83600374908ea52Sunny Goyal        public DragViewStateAnnouncer stateAnnouncer;
69e78e3d734b577c1ab6dc0738a83600374908ea52Sunny Goyal
70cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        public DragObject() {
71cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen        }
721587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal
731587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal        /**
741587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal         * This is used to compute the visual center of the dragView. This point is then
751587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal         * used to visualize drop locations and determine where to drop an item. The idea is that
761587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal         * the visual center represents the user's interpretation of where the item is, and hence
771587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal         * is the appropriate point to use when determining drop location.
781587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal         */
791587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal        public final float[] getVisualCenter(float[] recycle) {
801587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            final float res[] = (recycle == null) ? new float[2] : recycle;
811587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal
821587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            // These represent the visual top and left of drag view if a dragRect was provided.
831587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            // If a dragRect was not provided, then they correspond to the actual view left and
841587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            // top, as the dragRect is in that case taken to be the entire dragView.
851587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            // R.dimen.dragViewOffsetY.
861587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            int left = x - xOffset;
871587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            int top = y - yOffset;
881587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal
891587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            // In order to find the visual center, we shift by half the dragRect
901587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            res[0] = left + dragView.getDragRegion().width() / 2;
911587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            res[1] = top + dragView.getDragRegion().height() / 2;
921587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal
931587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal            return res;
941587d5362f5a66e005aa36fdfc7082c34b8ea3b7Sunny Goyal        }
95cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen    }
96cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
970280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka    /**
980280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka     * Used to temporarily disable certain drop targets
990280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka     *
1000280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka     * @return boolean specifying whether this drop target is currently enabled
1010280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka     */
1020280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka    boolean isDropEnabled();
10331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
10431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
1051797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * Handle an object being dropped on the DropTarget.
1061797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     *
1071797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * This will be called only if this target previously returned true for {@link #acceptDrop}. It
1081797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * is the responsibility of this target to exit out of the spring loaded mode (either
1091797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * immediately or after any pending animations).
1101797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     *
1111797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * If the drop was cancelled for some reason, onDrop will never get called, the UI will
1121797af41d162413dc98c33fab8ba19f96b63874bSunny Goyal     * automatically exit out of this mode.
11331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
1143dce5f3f507d0fbd27ab9c62ad66e0259abf22b3Sunny Goyal    void onDrop(DragObject dragObject, DragOptions options);
115cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen
116cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen    void onDragEnter(DragObject dragObject);
11731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
118cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen    void onDragOver(DragObject dragObject);
11931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
120cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen    void onDragExit(DragObject dragObject);
12131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project
12231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project    /**
12370864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey     * Check if a drop action can occur at, or near, the requested location.
1244ed6278e518cc6894cb150b606382e8e6a012599Patrick Dubroy     * This will be called just before onDrop.
12570864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey     * @return True if the drop will be accepted, false otherwise.
12631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project     */
127cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen    boolean acceptDrop(DragObject dragObject);
12870864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey
129e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal    void prepareAccessibilityDrop();
130e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal
13100acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato    // These methods are implemented in Views
1327d30a37007bac318db1c9af47a9af12d348042a5Adam Cohen    void getHitRectRelativeToDragLayer(Rect outRect);
13331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project}
134