Android in the left half of the video screen to change the brightness of the right half of the slide up and down to change the sound _android

Source: Internet
Author: User
Tags abs gety

Description

Implementation features:

(1) The right part of the screen slide, the sound becomes big, down, the sound becomes small screen left half of the slide, brightness, decline, brightness becomes small

(2) If the brightness >1 or less than 0.2, the mobile phone vibration

Private float starty;//Record the y-coordinate of the finger pressed private float startx;//record the y-coordinate when the finger is pressed private int downvol;//record the volume of the finger pressed private vibrator V ibrator;//Mobile Phone vibrator//Don't forget the vibration permission <uses-permission android:name= "Android.permission.VIBRATE"/> * * Set screen Brightness LP = 0 All dark, lp=- 1, according to system setup, LP = 1; Lightest/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 ...
Turn off 10 seconds to vibrate 200 milliseconds, and switch vibrator.vibrate (pattern,-1) continuously; else if (Lp.screenbrightness < 0.2) {lp.screenbrightness = (float) 0.2; vibrator = (Vibrator) Getsystemservice (Vibra
Tor_service); Long[] Pattern = {10, 200};
Off/on/off/on. Vibrator.vibrate (Pattern,-1);
} GetWindow (). SetAttributes (LP); @Override public Boolean OntouchevenT (Motionevent event) {//Pass events to gesture recognizer (note: Only parse the event, no interception, parse into gesture recognition Click, double-click, Long Press) 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&GT;SCREENWIDTH/2) {//The right part of the screen is slippery, the sound becomes larger, the sound falls, the voice becomes smaller int touchrang=math.min (screenwidth,screenheight);//int Curvol
= (int) (downvol+ (distance/screenheight) *maxvolume); int curvol= (int) (downvol+ (Distancey/touchrang) *maxvolume)//Consideration of the problem int volume=math.min (MATH.MAX) with a screen switch
Maxvolume);
Updatevolume (volume);  }else{//Screen on the left half of the slide, brightness become large, slide, brightness to small 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;} if (Distancey < Fling_min_distance && Math.Abs (Distancey) > Fling_min_velocity) {setbrightness (-20);}}
Break
Case MotionEvent.ACTION_UP:handler.sendEmptyMessageDelayed (hide_control,5000);
Break
Return Super.ontouchevent (event); }

The above is a small set to introduce the Android video screen in the left half of the slide to change the brightness of the right half of the light up and down to change the sound, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.