Skip to content

Commit a273e7d

Browse files
committed
Working on beta
1 parent 8ffdd2d commit a273e7d

File tree

12 files changed

+283
-121
lines changed

12 files changed

+283
-121
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

apng_library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 21
99
targetSdkVersion 28
1010
versionCode 1
11-
versionName "1.0.10"
11+
versionName "1.0.10-beta1"
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414

apng_library/src/main/java/oupson/apng/ApngAnimator.kt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.content.SharedPreferences
55
import android.graphics.*
66
import android.net.Uri
7+
import android.util.Log
78
import android.widget.ImageView
89
import androidx.annotation.RawRes
910
import kotlinx.coroutines.Dispatchers
@@ -18,6 +19,8 @@ import oupson.apng.utils.Utils.Companion.isPng
1819
import java.io.File
1920
import java.net.URL
2021

22+
// TODO REWRITE WITH CALLBACKS
23+
2124
/**
2225
* @param file The APNG to load
2326
* @param speed The speed of the APNG
@@ -270,20 +273,32 @@ class ApngAnimator(private val context: Context?) {
270273
GlobalScope.launch(Dispatchers.IO) {
271274
this@ApngAnimator.speed = speed
272275
// Download PNG
273-
Loader.load(context!!, url).apply {
274-
try {
275-
this@ApngAnimator.load(this, speed, apngAnimatorOptions)
276-
} catch (e : NotPngException) {
277-
if (loadNotApng) {
278-
val bytes = this.readBytes()
279-
GlobalScope.launch(Dispatchers.Main) {
280-
imageView?.scaleType = this@ApngAnimator.scaleType ?: ImageView.ScaleType.FIT_CENTER
281-
imageView?.setImageBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.size))
276+
try {
277+
Loader.load(context!!, url).apply {
278+
try {
279+
this@ApngAnimator.load(this, speed, apngAnimatorOptions)
280+
} catch (e: NotPngException) {
281+
if (loadNotApng) {
282+
val bytes = this.readBytes()
283+
GlobalScope.launch(Dispatchers.Main) {
284+
imageView?.scaleType =
285+
this@ApngAnimator.scaleType ?: ImageView.ScaleType.FIT_CENTER
286+
imageView?.setImageBitmap(
287+
BitmapFactory.decodeByteArray(
288+
bytes,
289+
0,
290+
bytes.size
291+
)
292+
)
293+
}
294+
} else {
295+
throw NotApngException()
282296
}
283-
} else {
284-
throw NotApngException()
285297
}
286298
}
299+
} catch (e : java.lang.Exception) {
300+
if (BuildConfig.DEBUG)
301+
Log.e("ApngAnimator", "Error : $e")
287302
}
288303
}
289304
return this
@@ -535,6 +550,7 @@ class ApngAnimator(private val context: Context?) {
535550
private fun toAnimationDrawable( generatedFrame : ArrayList<Bitmap> ): CustomAnimationDrawable {
536551
if (isApng) {
537552
return CustomAnimationDrawable().apply {
553+
isOneShot = false
538554
for (i in 0 until generatedFrame.size) {
539555
addFrame(BitmapDrawable(generatedFrame[i]), ((duration!![i]) / (speed ?: 1f)).toInt())
540556
}

apng_library/src/main/java/oupson/apng/Frame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import oupson.apng.utils.Utils.Companion.isPng
1919
* @param maxWidth The max width of the APNG
2020
* @param maxHeight The max height of the APNG
2121
*/
22-
class Frame// Get width and height for image
22+
class Frame // Get width and height for image
2323
(
2424
byteArray: ByteArray,
2525
delay: Float = 1000f,

apng_library/src/main/java/oupson/apng/Loader.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import java.net.URL
1212
class Loader {
1313
companion object {
1414
/**
15-
* Download file from given url
16-
* @param context Context of app
17-
* @param url Url of the file to download
18-
* @return [ByteArray] of the file
15+
* Download file from given url.
16+
* @param context Context of app.
17+
* @param url Url of the file to download.
18+
* @return [ByteArray] of the file.
1919
*/
2020
@Throws(IOException::class, java.io.FileNotFoundException::class)
2121
suspend fun load(context: Context, url: URL) =

apng_library/src/main/java/oupson/apng/decoder/ApngDecoder.kt

Lines changed: 220 additions & 86 deletions
Large diffs are not rendered by default.

app-test/src/main/java/oupson/apngcreator/fragments/ApngDecoderFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ApngDecoderFragment : Fragment() {
4444

4545
override fun onError(error: Exception) {
4646
if (BuildConfig.DEBUG)
47-
Log.e(TAG, "onError", error)
47+
Log.e(TAG, "onError : $error")
4848
}
4949
})
5050
}

app-test/src/main/java/oupson/apngcreator/fragments/JavaFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.jetbrains.annotations.NotNull;
1616

1717
import oupson.apng.decoder.ApngDecoder;
18+
import oupson.apngcreator.BuildConfig;
1819
import oupson.apngcreator.R;
1920

2021

@@ -24,7 +25,8 @@ public class JavaFragment extends Fragment {
2425
@Override
2526
public View onCreateView(LayoutInflater inflater, ViewGroup container,
2627
Bundle savedInstanceState) {
27-
Log.i(TAG, "onCreateView()");
28+
if (BuildConfig.DEBUG)
29+
Log.i(TAG, "onCreateView()");
2830

2931
View v = inflater.inflate(R.layout.fragment_java, container, false);
3032

@@ -49,12 +51,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
4951
ApngDecoder.decodeApngAsyncInto(context, imageUrl, imageView, 1f, new ApngDecoder.Callback() {
5052
@Override
5153
public void onSuccess(@NotNull Drawable drawable) {
52-
Log.i(TAG, "Success");
54+
if (BuildConfig.DEBUG)
55+
Log.i(TAG, "Success");
5356
}
5457

5558
@Override
5659
public void onError(@NotNull Exception error) {
57-
Log.e(TAG, "Error", error);
60+
if (BuildConfig.DEBUG)
61+
Log.e(TAG, "Error : " + error.toString());
5862
}
5963
});
6064

app-test/src/main/java/oupson/apngcreator/fragments/KotlinFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ class KotlinFragment : Fragment() {
8787
})
8888

8989
if (animator == null) {
90-
animator = apngImageView?.loadApng(imageUrls[selected])?.apply {
91-
onLoaded {
92-
setOnFrameChangeLister {
93-
// Log.e("app-test", "onLoop")
90+
try {
91+
animator = apngImageView?.loadApng(imageUrls[selected])?.apply {
92+
onLoaded {
93+
setOnFrameChangeLister {
94+
// Log.e("app-test", "onLoop")
95+
}
9496
}
9597
}
98+
} catch (e : Exception) {
99+
if (BuildConfig.DEBUG)
100+
Log.e(TAG, "Error : $e")
96101
}
97102
}
98103

app-test/src/main/res/layout/activity_viewer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:layout_width="match_parent"
55
android:layout_height="match_parent">
66

7-
<ImageView
7+
<androidx.appcompat.widget.AppCompatImageView
88
android:id="@+id/viewerImageView"
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent"

app-test/src/main/res/layout/fragment_kotlin.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent">
1111

12-
<ImageView
12+
<androidx.appcompat.widget.AppCompatImageView
1313
android:id="@+id/ApngImageView"
1414
android:layout_width="0dp"
1515
android:layout_height="0dp"
@@ -22,7 +22,7 @@
2222
app:layout_constraintTop_toTopOf="parent"
2323
android:contentDescription="@string/description_viewer_imageView"/>
2424

25-
<ImageView
25+
<androidx.appcompat.widget.AppCompatImageView
2626
android:id="@+id/NormalImageView"
2727
android:layout_width="0dp"
2828
android:layout_height="0dp"
@@ -36,7 +36,7 @@
3636
app:layout_constraintTop_toBottomOf="@id/ApngImageView"
3737
android:contentDescription="@string/description_viewer_imageView" />
3838

39-
<SeekBar
39+
<androidx.appcompat.widget.AppCompatSeekBar
4040
android:id="@+id/SpeedSeekBar"
4141
style="@style/Widget.AppCompat.SeekBar"
4242
android:layout_width="0dp"
@@ -49,24 +49,26 @@
4949
app:layout_constraintEnd_toEndOf="parent"
5050
app:layout_constraintStart_toStartOf="parent" />
5151

52-
<Button
52+
<androidx.appcompat.widget.AppCompatButton
5353
android:id="@+id/PlayButton"
54-
style="@android:style/Widget.Material.Light.Button.Borderless.Colored"
54+
android:theme="@style/Widget.AppCompat.Button.Borderless.Colored"
55+
android:backgroundTint="@color/colorPrimary"
5556
android:layout_width="wrap_content"
5657
android:layout_height="wrap_content"
5758
android:layout_marginStart="8dp"
58-
android:background="@android:color/white"
59+
android:textColor="@color/control"
5960
android:text="@string/title_playButton"
6061
app:layout_constraintBottom_toBottomOf="parent"
6162
app:layout_constraintStart_toStartOf="parent" />
6263

63-
<Button
64+
<androidx.appcompat.widget.AppCompatButton
6465
android:id="@+id/PauseButton"
65-
style="@style/Widget.AppCompat.Button.Borderless.Colored"
66+
android:theme="@style/Widget.AppCompat.Button.Borderless.Colored"
67+
android:backgroundTint="@color/colorPrimary"
6668
android:layout_width="wrap_content"
6769
android:layout_height="wrap_content"
6870
android:layout_marginEnd="8dp"
69-
android:background="@android:color/white"
71+
android:textColor="@color/control"
7072
android:text="@string/title_pauseButton"
7173
app:layout_constraintBottom_toBottomOf="parent"
7274
app:layout_constraintEnd_toEndOf="parent" />

app-test/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/is_theme_light</item>
1515
<item name="android:navigationBarColor">@color/colorPrimary</item>
1616
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">@bool/nav_bar_light</item>
17+
<item name="colorControlHighlight">@color/colorPrimary</item>
1718
</style>
1819

1920
<style name="AppShapeAppearance.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">

0 commit comments

Comments
 (0)