Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184416
Change subject: [WIP] Play videos in Gallery.
......................................................................
[WIP] Play videos in Gallery.
Not usable yet! move along...
Change-Id: I4f670d1056ba78aa3bc08d8e0c8c166a92705dc4
---
M wikipedia/res/layout/fragment_gallery_item.xml
M wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
2 files changed, 76 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/16/184416/1
diff --git a/wikipedia/res/layout/fragment_gallery_item.xml
b/wikipedia/res/layout/fragment_gallery_item.xml
index 800908e..7b2fc77 100644
--- a/wikipedia/res/layout/fragment_gallery_item.xml
+++ b/wikipedia/res/layout/fragment_gallery_item.xml
@@ -6,11 +6,19 @@
android:layout_height="match_parent">
<ImageView
android:id="@+id/gallery_image"
+ android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:contentDescription="@null"
/>
+ <VideoView
+ android:id="@+id/gallery_video"
+ android:visibility="gone"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ />
<ProgressBar
android:id="@+id/gallery_item_progress_bar"
android:layout_width="wrap_content"
diff --git
a/wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
b/wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
index 05c1021..7e0b68a 100644
---
a/wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
+++
b/wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
@@ -6,6 +6,8 @@
import org.wikipedia.concurrency.SaneAsyncTask;
import org.wikipedia.util.ShareUtils;
import android.graphics.drawable.BitmapDrawable;
+import android.media.MediaPlayer;
+import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
@@ -17,8 +19,10 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
+import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.Toast;
+import android.widget.VideoView;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import uk.co.senab.photoview.PhotoViewAttacher;
@@ -37,7 +41,10 @@
private View containerView;
private PhotoViewAttacher attacher;
- private ImageView mainImage;
+ private ImageView imageView;
+
+ private VideoView videoView;
+ private MediaController mediaController;
private GalleryItem galleryItem;
public GalleryItem getGalleryItem() {
@@ -69,8 +76,9 @@
View rootView = inflater.inflate(R.layout.fragment_gallery_item,
container, false);
containerView = rootView.findViewById(R.id.gallery_item_container);
progressBar = (ProgressBar)
rootView.findViewById(R.id.gallery_item_progress_bar);
- mainImage = (ImageView) rootView.findViewById(R.id.gallery_image);
- attacher = new PhotoViewAttacher(mainImage);
+ videoView = (VideoView) rootView.findViewById(R.id.gallery_video);
+ imageView = (ImageView) rootView.findViewById(R.id.gallery_image);
+ attacher = new PhotoViewAttacher(imageView);
attacher.setOnViewTapListener(new
PhotoViewAttacher.OnViewTapListener() {
@Override
public void onViewTap(View view, float v, float v2) {
@@ -90,7 +98,7 @@
if (galleryItem == null) {
loadGalleryItem();
} else {
- loadImage();
+ loadMedia();
}
}
@@ -126,9 +134,9 @@
menu.findItem(R.id.menu_gallery_more_info).setEnabled(galleryItem !=
null);
menu.findItem(R.id.menu_gallery_visit_page).setEnabled(galleryItem !=
null);
menu.findItem(R.id.menu_gallery_share).setEnabled(galleryItem != null
- &&
mainImage.getDrawable() != null);
+ &&
imageView.getDrawable() != null);
menu.findItem(R.id.menu_gallery_save).setEnabled(galleryItem != null
- &&
mainImage.getDrawable() != null);
+ &&
imageView.getDrawable() != null);
}
@Override
@@ -171,7 +179,7 @@
galleryItem = (GalleryItem)result.values().toArray()[0];
parentActivity.getGalleryCache().put((PageTitle)result.keySet().toArray()[0],
galleryItem);
- loadImage();
+ loadMedia();
} else {
updateProgressBar(false, true, 0);
parentActivity.showError(getString(R.string.error_network_error));
@@ -191,25 +199,60 @@
/**
* Load the actual media associated with our gallery item into the UI.
*/
- private void loadImage() {
- // it's actually OK to use the thumbUrl in all cases, and here's why:
- // - in the case of a JPG or PNG image:
- // - if the image is bigger than the requested thumbnail size,
then the
- // thumbnail will correctly be a scaled-down version of the
image, so
- // that it won't overload the device's bitmap buffer.
- // - if the image is smaller than the requested thumbnail size,
then the
- // thumbnail url will be the same as the actual image url.
- // - in the case of an SVG file:
- // - we need the thumbnail image anyway, since the ImageView can't
- // display SVGs.
- // - in the case of OGV videos:
- // - definitely need a thumbnail
- String url = galleryItem.getThumbUrl();
- Log.d(TAG, "loading from url: " + url);
+ private void loadMedia() {
+ if (galleryItem.getMimeType().contains("ogg")
+ || galleryItem.getMimeType().contains("webm")) {
+ loadVideo(galleryItem.getUrl());
+ } else {
+ // it's actually OK to use the thumbUrl in all cases, and here's
why:
+ // - in the case of a JPG or PNG image:
+ // - if the image is bigger than the requested thumbnail size,
then the
+ // thumbnail will correctly be a scaled-down version of the
image, so
+ // that it won't overload the device's bitmap buffer.
+ // - if the image is smaller than the requested thumbnail
size, then the
+ // thumbnail url will be the same as the actual image url.
+ // - in the case of an SVG file:
+ // - we need the thumbnail image anyway, since the ImageView
can't
+ // display SVGs.
+ // - in the case of OGV videos:
+ // - definitely need a thumbnail
+ loadImage(galleryItem.getThumbUrl());
+ }
+ parentActivity.supportInvalidateOptionsMenu();
+ parentActivity.layoutGalleryDescription();
+ }
+
+ private void loadVideo(String url) {
+ videoView.setVisibility(View.VISIBLE);
+ mediaController = new MediaController(parentActivity);
+ updateProgressBar(true, true, 0);
+ videoView.setMediaController(mediaController);
+ videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
+ public void onPrepared(MediaPlayer mp) {
+ updateProgressBar(false, true, 0);
+ }
+ });
+ videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+ @Override
+ public boolean onError(MediaPlayer mp, int what, int extra) {
+ // display the thumbnail for this item instead.
+ updateProgressBar(false, true, 0);
+ videoView.setVisibility(View.GONE);
+ loadImage(galleryItem.getThumbUrl());
+ return true;
+ }
+ });
+ videoView.setVideoURI(Uri.parse(url));
+ }
+
+ private void loadImage(String url) {
+ imageView.setVisibility(View.VISIBLE);
+ Log.d(TAG, "loading from url: " + url);
Picasso.with(parentActivity)
.load(url)
- .into(mainImage, new Callback() {
+ .into(imageView, new Callback() {
@Override
public void onSuccess() {
if (!isAdded()) {
@@ -230,9 +273,6 @@
parentActivity.showError(getString(R.string.gallery_error_draw_failed));
}
});
-
- parentActivity.supportInvalidateOptionsMenu();
- parentActivity.layoutGalleryDescription();
}
/**
@@ -272,7 +312,7 @@
}
parentActivity.getFunnel().logGalleryShare(pageTitle,
galleryItem.getName());
ShareUtils.shareImage(parentActivity,
- ((BitmapDrawable) mainImage.getDrawable()).getBitmap(),
+ ((BitmapDrawable) imageView.getDrawable()).getBitmap(),
"image/jpeg",
new java.io.File(galleryItem.getUrl()).getName(),
pageTitle.getDisplayText(),
@@ -292,7 +332,7 @@
@Override
public Void performTask() throws Throwable {
MediaStore.Images.Media.insertImage(parentActivity.getContentResolver(),
- ((BitmapDrawable)
mainImage.getDrawable()).getBitmap(),
+ ((BitmapDrawable)
imageView.getDrawable()).getBitmap(),
pageTitle.getDisplayText(), galleryItem.getName());
return null;
}
--
To view, visit https://gerrit.wikimedia.org/r/184416
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f670d1056ba78aa3bc08d8e0c8c166a92705dc4
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits