Closes #14131: Move constants to dimens.xml (#14135)

Co-authored-by: Elise Richards <erichards@mozilla.com>
pull/149/head
Tiger Oakes 4 years ago committed by GitHub
parent dc9bc534db
commit b563576335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,8 +12,6 @@ import android.graphics.PointF
import android.graphics.Rect import android.graphics.Rect
import android.view.View import android.view.View
import android.view.ViewConfiguration import android.view.ViewConfiguration
import androidx.annotation.Dimension
import androidx.annotation.Dimension.DP
import androidx.core.animation.doOnEnd import androidx.core.animation.doOnEnd
import androidx.core.graphics.contains import androidx.core.graphics.contains
import androidx.core.graphics.toPoint import androidx.core.graphics.toPoint
@ -21,8 +19,8 @@ import androidx.core.view.isVisible
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.support.ktx.android.util.dpToPx
import mozilla.components.support.ktx.android.view.getRectWithViewLocation import mozilla.components.support.ktx.android.view.getRectWithViewLocation
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getRectWithScreenLocation import org.mozilla.fenix.ext.getRectWithScreenLocation
import org.mozilla.fenix.ext.getWindowInsets import org.mozilla.fenix.ext.getWindowInsets
import org.mozilla.fenix.ext.isKeyboardVisible import org.mozilla.fenix.ext.isKeyboardVisible
@ -57,7 +55,8 @@ class ToolbarGestureHandler(
private val windowWidth: Int private val windowWidth: Int
get() = activity.resources.displayMetrics.widthPixels get() = activity.resources.displayMetrics.widthPixels
private val previewOffset = PREVIEW_OFFSET.dpToPx(activity.resources.displayMetrics) private val previewOffset =
activity.resources.getDimensionPixelSize(R.dimen.browser_fragment_gesture_preview_offset)
private val touchSlop = ViewConfiguration.get(activity).scaledTouchSlop private val touchSlop = ViewConfiguration.get(activity).scaledTouchSlop
private val minimumFlingVelocity = ViewConfiguration.get(activity).scaledMinimumFlingVelocity private val minimumFlingVelocity = ViewConfiguration.get(activity).scaledMinimumFlingVelocity
@ -304,12 +303,6 @@ class ToolbarGestureHandler(
*/ */
private const val OVERSCROLL_HIDE_PERCENT = 0.20 private const val OVERSCROLL_HIDE_PERCENT = 0.20
/**
* The size of the gap between the tab preview and content layout.
*/
@Dimension(unit = DP)
private const val PREVIEW_OFFSET = 48
/** /**
* Animation duration when switching to another tab * Animation duration when switching to another tab
*/ */

@ -119,8 +119,7 @@ class FenixSnackbar private constructor(
val callback = FenixSnackbarCallback(content) val callback = FenixSnackbarCallback(content)
val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar
val toolbarHeight = view.context.resources val toolbarHeight = view.resources.getDimensionPixelSize(R.dimen.browser_toolbar_height)
.getDimensionPixelSize(R.dimen.browser_toolbar_height)
return FenixSnackbar(parent, content, callback, isError).also { return FenixSnackbar(parent, content, callback, isError).also {
it.duration = durationOrAccessibleDuration it.duration = durationOrAccessibleDuration

@ -27,7 +27,6 @@ import mozilla.components.browser.state.state.ExternalAppType
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.support.ktx.android.util.dpToFloat
import mozilla.components.support.utils.URLStringUtils import mozilla.components.support.utils.URLStringUtils
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration
@ -111,7 +110,7 @@ class BrowserToolbarView(
view.apply { view.apply {
setScrollFlags() setScrollFlags()
elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics) elevation = resources.getDimension(R.dimen.browser_fragment_toolbar_elevation)
if (!isCustomTabSession) { if (!isCustomTabSession) {
display.setUrlBackground(getDrawable(R.drawable.search_url_background)) display.setUrlBackground(getDrawable(R.drawable.search_url_background))

@ -9,10 +9,13 @@ import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.style.AbsoluteSizeSpan import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import androidx.annotation.AttrRes
import androidx.annotation.Dimension
import androidx.annotation.Dimension.DP
import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.util.dpToPx
fun SpannableString.setTextSize(context: Context, textSize: Int) = fun SpannableString.setTextSize(context: Context, @Dimension(unit = DP) textSize: Int) =
this.setSpan( this.setSpan(
AbsoluteSizeSpan(textSize.dpToPx(context.resources.displayMetrics)), AbsoluteSizeSpan(textSize.dpToPx(context.resources.displayMetrics)),
0, 0,
@ -20,11 +23,9 @@ fun SpannableString.setTextSize(context: Context, textSize: Int) =
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
) )
fun SpannableString.setTextColor(context: Context, colorResId: Int) = fun SpannableString.setTextColor(context: Context, @AttrRes colorResId: Int) =
this.setSpan( this.setSpan(
ForegroundColorSpan( ForegroundColorSpan(context.getColorFromAttr(colorResId)),
context.getColorFromAttr(colorResId)
),
0, 0,
this.length, this.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE Spannable.SPAN_EXCLUSIVE_EXCLUSIVE

@ -9,11 +9,13 @@ import android.os.Build
import android.view.TouchDelegate import android.view.TouchDelegate
import android.view.View import android.view.View
import androidx.annotation.Dimension import androidx.annotation.Dimension
import androidx.annotation.Dimension.DP
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.R
fun View.increaseTapArea(extraDps: Int) { fun View.increaseTapArea(@Dimension(unit = DP) extraDps: Int) {
val dips = extraDps.dpToPx(resources.displayMetrics) val dips = extraDps.dpToPx(resources.displayMetrics)
val parent = this.parent as View val parent = this.parent as View
parent.post { parent.post {
@ -73,7 +75,7 @@ fun View.isKeyboardVisible(): Boolean {
val minimumKeyboardHeight = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val minimumKeyboardHeight = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
0 0
} else { } else {
MINIMUM_KEYBOARD_HEIGHT.dpToPx(resources.displayMetrics) resources.getDimensionPixelSize(R.dimen.minimum_keyboard_height)
} }
return getKeyboardHeight() > minimumKeyboardHeight return getKeyboardHeight() > minimumKeyboardHeight
} }

@ -20,6 +20,7 @@ import android.widget.Button
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.BOTTOM import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
@ -69,7 +70,7 @@ import mozilla.components.feature.top.sites.TopSitesConfig
import mozilla.components.feature.top.sites.TopSitesFeature import mozilla.components.feature.top.sites.TopSitesFeature
import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.content.res.resolveAttribute
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
@ -313,13 +314,13 @@ class HomeFragment : Fragment() {
applyTo(view.toolbarLayout) applyTo(view.toolbarLayout)
} }
view.bottom_bar.background = resources.getDrawable( view.bottom_bar.background = AppCompatResources.getDrawable(
ThemeManager.resolveAttribute(R.attr.bottomBarBackgroundTop, requireContext()), view.context,
null view.context.theme.resolveAttribute(R.attr.bottomBarBackgroundTop)
) )
view.homeAppBar.updateLayoutParams<ViewGroup.MarginLayoutParams> { view.homeAppBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = HEADER_MARGIN.dpToPx(resources.displayMetrics) topMargin = resources.getDimensionPixelSize(R.dimen.home_fragment_top_toolbar_header_margin)
} }
} }
ToolbarPosition.BOTTOM -> { ToolbarPosition.BOTTOM -> {
@ -1002,8 +1003,5 @@ class HomeFragment : Fragment() {
private const val ANIM_SNACKBAR_DELAY = 100L private const val ANIM_SNACKBAR_DELAY = 100L
private const val CFR_WIDTH_DIVIDER = 1.7 private const val CFR_WIDTH_DIVIDER = 1.7
private const val CFR_Y_OFFSET = -20 private const val CFR_Y_OFFSET = -20
// Layout
private const val HEADER_MARGIN = 60
} }
} }

@ -18,7 +18,7 @@ class PrivateBrowsingDescriptionViewHolder(
) : RecyclerView.ViewHolder(view) { ) : RecyclerView.ViewHolder(view) {
init { init {
val resources = view.context.resources val resources = view.resources
val appName = resources.getString(R.string.app_name) val appName = resources.getString(R.string.app_name)
view.private_session_description.text = resources.getString( view.private_session_description.text = resources.getString(
R.string.private_browsing_placeholder_description_2, appName R.string.private_browsing_placeholder_description_2, appName

@ -11,14 +11,13 @@ import androidx.appcompat.content.res.AppCompatResources
import kotlinx.android.synthetic.main.list_element.* import kotlinx.android.synthetic.main.list_element.*
import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.util.dpToFloat
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.utils.view.ViewHolder
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.loadIntoView
import org.mozilla.fenix.ext.toShortUrl import org.mozilla.fenix.ext.toShortUrl
import org.mozilla.fenix.home.sessioncontrol.CollectionInteractor import org.mozilla.fenix.home.sessioncontrol.CollectionInteractor
import org.mozilla.fenix.utils.view.ViewHolder
import mozilla.components.feature.tab.collections.Tab as ComponentTab import mozilla.components.feature.tab.collections.Tab as ComponentTab
class TabInCollectionViewHolder( class TabInCollectionViewHolder(
@ -42,7 +41,7 @@ class TabInCollectionViewHolder(
0, 0,
view.width, view.width,
view.height, view.height,
FAV_ICON_BORDER_RADIUS_IN_DP.dpToFloat(view.context.resources.displayMetrics) view.resources.getDimension(R.dimen.tab_tray_favicon_border_radius)
) )
} }
} }

@ -72,7 +72,7 @@ class BookmarkTouchCallback(
R.drawable.swipe_delete_background R.drawable.swipe_delete_background
)!! )!!
val margin = val margin =
SwipeToDeleteCallback.MARGIN.dpToPx(recyclerView.context.resources.displayMetrics) SwipeToDeleteCallback.MARGIN.dpToPx(recyclerView.resources.displayMetrics)
val cellHeight = viewHolder.itemView.bottom - viewHolder.itemView.top val cellHeight = viewHolder.itemView.bottom - viewHolder.itemView.top
val iconTop = viewHolder.itemView.top + (cellHeight - icon.intrinsicHeight) / 2 val iconTop = viewHolder.itemView.top + (cellHeight - icon.intrinsicHeight) / 2
val iconBottom = iconTop + icon.intrinsicHeight val iconBottom = iconTop + icon.intrinsicHeight

@ -15,7 +15,6 @@ import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.library.LibrarySiteItemView import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel
@ -85,8 +84,8 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi
view.setOnClickListener { view.setOnClickListener {
onSelect(folder.node) onSelect(folder.node)
} }
val pxToIndent = dpsToIndent.dpToPx(view.context.resources.displayMetrics) val pxToIndent = view.resources.getDimensionPixelSize(R.dimen.bookmark_select_folder_indent)
val padding = pxToIndent * if (folder.depth > maxDepth) maxDepth else folder.depth val padding = pxToIndent * minOf(MAX_DEPTH, folder.depth)
view.updatePaddingRelative(start = padding) view.updatePaddingRelative(start = padding)
} }
@ -117,8 +116,7 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi
this == sharedViewModel.selectedFolder this == sharedViewModel.selectedFolder
companion object { companion object {
private const val maxDepth = 10 private const val MAX_DEPTH = 10
private const val dpsToIndent = 10
} }
} }

@ -35,7 +35,6 @@ import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.service.fxa.sync.SyncStatusObserver import mozilla.components.service.fxa.sync.SyncStatusObserver
import mozilla.components.service.fxa.sync.getLastSynced import mozilla.components.service.fxa.sync.getLastSynced
import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.StoreProvider
@ -162,7 +161,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
} }
setOnBindEditTextListener { editText -> setOnBindEditTextListener { editText ->
editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH)) editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH))
editText.minHeight = DEVICE_NAME_EDIT_TEXT_MIN_HEIGHT_DP.dpToPx(resources.displayMetrics) editText.minHeight = resources.getDimensionPixelSize(R.dimen.account_settings_device_name_min_height)
} }
} }

