Skip to content

Commit 6c5c0b3

Browse files
committed
improve the handling of top notches
1 parent f89d9a4 commit 6c5c0b3

File tree

8 files changed

+51
-5
lines changed

8 files changed

+51
-5
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ class MainActivity : SimpleActivity(), FlingListener {
162162

163163
refetchLaunchers()
164164
}
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+
}
165170
}
166171

167172
override fun onStart() {
@@ -293,6 +298,20 @@ class MainActivity : SimpleActivity(), FlingListener {
293298
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
294299
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
295300

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+
296315
private fun refetchLaunchers() {
297316
val launchers = getAllAppLaunchers()
298317
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)

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

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

33
import android.annotation.SuppressLint
44
import android.content.Context
5+
import android.graphics.drawable.Drawable
56
import android.util.AttributeSet
67
import android.view.MotionEvent
78
import android.view.Surface
@@ -29,7 +30,6 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
2930
override fun setupFragment(activity: MainActivity) {
3031
this.activity = activity
3132
background.applyColorFilter(activity.getProperBackgroundColor())
32-
setPadding(0, activity.statusBarHeight, 0, 0)
3333

3434
all_apps_grid.setOnTouchListener { v, event ->
3535
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
@@ -139,6 +139,12 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
139139
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
140140
}
141141

142+
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
143+
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
144+
setPadding(0, topPadding, 0, 0)
145+
setBackgroundDrawable(backgroundDrawable)
146+
}
147+
142148
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
143149
val gridItem =
144150
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, "", "", null, appLauncher.drawable)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +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
910
import android.os.Process
1011
import android.util.AttributeSet
1112
import android.view.MotionEvent
@@ -28,10 +29,10 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
2829
var touchDownY = -1
2930
var ignoreTouches = false
3031

32+
@SuppressLint("ClickableViewAccessibility")
3133
override fun setupFragment(activity: MainActivity) {
3234
this.activity = activity
3335
background.applyColorFilter(activity.getProperBackgroundColor())
34-
setPadding(0, activity.statusBarHeight, 0, 0)
3536
getAppWidgets()
3637

3738
widgets_list.setOnTouchListener { v, event ->
@@ -198,6 +199,12 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
198199
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
199200
}
200201

202+
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
203+
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
204+
setPadding(0, topPadding, 0, 0)
205+
setBackgroundDrawable(backgroundDrawable)
206+
}
207+
201208
private fun getAppMetadataFromPackage(packageName: String): WidgetsListSection? {
202209
try {
203210
val appInfo = activity!!.packageManager.getApplicationInfo(packageName, 0)

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

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

3+
import android.view.View
4+
import com.simplemobiletools.commons.helpers.isSPlus
5+
36
const val WIDGET_LIST_SECTION = 0
47
const val WIDGET_LIST_ITEMS_HOLDER = 1
58

@@ -22,3 +25,8 @@ const val ITEM_TYPE_SHORTCUT = 2
2225
const val WIDGET_HOST_ID = 12345
2326
const val MAX_ALLOWED_MOVE_PX = 10
2427
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/fragment_background">
4+
<shape android:shape="rectangle" />
5+
</item>
6+
</layer-list>

app/src/main/res/drawable/all_apps_background.xml renamed to app/src/main/res/drawable/fragment_background_rounded_corners.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3-
<item android:id="@+id/bottom_sheet_background">
3+
<item android:id="@+id/fragment_background">
44
<shape android:shape="rectangle">
55
<corners
66
android:topLeftRadius="@dimen/material_button_corner_radius"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:id="@+id/all_apps_holder"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
android:background="@drawable/all_apps_background">
7+
android:background="@drawable/fragment_background_rounded_corners">
88

99
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
1010
android:id="@+id/all_apps_fastscroller"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:id="@+id/widgets_holder"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
android:background="@drawable/all_apps_background">
7+
android:background="@drawable/fragment_background_rounded_corners">
88

99
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
1010
android:id="@+id/widgets_fastscroller"

0 commit comments

Comments
 (0)