android手勢動畫

來源:互聯網
上載者:User

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) {

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_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) {
// NOTE: add for QuickWindow case
Slog.d(TAG, "[justin]interceptKeyBeforeQueueing KEYCODE_VOLUME_UP(HALL OPEN)->QuickWindow hide or show big phone UI or small clock UI");
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));
/**lizhihong@szhyst.com 2015.3.17 begin */
isQuickWindowShow = false;
/**lizhihong@szhyst.com 2015.3.17 end */
}
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) {
android.util.Log.v("liuxinwen", "KEYCODE_F2");

// NOTE: add for QuickWindow case
Slog.d(TAG,
"[justin]interceptKeyBeforeQueueing KEYCODE_VOLUME_DOWN(HALL CLOSE)->QuickWindow show or small window");
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: {
Log.d("lizhihong","KEYCODE_F3-->" + down);
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);
}
/**lizhihong@szhyst.com 2015.3.23 begin */
if (SystemProperties.getBoolean("persist.sys.gesture.vibrate", false)) {
mVibrator.vibrate(200l);
}
/**lizhihong@szhyst.com 2015.3.23 end */
}

 

播放手勢動畫

在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;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.