• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.documentsui.base;
18 
19 import android.view.KeyEvent;
20 import android.view.MotionEvent;
21 
22 /**
23  * Utility code for dealing with MotionEvents.
24  */
25 public final class Events {
26 
isMouseEvent(MotionEvent e)27     public static boolean isMouseEvent(MotionEvent e) {
28         return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE;
29     }
30 
isActionDown(MotionEvent e)31     public static boolean isActionDown(MotionEvent e) {
32         return e.getActionMasked() == MotionEvent.ACTION_DOWN;
33     }
34 
isActionUp(MotionEvent e)35     public static boolean isActionUp(MotionEvent e) {
36         return e.getActionMasked() == MotionEvent.ACTION_UP;
37     }
38 
isMultiPointerActionDown(MotionEvent e)39     public static boolean isMultiPointerActionDown(MotionEvent e) {
40         return e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
41     }
42 
isMultiPointerActionUp(MotionEvent e)43     public static boolean isMultiPointerActionUp(MotionEvent e) {
44         return e.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
45     }
46 
isCtrlKeyPressed(MotionEvent e)47     public static boolean isCtrlKeyPressed(MotionEvent e) {
48         return hasBit(e.getMetaState(), KeyEvent.META_CTRL_ON);
49     }
50 
isAltKeyPressed(MotionEvent e)51     public static boolean isAltKeyPressed(MotionEvent e) {
52         return hasBit(e.getMetaState(), KeyEvent.META_ALT_ON);
53     }
54 
isShiftKeyPressed(MotionEvent e)55     public static boolean isShiftKeyPressed(MotionEvent e) {
56         return hasBit(e.getMetaState(), KeyEvent.META_SHIFT_ON);
57     }
58 
hasBit(int metaState, int bit)59     private static boolean hasBit(int metaState, int bit) {
60         return (metaState & bit) != 0;
61     }
62 
63     /**
64      * @return true if keyCode is a known navigation code (e.g. up, down, home).
65      */
isNavigationKeyCode(int keyCode)66     public static boolean isNavigationKeyCode(int keyCode) {
67         switch (keyCode) {
68             case KeyEvent.KEYCODE_DPAD_UP:
69             case KeyEvent.KEYCODE_DPAD_DOWN:
70             case KeyEvent.KEYCODE_DPAD_LEFT:
71             case KeyEvent.KEYCODE_DPAD_RIGHT:
72             case KeyEvent.KEYCODE_MOVE_HOME:
73             case KeyEvent.KEYCODE_MOVE_END:
74             case KeyEvent.KEYCODE_PAGE_UP:
75             case KeyEvent.KEYCODE_PAGE_DOWN:
76                 return true;
77             default:
78                 return false;
79         }
80     }
81 }
82