@ -17,7 +17,6 @@ import kotlinx.android.synthetic.main.view_synced_tabs_group.view.*
import kotlinx.android.synthetic.main.view_synced_tabs_title.view.* import kotlinx.android.synthetic.main.view_synced_tabs_title.view.*
import mozilla.components.concept.sync.DeviceType import mozilla.components.concept.sync.DeviceType
import mozilla.components.feature.syncedtabs.view.SyncedTabsView import mozilla.components.feature.syncedtabs.view.SyncedTabsView
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.sync.SyncedTabsAdapter.AdapterItem import org.mozilla.fenix.sync.SyncedTabsAdapter.AdapterItem
@ -135,13 +134,8 @@ sealed class SyncedTabsViewHolder(itemView: View) : RecyclerView.ViewHolder(item
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT LinearLayout.LayoutParams.WRAP_CONTENT
) )
val displayMetrics = itemView.context.resources.displayMetrics val margin = itemView.resources.getDimensionPixelSize(R.dimen.synced_tabs_error_margin)
val margin = ERROR_MARGIN.dpToPx(displayMetrics)
lp.setMargins(margin, margin, margin, 0) lp.setMargins(margin, margin, margin, 0)
itemView.layoutParams = lp itemView.layoutParams = lp
} }
companion object {
private const val ERROR_MARGIN = 20
}
} }

