give more info about long pressed item to the activity
This commit is contained in:
parent
97fd224619
commit
012f56cec0
|
@ -77,7 +77,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
getDefaultAppPackages()
|
getDefaultAppPackages()
|
||||||
config.wasHomeScreenInit = true
|
config.wasHomeScreenInit = true
|
||||||
home_screen_grid.fetchAppIcons()
|
home_screen_grid.fetchGridItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
if (mIsIconLongPressed && mOpenPopupMenu != null) {
|
if (mIsIconLongPressed && mOpenPopupMenu != null) {
|
||||||
mOpenPopupMenu?.dismiss()
|
mOpenPopupMenu?.dismiss()
|
||||||
mOpenPopupMenu = null
|
mOpenPopupMenu = null
|
||||||
|
home_screen_grid.itemDraggingStarted()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
|
if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
|
||||||
|
@ -150,6 +151,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
mTouchDownY = -1
|
mTouchDownY = -1
|
||||||
mIgnoreMoveEvents = false
|
mIgnoreMoveEvents = false
|
||||||
mIsIconLongPressed = false
|
mIsIconLongPressed = false
|
||||||
|
home_screen_grid.itemDraggingStopped()
|
||||||
if (!mIgnoreUpEvent) {
|
if (!mIgnoreUpEvent) {
|
||||||
if (all_apps_fragment.y < mScreenHeight * 0.7) {
|
if (all_apps_fragment.y < mScreenHeight * 0.7) {
|
||||||
showFragment(all_apps_fragment)
|
showFragment(all_apps_fragment)
|
||||||
|
@ -178,7 +180,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasDeletedAnything) {
|
if (hasDeletedAnything) {
|
||||||
home_screen_grid.fetchAppIcons()
|
home_screen_grid.fetchGridItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
mCachedLaunchers = launchers
|
mCachedLaunchers = launchers
|
||||||
|
@ -229,10 +231,10 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
|
|
||||||
mIgnoreMoveEvents = true
|
mIgnoreMoveEvents = true
|
||||||
main_holder.performHapticFeedback()
|
main_holder.performHapticFeedback()
|
||||||
val clickedPackageName = home_screen_grid.isClickingIcon(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
||||||
if (clickedPackageName.isNotEmpty()) {
|
if (clickedGridItem != null) {
|
||||||
mIsIconLongPressed = true
|
mIsIconLongPressed = true
|
||||||
showHomeIconMenu(x, y, clickedPackageName)
|
showHomeIconMenu(x, y, clickedGridItem.packageName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,9 +243,9 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
|
|
||||||
fun homeScreenClicked(x: Float, y: Float) {
|
fun homeScreenClicked(x: Float, y: Float) {
|
||||||
if (x >= home_screen_grid.left && x <= home_screen_grid.right && y >= home_screen_grid.top && y <= home_screen_grid.bottom) {
|
if (x >= home_screen_grid.left && x <= home_screen_grid.right && y >= home_screen_grid.top && y <= home_screen_grid.bottom) {
|
||||||
val clickedPackageName = home_screen_grid.isClickingIcon(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
||||||
if (clickedPackageName.isNotEmpty()) {
|
if (clickedGridItem != null) {
|
||||||
launchApp(clickedPackageName)
|
launchApp(clickedGridItem.packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +253,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) {
|
private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) {
|
||||||
home_screen_popup_menu_anchor.x = x
|
home_screen_popup_menu_anchor.x = x
|
||||||
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
|
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
|
||||||
mOpenPopupMenu = handleAppIconPopupMenu(home_screen_popup_menu_anchor, clickedPackageName)
|
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, clickedPackageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMainLongPressMenu(x: Float, y: Float) {
|
private fun showMainLongPressMenu(x: Float, y: Float) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ fun Activity.uninstallApp(packageName: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.handleAppIconPopupMenu(anchorView: View, appPackageName: String): PopupMenu {
|
fun Activity.handleGridItemPopupMenu(anchorView: View, appPackageName: String): PopupMenu {
|
||||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
||||||
inflate(R.menu.menu_app_icon)
|
inflate(R.menu.menu_app_icon)
|
||||||
|
|
|
@ -13,7 +13,7 @@ import com.simplemobiletools.launcher.R
|
||||||
import com.simplemobiletools.launcher.activities.MainActivity
|
import com.simplemobiletools.launcher.activities.MainActivity
|
||||||
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||||
import com.simplemobiletools.launcher.extensions.handleAppIconPopupMenu
|
import com.simplemobiletools.launcher.extensions.handleGridItemPopupMenu
|
||||||
import com.simplemobiletools.launcher.extensions.launchApp
|
import com.simplemobiletools.launcher.extensions.launchApp
|
||||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||||
import com.simplemobiletools.launcher.models.AppLauncher
|
import com.simplemobiletools.launcher.models.AppLauncher
|
||||||
|
@ -124,6 +124,6 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||||
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
|
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
|
||||||
all_apps_popup_menu_anchor.x = x
|
all_apps_popup_menu_anchor.x = x
|
||||||
all_apps_popup_menu_anchor.y = y
|
all_apps_popup_menu_anchor.y = y
|
||||||
activity?.handleAppIconPopupMenu(all_apps_popup_menu_anchor, packageName)
|
activity?.handleGridItemPopupMenu(all_apps_popup_menu_anchor, packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
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 labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
|
private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
|
||||||
private var textPaint: TextPaint
|
private var textPaint: TextPaint
|
||||||
|
private var isDraggingItem = false
|
||||||
|
|
||||||
// let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps
|
// let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps
|
||||||
private var rowXCoords = ArrayList<Int>(COLUMN_COUNT)
|
private var rowXCoords = ArrayList<Int>(COLUMN_COUNT)
|
||||||
|
@ -34,8 +35,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
private var rowHeight = 0
|
private var rowHeight = 0
|
||||||
private var iconSize = 0
|
private var iconSize = 0
|
||||||
|
|
||||||
private var appIcons = ArrayList<HomeScreenGridItem>()
|
private var gridItems = ArrayList<HomeScreenGridItem>()
|
||||||
private var appIconDrawables = HashMap<String, Drawable>()
|
private var gridItemDrawables = HashMap<String, Drawable>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
@ -44,17 +45,17 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
setShadowLayer(.5f, 0f, 0f, Color.BLACK)
|
setShadowLayer(.5f, 0f, 0f, Color.BLACK)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchAppIcons()
|
fetchGridItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchAppIcons() {
|
fun fetchGridItems() {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
appIconDrawables.clear()
|
gridItemDrawables.clear()
|
||||||
appIcons = context.homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
|
gridItems = context.homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
|
||||||
appIcons.forEach { item ->
|
gridItems.forEach { item ->
|
||||||
val drawable = context.getDrawableForPackageName(item.packageName)
|
val drawable = context.getDrawableForPackageName(item.packageName)
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
appIconDrawables[item.packageName] = drawable
|
gridItemDrawables[item.packageName] = drawable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +63,16 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun itemDraggingStarted() {
|
||||||
|
isDraggingItem = true
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun itemDraggingStopped() {
|
||||||
|
isDraggingItem = false
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("DrawAllocation")
|
@SuppressLint("DrawAllocation")
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
|
@ -78,29 +89,29 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appIcons.forEach { icon ->
|
gridItems.forEach { item ->
|
||||||
val drawable = appIconDrawables[icon.packageName]
|
val drawable = gridItemDrawables[item.packageName]
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
val drawableX = rowXCoords[icon.left] + iconMargin
|
val drawableX = rowXCoords[item.left] + iconMargin
|
||||||
|
|
||||||
// icons at the bottom are drawn at the bottom of the grid and they have no label
|
// icons at the bottom are drawn at the bottom of the grid and they have no label
|
||||||
if (icon.top == ROW_COUNT - 1) {
|
if (item.top == ROW_COUNT - 1) {
|
||||||
val drawableY = rowYCoords[icon.top] + rowHeight - iconSize - iconMargin * 2
|
val drawableY = rowYCoords[item.top] + rowHeight - iconSize - iconMargin * 2
|
||||||
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||||
} else {
|
} else {
|
||||||
val drawableY = rowYCoords[icon.top] + iconSize / 2
|
val drawableY = rowYCoords[item.top] + iconSize / 2
|
||||||
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||||
|
|
||||||
val textY = rowYCoords[icon.top] + iconSize * 1.5f + labelSideMargin
|
val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin
|
||||||
val staticLayout = StaticLayout.Builder
|
val staticLayout = StaticLayout.Builder
|
||||||
.obtain(icon.title, 0, icon.title.length, textPaint, rowWidth - 2 * labelSideMargin)
|
.obtain(item.title, 0, item.title.length, textPaint, rowWidth - 2 * labelSideMargin)
|
||||||
.setMaxLines(2)
|
.setMaxLines(2)
|
||||||
.setEllipsize(TextUtils.TruncateAt.END)
|
.setEllipsize(TextUtils.TruncateAt.END)
|
||||||
.setAlignment(Layout.Alignment.ALIGN_CENTER)
|
.setAlignment(Layout.Alignment.ALIGN_CENTER)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
canvas.save()
|
canvas.save()
|
||||||
canvas.translate(rowXCoords[icon.left].toFloat() + labelSideMargin, textY)
|
canvas.translate(rowXCoords[item.left].toFloat() + labelSideMargin, textY)
|
||||||
staticLayout.draw(canvas)
|
staticLayout.draw(canvas)
|
||||||
canvas.restore()
|
canvas.restore()
|
||||||
}
|
}
|
||||||
|
@ -110,13 +121,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isClickingIcon(x: Float, y: Float): String {
|
fun isClickingGridItem(x: Float, y: Float): HomeScreenGridItem? {
|
||||||
for (appIcon in appIcons) {
|
for (gridItem in gridItems) {
|
||||||
if (x >= appIcon.left * rowWidth && x <= appIcon.right * rowWidth && y >= appIcon.top * rowHeight && y <= appIcon.bottom * rowHeight) {
|
if (x >= gridItem.left * rowWidth && x <= gridItem.right * rowWidth && y >= gridItem.top * rowHeight && y <= gridItem.bottom * rowHeight) {
|
||||||
return appIcon.packageName
|
return gridItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue