mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-16 19:40:41 +01:00
adding some dragging improvements
This commit is contained in:
parent
d98e3a9ddc
commit
f1f1c77844
@ -4,20 +4,15 @@ import android.annotation.SuppressLint
|
|||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.appwidget.AppWidgetProviderInfo
|
import android.appwidget.AppWidgetProviderInfo
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.*
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Paint
|
|
||||||
import android.graphics.Rect
|
|
||||||
import android.graphics.drawable.BitmapDrawable
|
|
||||||
import android.text.Layout
|
import android.text.Layout
|
||||||
import android.text.StaticLayout
|
import android.text.StaticLayout
|
||||||
import android.text.TextPaint
|
import android.text.TextPaint
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.commons.extensions.navigationBarHeight
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
import com.simplemobiletools.commons.extensions.performHapticFeedback
|
import com.simplemobiletools.commons.extensions.*
|
||||||
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.activities.MainActivity
|
||||||
@ -130,6 +125,17 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (draggedItemCurrentCoords.first == -1 && draggedItemCurrentCoords.second == -1 && draggedItem != null) {
|
||||||
|
if (draggedItem!!.type == ITEM_TYPE_WIDGET) {
|
||||||
|
val draggedWidgetView = widgetViews.firstOrNull { it.tag == draggedItem?.widgetId }
|
||||||
|
if (draggedWidgetView != null) {
|
||||||
|
draggedWidgetView.buildDrawingCache()
|
||||||
|
draggedItem!!.drawable = Bitmap.createBitmap(draggedWidgetView.drawingCache).toDrawable(context.resources)
|
||||||
|
draggedWidgetView.beGone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
draggedItemCurrentCoords = Pair(x, y)
|
draggedItemCurrentCoords = Pair(x, y)
|
||||||
redrawGrid()
|
redrawGrid()
|
||||||
}
|
}
|
||||||
@ -282,8 +288,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
context.homeScreenGridItemsDB.updateItemPosition(widgetItem.left, widgetItem.top, widgetItem.right, widgetItem.bottom, widgetItem.id!!)
|
context.homeScreenGridItemsDB.updateItemPosition(widgetItem.left, widgetItem.top, widgetItem.right, widgetItem.bottom, widgetItem.id!!)
|
||||||
val widgetView = widgetViews.firstOrNull { it.tag == widgetItem.widgetId }
|
val widgetView = widgetViews.firstOrNull { it.tag == widgetItem.widgetId }
|
||||||
if (widgetView != null) {
|
if (widgetView != null) {
|
||||||
widgetView.x = calculateWidgetX(widgetItem.left)
|
post {
|
||||||
widgetView.y = calculateWidgetY(widgetItem.top)
|
widgetView.x = calculateWidgetX(widgetItem.left)
|
||||||
|
widgetView.y = calculateWidgetY(widgetItem.top)
|
||||||
|
widgetView.beVisible()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gridItems.firstOrNull { it.id == widgetItem.id }?.apply {
|
gridItems.firstOrNull { it.id == widgetItem.id }?.apply {
|
||||||
@ -296,6 +305,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
performHapticFeedback()
|
performHapticFeedback()
|
||||||
|
widgetViews.firstOrNull { it.tag == draggedItem?.widgetId }?.apply {
|
||||||
|
post {
|
||||||
|
beVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,12 +353,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
widgetView.longPressListener = { x, y ->
|
widgetView.longPressListener = { x, y ->
|
||||||
val yOffset = resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
|
val yOffset = resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
|
||||||
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y - yOffset, item, false)
|
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y - yOffset, item, false)
|
||||||
|
|
||||||
val gridItem = gridItems.firstOrNull { it.widgetId == appWidgetId }
|
|
||||||
if (gridItem != null) {
|
|
||||||
widgetView.buildDrawingCache()
|
|
||||||
gridItem.drawable = BitmapDrawable(widgetView.drawingCache)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetView.x = calculateWidgetX(item.left)
|
widgetView.x = calculateWidgetX(item.left)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user