Android Phone rotation direction recognition

Source: Internet
Author: User

Private Orientationeventlistener Morientationlistener;    Private String TAG = "mainactivity"; private int screencurorient = 2; 1 indicates a vertical screen, 2 indicates a positive horizontal screen, 3 is a reverse vertical screen, 4 indicates a reverse horizontal private final void Startorientationchangelistener () {morientationlistener = new O                Rientationeventlistener (This) {@Override public void onorientationchanged (int rotation) {                Determine four directions if (rotation = =-1) {LOG.D (TAG, "mobile phone flat put:" + rotation);                } else if (Rotation < | | rotation >) {screenorientchange (1);                } else if (rotation < && rotation >) {screenorientchange (4);                } else if (rotation < && rotation >) {screenorientchange (3);                } else if (Rotation < 280 && Rotation > 260) {screenorientchange (2);       } else {         }            }        };    Morientationlistener.enable (); } private void Screenorientchange (int Orient) {if (Orient! = screencurorient) {Screencuror            ient = Orient;                    Switch (screencurorient) {case 1:LOG.D (TAG, "upright screen:");                    Setrequestedorientation (activityinfo.screen_orientation_portrait);                Break                    Case 2:LOG.D (TAG, "positive horizontal screen:");                    Setrequestedorientation (Activityinfo.screen_orientation_landscape);                Break                    Case 3:LOG.D (TAG, "anti-vertical screen:");                    Setrequestedorientation (activityinfo.screen_orientation_portrait);                Break                    Case 4:LOG.D (TAG, "Reverse horizontal screen:");                    Setrequestedorientation (Activityinfo.screen_orientation_landscape);            Break }        }    }

InonCreatemethod, you can call the Startorientationchangelistener method.

Android Phone rotation direction recognition

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.