diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounter.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounter.kt index 59c34910dc..d6fc74817a 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounter.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounter.kt @@ -15,7 +15,6 @@ import android.view.ViewTreeObserver import android.widget.ImageView import android.widget.RelativeLayout import android.widget.TextView -import mozilla.components.support.utils.DrawableUtils import mozilla.components.ui.tabcounter.R import java.text.NumberFormat @@ -39,18 +38,14 @@ open class TabCounter @JvmOverloads constructor( box = findViewById(R.id.counter_box) text = findViewById(R.id.counter_text) text.text = DEFAULT_TABS_COUNTER_TEXT - val shiftOneDpForDefaultText = TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, 1f, context.resources.displayMetrics + val shiftThreeDp = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics ).toInt() - text.setPadding(0, 0, 0, shiftOneDpForDefaultText) + text.setPadding(0, shiftThreeDp, shiftThreeDp, 0) animationSet = createAnimatorSet() } - fun getText(): CharSequence { - return text.text - } - fun setCountWithAnimation(count: Int) { // Don't animate from initial state. if (this.count == 0) { @@ -70,7 +65,6 @@ open class TabCounter @JvmOverloads constructor( adjustTextSize(count) - text.setPadding(0, 0, 0, 0) text.text = formatForDisplay(count) this.count = count @@ -85,21 +79,10 @@ open class TabCounter @JvmOverloads constructor( fun setCount(count: Int) { adjustTextSize(count) - text.setPadding(0, 0, 0, 0) text.text = formatForDisplay(count) this.count = count } - private fun tintDrawables(tabCounterTint: Int) { - val tabCounterBox = DrawableUtils.loadAndTintDrawable( - context, - R.drawable.mozac_ui_tabcounter_box, tabCounterTint - ) - box.setImageDrawable(tabCounterBox) - - text.setTextColor(tabCounterTint) - } - private fun createAnimatorSet(): AnimatorSet { val animatorSet = AnimatorSet() createBoxAnimatorSet(animatorSet) @@ -233,6 +216,12 @@ open class TabCounter @JvmOverloads constructor( // Only apply the size when we calculate a valid value. text.setTextSize(TypedValue.COMPLEX_UNIT_PX, sizeInPixel.toFloat()) text.setTypeface(null, Typeface.BOLD) + val shiftDp = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + if (newRatio == TWO_DIGITS_SIZE_RATIO) TWO_DIGIT_PADDING else ONE_DIGIT_PADDING, + context.resources.displayMetrics + ).toInt() + text.setPadding(0, shiftDp, shiftDp, 0) } } }) @@ -248,6 +237,8 @@ open class TabCounter @JvmOverloads constructor( internal const val ONE_DIGIT_SIZE_RATIO = 0.5f internal const val TWO_DIGITS_SIZE_RATIO = 0.4f + internal const val ONE_DIGIT_PADDING = 2F + internal const val TWO_DIGIT_PADDING = 3F internal const val TWO_DIGITS_TAB_COUNT_THRESHOLD = 10 // createBoxAnimatorSet diff --git a/app/src/main/res/layout/mozac_ui_tabcounter_layout.xml b/app/src/main/res/layout/mozac_ui_tabcounter_layout.xml index 6d88a0e748..a25b30d614 100644 --- a/app/src/main/res/layout/mozac_ui_tabcounter_layout.xml +++ b/app/src/main/res/layout/mozac_ui_tabcounter_layout.xml @@ -28,8 +28,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="1dp" - android:layout_marginEnd="1dp" android:textColor="?primaryText" android:textSize="12sp" android:textStyle="bold"