1 /*
2  * Copyright (C) 2017 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.testing;
18 
19 import android.os.SystemClock;
20 import android.view.KeyEvent;
21 
22 public class KeyEvents {
23 
KeyEvents()24     private KeyEvents() {}
25 
createTestEvent(int action, int keyCode, int meta)26     public static KeyEvent createTestEvent(int action, int keyCode, int meta) {
27         long time = SystemClock.uptimeMillis();
28         return new KeyEvent(
29                 time,
30                 time,
31                 action,
32                 keyCode,
33                 0,
34                 meta);
35     }
36 
createLeftCtrlKey(int action)37     public static KeyEvent createLeftCtrlKey(int action) {
38         int meta = (action == KeyEvent.ACTION_UP)
39                 ? 0
40                 : KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_META_ON;
41 
42         return createTestEvent(action, KeyEvent.KEYCODE_CTRL_LEFT, meta);
43     }
44 
createRightCtrlKey(int action)45     public static KeyEvent createRightCtrlKey(int action) {
46         int meta = (action == KeyEvent.ACTION_UP)
47                 ? 0
48                 : KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_RIGHT_ON | KeyEvent.META_META_ON;
49 
50         return createTestEvent(action, KeyEvent.KEYCODE_CTRL_RIGHT, meta);
51     }
52 }
53