Android gesture Animation

Source: Internet
Author: User

Android gesture Animation

In PhoneWindowManager. java

Add the following code to the interceptKeyBeforeQueueing method:

Switch (keyCode ){

Case KeyEvent. KEYCODE_C :{
If (down & SystemProperties. getBoolean ("persist. sys. gesture. enable", false)
& SystemProperties. getBoolean ("persist. sys. gesture. c", false )){
PlayGestureAnimation ('C'); // This is where the gesture animation is played.
// WakeScreenHandler. sendEmptyMessageDelayed (MSG_WAKE_SCREEN, 220 );
MyHandler. sendEmptyMessageDelayed (MSG_OPEN_CAMERA, 1000); // This part is accompanied by a gesture animation, such as opening a camera.
SetSleep (); // The playback gesture animation is not in the main thread, so you need to sleep in the main thread and wait for the start of the gesture animation.
DismissKeyguardOnNextActivity (); // unlock
Result | = ACTION_WAKE_UP; // wake up the screen.
}
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 ));
/** Beg5.3.17 begin lizhihong@szhyst.com */
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;
}

}

 

// Play gesture Animation

Private void playGestureAnimation (char keyCode ){
String [] cmd = {"bootanimation", keyCode + "x "};
Try {
Runtime.getruntime(cmd.exe c (cmd );
} Catch (Exception e ){
Log. e (TAG, "command exe err! ");
}
}

 

// This action is accompanied by a gesture Animation

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. fileemedieactivity ");
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 ();
}
}

// Wake up the screen and unlock

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 );
}
/** Beg5.3.23 begin lizhihong@szhyst.com */
If (SystemProperties. getBoolean ("persist. sys. gesture. vibrate", false )){
MVibrator. vibrate (200l );
}
/** Lizhihong@szhyst.com 2015.3.23 end */
}

 

Play gesture Animation

In bootanimation_main.cpp under frameworks/base/cmds/bootanimation

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.