Merge pull request #96 from esensar/feature/57-always-go-home

Add a setting for always closing drawers when using home button
This commit is contained in:
Tibor Kaputa 2023-08-02 11:39:42 +02:00 committed by GitHub
commit 6e89e55c70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 32 deletions

View file

@ -44,13 +44,19 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTop"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/LauncherTheme">
<intent-filter>
<action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
@ -97,7 +103,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -116,7 +121,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -135,7 +139,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -154,7 +157,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -173,7 +175,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -192,7 +193,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -211,7 +211,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -230,7 +229,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -249,7 +247,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -268,7 +265,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -287,7 +283,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -306,7 +301,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -325,7 +319,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -344,7 +337,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -363,7 +355,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -382,7 +373,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -401,7 +391,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -420,7 +409,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -439,7 +427,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

View file

@ -69,6 +69,7 @@ class MainActivity : SimpleActivity(), FlingListener {
private var mActionOnCanBindWidget: ((granted: Boolean) -> Unit)? = null
private var mActionOnWidgetConfiguredWidget: ((granted: Boolean) -> Unit)? = null
private var mActionOnAddShortcut: ((shortcutId: String, label: String, icon: Drawable) -> Unit)? = null
private var wasJustPaused: Boolean = false
private lateinit var mDetector: GestureDetectorCompat
@ -113,6 +114,17 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
if (wasJustPaused) {
if (isAllAppsFragmentExpanded()) {
hideFragment(all_apps_fragment)
}
if (isWidgetsFragmentExpanded()) {
hideFragment(widgets_fragment)
}
} else {
closeAppDrawer()
closeWidgetsFragment()
}
if (intent != null) {
handleIntentAction(intent)
}
@ -198,6 +210,7 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onResume() {
super.onResume()
wasJustPaused = false
updateStatusbarColor(Color.TRANSPARENT)
main_holder.onGlobalLayout {
@ -247,6 +260,12 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onStop() {
super.onStop()
home_screen_grid?.appWidgetHost?.stopListening()
wasJustPaused = false
}
override fun onPause() {
super.onPause()
wasJustPaused = true
}
override fun onBackPressed() {
@ -488,13 +507,35 @@ class MainActivity : SimpleActivity(), FlingListener {
}
}
fun closeAppDrawer() {
fun closeAppDrawer(delayed: Boolean = false) {
if (isAllAppsFragmentExpanded()) {
Handler(Looper.getMainLooper()).postDelayed({
val close = {
all_apps_fragment.y = mScreenHeight.toFloat()
all_apps_fragment.all_apps_grid.scrollToPosition(0)
(all_apps_fragment as AllAppsFragment).touchDownY = -1
home_screen_grid.fragmentCollapsed()
}, APP_DRAWER_CLOSE_DELAY)
}
if (delayed) {
Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY)
} else {
close()
}
}
}
fun closeWidgetsFragment(delayed: Boolean = false) {
if (isWidgetsFragmentExpanded()) {
val close = {
widgets_fragment.y = mScreenHeight.toFloat()
widgets_fragment.widgets_list.scrollToPosition(0)
(widgets_fragment as WidgetsFragment).touchDownY = -1
home_screen_grid.fragmentCollapsed()
}
if (delayed) {
Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY)
} else {
close()
}
}
}

View file

@ -121,7 +121,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
LaunchersAdapter(activity!!, launchers, this) {
activity?.launchApp((it as AppLauncher).packageName, it.activityName)
if (activity?.config?.closeAppDrawer == true) {
activity?.closeAppDrawer()
activity?.closeAppDrawer(delayed = true)
}
ignoreTouches = false
touchDownY = -1

View file

@ -19,4 +19,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">Tanca el calaix d\'aplicacions en obrir una aplicació</string>
<string name="home_screen_settings">Home screen</string>
<string name="widget_too_big">El giny és massa gros per a la mida de la pantalla d\'inici actual</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">App-Schublade beim Öffnen einer App schließen</string>
<string name="home_screen_settings">Startbildschirm</string>
<string name="widget_too_big">Das Widget ist zu groß für den aktuellen Startbildschirm</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">App-overzicht sluiten na het kiezen van een app</string>
<string name="home_screen_settings">Beginscherm</string>
<string name="widget_too_big">Widget is te groot voor de huidige afmetingen van het beginscherm</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">Zamykaj szufladę aplikacji przy uruchomieniu aplikacji</string>
<string name="home_screen_settings">Ekran główny</string>
<string name="widget_too_big">Widżet jest za duży dla aktualnego rozmiaru ekranu głównego</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">Закрывать боковую панель при открытии приложения</string>
<string name="home_screen_settings">Домашний экран</string>
<string name="widget_too_big">Виджет слишком велик для текущего размера домашнего экрана</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">Bir uygulama açıldığında uygulama çekmecesini kapat</string>
<string name="home_screen_settings">Ana ekran</string>
<string name="widget_too_big">Widget, şu anki ana ekran boyutu için çok büyük</string>
</resources>
</resources>

View file

@ -15,4 +15,4 @@
<string name="close_app_drawer_on_app_open">打开抽屉内应用时关闭抽屉</string>
<string name="home_screen_settings">主屏幕</string>
<string name="widget_too_big">小部件对当前屏幕尺寸而言太大了</string>
</resources>
</resources>