Custom button light [2/2]
*DU Edits* - Adapt to our custom seekbar - Wrap preferences/seekbar with a category / update strings - Add check to remove preferences depending on bool (config_button_brightness_support) Change-Id: I90531723f8751a92766e96f5409d979a2f5bd524 Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -24,6 +24,9 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.Vibrator;
|
||||
import android.os.RemoteException;
|
||||
import android.os.PowerManager;
|
||||
import android.os.ServiceManager;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
@@ -33,10 +36,14 @@ import androidx.preference.SwitchPreference;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Toast;
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.SecureSettingSwitchPreference;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Utils;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
|
||||
import com.android.internal.util.hwkeys.ActionConstants;
|
||||
import com.android.internal.util.hwkeys.ActionUtils;
|
||||
|
||||
@@ -60,6 +67,11 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
|
||||
private static final String CATEGORY_APPSWITCH = "app_switch_key";
|
||||
private static final String CATEGORY_VOLUME = "volume_keys";
|
||||
private static final String CATEGORY_POWER = "power_key";
|
||||
|
||||
private static final String KEY_BUTTON_MANUAL_BRIGHTNESS_NEW = "button_manual_brightness_new";
|
||||
private static final String KEY_BUTTON_TIMEOUT = "button_timeout";
|
||||
private static final String KEY_BUTON_BACKLIGHT_OPTIONS = "button_backlight_options_category";
|
||||
|
||||
// Masks for checking presence of hardware keys.
|
||||
// Must match values in frameworks/base/core/res/res/values/config.xml
|
||||
public static final int KEY_MASK_HOME = 0x01;
|
||||
@@ -73,6 +85,9 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
|
||||
private static final String TORCH_POWER_BUTTON_GESTURE = "torch_power_button_gesture";
|
||||
|
||||
private ListPreference mTorchPowerButton;
|
||||
private CustomSeekBarPreference mButtonTimoutBar;
|
||||
private CustomSeekBarPreference mManualButtonBrightness;
|
||||
private PreferenceCategory mButtonBackLightCategory;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -133,6 +148,32 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
|
||||
mTorchPowerButton.setValue(Integer.toString(mTorchPowerButtonValue));
|
||||
mTorchPowerButton.setSummary(mTorchPowerButton.getEntry());
|
||||
mTorchPowerButton.setOnPreferenceChangeListener(this);
|
||||
|
||||
mManualButtonBrightness = (CustomSeekBarPreference) findPreference(
|
||||
KEY_BUTTON_MANUAL_BRIGHTNESS_NEW);
|
||||
final int customButtonBrightness = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_button_brightness_default);
|
||||
final int currentBrightness = Settings.System.getInt(resolver,
|
||||
Settings.System.CUSTOM_BUTTON_BRIGHTNESS, customButtonBrightness);
|
||||
PowerManager pm = (PowerManager)getActivity().getSystemService(Context.POWER_SERVICE);
|
||||
mManualButtonBrightness.setMax(pm.getMaximumScreenBrightnessSetting());
|
||||
mManualButtonBrightness.setValue(currentBrightness);
|
||||
mManualButtonBrightness.setOnPreferenceChangeListener(this);
|
||||
|
||||
mButtonTimoutBar = (CustomSeekBarPreference) findPreference(KEY_BUTTON_TIMEOUT);
|
||||
int currentTimeout = Settings.System.getInt(resolver,
|
||||
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 0);
|
||||
mButtonTimoutBar.setValue(currentTimeout);
|
||||
mButtonTimoutBar.setOnPreferenceChangeListener(this);
|
||||
|
||||
final boolean enableBacklightOptions = getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_button_brightness_support);
|
||||
|
||||
mButtonBackLightCategory = (PreferenceCategory) findPreference(KEY_BUTON_BACKLIGHT_OPTIONS);
|
||||
|
||||
if (!enableBacklightOptions) {
|
||||
prefScreen.removePreference(mButtonBackLightCategory);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@@ -145,8 +186,18 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
|
||||
Settings.System.putInt(resolver, Settings.System.TORCH_POWER_BUTTON_GESTURE,
|
||||
mTorchPowerButtonValue);
|
||||
return true;
|
||||
} else if (preference == mButtonTimoutBar) {
|
||||
int buttonTimeout = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, buttonTimeout);
|
||||
} else if (preference == mManualButtonBrightness) {
|
||||
int buttonBrightness = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.CUSTOM_BUTTON_BRIGHTNESS, buttonBrightness);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user