Skip to content

Commit 34893ab

Browse files
committed
Move ImageMixer from java->kotlin + fix string lint issue
1 parent e27544a commit 34893ab

File tree

5 files changed

+61
-49
lines changed

5 files changed

+61
-49
lines changed

app/src/main/java/com/camobap/imgmixer/ImageMixer.java

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.camobap.imgmixer
2+
3+
import androidx.annotation.Keep
4+
5+
import java.io.File
6+
7+
@Keep
8+
class ImageMixer(width: Int, height: Int) {
9+
10+
@Keep
11+
private var nativeHandle: Long = 0
12+
13+
init {
14+
initialize(width, height)
15+
}
16+
17+
fun load(imagePath: File) {
18+
load0(imagePath.absolutePath)
19+
}
20+
21+
fun convert(outFile: File) {
22+
convert0(outFile.absolutePath)
23+
}
24+
25+
@Keep
26+
external fun clear()
27+
28+
@Keep
29+
private external fun convert0(outPath: String)
30+
31+
@Keep
32+
private external fun load0(imagePath: String)
33+
34+
@Keep
35+
protected external fun initialize(width: Int, height: Int)
36+
37+
@Keep
38+
@Throws(Throwable::class)
39+
protected external fun finalize()
40+
41+
companion object {
42+
init {
43+
System.loadLibrary("ndk-shader-mixer")
44+
}
45+
}
46+
}

app/src/main/java/com/camobap/imgmixer/MainActivity.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import androidx.core.content.FileProvider
1313

1414
class MainActivity : AppCompatActivity() {
1515

16-
val imageMixer: ImageMixer = ImageMixer(1024, 1024)
16+
private val imageMixer: ImageMixer = ImageMixer(1024, 1024)
1717

1818
override fun onCreate(savedInstanceState: Bundle?) {
1919
super.onCreate(savedInstanceState)
@@ -26,16 +26,24 @@ class MainActivity : AppCompatActivity() {
2626
}
2727
}
2828

29-
fun doProcessing(view: View) {
29+
override fun onDestroy() {
30+
super.onDestroy()
31+
32+
imageMixer.clear()
33+
}
34+
35+
fun doProcessing(@Suppress("UNUSED_PARAMETER") view: View) {
3036
val resultFile = File(filesDir, "result.bmp")
3137

32-
imageMixer.convert(resultFile);
38+
imageMixer.convert(resultFile)
39+
40+
val authority = BuildConfig.APPLICATION_ID + ".provider"
41+
val uri = FileProvider.getUriForFile(this, authority, resultFile.absoluteFile)
3342

3443
val intent = Intent()
3544
intent.action = Intent.ACTION_VIEW
36-
val uri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", resultFile.absoluteFile)
3745
intent.setDataAndType(uri, "image/*")
38-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
46+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
3947
startActivity(intent)
4048
}
4149
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:layout_height="match_parent"
88
tools:context=".MainActivity">
99

10-
<Button android:text="Test"
10+
<Button android:text="@string/test"
1111
android:layout_width="wrap_content"
1212
android:layout_height="wrap_content"
1313
app:layout_constraintBottom_toBottomOf="parent"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">ImageMixer</string>
3+
<string name="test">Apply filter</string>
34
</resources>

0 commit comments

Comments
 (0)