Skip to content

Commit

Permalink
迁移仓库
Browse files Browse the repository at this point in the history
  • Loading branch information
devzwy committed Apr 22, 2021
1 parent e09312c commit 0317d3e
Show file tree
Hide file tree
Showing 22 changed files with 617 additions and 587 deletions.
15 changes: 12 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ dependencies {
kapt 'com.github.bumptech.glide:compiler:4.11.0'


implementation 'com.zwy.nsfw:nsfw_initializer:1.3.9'
implementation 'com.zwy.nsfw:nsfw:1.3.9'
// implementation 'com.zwy.nsfw:nsfw_initializer:1.3.9'
// implementation 'com.zwy.nsfw:nsfw:1.3.9'
implementation 'org.tensorflow:tensorflow-lite:2.1.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.1.0'

// implementation project(path: ':nsfw_initializer')
// implementation project(path: ':nsfw')
implementation project(path: ':nsfw')
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:name=".KtApp"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/zww/sample/JavaApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.zww.sample;

import android.annotation.SuppressLint;
import android.app.Application;
import android.widget.Toast;

import io.github.devzwy.nsfw.NSFWHelper;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;

public class JavaApp extends Application {
@SuppressLint("NewApi")
@Override
public void onCreate() {
super.onCreate();
NSFWHelper.INSTANCE.initHelper(this, this.getFilesDir().getPath() + "/nsfw.tflite", true, 4, new Function0<Unit>() {
@Override
public Unit invoke() {
Toast.makeText(JavaApp.this, "初始化成功", Toast.LENGTH_SHORT).show();
return null;
}
}, new Function1<String, Unit>() {
@Override
public Unit invoke(String s) {
Toast.makeText(JavaApp.this, s, Toast.LENGTH_SHORT).show();
return null;
}
});
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/zww/sample/KtApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.zww.sample

import android.app.Application
import android.widget.Toast
import io.github.devzwy.nsfw.NSFWHelper

class KtApp:Application() {
override fun onCreate() {
super.onCreate()
NSFWHelper.openDebugLog()
NSFWHelper.initHelper(
context = this,
modelPath = "${this.filesDir.path}/nsfw.tflite",
isOpenGPU = true,
onInitError = {
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
},
onInitSuccess = {
Toast.makeText(this, "初始化成功", Toast.LENGTH_SHORT).show()
})
}
}
65 changes: 48 additions & 17 deletions app/src/main/java/com/zww/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zwy.nsfw.NSFWScoreBean
import com.zwy.nsfw.getNSFWScore
import io.github.devzwy.nsfw.NSFWHelper
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
import kotlin.random.Random


class MainActivity : BaseActivity() {
override fun initData() {
Expand All @@ -23,35 +22,67 @@ class MainActivity : BaseActivity() {
object : BaseQuickAdapter<MyNSFWBean, BaseViewHolder>(R.layout.item_main) {
@SuppressLint("SetTextI18n")
override fun convert(holder: BaseViewHolder, item: MyNSFWBean) {
Glide.with(this@MainActivity).load(item.bitmap).into(holder.getView(R.id.iv))
Glide.with(this@MainActivity).load(item.bitmap)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.getView(R.id.iv))
holder.getView<TextView>(R.id.tv).apply {
item.nsfwScoreBean.let {
NSFWHelper.getNSFWScore(item.bitmap) {
this.text =
"nsfw:${it.nsfwScore}\nsfw:${it.sfwScore}\n扫描耗时:${it.timeConsumingToScanData} ms"
if (it.nsfwScore>0.7){
if (it.nsfwScore > 0.7) {
this.setBackgroundColor(Color.parseColor("#C1FF0000"))
}else if (it.nsfwScore>0.5){
} else if (it.nsfwScore > 0.5) {
this.setBackgroundColor(Color.parseColor("#C1FF9800"))
}else {
} else {
this.setBackgroundColor(Color.parseColor("#803700B3"))
}
}


// item.nsfwScoreBean.let {
// this.text =
// "nsfw:${it.nsfwScore}\nsfw:${it.sfwScore}\n扫描耗时:${it.timeConsumingToScanData} ms"
// if (it.nsfwScore > 0.7) {
// this.setBackgroundColor(Color.parseColor("#C1FF0000"))
// } else if (it.nsfwScore > 0.5) {
// this.setBackgroundColor(Color.parseColor("#C1FF9800"))
// } else {
// this.setBackgroundColor(Color.parseColor("#803700B3"))
// }
// }
}

}
}.also { adapter ->
adapter.setAnimationWithDefault(BaseQuickAdapter.AnimationType.ScaleIn)
adapter.isAnimationFirstOnly = false

resources.assets.also { asset ->
asset.list("img")?.forEach {
"img/$it".also { assetFilePath ->
BitmapFactory.decodeStream(asset.open(assetFilePath)).also {
adapter.addData(MyNSFWBean(it.getNSFWScore(), it))
Thread(Runnable {


for (i in 1..50) {

BitmapFactory.decodeStream(
resources.assets.open(
"img/${
resources.assets.list(
"img"
)!![Random.nextInt(
1, resources.assets.list(
"img"
)!!.size
)]
}"
)
).also { bitmap ->
runOnUiThread {
adapter.addData(MyNSFWBean(bitmap))
}

}
}
}

}).start()

}
}
Expand All @@ -62,4 +93,4 @@ class MainActivity : BaseActivity() {
}
}

data class MyNSFWBean(val nsfwScoreBean: NSFWScoreBean, val bitmap: Bitmap)
data class MyNSFWBean(val bitmap: Bitmap)
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
buildscript {
ext.kotlin_version = '1.3.72'
ext.libVersion = '1.3.9'
ext.libVersion = '1.5.0'
repositories {
google()
jcenter()
google()
mavenCentral()
}
dependencies {
Expand All @@ -17,8 +17,8 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
google()
mavenCentral()
}

Expand Down
Loading

0 comments on commit 0317d3e

Please sign in to comment.