mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-16 19:40:41 +01:00
use flat top fragment backgrounds until screen corners can be detected reliably
This commit is contained in:
parent
6c5c0b34da
commit
a1742ff5aa
@ -151,8 +151,12 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateStatusbarColor(Color.TRANSPARENT)
|
||||
(all_apps_fragment as AllAppsFragment).setupViews()
|
||||
(widgets_fragment as WidgetsFragment).setupViews()
|
||||
|
||||
main_holder.onGlobalLayout {
|
||||
val addTopPadding = main_holder.rootWindowInsets.displayCutout != null
|
||||
(all_apps_fragment as AllAppsFragment).setupViews(addTopPadding)
|
||||
(widgets_fragment as WidgetsFragment).setupViews(addTopPadding)
|
||||
}
|
||||
|
||||
ensureBackgroundThread {
|
||||
if (mCachedLaunchers.isEmpty()) {
|
||||
@ -162,11 +166,6 @@ 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() {
|
||||
@ -298,20 +297,6 @@ 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,7 +2,7 @@ package com.simplemobiletools.launcher.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
@ -25,11 +25,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
private var lastTouchCoords = Pair(0f, 0f)
|
||||
var touchDownY = -1
|
||||
var ignoreTouches = false
|
||||
var hasTopPadding = false
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
|
||||
all_apps_grid.setOnTouchListener { v, event ->
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||
@ -104,7 +104,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
}
|
||||
}
|
||||
|
||||
fun setupViews() {
|
||||
fun setupViews(addTopPadding: Boolean = hasTopPadding) {
|
||||
if (activity == null) {
|
||||
return
|
||||
}
|
||||
@ -137,12 +137,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
|
||||
all_apps_grid.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding)
|
||||
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
|
||||
}
|
||||
|
||||
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
|
||||
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
|
||||
hasTopPadding = addTopPadding
|
||||
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
|
||||
setPadding(0, topPadding, 0, 0)
|
||||
setBackgroundDrawable(backgroundDrawable)
|
||||
background = ColorDrawable(context.getProperBackgroundColor())
|
||||
}
|
||||
|
||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||
|
@ -6,7 +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.graphics.drawable.ColorDrawable
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
@ -28,11 +28,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
private var lastTouchCoords = Pair(0f, 0f)
|
||||
var touchDownY = -1
|
||||
var ignoreTouches = false
|
||||
var hasTopPadding = false
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
getAppWidgets()
|
||||
|
||||
widgets_list.setOnTouchListener { v, event ->
|
||||
@ -164,7 +164,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
}
|
||||
}
|
||||
|
||||
fun setupViews() {
|
||||
fun setupViews(addTopPadding: Boolean = hasTopPadding) {
|
||||
if (activity == null) {
|
||||
return
|
||||
}
|
||||
@ -197,12 +197,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
|
||||
widgets_list.setPadding(0, 0, 0, bottomListPadding)
|
||||
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
|
||||
}
|
||||
|
||||
fun setupBackground(backgroundDrawable: Drawable, removeRoundedCorners: Boolean) {
|
||||
val topPadding = if (removeRoundedCorners) 0 else activity!!.statusBarHeight
|
||||
hasTopPadding = addTopPadding
|
||||
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
|
||||
setPadding(0, topPadding, 0, 0)
|
||||
setBackgroundDrawable(backgroundDrawable)
|
||||
background = ColorDrawable(context.getProperBackgroundColor())
|
||||
}
|
||||
|
||||
private fun getAppMetadataFromPackage(packageName: String): WidgetsListSection? {
|
||||
|
@ -1,8 +1,5 @@
|
||||
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
|
||||
|
||||
@ -25,8 +22,3 @@ 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
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?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,10 +0,0 @@
|
||||
<?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">
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/material_button_corner_radius"
|
||||
android:topRightRadius="@dimen/material_button_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
@ -3,8 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/all_apps_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/fragment_background_rounded_corners">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
android:id="@+id/all_apps_fastscroller"
|
||||
|
@ -3,8 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/widgets_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/fragment_background_rounded_corners">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
android:id="@+id/widgets_fastscroller"
|
||||
|
Loading…
x
Reference in New Issue
Block a user