blob: 45edaef861668242afa90751f4ee5d5763b61165 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Michael Jurkad3ef3062010-11-23 16:23:58 -080018
19public class SpringLoadedDragController implements OnAlarmListener {
20 // how long the user must hover over a mini-screen before it unshrinks
Winson Chung3bc21c32012-01-20 13:59:18 -080021 final long ENTER_SPRING_LOAD_HOVER_TIME = 500;
Winson Chung1c4cf4a2011-07-29 14:49:10 -070022 final long ENTER_SPRING_LOAD_CANCEL_HOVER_TIME = 950;
Michael Jurkad3ef3062010-11-23 16:23:58 -080023 final long EXIT_SPRING_LOAD_HOVER_TIME = 200;
24
25 Alarm mAlarm;
26
27 // the screen the user is currently hovering over, if any
28 private CellLayout mScreen;
29 private Launcher mLauncher;
30
31 public SpringLoadedDragController(Launcher launcher) {
32 mLauncher = launcher;
33 mAlarm = new Alarm();
34 mAlarm.setOnAlarmListener(this);
35 }
36
Winson Chungb26f3d62011-06-02 10:49:29 -070037 public void cancel() {
38 mAlarm.cancelAlarm();
39 }
40
41 // Set a new alarm to expire for the screen that we are hovering over now
42 public void setAlarm(CellLayout cl) {
Winson Chungb8dffaf2011-07-08 11:14:33 -070043 mAlarm.cancelAlarm();
Winson Chung1c4cf4a2011-07-29 14:49:10 -070044 mAlarm.setAlarm((cl == null) ? ENTER_SPRING_LOAD_CANCEL_HOVER_TIME :
45 ENTER_SPRING_LOAD_HOVER_TIME);
Michael Jurkad3ef3062010-11-23 16:23:58 -080046 mScreen = cl;
Michael Jurkad3ef3062010-11-23 16:23:58 -080047 }
48
49 // this is called when our timer runs out
50 public void onAlarm(Alarm alarm) {
51 if (mScreen != null) {
Winson Chungb26f3d62011-06-02 10:49:29 -070052 // Snap to the screen that we are hovering over now
53 Workspace w = mLauncher.getWorkspace();
54 int page = w.indexOfChild(mScreen);
Winson Chungb8dffaf2011-07-08 11:14:33 -070055 if (page != w.getCurrentPage()) {
56 w.snapToPage(page);
57 }
Winson Chungc07918d2011-07-01 15:35:26 -070058 } else {
59 mLauncher.getDragController().cancelDrag();
Michael Jurkad3ef3062010-11-23 16:23:58 -080060 }
61 }
62}