Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd6045be authored by Salvador Martinez's avatar Salvador Martinez
Browse files

Update Battery Saver schedule to add order to seekbar

If the first time battery saver warning was the one causing
a change in settings global the radio button picker doesn't update
the preferences correctly and would put the seekbar at the top. This
explicitly adds an order to the seekbar so that if it gets updated
for some reason it will show up at the end again.

Test: atest BatterySaverScheduleSettingsTest
Bug: 131434758
Change-Id: Iebab5d176c8fbdaea078e13a71eff7e21408353b
parent 8b285f23
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ public class BatterySaverScheduleSeekBarController implements
    }

    public void addToScreen(PreferenceScreen screen) {
        // makes sure it gets added after the preferences if called due to first time battery
        // saver message
        mSeekBarPreference.setOrder(5);
        screen.addPreference(mSeekBarPreference);
    }
}
+31 −0
Original line number Diff line number Diff line
@@ -17,15 +17,20 @@
package com.android.settings.fuelgauge.batterysaver;

import android.content.Context;
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
@@ -51,8 +56,18 @@ import java.util.List;
public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {

    public BatterySaverScheduleRadioButtonsController mRadioButtonController;
    @VisibleForTesting
    Context mContext;
    private BatterySaverScheduleSeekBarController mSeekBarController;

    @VisibleForTesting
    final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            updateCandidates();
        }
    };

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.battery_saver_schedule_settings;
@@ -64,6 +79,16 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
        mSeekBarController = new BatterySaverScheduleSeekBarController(context);
        mRadioButtonController = new BatterySaverScheduleRadioButtonsController(
                context, mSeekBarController);
        mContext = context;
    }

    @Override
    public void onResume() {
        super.onResume();
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED),
                false,
                mSettingsObserver);
    }

    @Override
@@ -78,6 +103,12 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onPause() {
        mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
        super.onPause();
    }

    @Override
    protected List<? extends CandidateInfo> getCandidates() {
        Context context = getContext();