Skip to content

Commit a1742ff

Browse files
committed
use flat top fragment backgrounds until screen corners can be detected reliably
1 parent 6c5c0b3 commit a1742ff

File tree

8 files changed

+20
-63
lines changed

8 files changed

+20
-63
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ class MainActivity : SimpleActivity(), FlingListener {
151151
override fun onResume() {
152152
super.onResume()
153153
updateStatusbarColor(Color.TRANSPARENT)
154-
(all_apps_fragment as AllAppsFragment).setupViews()
155-
(widgets_fragment as WidgetsFragment).setupViews()
154+
155+
main_holder.onGlobalLayout {
156+
val addTopPadding = main_holder.rootWindowInsets.displayCutout != null
157+
(all_apps_fragment as AllAppsFragment).setupViews(addTopPadding)
158+
(widgets_fragment as WidgetsFragment).setupViews(addTopPadding)
159+
}
156160

157161
ensureBackgroundThread {
158162
if (mCachedLaunchers.isEmpty()) {
@@ -162,11 +166,6 @@ class MainActivity : SimpleActivity(), FlingListener {
162166

163167
refetchLaunchers()
164168
}
165-
166-
// most devices have the top corners rounded, but in case someone has notch disabled, they might be in right angle
167-
main_holder.onGlobalLayout {
168-
setupFragmentBackgrounds()
169-
}
170169
}
171170

172171
override fun onStart() {
@@ -298,20 +297,6 @@ class MainActivity : SimpleActivity(), FlingListener {
298297
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
299298
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
300299

301-
private fun setupFragmentBackgrounds() {
302-
val removeRoundedCorners = shouldRemoveTopRoundedCorners(main_holder)
303-
val backgroundId = if (removeRoundedCorners) {
304-
R.drawable.fragment_background_flat_top
305-
} else {
306-
R.drawable.fragment_background_rounded_corners
307-
}
308-
309-
val backgroundDrawable = resources.getDrawable(backgroundId)
310-
backgroundDrawable.applyColorFilter(getProperBackgroundColor())
311-
(all_apps_fragment as AllAppsFragment).setupBackground(backgroundDrawable, removeRoundedCorners)
312-
(widgets_fragment as WidgetsFragment).setupBackground(backgroundDrawable, removeRoundedCorners)
313-
}
314-
315300
private fun refetchLaunchers() {
316301
val launchers = getAllAppLaunchers()
317302
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)

app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.simplemobiletools.launcher.fragments
22

33
import android.annotation.SuppressLint
44
import android.content.Context
5-
import android.graphics.drawable.Drawable
5+
import android.graphics.drawable.ColorDrawable
66
import android.util.AttributeSet
77
import android.view.MotionEvent
88
import android.view.Surface
@@ -25,11 +25,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
2525
private var lastTouchCoords = Pair(0f, 0f)
2626
var touchDownY = -1
2727
var ignoreTouches = false
28+
var hasTopPadding = false
2829

2930
@SuppressLint("ClickableViewAccessibility")
3031
override fun setupFragment(activity: MainActivity) {
3132
this.activity = activity
32-
background.applyColorFilter(activity.getProperBackgroundColor())
3333

3434
all_apps_grid.setOnTouchListener { v, event ->
3535
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
@@ -104,7 +104,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
104104
}
105105
}
106106

107-
fun setupViews() {
107+
fun setupViews(addTopPadding: Boolean = hasTopPadding) {
108108
if (activity == null) {
109109
return
110110
}
@@ -137,12 +137,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
137137

138138
all_apps_grid.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding)
139139
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
140-
}
141140

142-
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
143-
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
141+
hasTopPadding = addTopPadding
142+
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
144143
setPadding(0, topPadding, 0, 0)
145-
setBackgroundDrawable(backgroundDrawable)
144+
background = ColorDrawable(context.getProperBackgroundColor())
146145
}
147146

148147
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {

app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import android.content.Context
66
import android.content.Intent
77
import android.content.pm.LauncherApps
88
import android.content.pm.PackageManager
9-
import android.graphics.drawable.Drawable
9+
import android.graphics.drawable.ColorDrawable
1010
import android.os.Process
1111
import android.util.AttributeSet
1212
import android.view.MotionEvent
@@ -28,11 +28,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
2828
private var lastTouchCoords = Pair(0f, 0f)
2929
var touchDownY = -1
3030
var ignoreTouches = false
31+
var hasTopPadding = false
3132

3233
@SuppressLint("ClickableViewAccessibility")
3334
override fun setupFragment(activity: MainActivity) {
3435
this.activity = activity
35-
background.applyColorFilter(activity.getProperBackgroundColor())
3636
getAppWidgets()
3737

3838
widgets_list.setOnTouchListener { v, event ->
@@ -164,7 +164,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
164164
}
165165
}
166166

167-
fun setupViews() {
167+
fun setupViews(addTopPadding: Boolean = hasTopPadding) {
168168
if (activity == null) {
169169
return
170170
}
@@ -197,12 +197,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
197197

198198
widgets_list.setPadding(0, 0, 0, bottomListPadding)
199199
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
200-
}
201200

202-
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
203-
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
201+
hasTopPadding = addTopPadding
202+
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
204203
setPadding(0, topPadding, 0, 0)
205-
setBackgroundDrawable(backgroundDrawable)
204+
background = ColorDrawable(context.getProperBackgroundColor())
206205
}
207206

208207
private fun getAppMetadataFromPackage(packageName: String): WidgetsListSection? {

app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.simplemobiletools.launcher.helpers
22

3-
import android.view.View
4-
import com.simplemobiletools.commons.helpers.isSPlus
5-
63
const val WIDGET_LIST_SECTION = 0
74
const val WIDGET_LIST_ITEMS_HOLDER = 1
85

@@ -25,8 +22,3 @@ const val ITEM_TYPE_SHORTCUT = 2
2522
const val WIDGET_HOST_ID = 12345
2623
const val MAX_ALLOWED_MOVE_PX = 10
2724
const val MAX_CLICK_DURATION = 150
28-
29-
// remove rounded corners if the display isnt using them
30-
fun shouldRemoveTopRoundedCorners(mainView: View): Boolean {
31-
return isSPlus() && mainView.rootWindowInsets.displayCutout == null
32-
}

app/src/main/res/drawable/fragment_background_flat_top.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/res/drawable/fragment_background_rounded_corners.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/src/main/res/layout/all_apps_fragment.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:id="@+id/all_apps_holder"
55
android:layout_width="match_parent"
6-
android:layout_height="wrap_content"
7-
android:background="@drawable/fragment_background_rounded_corners">
6+
android:layout_height="wrap_content">
87

98
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
109
android:id="@+id/all_apps_fastscroller"

app/src/main/res/layout/widgets_fragment.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:id="@+id/widgets_holder"
55
android:layout_width="match_parent"
6-
android:layout_height="wrap_content"
7-
android:background="@drawable/fragment_background_rounded_corners">
6+
android:layout_height="wrap_content">
87

98
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
109
android:id="@+id/widgets_fastscroller"

0 commit comments

Comments
 (0)