blob: 5c3752ad6d68df9273ea533718590752cbcf1ac8 [file] [log] [blame]
Winson Chung88f33452012-02-23 15:23:44 -08001/*
2 * Copyright (C) 2012 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
19import android.view.View;
20
21public class CheckLongPressHelper {
22 private View mView;
23 private boolean mHasPerformedLongPress;
24 private CheckForLongPress mPendingCheckForLongPress;
25
26 class CheckForLongPress implements Runnable {
27 public void run() {
28 if ((mView.getParent() != null) && mView.hasWindowFocus()
29 && !mHasPerformedLongPress) {
30 if (mView.performLongClick()) {
Winson Chung401d3a52012-03-08 12:10:40 -080031 mView.setPressed(false);
Winson Chung88f33452012-02-23 15:23:44 -080032 mHasPerformedLongPress = true;
33 }
34 }
35 }
36 }
37
38 public CheckLongPressHelper(View v) {
39 mView = v;
40 }
41
42 public void postCheckForLongPress() {
43 mHasPerformedLongPress = false;
44
45 if (mPendingCheckForLongPress == null) {
46 mPendingCheckForLongPress = new CheckForLongPress();
47 }
48 mView.postDelayed(mPendingCheckForLongPress, LauncherApplication.getLongPressTimeout());
49 }
50
51 public void cancelLongPress() {
52 mHasPerformedLongPress = false;
53 if (mPendingCheckForLongPress != null) {
54 mView.removeCallbacks(mPendingCheckForLongPress);
55 mPendingCheckForLongPress = null;
56 }
57 }
58
59 public boolean hasPerformedLongPress() {
60 return mHasPerformedLongPress;
61 }
62}