diff options
| author | Bruno Martins <bgcngm@gmail.com> | 2022-02-17 21:45:07 +0000 |
|---|---|---|
| committer | Bruno Martins <bgcngm@gmail.com> | 2022-02-17 23:16:56 +0000 |
| commit | f95fa2950639a3bc31dbac80bb2a291a0f9023c5 (patch) | |
| tree | 4da8557a342c4819122ce53fbc78843307a04871 | |
| parent | 8593e795263fb22c9a1c4973ab9332467062b9ee (diff) | |
pro1: devicesettings: Refactor
Change-Id: Idd472c36699e13194ecf6b480895f3d9253f5b06
16 files changed, 245 insertions, 277 deletions
diff --git a/devicesettings/Android.bp b/devicesettings/Android.bp index 242e3ca..498cada 100644 --- a/devicesettings/Android.bp +++ b/devicesettings/Android.bp @@ -19,8 +19,4 @@ android_app { "SettingsLib", "setupdesign", ], - - optimize: { - proguard_flags_files: ["proguard.flags"], - }, } diff --git a/devicesettings/AndroidManifest.xml b/devicesettings/AndroidManifest.xml index b1a1ee3..d419383 100644 --- a/devicesettings/AndroidManifest.xml +++ b/devicesettings/AndroidManifest.xml @@ -45,7 +45,7 @@ </intent-filter> </provider> - <receiver android:name="org.lineageos.settings.device.BootCompletedReceiver"> + <receiver android:name=".BootCompletedReceiver"> <intent-filter> <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" /> <category android:name="android.intent.category.DEFAULT" /> @@ -53,7 +53,7 @@ </receiver> <activity - android:name=".KeyboardSettingsActivity" + android:name=".keyboard.KeyboardSettingsActivity" android:label="@string/keyboard_settings_title"> <intent-filter> <action android:name="org.lineageos.settings.device.ADVANCED_KEYBOARD_SETTINGS" /> @@ -62,7 +62,7 @@ </activity> <activity - android:name=".SetupWizardActivity" + android:name=".setupwizard.SetupWizardActivity" android:theme="@style/Theme.SetupWizard"> <intent-filter> <action android:name="org.lineageos.settings.device.SUW_SETTINGS" /> @@ -71,7 +71,7 @@ </activity> <activity - android:name=".TouchscreenSettingsActivity" + android:name=".touchscreen.TouchscreenSettingsActivity" android:label="@string/touchscreen_settings_title"> <intent-filter> <action android:name="com.android.settings.action.IA_SETTINGS" /> diff --git a/devicesettings/proguard.flags b/devicesettings/proguard.flags deleted file mode 100644 index 43b57d9..0000000 --- a/devicesettings/proguard.flags +++ /dev/null @@ -1,3 +0,0 @@ --keepclasseswithmembers class * { - public <init>(android.content.Context, android.util.AttributeSet); -} diff --git a/devicesettings/src/org/lineageos/settings/device/BootCompletedReceiver.java b/devicesettings/src/org/lineageos/settings/device/BootCompletedReceiver.java index e1525d0..77ebcaf 100644 --- a/devicesettings/src/org/lineageos/settings/device/BootCompletedReceiver.java +++ b/devicesettings/src/org/lineageos/settings/device/BootCompletedReceiver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 The LineageOS Project + * Copyright (C) 2020-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,96 +21,18 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.util.Log; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; - -import org.lineageos.settings.device.R; +import org.lineageos.settings.device.keyboard.KeyboardUtils; +import org.lineageos.settings.device.touchscreen.TouchscreenUtils; public class BootCompletedReceiver extends BroadcastReceiver { + @Override public void onReceive(Context context, Intent intent) { - setKeyboardKeymap(context); - setKeyboardPollInterval(context); - setTouchscreenMargin(context); - } - private static final String TAG = BootCompletedReceiver.class.getSimpleName(); - private static final boolean DEBUG = false; - - private void setKeyboardKeymap(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - if (!prefs.contains(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY)) { - File f = new File(Constants.KEYBOARD_KEYMAP_CFG_FILE); - prefs.edit().putBoolean(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY, f.exists()).commit(); - } - boolean custom = prefs.getBoolean(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY, false); - if (custom) { - CustomKeymap.install(); - } - else { - boolean value; - - value = prefs.getBoolean(Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY, false); - if (value) { - for (int i = 0; i < Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT[i] + "\n"); - } - } - - value = prefs.getBoolean(Constants.KEYBOARD_KEYMAP_FNKEYS_KEY, false); - if (value) { - for (int i = 0; i < Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT[i] + "\n"); - } - } - - value = prefs.getBoolean(Constants.KEYBOARD_KEYMAP_ALTGR_KEY, false); - if (value) { - for (int i = 0; i < Constants.KEYBOARD_KEYMAP_ALTGR_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_ALTGR_TEXT[i] + "\n"); - } - } - } - } - - private void setKeyboardPollInterval(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - int value = prefs.getBoolean(Constants.KEYBOARD_FASTPOLL_KEY, false) - ? Constants.KEYBOARD_POLL_INTERVAL_FAST - : Constants.KEYBOARD_POLL_INTERVAL_SLOW; - writeFile(Constants.KEYBOARD_POLL_INTERVAL_SYS_FILE, Integer.toString(value)); - } - - private void setTouchscreenMargin(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - int value = Constants.TOUCHSCREEN_MARGIN_STEP * prefs.getInt(Constants.TOUCHSCREEN_MARGIN_KEY, - context.getResources().getInteger(R.integer.touchscreen_margin_default)); - writeFile(Constants.TOUCHSCREEN_MARGIN_SYS_FILE, Integer.toString(value)); - } - - private String readFile(String filename) { - String result = null; - try { - FileReader reader = new FileReader(filename); - char[] buffer = new char[4096]; - reader.read(buffer); - result = new String(buffer); - } - catch (Exception e) { /* Ignore */ } - return result; - } - private boolean writeFile(String filename, String text) { - boolean result = false; - try { - FileWriter writer = new FileWriter(filename); - writer.write(text); - writer.flush(); - result = true; - } - catch (Exception e) { /* Ignore */ } - return result; + KeyboardUtils.setKeyboardKeymap(prefs); + KeyboardUtils.setKeyboardPollInterval(prefs); + TouchscreenUtils.setTouchscreenMargin(context); } } diff --git a/devicesettings/src/org/lineageos/settings/device/CustomKeymap.java b/devicesettings/src/org/lineageos/settings/device/CustomKeymap.java deleted file mode 100644 index b60c594..0000000 --- a/devicesettings/src/org/lineageos/settings/device/CustomKeymap.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2018-2021 The LineageOS 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 org.lineageos.settings.device; - -import android.util.Log; - -import java.io.File; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.FileInputStream; -import java.io.BufferedWriter; -import java.io.OutputStreamWriter; -import java.io.FileOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -public class CustomKeymap { - - private static final String TAG = CustomKeymap.class.getSimpleName(); - private static final boolean DEBUG = false; - - private CustomKeymap() { - // This class is not supposed to be instantiated - } - - public static boolean install() { - if (DEBUG) Log.d(TAG, "Installing custom keymap"); - BufferedReader in = null; - BufferedWriter out = null; - - try { - in = new BufferedReader( - new InputStreamReader( - new FileInputStream( - new File(Constants.KEYBOARD_KEYMAP_CFG_FILE) - ) - ) - ); - if (DEBUG) Log.d(TAG, "Opened input: " + Constants.KEYBOARD_KEYMAP_CFG_FILE); - - out = new BufferedWriter( - new OutputStreamWriter( - new FileOutputStream( - new File(Constants.KEYBOARD_KEYMAP_SYS_FILE) - ) - ) - ); - if (DEBUG) Log.d(TAG, "Opened output: " + Constants.KEYBOARD_KEYMAP_SYS_FILE); - - for (String line; (line = in.readLine()) != null;) { - out.write(line); - out.newLine(); - } - } catch(FileNotFoundException e) { - Log.e(TAG, "FileNotFoundException: ", e); - return false; - } catch(IOException e) { - Log.e(TAG, "IOException: ", e); - return false; - } finally { - try { - out.close(); - in.close(); - } catch(IOException e) { - Log.e(TAG, "IOException: ", e); - return false; - } - } - - if (DEBUG) Log.d(TAG, "Wrote custom keymap to kernel"); - return true; - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/DeviceSettingsSearchIndexablesProvider.java b/devicesettings/src/org/lineageos/settings/device/DeviceSettingsSearchIndexablesProvider.java index 26b2932..8dec9d7 100644 --- a/devicesettings/src/org/lineageos/settings/device/DeviceSettingsSearchIndexablesProvider.java +++ b/devicesettings/src/org/lineageos/settings/device/DeviceSettingsSearchIndexablesProvider.java @@ -16,11 +16,6 @@ package org.lineageos.settings.device; -import android.database.Cursor; -import android.database.MatrixCursor; -import android.provider.SearchIndexableResource; -import android.provider.SearchIndexablesProvider; - import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME; import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID; import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION; @@ -32,6 +27,14 @@ import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.provider.SearchIndexableResource; +import android.provider.SearchIndexablesProvider; + +import org.lineageos.settings.device.keyboard.KeyboardSettingsActivity; +import org.lineageos.settings.device.touchscreen.TouchscreenSettingsActivity; + public class DeviceSettingsSearchIndexablesProvider extends SearchIndexablesProvider { private static final String TAG = "DeviceSettingsSearchIndexablesProvider"; diff --git a/devicesettings/src/org/lineageos/settings/device/Constants.java b/devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java index d320e87..5920dea 100644 --- a/devicesettings/src/org/lineageos/settings/device/Constants.java +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 The LineageOS Project + * Copyright (C) 2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,14 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.keyboard; public class Constants { // Keyboard layout public static final String KEYBOARD_LAYOUT_KEY = "keyboard_layout"; public static final String KEYBOARD_LAYOUT_PROPERTY = "sys.keyboard.layout"; - public static final String KEYBOARD_LAYOUT_SYS_FILE = "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/layout"; + public static final String KEYBOARD_LAYOUT_SYS_FILE = + "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/layout"; // Keyboard keymap public static final String KEYBOARD_KEYMAP_CUSTOM_KEY = "keyboard_keymap_custom"; @@ -48,17 +49,14 @@ public class Constants { public static final String[] KEYBOARD_KEYMAP_ALTGR_TEXT = { "69:0064:0064" }; - public static final String KEYBOARD_KEYMAP_SYS_FILE = "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/keymap"; + public static final String KEYBOARD_KEYMAP_SYS_FILE = + "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/keymap"; // Keyboard poll interval public static final String KEYBOARD_FASTPOLL_KEY = "keyboard_fastpoll"; - public static final int KEYBOARD_POLL_INTERVAL_DEFAULT = 40; - public static final int KEYBOARD_POLL_INTERVAL_FAST = 20; - public static final int KEYBOARD_POLL_INTERVAL_SLOW = 40; - public static final String KEYBOARD_POLL_INTERVAL_SYS_FILE = "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/poll_interval"; - - // Touch screen margin - public static final String TOUCHSCREEN_MARGIN_KEY = "touchscreen_margin"; - public static final int TOUCHSCREEN_MARGIN_STEP = 16; - public static final String TOUCHSCREEN_MARGIN_SYS_FILE = "/sys/goodix/margin_x"; + public static final int KEYBOARD_POLL_INTERVAL_DEFAULT = 40; + public static final int KEYBOARD_POLL_INTERVAL_FAST = 20; + public static final int KEYBOARD_POLL_INTERVAL_SLOW = 40; + public static final String KEYBOARD_POLL_INTERVAL_SYS_FILE = + "/sys/devices/soc/c17a000.i2c/i2c-6/6-0058/poll_interval"; } diff --git a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java index b5aa991..0746f07 100644 --- a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsActivity.java +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019,2022 The LineageOS Project + * Copyright (C) 2020-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.keyboard; import android.os.Bundle; diff --git a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java index e178897..fb6aab5 100644 --- a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 The LineageOS Project + * Copyright (C) 2020-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.keyboard; -import android.app.ActionBar; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.os.SystemProperties; import android.preference.PreferenceManager; -import android.view.MenuItem; import android.util.Log; import android.widget.Toast; @@ -30,14 +28,11 @@ import androidx.preference.ListPreference; import androidx.preference.PreferenceFragment; import androidx.preference.SwitchPreference; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; - import org.lineageos.internal.util.FileUtils; - import org.lineageos.settings.device.R; +import java.io.File; + public class KeyboardSettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -55,8 +50,6 @@ public class KeyboardSettingsFragment extends PreferenceFragment @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.keyboard_panel); - final ActionBar actionBar = getActivity().getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); mLayoutPref = findPreference(Constants.KEYBOARD_LAYOUT_KEY); mKeymapCustomPref = findPreference(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY); @@ -85,15 +78,6 @@ public class KeyboardSettingsFragment extends PreferenceFragment } @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - getActivity().onBackPressed(); - return true; - } - return false; - } - - @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { switch (key) { case Constants.KEYBOARD_LAYOUT_KEY: @@ -138,7 +122,7 @@ public class KeyboardSettingsFragment extends PreferenceFragment } if (mKeymapCustomPref.isChecked()) { - if (CustomKeymap.install()) { + if (KeyboardUtils.installCustomKeymap()) { mKeymapCustomPref.setSummary(getResources().getString( R.string.keyboard_keymap_custom_summary_enabled)); mKeymapFnKeysPref.setChecked(false); @@ -158,7 +142,7 @@ public class KeyboardSettingsFragment extends PreferenceFragment if (mKeymapFnKeysPref.isChecked()) { for (int i = 0; i < Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + KeyboardUtils.writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT[i] + "\n"); } mKeymapCustomPref.setChecked(false); @@ -166,7 +150,7 @@ public class KeyboardSettingsFragment extends PreferenceFragment if (mKeymapSpacePowerPref.isChecked()) { for (int i = 0; i < Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + KeyboardUtils.writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT[i] + "\n"); } mKeymapCustomPref.setChecked(false); @@ -174,7 +158,7 @@ public class KeyboardSettingsFragment extends PreferenceFragment if (mKeymapAltGrPref.isChecked()) { for (int i = 0; i < Constants.KEYBOARD_KEYMAP_ALTGR_TEXT.length; ++i) { - writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + KeyboardUtils. writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, Constants.KEYBOARD_KEYMAP_ALTGR_TEXT[i] + "\n"); } mKeymapCustomPref.setChecked(false); @@ -182,33 +166,9 @@ public class KeyboardSettingsFragment extends PreferenceFragment } private void doUpdateFastPollPreference() { - int value = mFastPollPref.isChecked() - ? Constants.KEYBOARD_POLL_INTERVAL_FAST - : Constants.KEYBOARD_POLL_INTERVAL_SLOW; - writeFile(Constants.KEYBOARD_POLL_INTERVAL_SYS_FILE, Integer.toString(value)); - } - - private String readFile(String filename) { - String result = null; - try { - FileReader reader = new FileReader(filename); - char[] buffer = new char[4096]; - reader.read(buffer); - result = new String(buffer); - } - catch (Exception e) { /* Ignore */ } - return result; - } - - private boolean writeFile(String filename, String text) { - boolean result = false; - try { - FileWriter writer = new FileWriter(filename); - writer.write(text); - writer.flush(); - result = true; - } - catch (Exception e) { /* Ignore */ } - return result; + final int interval = mFastPollPref.isChecked() ? + Constants.KEYBOARD_POLL_INTERVAL_FAST : Constants.KEYBOARD_POLL_INTERVAL_SLOW; + KeyboardUtils.writeFile(Constants.KEYBOARD_POLL_INTERVAL_SYS_FILE, + Integer.toString(interval)); } } diff --git a/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardUtils.java b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardUtils.java new file mode 100644 index 0000000..469e73e --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardUtils.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2022 The LineageOS 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 org.lineageos.settings.device.keyboard; + +import android.content.SharedPreferences; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.OutputStreamWriter; + +public class KeyboardUtils { + + private static final String TAG = KeyboardUtils.class.getSimpleName(); + private static final boolean DEBUG = false; + + public static boolean installCustomKeymap() { + if (DEBUG) Log.d(TAG, "Installing custom keymap"); + BufferedReader in = null; + BufferedWriter out = null; + + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( + new File(Constants.KEYBOARD_KEYMAP_CFG_FILE) + ) + ) + ); + if (DEBUG) Log.d(TAG, "Opened input: " + Constants.KEYBOARD_KEYMAP_CFG_FILE); + + out = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream( + new File(Constants.KEYBOARD_KEYMAP_SYS_FILE) + ) + ) + ); + if (DEBUG) Log.d(TAG, "Opened output: " + Constants.KEYBOARD_KEYMAP_SYS_FILE); + + for (String line; (line = in.readLine()) != null;) { + out.write(line); + out.newLine(); + } + } catch(FileNotFoundException e) { + Log.e(TAG, "FileNotFoundException: ", e); + return false; + } catch(IOException e) { + Log.e(TAG, "IOException: ", e); + return false; + } finally { + try { + out.close(); + in.close(); + } catch(IOException e) { + Log.e(TAG, "IOException: ", e); + return false; + } + } + + if (DEBUG) Log.d(TAG, "Wrote custom keymap to kernel"); + return true; + } + + public static void setKeyboardKeymap(SharedPreferences prefs) { + if (!prefs.contains(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY)) { + File f = new File(Constants.KEYBOARD_KEYMAP_CFG_FILE); + prefs.edit().putBoolean(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY, f.exists()).commit(); + } + if (prefs.getBoolean(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY, false)) { + installCustomKeymap(); + } else { + if (prefs.getBoolean(Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY, false)) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT.length; ++i) { + writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT[i] + "\n"); + } + } + + if (prefs.getBoolean(Constants.KEYBOARD_KEYMAP_FNKEYS_KEY, false)) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT.length; ++i) { + writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT[i] + "\n"); + } + } + + if (prefs.getBoolean(Constants.KEYBOARD_KEYMAP_ALTGR_KEY, false)) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_ALTGR_TEXT.length; ++i) { + writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_ALTGR_TEXT[i] + "\n"); + } + } + } + } + + public static void setKeyboardPollInterval(SharedPreferences prefs) { + final int interval = prefs.getBoolean(Constants.KEYBOARD_FASTPOLL_KEY, false) ? + Constants.KEYBOARD_POLL_INTERVAL_FAST : Constants.KEYBOARD_POLL_INTERVAL_SLOW; + writeFile(Constants.KEYBOARD_POLL_INTERVAL_SYS_FILE, Integer.toString(interval)); + } + + public static boolean writeFile(String filename, String text) { + boolean result = false; + try { + FileWriter writer = new FileWriter(filename); + writer.write(text); + writer.flush(); + result = true; + } + catch (Exception e) { /* Ignore */ } + return result; + } +} diff --git a/devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardActivity.java index 8f37e20..8f6b95b 100644 --- a/devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java +++ b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 The LineageOS Project + * Copyright (C) 2021-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.setupwizard; import android.os.SystemProperties; import android.view.View; @@ -23,7 +23,7 @@ import android.widget.SimpleAdapter; import android.widget.Spinner; import org.lineageos.internal.util.FileUtils; - +import org.lineageos.settings.device.keyboard.Constants; import org.lineageos.settings.device.R; import java.util.ArrayList; diff --git a/devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java index 292e056..caca0e3 100644 --- a/devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java +++ b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.setupwizard; import android.app.Activity; import android.graphics.drawable.Drawable; diff --git a/devicesettings/src/org/lineageos/settings/device/touchscreen/Constants.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/Constants.java new file mode 100644 index 0000000..100b247 --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/Constants.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 The LineageOS 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 org.lineageos.settings.device.touchscreen; + +public class Constants { + // Touch screen margin + public static final String TOUCHSCREEN_MARGIN_KEY = "touchscreen_margin"; + public static final int TOUCHSCREEN_MARGIN_STEP = 16; + public static final String TOUCHSCREEN_MARGIN_SYS_FILE = "/sys/goodix/margin_x"; +} diff --git a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsActivity.java index 6eb7880..e58b21a 100644 --- a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019,2022 The LineageOS Project + * Copyright (C) 2020-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.touchscreen; import android.os.Bundle; diff --git a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java index 6fbf3b5..d41c6fa 100644 --- a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 The LineageOS Project + * Copyright (C) 2020-2022 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,16 @@ * limitations under the License. */ -package org.lineageos.settings.device; +package org.lineageos.settings.device.touchscreen; -import android.app.ActionBar; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.view.MenuItem; import androidx.preference.PreferenceFragment; import org.lineageos.internal.util.FileUtils; - import org.lineageos.settings.device.R; import org.lineageos.settings.device.widget.SeekBarPreference; @@ -41,8 +38,6 @@ public class TouchscreenSettingsFragment extends PreferenceFragment @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.touchscreen_panel); - final ActionBar actionBar = getActivity().getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); mMarginSeekBar = findPreference(Constants.TOUCHSCREEN_MARGIN_KEY); @@ -63,15 +58,6 @@ public class TouchscreenSettingsFragment extends PreferenceFragment } @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - getActivity().onBackPressed(); - return true; - } - return false; - } - - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPrefs, String key) { if (Constants.TOUCHSCREEN_MARGIN_KEY.equals(key)) { doUpdateMarginPreference(); diff --git a/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenUtils.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenUtils.java new file mode 100644 index 0000000..adc28fe --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 The LineageOS 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 org.lineageos.settings.device.touchscreen; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import org.lineageos.internal.util.FileUtils; +import org.lineageos.settings.device.R; + +public class TouchscreenUtils { + + public static void setTouchscreenMargin(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + final int margin = Constants.TOUCHSCREEN_MARGIN_STEP * + prefs.getInt(Constants.TOUCHSCREEN_MARGIN_KEY, + context.getResources().getInteger(R.integer.touchscreen_margin_default)); + FileUtils.writeLine(Constants.TOUCHSCREEN_MARGIN_SYS_FILE, Integer.toString(margin)); + } +} |
