pipa: peripheralmanager: Split refresh rate handling from force stylus
* lets just make sylus mode a thing which for 120hz for it to work
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
<!-- Xiaomi Stylus -->
|
||||
<string name="stylus_title">Stylus</string>
|
||||
<string name="stylus_summary">Stylus Settings</string>
|
||||
<string name="stylus_switch_title">Force recognize stylus</string>
|
||||
<string name="stylus_switch_summary">Enable this settings to allow using third party styluses</string>
|
||||
|
||||
<string name="stylus_switch_title">Stylus Mode</string>
|
||||
<string name="force_stylus_switch_title">Force recognize stylus</string>
|
||||
<string name="force_stylus_switch_summary">Enable this settings to allow using third party styluses</string>
|
||||
<string name="stylus_more_info">Stylus Mode limits display\'s max refresh rate to 120Hz</string>
|
||||
</resources>
|
||||
|
||||
@@ -18,10 +18,21 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/stylus_title">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="stylus_switch_key"
|
||||
android:defaultValue="false"
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="stylus_mode_key"
|
||||
android:title="@string/stylus_switch_title"
|
||||
android:summary="@string/stylus_switch_summary"/>
|
||||
android:defaultValue="false" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="force_recognize_stylus_key"
|
||||
android:title="@string/force_stylus_switch_title"
|
||||
android:summary="@string/force_stylus_switch_summary"
|
||||
android:defaultValue="false"
|
||||
android:dependency="stylus_mode_key" />
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="footer_key"
|
||||
android:title="@string/stylus_more_info"
|
||||
android:selectable="false" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -43,14 +43,12 @@ public class PenUtils {
|
||||
Log.d(TAG, "enablePenMode: Enable Pen Mode");
|
||||
SystemProperties.set("persist.vendor.parts.pen", "18");
|
||||
Log.d(TAG, "enablePenMode: Setting Refresh Rates for Pen");
|
||||
mRefreshUtils.setPenRefreshRate();
|
||||
}
|
||||
|
||||
public static void disablePenMode() {
|
||||
Log.d(TAG, "disablePenMode: Disable Pen Mode");
|
||||
SystemProperties.set("persist.vendor.parts.pen", "2");
|
||||
Log.d(TAG, "disablePenMode: Resetting Refresh Rate Values");
|
||||
mRefreshUtils.setDefaultRefreshRate();
|
||||
}
|
||||
|
||||
private static void refreshPenMode() {
|
||||
|
||||
@@ -19,38 +19,40 @@ package org.lineageos.xiaomiperipheralmanager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Switch;
|
||||
import android.util.Log;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceFragment;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
import org.lineageos.xiaomiperipheralmanager.PenUtils;
|
||||
import org.lineageos.xiaomiperipheralmanager.R;
|
||||
|
||||
public class StylusSettingsFragment extends PreferenceFragment implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = "XiaomiPeripheralManagerPenUtils";
|
||||
private static final String STYLUS_KEY = "stylus_switch_key";
|
||||
private static final String STYLUS_MODE_KEY = "stylus_mode_key";
|
||||
private static final String FORCE_RECOGNIZE_STYLUS_KEY =
|
||||
"force_recognize_stylus_key";
|
||||
|
||||
private SharedPreferences mStylusPreference;
|
||||
private RefreshUtils mRefreshUtils;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.stylus_settings);
|
||||
|
||||
mStylusPreference = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
SwitchPreference switchPreference = (SwitchPreference) findPreference(STYLUS_KEY);
|
||||
Context context = getContext();
|
||||
mStylusPreference = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
mRefreshUtils = new RefreshUtils(context);
|
||||
|
||||
switchPreference.setChecked(mStylusPreference.getBoolean(STYLUS_KEY, false));
|
||||
switchPreference.setEnabled(true);
|
||||
}
|
||||
MainSwitchPreference stylusModePref =
|
||||
(MainSwitchPreference)findPreference("stylus_mode_key");
|
||||
stylusModePref.setChecked(
|
||||
mStylusPreference.getBoolean("stylus_mode_key", false));
|
||||
|
||||
SwitchPreference forceRecognizePref =
|
||||
(SwitchPreference)findPreference("force_recognize_stylus_key");
|
||||
forceRecognizePref.setChecked(
|
||||
mStylusPreference.getBoolean("force_recognize_stylus_key", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
@@ -65,18 +67,26 @@ public class StylusSettingsFragment extends PreferenceFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreference, String key) {
|
||||
if (STYLUS_KEY.equals(key)) {
|
||||
forceStylus(mStylusPreference.getBoolean(key, false));
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key) {
|
||||
if (STYLUS_MODE_KEY.equals(key)) {
|
||||
setStylusMode(sharedPreferences.getBoolean(key, false));
|
||||
} else if (FORCE_RECOGNIZE_STYLUS_KEY.equals(key)) {
|
||||
setForceRecognizeStylus(sharedPreferences.getBoolean(key, false));
|
||||
}
|
||||
}
|
||||
|
||||
private void forceStylus(boolean status) {
|
||||
mStylusPreference.edit().putBoolean(STYLUS_KEY, status).apply();
|
||||
private void setStylusMode(boolean enabled) {
|
||||
if (enabled)
|
||||
mRefreshUtils.setPenRefreshRate();
|
||||
else
|
||||
mRefreshUtils.setDefaultRefreshRate();
|
||||
}
|
||||
|
||||
if (status)
|
||||
PenUtils.enablePenMode();
|
||||
else
|
||||
PenUtils.disablePenMode();
|
||||
private void setForceRecognizeStylus(boolean enabled) {
|
||||
if (enabled)
|
||||
PenUtils.enablePenMode();
|
||||
else
|
||||
PenUtils.disablePenMode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user