@ -8,10 +8,10 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.CheckedTextView import android.widget.CheckedTextView
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.core.content.ContextCompat import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.updatePaddingRelative import androidx.core.view.updatePaddingRelative
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds
import org.mozilla.fenix.R import org.mozilla.fenix.R
internal class CollectionsAdapter( internal class CollectionsAdapter(
@ -36,15 +36,17 @@ internal class CollectionsAdapter(
override fun onBindViewHolder(holder: CollectionItemViewHolder, position: Int) { override fun onBindViewHolder(holder: CollectionItemViewHolder, position: Int) {
if (position == 0) { if (position == 0) {
val displayMetrics = holder.textView.context.resources.displayMetrics val resources = holder.textView.resources
holder.textView.updatePaddingRelative(start = NEW_COLLECTION_PADDING_START.dpToPx(displayMetrics)) holder.textView.updatePaddingRelative(
start = resources.getDimensionPixelSize(R.dimen.tab_tray_new_collection_padding_start)
)
holder.textView.compoundDrawablePadding = holder.textView.compoundDrawablePadding =
NEW_COLLECTION_DRAWABLE_PADDING.dpToPx(displayMetrics) resources.getDimensionPixelSize(R.dimen.tab_tray_new_collection_drawable_padding)
holder.textView.setCompoundDrawablesWithIntrinsicBounds( holder.textView.putCompoundDrawablesRelativeWithIntrinsicBounds(
ContextCompat.getDrawable( start = AppCompatResources.getDrawable(
holder.textView.context, holder.textView.context,
R.drawable.ic_new R.drawable.ic_new
), null, null, null )
) )
} else { } else {
holder.textView.isChecked = checkedPosition == position holder.textView.isChecked = checkedPosition == position
@ -65,9 +67,4 @@ internal class CollectionsAdapter(
override fun getItemCount() = collections.size override fun getItemCount() = collections.size
fun getSelectedCollection() = checkedPosition - 1 fun getSelectedCollection() = checkedPosition - 1
companion object {
private const val NEW_COLLECTION_PADDING_START = 24
private const val NEW_COLLECTION_DRAWABLE_PADDING = 28
}
} }

@ -42,7 +42,6 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.tabstray.TabViewHolder import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.feature.syncedtabs.SyncedTabsFeature import mozilla.components.feature.syncedtabs.SyncedTabsFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.toolbar.TabCounter.Companion.INFINITE_CHAR_PADDING_BOTTOM import org.mozilla.fenix.components.toolbar.TabCounter.Companion.INFINITE_CHAR_PADDING_BOTTOM
@ -429,15 +428,20 @@ class TabTrayView(
) )
) )
val displayMetrics = view.context.resources.displayMetrics
view.handle.updateLayoutParams<ViewGroup.MarginLayoutParams> { view.handle.updateLayoutParams<ViewGroup.MarginLayoutParams> {
height = height = view.resources.getDimensionPixelSize(
if (multiselect) MULTISELECT_HANDLE_HEIGHT.dpToPx(displayMetrics) else NORMAL_HANDLE_HEIGHT.dpToPx( if (multiselect) {
displayMetrics R.dimen.tab_tray_multiselect_handle_height
) } else {
topMargin = if (multiselect) 0.dpToPx(displayMetrics) else NORMAL_TOP_MARGIN.dpToPx( R.dimen.tab_tray_normal_handle_height
displayMetrics }
)
topMargin = view.resources.getDimensionPixelSize(
if (multiselect) {
R.dimen.tab_tray_multiselect_handle_top_margin
} else {
R.dimen.tab_tray_normal_handle_top_margin
}
) )
} }
@ -524,7 +528,7 @@ class TabTrayView(
val topOffset = if (landscape) { val topOffset = if (landscape) {
0 0
} else { } else {
view.context.resources.getDimension(R.dimen.tab_tray_top_offset).toInt() view.resources.getDimensionPixelSize(R.dimen.tab_tray_top_offset)
} }
behavior.setExpandedOffset(topOffset) behavior.setExpandedOffset(topOffset)
@ -538,11 +542,11 @@ class TabTrayView(
if (private) { if (private) {
fabView.new_tab_button.extend() fabView.new_tab_button.extend()
fabView.new_tab_button.contentDescription = fabView.new_tab_button.contentDescription =
view.context.resources.getString(R.string.add_private_tab) view.context.getString(R.string.add_private_tab)
} else { } else {
fabView.new_tab_button.shrink() fabView.new_tab_button.shrink()
fabView.new_tab_button.contentDescription = fabView.new_tab_button.contentDescription =
view.context.resources.getString(R.string.add_tab) view.context.getString(R.string.add_tab)
} }
} }
@ -579,9 +583,6 @@ class TabTrayView(
private const val EXPAND_AT_SIZE = 3 private const val EXPAND_AT_SIZE = 3
private const val SLIDE_OFFSET = 0 private const val SLIDE_OFFSET = 0
private const val SELECTION_DELAY = 500 private const val SELECTION_DELAY = 500
private const val MULTISELECT_HANDLE_HEIGHT = 11
private const val NORMAL_HANDLE_HEIGHT = 3
private const val NORMAL_TOP_MARGIN = 8
private const val NORMAL_HANDLE_PERCENT_WIDTH = 0.1F private const val NORMAL_HANDLE_PERCENT_WIDTH = 0.1F
} }
} }

