Bug 1371217 - Top Sites, Bookmarks & History are not centered; r=AndreiLazar a=jcristau
☠☠ backed out by 498f86658eaa ☠ ☠
authorAnca Manu <anca.manu@softvision.ro>
Fri, 31 May 2019 08:37:23 +0000
changeset 536686 d6fc2a5a92f24c730c2d033de7a3c692c2d01da0
parent 536685 44474b3668a5779c7f515a554c5de78341736592
child 536687 1debce08ebc9f8f2b9ad5dacafe6bfd4d77df1e5
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAndreiLazar, jcristau
bugs1371217
milestone68.0
Bug 1371217 - Top Sites, Bookmarks & History are not centered; r=AndreiLazar a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D28833
mobile/android/base/java/org/mozilla/gecko/home/TabMenuStrip.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStrip.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStrip.java
@@ -1,25 +1,27 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.home;
 
+import android.content.res.Configuration;
 import android.support.v4.content.ContextCompat;
 import org.mozilla.gecko.R;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewTreeObserver;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.HorizontalScrollView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
@@ -35,16 +37,17 @@ public class TabMenuStrip extends Horizo
     // except for the first and last tab in the tab strip.
     private static final int TITLE_OFFSET_DIPS = 24;
 
     private final int titleOffset;
     private final TabMenuStripLayout layout;
 
     private final Paint shadowPaint;
     private final int shadowSize;
+    private int stripPosition;
 
     public interface OnTitleClickListener {
         void onTitleClicked(int index);
     }
 
     public TabMenuStrip(Context context, AttributeSet attrs) {
         super(context, attrs);
 
@@ -53,16 +56,17 @@ public class TabMenuStrip extends Horizo
         setFillViewport(true);
 
         final Resources res = getResources();
 
         titleOffset = (int) (TITLE_OFFSET_DIPS * res.getDisplayMetrics().density);
 
         layout = new TabMenuStripLayout(context, attrs);
         addView(layout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+        layout.setGravity(Gravity.CENTER);
 
         shadowSize = res.getDimensionPixelSize(R.dimen.tabs_strip_shadow_size);
 
         shadowPaint = new Paint();
         shadowPaint.setColor(ContextCompat.getColor(context, R.color.url_bar_shadow));
         shadowPaint.setStrokeWidth(0.0f);
     }
 
@@ -81,16 +85,17 @@ public class TabMenuStrip extends Horizo
 
     @Override
     public void removeAllPagerViews() {
         layout.removeAllViews();
     }
 
     @Override
     public void onPageSelected(final int position) {
+        stripPosition = position;
         layout.onPageSelected(position);
     }
 
     @Override
     public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
         layout.onPageScrolled(position, positionOffset, positionOffsetPixels);
 
         final View selectedTitle = layout.getChildAt(position);
@@ -119,9 +124,14 @@ public class TabMenuStrip extends Horizo
             scrollTo(titleRight - getWidth(), 0);
         }
     }
 
     @Override
     public void setOnTitleClickListener(OnTitleClickListener onTitleClickListener) {
         layout.setOnTitleClickListener(onTitleClickListener);
     }
+
+    @Override
+    protected void onConfigurationChanged(Configuration newConfig) {
+        layout.onPageSelected(stripPosition);
+    }
 }