lets not add any extra margin to widgets
This commit is contained in:
parent
8e79a9ccf5
commit
e83aef8d9d
|
@ -16,3 +16,5 @@ 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
|
||||||
const val ITEM_TYPE_SHORTCUT = 2
|
const val ITEM_TYPE_SHORTCUT = 2
|
||||||
|
|
||||||
|
const val WIDGET_HOST_ID = 12345
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package com.simplemobiletools.launcher.helpers
|
|
||||||
|
|
||||||
import android.appwidget.AppWidgetHost
|
|
||||||
import android.content.Context
|
|
||||||
|
|
||||||
class MyAppWidgetHost(context: Context, hostId: Int) : AppWidgetHost(context, hostId)
|
|
|
@ -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.AppWidgetHost
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
|
@ -28,7 +29,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
|
||||||
private var iconMargin = context.resources.getDimension(R.dimen.icon_side_margin).toInt()
|
private var iconMargin = context.resources.getDimension(R.dimen.icon_side_margin).toInt()
|
||||||
private var widgetMargin = context.resources.getDimension(R.dimen.widget_side_margin).toInt()
|
|
||||||
private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
|
private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
|
||||||
private var roundedCornerRadius = context.resources.getDimension(R.dimen.activity_margin)
|
private var roundedCornerRadius = context.resources.getDimension(R.dimen.activity_margin)
|
||||||
private var textPaint: TextPaint
|
private var textPaint: TextPaint
|
||||||
|
@ -171,21 +171,21 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
redrawIcons = true
|
redrawIcons = true
|
||||||
} else if (draggedItem != null) {
|
} else if (draggedItem != null) {
|
||||||
// we are dragging a new item at the home screen from the All Apps fragment
|
// we are dragging a new item at the home screen from the All Apps fragment
|
||||||
val newHomeScreenGridItem =
|
val newHomeScreenGridItem = HomeScreenGridItem(
|
||||||
HomeScreenGridItem(
|
null,
|
||||||
null,
|
xIndex,
|
||||||
xIndex,
|
yIndex,
|
||||||
yIndex,
|
xIndex + 1,
|
||||||
xIndex + 1,
|
yIndex + 1,
|
||||||
yIndex + 1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
draggedItem!!.packageName,
|
||||||
draggedItem!!.packageName,
|
draggedItem!!.title,
|
||||||
draggedItem!!.title,
|
draggedItem!!.type,
|
||||||
draggedItem!!.type,
|
"",
|
||||||
"",
|
draggedItem!!.drawable
|
||||||
draggedItem!!.drawable
|
)
|
||||||
)
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val newId = context.homeScreenGridItemsDB.insert(newHomeScreenGridItem)
|
val newId = context.homeScreenGridItemsDB.insert(newHomeScreenGridItem)
|
||||||
newHomeScreenGridItem.id = newId
|
newHomeScreenGridItem.id = newId
|
||||||
|
@ -239,7 +239,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val infoList = AppWidgetManager.getInstance(context).installedProviders
|
val infoList = AppWidgetManager.getInstance(context).installedProviders
|
||||||
val appWidgetProviderInfo = infoList.firstOrNull { it.provider.shortClassName == draggedItem?.shortClassName }
|
val appWidgetProviderInfo = infoList.firstOrNull { it.provider.shortClassName == draggedItem?.shortClassName }
|
||||||
if (appWidgetProviderInfo != null) {
|
if (appWidgetProviderInfo != null) {
|
||||||
val appWidgetHost = MyAppWidgetHost(context, 12345)
|
val appWidgetHost = AppWidgetHost(context, WIDGET_HOST_ID)
|
||||||
val appWidgetId = appWidgetHost.allocateAppWidgetId()
|
val appWidgetId = appWidgetHost.allocateAppWidgetId()
|
||||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
val canCreateWidget = appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, appWidgetProviderInfo.provider)
|
val canCreateWidget = appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, appWidgetProviderInfo.provider)
|
||||||
|
@ -248,10 +248,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
appWidgetHost.startAppWidgetConfigureActivityForResult(context as MainActivity, appWidgetId, 0, REQUEST_CONFIGURE_WIDGET, null)
|
appWidgetHost.startAppWidgetConfigureActivityForResult(context as MainActivity, appWidgetId, 0, REQUEST_CONFIGURE_WIDGET, null)
|
||||||
} else {
|
} else {
|
||||||
val widgetView = appWidgetHost.createView(context, appWidgetId, appWidgetProviderInfo)
|
val widgetView = appWidgetHost.createView(context, appWidgetId, appWidgetProviderInfo)
|
||||||
widgetView.x = widgetRect.left * rowWidth + sideMargins.left.toFloat() + widgetMargin
|
widgetView.x = widgetRect.left * rowWidth + sideMargins.left.toFloat()
|
||||||
widgetView.y = widgetRect.top * rowHeight + sideMargins.top.toFloat() + widgetMargin
|
widgetView.y = widgetRect.top * rowHeight + sideMargins.top.toFloat()
|
||||||
val widgetWidth = draggedItem!!.widthCells * rowWidth - widgetMargin * 2
|
val widgetWidth = draggedItem!!.widthCells * rowWidth
|
||||||
val widgetHeight = draggedItem!!.heightCells * rowHeight - widgetMargin * 2
|
val widgetHeight = draggedItem!!.heightCells * rowHeight
|
||||||
addView(widgetView, widgetWidth, widgetHeight)
|
addView(widgetView, widgetWidth, widgetHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,4 @@
|
||||||
<dimen name="home_long_press_anchor_offset_y">50dp</dimen>
|
<dimen name="home_long_press_anchor_offset_y">50dp</dimen>
|
||||||
<dimen name="widget_preview_size">140dp</dimen>
|
<dimen name="widget_preview_size">140dp</dimen>
|
||||||
<dimen name="icon_side_margin">10dp</dimen>
|
<dimen name="icon_side_margin">10dp</dimen>
|
||||||
<dimen name="widget_side_margin">6dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue