mirror of
https://github.com/florisboard/florisboard.git
synced 2024-09-20 03:52:18 +02:00
Add base for Settings
This commit is contained in:
parent
c671b8fb39
commit
c2e41011be
@ -30,6 +30,7 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.2.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
@ -7,21 +7,48 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/KeyboardTheme.MaterialLight">
|
||||
android:supportsRtl="true">
|
||||
|
||||
<!-- IME service -->
|
||||
<service
|
||||
android:name=".ime.core.FlorisBoard"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_INPUT_METHOD">
|
||||
android:permission="android.permission.BIND_INPUT_METHOD"
|
||||
android:theme="@style/KeyboardTheme.MaterialLight">
|
||||
<meta-data
|
||||
android:name="android.view.im"
|
||||
android:resource="@xml/method" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.view.InputMethod" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- UI related activities -->
|
||||
<activity
|
||||
android:name="dev.patrickgold.florisboard.settings.SettingsLauncherActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/SettingsTheme.Light">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="dev.patrickgold.florisboard.settings.SettingsMainActivity"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/SettingsTheme.Light" />
|
||||
|
||||
<activity
|
||||
android:name="dev.patrickgold.florisboard.settings.SettingsKbdActivity"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/settings__kbd__title"
|
||||
android:theme="@style/SettingsTheme.Light" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.patrickgold.florisboard.ime.core
|
||||
|
||||
import android.content.Intent
|
||||
import android.inputmethodservice.InputMethodService
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
@ -7,6 +8,7 @@ import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.LinearLayout
|
||||
import androidx.preference.PreferenceManager
|
||||
import dev.patrickgold.florisboard.R
|
||||
import dev.patrickgold.florisboard.ime.key.KeyCode
|
||||
import dev.patrickgold.florisboard.ime.key.KeyData
|
||||
@ -14,6 +16,7 @@ import dev.patrickgold.florisboard.ime.key.KeyType
|
||||
import dev.patrickgold.florisboard.ime.keyboard.KeyboardView
|
||||
import dev.patrickgold.florisboard.ime.keyboard.KeyboardMode
|
||||
import dev.patrickgold.florisboard.ime.layout.LayoutManager
|
||||
import dev.patrickgold.florisboard.settings.SettingsMainActivity
|
||||
import java.util.*
|
||||
|
||||
class FlorisBoard : InputMethodService() {
|
||||
@ -29,6 +32,9 @@ class FlorisBoard : InputMethodService() {
|
||||
val layoutManager = LayoutManager(this)
|
||||
|
||||
override fun onCreateInputView(): View? {
|
||||
// Set default preference values if user has not used preferences screen
|
||||
PreferenceManager.setDefaultValues(this, R.xml.prefs_kbd, true)
|
||||
|
||||
val rootView = layoutInflater.inflate(R.layout.florisboard, null) as LinearLayout
|
||||
layoutManager.autoFetchAssociationsFromPrefs()
|
||||
for (mode in KeyboardMode.values()) {
|
||||
@ -95,7 +101,11 @@ class FlorisBoard : InputMethodService() {
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode.LANGUAGE_SWITCH -> {}
|
||||
KeyCode.LANGUAGE_SWITCH -> {
|
||||
val i = Intent(this, SettingsMainActivity::class.java)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(i)
|
||||
}
|
||||
KeyCode.SHIFT -> {
|
||||
if (hasCapsRecentlyChanged) {
|
||||
osHandler.removeCallbacksAndMessages(null)
|
||||
|
@ -1,10 +1,13 @@
|
||||
package dev.patrickgold.florisboard.ime.keyboard
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.flexbox.FlexboxLayout
|
||||
import dev.patrickgold.florisboard.R
|
||||
|
||||
|
||||
class KeyboardRowView : FlexboxLayout {
|
||||
constructor(context: Context) : this(context, null)
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs,
|
||||
@ -17,7 +20,16 @@ class KeyboardRowView : FlexboxLayout {
|
||||
|
||||
layoutParams = layoutParams.apply {
|
||||
// TODO: get height from preferences
|
||||
height = resources.getDimension(R.dimen.keyboard_row_height).toInt()
|
||||
val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val factor = preferences.getString("keyboard_height_factor", "normal")
|
||||
height = (resources.getDimension(R.dimen.keyboard_row_height).toInt() * when (factor) {
|
||||
"small" -> 0.70f
|
||||
"mid_small" -> 0.85f
|
||||
"normal" -> 1.00f
|
||||
"mid_tall" -> 1.15f
|
||||
"tall" -> 1.30f
|
||||
else -> 1.00f
|
||||
}).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package dev.patrickgold.florisboard.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import dev.patrickgold.florisboard.R
|
||||
|
||||
class SettingsKbdActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.settings__kbd)
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(
|
||||
R.id.settings__kbd,
|
||||
SettingsFragment()
|
||||
)
|
||||
.commit()
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.prefs_kbd, rootKey)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.patrickgold.florisboard.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceManager
|
||||
import dev.patrickgold.florisboard.R
|
||||
|
||||
class SettingsLauncherActivity : Activity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Set default preference values if user has not used preferences screen
|
||||
PreferenceManager.setDefaultValues(this, R.xml.prefs_kbd, true)
|
||||
|
||||
startActivity(Intent(this, SettingsMainActivity::class.java))
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.patrickgold.florisboard.settings
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dev.patrickgold.florisboard.R
|
||||
|
||||
class SettingsMainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.settings)
|
||||
val btn1 = findViewById<Button>(R.id.settings_switch_kbd)
|
||||
btn1.setOnClickListener { v ->
|
||||
startActivity(Intent(this, SettingsKbdActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
10
app/src/main/res/layout/settings.xml
Normal file
10
app/src/main/res/layout/settings.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/settings_switch_kbd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings__kbd__title" />
|
||||
</LinearLayout>
|
9
app/src/main/res/layout/settings__kbd.xml
Normal file
9
app/src/main/res/layout/settings__kbd.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/settings__kbd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
17
app/src/main/res/values/arrays.xml
Normal file
17
app/src/main/res/values/arrays.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="pref__kbd__height_factor__entries">
|
||||
<item>Short</item>
|
||||
<item>Mid-short</item>
|
||||
<item>Normal</item>
|
||||
<item>Mid-tall</item>
|
||||
<item>Tall</item>
|
||||
</string-array>
|
||||
<string-array name="pref__kbd__height_factor__values">
|
||||
<item>short</item>
|
||||
<item>mid_short</item>
|
||||
<item>normal</item>
|
||||
<item>mid_tall</item>
|
||||
<item>tall</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -8,4 +8,11 @@
|
||||
<string name="key__view_symbols2">=\\<</string>
|
||||
|
||||
<string name="key_popup__threedots_alt">Three-dot icon. If visible, indicates that more letters can be used if longer pressed.</string>
|
||||
|
||||
<!-- Settings UI strings -->
|
||||
<string name="settings__title">Settings</string>
|
||||
<string name="settings__kbd__title">Keyboard preferences</string>
|
||||
|
||||
<!-- Preferences UI strings -->
|
||||
<string name="pref__kbd__height_factor__label">Keyboard height</string>
|
||||
</resources>
|
||||
|
@ -29,4 +29,8 @@
|
||||
<item name="keyboard_bgColor">#dfdfdf</item>
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme.Light" parent="Theme.AppCompat.Light">
|
||||
<!---->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
17
app/src/main/res/xml/prefs_kbd.xml
Normal file
17
app/src/main/res/xml/prefs_kbd.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory app:title="Layout">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="normal"
|
||||
app:entries="@array/pref__kbd__height_factor__entries"
|
||||
app:entryValues="@array/pref__kbd__height_factor__values"
|
||||
app:key="keyboard_height_factor"
|
||||
app:title="@string/pref__kbd__height_factor__label"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user