Add java activity

This commit is contained in:
oupson 2019-06-12 11:32:24 +02:00
parent b4d40c5764
commit 84c97fb106
11 changed files with 109 additions and 42 deletions

View File

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Downloads/javadoc" />
<option name="OPTION_SCOPE" value="package" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
@ -13,18 +17,24 @@
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>

View File

@ -37,4 +37,4 @@ dependencies {
}
repositories {
mavenCentral()
}
}

View File

@ -24,6 +24,7 @@ import java.net.URL
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(file, speed, apngAnimatorOptions)
}
@ -35,6 +36,7 @@ fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: Ap
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(uri, speed, apngAnimatorOptions)
}
@ -46,6 +48,7 @@ fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: Apn
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
loadUrl(url, speed, apngAnimatorOptions)
}
@ -57,6 +60,7 @@ fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: Apng
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(byteArray, speed, apngAnimatorOptions)
}
@ -68,6 +72,7 @@ fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorO
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(string, speed, apngAnimatorOptions)
}
@ -79,6 +84,7 @@ fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOption
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(@RawRes res : Int, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(res, speed, apngAnimatorOptions)
}
@ -109,7 +115,7 @@ class ApngAnimator(private val context: Context?) {
private var activeAnimation: CustomAnimationDrawable? = null
private var doOnLoaded : (ApngAnimator) -> Unit = {}
private var animationLoopListener : () -> Unit = {}
private var frameChangeLister: (index : Int) -> Unit? = {}
private var duration : ArrayList<Float>? = null
@ -472,7 +478,7 @@ class ApngAnimator(private val context: Context?) {
}
activeAnimation = animResume
imageView?.setImageDrawable(activeAnimation)
activeAnimation?.setOnAnimationLoopListener(animationLoopListener)
activeAnimation?.setOnFrameChangeListener(frameChangeLister)
imageView?.invalidate()
duration = dura
break@frameLoop
@ -493,12 +499,12 @@ class ApngAnimator(private val context: Context?) {
/**
* Set animation loop listener
* @param animationLoopListener The animation loop listener.
* @param frameChangeListener The listener.
*/
fun setOnAnimationLoopListener(animationLoopListener : () -> Unit) {
fun setOnFrameChangeLister(frameChangeListener : (index : Int) -> Unit?) {
if (isApng) {
this.animationLoopListener = animationLoopListener
anim?.setOnAnimationLoopListener(animationLoopListener)
this.frameChangeLister = frameChangeListener
anim?.setOnFrameChangeListener(frameChangeListener)
}
}

View File

@ -7,19 +7,15 @@ import android.graphics.drawable.AnimationDrawable
* for the caller to listen for specific animation related events.
*/
class CustomAnimationDrawable : AnimationDrawable() {
private var onAnimationLoop : () -> Unit = {}
private var onFrameChangeListener : (index : Int) -> Unit? = {}
fun setOnAnimationLoopListener( f : () -> Unit) {
onAnimationLoop = f
fun setOnFrameChangeListener( f : (index : Int) -> Unit?) {
onFrameChangeListener = f
}
override fun selectDrawable(index: Int): Boolean {
val drawableChanged = super.selectDrawable(index)
if (index != 0 && index == numberOfFrames - 1) {
onAnimationLoop()
}
onFrameChangeListener(index)
return drawableChanged
}
}

View File

@ -1,41 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="oupson.apngcreator">
xmlns:tools="http://schemas.android.com/tools"
package="oupson.apngcreator">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".JavaActivity"
android:exported="true">
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="APNG Viewer">
android:name=".Main2Activity"
android:label="APNG Viewer">
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/png" />
<data android:mimeType="image/png"/>
</intent-filter>
</activity>
<activity android:name=".CreatorActivity"
android:exported="true"/>
<activity
android:name=".CreatorActivity"
android:exported="true"/>
</application>
</manifest>

View File

@ -0,0 +1,30 @@
package oupson.apngcreator;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import kotlin.Unit;
import oupson.apng.ApngAnimator;
import oupson.apng.ApngAnimatorKt;
public class JavaActivity extends AppCompatActivity {
static String TAG = "JavaActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java);
String imageUrl = "https://metagif.files.wordpress.com/2015/01/bugbuckbunny.png";
ImageView image = findViewById(R.id.javaImageView);
ApngAnimator a = ApngAnimatorKt.loadApng(image, imageUrl);
a.onLoaded((animator) -> {
animator.setOnFrameChangeLister((index) -> {
if (index == 0) {
Log.i(TAG, "Loop");
}
return Unit.INSTANCE;
});
return Unit.INSTANCE;
});
}
}

View File

@ -52,6 +52,9 @@ class MainActivity : AppCompatActivity() {
startActivity<CreatorActivity>()
finish()
}
R.id.action_open_java_activity -> {
startActivity<JavaActivity>()
}
}
}
}.lparams {
@ -115,7 +118,7 @@ class MainActivity : AppCompatActivity() {
id = View.generateViewId()
animator = this.loadApng(imageUrl).apply {
onLoaded {
setOnAnimationLoopListener {
setOnFrameChangeLister {
// Log.e("app-test", "onLoop")
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".JavaActivity">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp" app:srcCompat="@mipmap/ic_launcher" android:id="@+id/javaImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -3,5 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_open_create_activity"
android:title="Create apng"
app:showAsAction="never"/>
app:showAsAction="never" />
<item android:id="@+id/action_open_java_activity"
android:title="Java Activity"
app:showAsAction="never" />
</menu>

View File

@ -10,7 +10,6 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}