aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/values/config.xml3
-rw-r--r--res/xml/main.xml15
-rw-r--r--src/com/aicp/device/DeviceSettings.java14
-rw-r--r--src/com/aicp/device/GameModeSwitch.java58
-rw-r--r--src/com/aicp/device/Startup.java6
5 files changed, 96 insertions, 0 deletions
diff --git a/res/values/config.xml b/res/values/config.xml
index 287d8b6..1d5f7f8 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -132,4 +132,7 @@
<!-- Show/hide the QS tile, if device supports switching HighBrightness mode or not -->
<bool name="enableHBMModeTile">false</bool>
+
+ <!-- Path to devices game mode toggle file -->
+ <string name="pathGameModeToggle"></string>
</resources>
diff --git a/res/xml/main.xml b/res/xml/main.xml
index 13baa71..002f59a 100644
--- a/res/xml/main.xml
+++ b/res/xml/main.xml
@@ -94,6 +94,21 @@
</com.aicp.gear.preference.SelfRemovingPreferenceCategory>
<PreferenceCategory
+ android:key="category_gamemode"
+ android:title="@string/category_gamemode">
+ <SwitchPreference
+ android:key="game_mode"
+ android:summary="@string/game_mode_summary"
+ android:icon="@drawable/ic_game_mode"
+ android:title="@string/game_mode_title"
+ android:persistent="false" />
+ <Preference
+ android:icon="@drawable/ic_info"
+ android:persistent="false"
+ android:summary="@string/game_mode_warning" />
+ </PreferenceCategory>
+
+ <PreferenceCategory
android:key="category_gestures"
android:title="@string/screen_gestures_panel_title">
diff --git a/src/com/aicp/device/DeviceSettings.java b/src/com/aicp/device/DeviceSettings.java
index 1574128..92280ef 100644
--- a/src/com/aicp/device/DeviceSettings.java
+++ b/src/com/aicp/device/DeviceSettings.java
@@ -79,6 +79,7 @@ public class DeviceSettings extends PreferenceFragment implements
private static final String KEY_GESTURES_CATEGORY = "category_gestures";
private static final String KEY_POWER_CATEGORY = "category_power";
private static final String KEY_AUDIOGAINS_CATEGORY = "category_audiogains";
+ private static final String KEY_GAMEMODE_CATEGORY = "category_gamemode";
public static final String KEY_HEADPHONE_GAIN = "headphone_gain";
public static final String KEY_EARPIECE_GAIN = "earpiece_gain";
@@ -101,6 +102,7 @@ public class DeviceSettings extends PreferenceFragment implements
public static final String KEY_S2S_SWITCH = "sweep_to_sleep";
public static final String KEY_S2W_SWITCH = "sweep_to_wake";
public static final String KEY_FASTCHARGE_SWITCH = "fastcharge";
+ public static final String KEY_GAMEMODE_SWITCH = "game_mode";
private static final String KEY_PEAK_REFRESH_RATE = "peakrefreshrate";
private static final String KEY_MIN_REFRESH_RATE = "minrefreshrate";
public static final String KEY_OFFSCREEN_GESTURES = "gesture_category";
@@ -135,6 +137,7 @@ public class DeviceSettings extends PreferenceFragment implements
private static TwoStatePreference mHWKSwitch;
private static TwoStatePreference mSTapSwitch;
private static TwoStatePreference mFastChargeSwitch;
+ private static TwoStatePreference mGameModeSwitch;
private static TwoStatePreference mDoubleTapToWakeSwitch;
private static TwoStatePreference mSweepToSleepSwitch;
private static TwoStatePreference mSweepToWakeSwitch;
@@ -271,6 +274,17 @@ public class DeviceSettings extends PreferenceFragment implements
initRefreshRatePreference(mMinRefreshRatePref, MIN_REFRESH_RATE);
}
+ PreferenceCategory gamemodeCategory = (PreferenceCategory) findPreference(KEY_GAMEMODE_CATEGORY);
+ mGameModeSwitch = (TwoStatePreference) findPreference(KEY_GAMEMODE_SWITCH);
+ if (mGameModeSwitch != null && GameModeSwitch.isSupported(getContext())){
+ mGameModeSwitch.setEnabled(true);
+ mGameModeSwitch.setChecked(GameModeSwitch.isCurrentlyEnabled(getContext()));
+ mGameModeSwitch.setOnPreferenceChangeListener(new GameModeSwitch(getContext()));
+ } else {
+ gamemodeCategory.removePreference(mGameModeSwitch);
+ gamemodeCategory.getParent().removePreference(gamemodeCategory);;
+ }
+
PreferenceCategory powerCategory = (PreferenceCategory) findPreference(KEY_POWER_CATEGORY);
mFastChargeSwitch = (TwoStatePreference) findPreference(KEY_FASTCHARGE_SWITCH);
if (mFastChargeSwitch != null && FastChargeSwitch.isSupported(getContext())){
diff --git a/src/com/aicp/device/GameModeSwitch.java b/src/com/aicp/device/GameModeSwitch.java
new file mode 100644
index 0000000..1596fc1
--- /dev/null
+++ b/src/com/aicp/device/GameModeSwitch.java
@@ -0,0 +1,58 @@
+/*
+* Copyright (C) 2016 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package com.aicp.device;
+
+import android.content.Context;
+import android.provider.Settings;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+public class GameModeSwitch implements OnPreferenceChangeListener {
+
+ public static final String SETTINGS_KEY = DeviceSettings.KEY_SETTINGS_PREFIX + DeviceSettings.KEY_GAMEMODE_SWITCH;
+
+ private Context mContext;
+
+ public GameModeSwitch(Context context) {
+ mContext = context;
+ }
+
+ public static String getFile(Context context) {
+ String fileName = context.getResources().getString(R.string.pathGameModeToggle);
+ if (fileName != null && !fileName.isEmpty() && Utils.fileWritable(fileName)) {
+ return fileName;
+ }
+ return null;
+ }
+
+ public static boolean isSupported(Context context) {
+ return getFile(context) != null;
+ }
+
+ public static boolean isCurrentlyEnabled(Context context) {
+ return Utils.getFileValueAsBoolean(getFile(context), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Settings.System.putInt(mContext.getContentResolver(), SETTINGS_KEY, enabled ? 1 : 0);
+ Utils.writeValue(getFile(mContext), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/src/com/aicp/device/Startup.java b/src/com/aicp/device/Startup.java
index 85dc851..4ea85b1 100644
--- a/src/com/aicp/device/Startup.java
+++ b/src/com/aicp/device/Startup.java
@@ -80,6 +80,9 @@ public class Startup extends BroadcastReceiver {
enabled = sharedPrefs.getBoolean(DeviceSettings.KEY_S2S_SWITCH, false);
Settings.System.putInt(resolver, SweepToSleepSwitch.SETTINGS_KEY, enabled ? 1 : 0);
+ enabled = sharedPrefs.getBoolean(DeviceSettings.KEY_GAMEMODE_SWITCH, false);
+ Settings.System.putInt(resolver, GameModeSwitch.SETTINGS_KEY, enabled ? 1 : 0);
+
enabled = sharedPrefs.getBoolean(DeviceSettings.KEY_S2W_SWITCH, false);
Settings.System.putInt(resolver, SweepToWakeSwitch.SETTINGS_KEY, enabled ? 1 : 0);
@@ -241,6 +244,9 @@ public class Startup extends BroadcastReceiver {
enabled = Settings.System.getInt(resolver, SweepToSleepSwitch.SETTINGS_KEY, 0) != 0;
restore(SweepToSleepSwitch.getFile(context), enabled);
+ enabled = Settings.System.getInt(resolver, GameModeSwitch.SETTINGS_KEY, 0) != 0;
+ restore(GameModeSwitch.getFile(context), enabled);
+
enabled = Settings.System.getInt(resolver, SweepToWakeSwitch.SETTINGS_KEY, 0) != 0;
restore(SweepToWakeSwitch.getFile(context), enabled);