Rotate the screen with buttons in Android

Source: Internet
Author: User

Http://blog.csdn.net/linweig/article/details/6205142

The Home key on Android is directly processed by the system and has the following functions:

1: Go to the home page. If the home process is dead, restart the home process.
2: press for 5 seconds. The application selection window is displayed. You can switch the application.
As needed, I need to modify some of the logic here. The modified logic cannot be released, and the approximate location I found is released here.
View plaincopy to clipboardprint?
Public Boolean interceptkeyti (windowstate win, int code, int metakeys, Boolean down,
Int repeatcount, int flags ){
Boolean keyguardon = keyguardon ();
If (false ){
Log. D (TAG, "interceptkeyti code =" + code + "down =" + down + "repeatcount ="
+ Repeatcount + "keyguardon =" + keyguardon + "mhomepressed =" + mhomepressed );
}
// Clear a pending home longpress if the user releases home
// Todo: This cocould probably be inside the next bit of logic, but that code
// Turned out to be a bit fragile so I'm doing it here explicitly, for now.
If (code = keyevent. keycode_home )&&! Down ){
Mhandler. removecallbacks (mhomelongpress );
}
// If the Home button is currently being held, then we do special
// Chording with it.
If (mhomepressed ){

// If we have released the Home key, and didn't do anything else
// While it was pressed, then it is time to go home!
If (code = keyevent. keycode_home ){
If (! Down ){
Mhomepressed = false;

If (flags & keyevent. flag_canceled) = 0 ){
// If an incoming call is ringing, home is totally disabled.
// (The user is already on the incallscreen at this point,
// And his only options are to answer or reject the call .)
Boolean incomingringing = false;
Try {
Itelephony phoneserv = getphoneinterface ();
If (phoneserv! = NULL ){
Incomingringing = phoneserv. isringing ();
} Else {
Log. W (TAG, "unable to find itelephony interface ");
}
} Catch (RemoteException ex ){
Log. W (TAG, "RemoteException from getphoneinterface ()", ex );
}

If (incomingringing ){
Log. I (TAG, "ignoring home; there's a ringing incoming call .");
} Else {
Launchhomefromhotkey ();
}
} Else {
Log. I (TAG, "ignoring home; event canceled .");
}
}
}

Return true;
}

// First we always handle the Home key here, So applications
// Can never break it, although if keyguard is on, we do let
// It handle it, because that gives us the correct 5 second
// Timeout.
If (code = keyevent. keycode_home ){
// If a system window has focus, then it doesn't make sense
// Right now to interact with applications.
Windowmanager. layoutparams attrs = win! = NULL? Win. getattrs (): NULL;
If (attrs! = NULL ){
Final int type = attrs. type;
If (type = windowmanager. layoutparams. type_keyguard
| Type = windowmanager. layoutparams. type_keyguard_dialog ){
// The "app" is keyguard, so give it the key
Return false;
}
Final int typecount = window_types_where_home_doesnt_work.length;
For (INT I = 0; I <typecount; I ++ ){
If (type = window_types_where_home_doesnt_work [I]) {
// Don't do anything, but also don't pass it to the app
Return true;
}
}
}

If (down & repeatcount = 0 ){
If (! Keyguardon ){
Mhandler. postdelayed (mhomelongpress, viewconfiguration. getglobalactionkeytimeout ());
}
Mhomepressed = true;
}
Return true;
}
Public Boolean interceptkeyti (windowstate win, int code, int metakeys, Boolean down,
Int repeatcount, int flags ){
Boolean keyguardon = keyguardon ();
If (false ){
Log. D (TAG, "interceptkeyti code =" + code + "down =" + down + "repeatcount ="
+ Repeatcount + "keyguardon =" + keyguardon + "mhomepressed =" + mhomepressed );
}
// Clear a pending home longpress if the user releases home
// Todo: This cocould probably be inside the next bit of logic, but that code
// Turned out to be a bit fragile so I'm doing it here explicitly, for now.
If (code = keyevent. keycode_home )&&! Down ){
Mhandler. removecallbacks (mhomelongpress );
}
// If the Home button is currently being held, then we do special
// Chording with it.
If (mhomepressed ){

// If we have released the Home key, and didn't do anything else
// While it was pressed, then it is time to go home!
If (code = keyevent. keycode_home ){
If (! Down ){
Mhomepressed = false;

If (flags & keyevent. flag_canceled) = 0 ){
// If an incoming call is ringing, home is totally disabled.
// (The user is already on the incallscreen at this point,
// And his only options are to answer or reject the call .)
Boolean incomingringing = false;
Try {
Itelephony phoneserv = getphoneinterface ();
If (phoneserv! = NULL ){
Incomingringing = phoneserv. isringing ();
} Else {
Log. W (TAG, "unable to find itelephony interface ");
}
} Catch (RemoteException ex ){
Log. W (TAG, "RemoteException from getphoneinterface ()", ex );
}

If (incomingringing ){
Log. I (TAG, "ignoring home; there's a ringing incoming call .");
} Else {
Launchhomefromhotkey ();
}
} Else {
Log. I (TAG, "ignoring home; event canceled .");
}
}
}

Return true;
}

// First we always handle the Home key here, So applications
// Can never break it, although if keyguard is on, we do let
// It handle it, because that gives us the correct 5 second
// Timeout.
If (code = keyevent. keycode_home ){
// If a system window has focus, then it doesn't make sense
// Right now to interact with applications.
Windowmanager. layoutparams attrs = win! = NULL? Win. getattrs (): NULL;
If (attrs! = NULL ){
Final int type = attrs. type;
If (type = windowmanager. layoutparams. type_keyguard
| Type = windowmanager. layoutparams. type_keyguard_dialog ){
// The "app" is keyguard, so give it the key
Return false;
}
Final int typecount = window_types_where_home_doesnt_work.length;
For (INT I = 0; I <typecount; I ++ ){
If (type = window_types_where_home_doesnt_work [I]) {
// Don't do anything, but also don't pass it to the app
Return true;
}
}
}

If (down & repeatcount = 0 ){
If (! Keyguardon ){
Mhandler. postdelayed (mhomelongpress, viewconfiguration. getglobalactionkeytimeout ());
}
Mhomepressed = true;
}
Return true;
}
Some code is posted in frameworks/policies/base/phone/COM/Android/Internal/policy/impl/phonewindowmanager. java includes special buttons, including special buttons in Android, search, and other special keys.
The Home key logic is roughly analyzed as follows:
1: If you press the Home key, a timer is started, specifically the mhomelongpress object in it. If it exceeds 5 s, a window for app switching is displayed.
2: When you release the Home key, it is regarded as the standalone time. Now, some floating modal windows in the system are closed. The specific code is:
Sendclosesystemwindows (system_dialog_reason_home_key );
3: After closing the modal window, start or switch the home application. Code:
Startdockorhome
The code I have added cannot be released here. If you have such a requirement, You can manually add it here.

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.