0
0
mirror of https://github.com/florisboard/florisboard.git synced 2024-09-20 03:52:18 +02:00

Add cardView style for error, warning and success / Enable viewBinding

- From now on, viewBinding will be used instead of findViewById(), if
  possible. This reduces unnecessary lines of code and reduces errors
  due to NullPointerExceptions.
- Add error message in HomeFragment to warn user that IME is not enabled.
This commit is contained in:
Patrick Goldinger 2020-06-22 15:48:16 +02:00
parent 4e69793298
commit 0172026577
12 changed files with 121 additions and 12 deletions

View File

@ -16,6 +16,10 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
viewBinding true
}
buildTypes {
release {
minifyEnabled false

View File

@ -16,7 +16,7 @@
<!-- IME service -->
<service
android:name=".ime.core.FlorisBoard"
android:name="dev.patrickgold.florisboard.ime.core.FlorisBoard"
android:label="@string/app_name"
android:permission="android.permission.BIND_INPUT_METHOD">
<meta-data

View File

@ -10,6 +10,7 @@ import android.os.Build
import android.os.Handler
import android.os.VibrationEffect
import android.os.Vibrator
import android.provider.Settings
import android.util.Log
import android.view.Gravity
import android.view.View
@ -63,6 +64,26 @@ class FlorisBoard : InputMethodService() {
}
companion object {
private const val IME_ID: String = "dev.patrickgold.florisboard/.ime.core.FlorisBoard"
fun checkIfImeIsEnabled(context: Context): Boolean {
val activeImeIds = Settings.Secure.getString(
context.contentResolver,
Settings.Secure.ENABLED_INPUT_METHODS
)
if (BuildConfig.DEBUG) Log.i(FlorisBoard::class.simpleName, "List of active IMEs: $activeImeIds")
return activeImeIds.split(":").contains(IME_ID)
}
fun checkIfImeIsSelected(context: Context): Boolean {
val selectedImeId = Settings.Secure.getString(
context.contentResolver,
Settings.Secure.DEFAULT_INPUT_METHOD
)
if (BuildConfig.DEBUG) Log.i(FlorisBoard::class.simpleName, "Selected IME: $selectedImeId")
return selectedImeId == IME_ID
}
@Synchronized
fun getInstance(): FlorisBoard {
return florisboardInstance!!

View File

@ -1,23 +1,58 @@
/*
* Copyright (C) 2020 Patrick Goldinger
*
* 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 dev.patrickgold.florisboard.settings
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.Toast
import androidx.fragment.app.Fragment
import dev.patrickgold.florisboard.R
import dev.patrickgold.florisboard.databinding.SettingsFragmentHomeBinding
import dev.patrickgold.florisboard.ime.core.FlorisBoard
class HomeFragment : Fragment() {
private lateinit var rootView: LinearLayout
private lateinit var binding: SettingsFragmentHomeBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
rootView = inflater.inflate(R.layout.settings_fragment_home, container, false) as LinearLayout
binding = SettingsFragmentHomeBinding.inflate(inflater, container, false)
binding.imeNotEnabledCard.setOnClickListener {
// TODO: Open setup wizard here
Toast.makeText(context, "Setup wizard NYI!!", Toast.LENGTH_SHORT).show()
}
return rootView
return binding.root
}
override fun onResume() {
super.onResume()
updateImeNotEnabledCardVisibility()
}
private fun updateImeNotEnabledCardVisibility() {
binding.imeNotEnabledCard.visibility =
if (FlorisBoard.checkIfImeIsEnabled(requireContext())) {
View.GONE
} else {
View.VISIBLE
}
}
}

View File

@ -5,6 +5,18 @@
android:orientation="vertical"
android:paddingVertical="8dp">
<androidx.cardview.widget.CardView
android:id="@+id/ime_not_enabled_card"
style="@style/SettingsCardView.Clickable.Error">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings__home__ime_not_enabled"
android:textColor="?textColorError"/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
style="@style/SettingsCardView">

View File

@ -24,9 +24,9 @@
android:layout_marginEnd="4dp"
android:padding="8dp"
android:background="@drawable/shape_rect_rounded"
android:backgroundTint="#F8F808"
android:backgroundTint="?colorWarning"
android:text="@string/settings__keyboard__subtype_no_subtypes_configured_warning"
android:textColor="#000000"/>
android:textColor="?textColorWarning"/>
<LinearLayout
android:id="@+id/settings__keyboard__subtype_list"

View File

@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:paddingHorizontal="8dp"
android:gravity="center_vertical">
<TextView
@ -27,7 +27,7 @@
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/language_dropdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="48dp"
android:entries="@array/supported_languages"/>
</LinearLayout>
@ -36,7 +36,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:paddingHorizontal="8dp"
android:gravity="center_vertical">
<TextView
@ -52,7 +52,7 @@
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/layout_dropdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="48dp"
android:entries="@array/valid_layout_names"/>
</LinearLayout>

View File

@ -36,4 +36,12 @@
<attr name="smartbar_candidate_fgColor" format="color" />
</declare-styleable>
<declare-styleable name="SettingsTheme">
<attr name="colorSuccess" format="reference|color"/>
<attr name="textColorSuccess" format="reference|color"/>
<attr name="colorWarning" format="reference|color"/>
<attr name="textColorWarning" format="reference|color"/>
<attr name="textColorError" format="reference|color"/>
</declare-styleable>
</resources>

View File

@ -5,6 +5,13 @@
<color name="colorAccent">#FF9800</color><!-- Orange 500 -->
<color name="colorAccentDark">#F57C00</color><!-- Orange 700 -->
<color name="colorSuccess">@color/colorPrimary</color><!-- Green 500 -->
<color name="textColorSuccess">#FFFFFF</color><!-- White -->
<color name="colorWarning">#FFFF00</color><!-- Yellow A200 -->
<color name="textColorWarning">#000000</color><!-- Black -->
<color name="colorError">#B00020</color><!-- Red 1000? -->
<color name="textColorError">#FFFFFF</color><!-- White -->
<color name="ic_launcher_background">#78909C</color>
<color name="cardViewBackgroundColor">#FFFFFF</color><!-- White -->

View File

@ -52,6 +52,7 @@
<string name="settings__navigation__advanced">Advanced</string>
<string name="settings__home__title">Welcome to %s</string>
<string name="settings__home__ime_not_enabled">FlorisBoard is not enabled in the system and thus won\'t be available as an input method in the input picker. Click here to resolve this issue.</string>
<string name="settings__keyboard__title">Keyboard &amp; Text Correction</string>
<string name="settings__keyboard__subtype_no_subtypes_configured_warning">It seems that you haven\'t configured any subtypes. As a fallback the subtype English/QWERTY will be used!</string>

View File

@ -76,5 +76,19 @@
<item name="cardBackgroundColor">@color/cardViewBackgroundColor</item>
<item name="cardCornerRadius">4dp</item>
</style>
<style name="SettingsCardView.Clickable">
<item name="android:foreground">?selectableItemBackground</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>
<style name="SettingsCardView.Clickable.Success">
<item name="cardBackgroundColor">?colorSuccess</item>
</style>
<style name="SettingsCardView.Clickable.Warning">
<item name="cardBackgroundColor">?colorWarning</item>
</style>
<style name="SettingsCardView.Clickable.Error">
<item name="cardBackgroundColor">?colorError</item>
</style>
</resources>

View File

@ -94,6 +94,13 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorSuccess">@color/colorSuccess</item>
<item name="textColorSuccess">@color/textColorSuccess</item>
<item name="colorWarning">@color/colorWarning</item>
<item name="textColorWarning">@color/textColorWarning</item>
<item name="colorError">@color/colorError</item>
<item name="textColorError">@color/textColorError</item>
<!-- IMPORTANT: the following 2 colors MUST be references and not inline colors, or older
versions of Android will not set the window background and thus causing weird