jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/368827 )

Change subject: Correctly render explicit background color in 
ZoomableDraweeView.
......................................................................


Correctly render explicit background color in ZoomableDraweeView.

Bug: T106077
Change-Id: I25fe0384678b7a7013785a4541fb36d6797dc0ef
---
M app/src/main/java/org/wikipedia/gallery/GalleryItemFragment.java
A app/src/main/java/org/wikipedia/views/ZoomableDraweeViewWithBackground.java
M app/src/main/res/layout/fragment_gallery_item.xml
3 files changed, 57 insertions(+), 14 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mholloway: Looks good to me, approved



diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryItemFragment.java 
b/app/src/main/java/org/wikipedia/gallery/GalleryItemFragment.java
index 5fc58bb..fcabd29 100644
--- a/app/src/main/java/org/wikipedia/gallery/GalleryItemFragment.java
+++ b/app/src/main/java/org/wikipedia/gallery/GalleryItemFragment.java
@@ -1,7 +1,6 @@
 package org.wikipedia.gallery;
 
 import android.graphics.Bitmap;
-import android.graphics.Color;
 import android.graphics.drawable.Animatable;
 import android.media.MediaPlayer;
 import android.net.Uri;
@@ -29,7 +28,6 @@
 import com.facebook.drawee.view.SimpleDraweeView;
 import com.facebook.imagepipeline.image.ImageInfo;
 import com.facebook.samples.zoomable.DoubleTapGestureListener;
-import com.facebook.samples.zoomable.ZoomableDraweeView;
 
 import org.wikipedia.Constants;
 import org.wikipedia.R;
@@ -43,6 +41,7 @@
 import org.wikipedia.util.PermissionUtil;
 import org.wikipedia.util.ShareUtil;
 import org.wikipedia.util.log.L;
+import org.wikipedia.views.ZoomableDraweeViewWithBackground;
 
 import retrofit2.Call;
 
@@ -62,7 +61,7 @@
     }
 
     private ProgressBar progressBar;
-    private ZoomableDraweeView imageView;
+    private ZoomableDraweeViewWithBackground imageView;
     private View videoContainer;
     private VideoView videoView;
     private SimpleDraweeView videoThumbnail;
@@ -119,7 +118,7 @@
         videoView = (VideoView) rootView.findViewById(R.id.gallery_video);
         videoThumbnail = (SimpleDraweeView) 
rootView.findViewById(R.id.gallery_video_thumbnail);
         videoPlayButton = 
rootView.findViewById(R.id.gallery_video_play_button);
-        imageView = (ZoomableDraweeView) 
rootView.findViewById(R.id.gallery_image);
+        imageView = (ZoomableDraweeViewWithBackground) 
rootView.findViewById(R.id.gallery_image);
         imageView.setTapListener(new DoubleTapGestureListener(imageView) {
             @Override
             public boolean onSingleTapConfirmed(MotionEvent e) {
@@ -380,6 +379,7 @@
         imageView.setVisibility(View.VISIBLE);
         L.v("Loading image from url: " + url);
 
+        imageView.setDrawBackground(false);
         imageView.setController(Fresco.newDraweeControllerBuilder()
                 .setUri(url)
                 .setAutoPlayAnimations(true)
@@ -389,10 +389,8 @@
                         if (!isAdded()) {
                             return;
                         }
+                        imageView.setDrawBackground(true);
                         updateProgressBar(false, true, 0);
-                        if 
(shouldHaveWhiteBackground(galleryItem.getMimeType())) {
-                            imageView.setBackgroundColor(Color.WHITE);
-                        }
                         parentActivity.supportInvalidateOptionsMenu();
                     }
 
@@ -456,10 +454,6 @@
         if (galleryItem != null && callback() != null) {
             callback().onDownload(galleryItem);
         }
-    }
-
-    private boolean shouldHaveWhiteBackground(String mimeType) {
-        return mimeType.contains("svg") || mimeType.contains("png") || 
mimeType.contains("gif");
     }
 
     @Nullable private Callback callback() {
diff --git 
a/app/src/main/java/org/wikipedia/views/ZoomableDraweeViewWithBackground.java 
b/app/src/main/java/org/wikipedia/views/ZoomableDraweeViewWithBackground.java
new file mode 100644
index 0000000..b1bb849
--- /dev/null
+++ 
b/app/src/main/java/org/wikipedia/views/ZoomableDraweeViewWithBackground.java
@@ -0,0 +1,50 @@
+package org.wikipedia.views;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+
+import com.facebook.samples.zoomable.DefaultZoomableController;
+import com.facebook.samples.zoomable.ZoomableDraweeView;
+
+public class ZoomableDraweeViewWithBackground extends ZoomableDraweeView {
+    private final Paint backgroundPaint = new Paint();
+    private boolean drawBackground;
+
+    public ZoomableDraweeViewWithBackground(Context context) {
+        super(context);
+        init();
+    }
+
+    public ZoomableDraweeViewWithBackground(Context context, AttributeSet 
attrs) {
+        super(context, attrs);
+        init();
+    }
+
+    public ZoomableDraweeViewWithBackground(Context context, AttributeSet 
attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init();
+    }
+
+    public void setDrawBackground(boolean draw) {
+        drawBackground = draw;
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        if (drawBackground) {
+            DefaultZoomableController controller = (DefaultZoomableController) 
getZoomableController();
+            int saveCount = canvas.save();
+            canvas.concat(controller.getTransform());
+            canvas.drawRect(controller.getImageBounds(), backgroundPaint);
+            canvas.restoreToCount(saveCount);
+        }
+        super.onDraw(canvas);
+    }
+
+    private void init() {
+        backgroundPaint.setColor(Color.WHITE);
+    }
+}
diff --git a/app/src/main/res/layout/fragment_gallery_item.xml 
b/app/src/main/res/layout/fragment_gallery_item.xml
index 54b6f12..c7daa61 100644
--- a/app/src/main/res/layout/fragment_gallery_item.xml
+++ b/app/src/main/res/layout/fragment_gallery_item.xml
@@ -5,8 +5,7 @@
              xmlns:app="http://schemas.android.com/apk/res-auto";
              android:id="@+id/gallery_item_container"
              android:layout_width="match_parent"
-             android:layout_height="match_parent"
-             android:background="@android:color/black">
+             android:layout_height="match_parent">
     <FrameLayout
         android:id="@+id/gallery_video_container"
         android:layout_width="match_parent"
@@ -36,7 +35,7 @@
             android:contentDescription="@null"
             />
     </FrameLayout>
-    <com.facebook.samples.zoomable.ZoomableDraweeView
+    <org.wikipedia.views.ZoomableDraweeViewWithBackground
         android:id="@+id/gallery_image"
         android:visibility="gone"
         android:layout_width="match_parent"

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

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

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

Reply via email to