Remove obsolete API level checks
This commit is contained in:
parent
05680afcd5
commit
97ba10d3a7
@ -3,7 +3,6 @@ package de.mm20.launcher2.activity;
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.LauncherApps
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import de.mm20.launcher2.favorites.FavoritesRepository
|
||||
import de.mm20.launcher2.search.data.AppShortcut
|
||||
@ -15,18 +14,16 @@ class AddItemActivity : Activity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
val pinRequest = launcherApps.getPinItemRequest(intent) ?: return run { finish() }
|
||||
val shortcutInfo = pinRequest.shortcutInfo ?: return run { finish() }
|
||||
val shortcut = AppShortcut(
|
||||
this.applicationContext, shortcutInfo,
|
||||
packageManager.getApplicationInfo(shortcutInfo.`package`, 0)
|
||||
.loadLabel(packageManager).toString()
|
||||
)
|
||||
if (pinRequest.accept()) {
|
||||
favoritesRepository.pinItem(shortcut)
|
||||
}
|
||||
val launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
val pinRequest = launcherApps.getPinItemRequest(intent) ?: return run { finish() }
|
||||
val shortcutInfo = pinRequest.shortcutInfo ?: return run { finish() }
|
||||
val shortcut = AppShortcut(
|
||||
this.applicationContext, shortcutInfo,
|
||||
packageManager.getApplicationInfo(shortcutInfo.`package`, 0)
|
||||
.loadLabel(packageManager).toString()
|
||||
)
|
||||
if (pinRequest.accept()) {
|
||||
favoritesRepository.pinItem(shortcut)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
||||
@ -96,11 +96,6 @@ class PreferencesAppearanceFragment : PreferenceFragmentCompat() {
|
||||
.show()
|
||||
true
|
||||
}
|
||||
|
||||
val systemBarsCategory = findPreference<PreferenceCategory>("system_bars")!!
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
systemBarsCategory.removePreference(findPreference("light_nav_bar"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -40,11 +40,7 @@ internal class AppRepositoryImpl(
|
||||
|
||||
|
||||
private val profiles: List<UserHandle> =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
launcherApps.profiles.takeIf { it.isNotEmpty() } ?: listOf(Process.myUserHandle())
|
||||
} else {
|
||||
listOf(Process.myUserHandle())
|
||||
}
|
||||
launcherApps.profiles.takeIf { it.isNotEmpty() } ?: listOf(Process.myUserHandle())
|
||||
|
||||
|
||||
private val installingPackages = mutableMapOf<Int, String>()
|
||||
|
||||
@ -48,7 +48,6 @@ class LauncherAppDeserializer(val context: Context) : SearchableDeserializer {
|
||||
}
|
||||
|
||||
class AppShortcutSerializer : SearchableSerializer {
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
override fun serialize(searchable: Searchable): String {
|
||||
searchable as AppShortcut
|
||||
return jsonObjectOf(
|
||||
@ -67,7 +66,6 @@ class AppShortcutDeserializer(
|
||||
val context: Context
|
||||
) : SearchableDeserializer, KoinComponent {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
override fun deserialize(serialized: String): Searchable? {
|
||||
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
if (!launcherApps.hasShortcutHostPermission()) return null
|
||||
|
||||
@ -22,7 +22,6 @@ import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
class AppShortcut(
|
||||
context: Context,
|
||||
val launcherShortcut: ShortcutInfo,
|
||||
@ -78,7 +77,7 @@ class AppShortcut(
|
||||
context.resources.displayMetrics.densityDpi
|
||||
)
|
||||
} ?: return null
|
||||
if (isAtLeastApiLevel(Build.VERSION_CODES.O) && icon is AdaptiveIconDrawable) {
|
||||
if (icon is AdaptiveIconDrawable) {
|
||||
return LauncherIcon(
|
||||
foreground = icon.foreground,
|
||||
background = icon.background,
|
||||
|
||||
@ -8,15 +8,12 @@ import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.graphics.drawable.AdaptiveIconDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Process
|
||||
import android.os.UserHandle
|
||||
import androidx.core.content.getSystemService
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.getSerialNumber
|
||||
import de.mm20.launcher2.preferences.LauncherPreferences
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -36,26 +33,24 @@ class LauncherApp(
|
||||
version = getPackageVersionName(context, launcherActivityInfo.applicationInfo.packageName),
|
||||
shortcuts = run {
|
||||
val appShortcuts = mutableListOf<AppShortcut>()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
val launcherApps = context.getSystemService<LauncherApps>()!!
|
||||
if (!launcherApps.hasShortcutHostPermission()) return@run appShortcuts
|
||||
val query = LauncherApps.ShortcutQuery()
|
||||
.setPackage(launcherActivityInfo.applicationInfo.packageName)
|
||||
.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC or LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST)
|
||||
val shortcuts = try {
|
||||
launcherApps.getShortcuts(query, launcherActivityInfo.user)
|
||||
} catch (e: IllegalStateException) {
|
||||
emptyList<ShortcutInfo>()
|
||||
}
|
||||
appShortcuts.addAll(shortcuts?.map {
|
||||
AppShortcut(
|
||||
context,
|
||||
it,
|
||||
launcherActivityInfo.label.toString()
|
||||
)
|
||||
}
|
||||
?: emptyList())
|
||||
val launcherApps = context.getSystemService<LauncherApps>()!!
|
||||
if (!launcherApps.hasShortcutHostPermission()) return@run appShortcuts
|
||||
val query = LauncherApps.ShortcutQuery()
|
||||
.setPackage(launcherActivityInfo.applicationInfo.packageName)
|
||||
.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC or LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST)
|
||||
val shortcuts = try {
|
||||
launcherApps.getShortcuts(query, launcherActivityInfo.user)
|
||||
} catch (e: IllegalStateException) {
|
||||
emptyList<ShortcutInfo>()
|
||||
}
|
||||
appShortcuts.addAll(shortcuts?.map {
|
||||
AppShortcut(
|
||||
context,
|
||||
it,
|
||||
launcherActivityInfo.label.toString()
|
||||
)
|
||||
}
|
||||
?: emptyList())
|
||||
appShortcuts
|
||||
}
|
||||
), KoinComponent {
|
||||
@ -73,7 +68,11 @@ class LauncherApp(
|
||||
return launcherActivityInfo.user
|
||||
}
|
||||
|
||||
override suspend fun loadIcon(context: Context, size: Int, legacyIconBackground: LegacyIconBackground): LauncherIcon? {
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
legacyIconBackground: LegacyIconBackground
|
||||
): LauncherIcon? {
|
||||
try {
|
||||
val icon =
|
||||
withContext(Dispatchers.IO) {
|
||||
|
||||
@ -17,7 +17,7 @@ class BadgeDrawable(context: Context, drawable: Drawable) : Drawable() {
|
||||
|
||||
init {
|
||||
val size = (28.8 * context.dp).roundToInt()
|
||||
val drw: Drawable = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable is AdaptiveIconDrawable) {
|
||||
val drw: Drawable = if (drawable is AdaptiveIconDrawable) {
|
||||
LayerDrawable(arrayOf(
|
||||
drawable.background,
|
||||
drawable.foreground
|
||||
|
||||
@ -124,13 +124,11 @@ public class CrashUtil {
|
||||
}
|
||||
|
||||
private static void createNotificationChannel(NotificationManager notificationManager, Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
CharSequence name = context.getString(R.string.notification_crash_report_title);
|
||||
String description = "";
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_NOTIFICATION_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setDescription(description);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
CharSequence name = context.getString(R.string.notification_crash_report_title);
|
||||
String description = "";
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_NOTIFICATION_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setDescription(description);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
private static String getStackTrace(Throwable e) {
|
||||
|
||||
@ -10,7 +10,6 @@ import androidx.annotation.RequiresApi
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
class ClockDynamicLauncherIcon(
|
||||
foreground: LayerDrawable,
|
||||
background: Drawable?,
|
||||
|
||||
@ -14,7 +14,6 @@ import de.mm20.launcher2.search.data.Searchable
|
||||
|
||||
class GoogleClockIconProvider(val context: Context) : IconProvider {
|
||||
override suspend fun getIcon(searchable: Searchable, size: Int): LauncherIcon? {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return null
|
||||
if (searchable !is Application) return null
|
||||
if (searchable.`package` != "com.google.android.deskclock") return null
|
||||
val pm = context.packageManager
|
||||
|
||||
@ -48,7 +48,7 @@ class IconPackIconProvider(
|
||||
?: return generateIcon(context, searchable.launcherActivityInfo, size)
|
||||
val drawable = ResourcesCompat.getDrawable(res, resId, context.theme) ?: return null
|
||||
return when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable is AdaptiveIconDrawable -> {
|
||||
drawable is AdaptiveIconDrawable -> {
|
||||
LauncherIcon(
|
||||
foreground = drawable.foreground,
|
||||
background = drawable.background,
|
||||
|
||||
@ -81,9 +81,6 @@ class ThemedIconProvider(
|
||||
}
|
||||
|
||||
private fun getClockIcon(resources: Resources, resId: Int): LauncherIcon? {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
val array = resources.obtainTypedArrayOrNull(resId) ?: return null
|
||||
var i = 0
|
||||
|
||||
@ -33,7 +33,6 @@ object LauncherIconShape {
|
||||
}
|
||||
val platformDefault: Shape = run {
|
||||
val platformShape = getSystemShape()
|
||||
if (platformShape == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return@run CircleShape
|
||||
GenericShape { size, _ ->
|
||||
Log.d("MM20", "GenericShape {}")
|
||||
val matrix = Matrix()
|
||||
@ -45,11 +44,7 @@ object LauncherIconShape {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSystemShape(): Path? {
|
||||
return if (isAtLeastApiLevel(Build.VERSION_CODES.O)) {
|
||||
AdaptiveIconDrawable(null, null).iconMask
|
||||
} else {
|
||||
null
|
||||
}
|
||||
private fun getSystemShape(): Path {
|
||||
return AdaptiveIconDrawable(null, null).iconMask
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,6 @@ import android.graphics.drawable.LayerDrawable
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.graphics.drawable.shapes.OvalShape
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Process
|
||||
import android.service.notification.StatusBarNotification
|
||||
@ -37,8 +36,10 @@ import de.mm20.launcher2.badges.BadgeRepository
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.favorites.FavoritesRepository
|
||||
import de.mm20.launcher2.icons.IconRepository
|
||||
import de.mm20.launcher2.ktx.*
|
||||
import de.mm20.launcher2.ui.legacy.helper.ActivityStarter
|
||||
import de.mm20.launcher2.ktx.castToOrNull
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.ktx.getBadgeIcon
|
||||
import de.mm20.launcher2.ktx.lifecycleOwner
|
||||
import de.mm20.launcher2.notifications.NotificationRepository
|
||||
import de.mm20.launcher2.search.data.AppInstallation
|
||||
import de.mm20.launcher2.search.data.Application
|
||||
@ -46,11 +47,13 @@ import de.mm20.launcher2.search.data.LauncherApp
|
||||
import de.mm20.launcher2.search.data.Searchable
|
||||
import de.mm20.launcher2.transition.ChangingLayoutTransition
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.legacy.helper.ActivityStarter
|
||||
import de.mm20.launcher2.ui.legacy.searchable.SearchableView
|
||||
import de.mm20.launcher2.ui.legacy.view.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.util.concurrent.Executors
|
||||
@ -176,7 +179,10 @@ class ApplicationDetailRepresentation : Representation, KoinComponent {
|
||||
return scene
|
||||
}
|
||||
|
||||
private fun updateNotifications(chipGroup: ChipGroup, notifications: List<StatusBarNotification>) {
|
||||
private fun updateNotifications(
|
||||
chipGroup: ChipGroup,
|
||||
notifications: List<StatusBarNotification>
|
||||
) {
|
||||
val context = chipGroup.context
|
||||
chipGroup.removeAllViews()
|
||||
notifications.forEach {
|
||||
@ -299,69 +305,67 @@ class ApplicationDetailRepresentation : Representation, KoinComponent {
|
||||
|
||||
private fun setupShortcuts(appShortcuts: ChipGroup, app: Application) {
|
||||
val context = appShortcuts.context
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
val launcherApps =
|
||||
context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
if (launcherApps.hasShortcutHostPermission()) {
|
||||
val shortcuts = app.shortcuts
|
||||
val launcherApps =
|
||||
context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
if (launcherApps.hasShortcutHostPermission()) {
|
||||
val shortcuts = app.shortcuts
|
||||
|
||||
val repository: FavoritesRepository by inject()
|
||||
val repository: FavoritesRepository by inject()
|
||||
|
||||
var count = 0
|
||||
for (si in shortcuts) {
|
||||
if (count > 4) break
|
||||
count++
|
||||
val view = Chip(context)
|
||||
view.text = si.label
|
||||
var count = 0
|
||||
for (si in shortcuts) {
|
||||
if (count > 4) break
|
||||
count++
|
||||
val view = Chip(context)
|
||||
view.text = si.label
|
||||
|
||||
view.chipIcon = createShortcutDrawable(
|
||||
launcherApps.getShortcutBadgedIconDrawable(
|
||||
si.launcherShortcut,
|
||||
context.resources.displayMetrics.densityDpi
|
||||
)
|
||||
view.chipIcon = createShortcutDrawable(
|
||||
launcherApps.getShortcutBadgedIconDrawable(
|
||||
si.launcherShortcut,
|
||||
context.resources.displayMetrics.densityDpi
|
||||
)
|
||||
)
|
||||
|
||||
view.chipIconSize = 24 * context.dp
|
||||
view.chipIconSize = 24 * context.dp
|
||||
|
||||
view.chipIconTint = null
|
||||
view.chipIconTint = null
|
||||
|
||||
view.chipStrokeWidth = 1 * context.dp
|
||||
view.chipStrokeColor =
|
||||
ContextCompat.getColorStateList(context, R.color.chip_stroke)
|
||||
view.chipBackgroundColor =
|
||||
ContextCompat.getColorStateList(context, R.color.chip_background)
|
||||
view.setTextAppearanceResource(R.style.ChipTextAppearance)
|
||||
view.closeIcon = context.getDrawable(R.drawable.ic_star_solid)
|
||||
view.closeIconTint = ColorStateList.valueOf(
|
||||
ContextCompat.getColor(
|
||||
context,
|
||||
R.color.text_color_primary
|
||||
)
|
||||
view.chipStrokeWidth = 1 * context.dp
|
||||
view.chipStrokeColor =
|
||||
ContextCompat.getColorStateList(context, R.color.chip_stroke)
|
||||
view.chipBackgroundColor =
|
||||
ContextCompat.getColorStateList(context, R.color.chip_background)
|
||||
view.setTextAppearanceResource(R.style.ChipTextAppearance)
|
||||
view.closeIcon = context.getDrawable(R.drawable.ic_star_solid)
|
||||
view.closeIconTint = ColorStateList.valueOf(
|
||||
ContextCompat.getColor(
|
||||
context,
|
||||
R.color.text_color_primary
|
||||
)
|
||||
val isPinned = repository.isPinned(si).asLiveData()
|
||||
)
|
||||
val isPinned = repository.isPinned(si).asLiveData()
|
||||
|
||||
isPinned.observe(context as LifecycleOwner, Observer {
|
||||
view.isCloseIconVisible = isPinned.value == true
|
||||
})
|
||||
isPinned.observe(context as LifecycleOwner, Observer {
|
||||
view.isCloseIconVisible = isPinned.value == true
|
||||
})
|
||||
|
||||
view.setOnClickListener {
|
||||
ActivityStarter.start(context, view)
|
||||
launcherApps.startShortcut(si.launcherShortcut, null, null)
|
||||
}
|
||||
view.setOnLongClickListener {
|
||||
if (isPinned.value == true) {
|
||||
repository.unpinItem(si)
|
||||
} else {
|
||||
repository.pinItem(si)
|
||||
}
|
||||
true
|
||||
}
|
||||
view.setOnCloseIconClickListener {
|
||||
repository.unpinItem(si)
|
||||
view.isCloseIconVisible = false
|
||||
}
|
||||
appShortcuts.addView(view)
|
||||
view.setOnClickListener {
|
||||
ActivityStarter.start(context, view)
|
||||
launcherApps.startShortcut(si.launcherShortcut, null, null)
|
||||
}
|
||||
view.setOnLongClickListener {
|
||||
if (isPinned.value == true) {
|
||||
repository.unpinItem(si)
|
||||
} else {
|
||||
repository.pinItem(si)
|
||||
}
|
||||
true
|
||||
}
|
||||
view.setOnCloseIconClickListener {
|
||||
repository.unpinItem(si)
|
||||
view.isCloseIconVisible = false
|
||||
}
|
||||
appShortcuts.addView(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
class AppShortcutDetailRepresentation : Representation, KoinComponent {
|
||||
|
||||
private val iconRepository: IconRepository by inject()
|
||||
|
||||
@ -101,11 +101,7 @@ open class SearchableView(context: Context, representation: Int) : FrameLayout(c
|
||||
is Contact -> ContactDetailRepresentation()
|
||||
is CalendarEvent -> CalendarDetailRepresentation()
|
||||
is Wikipedia -> WikipediaDetailRepresentation()
|
||||
is AppShortcut -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
AppShortcutDetailRepresentation()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
is AppShortcut -> AppShortcutDetailRepresentation()
|
||||
else -> return
|
||||
}
|
||||
applyScene(representation.getScene(this, searchable, previousRepresentation))
|
||||
|
||||
@ -59,7 +59,6 @@ class LauncherIconView : View, KoinComponent {
|
||||
private var platformShapeBounds: RectF? = null
|
||||
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun getSystemShape(): Path {
|
||||
return AdaptiveIconDrawable(null, null).iconMask
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user