Android 13 亮度调节代码分析

frameworks\base\packages\SystemUI\res\layout\quick_settings_brightness_dialog.xml

进度条控件

复制代码
<com.android.systemui.settings.brightness.BrightnessSliderView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/brightness_slider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/brightness_mirror_height"
        android:layout_gravity="center"
        android:contentDescription="@string/accessibility_brightness"
        android:importantForAccessibility="no" >

        <com.android.systemui.settings.brightness.ToggleSeekBar
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:minHeight="48dp"
            android:thumb="@null"
            android:background="@null"
            android:paddingStart="0dp"
            android:paddingEnd="0dp"
            android:progressDrawable="@drawable/brightness_progress_drawable"
            android:splitTrack="false"
        />
    </com.android.systemui.settings.brightness.BrightnessSliderView>

frameworks\base\packages\SystemUI\src\com\android\systemui\settings\brightness\BrightnessSliderView.java

复制代码
// Inflated from quick_settings_brightness_dialog
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setLayerType(LAYER_TYPE_HARDWARE, null);

        mSlider = requireViewById(R.id.slider);
        mSlider.setAccessibilityLabel(getContentDescription().toString());

        // Finds the progress drawable. Assumes brightness_progress_drawable.xml
        try {
            LayerDrawable progress = (LayerDrawable) mSlider.getProgressDrawable();
            DrawableWrapper progressSlider = (DrawableWrapper) progress
                    .findDrawableByLayerId(android.R.id.progress);
            LayerDrawable actualProgressSlider = (LayerDrawable) progressSlider.getDrawable();
            mProgressDrawable = actualProgressSlider.findDrawableByLayerId(R.id.slider_foreground);
        } catch (Exception e) {
            // Nothing to do, mProgressDrawable will be null.
        }
    }

frameworks\base\packages\SystemUI\src\com\android\systemui\settings\brightness\BrightnessController.java

复制代码
private volatile boolean mAutomatic;  // Brightness adjusted automatically using ambient light.
    private volatile boolean mIsVrModeEnabled;
    private boolean mListening;
    private boolean mExternalChange;
    private boolean mControlValueInitialized;
    private float mBrightnessMin = PowerManager.BRIGHTNESS_MIN;
    private float mBrightnessMax = PowerManager.BRIGHTNESS_MAX;

    private void updateSlider(float brightnessValue, boolean inVrMode) {
        final float min;
        final float max;
        if (inVrMode) {
            min = mMinimumBacklightForVr;
            max = mMaximumBacklightForVr;
        } else {
            min = mBrightnessMin;
            max = mBrightnessMax;
        }

        // Ensure the slider is in a fixed position first, then check if we should animate.
        if (mSliderAnimator != null && mSliderAnimator.isStarted()) {
            mSliderAnimator.cancel();
        }
        // convertGammaToLinearFloat returns 0-1
        if (BrightnessSynchronizer.floatEquals(brightnessValue,
                convertGammaToLinearFloat(mControl.getValue(), min, max))) {
            // If the value in the slider is equal to the value on the current brightness
            // then the slider does not need to animate, since the brightness will not change.
            return;
        }
        // Returns GAMMA_SPACE_MIN - GAMMA_SPACE_MAX
        final int sliderVal = convertLinearToGammaFloat(brightnessValue, min, max);
        animateSliderTo(sliderVal);
    }

亮度最小值由PowerManager.BRIGHTNESS_MIN控制

frameworks\base\core\java\android\os\PowerManager.java 修改即可

复制代码
    //Brightness values for new float implementation:
    /**
     * Brightness value for fully on as float.
     * @hide
     */
    public static final float BRIGHTNESS_MAX = 1.0f;

    /**
     * Brightness value for minimum valid brightness as float.
     * @hide
     */
    public static final float BRIGHTNESS_MIN = 0.5f;

    /**
     * Brightness value for fully off in float.
     * @hide
     */
    public static final float BRIGHTNESS_OFF_FLOAT = -1.0f;
相关推荐
雨白1 天前
Android 两种拖拽 API 详解:ViewDragHelper 和 OnDragListener 的原理与区别
android
元亓亓亓1 天前
JavaWeb--day3--Ajax&Element&路由&打包部署
android·ajax·okhttp
居然是阿宋1 天前
Android XML属性与Jetpack Compose的对应关系(控件基础属性篇)
android
GoatJun1 天前
Android ScrollView嵌套RecyclerView 导致RecyclerView数据展示不全问题
android
潜龙95271 天前
第6.2节 Android Agent开发<二>
android·python·覆盖率数据
网安Ruler1 天前
代码审计-PHP专题&原生开发&SQL注入&1day分析构造&正则搜索&语句执行监控&功能定位
android
paid槮1 天前
MySql基础:数据类型
android·mysql·adb
用户2018792831671 天前
AMS和app通信的小秘密
android
用户2018792831671 天前
ThreadPoolExecutor之市场雇工的故事
android
诺诺Okami1 天前
Android Framework-Launcher-InvariantDeviceProfile
android