How to use the video playback screen's sense of gravity to switch between the horizontal and vertical screens, and the video playback screen's gravity

Source: Internet
Author: User

How to use the video playback screen's sense of gravity to switch between the horizontal and vertical screens, and the video playback screen's gravity































Previously, I just introduced some code to implement the video playback flat and flip function! You can flip the screen as you wish to meet your needs. However, when you make an image, problems may occur! What is the problem? Wait for me .. Come on!

It's a sauce. When I play a video, I will click the screen switch button to switch between the screen and the vertical screen, of course, I also use the flip screen to automatically switch the horizontal and vertical screens of the screen through gravity. Then, the problem arises. click the button and sense of gravity ~~~ A conflict may occur! The conflict is like this: currently, I keep my mobile phone on a horizontal screen (portrait screen), and then I want to switch the screen direction by clicking the button. Then, you will see that I click to switch the screen does not work !!! The reason is that when the mobile phone is in the horizontal screen, the gravity command keeps the mobile phone in the horizontal screen, although you have a command to switch the screen direction by clicking the button. However, the gravity command has been executing and masks the button command. The button operation is useless.

/** OrientationSensorListener. in the 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 = 90-(int) Math. round (angle); // normalize to 0-359 range if (orientation >=360) {orientation-= 360;} if (orientation <0) {orientation + = 360 ;}} if (isClickFullScreenButton) {// landscape if (isLandscape & (orientation> 315 & orientation <= 360) | (orientation> = 0 & orientation <= 45) | (orientatio N> 135 & orientation <= 225) {isLandscape = false; isClickFullScreenButton = false; isSennor = true ;}// if (! IsLandscape & (orientation> 45 & orientation <= 135) | (orientation> 225 & orientation <= 315) {isLandscape = true; isClickFullScreenButton = false; isSennor = true ;}} if (! IsSennor) {// determine whether to transfer the interrupt message return;} if (rotateHandler! = Null) {rotateHandler. obtainMessage (888, orientation, 0 ). sendToTarget () ;}/ ** call this method when you click the screen switch button: interrupt Handler Information Transmission */public void setIsSennor () {isSennor = false ;} /** call this method when you click the screen switch button: confirm the screen direction */public void setIsLandscape (boolean bool) {isLandscape = bool ;} /** call this method when you click the screen switch button: Set whether the button has been clicked */public void setButtonFullScreenClicked () {isClickFullScreenButton = true ;}

So we can solve this problem (IDEA ):

When the sensor gravity is registered, the method of the sensor gravity will always listen and pass the information release command. In fact, it is like a message release command that passes information through the neural hub of the human body. Then, let's just take a bit of medicine to interrupt the transmission of information and do something here.

Step 1: When you click the switch button, publish the information to the sense of gravity. At this time, you need to interrupt the transmission of information.

Step 2: When you click the switch button, publish the information to the sense of gravity. I have already clicked the switch button on the screen.

Step 3: After you click the switch button, you need to tell gravity that the screen is in the horizontal or vertical status.

Then, let's look at the above Code. In the onSensorChanged method, according to the code reading direction. When the user clicks the button to switch the screen, but does not flip the screen, the program reads if (! IsSennor) will be interrupted! Gravity does not work and is controlled by the button command. When the user flipped over the screen, the program continued to read without being interrupted and the gravity was activated. When a boolean variable (isClickFullScreenButton) is encountered in the code, the code continues to read the variable in its method. Then we can see that the two statuses are landscape and landscape respectively. This is the screen status when the button is clicked, which is assumed to be landscape. (At this time, the user flipped the screen) at this time, the status value will be set, so that the sense of gravity (isSennor) is activated so that the program will keep the information transmitted, the screen switching function is activated.

So as to achieve this, suppose ~ Horizontal screen ~ Status: You can click the button to switch the portrait status of the screen and keep it. Until the user flipped the screen to the portrait screen, and thus activated the gravity state. In this way, the user can freely flip the screen through gravity to switch between the horizontal and vertical screens!

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.