Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2018 The Xiaomi-SDM660 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 org.lineageos.settings.device;
  18.  
  19. import android.content.ComponentName;
  20. import android.content.Context;
  21. import android.content.Intent;
  22. import android.content.pm.PackageManager;
  23. import android.view.KeyEvent;
  24.  
  25. import com.android.internal.os.DeviceKeyHandler;
  26.  
  27. public class KeyHandler implements DeviceKeyHandler {
  28.  
  29. private static final int SCANCODE_JASMINE_UP = 103;
  30. private static final int SCANCODE_JASMINE_DOWN = 108;
  31. private static final int SCANCODE_JASMINE_LEFT = 105;
  32. private static final int SCANCODE_JASMINE_RIGHT = 106;
  33.  
  34. private static final String FP_SWIPE_DIRECTION = "FP_SWIPE_DIRECTION";
  35. private static final int FP_SWIPE_UP = 0;
  36. private static final int FP_SWIPE_DOWN = 1;
  37. private static final int FP_SWIPE_LEFT = 2;
  38. private static final int FP_SWIPE_RIGHT = 3;
  39.  
  40. private static PackageManager sPackageManager;
  41. protected final Context mContext;
  42.  
  43. public KeyHandler(Context context) {
  44. sPackageManager = context.getPackageManager();
  45. mContext = context;
  46. }
  47.  
  48. @Override
  49. public boolean canhandleKeyEvent(KeyEvent event) {
  50. int scanCode = event.getScanCode();
  51. int action = event.getAction();
  52.  
  53. int swipeDirection = -1;
  54.  
  55. switch (scanCode) {
  56. case SCANCODE_JASMINE_UP:
  57. swipeDirection = FP_SWIPE_UP;
  58. break;
  59.  
  60. case SCANCODE_JASMINE_DOWN:
  61. swipeDirection = FP_SWIPE_DOWN;
  62. break;
  63.  
  64. case SCANCODE_JASMINE_LEFT:
  65. swipeDirection = FP_SWIPE_LEFT;
  66. break;
  67.  
  68. case SCANCODE_JASMINE_RIGHT:
  69. swipeDirection = FP_SWIPE_RIGHT;
  70. break;
  71.  
  72. default:
  73. swipeDirection = -1;
  74. break;
  75. }
  76.  
  77. if (swipeDirection >= 0) {
  78. if (action == KeyEvent.ACTION_UP) {
  79. Intent startAction = new Intent()
  80. .setComponent(new ComponentName("org.lineageos.settings.device",
  81. "org.lineageos.settings.device.StartAction"))
  82. .putExtra(FP_SWIPE_DIRECTION, swipeDirection);
  83.  
  84. if (startAction.resolveActivity(sPackageManager) != null) {
  85. mContext.startService(startAction);
  86. }
  87. }
  88. }
  89. return event;
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement