How to use the sense gravity of the video playback screen to switch the screen vertically

Source: Internet
Author: User































Before, just introduced some code to achieve the video playback of the calming flip this feature! You can flip the screen as you want, to meet the needs of the user. However, when you really do a look like, there will be problems arise! So what's the problem? Wait for me. Come on!

is the sauce, I use the video playback when there will be a click on the screen to switch the screen to switch playback, of course, I also have to use the flip screen through the sense of gravity from the screen to toggle the display. Then, the problem arises, click the button and the sense of gravity ~ ~ ~ There will be a conflict! And the conflict is this: I'm currently in the horizontal screen (vertical screen), and then I want to click on the button to switch the direction of the screen. Well, you will encounter me clicking the button to toggle the screen does not work!!! The reason is that when the phone is in the horizontal screen, the sense of gravity command at this time to keep the phone in the horizontal screen, although you have to click the button to switch the screen direction of the command. However, the sense-of-gravity command has been executing and masking the button's commands. The operation of the button is of little use.

/** Orientationsensorlistener.java class */public void Onsensorchanged (Sensorevent event) {float[] values = event.values;        int orientation = Orientation_unknown;        float X =-values[_data_x];        float Y =-values[_data_y];                float Z =-values[_data_z];        float magnitude = x * x + y * y;            Don ' t trust the angle if the magnitude is small compared to the Y value if (magnitude * 4 >= Z * z) {            float Oneeightyoverpi = 57.29577957855f;            float angle = (float) math.atan2 (-y, X) * ONEEIGHTYOVERPI;            Orientation =-(int) math.round (angle);            Normalize to 0-359 range if (orientation >=) {orientation-= 360;            } if (Orientation < 0) {orientation + = 360;  }} if (Isclickfullscreenbutton) {//Vertical screen if (Islandscape && ((orientation > 315 && Orientation <= 360) | | (Orientation >= 0 && Orientation <= 45)) || (Orientation > 135 && Orientation <= 225))        ) {Islandscape = false;        Isclickfullscreenbutton = false;        Issennor = true; }//cross-screen if (!islandscape && (Orientation > Orientation && <= 135) | | (Orientation > 225 && Orientation <= 315)))        {Islandscape = true;        Isclickfullscreenbutton = false;        Issennor = true;                }} if (!issennor) {//To determine if an interrupt message is to be passed to return;} if (rotatehandler!=null) {rotatehandler.obtainmessage (888, orientation, 0). Sendtotarget ();}} /** call this method when you click on the screen toggle button: Interrupt handler message transfer */public void Setissennor () {Issennor = false;} /** call this method when you click on the Screen toggle button: Confirm the orientation of the screen at this time */public void Setislandscape (boolean bool) {islandscape = bool;} /** call this method when you click on the screen toggle button: Set whether the button has been clicked */public void setbuttonfullscreenclicked () {Isclickfullscreenbutton = tRue;} 

So, we're going to solve this problem (thinking):

The sense of gravity when it is registered, the method of gravity will always listen and pass the message release command. In fact, it is like the human nerve passing information through the nerve center to pass information as the release command. Well, we'll just have to stop the transmission of the information and do something about it here.

The first step: When you click the toggle button, post information to the sense of gravity said, at this time you want to interrupt the transmission of information.

The second step: When you click on the toggle button, post information to the sense of gravity said, I have clicked on the screen toggle button.

The third step: When you click the toggle button, after the first step, but also to tell the sense of gravity said that the screen is in the state: Horizontal screen or vertical screen status.

Then, it looks from the code above. According to the reading direction of the code, in the Onsensorchanged method. When the user taps the button to switch the screen without flipping the screen, the program reads if (!issennor) is interrupted! The sense of gravity does not work and is completely controlled by the button's command to flip the screen. And when the user flips over the screen, the program continues to read without interruption and realizes that the sense of gravity is activated. The code continues to its methods when it encounters a Boolean variable (Isclickfullscreenbutton). Then you will see two judgments are horizontal screen and vertical screen status, this is the button is clicked when the screen state, assuming that the horizontal screen. (The user flips the screen at this time) the state value is set, so the sense of gravity (Issennor) is activated so that the program keeps the message passing, that is, activating the sense gravity toggle screen function.

Thus realized, assume ~ Horizontal screen ~ state: The user can toggle the screen's vertical screen state by clicking the button, and keep going. Until the user flips the screen to the vertical screen and thus activates the sense gravity state. The user is also able to toggle the screen by feeling gravity to switch the display!

How to use the sense gravity of the video playback screen to switch the screen vertically

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.