blob: 900758118bbb651a2ffa1898d79e06907701dc2b [file] [log] [blame]
Michael Jurkad3ef3062010-11-23 16:23:58 -08001/*
2 * Copyright (C) 2010 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
17package com.android.launcher2;
18
19public class SpringLoadedDragController implements OnAlarmListener {
20 // how long the user must hover over a mini-screen before it unshrinks
21 final long ENTER_SPRING_LOAD_HOVER_TIME = 1000;
22 final long EXIT_SPRING_LOAD_HOVER_TIME = 200;
23
24 Alarm mAlarm;
25
26 // the screen the user is currently hovering over, if any
27 private CellLayout mScreen;
28 private Launcher mLauncher;
Michael Jurka0bb85632011-01-26 00:00:44 -080029 boolean mFinishedAnimation = false;
30 boolean mWaitingToReenter = false;
Michael Jurkad3ef3062010-11-23 16:23:58 -080031
32 public SpringLoadedDragController(Launcher launcher) {
33 mLauncher = launcher;
34 mAlarm = new Alarm();
35 mAlarm.setOnAlarmListener(this);
36 }
37
Michael Jurka0bb85632011-01-26 00:00:44 -080038 public void onDragEnter(CellLayout cl, boolean isSpringLoaded) {
Michael Jurkad3ef3062010-11-23 16:23:58 -080039 mScreen = cl;
40 mAlarm.setAlarm(ENTER_SPRING_LOAD_HOVER_TIME);
Michael Jurka0bb85632011-01-26 00:00:44 -080041 mFinishedAnimation = isSpringLoaded;
42 mWaitingToReenter = false;
43 }
44
45 public void onEnterSpringLoadedMode(boolean waitToReenter) {
46 mFinishedAnimation = true;
47 mWaitingToReenter = waitToReenter;
Michael Jurkad3ef3062010-11-23 16:23:58 -080048 }
49
50 public void onDragExit() {
51 if (mScreen != null) {
52 mScreen.onDragExit();
53 }
54 mScreen = null;
Michael Jurka0bb85632011-01-26 00:00:44 -080055 if (mFinishedAnimation && !mWaitingToReenter) {
56 mAlarm.setAlarm(EXIT_SPRING_LOAD_HOVER_TIME);
57 }
Michael Jurkad3ef3062010-11-23 16:23:58 -080058 }
59
60 // this is called when our timer runs out
61 public void onAlarm(Alarm alarm) {
62 if (mScreen != null) {
63 // we're currently hovering over a screen
64 mLauncher.enterSpringLoadedDragMode(mScreen);
65 } else {
66 mLauncher.exitSpringLoadedDragMode();
67 }
68 }
69}