Files
packages_apps_Settings/src/com/android/settings/gestures/TapPreferenceController.java
Ido Ben-Hur 6f43cd72cd Settings: Allow showing Ambient instead of fully waking [2/2]
* [joeyhuab] Adapt to A16; Remove MainSwitchPreference.updateStatus like 041bc113eb

Separate configs for st2w and lift to wake
Follow our convention in the rest of the switches in that page

Change-Id: Ibd82d808aca2caf3f9c4518eb0c2e5f60669759e
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: Edwiin Kusuma Jaya <kutemeikito0905@gmail.com>
2025-12-10 00:41:32 +09:00

105 lines
3.6 KiB
Java

/*
* Copyright (C) 2023 Yet Another AOSP Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.Settings;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.MainSwitchPreference;
import org.evolution.settings.preferences.SecureSettingSwitchPreference;
public class TapPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, OnCheckedChangeListener {
private static final String KEY = "gesture_tap";
private static final String AMBIENT_KEY = "doze_tap_gesture_ambient";
private final Context mContext;
private MainSwitchPreference mSwitch;
private SecureSettingSwitchPreference mAmbientPref;
public TapPreferenceController(Context context) {
super(context);
mContext = context;
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mAmbientPref = screen.findPreference(AMBIENT_KEY);
mSwitch = screen.findPreference(getPreferenceKey());
mSwitch.setOnPreferenceClickListener(preference -> {
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, 1) == 1;
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
enabled ? 0 : 1);
updateAmbientEnablement(!enabled);
return true;
});
mSwitch.addOnSwitchChangeListener(this);
updateState(mSwitch);
}
public void setChecked(boolean isChecked) {
if (mSwitch != null) {
mSwitch.setChecked(isChecked);
}
updateAmbientEnablement(isChecked);
}
@Override
public void updateState(Preference preference) {
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, 1) == 1;
setChecked(enabled);
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, isChecked ? 1 : 0);
SystemProperties.set("persist.sys.tap_gesture", isChecked ? "1" : "0");
updateAmbientEnablement(isChecked);
}
private void updateAmbientEnablement(boolean enabled) {
if (mAmbientPref == null) return;
mAmbientPref.setEnabled(enabled);
}
}