The left half of the video screen slides up and down to change the brightness, and the right half slides up and down to change the sound and brightness.

Source: Internet
Author: User
Tags gety

The left half of the video screen slides up and down to change the brightness, and the right half slides up and down to change the sound and brightness.

Note:
Functions:
(1) the right part of the screen slides up and down, and the sound slides up and down. The left part of the screen slides up and down, the brightness increases, and the brightness decreases.
(2) If the brightness is greater than 1 or less than 0.2, the phone shake


Private float startY; // records the Y coordinate when the finger is pressed.
Private float startX; // records the Y coordinate when the finger is pressed.
Private int downVol; // record the volume when the finger is pressed
Private Vibrator vibrator; // mobile phone Vibrator
// Do not forget the vibration permission <uses-permission android: name = "android. permission. VIBRATE"/>
/*
* Set the screen brightness lp = 0 to full darkness, lp =-1. According to the system settings, lp = 1; brightest
*/
Public void setBrightness (float brightness ){
WindowManager. LayoutParams lp = getWindow (). getAttributes ();
// If (lp. screenBrightness <= 0.1 ){
// Return;
//}
Lp. screenBrightness = lp. screenBrightness + brightness/255.0f;
If (lp. screenBrightness> 1 ){
Lp. screenBrightness = 1;
Vibrator = (Vibrator) getSystemService (VIBRATOR_SERVICE );
Long [] pattern = {10,200}; // OFF/ON/OFF/ON... Close 10 seconds Vibration for 200 milliseconds, keep switching
Vibrator. vibrate (pattern,-1 );
} Else if (lp. screenBrightness <0.2 ){
Lp. screenBrightness = (float) 0.2;
Vibrator = (Vibrator) getSystemService (VIBRATOR_SERVICE );
Long [] pattern = {10,200}; // OFF/ON/OFF/ON...
Vibrator. vibrate (pattern,-1 );
}
GetWindow (). setAttributes (lp );
}
@ Override
Public boolean onTouchEvent (MotionEvent event ){
// Send the event to the gesture recognition device (Note: Only the event is parsed and not intercepted. The event is parsed into the click, double-click, and long-press of Gesture Recognition)
Detector. onTouchEvent (event );

Switch (event. getAction ()){
Case MotionEvent. ACTION_DOWN:
StartY = event. getY ();
StartX = event. getX ();
DownVol = audioManager. getStreamVolume (AudioManager. STREAM_MUSIC );
Handler. removeMessages (HIDE_CONTROL );
Break;
Case MotionEvent. ACTION_MOVE:
Float endY = event. getY ();
Float distanceY = startY-endY;
If (startX> screenWidth/2 ){
// The right part of the screen slides up, the sound increases, the sound drops, and the sound decreases
Int touchRang = Math. min (screenWidth, screenHeight );
// Int curvol = (int) (downVol + (distance/screenHeight) * maxVolume );
Int curvol = (int) (downVol + (distanceY/touchRang) * maxVolume); // considering the problem of horizontal/vertical screen Switching
Int volume = Math. min (Math. max (0, curvol), maxVolume );
UpdateVolume (volume );
} Else {
// The left part of the screen slides up and down, causing greater brightness and lower brightness.
Final double FLING_MIN_DISTANCE = 0.5;
Final double FLING_MIN_VELOCITY = 0.5;
If (distanceY> FLING_MIN_DISTANCE & Math. abs (distanceY)> FLING_MIN_VELOCITY ){
SetBrightness (20 );
}
If (distanceY <FLING_MIN_DISTANCE
& Math. abs (distanceY)> FLING_MIN_VELOCITY ){
SetBrightness (-20 );
}
}

Break;
Case MotionEvent. ACTION_UP:
Handler. sendEmptyMessageDelayed (hidemo_control, 5000 );
Break;
}
Return super. onTouchEvent (event );
}

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.