blob: 0d4785d491da9f3d74856e1139e1aae3dc892c5f [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;
29
30 public SpringLoadedDragController(Launcher launcher) {
31 mLauncher = launcher;
32 mAlarm = new Alarm();
33 mAlarm.setOnAlarmListener(this);
34 }
35
Winson Chungb26f3d62011-06-02 10:49:29 -070036 public void cancel() {
37 mAlarm.cancelAlarm();
38 }
39
40 // Set a new alarm to expire for the screen that we are hovering over now
41 public void setAlarm(CellLayout cl) {
42 if (mScreen != cl) {
Winson Chungc07918d2011-07-01 15:35:26 -070043 mAlarm.cancelAlarm();
Winson Chungb26f3d62011-06-02 10:49:29 -070044 mAlarm.setAlarm(ENTER_SPRING_LOAD_HOVER_TIME);
45 }
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);
55 w.snapToPage(page);
Winson Chungc07918d2011-07-01 15:35:26 -070056 } else {
57 mLauncher.getDragController().cancelDrag();
Michael Jurkad3ef3062010-11-23 16:23:58 -080058 }
59 }
60}