mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-24 12:50:50 +02:00
add option to hide keyboard when scrolling (cf. #142)
Some checks failed
Android CI / build (push) Has been cancelled
Some checks failed
Android CI / build (push) Has been cancelled
This commit is contained in:
parent
22633bdac3
commit
077bd1ce44
6 changed files with 36 additions and 4 deletions
|
@ -72,6 +72,7 @@ import eu.jonahbauer.android.preference.annotations.Preferences;
|
||||||
@Preference(name = "search_auto_launch", type = boolean.class, defaultValue = "true"),
|
@Preference(name = "search_auto_launch", type = boolean.class, defaultValue = "true"),
|
||||||
@Preference(name = "search_web", type = boolean.class, description = "false"),
|
@Preference(name = "search_web", type = boolean.class, description = "false"),
|
||||||
@Preference(name = "search_auto_open_keyboard", type = boolean.class, defaultValue = "true"),
|
@Preference(name = "search_auto_open_keyboard", type = boolean.class, defaultValue = "true"),
|
||||||
|
@Preference(name = "search_auto_close_keyboard", type = boolean.class, defaultValue = "false"),
|
||||||
}),
|
}),
|
||||||
@PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = {
|
@PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = {
|
||||||
@Preference(name = "double_swipe", type = boolean.class, defaultValue = "true"),
|
@Preference(name = "double_swipe", type = boolean.class, defaultValue = "true"),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.jrpie.android.launcher.ui
|
package de.jrpie.android.launcher.ui
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.ColorMatrix
|
import android.graphics.ColorMatrix
|
||||||
import android.graphics.ColorMatrixColorFilter
|
import android.graphics.ColorMatrixColorFilter
|
||||||
|
@ -38,10 +39,17 @@ fun ImageView.transformGrayscale(grayscale: Boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Taken from https://stackoverflow.com/a/50743764/12787264
|
// Taken from https://stackoverflow.com/a/50743764
|
||||||
fun View.openSoftKeyboard(context: Context) {
|
fun View.openSoftKeyboard(context: Context) {
|
||||||
this.requestFocus()
|
this.requestFocus()
|
||||||
// open the soft keyboard
|
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
|
||||||
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/17789187
|
||||||
|
fun closeSoftKeyboard(activity: Activity) {
|
||||||
|
activity.currentFocus?.let { focus ->
|
||||||
|
(activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||||
|
.hideSoftInputFromWindow( focus.windowToken, 0 )
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,13 +11,16 @@ import android.widget.Toast
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.apps.AppFilter
|
import de.jrpie.android.launcher.apps.AppFilter
|
||||||
import de.jrpie.android.launcher.databinding.ListAppsBinding
|
import de.jrpie.android.launcher.databinding.ListAppsBinding
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
import de.jrpie.android.launcher.ui.UIObject
|
import de.jrpie.android.launcher.ui.UIObject
|
||||||
|
import de.jrpie.android.launcher.ui.closeSoftKeyboard
|
||||||
import de.jrpie.android.launcher.ui.list.ListActivity
|
import de.jrpie.android.launcher.ui.list.ListActivity
|
||||||
import de.jrpie.android.launcher.ui.openSoftKeyboard
|
import de.jrpie.android.launcher.ui.openSoftKeyboard
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,6 +93,20 @@ class ListFragmentApps : Fragment(), UIObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adapter = appsRecyclerAdapter
|
adapter = appsRecyclerAdapter
|
||||||
|
if (LauncherPreferences.functionality().searchAutoCloseKeyboard()) {
|
||||||
|
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
|
var totalDy: Int = 0
|
||||||
|
var threshold = (resources.displayMetrics.density * 100).toInt()
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
totalDy += dy
|
||||||
|
|
||||||
|
if (totalDy.absoluteValue > 100) {
|
||||||
|
totalDy = 0
|
||||||
|
closeSoftKeyboard(requireActivity())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.listAppsSearchview.setOnQueryTextListener(object :
|
binding.listAppsSearchview.setOnQueryTextListener(object :
|
||||||
|
|
|
@ -147,6 +147,7 @@
|
||||||
<string name="settings_functionality_search_auto_launch_key" translatable="false">functionality.search_auto_launch</string>
|
<string name="settings_functionality_search_auto_launch_key" translatable="false">functionality.search_auto_launch</string>
|
||||||
<string name="settings_functionality_search_web_key" translatable="false">functionality.search_web</string>
|
<string name="settings_functionality_search_web_key" translatable="false">functionality.search_web</string>
|
||||||
<string name="settings_functionality_search_auto_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string>
|
<string name="settings_functionality_search_auto_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string>
|
||||||
|
<string name="settings_functionality_search_auto_close_keyboard_key" translatable="false">functionality.search_auto_close_keyboard</string>
|
||||||
|
|
||||||
|
|
||||||
<string name="settings_actions_lock_method_key" translatable="false">settings_action_lock_method</string>
|
<string name="settings_actions_lock_method_key" translatable="false">settings_action_lock_method</string>
|
||||||
|
|
|
@ -167,6 +167,7 @@
|
||||||
<string name="settings_functionality_search_web">Search the web</string>
|
<string name="settings_functionality_search_web">Search the web</string>
|
||||||
<string name="settings_functionality_search_web_summary">Press return while searching the app list to launch a web search.</string>
|
<string name="settings_functionality_search_web_summary">Press return while searching the app list to launch a web search.</string>
|
||||||
<string name="settings_functionality_auto_keyboard">Start keyboard for search</string>
|
<string name="settings_functionality_auto_keyboard">Start keyboard for search</string>
|
||||||
|
<string name="settings_functionality_auto_close_keyboard">Close keyboard when scrolling</string>
|
||||||
|
|
||||||
<string name="settings_launcher_sensitivity">Sensitivity</string>
|
<string name="settings_launcher_sensitivity">Sensitivity</string>
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,10 @@
|
||||||
android:key="@string/settings_functionality_search_auto_open_keyboard_key"
|
android:key="@string/settings_functionality_search_auto_open_keyboard_key"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:title="@string/settings_functionality_auto_keyboard" />
|
android:title="@string/settings_functionality_auto_keyboard" />
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="@string/settings_functionality_search_auto_close_keyboard_key"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:title="@string/settings_functionality_auto_close_keyboard" />
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="@string/settings_enabled_gestures_double_swipe_key"
|
android:key="@string/settings_enabled_gestures_double_swipe_key"
|
||||||
android:summary="@string/settings_enabled_gestures_double_swipe_summary"
|
android:summary="@string/settings_enabled_gestures_double_swipe_summary"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue