• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.launcher3;
18 
19 import android.view.View;
20 
21 public class CheckLongPressHelper {
22     private View mView;
23     private boolean mHasPerformedLongPress;
24     private CheckForLongPress mPendingCheckForLongPress;
25 
26     class CheckForLongPress implements Runnable {
run()27         public void run() {
28             if ((mView.getParent() != null) && mView.hasWindowFocus()
29                     && !mHasPerformedLongPress) {
30                 if (mView.performLongClick()) {
31                     mView.setPressed(false);
32                     mHasPerformedLongPress = true;
33                 }
34             }
35         }
36     }
37 
CheckLongPressHelper(View v)38     public CheckLongPressHelper(View v) {
39         mView = v;
40     }
41 
postCheckForLongPress()42     public void postCheckForLongPress() {
43         mHasPerformedLongPress = false;
44 
45         if (mPendingCheckForLongPress == null) {
46             mPendingCheckForLongPress = new CheckForLongPress();
47         }
48         mView.postDelayed(mPendingCheckForLongPress,
49                 LauncherAppState.getInstance().getLongPressTimeout());
50     }
51 
cancelLongPress()52     public void cancelLongPress() {
53         mHasPerformedLongPress = false;
54         if (mPendingCheckForLongPress != null) {
55             mView.removeCallbacks(mPendingCheckForLongPress);
56             mPendingCheckForLongPress = null;
57         }
58     }
59 
hasPerformedLongPress()60     public boolean hasPerformedLongPress() {
61         return mHasPerformedLongPress;
62     }
63 }
64