Replaced the gif decoder.

Closes #16
captchafix
Florens Douwes 11 years ago
parent 8aca835fb2
commit bb5753ad0f
  1. 1
      Clover/app/build.gradle
  2. 2
      Clover/app/proguard.cfg
  3. 122
      Clover/app/src/main/java/org/floens/chan/ui/view/GIFView.java
  4. 21
      Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java

@ -72,6 +72,7 @@ dependencies {
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.android.support:support-v13:18.0.+'
compile 'com.koushikdutta.ion:ion:1.+'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.0.+'
compile files('libs/httpclientandroidlib-1.2.1.jar')
}

@ -130,3 +130,5 @@
-keep public class org.jsoup.** {
public *;
}
-keep public class pl.droidsonroids.gif.GifIOException{*;}

@ -1,122 +0,0 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.graphics.Paint;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import org.floens.chan.utils.Utils;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class GIFView extends View {
private static final ExecutorService executor = Executors.newFixedThreadPool(1);
private Movie movie;
private long movieStart;
public GIFView(Context activity) {
super(activity);
init();
}
public GIFView(Context activity, AttributeSet attbs) {
super(activity, attbs);
init();
}
public GIFView(Context activity, AttributeSet attbs, int style) {
super(activity, attbs, style);
init();
}
private void init() {
Paint paint = new Paint();
paint.setAntiAlias(true);
setLayerType(LAYER_TYPE_SOFTWARE, paint);
}
public void setPath(final String path) {
executor.submit(new Runnable() {
@Override
public void run() {
final Movie movie = Movie.decodeFile(path);
if (movie != null) {
Utils.runOnUiThread(new Runnable() {
@Override
public void run() {
GIFView.this.movie = movie;
invalidate();
}
});
}
}
});
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
long now = SystemClock.uptimeMillis();
if (movieStart == 0) { // first time
movieStart = now;
}
if (movie != null) {
int dur = movie.duration();
if (dur == 0) {
dur = 1000;
}
int relTime = (int) ((now - movieStart) % dur);
movie.setTime(relTime);
canvas.save();
float width = (float) getWidth() / (float) movie.width();
float height = (float) getHeight() / (float) movie.height();
float scale = width > height ? height : width;
int widthPixels = (int) (movie.width() * scale);
int heightPixels = (int) (movie.height() * scale);
canvas.translate((getWidth() - widthPixels) / 2, (getHeight() - heightPixels) / 2);
canvas.scale(scale, scale);
movie.draw(canvas, 0, 0);
canvas.restore();
invalidate();
}
}
}

@ -41,8 +41,12 @@ import org.floens.chan.utils.Logger;
import org.floens.chan.utils.Utils;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CancellationException;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;
public class ThumbnailImageView extends LoadView implements View.OnClickListener {
private static final String TAG = "ThumbnailImageView";
@ -58,6 +62,7 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener
private Request<?> imageRequest;
private Future<?> ionRequest;
private VideoView videoView;
private GifDrawable gifDrawable;
public ThumbnailImageView(Context context) {
super(context);
@ -82,6 +87,7 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener
this.callback = callback;
}
public void setThumbnail(String thumbnailUrl) {
if (getWidth() == 0 || getHeight() == 0) {
Logger.e(TAG, "getWidth() or getHeight() returned 0, not loading");
@ -211,12 +217,23 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener
}
private void onGif(File file) {
GIFView view = new GIFView(getContext());
view.setPath(file.getAbsolutePath());
GifDrawable drawable;
try {
drawable = new GifDrawable(file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
onError();
return;
}
GifImageView view = new GifImageView(getContext());
view.setImageDrawable(drawable);
view.setLayoutParams(Utils.MATCH_PARAMS);
setView(view, false);
callback.setProgress(false);
callback.setLinearProgress(0, 0, true);
thumbnailNeeded = false;
}
public void setVideo(String videoUrl) {

Loading…
Cancel
Save