mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-23 14:27:21 +02:00
launch widget Configure activity when appropriate
This commit is contained in:
parent
7b52bf2b30
commit
e76b2dcc51
@ -419,7 +419,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
try {
|
try {
|
||||||
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
|
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
|
||||||
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
|
||||||
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, 1, 1, defaultDialerPackage, title, ITEM_TYPE_ICON, null)
|
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, 1, 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", null)
|
||||||
homeScreenGridItems.add(dialerIcon)
|
homeScreenGridItems.add(dialerIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -429,7 +429,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
|
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
|
||||||
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
|
||||||
val SMSMessengerIcon =
|
val SMSMessengerIcon =
|
||||||
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, 1, 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, null)
|
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, 1, 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", null)
|
||||||
homeScreenGridItems.add(SMSMessengerIcon)
|
homeScreenGridItems.add(SMSMessengerIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -440,7 +440,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||||
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
||||||
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
||||||
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, 1, 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, null)
|
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, 1, 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", null)
|
||||||
homeScreenGridItems.add(browserIcon)
|
homeScreenGridItems.add(browserIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -451,7 +451,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
|
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
|
||||||
if (storePackage != null) {
|
if (storePackage != null) {
|
||||||
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
|
||||||
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, 1, 1, storePackage, title, ITEM_TYPE_ICON, null)
|
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, 1, 1, storePackage, title, ITEM_TYPE_ICON, "", null)
|
||||||
homeScreenGridItems.add(storeIcon)
|
homeScreenGridItems.add(storeIcon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,7 +463,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||||
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
|
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
|
||||||
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
|
||||||
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, 1, 1, defaultCameraPackage, title, ITEM_TYPE_ICON, null)
|
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, 1, 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", null)
|
||||||
homeScreenGridItems.add(cameraIcon)
|
homeScreenGridItems.add(cameraIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -136,7 +136,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, -1, 1, 1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, appLauncher.drawable)
|
val gridItem = HomeScreenGridItem(null, -1, -1, -1, -1, 1, 1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", appLauncher.drawable)
|
||||||
activity?.showHomeIconMenu(x, y, gridItem, true)
|
activity?.showHomeIconMenu(x, y, gridItem, true)
|
||||||
ignoreTouches = true
|
ignoreTouches = true
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon
|
val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon
|
||||||
val widthCells = Math.min(COLUMN_COUNT, getTileCount(info.minWidth))
|
val widthCells = Math.min(COLUMN_COUNT, getTileCount(info.minWidth))
|
||||||
val heightCells = Math.min(ROW_COUNT, getTileCount(info.minHeight))
|
val heightCells = Math.min(ROW_COUNT, getTileCount(info.minHeight))
|
||||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false)
|
val widget =
|
||||||
|
AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, info.provider.shortClassName)
|
||||||
appWidgets.add(widget)
|
appWidgets.add(widget)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
val appIcon = appMetadata.appIcon
|
val appIcon = appMetadata.appIcon
|
||||||
val widgetTitle = info.loadLabel(packageManager).toString()
|
val widgetTitle = info.loadLabel(packageManager).toString()
|
||||||
val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo)
|
val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo)
|
||||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true)
|
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true, "")
|
||||||
appWidgets.add(widget)
|
appWidgets.add(widget)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +232,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
appWidget.appPackageName,
|
appWidget.appPackageName,
|
||||||
"",
|
"",
|
||||||
ITEM_TYPE_WIDGET,
|
ITEM_TYPE_WIDGET,
|
||||||
|
appWidget.shortClassName,
|
||||||
appWidget.widgetPreviewImage
|
appWidget.widgetPreviewImage
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ const val ROW_COUNT = 6
|
|||||||
const val COLUMN_COUNT = 5
|
const val COLUMN_COUNT = 5
|
||||||
|
|
||||||
const val UNINSTALL_APP_REQUEST_CODE = 50
|
const val UNINSTALL_APP_REQUEST_CODE = 50
|
||||||
|
const val REQUEST_CONFIGURE_WIDGET = 51
|
||||||
|
|
||||||
const val ITEM_TYPE_ICON = 0
|
const val ITEM_TYPE_ICON = 0
|
||||||
const val ITEM_TYPE_WIDGET = 1
|
const val ITEM_TYPE_WIDGET = 1
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.simplemobiletools.launcher.helpers
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetHost
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
class MyAppWidgetHost(context: Context, hostId: Int) : AppWidgetHost(context, hostId)
|
@ -10,7 +10,8 @@ data class AppWidget(
|
|||||||
val widgetPreviewImage: Drawable?,
|
val widgetPreviewImage: Drawable?,
|
||||||
var widthCells: Int,
|
var widthCells: Int,
|
||||||
val heightCells: Int,
|
val heightCells: Int,
|
||||||
val isShortcut: Boolean
|
val isShortcut: Boolean,
|
||||||
|
val shortClassName: String // identifier to know which app widget are we using
|
||||||
) : WidgetsListItem() {
|
) : WidgetsListItem() {
|
||||||
override fun getHashToCompare() = getStringToCompare().hashCode()
|
override fun getHashToCompare() = getStringToCompare().hashCode()
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ data class HomeScreenGridItem(
|
|||||||
@ColumnInfo(name = "package_name") var packageName: String,
|
@ColumnInfo(name = "package_name") var packageName: String,
|
||||||
@ColumnInfo(name = "title") var title: String,
|
@ColumnInfo(name = "title") var title: String,
|
||||||
@ColumnInfo(name = "type") var type: Int,
|
@ColumnInfo(name = "type") var type: Int,
|
||||||
|
@ColumnInfo(name = "short_class_name") var shortClassName: String,
|
||||||
|
|
||||||
@Ignore var drawable: Drawable?
|
@Ignore var drawable: Drawable?
|
||||||
) {
|
) {
|
||||||
constructor() : this(null, -1, -1, -1, -1, 1, 1, "", "", ITEM_TYPE_ICON, null)
|
constructor() : this(null, -1, -1, -1, -1, 1, 1, "", "", ITEM_TYPE_ICON, "", null)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.launcher.views
|
package com.simplemobiletools.launcher.views
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@ -17,12 +18,10 @@ import com.simplemobiletools.commons.extensions.performHapticFeedback
|
|||||||
import com.simplemobiletools.commons.extensions.statusBarHeight
|
import com.simplemobiletools.commons.extensions.statusBarHeight
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
|
import com.simplemobiletools.launcher.activities.MainActivity
|
||||||
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
||||||
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
||||||
import com.simplemobiletools.launcher.helpers.COLUMN_COUNT
|
import com.simplemobiletools.launcher.helpers.*
|
||||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
|
||||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET
|
|
||||||
import com.simplemobiletools.launcher.helpers.ROW_COUNT
|
|
||||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||||
|
|
||||||
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||||
@ -179,6 +178,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
draggedItem!!.packageName,
|
draggedItem!!.packageName,
|
||||||
draggedItem!!.title,
|
draggedItem!!.title,
|
||||||
draggedItem!!.type,
|
draggedItem!!.type,
|
||||||
|
"",
|
||||||
draggedItem!!.drawable
|
draggedItem!!.drawable
|
||||||
)
|
)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
@ -231,7 +231,19 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (areAllCellsEmpty) {
|
if (areAllCellsEmpty) {
|
||||||
|
val infoList = AppWidgetManager.getInstance(context).installedProviders
|
||||||
|
val appWidgetProviderInfo = infoList.firstOrNull { it.provider.shortClassName == draggedItem?.shortClassName }
|
||||||
|
if (appWidgetProviderInfo != null) {
|
||||||
|
val appWidgetHost = MyAppWidgetHost(context, 12345)
|
||||||
|
val appWidgetId = appWidgetHost.allocateAppWidgetId()
|
||||||
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
|
val canCreateWidget = appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, appWidgetProviderInfo.provider)
|
||||||
|
if (canCreateWidget) {
|
||||||
|
if (appWidgetProviderInfo.configure != null) {
|
||||||
|
appWidgetHost.startAppWidgetConfigureActivityForResult(context as MainActivity, appWidgetId, 0, REQUEST_CONFIGURE_WIDGET, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
performHapticFeedback()
|
performHapticFeedback()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user