android手势动画
在PhoneWindowManager.java中
interceptKeyBeforeQueueing方法中添加如下代碼
?switch (keyCode) {
??????? case KeyEvent.KEYCODE_C: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.c", false)) {
?? ??? ??? ??? ?playGestureAnimation('c'); //這個地方是播放手勢動畫
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ??? ?myHandler.sendEmptyMessageDelayed(MSG_OPEN_CAMERA, 1000);//這個地方是手勢動畫伴隨的動作,比如打開相機
?? ??? ??? ??? ?setSleep();//播放手勢動畫不在主線程中,所以要主線程睡眠下,等待啟動手勢動畫
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();//這個是解鎖
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;//這個地方是喚醒屏幕
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
case KeyEvent.KEYCODE_E: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.e", false)) {
?? ??? ??? ??? ?playGestureAnimation('e');
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ??? ?myHandler.sendEmptyMessageDelayed(MSG_OPEN_BROWSER, 1000);
?? ??? ??? ??? ?setSleep();
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_W: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.w", false)) {
?? ??? ??? ??? ?playGestureAnimation('w');
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ??? ?myHandler.sendEmptyMessageDelayed(MSG_OPEN_FILE, 1000);
?? ??? ??? ??? ?setSleep();
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_M: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.m",false)) {
?? ??? ??? ??? ?playGestureAnimation('m');
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ??? ?myHandler.sendEmptyMessageDelayed(MSG_OPEN_MUSIC, 1000);
?? ??? ??? ??? ?setSleep();
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_O: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.o",false)) {
?? ??? ??? ??? ?playGestureAnimation('o');
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ??? ?myHandler.sendEmptyMessageDelayed(MSG_OPEN_DIALER, 1000);
?? ??? ??? ??? ?setSleep();
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F9: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.down",false)) {
?? ??? ??? ??? ?KeyEvent e = new KeyEvent(KeyEvent.ACTION_DOWN,
?? ??? ??? ??? ??? ??? ?KeyEvent.KEYCODE_MEDIA_PAUSE);
?? ??? ??? ??? ?if (down && (result & ACTION_PASS_TO_USER) == 0) {
?? ??? ??? ??? ??? ?mBroadcastWakeLock.acquire();
?? ??? ??? ??? ??? ?Message msg = mHandler.obtainMessage(
?? ??? ??? ??? ??? ??? ??? ?MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
?? ??? ??? ??? ??? ??? ??? ?new KeyEvent(e));
?? ??? ??? ??? ??? ?msg.setAsynchronous(true);
?? ??? ??? ??? ??? ?msg.sendToTarget();
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F11: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.right",false)) {
?? ??? ??? ??? ?KeyEvent e = new KeyEvent(KeyEvent.ACTION_DOWN,
?? ??? ??? ??? ??? ??? ?KeyEvent.KEYCODE_MEDIA_NEXT);
?? ??? ??? ??? ?if (down && (result & ACTION_PASS_TO_USER) == 0) {
?? ??? ??? ??? ??? ?android.util.Log.v(TAG, "KEYCODE_F11");
?? ??? ??? ??? ??? ?mBroadcastWakeLock.acquire();
?? ??? ??? ??? ??? ?Message msg = mHandler.obtainMessage(
?? ??? ??? ??? ??? ??? ??? ?MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
?? ??? ??? ??? ??? ??? ??? ?new KeyEvent(e));
?? ??? ??? ??? ??? ?msg.setAsynchronous(true);
?? ??? ??? ??? ??? ?msg.sendToTarget();
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F12: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.left",false)) {
?? ??? ??? ??? ?KeyEvent e = new KeyEvent(KeyEvent.ACTION_DOWN,
?? ??? ??? ??? ??? ??? ?KeyEvent.KEYCODE_MEDIA_PREVIOUS);
?? ??? ??? ??? ?if (down && (result & ACTION_PASS_TO_USER) == 0) {
?? ??? ??? ??? ??? ?android.util.Log.v(TAG, "KEYCODE_F11");
?? ??? ??? ??? ??? ?mBroadcastWakeLock.acquire();
?? ??? ??? ??? ??? ?Message msg = mHandler.obtainMessage(
?? ??? ??? ??? ??? ??? ??? ?MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
?? ??? ??? ??? ??? ??? ??? ?new KeyEvent(e));
?? ??? ??? ??? ??? ?msg.setAsynchronous(true);
?? ??? ??? ??? ??? ?msg.sendToTarget();
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F10: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.up",false)) {
?? ??? ??? ??? ?playGestureAnimation('u');
?? ??? ??? ??? ?setSleep();
?? ??? ??? ??? ?dismissKeyguardOnNextActivity();
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ??? ?//wakeScreenHandler.sendEmptyMessageDelayed(MSG_WAKE_SCREEN, 220);
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F1: {
?????? ??? ?if (down) {
??????????????? if (isQuickWindowShow) {
??????????????? mContext.stopService(new Intent("com.sprd.quickwindow.QuickWindowService.action"));
??????????????? ContentValues values = new ContentValues();
??????????????? values.put("hallvalue", -1);
??????????????? final Uri uri = Uri.parse("content://com.sprd.quickwindow.provider");
??????????????? mContext.getContentResolver().update(uri, values, "id=1", null);
??????????????? mContext.sendBroadcast(new Intent(ACTION_QUICKWINDOW_HIDE));
??????????????? isQuickWindowShow = false;
?????? ??? ??? ?}
?????? ??? ??? ?screenOffHandler.removeMessages(MSG_GO_TO_SLEEP);
?????? ??? ??? ?result |= ACTION_WAKE_UP;
?????? ??? ?}
?????? ??? ??? ?break;
?????? ??? ?}
?? ??? ?case KeyEvent.KEYCODE_F2: {
?? ??? ??? ?android.util.Log.v("liuxinwen", "isScreenOn = " + isScreenOn);
?? ??? ??? ?if (down && isScreenOn) {
?? ??? ??? ??? ?ContentValues values = new ContentValues();
?? ??? ??? ??? ?values.put("hallvalue", 1);
?? ??? ??? ??? ?final Uri uri = Uri
?? ??? ??? ??? ??? ??? ?.parse("content://com.sprd.quickwindow.provider");
?? ??? ??? ??? ?mContext.getContentResolver().update(uri, values, "id=1", null);
?? ??? ??? ??? ?ITelephony telephonyService = getTelephonyService();
?? ??? ??? ??? ?if (telephonyService != null) {
?? ??? ??? ??? ??? ?Slog.d(TAG, "[justin]telephonyService is not null");
?? ??? ??? ??? ??? ?try {
?? ??? ??? ??? ??? ??? ?Slog.d(TAG, "quickwindow case. isRinging:"
?? ??? ??? ??? ??? ??? ??? ??? ?+ telephonyService.isRinging() + " isOffhook:"
?? ??? ??? ??? ??? ??? ??? ??? ?+ telephonyService.isOffhook());
?? ??? ??? ??? ??? ??? ?if (!telephonyService.isRinging()
?? ??? ??? ??? ??? ??? ??? ??? ?&& !telephonyService.isOffhook()
?? ??? ??? ??? ??? ??? ??? ??? ?&& mAlarmState != ALARM_ALERT) {// no ring and
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?// no clock
?? ??? ??? ??? ??? ??? ??? ?Slog.d(TAG,
?? ??? ??? ??? ??? ??? ??? ??? ??? ?"[justin]not ringing and not clock, need show quickwindow.");
?? ??? ??? ??? ??? ??? ??? ?mContext.startService(new Intent(
?? ??? ??? ??? ??? ??? ??? ??? ??? ?"com.sprd.quickwindow.QuickWindowService.action"));
?? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ?Slog.d(TAG,
?? ??? ??? ??? ??? ??? ??? ??? ?"[justin]ringing or clock, show small phone UI or small clock UI.");
?? ??? ??? ??? ??? ??? ?mContext.sendBroadcast(new Intent(
?? ??? ??? ??? ??? ??? ??? ??? ?ACTION_QUICKWINDOW_SHOW));
?? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ?isQuickWindowShow = true;
?? ??? ??? ??? ??? ?} catch (RemoteException ex) {
?? ??? ??? ??? ??? ??? ?Slog.w(TAG, "ITelephony threw RemoteException", ex);
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ??? ?if (down && isScreenOn) {
?? ??? ??? ??? ?screenOffHandler.sendEmptyMessageDelayed(MSG_GO_TO_SLEEP, 5000);
?? ??? ??? ?}
?????? ??? ??? ?break;
?????? ??? ?}
?? ??? ?
?? ??? ?case KeyEvent.KEYCODE_F3: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.air.distance", false)) {
?? ??? ??? ??? ?mContext.sendBroadcast(new Intent(ACTION_NO_TOUCH_TURN_PAGE));
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?
?? ??? ?case KeyEvent.KEYCODE_U: {
?? ??? ??? ?if (down && SystemProperties.getBoolean("persist.sys.gesture.enable", false)
?? ??? ??? ??? ??? ?&& SystemProperties.getBoolean("persist.sys.gesture.double", false)) {
?? ??? ??? ??? ?android.util.Log.v(TAG, "persist.sys.gesture.doubleclicke");
?? ??? ??? ??? ?result |= ACTION_WAKE_UP;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
}
//播放手勢動畫
?private void playGestureAnimation(char keyCode) {
?? ??? ?String[] cmd = {"bootanimation",keyCode + "x"};
?? ??? ?try {
?? ??? ??? ?Runtime.getRuntime().exec(cmd);
?? ??? ?} catch (Exception e) {
?? ??? ??? ?Log.e(TAG, " command exe err!");
?? ??? ?}
?? ?}
?Handler myHandler = new Handler() {
?? ??? ?public void handleMessage(Message msg) {
?? ??? ??? ?Intent intent = new Intent();
?? ??? ??? ?switch (msg.what) {
?? ??? ??? ?case MSG_OPEN_CAMERA:
?? ??? ??? ??? ?intent.setAction("android.intent.action.VIEW");
?? ??? ??? ??? ?intent.setClassName("com.android.camera2",
?? ??? ??? ??? ??? ??? ?"com.android.camera.CameraLauncher");
?? ??? ??? ??? ?intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
??????????????????????? | Intent.FLAG_ACTIVITY_SINGLE_TOP
??????????????????????? | Intent.FLAG_ACTIVITY_CLEAR_TOP);
?? ??? ??? ??? ?mContext.startActivityAsUser(intent, UserHandle.CURRENT);
?? ??? ??? ??? ?break;
?? ??? ??? ?case MSG_OPEN_BROWSER:
?? ??? ??? ??? ?intent.setAction("android.intent.action.VIEW");
?? ??? ??? ??? ?intent.setClassName("com.android.browser",
?? ??? ??? ??? ??? ??? ?"com.android.browser.BrowserActivity");
?? ??? ??? ??? ?intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
??????????????????????? | Intent.FLAG_ACTIVITY_SINGLE_TOP
??????????????????????? | Intent.FLAG_ACTIVITY_CLEAR_TOP);
?? ??? ??? ??? ?mContext.startActivityAsUser(intent, UserHandle.CURRENT);
?? ??? ??? ??? ?break;
?? ??? ??? ?case MSG_OPEN_FILE:
?? ??? ??? ??? ?intent.setClassName("com.sprd.fileexplorer",
?? ??? ??? ??? ??? ??? ?"com.sprd.fileexplorer.activities.FileExploreActivity");
?? ??? ??? ??? ?intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
??????????????????????? | Intent.FLAG_ACTIVITY_SINGLE_TOP
??????????????????????? | Intent.FLAG_ACTIVITY_CLEAR_TOP);
?? ??? ??? ??? ?mContext.startActivityAsUser(intent, UserHandle.CURRENT);
?? ??? ??? ??? ?break;
?? ??? ??? ?case MSG_OPEN_MUSIC:
?? ??? ??? ??? ?intent.setClassName("com.android.music",
?? ??? ??? ??? ??? ??? ?"com.android.music.MusicBrowserActivity");
?? ??? ??? ??? ?intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
??????????????????????? | Intent.FLAG_ACTIVITY_SINGLE_TOP
??????????????????????? | Intent.FLAG_ACTIVITY_CLEAR_TOP);
?? ??? ??? ??? ?mContext.startActivityAsUser(intent, UserHandle.CURRENT);
?? ??? ??? ??? ?break;
?? ??? ??? ?case MSG_OPEN_DIALER:
?? ??? ??? ??? ?intent.setClassName("com.android.dialer",
?? ??? ??? ??? ??? ??? ?"com.android.dialer.DialtactsActivity");
?? ??? ??? ??? ?intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
??????????????????????? | Intent.FLAG_ACTIVITY_SINGLE_TOP
??????????????????????? | Intent.FLAG_ACTIVITY_CLEAR_TOP);
?? ??? ??? ??? ?mContext.startActivityAsUser(intent, UserHandle.CURRENT);
?? ??? ??? ??? ?break;
?? ??? ??? ?default:
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?super.handleMessage(msg);
?? ??? ?}
?? ?}; ?
???
private void setSleep() {
?? ??? ?try {
?? ??? ??? ?Thread.sleep(170);
?? ??? ?} catch (InterruptedException e) {
?? ??? ??? ?// TODO Auto-generated catch block
?? ??? ??? ?e.printStackTrace();
?? ??? ?}
?? ?}
//喚醒屏幕,解鎖
??? private void dismissKeyguardOnNextActivity() {
?? ??? ?PowerManager pm=(PowerManager) mContext.getSystemService(Context.POWER_SERVICE);? ?
??????? PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright"); ?
??????? wl.acquire(); ?
??????? wl.release();
?????? ?
?? ??? ?if (mLockPatternUtils.getActivePasswordQuality() == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
?? ??? ??? ?mKeyguardDelegate.keyguardDone(false,true);
?? ??? ?}
?? ??? ?if (SystemProperties.getBoolean("persist.sys.gesture.vibrate", false)) {
?? ??? ??? ?mVibrator.vibrate(200l);
?? ??? ?}
??? }
播放手勢動畫
在frameworks/base/cmds/bootanimation下bootanimation_main.cpp中
switch(argv[1][0]) {
?? ?case 'c':
?? ??? ?bootanimation_path = "/system/media/gesture_c_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'e':
?? ??? ?bootanimation_path = "/system/media/gesture_e_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'o':
?? ??? ?bootanimation_path = "/system/media/gesture_o_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'w':
?? ??? ?bootanimation_path = "/system/media/gesture_w_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'm':
?? ??? ?bootanimation_path = "/system/media/gesture_m_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'l':
?? ??? ?bootanimation_path = "/system/media/gesture_left_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'r':
?? ??? ?bootanimation_path = "/system/media/gesture_right_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'u':
?? ??? ?bootanimation_path = "/system/media/gesture_up_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?case 'd':
?? ??? ?bootanimation_path = "/system/media/gesture_down_animation.zip";
??????? bootanimation_sound_path = "";
?? ??? ?break;
?? ?default:
?? ??? ?break;
?? ?}
總結
以上是生活随笔為你收集整理的android手势动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android源码设计模式探索与实战【建
- 下一篇: 巨头集体跨界,老玩家悄然出圈,谁在争夺6