• 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.launcher2;
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, LauncherApplication.getLongPressTimeout());
49     }
50 
cancelLongPress()51     public void cancelLongPress() {
52         mHasPerformedLongPress = false;
53         if (mPendingCheckForLongPress != null) {
54             mView.removeCallbacks(mPendingCheckForLongPress);
55             mPendingCheckForLongPress = null;
56         }
57     }
58 
hasPerformedLongPress()59     public boolean hasPerformedLongPress() {
60         return mHasPerformedLongPress;
61     }
62 }
63