@ -80,7 +80,7 @@ class TouchCallback(
val iconLeft: Int val iconLeft: Int
val iconRight: Int val iconRight: Int
val margin = val margin =
SwipeToDeleteCallback.MARGIN.dpToPx(recyclerView.context.resources.displayMetrics) SwipeToDeleteCallback.MARGIN.dpToPx(recyclerView.resources.displayMetrics)
val iconWidth = icon.intrinsicWidth val iconWidth = icon.intrinsicWidth
val iconHeight = icon.intrinsicHeight val iconHeight = icon.intrinsicHeight
val cellHeight = itemView.bottom - itemView.top val cellHeight = itemView.bottom - itemView.top

@ -68,8 +68,7 @@ fun CoroutineScope.allowUndo(
} }
val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar val shouldUseBottomToolbar = view.context.settings().shouldUseBottomToolbar
val toolbarHeight = view.context.resources val toolbarHeight = view.resources.getDimensionPixelSize(R.dimen.browser_toolbar_height)
.getDimensionPixelSize(R.dimen.browser_toolbar_height)
snackbar.view.updatePadding( snackbar.view.updatePadding(
bottom = if ( bottom = if (

@ -35,11 +35,12 @@
<dimen name="phone_feature_label_recommended_text_size">14sp</dimen> <dimen name="phone_feature_label_recommended_text_size">14sp</dimen>
<dimen name="site_permissions_exceptions_item_text_size">18sp</dimen> <dimen name="site_permissions_exceptions_item_text_size">18sp</dimen>
<dimen name="site_permissions_exceptions_item_height">56dp</dimen> <dimen name="site_permissions_exceptions_item_height">56dp</dimen>
<dimen name="synced_tab_item_min_height">56dp</dimen>
<dimen name="component_collection_creation_list_margin">16dp</dimen> <dimen name="component_collection_creation_list_margin">16dp</dimen>
<dimen name="exceptions_description_margin">12dp</dimen> <dimen name="exceptions_description_margin">12dp</dimen>
<dimen name="preference_seek_bar_padding">16dp</dimen> <dimen name="preference_seek_bar_padding">16dp</dimen>
<dimen name="custom_checkbox_alignment_margin">68dp</dimen> <dimen name="custom_checkbox_alignment_margin">68dp</dimen>
<!--The assumed minimum height of the keyboard on Lollipop.-->
<dimen name="minimum_keyboard_height">100dp</dimen>
<dimen name="context_menu_height">48dp</dimen> <dimen name="context_menu_height">48dp</dimen>
<dimen name="context_menu_x_offset">8dp</dimen> <dimen name="context_menu_x_offset">8dp</dimen>
@ -81,8 +82,17 @@
<!-- ETP Onboarding Popup --> <!-- ETP Onboarding Popup -->
<dimen name="etp_onboarding_popup_width">256dp</dimen> <dimen name="etp_onboarding_popup_width">256dp</dimen>
<!-- Edit Fragment --> <!-- Bookmark Edit Fragment -->
<dimen name="bookmark_edit_text_height">48dp</dimen> <dimen name="bookmark_edit_text_height">48dp</dimen>
<dimen name="bookmark_select_folder_indent">10dp</dimen>
<!-- Home Fragment -->
<dimen name="home_fragment_top_toolbar_header_margin">60dp</dimen>
<!-- Browser Fragment -->
<!--The size of the gap between the tab preview and content layout.-->
<dimen name="browser_fragment_gesture_preview_offset">48dp</dimen>
<dimen name="browser_fragment_toolbar_elevation">16dp</dimen>
<!-- Search Fragment --> <!-- Search Fragment -->
<dimen name="search_fragment_clipboard_item_height">56dp</dimen> <dimen name="search_fragment_clipboard_item_height">56dp</dimen>
@ -160,6 +170,13 @@
<dimen name="tab_tray_top_offset">40dp</dimen> <dimen name="tab_tray_top_offset">40dp</dimen>
<dimen name="tab_tray_thumbnail_width">92dp</dimen> <dimen name="tab_tray_thumbnail_width">92dp</dimen>
<dimen name="tab_tray_thumbnail_height">69dp</dimen> <dimen name="tab_tray_thumbnail_height">69dp</dimen>
<dimen name="tab_tray_favicon_border_radius">4dp</dimen>
<dimen name="tab_tray_multiselect_handle_height">11dp</dimen>
<dimen name="tab_tray_normal_handle_height">11dp</dimen>
<dimen name="tab_tray_multiselect_handle_top_margin">0dp</dimen>
<dimen name="tab_tray_normal_handle_top_margin">8dp</dimen>
<dimen name="tab_tray_new_collection_padding_start">24dp</dimen>
<dimen name="tab_tray_new_collection_drawable_padding">28dp</dimen>
<!-- Saved Logins Fragment --> <!-- Saved Logins Fragment -->
<dimen name="saved_logins_sort_menu_dropdown_chevron_icon_margin_start">10dp</dimen> <dimen name="saved_logins_sort_menu_dropdown_chevron_icon_margin_start">10dp</dimen>
@ -170,6 +187,12 @@
<dimen name="saved_logins_item_margin_start">16dp</dimen> <dimen name="saved_logins_item_margin_start">16dp</dimen>
<dimen name="saved_logins_item_margin_end">48dp</dimen> <dimen name="saved_logins_item_margin_end">48dp</dimen>
<!-- Synced Tabs Fragment -->
<dimen name="synced_tabs_error_margin">20dp</dimen>
<!-- Account Settings Fragment -->
<dimen name="account_settings_device_name_min_height">48dp</dimen>
<!-- Top sites --> <!-- Top sites -->
<dimen name="top_sites_favicon_size">40dp</dimen> <dimen name="top_sites_favicon_size">40dp</dimen>
<dimen name="top_sites_favicon_padding">4dp</dimen> <dimen name="top_sites_favicon_padding">4dp</dimen>

@ -21,10 +21,12 @@ import io.mockk.mockkStatic
import io.mockk.slot import io.mockk.slot
import io.mockk.verify import io.mockk.verify
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.util.dpToPx
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.robolectric.annotation.Config import org.robolectric.annotation.Config
@ -41,6 +43,9 @@ class ViewTest {
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt") mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
mockkStatic("org.mozilla.fenix.ext.ViewKt") mockkStatic("org.mozilla.fenix.ext.ViewKt")
every { view.resources.getDimensionPixelSize(any()) } answers {
testContext.resources.getDimensionPixelSize(firstArg())
}
every { view.resources.displayMetrics } returns displayMetrics every { view.resources.displayMetrics } returns displayMetrics
every { view.parent } returns parent every { view.parent } returns parent
every { parent.touchDelegate = any() } just Runs every { parent.touchDelegate = any() } just Runs
@ -119,7 +124,7 @@ class ViewTest {
@Config(sdk = [Build.VERSION_CODES.LOLLIPOP, Build.VERSION_CODES.LOLLIPOP_MR1]) @Config(sdk = [Build.VERSION_CODES.LOLLIPOP, Build.VERSION_CODES.LOLLIPOP_MR1])
@Test @Test
fun `isKeyboardVisible returns false when the keyboard height is less than or equal to the minimum threshold`() { fun `isKeyboardVisible returns false when the keyboard height is less than or equal to the minimum threshold`() {
val threshold = MINIMUM_KEYBOARD_HEIGHT.dpToPx(displayMetrics) val threshold = testContext.resources.getDimensionPixelSize(R.dimen.minimum_keyboard_height)
every { view.getKeyboardHeight() } returns threshold - 1 every { view.getKeyboardHeight() } returns threshold - 1
assertEquals(false, view.isKeyboardVisible()) assertEquals(false, view.isKeyboardVisible())
@ -131,7 +136,7 @@ class ViewTest {
@Config(sdk = [Build.VERSION_CODES.LOLLIPOP, Build.VERSION_CODES.LOLLIPOP_MR1]) @Config(sdk = [Build.VERSION_CODES.LOLLIPOP, Build.VERSION_CODES.LOLLIPOP_MR1])
@Test @Test
fun `isKeyboardVisible returns true when the keyboard height is greater than the minimum threshold`() { fun `isKeyboardVisible returns true when the keyboard height is greater than the minimum threshold`() {
val threshold = MINIMUM_KEYBOARD_HEIGHT.dpToPx(displayMetrics) val threshold = testContext.resources.getDimensionPixelSize(R.dimen.minimum_keyboard_height)
every { view.getKeyboardHeight() } returns threshold + 1 every { view.getKeyboardHeight() } returns threshold + 1
assertEquals(true, view.isKeyboardVisible()) assertEquals(true, view.isKeyboardVisible())

Loading…
Cancel
Save