adding some initial widget long press handling
This commit is contained in:
parent
03b8ee01f4
commit
7f777cf557
7 changed files with 71 additions and 12 deletions
|
@ -8,6 +8,10 @@
|
|||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.BIND_APPWIDGET"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
mTouchDownY = -1
|
||||
mIgnoreMoveEvents = false
|
||||
mLongPressedIcon = null
|
||||
(widgets_fragment as WidgetsFragment).ignoreTouches = false
|
||||
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||
home_screen_grid.itemDraggingStopped(event.x.toInt(), event.y.toInt())
|
||||
if (!mIgnoreUpEvent) {
|
||||
|
@ -252,6 +253,12 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem, isOnAllAppsFragment)
|
||||
}
|
||||
|
||||
fun widgetLongPressedOnList(gridItem: HomeScreenGridItem) {
|
||||
mLongPressedIcon = gridItem
|
||||
hideFragment(widgets_fragment)
|
||||
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -9,10 +9,7 @@ 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.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
import com.simplemobiletools.commons.extensions.portrait
|
||||
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.simplemobiletools.launcher.R
|
|||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.helpers.WIDGET_LIST_ITEMS_HOLDER
|
||||
import com.simplemobiletools.launcher.helpers.WIDGET_LIST_SECTION
|
||||
import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
|
||||
import com.simplemobiletools.launcher.models.WidgetsListItem
|
||||
import com.simplemobiletools.launcher.models.WidgetsListItemsHolder
|
||||
import com.simplemobiletools.launcher.models.WidgetsListSection
|
||||
|
@ -21,7 +22,8 @@ import kotlinx.android.synthetic.main.item_widget_preview.view.*
|
|||
|
||||
class WidgetsAdapter(
|
||||
val activity: SimpleActivity,
|
||||
val widgetListItems: ArrayList<WidgetsListItem>
|
||||
val widgetListItems: ArrayList<WidgetsListItem>,
|
||||
val widgetsFragmentListener: WidgetsFragmentListener
|
||||
) : RecyclerView.Adapter<WidgetsAdapter.ViewHolder>() {
|
||||
|
||||
private var textColor = activity.getProperTextColor()
|
||||
|
@ -104,6 +106,11 @@ class WidgetsAdapter(
|
|||
widgetPreview.setOnClickListener {
|
||||
activity.toast(R.string.touch_hold_widget)
|
||||
}
|
||||
|
||||
widgetPreview.setOnLongClickListener { view ->
|
||||
widgetsFragmentListener.onWidgetLongPressed(widget)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.launcher.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -7,6 +8,7 @@ import android.content.pm.LauncherApps
|
|||
import android.content.pm.PackageManager
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -14,13 +16,15 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.launcher.activities.MainActivity
|
||||
import com.simplemobiletools.launcher.adapters.WidgetsAdapter
|
||||
import com.simplemobiletools.launcher.models.AppWidget
|
||||
import com.simplemobiletools.launcher.models.WidgetsListItem
|
||||
import com.simplemobiletools.launcher.models.WidgetsListItemsHolder
|
||||
import com.simplemobiletools.launcher.models.WidgetsListSection
|
||||
import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
|
||||
import com.simplemobiletools.launcher.models.*
|
||||
import kotlinx.android.synthetic.main.widgets_fragment.view.*
|
||||
|
||||
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet) {
|
||||
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), WidgetsFragmentListener {
|
||||
private var touchDownY = -1
|
||||
private var lastTouchCoords = Pair(0f, 0f)
|
||||
var ignoreTouches = false
|
||||
|
||||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
background.applyColorFilter(activity.getProperBackgroundColor())
|
||||
|
@ -36,6 +40,33 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
setupAdapter(appWidgets)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
if (ignoreTouches) {
|
||||
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
|
||||
if (lastTouchCoords.first != event.x || lastTouchCoords.second != event.y) {
|
||||
touchDownY = -1
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
lastTouchCoords = Pair(event.x, event.y)
|
||||
var shouldIntercept = false
|
||||
|
||||
// pull the whole fragment down if it is scrolled way to the top and the users pulls it even further
|
||||
if (touchDownY != -1) {
|
||||
shouldIntercept = touchDownY - event.y.toInt() < 0 && widgets_list.computeVerticalScrollOffset() == 0
|
||||
if (shouldIntercept) {
|
||||
activity?.startHandlingTouches(touchDownY)
|
||||
touchDownY = -1
|
||||
}
|
||||
} else {
|
||||
touchDownY = event.y.toInt()
|
||||
}
|
||||
|
||||
return shouldIntercept
|
||||
}
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
fun getAppWidgets() {
|
||||
ensureBackgroundThread {
|
||||
// get the casual widgets
|
||||
|
@ -108,7 +139,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
|
||||
private fun setupAdapter(widgetsListItems: ArrayList<WidgetsListItem>) {
|
||||
activity?.runOnUiThread {
|
||||
WidgetsAdapter(activity!!, widgetsListItems).apply {
|
||||
WidgetsAdapter(activity!!, widgetsListItems, this).apply {
|
||||
widgets_list.adapter = this
|
||||
}
|
||||
}
|
||||
|
@ -171,4 +202,10 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onWidgetLongPressed(appWidget: AppWidget) {
|
||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appWidget.appPackageName, "", appWidget.widgetPreviewImage)
|
||||
activity?.widgetLongPressedOnList(gridItem)
|
||||
ignoreTouches = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.simplemobiletools.launcher.interfaces
|
||||
|
||||
import com.simplemobiletools.launcher.models.AppWidget
|
||||
|
||||
interface WidgetsFragmentListener {
|
||||
fun onWidgetLongPressed(appWidget: AppWidget)
|
||||
}
|
|
@ -210,7 +210,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
val drawableY = rowYCoords[item.top] + iconSize / 2 + sideMargins.top
|
||||
item.drawable!!.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||
|
||||
if (item.id != draggedItem?.id) {
|
||||
if (item.id != draggedItem?.id && item.title.isNotEmpty()) {
|
||||
val textX = rowXCoords[item.left].toFloat() + labelSideMargin + sideMargins.left
|
||||
val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin + sideMargins.top
|
||||
val staticLayout = StaticLayout.Builder
|
||||
|
|
Loading…
Reference in a new issue