change the way widget resizing frame works
This commit is contained in:
parent
626a553331
commit
2a5909573d
|
@ -211,7 +211,6 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
|
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
|
||||||
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
|
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
|
||||||
|
|
||||||
|
|
||||||
private fun refetchLaunchers() {
|
private fun refetchLaunchers() {
|
||||||
val launchers = getAllAppLaunchers()
|
val launchers = getAllAppLaunchers()
|
||||||
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)
|
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)
|
||||||
|
@ -262,6 +261,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
|
|
||||||
window.navigationBarColor = resources.getColor(R.color.semitransparent_navigation)
|
window.navigationBarColor = resources.getColor(R.color.semitransparent_navigation)
|
||||||
home_screen_grid.fragmentExpanded()
|
home_screen_grid.fragmentExpanded()
|
||||||
|
home_screen_grid.hideResizeLines()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideFragment(fragment: View) {
|
private fun hideFragment(fragment: View) {
|
||||||
|
@ -287,8 +287,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
main_holder.performHapticFeedback()
|
main_holder.performHapticFeedback()
|
||||||
}
|
}
|
||||||
|
|
||||||
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())
|
||||||
val anchorY = home_screen_grid.sideMargins.top + (clickedGridItem.top * home_screen_grid.rowHeight.toFloat()) - yOffset
|
|
||||||
showHomeIconMenu(x, anchorY, clickedGridItem, false)
|
showHomeIconMenu(x, anchorY, clickedGridItem, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -298,6 +297,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun homeScreenClicked(x: Float, y: Float) {
|
fun homeScreenClicked(x: Float, y: Float) {
|
||||||
|
home_screen_grid.hideResizeLines()
|
||||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||||
if (clickedGridItem != null) {
|
if (clickedGridItem != null) {
|
||||||
launchApp(clickedGridItem.packageName)
|
launchApp(clickedGridItem.packageName)
|
||||||
|
@ -305,6 +305,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean) {
|
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean) {
|
||||||
|
home_screen_grid.hideResizeLines()
|
||||||
mLongPressedIcon = gridItem
|
mLongPressedIcon = gridItem
|
||||||
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
|
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
|
||||||
y
|
y
|
||||||
|
@ -329,6 +330,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMainLongPressMenu(x: Float, y: Float) {
|
private fun showMainLongPressMenu(x: Float, y: Float) {
|
||||||
|
home_screen_grid.hideResizeLines()
|
||||||
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_button_offset_y)
|
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
|
||||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
|
@ -345,32 +347,34 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
|
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
|
||||||
var visibleMenuButtons = 3
|
var visibleMenuButtons = 4
|
||||||
if (gridItem.type != ITEM_TYPE_ICON) {
|
if (gridItem.type != ITEM_TYPE_ICON) {
|
||||||
visibleMenuButtons -= 2
|
visibleMenuButtons -= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOnAllAppsFragment) {
|
if (isOnAllAppsFragment) {
|
||||||
visibleMenuButtons -= 1
|
visibleMenuButtons--
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gridItem.type != ITEM_TYPE_WIDGET) {
|
||||||
|
visibleMenuButtons--
|
||||||
}
|
}
|
||||||
|
|
||||||
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1)
|
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1)
|
||||||
anchorView.y -= yOffset
|
anchorView.y -= yOffset
|
||||||
|
|
||||||
if (gridItem.type == ITEM_TYPE_WIDGET) {
|
|
||||||
home_screen_grid.widgetLongPressed(gridItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
setForceShowIcon(true)
|
setForceShowIcon(true)
|
||||||
inflate(R.menu.menu_app_icon)
|
inflate(R.menu.menu_app_icon)
|
||||||
|
menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET
|
||||||
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
|
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||||
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
|
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||||
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
|
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
|
||||||
setOnMenuItemClickListener { item ->
|
setOnMenuItemClickListener { item ->
|
||||||
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.resize -> home_screen_grid.widgetLongPressed(gridItem)
|
||||||
R.id.app_info -> launchAppInfo(gridItem.packageName)
|
R.id.app_info -> launchAppInfo(gridItem.packageName)
|
||||||
R.id.remove -> home_screen_grid.removeAppIcon(gridItem)
|
R.id.remove -> home_screen_grid.removeAppIcon(gridItem)
|
||||||
R.id.uninstall -> uninstallApp(gridItem.packageName)
|
R.id.uninstall -> uninstallApp(gridItem.packageName)
|
||||||
|
@ -381,10 +385,6 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
setOnDismissListener {
|
setOnDismissListener {
|
||||||
mOpenPopupMenu = null
|
mOpenPopupMenu = null
|
||||||
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
|
|
||||||
if (gridItem.type == ITEM_TYPE_WIDGET) {
|
|
||||||
home_screen_grid.hideResizeLines()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
show()
|
show()
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
||||||
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
||||||
import com.simplemobiletools.launcher.helpers.*
|
import com.simplemobiletools.launcher.helpers.*
|
||||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||||
|
import kotlinx.android.synthetic.main.activity_main.view.*
|
||||||
|
|
||||||
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
|
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
|
||||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
@ -35,14 +36,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
private var draggedItem: HomeScreenGridItem? = null
|
private var draggedItem: HomeScreenGridItem? = null
|
||||||
private var resizedWidget: HomeScreenGridItem? = null
|
private var resizedWidget: HomeScreenGridItem? = null
|
||||||
private var isFirstDraw = true
|
private var isFirstDraw = true
|
||||||
private var resizeWidgetFrame: MyAppWidgetResizeFrame
|
private var iconSize = 0
|
||||||
|
|
||||||
// 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)
|
||||||
private var rowYCoords = ArrayList<Int>(ROW_COUNT)
|
private var rowYCoords = ArrayList<Int>(ROW_COUNT)
|
||||||
var rowWidth = 0
|
var rowWidth = 0
|
||||||
var rowHeight = 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
|
// apply fake margins at the home screen. Real ones would cause the icons be cut at dragging at screen sides
|
||||||
var sideMargins = Rect()
|
var sideMargins = Rect()
|
||||||
|
@ -77,7 +77,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchGridItems()
|
fetchGridItems()
|
||||||
resizeWidgetFrame = MyAppWidgetResizeFrame(context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchGridItems() {
|
fun fetchGridItems() {
|
||||||
|
@ -172,19 +171,23 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
redrawGrid()
|
redrawGrid()
|
||||||
|
|
||||||
val widgetView = widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }
|
val widgetView = widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }
|
||||||
removeView(resizeWidgetFrame)
|
resize_frame.beGone()
|
||||||
if (widgetView != null) {
|
if (widgetView != null) {
|
||||||
val viewX = widgetView.x.toInt()
|
val viewX = widgetView.x.toInt()
|
||||||
val viewY = widgetView.y.toInt()
|
val viewY = widgetView.y.toInt()
|
||||||
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
|
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
|
||||||
resizeWidgetFrame.updateFrameCoords(frameRect)
|
resize_frame.updateFrameCoords(frameRect)
|
||||||
addView(resizeWidgetFrame)
|
resize_frame.beVisible()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hideResizeLines() {
|
fun hideResizeLines() {
|
||||||
|
if (resizedWidget == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
resizedWidget = null
|
resizedWidget = null
|
||||||
removeView(resizeWidgetFrame)
|
resize_frame.beGone()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAppIcon() {
|
private fun addAppIcon() {
|
||||||
|
@ -381,8 +384,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
widgetView.tag = appWidgetId
|
widgetView.tag = appWidgetId
|
||||||
widgetView.setAppWidget(appWidgetId, appWidgetProviderInfo)
|
widgetView.setAppWidget(appWidgetId, appWidgetProviderInfo)
|
||||||
widgetView.longPressListener = { x, y ->
|
widgetView.longPressListener = { x, y ->
|
||||||
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y)
|
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y, item, false)
|
||||||
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y - yOffset, item, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetView.x = calculateWidgetX(item.left)
|
widgetView.x = calculateWidgetX(item.left)
|
||||||
|
|
|
@ -7,16 +7,17 @@ import android.graphics.Color
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.widget.FrameLayout
|
import android.util.AttributeSet
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
|
|
||||||
@SuppressLint("ViewConstructor")
|
@SuppressLint("ViewConstructor")
|
||||||
class MyAppWidgetResizeFrame(context: Context) : FrameLayout(context) {
|
class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
|
||||||
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
|
||||||
private var resizeWidgetLinePaint: Paint
|
private var resizeWidgetLinePaint: Paint
|
||||||
|
|
||||||
init {
|
init {
|
||||||
layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
|
||||||
background = ColorDrawable(Color.TRANSPARENT)
|
background = ColorDrawable(Color.TRANSPARENT)
|
||||||
|
|
||||||
resizeWidgetLinePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
resizeWidgetLinePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:fillColor="#FFFFFFFF" android:pathData="M17.344 7.992v6.68h2.672l-0.001-8.016c0-1.47-1.202-2.672-2.672-2.672L9.328 3.985v2.672h6.68c0.735 0 1.336 0.601 1.336 1.336zm4.007 9.352H7.992c-0.735 0-1.336-0.601-1.336-1.336V2.649c0-0.735-0.601-1.336-1.336-1.336-0.735 0-1.336 0.601-1.336 1.336l0.001 1.336H2.649c-0.735 0-1.336 0.601-1.336 1.336 0 0.735 0.601 1.336 1.336 1.336l1.336-0.001v10.687c0 1.47 1.202 2.672 2.672 2.672h10.687v1.336c0 0.735 0.601 1.336 1.336 1.336 0.735 0 1.336-0.601 1.336-1.336v-1.336h1.336c0.735 0 1.336-0.601 1.336-1.336 0-0.735-0.601-1.336-1.336-1.336z"/>
|
||||||
|
</vector>
|
|
@ -7,7 +7,15 @@
|
||||||
<com.simplemobiletools.launcher.views.HomeScreenGrid
|
<com.simplemobiletools.launcher.views.HomeScreenGrid
|
||||||
android:id="@+id/home_screen_grid"
|
android:id="@+id/home_screen_grid"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.simplemobiletools.launcher.views.MyAppWidgetResizeFrame
|
||||||
|
android:id="@+id/resize_frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.launcher.views.HomeScreenGrid>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/all_apps_fragment"
|
android:id="@+id/all_apps_fragment"
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
android:icon="@drawable/ic_info_vector"
|
android:icon="@drawable/ic_info_vector"
|
||||||
android:title="@string/app_info"
|
android:title="@string/app_info"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/resize"
|
||||||
|
android:icon="@drawable/ic_resize_vector"
|
||||||
|
android:title="@string/resize"
|
||||||
|
app:showAsAction="always" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/remove"
|
android:id="@+id/remove"
|
||||||
android:icon="@drawable/ic_cross_vector"
|
android:icon="@drawable/ic_cross_vector"
|
||||||
|
|
Loading…
Reference in New Issue