jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: move View concerns to ArticleHeaderView
......................................................................


Hygiene: move View concerns to ArticleHeaderView

Continue to prune the LeadImagesHandler class by moving some View
concerns to ArticleHeaderView and encapsulating some of the presentation
logic in ArticleHeaderView by hiding internal View implementation
details.

Change-Id: I12341a8fa7b6fd75c5c443dd609d4a11f755209f
---
M app/src/main/java/org/wikipedia/Utils.java
M app/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
M app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
M app/src/main/res/layout/view_article_header.xml
M app/src/main/res/values/attrs.xml
M app/src/main/res/values/styles_light.xml
6 files changed, 232 insertions(+), 184 deletions(-)

Approvals:
  BearND: Looks good to me, but someone else must approve
  Mholloway: Looks good to me, but someone else must approve
  Dbrant: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/Utils.java 
b/app/src/main/java/org/wikipedia/Utils.java
index 4fce8be..4056391 100644
--- a/app/src/main/java/org/wikipedia/Utils.java
+++ b/app/src/main/java/org/wikipedia/Utils.java
@@ -424,13 +424,13 @@
     /**
      * Resolves the resource ID of a theme-dependent attribute (for example, a 
color value
      * that changes based on the selected theme)
-     * @param activity The activity whose theme contains the attribute.
+     * @param context The Context whose theme contains the attribute.
      * @param id Theme-dependent attribute ID to be resolved.
      * @return The actual resource ID of the requested theme-dependent 
attribute.
      */
