Android video player The left edge of the screen with your finger swipe up and down brightness adjust dimming principle implementation (2): Subsequent improvements

Source: Internet
Author: User
Tags gety rewind

??

Android video player The left edge of the screen with your finger swipe up and down brightness adjust dimming principle implementation (2): Subsequent improvements

Appendix 1 Although it is possible to adjust the brightness of the left half of the screen with the swipe/slide of the finger, there is an imperfect place: when the finger is left and right in the left side of the screen, the same is true for the dimming of the invention. This is not perfect, assuming that the current view is a video player view, if the user's fingers are left sliding/right in the horizontal direction, it is clear that the intent is fast forward/rewind rather than adjusting the shading, so you need to improve the code in appendix article 1 to implement the correct logic.
Areas needing improvement focus on dispatchtouchevent, improved thinking: If the user's fingers move horizontally (x-axis) in the left half of the direction and the vertical (y-axis) direction of the displacement, only when the vertical (y-axis) displacement is greater than the horizontal (x-axis) direction, To think that this is an effective dimming operation, otherwise the decision is the horizontal direction of the normal displacement, and then do not consume this event, continue to pass the event down.
Improved appendix article 1 upper Java code:

Package Zhangphil.app;import Android.app.activity;import Android.os.bundle;import android.view.LayoutInflater; Import Android.view.motionevent;import Android.view.view;import Android.view.windowmanager;import Android.widget.textview;public class Mainactivity extends Activity {private float starty = 0;//finger pressed y coordinate private fl    Oat StartX = 0;//The y coordinate when the finger is pressed private TextView brightnesstextview;    Private View Mvideoview;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Mvideoview = Layoutinflater.from (this). Inflate (r.layout.activity_main, NULL);        Setcontentview (Mvideoview);    Brightnesstextview = (TextView) Mvideoview.findviewbyid (R.id.text); */* * Set screen brightness * 0 Darkest * 1 Brightest * * public void setbrightness (float brightness) {windowmanager.layout        Params LP = GetWindow (). GetAttributes ();        lp.screenbrightness = lp.screenbrightness + brightness/255.0f; if (lp.screenbrightness > 1) {lp.screenbrightness = 1;        } else if (Lp.screenbrightness < 0.1) {lp.screenbrightness = (float) 0.1;        } GetWindow (). SetAttributes (LP);        float sb = lp.screenbrightness;    Brightnesstextview.settext ((int) Math.ceil (SB * 100) + "%");        } @Override public boolean ontouchevent (Motionevent event) {int screenwidth = Mvideoview.getwidth ();                Switch (event.getaction ()) {Case MotionEvent.ACTION_DOWN:startX = Event.getx ();                Starty = Event.gety ();            Break                Case MotionEvent.ACTION_MOVE:float EndX = Event.getx ();                float EndY = event.gety ();                float Distancey = Starty-endy;                    if (StartX > SCREENWIDTH/2) {//Right//handle volume here} else {               This code is to fix a bug//bug: When the finger moves horizontally on the left side of the screen, it should be fast-forward and rewind, but it becomes a sensitivity adjustment.     Adding some of this code can be achieved by moving horizontally on the left side of the screen when the fast-forward rewind logic, rather than adjusting the shading//by phil float Distancex = Math.Abs                    (ENDX-STARTX);                        if (Distancex > Math.Abs (Distancey)) {//LOG.D ("displacement", distancex+ "," +distancey ");                    return false;                    }//Slide on the left half of the screen, brightness becomes larger, slide down, brightness becomes small final double fling_min_distance = 1;                    Final double fling_min_velocity = 1; if (Distancey > Fling_min_distance && math.abs (Distancey) > fling_min_velocity) {Set                    Brightness (10);                        } if (Distancey < fling_min_distance && Math.Abs (Distancey) > Fling_min_velocity) {                    Setbrightness (-10);        }} break;    } return Super.ontouchevent (event); }}


Layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:id=" @+id/activity_main "    android:layout_width=" match_parent "    android:layout_height = "Match_parent"    android:background= "@mipmap/ic_launcher" >    <textview        android:id= "@+id/text"        android:layout_width= "150DP"        android:layout_height= "50DP"        android:layout_gravity= "center"        Android:background= "@android: Color/holo_orange_light"        android:gravity= "center"        android:textcolor= "@ Android:color/white "/></framelayout>


Thanks:
Feng Zuxue is also contributing to this article!


Appendix:
1, "Android video player screen on the left side with your finger swipe up and down brightness adjust dimming principle implementation" link address: http://blog.csdn.net/zhangphil/article/details/56831156

Android video player The left edge of the screen with your finger swipe up and down brightness adjust dimming principle implementation (2): Subsequent improvements

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.