adding some long press related improvements
This commit is contained in:
parent
f1f1c77844
commit
3c85d89dad
|
@ -269,10 +269,11 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
|
||||
mIgnoreMoveEvents = true
|
||||
main_holder.performHapticFeedback()
|
||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||
if (clickedGridItem != null) {
|
||||
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem, false)
|
||||
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
|
||||
val anchorY = home_screen_grid.sideMargins.top + (clickedGridItem.top * home_screen_grid.rowHeight.toFloat()) - yOffset
|
||||
showHomeIconMenu(x, anchorY, clickedGridItem, false)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -288,10 +289,19 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
|
||||
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean) {
|
||||
mLongPressedIcon = gridItem
|
||||
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
|
||||
y
|
||||
} else {
|
||||
home_screen_grid.sideMargins.top + (gridItem.top * home_screen_grid.rowHeight.toFloat())
|
||||
}
|
||||
|
||||
home_screen_popup_menu_anchor.x = x
|
||||
home_screen_popup_menu_anchor.y = y
|
||||
home_screen_popup_menu_anchor.y = anchorY
|
||||
|
||||
if (mOpenPopupMenu == null) {
|
||||
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem, isOnAllAppsFragment)
|
||||
}
|
||||
}
|
||||
|
||||
fun widgetLongPressedOnList(gridItem: HomeScreenGridItem) {
|
||||
mLongPressedIcon = gridItem
|
||||
|
@ -301,7 +311,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
|
||||
private fun showMainLongPressMenu(x: Float, y: Float) {
|
||||
home_screen_popup_menu_anchor.x = x
|
||||
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
|
||||
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
|
||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||
PopupMenu(contextTheme, home_screen_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
|
||||
inflate(R.menu.menu_home_screen)
|
||||
|
@ -316,8 +326,21 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
|
||||
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
|
||||
var visibleMenuButtons = 3
|
||||
if (gridItem.type != ITEM_TYPE_ICON) {
|
||||
visibleMenuButtons -= 2
|
||||
}
|
||||
|
||||
if (isOnAllAppsFragment) {
|
||||
visibleMenuButtons -= 1
|
||||
}
|
||||
|
||||
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1)
|
||||
anchorView.y -= yOffset
|
||||
|
||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
||||
setForceShowIcon(true)
|
||||
inflate(R.menu.menu_app_icon)
|
||||
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||
|
|
|
@ -9,7 +9,10 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory
|
||||
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
import com.simplemobiletools.commons.extensions.portrait
|
||||
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||
|
@ -19,7 +22,6 @@ import kotlinx.android.synthetic.main.item_launcher_label.view.*
|
|||
class LaunchersAdapter(
|
||||
val activity: SimpleActivity,
|
||||
var launchers: ArrayList<AppLauncher>,
|
||||
val fastScroller: RecyclerViewFastScroller,
|
||||
val allAppsListener: AllAppsListener,
|
||||
val itemClick: (Any) -> Unit
|
||||
) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate {
|
||||
|
@ -85,7 +87,7 @@ class LaunchersAdapter(
|
|||
|
||||
setOnClickListener { itemClick(launcher) }
|
||||
setOnLongClickListener { view ->
|
||||
allAppsListener.onAppLauncherLongPressed(view.x, view.y, launcher)
|
||||
allAppsListener.onAppLauncherLongPressed(view.x + width / 2, view.y, launcher)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
|
||||
val currAdapter = all_apps_grid.adapter
|
||||
if (currAdapter == null) {
|
||||
LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) {
|
||||
LaunchersAdapter(activity!!, launchers, this) {
|
||||
activity?.launchApp((it as AppLauncher).packageName)
|
||||
}.apply {
|
||||
all_apps_grid.adapter = this
|
||||
|
|
|
@ -4,7 +4,7 @@ import android.graphics.drawable.Drawable
|
|||
import androidx.room.*
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
||||
|
||||
// grid coords are from 0-5 by default. Icons occupy 1 slot only, widgets can be bigger
|
||||
// grid cells are from 0-5 by default. Icons occupy 1 slot only, widgets can be bigger
|
||||
@Entity(tableName = "home_screen_grid_items", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class HomeScreenGridItem(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
|
|
|
@ -35,12 +35,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
// 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 rowYCoords = ArrayList<Int>(ROW_COUNT)
|
||||
private var rowWidth = 0
|
||||
private var rowHeight = 0
|
||||
var rowWidth = 0
|
||||
var rowHeight = 0
|
||||
private var iconSize = 0
|
||||
|
||||
// apply fake margins at the home screen. Real ones would cause the icons be cut at dragging at screen sides
|
||||
private var sideMargins = Rect()
|
||||
var sideMargins = Rect()
|
||||
|
||||
private var gridItems = ArrayList<HomeScreenGridItem>()
|
||||
private var gridCenters = ArrayList<Pair<Int, Int>>()
|
||||
|
@ -351,7 +351,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
widgetView.tag = appWidgetId
|
||||
widgetView.setAppWidget(appWidgetId, appWidgetProviderInfo)
|
||||
widgetView.longPressListener = { x, y ->
|
||||
val yOffset = resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
|
||||
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
|
||||
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y - yOffset, item, false)
|
||||
}
|
||||
|
||||
|
@ -549,10 +549,21 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
|
||||
fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? {
|
||||
for (gridItem in gridItems) {
|
||||
if (gridItem.type == ITEM_TYPE_ICON) {
|
||||
val rect = getClickableRect(gridItem)
|
||||
if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) {
|
||||
return gridItem
|
||||
}
|
||||
} else if (gridItem.type == ITEM_TYPE_WIDGET) {
|
||||
val left = calculateWidgetX(gridItem.left)
|
||||
val top = calculateWidgetY(gridItem.top)
|
||||
val right = left + gridItem.widthCells * rowWidth
|
||||
val bottom = top + gridItem.heightCells * rowHeight
|
||||
|
||||
if (x >= left && x <= right && y >= top && y <= bottom) {
|
||||
return gridItem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<resources>
|
||||
<dimen name="launcher_icon_size">55dp</dimen>
|
||||
<dimen name="icon_long_press_anchor_offset_y">150dp</dimen>
|
||||
<dimen name="home_long_press_anchor_offset_y">40dp</dimen>
|
||||
<dimen name="long_press_anchor_button_offset_y">50dp</dimen>
|
||||
<dimen name="widget_preview_size">140dp</dimen>
|
||||
<dimen name="icon_side_margin">10dp</dimen>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue