Bug 1325931 - Use compound drawable text centering hack for AS Topsites
MozReview-Commit-ID: 4reNZTHHZNw
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
@@ -1,15 +1,16 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; 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.activitystream.topsites;
import android.graphics.Color;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@@ -82,23 +83,16 @@ import java.util.concurrent.Future;
ViewUtil.enableTouchRipple(menuButton);
}
void bind(final TopSite topSite, final int absolutePosition) {
this.topSite = topSite;
this.absolutePosition = absolutePosition;
- ActivityStream.extractLabel(itemView.getContext(), topSite.getUrl(), true, new ActivityStream.LabelCallback() {
- @Override
- public void onLabelExtracted(String label) {
- title.setText(label);
- }
- });
-
if (ongoingIconLoad != null) {
ongoingIconLoad.cancel(true);
}
ongoingIconLoad = Icons.with(itemView.getContext())
.pageUrl(topSite.getUrl())
.skipNetwork()
.build()
@@ -107,16 +101,26 @@ import java.util.concurrent.Future;
final Drawable pinDrawable;
if (topSite.isPinned()) {
pinDrawable = DrawableUtil.tintDrawable(itemView.getContext(), R.drawable.as_pin, itemView.getResources().getColor(R.color.placeholder_grey));
} else {
pinDrawable = null;
}
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, pinDrawable, null, null, null);
+ // setCenteredText() needs to have all drawable's in place to correctly layout the text,
+ // so we need to wait with requesting the title until we've set our pin icon.
+ ActivityStream.extractLabel(itemView.getContext(), topSite.getUrl(), true, new ActivityStream.LabelCallback() {
+ @Override
+ public void onLabelExtracted(String label) {
+ // We use consistent padding all around the title, and the top padding is never modified,
+ // so we can pass that in as the default padding:
+ ViewUtil.setCenteredText(title, label, title.getPaddingTop());
+ }
+ });
}
@Override
public void onIconResponse(IconResponse response) {
faviconView.updateImage(response);
final int tintColor = !response.hasColor() || response.getColor() == Color.WHITE ? Color.LTGRAY : Color.WHITE;