blob: 81149793dff6675bfcf48a3c722a35ed2110424c [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung88f33452012-02-23 15:23:44 -080018
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 }
Daniel Sandlere4f98912013-06-25 15:13:26 -040048 mView.postDelayed(mPendingCheckForLongPress,
49 LauncherAppState.getInstance().getLongPressTimeout());
Winson Chung88f33452012-02-23 15:23:44 -080050 }
51
52 public void cancelLongPress() {
53 mHasPerformedLongPress = false;
54 if (mPendingCheckForLongPress != null) {
55 mView.removeCallbacks(mPendingCheckForLongPress);
56 mPendingCheckForLongPress = null;
57 }
58 }
59
60 public boolean hasPerformedLongPress() {
61 return mHasPerformedLongPress;
62 }
63}