improve the handling of top notches
This commit is contained in:
parent
f89d9a4493
commit
6c5c0b34da
|
@ -162,6 +162,11 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
|
||||
refetchLaunchers()
|
||||
}
|
||||
|
||||
// most devices have the top corners rounded, but in case someone has notch disabled, they might be in right angle
|
||||
main_holder.onGlobalLayout {
|
||||
setupFragmentBackgrounds()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -293,6 +298,20 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
|
||||
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
|
||||
|
||||
private fun setupFragmentBackgrounds() {
|
||||
val removeRoundedCorners = shouldRemoveTopRoundedCorners(main_holder)
|
||||
val backgroundId = if (removeRoundedCorners) {
|
||||
R.drawable.fragment_background_flat_top
|
||||
} else {
|
||||
R.drawable.fragment_background_rounded_corners
|
||||
}
|
||||
|
||||
val backgroundDrawable = resources.getDrawable(backgroundId)
|
||||
backgroundDrawable.applyColorFilter(getProperBackgroundColor())
|
||||
(all_apps_fragment as AllAppsFragment).setupBackground(backgroundDrawable, removeRoundedCorners)
|
||||
(widgets_fragment as WidgetsFragment).setupBackground(backgroundDrawable, removeRoundedCorners)
|
||||
}
|
||||
|
||||
private fun refetchLaunchers() {
|
||||
val launchers = getAllAppLaunchers()
|
||||
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.launcher.fragments
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
|
@ -29,7 +30,6 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
setPadding(0, activity.statusBarHeight, 0, 0)
|
||||
|
||||
all_apps_grid.setOnTouchListener { v, event ->
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||
|
@ -139,6 +139,12 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
|
||||
}
|
||||
|
||||
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
|
||||
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
|
||||
setPadding(0, topPadding, 0, 0)
|
||||
setBackgroundDrawable(backgroundDrawable)
|
||||
}
|
||||
|
||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||
val gridItem =
|
||||
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, "", "", null, appLauncher.drawable)
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
|
@ -28,10 +29,10 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
var touchDownY = -1
|
||||
var ignoreTouches = false
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
setPadding(0, activity.statusBarHeight, 0, 0)
|
||||
getAppWidgets()
|
||||
|
||||
widgets_list.setOnTouchListener { v, event ->
|
||||
|
@ -198,6 +199,12 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
|
||||
}
|
||||
|
||||
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
|
||||
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
|
||||
setPadding(0, topPadding, 0, 0)
|
||||
setBackgroundDrawable(backgroundDrawable)
|
||||
}
|
||||
|
||||
private fun getAppMetadataFromPackage(packageName: String): WidgetsListSection? {
|
||||
try {
|
||||
val appInfo = activity!!.packageManager.getApplicationInfo(packageName, 0)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.simplemobiletools.launcher.helpers
|
||||
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.helpers.isSPlus
|
||||
|
||||
const val WIDGET_LIST_SECTION = 0
|
||||
const val WIDGET_LIST_ITEMS_HOLDER = 1
|
||||
|
||||
|
@ -22,3 +25,8 @@ const val ITEM_TYPE_SHORTCUT = 2
|
|||
const val WIDGET_HOST_ID = 12345
|
||||
const val MAX_ALLOWED_MOVE_PX = 10
|
||||
const val MAX_CLICK_DURATION = 150
|
||||
|
||||
// remove rounded corners if the display isnt using them
|
||||
fun shouldRemoveTopRoundedCorners(mainView: View): Boolean {
|
||||
return isSPlus() && mainView.rootWindowInsets.displayCutout == null
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/fragment_background">
|
||||
<shape android:shape="rectangle" />
|
||||
</item>
|
||||
</layer-list>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/bottom_sheet_background">
|
||||
<item android:id="@+id/fragment_background">
|
||||
<shape android:shape="rectangle">
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/material_button_corner_radius"
|
|
@ -4,7 +4,7 @@
|
|||
android:id="@+id/all_apps_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/all_apps_background">
|
||||
android:background="@drawable/fragment_background_rounded_corners">
|
||||
|
||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
android:id="@+id/all_apps_fastscroller"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
android:id="@+id/widgets_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/all_apps_background">
|
||||
android:background="@drawable/fragment_background_rounded_corners">
|
||||
|
||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
android:id="@+id/widgets_fastscroller"
|
||||
|
|
Loading…
Reference in New Issue