From f95fa2950639a3bc31dbac80bb2a291a0f9023c5 Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Thu, 17 Feb 2022 21:45:07 +0000 Subject: pro1: devicesettings: Refactor Change-Id: Idd472c36699e13194ecf6b480895f3d9253f5b06 --- devicesettings/Android.bp | 4 - devicesettings/AndroidManifest.xml | 8 +- devicesettings/proguard.flags | 3 - .../settings/device/BootCompletedReceiver.java | 92 +-------- .../org/lineageos/settings/device/Constants.java | 64 ------ .../lineageos/settings/device/CustomKeymap.java | 87 --------- .../DeviceSettingsSearchIndexablesProvider.java | 13 +- .../settings/device/KeyboardSettingsActivity.java | 32 --- .../settings/device/KeyboardSettingsFragment.java | 214 --------------------- .../settings/device/SetupWizardActivity.java | 103 ---------- .../settings/device/SetupWizardBaseActivity.java | 95 --------- .../device/TouchscreenSettingsActivity.java | 32 --- .../device/TouchscreenSettingsFragment.java | 90 --------- .../settings/device/keyboard/Constants.java | 62 ++++++ .../device/keyboard/KeyboardSettingsActivity.java | 32 +++ .../device/keyboard/KeyboardSettingsFragment.java | 174 +++++++++++++++++ .../settings/device/keyboard/KeyboardUtils.java | 134 +++++++++++++ .../device/setupwizard/SetupWizardActivity.java | 103 ++++++++++ .../setupwizard/SetupWizardBaseActivity.java | 95 +++++++++ .../settings/device/touchscreen/Constants.java | 24 +++ .../touchscreen/TouchscreenSettingsActivity.java | 32 +++ .../touchscreen/TouchscreenSettingsFragment.java | 76 ++++++++ .../device/touchscreen/TouchscreenUtils.java | 35 ++++ 23 files changed, 786 insertions(+), 818 deletions(-) delete mode 100644 devicesettings/proguard.flags delete mode 100644 devicesettings/src/org/lineageos/settings/device/Constants.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/CustomKeymap.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/KeyboardSettingsActivity.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java delete mode 100644 devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java create mode 100644 devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java create mode 100644 devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java create mode 100644 devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java create mode 100644 devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardUtils.java create mode 100644 devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardActivity.java create mode 100644 devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java create mode 100644 devicesettings/src/org/lineageos/settings/device/touchscreen/Constants.java create mode 100644 devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsActivity.java create mode 100644 devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java create mode 100644 devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenUtils.java 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 @@ - + @@ -53,7 +53,7 @@ @@ -62,7 +62,7 @@ @@ -71,7 +71,7 @@ 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 (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/Constants.java b/devicesettings/src/org/lineageos/settings/device/Constants.java deleted file mode 100644 index d320e87..0000000 --- a/devicesettings/src/org/lineageos/settings/device/Constants.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2018-2020 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; - -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"; - - // Keyboard keymap - public static final String KEYBOARD_KEYMAP_CUSTOM_KEY = "keyboard_keymap_custom"; - public static final String KEYBOARD_KEYMAP_CFG_FILE = "/data/system/keyboard/keymap"; - public static final String KEYBOARD_KEYMAP_SPACEPOWER_KEY = "keyboard_keymap_spacepower"; - public static final String[] KEYBOARD_KEYMAP_SPACEPOWER_TEXT = { - "48:0039:0074" - }; - public static final String KEYBOARD_KEYMAP_FNKEYS_KEY = "keyboard_keymap_fnkeys"; - public static final String[] KEYBOARD_KEYMAP_FNKEYS_TEXT = { - "57:0002:003b", - "60:0003:003c", - "8:0004:003d", - "61:0005:003e", - "55:0006:003f", - "19:0007:0040", - "3:0008:0041", - "53:0009:0042", - "13:000a:0043", - "45:000b:0044", - "29:000c:0057", - "37:000d:0058" - }; - public static final String KEYBOARD_KEYMAP_ALTGR_KEY = "keyboard_keymap_altgr"; - 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"; - - // 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"; -} 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/KeyboardSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsActivity.java deleted file mode 100644 index b5aa991..0000000 --- a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsActivity.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2018-2019,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; - -import android.os.Bundle; - -import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; -import com.android.settingslib.collapsingtoolbar.R; - -public class KeyboardSettingsActivity extends CollapsingToolbarBaseActivity { - - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getFragmentManager().beginTransaction().replace(R.id.content_frame, - new KeyboardSettingsFragment()).commit(); - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java deleted file mode 100644 index e178897..0000000 --- a/devicesettings/src/org/lineageos/settings/device/KeyboardSettingsFragment.java +++ /dev/null @@ -1,214 +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.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; - -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; - -public class KeyboardSettingsFragment extends PreferenceFragment - implements SharedPreferences.OnSharedPreferenceChangeListener { - - private static final String TAG = KeyboardSettingsFragment.class.getSimpleName(); - private static final boolean DEBUG = false; - - private ListPreference mLayoutPref; - private SharedPreferences mPrefs; - private SwitchPreference mKeymapCustomPref; - private SwitchPreference mKeymapSpacePowerPref; - private SwitchPreference mKeymapFnKeysPref; - private SwitchPreference mKeymapAltGrPref; - private SwitchPreference mFastPollPref; - - @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); - mKeymapSpacePowerPref = findPreference(Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY); - mKeymapFnKeysPref = findPreference(Constants.KEYBOARD_KEYMAP_FNKEYS_KEY); - mKeymapAltGrPref = findPreference(Constants.KEYBOARD_KEYMAP_ALTGR_KEY); - mFastPollPref = findPreference(Constants.KEYBOARD_FASTPOLL_KEY); - - String value = FileUtils.readOneLine(Constants.KEYBOARD_LAYOUT_SYS_FILE); - mLayoutPref.setValue(value.substring(0, 6)); - - mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - doUpdateKeymapPreferences(); - } - - @Override - public void onResume() { - super.onResume(); - mPrefs.registerOnSharedPreferenceChangeListener(this); - } - - @Override - public void onPause() { - super.onPause(); - mPrefs.unregisterOnSharedPreferenceChangeListener(this); - } - - @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: - doUpdateLayoutPreference(); - break; - case Constants.KEYBOARD_KEYMAP_CUSTOM_KEY: - case Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY: - case Constants.KEYBOARD_KEYMAP_FNKEYS_KEY: - case Constants.KEYBOARD_KEYMAP_ALTGR_KEY: - doUpdateKeymapPreferences(); - break; - case Constants.KEYBOARD_FASTPOLL_KEY: - doUpdateFastPollPreference(); - break; - } - } - - private void doUpdateLayoutPreference() { - String value = mLayoutPref.getValue(); - SystemProperties.set(Constants.KEYBOARD_LAYOUT_PROPERTY, value); - } - - private void doUpdateKeymapPreferences() { - FileUtils.writeLine(Constants.KEYBOARD_LAYOUT_SYS_FILE, mLayoutPref.getValue()); - - mKeymapFnKeysPref.setEnabled(true); - mKeymapSpacePowerPref.setEnabled(true); - mKeymapAltGrPref.setEnabled(true); - - File customKeymapFile = new File(Constants.KEYBOARD_KEYMAP_CFG_FILE); - if (customKeymapFile.exists()) { - if (DEBUG) Log.d(TAG, "Found custom keymap at " + - Constants.KEYBOARD_KEYMAP_CFG_FILE); - mKeymapCustomPref.setEnabled(true); - mKeymapCustomPref.setSummary(getResources().getString( - R.string.keyboard_keymap_custom_summary_available)); - } else { - mKeymapCustomPref.setChecked(false); - mKeymapCustomPref.setEnabled(false); - mKeymapCustomPref.setSummary(getResources().getString( - R.string.keyboard_keymap_custom_summary_disabled)); - } - - if (mKeymapCustomPref.isChecked()) { - if (CustomKeymap.install()) { - mKeymapCustomPref.setSummary(getResources().getString( - R.string.keyboard_keymap_custom_summary_enabled)); - mKeymapFnKeysPref.setChecked(false); - mKeymapFnKeysPref.setEnabled(false); - mKeymapSpacePowerPref.setChecked(false); - mKeymapSpacePowerPref.setEnabled(false); - mKeymapAltGrPref.setChecked(false); - mKeymapAltGrPref.setEnabled(false); - } else { - mKeymapCustomPref.setChecked(false); - Context context = getContext(); - Toast.makeText(context, context.getResources().getString( - R.string.keyboard_keymap_custom_failed), - Toast.LENGTH_LONG).show(); - } - } - - if (mKeymapFnKeysPref.isChecked()) { - 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"); - } - mKeymapCustomPref.setChecked(false); - } - - if (mKeymapSpacePowerPref.isChecked()) { - 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"); - } - mKeymapCustomPref.setChecked(false); - } - - if (mKeymapAltGrPref.isChecked()) { - 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"); - } - mKeymapCustomPref.setChecked(false); - } - } - - 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; - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java b/devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java deleted file mode 100644 index 8f37e20..0000000 --- a/devicesettings/src/org/lineageos/settings/device/SetupWizardActivity.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 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.os.SystemProperties; -import android.view.View; -import android.widget.AdapterView; -import android.widget.SimpleAdapter; -import android.widget.Spinner; - -import org.lineageos.internal.util.FileUtils; - -import org.lineageos.settings.device.R; - -import java.util.ArrayList; -import java.util.HashMap; - -public class SetupWizardActivity extends SetupWizardBaseActivity { - - @Override - protected int getLayoutResId() { - return R.layout.setupwizard; - } - - @Override - protected int getTitleResId() { - return R.string.setupwizard_title; - } - - @Override - protected int getIconResId() { - return R.drawable.ic_keyboard_outline; - } - - @Override - protected void setupPage() { - final Spinner spinner = (Spinner) findViewById(R.id.kbd_layout_list); - final SimpleAdapter adapter = constructKeylayoutAdapter(); - spinner.setAdapter(adapter); - spinner.setSelection(getSelectedIndex()); - spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - String[] values = getResources().getStringArray(R.array.keyboard_layout_values); - SystemProperties.set(Constants.KEYBOARD_LAYOUT_PROPERTY, values[position]); - } - - @Override - public void onNothingSelected(AdapterView parent) { - // do nothing - } - }); - } - - private SimpleAdapter constructKeylayoutAdapter() { - final String KEY_DISPLAYNAME = "name"; - - final String[] choices = getResources().getStringArray(R.array.keyboard_layout_titles); - final String[] from = new String[] { KEY_DISPLAYNAME }; - final int[] to = new int[] {android.R.id.text1}; - - ArrayList> arrayList = new ArrayList<>(); - for (int i = 0 ; i < choices.length; i++) { - HashMap hashMap = new HashMap<>(); - hashMap.put(KEY_DISPLAYNAME, choices[i]); - arrayList.add(hashMap); - } - - // we use different layouts for the spinner when opened and closed to imitate the look - // of other SuW pages (e.g. the timezone picker when closed) - final SimpleAdapter adapter = new SimpleAdapter(this, arrayList, - R.layout.kbd_layout_list_selected, from, to); - adapter.setDropDownViewResource(android.R.layout.simple_list_item_1); - - return adapter; - } - - private int getSelectedIndex() { - String value = FileUtils.readOneLine(Constants.KEYBOARD_LAYOUT_SYS_FILE); - value = value.substring(0, 6); - String[] values = getResources().getStringArray(R.array.keyboard_layout_values); - for (int i = 0; i < values.length; i++) { - if (values[i].equals(value)) { - return i; - } - } - return 0; - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java b/devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java deleted file mode 100644 index 292e056..0000000 --- a/devicesettings/src/org/lineageos/settings/device/SetupWizardBaseActivity.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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. - * 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.app.Activity; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; -import android.widget.Button; - -import com.android.settingslib.Utils; - -import com.google.android.setupdesign.GlifLayout; - -import org.lineageos.settings.device.R; - -public class SetupWizardBaseActivity extends Activity implements View.OnClickListener { - - private static final int WINDOW_FLAGS = View.STATUS_BAR_DISABLE_HOME - | View.STATUS_BAR_DISABLE_RECENT; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getWindow().getDecorView().setSystemUiVisibility(WINDOW_FLAGS); - - initLayout(); - } - - @Override - public void onClick(View view) { - // Keep this for navigating purposes - if (view.getId() == R.id.btn_next) { - setResult(RESULT_OK, null); - finish(); - } - } - - private void initLayout() { - if (getLayoutResId() != -1) { - setContentView(getLayoutResId()); - } - if (getTitleResId() != -1) { - final CharSequence headerText = TextUtils.expandTemplate(getText(getTitleResId())); - getGlifLayout().setHeaderText(headerText); - } - if (getIconResId() != -1) { - final GlifLayout layout = getGlifLayout(); - final Drawable icon = getDrawable(getIconResId()).mutate(); - icon.setTintList(Utils.getColorAccent(layout.getContext())); - layout.setIcon(icon); - } - - Button buttonNext = findViewById(R.id.btn_next); - buttonNext.setOnClickListener(this); - - setupPage(); - } - - protected GlifLayout getGlifLayout() { - return requireViewById(R.id.setup_wizard_layout); - } - - protected int getLayoutResId() { - return -1; - } - - protected int getTitleResId() { - return -1; - } - - protected int getIconResId() { - return -1; - } - - protected void setupPage() { - return; - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java deleted file mode 100644 index 6eb7880..0000000 --- a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsActivity.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2018-2019,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; - -import android.os.Bundle; - -import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; -import com.android.settingslib.collapsingtoolbar.R; - -public class TouchscreenSettingsActivity extends CollapsingToolbarBaseActivity { - - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getFragmentManager().beginTransaction().replace(R.id.content_frame, - new TouchscreenSettingsFragment()).commit(); - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java deleted file mode 100644 index 6fbf3b5..0000000 --- a/devicesettings/src/org/lineageos/settings/device/TouchscreenSettingsFragment.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2018-2019 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.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; - -public class TouchscreenSettingsFragment extends PreferenceFragment - implements SharedPreferences.OnSharedPreferenceChangeListener { - - private static final String TAG = TouchscreenSettingsFragment.class.getSimpleName(); - - private SeekBarPreference mMarginSeekBar; - private SharedPreferences mPrefs; - - @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); - - mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - doUpdateMarginPreference(); - } - - @Override - public void onResume() { - super.onResume(); - mPrefs.registerOnSharedPreferenceChangeListener(this); - } - - @Override - public void onPause() { - super.onPause(); - mPrefs.unregisterOnSharedPreferenceChangeListener(this); - } - - @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(); - } - } - - private void doUpdateMarginPreference() { - final Context context = getContext(); - final int margin = Constants.TOUCHSCREEN_MARGIN_STEP * - mPrefs.getInt(Constants.TOUCHSCREEN_MARGIN_KEY, - context.getResources().getInteger(R.integer.touchscreen_margin_default)); - - FileUtils.writeLine(Constants.TOUCHSCREEN_MARGIN_SYS_FILE, Integer.toString(margin)); - mMarginSeekBar.setSummary(getString(R.string.touchscreen_margin_summary, margin)); - } -} diff --git a/devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java b/devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java new file mode 100644 index 0000000..5920dea --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/Constants.java @@ -0,0 +1,62 @@ +/* + * 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; + +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"; + + // Keyboard keymap + public static final String KEYBOARD_KEYMAP_CUSTOM_KEY = "keyboard_keymap_custom"; + public static final String KEYBOARD_KEYMAP_CFG_FILE = "/data/system/keyboard/keymap"; + public static final String KEYBOARD_KEYMAP_SPACEPOWER_KEY = "keyboard_keymap_spacepower"; + public static final String[] KEYBOARD_KEYMAP_SPACEPOWER_TEXT = { + "48:0039:0074" + }; + public static final String KEYBOARD_KEYMAP_FNKEYS_KEY = "keyboard_keymap_fnkeys"; + public static final String[] KEYBOARD_KEYMAP_FNKEYS_TEXT = { + "57:0002:003b", + "60:0003:003c", + "8:0004:003d", + "61:0005:003e", + "55:0006:003f", + "19:0007:0040", + "3:0008:0041", + "53:0009:0042", + "13:000a:0043", + "45:000b:0044", + "29:000c:0057", + "37:000d:0058" + }; + public static final String KEYBOARD_KEYMAP_ALTGR_KEY = "keyboard_keymap_altgr"; + 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"; + + // 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"; +} diff --git a/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java new file mode 100644 index 0000000..0746f07 --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsActivity.java @@ -0,0 +1,32 @@ +/* + * 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. + * 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.os.Bundle; + +import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; +import com.android.settingslib.collapsingtoolbar.R; + +public class KeyboardSettingsActivity extends CollapsingToolbarBaseActivity { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getFragmentManager().beginTransaction().replace(R.id.content_frame, + new KeyboardSettingsFragment()).commit(); + } +} diff --git a/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java new file mode 100644 index 0000000..fb6aab5 --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/keyboard/KeyboardSettingsFragment.java @@ -0,0 +1,174 @@ +/* + * 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. + * 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.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.SystemProperties; +import android.preference.PreferenceManager; +import android.util.Log; +import android.widget.Toast; + +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragment; +import androidx.preference.SwitchPreference; + +import org.lineageos.internal.util.FileUtils; +import org.lineageos.settings.device.R; + +import java.io.File; + +public class KeyboardSettingsFragment extends PreferenceFragment + implements SharedPreferences.OnSharedPreferenceChangeListener { + + private static final String TAG = KeyboardSettingsFragment.class.getSimpleName(); + private static final boolean DEBUG = false; + + private ListPreference mLayoutPref; + private SharedPreferences mPrefs; + private SwitchPreference mKeymapCustomPref; + private SwitchPreference mKeymapSpacePowerPref; + private SwitchPreference mKeymapFnKeysPref; + private SwitchPreference mKeymapAltGrPref; + private SwitchPreference mFastPollPref; + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.keyboard_panel); + + mLayoutPref = findPreference(Constants.KEYBOARD_LAYOUT_KEY); + mKeymapCustomPref = findPreference(Constants.KEYBOARD_KEYMAP_CUSTOM_KEY); + mKeymapSpacePowerPref = findPreference(Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY); + mKeymapFnKeysPref = findPreference(Constants.KEYBOARD_KEYMAP_FNKEYS_KEY); + mKeymapAltGrPref = findPreference(Constants.KEYBOARD_KEYMAP_ALTGR_KEY); + mFastPollPref = findPreference(Constants.KEYBOARD_FASTPOLL_KEY); + + String value = FileUtils.readOneLine(Constants.KEYBOARD_LAYOUT_SYS_FILE); + mLayoutPref.setValue(value.substring(0, 6)); + + mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + doUpdateKeymapPreferences(); + } + + @Override + public void onResume() { + super.onResume(); + mPrefs.registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + mPrefs.unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + switch (key) { + case Constants.KEYBOARD_LAYOUT_KEY: + doUpdateLayoutPreference(); + break; + case Constants.KEYBOARD_KEYMAP_CUSTOM_KEY: + case Constants.KEYBOARD_KEYMAP_SPACEPOWER_KEY: + case Constants.KEYBOARD_KEYMAP_FNKEYS_KEY: + case Constants.KEYBOARD_KEYMAP_ALTGR_KEY: + doUpdateKeymapPreferences(); + break; + case Constants.KEYBOARD_FASTPOLL_KEY: + doUpdateFastPollPreference(); + break; + } + } + + private void doUpdateLayoutPreference() { + String value = mLayoutPref.getValue(); + SystemProperties.set(Constants.KEYBOARD_LAYOUT_PROPERTY, value); + } + + private void doUpdateKeymapPreferences() { + FileUtils.writeLine(Constants.KEYBOARD_LAYOUT_SYS_FILE, mLayoutPref.getValue()); + + mKeymapFnKeysPref.setEnabled(true); + mKeymapSpacePowerPref.setEnabled(true); + mKeymapAltGrPref.setEnabled(true); + + File customKeymapFile = new File(Constants.KEYBOARD_KEYMAP_CFG_FILE); + if (customKeymapFile.exists()) { + if (DEBUG) Log.d(TAG, "Found custom keymap at " + + Constants.KEYBOARD_KEYMAP_CFG_FILE); + mKeymapCustomPref.setEnabled(true); + mKeymapCustomPref.setSummary(getResources().getString( + R.string.keyboard_keymap_custom_summary_available)); + } else { + mKeymapCustomPref.setChecked(false); + mKeymapCustomPref.setEnabled(false); + mKeymapCustomPref.setSummary(getResources().getString( + R.string.keyboard_keymap_custom_summary_disabled)); + } + + if (mKeymapCustomPref.isChecked()) { + if (KeyboardUtils.installCustomKeymap()) { + mKeymapCustomPref.setSummary(getResources().getString( + R.string.keyboard_keymap_custom_summary_enabled)); + mKeymapFnKeysPref.setChecked(false); + mKeymapFnKeysPref.setEnabled(false); + mKeymapSpacePowerPref.setChecked(false); + mKeymapSpacePowerPref.setEnabled(false); + mKeymapAltGrPref.setChecked(false); + mKeymapAltGrPref.setEnabled(false); + } else { + mKeymapCustomPref.setChecked(false); + Context context = getContext(); + Toast.makeText(context, context.getResources().getString( + R.string.keyboard_keymap_custom_failed), + Toast.LENGTH_LONG).show(); + } + } + + if (mKeymapFnKeysPref.isChecked()) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT.length; ++i) { + KeyboardUtils.writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_FNKEYS_TEXT[i] + "\n"); + } + mKeymapCustomPref.setChecked(false); + } + + if (mKeymapSpacePowerPref.isChecked()) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT.length; ++i) { + KeyboardUtils.writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_SPACEPOWER_TEXT[i] + "\n"); + } + mKeymapCustomPref.setChecked(false); + } + + if (mKeymapAltGrPref.isChecked()) { + for (int i = 0; i < Constants.KEYBOARD_KEYMAP_ALTGR_TEXT.length; ++i) { + KeyboardUtils. writeFile(Constants.KEYBOARD_KEYMAP_SYS_FILE, + Constants.KEYBOARD_KEYMAP_ALTGR_TEXT[i] + "\n"); + } + mKeymapCustomPref.setChecked(false); + } + } + + private void doUpdateFastPollPreference() { + 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/setupwizard/SetupWizardActivity.java b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardActivity.java new file mode 100644 index 0000000..8f6b95b --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardActivity.java @@ -0,0 +1,103 @@ +/* + * 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. + * 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.setupwizard; + +import android.os.SystemProperties; +import android.view.View; +import android.widget.AdapterView; +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; +import java.util.HashMap; + +public class SetupWizardActivity extends SetupWizardBaseActivity { + + @Override + protected int getLayoutResId() { + return R.layout.setupwizard; + } + + @Override + protected int getTitleResId() { + return R.string.setupwizard_title; + } + + @Override + protected int getIconResId() { + return R.drawable.ic_keyboard_outline; + } + + @Override + protected void setupPage() { + final Spinner spinner = (Spinner) findViewById(R.id.kbd_layout_list); + final SimpleAdapter adapter = constructKeylayoutAdapter(); + spinner.setAdapter(adapter); + spinner.setSelection(getSelectedIndex()); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + String[] values = getResources().getStringArray(R.array.keyboard_layout_values); + SystemProperties.set(Constants.KEYBOARD_LAYOUT_PROPERTY, values[position]); + } + + @Override + public void onNothingSelected(AdapterView parent) { + // do nothing + } + }); + } + + private SimpleAdapter constructKeylayoutAdapter() { + final String KEY_DISPLAYNAME = "name"; + + final String[] choices = getResources().getStringArray(R.array.keyboard_layout_titles); + final String[] from = new String[] { KEY_DISPLAYNAME }; + final int[] to = new int[] {android.R.id.text1}; + + ArrayList> arrayList = new ArrayList<>(); + for (int i = 0 ; i < choices.length; i++) { + HashMap hashMap = new HashMap<>(); + hashMap.put(KEY_DISPLAYNAME, choices[i]); + arrayList.add(hashMap); + } + + // we use different layouts for the spinner when opened and closed to imitate the look + // of other SuW pages (e.g. the timezone picker when closed) + final SimpleAdapter adapter = new SimpleAdapter(this, arrayList, + R.layout.kbd_layout_list_selected, from, to); + adapter.setDropDownViewResource(android.R.layout.simple_list_item_1); + + return adapter; + } + + private int getSelectedIndex() { + String value = FileUtils.readOneLine(Constants.KEYBOARD_LAYOUT_SYS_FILE); + value = value.substring(0, 6); + String[] values = getResources().getStringArray(R.array.keyboard_layout_values); + for (int i = 0; i < values.length; i++) { + if (values[i].equals(value)) { + return i; + } + } + return 0; + } +} diff --git a/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java new file mode 100644 index 0000000..caca0e3 --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/setupwizard/SetupWizardBaseActivity.java @@ -0,0 +1,95 @@ +/* + * 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. + * 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.setupwizard; + +import android.app.Activity; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; + +import com.android.settingslib.Utils; + +import com.google.android.setupdesign.GlifLayout; + +import org.lineageos.settings.device.R; + +public class SetupWizardBaseActivity extends Activity implements View.OnClickListener { + + private static final int WINDOW_FLAGS = View.STATUS_BAR_DISABLE_HOME + | View.STATUS_BAR_DISABLE_RECENT; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getWindow().getDecorView().setSystemUiVisibility(WINDOW_FLAGS); + + initLayout(); + } + + @Override + public void onClick(View view) { + // Keep this for navigating purposes + if (view.getId() == R.id.btn_next) { + setResult(RESULT_OK, null); + finish(); + } + } + + private void initLayout() { + if (getLayoutResId() != -1) { + setContentView(getLayoutResId()); + } + if (getTitleResId() != -1) { + final CharSequence headerText = TextUtils.expandTemplate(getText(getTitleResId())); + getGlifLayout().setHeaderText(headerText); + } + if (getIconResId() != -1) { + final GlifLayout layout = getGlifLayout(); + final Drawable icon = getDrawable(getIconResId()).mutate(); + icon.setTintList(Utils.getColorAccent(layout.getContext())); + layout.setIcon(icon); + } + + Button buttonNext = findViewById(R.id.btn_next); + buttonNext.setOnClickListener(this); + + setupPage(); + } + + protected GlifLayout getGlifLayout() { + return requireViewById(R.id.setup_wizard_layout); + } + + protected int getLayoutResId() { + return -1; + } + + protected int getTitleResId() { + return -1; + } + + protected int getIconResId() { + return -1; + } + + protected void setupPage() { + return; + } +} 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/touchscreen/TouchscreenSettingsActivity.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsActivity.java new file mode 100644 index 0000000..e58b21a --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsActivity.java @@ -0,0 +1,32 @@ +/* + * 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. + * 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.os.Bundle; + +import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; +import com.android.settingslib.collapsingtoolbar.R; + +public class TouchscreenSettingsActivity extends CollapsingToolbarBaseActivity { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getFragmentManager().beginTransaction().replace(R.id.content_frame, + new TouchscreenSettingsFragment()).commit(); + } +} diff --git a/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java new file mode 100644 index 0000000..d41c6fa --- /dev/null +++ b/devicesettings/src/org/lineageos/settings/device/touchscreen/TouchscreenSettingsFragment.java @@ -0,0 +1,76 @@ +/* + * 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. + * 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.os.Bundle; +import android.preference.PreferenceManager; + +import androidx.preference.PreferenceFragment; + +import org.lineageos.internal.util.FileUtils; +import org.lineageos.settings.device.R; +import org.lineageos.settings.device.widget.SeekBarPreference; + +public class TouchscreenSettingsFragment extends PreferenceFragment + implements SharedPreferences.OnSharedPreferenceChangeListener { + + private static final String TAG = TouchscreenSettingsFragment.class.getSimpleName(); + + private SeekBarPreference mMarginSeekBar; + private SharedPreferences mPrefs; + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.touchscreen_panel); + + mMarginSeekBar = findPreference(Constants.TOUCHSCREEN_MARGIN_KEY); + + mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + doUpdateMarginPreference(); + } + + @Override + public void onResume() { + super.onResume(); + mPrefs.registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + mPrefs.unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPrefs, String key) { + if (Constants.TOUCHSCREEN_MARGIN_KEY.equals(key)) { + doUpdateMarginPreference(); + } + } + + private void doUpdateMarginPreference() { + final Context context = getContext(); + final int margin = Constants.TOUCHSCREEN_MARGIN_STEP * + mPrefs.getInt(Constants.TOUCHSCREEN_MARGIN_KEY, + context.getResources().getInteger(R.integer.touchscreen_margin_default)); + + FileUtils.writeLine(Constants.TOUCHSCREEN_MARGIN_SYS_FILE, Integer.toString(margin)); + mMarginSeekBar.setSummary(getString(R.string.touchscreen_margin_summary, margin)); + } +} 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)); + } +} -- cgit v1.2.3