Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android手勢動畫

android手勢動畫

編輯:關於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));
/**[email protected] 2015.3.17 begin */
isQuickWindowShow = false;
/**[email protected] 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);
}
/**[email protected] 2015.3.23 begin */
if (SystemProperties.getBoolean("persist.sys.gesture.vibrate", false)) {
mVibrator.vibrate(200l);
}
/**[email protected] 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;
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved