added own gif viewer implementation

This commit is contained in:
nuclearfog 2023-04-15 16:12:13 +02:00
parent 504590cbd4
commit aa283b983f
No known key found for this signature in database
GPG Key ID: 03488A185C476379
6 changed files with 98 additions and 40 deletions

View File

@ -64,7 +64,6 @@ dependencies {
//noinspection GradleDependency //noinspection GradleDependency
implementation 'com.squareup.picasso:picasso:2.8' implementation 'com.squareup.picasso:picasso:2.8'
implementation 'jp.wasabeef:picasso-transformations:2.4.0' implementation 'jp.wasabeef:picasso-transformations:2.4.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
implementation 'com.github.QuadFlask:colorpicker:0.0.15' implementation 'com.github.QuadFlask:colorpicker:0.0.15'
implementation 'com.github.nuclearfog:ZoomView:1.0.4' implementation 'com.github.nuclearfog:ZoomView:1.0.4'
implementation 'com.github.nuclearfog:Tagger:2.4' implementation 'com.github.nuclearfog:Tagger:2.4'

View File

@ -37,8 +37,6 @@
-dontwarn org.openjsse.net.ssl.OpenJSSE -dontwarn org.openjsse.net.ssl.OpenJSSE
-keep,allowobfuscation, allowoptimization class org.openjsse.net.ssl.OpenJSSE {*;} -keep,allowobfuscation, allowoptimization class org.openjsse.net.ssl.OpenJSSE {*;}
-keep class pl.droidsonroids.gif.** {*;}
-dontwarn javax.annotation.Nullable -dontwarn javax.annotation.Nullable
-keepclassmembers class * implements android.os.Parcelable {*;} -keepclassmembers class * implements android.os.Parcelable {*;}

View File

@ -181,40 +181,6 @@
limitations under the License. limitations under the License.
</pre> </pre>
<h3>Notices for libraries:</h3>
<ul>
<li>android-gif-drawable </li>
</ul>
<pre>
MIT License
Copyright (c) 2016 Karol Wrótniak,
Droids on Roids
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software
and associated documentation files (the "Software"),
to deal in the Software without restriction,
including without limitation the rights
to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission
notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre>
</body> </body>
</html> </html>

View File

@ -21,11 +21,11 @@ import org.nuclearfog.twidda.backend.async.ImageLoader.ImageResult;
import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler; import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.config.GlobalSettings; import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.ui.views.AnimatedImageView;
import org.nuclearfog.zoomview.ZoomView; import org.nuclearfog.zoomview.ZoomView;
import java.io.File; import java.io.File;
import pl.droidsonroids.gif.GifImageView;
/** /**
* Activity to show online and local images * Activity to show online and local images
@ -63,7 +63,7 @@ public class ImageViewer extends MediaActivity implements AsyncCallback<ImageRes
private static final String CACHE_FOLDER = "imagecache"; private static final String CACHE_FOLDER = "imagecache";
private ZoomView zoomImage; private ZoomView zoomImage;
private GifImageView gifImage; private AnimatedImageView gifImage;
private ProgressBar loadingCircle; private ProgressBar loadingCircle;
@Nullable @Nullable

View File

@ -0,0 +1,95 @@
package org.nuclearfog.twidda.ui.views;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.net.Uri;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.InputStream;
/**
* custom {@link android.widget.ImageView} implementation to support animated images
*
* @author nuclearfog
*/
public class AnimatedImageView extends AppCompatImageView {
/**
* image upscale limitation
*/
private static final float MAX_SCALE = 10.0f;
private Movie movie;
private float xOffset, yOffset;
private float scale = 0.0f;
private long moviestart = 0;
/**
* @inheritDoc
*/
public AnimatedImageView(Context context) {
this(context, null);
}
/**
* @inheritDoc
*/
public AnimatedImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
/**
* @inheritDoc
*/
@Override
public void setImageURI(@Nullable Uri uri) {
ContentResolver resolver = getContext().getContentResolver();
String mime = resolver.getType(uri);
if (mime != null && mime.contains("gif")) {
try {
InputStream is = resolver.openInputStream(uri);
movie = Movie.decodeStream(is);
} catch (FileNotFoundException e) {
// ignore, use static image
}
}
super.setImageURI(uri);
}
/**
* @inheritDoc
*/
@Override
protected void onDraw(Canvas canvas) {
if (movie != null) {
// calculate scale and offsets
if (scale == 0.0f && movie.height() > 0 && movie.width() > 0) {
scale = Math.min((float) getMeasuredHeight() / (float) movie.height(), (float) getMeasuredWidth() / (float) movie.width());
scale = Math.min(scale, MAX_SCALE);
if (scale > 0.0) {
xOffset = ((float) getWidth() / scale - (float) movie.width()) / 2.0f;
yOffset = ((float) getHeight() / scale - (float) movie.height()) / 2.0f;
}
}
long now = System.currentTimeMillis();
if (moviestart == 0)
moviestart = now;
// set relative time
movie.setTime((int) ((now - moviestart) % movie.duration()));
// scale, translate and draw canvas
if (scale != 0.0f)
canvas.scale(scale, scale);
movie.draw(canvas, xOffset, yOffset);
// trigger next drawing
invalidate();
} else {
super.onDraw(canvas);
}
}
}

View File

@ -29,7 +29,7 @@
app:max_zoom_in="10.0" app:max_zoom_in="10.0"
app:max_zoom_out="0.5" /> app:max_zoom_out="0.5" />
<pl.droidsonroids.gif.GifImageView <org.nuclearfog.twidda.ui.views.AnimatedImageView
android:id="@+id/page_image_gif" android:id="@+id/page_image_gif"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"