remove unneeded dimens
This commit is contained in:
parent
b422f5ba6a
commit
7f7780f678
2 changed files with 22 additions and 22 deletions
|
@ -10,20 +10,25 @@ import androidx.core.widget.PopupWindowCompat
|
||||||
import com.simplemobiletools.commons.R
|
import com.simplemobiletools.commons.R
|
||||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||||
|
import com.simplemobiletools.commons.extensions.windowManager
|
||||||
|
import com.simplemobiletools.commons.helpers.isRPlus
|
||||||
import kotlinx.android.synthetic.main.item_action_mode_popup.view.*
|
import kotlinx.android.synthetic.main.item_action_mode_popup.view.*
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
class BottomActionMenuItemPopup(private val context: Context, private val items: List<BottomActionMenuItem>, private val onSelect: (BottomActionMenuItem) -> Unit) {
|
class BottomActionMenuItemPopup(
|
||||||
|
private val context: Context,
|
||||||
|
private val items: List<BottomActionMenuItem>,
|
||||||
|
private val onSelect: (BottomActionMenuItem) -> Unit
|
||||||
|
) {
|
||||||
|
|
||||||
private val popup = PopupWindow(context, null, android.R.attr.popupMenuStyle)
|
private val popup = PopupWindow(context, null, android.R.attr.popupMenuStyle)
|
||||||
private var anchorView: View? = null
|
private var anchorView: View? = null
|
||||||
private var dropDownWidth = ViewGroup.LayoutParams.WRAP_CONTENT
|
private var dropDownWidth = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
private var dropDownHeight = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
private var dropDownVerticalOffset: Int = 0
|
private var dropDownVerticalOffset: Int = 0
|
||||||
private var dropDownHorizontalOffset: Int = 0
|
private var dropDownHorizontalOffset: Int = 0
|
||||||
private val tempRect = Rect()
|
private val tempRect = Rect()
|
||||||
private val popupMaxWidth: Int
|
|
||||||
private val popupMinWidth: Int
|
private val popupMinWidth: Int
|
||||||
private val popupWidthUnit: Int
|
|
||||||
private val popupPaddingBottom: Int
|
private val popupPaddingBottom: Int
|
||||||
private val popupPaddingStart: Int
|
private val popupPaddingStart: Int
|
||||||
private val popupPaddingEnd: Int
|
private val popupPaddingEnd: Int
|
||||||
|
@ -53,9 +58,7 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
|
|
||||||
init {
|
init {
|
||||||
popup.isFocusable = true
|
popup.isFocusable = true
|
||||||
popupMaxWidth = context.resources.getDimensionPixelSize(R.dimen.cab_popup_menu_max_width)
|
|
||||||
popupMinWidth = context.resources.getDimensionPixelSize(R.dimen.cab_popup_menu_min_width)
|
popupMinWidth = context.resources.getDimensionPixelSize(R.dimen.cab_popup_menu_min_width)
|
||||||
popupWidthUnit = context.resources.getDimensionPixelSize(R.dimen.cab_popup_menu_width_unit)
|
|
||||||
popupPaddingStart = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
popupPaddingStart = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
||||||
popupPaddingEnd = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
popupPaddingEnd = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
||||||
popupPaddingTop = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
popupPaddingTop = context.resources.getDimensionPixelSize(R.dimen.smaller_margin)
|
||||||
|
@ -64,15 +67,14 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
|
|
||||||
fun show(anchorView: View) {
|
fun show(anchorView: View) {
|
||||||
this.anchorView = anchorView
|
this.anchorView = anchorView
|
||||||
val height = buildDropDown()
|
buildDropDown()
|
||||||
PopupWindowCompat.setWindowLayoutType(popup, WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL)
|
PopupWindowCompat.setWindowLayoutType(popup, WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL)
|
||||||
popup.isOutsideTouchable = true
|
popup.isOutsideTouchable = true
|
||||||
val widthSpec = dropDownWidth
|
|
||||||
if (popup.isShowing) {
|
if (popup.isShowing) {
|
||||||
popup.update(anchorView, dropDownHorizontalOffset, dropDownVerticalOffset, widthSpec, if (height < 0) -1 else height)
|
popup.update(anchorView, dropDownHorizontalOffset, dropDownVerticalOffset, dropDownWidth, if (dropDownHeight < 0) -1 else dropDownHeight)
|
||||||
} else {
|
} else {
|
||||||
popup.width = widthSpec
|
popup.width = dropDownWidth
|
||||||
popup.height = height
|
popup.height = dropDownHeight
|
||||||
PopupWindowCompat.showAsDropDown(popup, anchorView, dropDownHorizontalOffset, dropDownVerticalOffset, dropDownGravity)
|
PopupWindowCompat.showAsDropDown(popup, anchorView, dropDownHorizontalOffset, dropDownVerticalOffset, dropDownGravity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +92,7 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildDropDown(): Int {
|
private fun buildDropDown() {
|
||||||
var otherHeights = 0
|
var otherHeights = 0
|
||||||
val dropDownList = ListView(context).apply {
|
val dropDownList = ListView(context).apply {
|
||||||
adapter = popupListAdapter
|
adapter = popupListAdapter
|
||||||
|
@ -104,7 +106,13 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
setPaddingRelative(popupPaddingStart, popupPaddingTop, popupPaddingEnd, popupPaddingBottom)
|
setPaddingRelative(popupPaddingStart, popupPaddingTop, popupPaddingEnd, popupPaddingBottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
val width = measureMenuSizeAndGetWidth(popupMaxWidth)
|
val screenWidth = if (isRPlus()) {
|
||||||
|
context.windowManager.currentWindowMetrics.bounds.width()
|
||||||
|
} else {
|
||||||
|
context.windowManager.defaultDisplay.width
|
||||||
|
}
|
||||||
|
|
||||||
|
val width = measureMenuSizeAndGetWidth((0.8 * screenWidth).toInt())
|
||||||
updateContentWidth(width)
|
updateContentWidth(width)
|
||||||
popup.contentView = dropDownList
|
popup.contentView = dropDownList
|
||||||
|
|
||||||
|
@ -135,7 +143,8 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
otherHeights += padding + listPadding
|
otherHeights += padding + listPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
return listContent + otherHeights
|
dropDownHeight = listContent + otherHeights
|
||||||
|
dropDownList.layoutParams = ViewGroup.LayoutParams(dropDownWidth, dropDownHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateContentWidth(width: Int) {
|
private fun updateContentWidth(width: Int) {
|
||||||
|
@ -239,9 +248,6 @@ class BottomActionMenuItemPopup(private val context: Context, private val items:
|
||||||
maxWidth = itemWidth
|
maxWidth = itemWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maxWidth = ceil(maxWidth.toDouble() / popupWidthUnit).toInt() * popupWidthUnit
|
|
||||||
|
|
||||||
return maxWidth
|
return maxWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
<dimen name="fastscroll_width">8dp</dimen>
|
<dimen name="fastscroll_width">8dp</dimen>
|
||||||
<dimen name="fastscroll_height">40dp</dimen>
|
<dimen name="fastscroll_height">40dp</dimen>
|
||||||
<dimen name="fingerprint_icon_size">72dp</dimen>
|
<dimen name="fingerprint_icon_size">72dp</dimen>
|
||||||
<dimen name="fastscroll_bubble_offset">30dp</dimen>
|
|
||||||
<dimen name="fab_size">56dp</dimen>
|
<dimen name="fab_size">56dp</dimen>
|
||||||
<dimen name="secondary_fab_bottom_margin">76dp</dimen>
|
<dimen name="secondary_fab_bottom_margin">76dp</dimen>
|
||||||
<dimen name="file_picker_icon_size">54dp</dimen>
|
<dimen name="file_picker_icon_size">54dp</dimen>
|
||||||
|
@ -34,9 +33,6 @@
|
||||||
<dimen name="rounded_corner_radius_big">10dp</dimen>
|
<dimen name="rounded_corner_radius_big">10dp</dimen>
|
||||||
<dimen name="bottom_sheet_corner_radius">24dp</dimen>
|
<dimen name="bottom_sheet_corner_radius">24dp</dimen>
|
||||||
<dimen name="breadcrumbs_layout_height">48dp</dimen>
|
<dimen name="breadcrumbs_layout_height">48dp</dimen>
|
||||||
<dimen name="bottom_cab_layout_height">48dp</dimen>
|
|
||||||
<dimen name="bottom_cab_layout_max_width">300dp</dimen>
|
|
||||||
<dimen name="bottom_cab_layout_item_size">48dp</dimen>
|
|
||||||
|
|
||||||
<dimen name="dragselect_hotspot_height">56dp</dimen>
|
<dimen name="dragselect_hotspot_height">56dp</dimen>
|
||||||
<dimen name="selection_check_size">26dp</dimen>
|
<dimen name="selection_check_size">26dp</dimen>
|
||||||
|
@ -55,9 +51,7 @@
|
||||||
<dimen name="actionbar_text_size">20sp</dimen>
|
<dimen name="actionbar_text_size">20sp</dimen>
|
||||||
<dimen name="extra_big_text_size">22sp</dimen>
|
<dimen name="extra_big_text_size">22sp</dimen>
|
||||||
|
|
||||||
<dimen name="cab_popup_menu_vertical_padding">8dp</dimen>
|
|
||||||
<dimen name="cab_popup_menu_max_width">336dp</dimen>
|
<dimen name="cab_popup_menu_max_width">336dp</dimen>
|
||||||
<dimen name="cab_popup_menu_min_width">168dp</dimen>
|
<dimen name="cab_popup_menu_min_width">168dp</dimen>
|
||||||
<dimen name="cab_popup_menu_width_unit">56dp</dimen>
|
|
||||||
<dimen name="cab_item_min_width">85dp</dimen>
|
<dimen name="cab_item_min_width">85dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue