"Android" system volume and screen brightness adjustment

Source: Internet
Author: User

Screen brightness adjustment
/** * Swipe to change brightness, do not require permission * * @param percent brightness percentage, value is 0.0----1.0 */private void Onbrightnessslide (float percent) {if (mbrightn        ESS < 0) {//mbrightness is the brightness of the current screen mbrightness = GetWindow (). GetAttributes (). screenbrightness;        if (mbrightness <= 0.00f) mbrightness = 0.50f;        if (Mbrightness < 0.01f) mbrightness = 0.01f;        Display Moperationbg.setimageresource (R.DRAWABLE.VIDEO_BRIGHTNESS_BG);    Mvolumebrightnesslayout.setvisibility (view.visible);    } windowmanager.layoutparams LPA = GetWindow (). GetAttributes ();    Lpa.screenbrightness = mbrightness + percent;    if (lpa.screenbrightness > 1.0f) lpa.screenbrightness = 1.0f;    else if (Lpa.screenbrightness < 0.01f) lpa.screenbrightness = 0.01f;    GetWindow (). SetAttributes (LPA);    Viewgroup.layoutparams LP = Moperationpercent.getlayoutparams (); This section is a lp.width = (int) (Findviewbyid (R.id.operation_full)) that changes the progress of the current brightness above the picture. Getlayoutparams (). Width * Lpa.screenbrightness); MOPERATIONPERCENT.SETLAYOUTPARAMS (LP);}
Volume adjustment
/** * Volume adjustment, do not need permission */public class Mainactivity extends Activity {private static final String TAG = "mainactivity";    Private Audiomanager Maudiomanager;    private int currentvolume;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Maudiomanager = (Audiomanager) getsystemservice (Audio_service);        Maximum volume int maxvolume = Maudiomanager. Getstreammaxvolume (Audiomanager.stream_music);        LOG.I (TAG, "Maximum Volume:" + Maxvolume);        Currentvolume = Maudiomanager. Getstreamvolume (Audiomanager.stream_music);    LOG.I (TAG, "Current Volume:" + Currentvolume); public void up (view view) {///volume increased//Audiomanager.stream_system Maudiomanager.adjuststreamvolu        Me (Audiomanager.stream_music, audiomanager.adjust_raise, audiomanager.fx_focus_navigation_up); Currentvolume = Maudiomanager.Getstreamvolume (Audiomanager.stream_music);    LOG.I (TAG, "Current Volume:" + Currentvolume);                public void-down (view view) {///volume decrease Maudiomanager.adjuststreamvolume (Audiomanager.stream_music,        Audiomanager.adjust_lower, AUDIOMANAGER.FX_FOCUS_NAVIGATION_UP);        Currentvolume = Maudiomanager. Getstreamvolume (Audiomanager.stream_music);    LOG.I (TAG, "Current Volume:" + Currentvolume); }}

Welcome Androider Scan The following two-dimensional code attention to the public number: Ayandio, or search: loveandroid321 attention

"Android" system volume and screen brightness adjustment

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.