parent
6e9d8686bf
commit
d50d5702ba
|
@ -13,6 +13,7 @@ import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.pm.LauncherApps
|
import android.content.pm.LauncherApps
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.pm.ShortcutInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
@ -235,8 +236,8 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
val item = launcherApps.getPinItemRequest(resultData)
|
val item = launcherApps.getPinItemRequest(resultData)
|
||||||
item.accept()
|
item.accept()
|
||||||
val shortcutId = item.shortcutInfo?.id!!
|
val shortcutId = item.shortcutInfo?.id!!
|
||||||
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
|
val label = item.shortcutInfo.getLabel()
|
||||||
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
||||||
mActionOnAddShortcut?.invoke(shortcutId, label, icon)
|
mActionOnAddShortcut?.invoke(shortcutId, label, icon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,8 +364,8 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val shortcutId = item.shortcutInfo?.id!!
|
val shortcutId = item.shortcutInfo?.id!!
|
||||||
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
|
val label = item.shortcutInfo.getLabel()
|
||||||
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
||||||
val (page, rect) = findFirstEmptyCell()
|
val (page, rect) = findFirstEmptyCell()
|
||||||
val gridItem = HomeScreenGridItem(
|
val gridItem = HomeScreenGridItem(
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -126,7 +126,7 @@ fun Activity.handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridI
|
||||||
if (hasShortcuts) {
|
if (hasShortcuts) {
|
||||||
val iconSize = resources.getDimensionPixelSize(R.dimen.menu_icon_size)
|
val iconSize = resources.getDimensionPixelSize(R.dimen.menu_icon_size)
|
||||||
shortcuts?.forEach {
|
shortcuts?.forEach {
|
||||||
menu.add(R.id.group_shortcuts, Menu.NONE, Menu.NONE, it.longLabel)
|
menu.add(R.id.group_shortcuts, Menu.NONE, Menu.NONE, it.getLabel())
|
||||||
.setIcon(
|
.setIcon(
|
||||||
launcherApps.getShortcutIconDrawable(it, resources.displayMetrics.densityDpi).toBitmap(width = iconSize, height = iconSize)
|
launcherApps.getShortcutIconDrawable(it, resources.displayMetrics.densityDpi).toBitmap(width = iconSize, height = iconSize)
|
||||||
.toDrawable(resources)
|
.toDrawable(resources)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.simplemobiletools.launcher.extensions
|
||||||
|
|
||||||
|
import android.content.pm.ShortcutInfo
|
||||||
|
|
||||||
|
fun ShortcutInfo?.getLabel() = this?.longLabel?.toString().ifNullOrEmpty { this?.shortLabel?.toString() } ?: ""
|
||||||
|
|
||||||
|
private fun String?.ifNullOrEmpty(block: () -> String?) = this?.ifEmpty { block() } ?: block()
|
Loading…
Reference in New Issue