SHARE
TWEET

Untitled

a guest Apr 26th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 int SCANCODE_CLOVER_DOWN = 172;
  35.  
  36.     private static final String FP_SWIPE_DIRECTION = "FP_SWIPE_DIRECTION";
  37.     private static final int FP_SWIPE_UP = 0;
  38.     private static final int FP_SWIPE_DOWN = 1;
  39.     private static final int FP_SWIPE_LEFT = 2;
  40.     private static final int FP_SWIPE_RIGHT = 3;
  41.  
  42.     private static PackageManager sPackageManager;
  43.     private final Context mContext;
  44.  
  45.     public KeyHandler(Context context) {
  46.         sPackageManager = context.getPackageManager();
  47.         mContext = context;
  48.     }
  49.  
  50.     @Override
  51.     public boolean handleKeyEvent(KeyEvent event) {
  52.         int scanCode = event.getScanCode();
  53.         int action = event.getAction();
  54.  
  55.         int swipeDirection = -1;
  56.  
  57.         switch (scanCode) {
  58.             case SCANCODE_JASMINE_UP:
  59.                 swipeDirection = FP_SWIPE_UP;
  60.                 break;
  61.  
  62.             case SCANCODE_CLOVER_DOWN:
  63.             case SCANCODE_JASMINE_DOWN:
  64.                 swipeDirection = FP_SWIPE_DOWN;
  65.                 break;
  66.  
  67.             case SCANCODE_JASMINE_LEFT:
  68.                 swipeDirection = FP_SWIPE_LEFT;
  69.                 break;
  70.  
  71.             case SCANCODE_JASMINE_RIGHT:
  72.                 swipeDirection = FP_SWIPE_RIGHT;
  73.                 break;
  74.  
  75.             default:
  76.                 swipeDirection = -1;
  77.                 break;
  78.         }
  79.  
  80.         if (swipeDirection >= 0) {
  81.             if (action == KeyEvent.ACTION_UP) {
  82.                 Intent startAction = new Intent()
  83.                         .setComponent(new ComponentName("org.lineageos.settings.device",
  84.                                 "org.lineageos.settings.device.StartAction"))
  85.                         .putExtra(FP_SWIPE_DIRECTION, swipeDirection);
  86.  
  87.                 if (startAction.resolveActivity(sPackageManager) != null) {
  88.                     mContext.startService(startAction);
  89.                 }
  90.             }
  91.         }
  92.         return false;
  93.     }
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top