-    public static int getThemedAttributeId(Activity activity, int id) {
+    public static int getThemedAttributeId(Context context, int id) {
         TypedValue tv = new TypedValue();
-        activity.getTheme().resolveAttribute(id, tv, true);
+        context.getTheme().resolveAttribute(id, tv, true);
         return tv.resourceId;
     }
 
diff --git 
a/app/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java 
b/app/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
index 3126e21..31cd378 100755
--- a/app/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
+++ b/app/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
@@ -2,12 +2,6 @@
 
 import android.content.res.Resources;
 import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
-import android.support.annotation.ColorInt;
-import android.support.annotation.ColorRes;
 import android.support.annotation.DimenRes;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -21,16 +15,10 @@
 import android.text.style.AbsoluteSizeSpan;
 import android.util.TypedValue;
 import android.graphics.PointF;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewGroup;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
-
-import com.squareup.picasso.Picasso;
-import com.squareup.picasso.Target;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -48,12 +36,9 @@
 import org.wikipedia.richtext.ParagraphSpan;
 import org.wikipedia.richtext.RichTextUtil;
 import org.wikipedia.util.DimenUtil;
-import org.wikipedia.util.GradientUtil;
 import org.wikipedia.util.StringUtil;
 import org.wikipedia.views.ArticleHeaderView;
 import org.wikipedia.views.ObservableWebView;
-import org.wikipedia.views.ConfigurableTextView;
-import org.wikipedia.views.ViewUtil;
 
 public class LeadImagesHandler {
     /**
@@ -97,7 +82,6 @@
     }
 
     @NonNull private final PageFragment parentFragment;
-    @NonNull private final ViewGroup imageContainer;
     @NonNull private final CommunicationBridge bridge;
     @NonNull private final ObservableWebView webView;
 
@@ -108,10 +92,9 @@
      */
     private boolean leadImagesEnabled;
 
+    @NonNull private final ArticleHeaderView articleHeaderView;
     private ImageView imagePlaceholder;
     private ImageViewWithFace image;
-    private ConfigurableTextView pageTitleText;
-    private Drawable pageTitleGradient;
 
     private int displayHeightDp;
     private int imageBaseYOffset;
@@ -123,17 +106,13 @@
                              @NonNull CommunicationBridge bridge,
                              @NonNull ObservableWebView webView,
                              @NonNull ArticleHeaderView articleHeaderView) {
+        this.articleHeaderView = articleHeaderView;
         this.parentFragment = parentFragment;
-        this.imageContainer = articleHeaderView;
         this.bridge = bridge;
         this.webView = webView;
 
         imagePlaceholder = articleHeaderView.getPlaceholder();
         image = articleHeaderView.getImage();
-        pageTitleText = articleHeaderView.getText();
-
-        pageTitleGradient = 
GradientUtil.getCubicGradient(getColor(R.color.lead_gradient_start), 
Gravity.BOTTOM);
-        pageTitleText.setTypeface(Typeface.create(Typeface.SERIF, 
Typeface.NORMAL));
 
         initDisplayDimensions();
 
@@ -142,10 +121,7 @@
         // hide ourselves by default
         hide();
 
-        
imagePlaceholder.setImageResource(Utils.getThemedAttributeId(getActivity(),
-                R.attr.lead_image_drawable));
-
-        image.setOnImageLoadListener(new ImageLoadListener());
+        articleHeaderView.setOnImageLoadListener(new ImageLoadListener());
     }
 
     /**
@@ -153,11 +129,11 @@
      * The only way to "show" the lead image view is by calling the 
beginLayout function.
      */
     public void hide() {
-        imageContainer.setVisibility(View.INVISIBLE);
+        articleHeaderView.hide();
     }
 
     @Nullable public Bitmap getLeadImageBitmap() {
-        return leadImagesEnabled ? newBitmapFromView(image) : null;
+        return leadImagesEnabled ? articleHeaderView.copyImage() : null;
     }
 
     public boolean isLeadImageEnabled() {
@@ -207,46 +183,20 @@
             // disable the lead image completely
             leadImagesEnabled = false;
         } else {
-            // enable the lead image, only if we actually have a url for it
-            if (thumbUrl == null) {
-                leadImagesEnabled = false;
-            } else {
-                // ...and only if the image is not a GIF, since GIF images are 
usually
-                // mathematical diagrams or animations that won't look good as 
a lead image.
-                // TODO: retrieve the MIME type of the lead image, instead of 
relying on file name.
-                leadImagesEnabled = !thumbUrl.endsWith(".gif");
-
-                // TODO: what's the harm in always setting the background to 
white unconditionally.
-                // also, if the image is not a JPG (i.e. it's a PNG or SVG) 
and might have
-                // transparency, give it a white background.
-                if (!thumbUrl.endsWith(".jpg")) {
-                    image.setBackgroundColor(Color.WHITE);
-                }
-            }
+            // Enable only if the image is not a GIF, since GIF images are 
usually mathematical
+            // diagrams or animations that won't look good as a lead image.
+            // TODO: retrieve the MIME type of the lead image, instead of 
relying on file name.
+            leadImagesEnabled = thumbUrl != null && !thumbUrl.endsWith(".gif");
         }
 
         // set the page title text, and honor any HTML formatting in the title
-        pageTitleText.setText(Html.fromHtml(getPage().getDisplayTitle()), 
getPage().getTitle().getSite().getLanguageCode());
+        articleHeaderView.setText(Html.fromHtml(getPage().getDisplayTitle()), 
getPage().getTitle().getSite().getLanguageCode());
         // Set the subtitle, too, so text measurements are accurate.
         layoutWikiDataDescription(getTitle().getDescription());
 
         // kick off the (asynchronous) laying out of the page title text
         layoutPageTitle((int) (getDimension(R.dimen.titleTextSize)
                 / displayDensity), listener, sequence);
-    }
-
-    // ideas from:
-    // 
http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android
-    // View has to be already displayed. Note: a copy of the ImageView's 
Drawable must be made in
-    // some fashion as it may be recycled. See T114658.
-    private Bitmap newBitmapFromView(ImageView view) {
-        // Define a bitmap with the same size as the view
-        Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), 
view.getHeight(),
-                Bitmap.Config.ARGB_8888);
-        // Bind a canvas to it
-        Canvas canvas = new Canvas(returnedBitmap);
-        view.draw(canvas);
-        return returnedBitmap;
     }
 
     /**
@@ -264,12 +214,12 @@
             return;
         }
         // set the font size of the title
-        pageTitleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);
+        articleHeaderView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);
         // if we're still not being shown (if the fragment is still being 
created),
         // then retry after a delay.
-        if (pageTitleText.getHeight() == 0) {
+        if (articleHeaderView.getTextHeight() == 0) {
             final int postDelay = 50;
-            pageTitleText.postDelayed(new Runnable() {
+            articleHeaderView.postDelayed(new Runnable() {
                 @Override
                 public void run() {
                     layoutPageTitle(fontSizeSp, listener, sequence);
@@ -277,13 +227,13 @@
             }, postDelay);
         } else {
             // give it a chance to redraw, and then see if it fits
-            pageTitleText.post(new Runnable() {
+            articleHeaderView.post(new Runnable() {
                 @Override
                 public void run() {
                     if (!isFragmentAdded()) {
                         return;
                     }
-                    if (((int) (pageTitleText.getHeight() / displayDensity) > 
TITLE_MAX_HEIGHT_DP)
+                    if (((int) (articleHeaderView.getTextHeight() / 
displayDensity) > TITLE_MAX_HEIGHT_DP)
                             && (fontSizeSp > TITLE_MIN_TEXT_SIZE_SP)) {
                         int newSize = fontSizeSp - 
TITLE_TEXT_SIZE_DECREMENT_SP;
                         if (newSize < TITLE_MIN_TEXT_SIZE_SP) {
@@ -315,45 +265,31 @@
 
         if (isMainPage()) {
             titleContainerHeight = (int) 
(Utils.getContentTopOffsetPx(getActivity()) / displayDensity);
-            hideLeadSection();
+            articleHeaderView.hide();
         } else if (!leadImagesEnabled) {
+            articleHeaderView.showText();
+
+            // TODO: remove. Somebody is resetting the visibility of the 
ImageView.
+            image.setImageDrawable(null);
+
             // ok, we're not going to show lead images, so we need to make some
             // adjustments to our layout:
             // make the WebView padding be just the height of the title text, 
plus a fixed offset
-            titleContainerHeight = (int) ((pageTitleText.getHeight() / 
displayDensity))
+            titleContainerHeight = (int) ((articleHeaderView.getTextHeight() / 
displayDensity))
                     + DISABLED_OFFSET_DP;
-            imageContainer.setLayoutParams(new 
CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT,
+            articleHeaderView.setLayoutParams(new 
CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT,
                     (int) ((titleContainerHeight) * displayDensity)));
-            // reset the background on the lead image, in case we previously 
set it to white.
-            image.setBackgroundColor(Color.TRANSPARENT);
-            // hide the lead image
-            image.setVisibility(View.GONE);
-            image.setImageDrawable(null);
-            imagePlaceholder.setVisibility(View.GONE);
-            pageTitleText.setVisibility(View.INVISIBLE);
-            // set the color of the title
-            
pageTitleText.setTextColor(getColor(Utils.getThemedAttributeId(getActivity(),
-                    R.attr.lead_disabled_text_color)));
-            // and give it no drop shadow
-            pageTitleText.setShadowLayer(0, 0, 0, 0);
-            pageTitleText.setBackgroundColor(Color.TRANSPARENT);
+
         } else {
+            articleHeaderView.showTextImage();
+
             // we're going to show the lead image, so make some adjustments to 
the
             // layout, in case we were previously not showing it:
             // make the WebView padding be a proportion of the total screen 
height
             titleContainerHeight = (int) (displayHeightDp * 
IMAGES_CONTAINER_RATIO);
-            imageContainer.setLayoutParams(new 
CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT,
+            articleHeaderView.setLayoutParams(new 
CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT,
                     (int) (titleContainerHeight * displayDensity)));
-            // prepare the lead image to be populated
-            image.setVisibility(View.INVISIBLE);
-            imagePlaceholder.setVisibility(View.VISIBLE);
-            pageTitleText.setVisibility(View.INVISIBLE);
-            // set the color of the title
-            pageTitleText.setTextColor(getColor(R.color.lead_text_color));
-            // and give it a nice drop shadow!
-            pageTitleText.setShadowLayer(2, 1, 1, 
getColor(R.color.lead_text_shadow));
-            // set the title container background to be a gradient
-            ViewUtil.setBackgroundDrawable(pageTitleText, pageTitleGradient);
+
         }
 
         final int paddingExtra = 8;
@@ -366,20 +302,6 @@
         listener.onLayoutComplete(sequence);
 
         forceRefreshWebView();
-
-        if (!isMainPage()) {
-            // make everything visible!
-            imageContainer.setVisibility(View.VISIBLE);
-            pageTitleText.setVisibility(View.VISIBLE);
-        }
-    }
-
-    // TODO: try to get DRY with hide() or consider renaming.
-    private void hideLeadSection() {
-        image.setVisibility(View.GONE);
-        image.setImageDrawable(null);
-        imagePlaceholder.setVisibility(View.GONE);
-        pageTitleText.setVisibility(View.GONE);
     }
 
     private void setWebViewPaddingTop(int padding) {
@@ -400,18 +322,18 @@
      */
     private void layoutWikiDataDescription(@Nullable final String description) 
{
         if (!TextUtils.isEmpty(description)) {
-            CharSequence title = pageTitleText.getText();
-            int titleLineCount = pageTitleText.getLineCount();
+            CharSequence title = articleHeaderView.getText();
+            int titleLineCount = articleHeaderView.getLineCount();
 
             SpannableStringBuilder builder = new SpannableStringBuilder(title);
             builder.append("\n");
             builder.append(subtitleSpannable(description, 
getDimensionPixelSize(R.dimen.descriptionTextSize)));
-            pageTitleText.setText(builder);
+            articleHeaderView.setText(builder);
 
             // Only show the description if it's two lines or less.
-            if ((pageTitleText.getLineCount() - titleLineCount) > 2) {
+            if ((articleHeaderView.getLineCount() - titleLineCount) > 2) {
                 // Restore title.
-                pageTitleText.setText(title);
+                articleHeaderView.setText(title);
             }
         }
     }
@@ -426,53 +348,6 @@
         int displayHeightPx = DimenUtil.getDisplayHeightPx();
 
         displayHeightDp = (int) (displayHeightPx / displayDensity);
-    }
-
-    private void detectFace(int bmpHeight, float aspect, @Nullable PointF 
faceLocation) {
-        int newWidth = image.getWidth();
-        int newHeight = (int) (newWidth * aspect);
-
-        // give our image an offset based on the location of the face,
-        // relative to the image container
-        float scale = (float) newHeight / (float) bmpHeight;
-        if (faceLocation != null) {
-            int faceY = (int) (faceLocation.y * scale);
-            // if we have a face, then offset to the face location
-            imageBaseYOffset = -(faceY - (imagePlaceholder.getHeight() / 2));
-            // Adjust the face position by a slight amount.
-            // The face recognizer gives the location of the *eyes*, whereas 
we actually
-            // want to center on the *nose*...
-            imageBaseYOffset += 
getDimension(R.dimen.face_detection_nose_y_offset);
-            faceYOffsetNormalized = faceLocation.y / bmpHeight;
-        } else {
-            // No face, so we'll just chop the top 25% off rather than 
centering
-            final float oneQuarter = 0.25f;
-            imageBaseYOffset = -(int) ((newHeight - 
imagePlaceholder.getHeight()) * oneQuarter);
-            faceYOffsetNormalized = oneQuarter;
-        }
-
-        // is the offset too far to the top?
-        imageBaseYOffset = Math.min(0, imageBaseYOffset);
-
-        // is the offset too far to the bottom?
-        imageBaseYOffset = Math.max(imageBaseYOffset, 
imagePlaceholder.getHeight() - newHeight);
-
-        // resize our image to have the same proportions as the acquired bitmap
-        if (newHeight < imagePlaceholder.getHeight()) {
-            // if the height of the image is less than the container, then just
-            // make it the same height as the placeholder.
-            setImageLayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 
imagePlaceholder.getHeight());
-            imageBaseYOffset = 0;
-        } else {
-            setImageLayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 
newHeight);
-        }
-
-        forceRefreshWebView();
-
-        // fade in the new image!
-        ViewAnimations.crossFade(imagePlaceholder, image);
-
-        startKenBurnsAnimation();
     }
 
     private void setImageLayoutParams(int width, int height) {
@@ -503,10 +378,7 @@
     private void loadLeadImage(@Nullable String url) {
         if (!isMainPage() && !TextUtils.isEmpty(url) && leadImagesEnabled) {
             String fullUrl = WikipediaApp.getInstance().getNetworkProtocol() + 
":" + url;
-            Picasso.with(getActivity())
-                   .load(fullUrl)
-                   .noFade()
-                   .into((Target) image);
+            articleHeaderView.loadImage(fullUrl);
         }
     }
 
@@ -536,7 +408,7 @@
             public boolean onClick(float x, float y) {
                 // if the click event is within the area of the lead image, 
then the user
                 // must have wanted to click on the lead image!
-                if (leadImagesEnabled && y < (imageContainer.getHeight() - 
webView.getScrollY())) {
+                if (leadImagesEnabled && y < (articleHeaderView.getHeight() - 
webView.getScrollY())) {
                     String imageName = 
getPage().getPageProperties().getLeadImageName();
                     if (imageName != null) {
                         PageTitle imageTitle = new PageTitle("File:" + 
imageName,
@@ -576,11 +448,6 @@
         return getResources().getDimensionPixelSize(id);
     }
 
-    @ColorInt
-    private int getColor(@ColorRes int id) {
-        return getResources().getColor(id);
-    }
-
     private Resources getResources() {
         return getActivity().getResources();
     }
@@ -592,20 +459,20 @@
     private class WebViewScrollListener implements 
ObservableWebView.OnScrollChangeListener {
         @Override
         public void onScrollChanged(int oldScrollY, int scrollY) {
-            CoordinatorLayout.LayoutParams contParams = 
(CoordinatorLayout.LayoutParams) imageContainer
+            CoordinatorLayout.LayoutParams contParams = 
(CoordinatorLayout.LayoutParams) articleHeaderView
                     .getLayoutParams();
             FrameLayout.LayoutParams imgParams = (FrameLayout.LayoutParams) 
image.getLayoutParams();
-            if (scrollY > imageContainer.getHeight()) {
-                if (contParams.topMargin != -imageContainer.getHeight()) {
-                    contParams.topMargin = -imageContainer.getHeight();
+            if (scrollY > articleHeaderView.getHeight()) {
+                if (contParams.topMargin != -articleHeaderView.getHeight()) {
+                    contParams.topMargin = -articleHeaderView.getHeight();
                     imgParams.topMargin = 0;
-                    imageContainer.setLayoutParams(contParams);
+                    articleHeaderView.setLayoutParams(contParams);
                     image.setLayoutParams(imgParams);
                 }
             } else {
                 contParams.topMargin = -scrollY;
                 imgParams.topMargin = imageBaseYOffset + scrollY / 2; 
//parallax, baby
-                imageContainer.setLayoutParams(contParams);
+                articleHeaderView.setLayoutParams(contParams);
                 image.setLayoutParams(imgParams);
             }
         }
@@ -616,7 +483,7 @@
         public void onImageLoaded(Bitmap bitmap, @Nullable final PointF 
faceLocation) {
             final int bmpHeight = bitmap.getHeight();
             final float aspect = (float) bitmap.getHeight() / (float) 
bitmap.getWidth();
-            imageContainer.post(new Runnable() {
+            articleHeaderView.post(new Runnable() {
                 @Override
                 public void run() {
                     if (isFragmentAdded()) {
@@ -630,5 +497,52 @@
         public void onImageFailed() {
             // just keep showing the placeholder image...
         }
+
+        private void detectFace(int bmpHeight, float aspect, @Nullable PointF 
faceLocation) {
+            int newWidth = image.getWidth();
+            int newHeight = (int) (newWidth * aspect);
+
+            // give our image an offset based on the location of the face,
+            // relative to the image container
+            float scale = (float) newHeight / (float) bmpHeight;
+            if (faceLocation != null) {
+                int faceY = (int) (faceLocation.y * scale);
+                // if we have a face, then offset to the face location
+                imageBaseYOffset = -(faceY - (imagePlaceholder.getHeight() / 
2));
+                // Adjust the face position by a slight amount.
+                // The face recognizer gives the location of the *eyes*, 
whereas we actually
+                // want to center on the *nose*...
+                imageBaseYOffset += 
getDimension(R.dimen.face_detection_nose_y_offset);
+                faceYOffsetNormalized = faceLocation.y / bmpHeight;
+            } else {
+                // No face, so we'll just chop the top 25% off rather than 
centering
+                final float oneQuarter = 0.25f;
+                imageBaseYOffset = -(int) ((newHeight - 
imagePlaceholder.getHeight()) * oneQuarter);
+                faceYOffsetNormalized = oneQuarter;
+            }
+
+            // is the offset too far to the top?
+            imageBaseYOffset = Math.min(0, imageBaseYOffset);
+
+            // is the offset too far to the bottom?
+            imageBaseYOffset = Math.max(imageBaseYOffset, 
imagePlaceholder.getHeight() - newHeight);
+
+            // resize our image to have the same proportions as the acquired 
bitmap
+            if (newHeight < imagePlaceholder.getHeight()) {
+                // if the height of the image is less than the container, then 
just
+                // make it the same height as the placeholder.
+                setImageLayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 
imagePlaceholder.getHeight());
+                imageBaseYOffset = 0;
+            } else {
+                setImageLayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 
newHeight);
+            }
+
+            forceRefreshWebView();
+
+            // fade in the new image!
+            ViewAnimations.crossFade(imagePlaceholder, image);
+
+            startKenBurnsAnimation();
+        }
     }
 }
diff --git a/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java 
b/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
index 6f0f8e4..925ab6b 100644
--- a/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
+++ b/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
@@ -2,13 +2,30 @@
 
 import android.annotation.TargetApi;
 import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
 import android.os.Build;
+import android.support.annotation.ColorInt;
+import android.support.annotation.ColorRes;
+import android.support.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
 import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 
+import com.squareup.picasso.Picasso;
+import com.squareup.picasso.Target;
+
 import org.wikipedia.R;
+import org.wikipedia.Utils;
 import org.wikipedia.page.leadimages.ImageViewWithFace;
+import org.wikipedia.page.leadimages.ImageViewWithFace.OnImageLoadListener;
+import org.wikipedia.util.GradientUtil;
 
 import butterknife.Bind;
 import butterknife.ButterKnife;
@@ -39,24 +56,138 @@
         init();
     }
 
+    public void hide() {
+        setVisibility(View.GONE);
+    }
+
+    public void showText() {
+        setVisibility(View.VISIBLE);
+
+        image.setVisibility(View.GONE);
+
+        placeholder.setVisibility(View.GONE);
+
+        setTextColor(getColor(Utils.getThemedAttributeId(getContext(),
+                R.attr.lead_disabled_text_color)));
+        clearTextDropShadow();
+        clearTextGradient();
+    }
+
+    public void showTextImage() {
+        setVisibility(View.VISIBLE);
+
+        image.setVisibility(View.INVISIBLE);
+
+        placeholder.setVisibility(View.VISIBLE);
+
+        setTextColor(getColor(R.color.lead_text_color));
+        setTextDropShadow();
+        setTextGradient();
+    }
+
+    // TODO: remove.
     public ImageViewWithFace getImage() {
         return image;
     }
 
+    public void setOnImageLoadListener(OnImageLoadListener listener) {
+        image.setOnImageLoadListener(listener);
+    }
+
+    public void loadImage(@NonNull String url) {
+        Picasso.with(getContext())
+                .load(url)
+                .noFade()
+                .into((Target) image);
+    }
+
+    // ideas from:
+    // 
http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android
+    // View has to be already displayed. Note: a copy of the ImageView's 
Drawable must be made in
+    // some fashion as it may be recycled. See T114658.
+    public Bitmap copyImage() {
+        // Define a bitmap with the same size as the view
+        Bitmap returnedBitmap = Bitmap.createBitmap(image.getWidth(), 
image.getHeight(),
+                Bitmap.Config.ARGB_8888);
+        // Bind a canvas to it
+        Canvas canvas = new Canvas(returnedBitmap);
+        image.draw(canvas);
+        return returnedBitmap;
+    }
+
+    // TODO: remove.
     public ImageView getPlaceholder() {
         return placeholder;
     }
 
-    public AppTextView getText() {
-        return text;
+    public int getLineCount() {
+        return text.getLineCount();
+    }
+
+    public CharSequence getText() {
+        return text.getText();
+    }
+
+    public void setText(CharSequence text) {
+        this.text.setText(text);
+    }
+
+    public void setText(CharSequence text, String locale) {
+        this.text.setText(text, locale);
+    }
+
+    public void setTextColor(@ColorInt int color) {
+        text.setTextColor(color);
+    }
+
+    public int getTextHeight() {
+        return text.getHeight();
+    }
+
+    public void setTextSize(int unit, float size) {
+        text.setTextSize(unit, size);
+    }
+
+    private void setTextDropShadow() {
+        text.setShadowLayer(2, 1, 1, getColor(R.color.lead_text_shadow));
+    }
+
+    private void clearTextDropShadow() {
+        text.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
+    }
+
+    private void clearTextGradient() {
+        text.setBackgroundColor(Color.TRANSPARENT);
+    }
+
+    private void setTextGradient() {
+        Drawable gradient = 
GradientUtil.getCubicGradient(getColor(R.color.lead_gradient_start),
+                Gravity.BOTTOM);
+        ViewUtil.setBackgroundDrawable(text, gradient);
     }
 
     private void init() {
         inflate();
-        ButterKnife.bind(this);
+        bind();
+        initText();
+        hide();
     }
 
     private void inflate() {
         inflate(getContext(), R.layout.view_article_header, this);
     }
+
+    private void bind() {
+        ButterKnife.bind(this);
+    }
+
+    private void initText() {
+        // TODO: replace with android:fontFamily="serif" attribute when our 
minimum API level is
+        //       Jelly Bean, API 16, or we make custom typeface attribute.
+        text.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL));
+    }
+
+    @ColorInt private int getColor(@ColorRes int id) {
+        return ContextCompat.getColor(getContext(), id);
+    }
 }
\ No newline at end of file
diff --git a/app/src/main/res/layout/view_article_header.xml 
b/app/src/main/res/layout/view_article_header.xml
index eab9b6d..ea8fe21 100644
--- a/app/src/main/res/layout/view_article_header.xml
+++ b/app/src/main/res/layout/view_article_header.xml
@@ -5,15 +5,16 @@
     <org.wikipedia.page.leadimages.ImageViewWithFace
         android:id="@+id/image"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="wrap_content"
         android:scaleType="centerCrop"
-        android:visibility="invisible" />
+        android:background="@color/white"
+        android:contentDescription="@null" />
 
     <!-- TODO: can this be merged with ImageViewWithFace? -->
     <ImageView
         android:id="@+id/placeholder"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="wrap_content"
         android:scaleType="centerCrop"
         android:src="?lead_image_drawable"
         android:contentDescription="@null" />
diff --git a/app/src/main/res/values/attrs.xml 
b/app/src/main/res/values/attrs.xml
index f386c6f..938e6a3 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -10,6 +10,7 @@
     <attr name="link_color" format="reference"/>
     <attr name="abusefilter_background_color" format="reference"/>
     <attr name="lead_image_drawable" format="reference"/>
+    <!-- TODO: rename? -->
     <attr name="lead_disabled_text_color" format="reference"/>
     <attr name="list_separator_color" format="reference"/>
     <attr name="syntax_highlight_template_color" format="reference"/>
diff --git a/app/src/main/res/values/styles_light.xml 
b/app/src/main/res/values/styles_light.xml
index a1e8f97..2580c82 100644
--- a/app/src/main/res/values/styles_light.xml
+++ b/app/src/main/res/values/styles_light.xml
@@ -36,6 +36,7 @@
         <item name="edit_text_color">@color/edit_text_light</item>
         <item name="link_color">@color/link_light</item>
         <item 
name="abusefilter_background_color">@color/abusefilter_background_light</item>
+        <!-- TODO: rename? -->
         <item name="lead_image_drawable">@drawable/lead_default</item>
         <item 
name="lead_disabled_text_color">@color/lead_disabled_text_light</item>
         <item name="list_separator_color">@color/list_separator_light</item>

-- 
To view, visit https://gerrit.wikimedia.org/r/247180
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I12341a8fa7b6fd75c5c443dd609d4a11f755209f
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to