parent
e6d8dd6bd3
commit
8fb0fe4d4e
@ -0,0 +1,43 @@ |
|||||||
|
package com.example.open_nsfw_android |
||||||
|
|
||||||
|
import android.graphics.Bitmap |
||||||
|
import android.graphics.BitmapFactory |
||||||
|
import android.os.Bundle |
||||||
|
import android.support.design.widget.Snackbar |
||||||
|
import android.support.v7.app.AppCompatActivity |
||||||
|
import android.util.Log |
||||||
|
import android.widget.Toast |
||||||
|
import com.bumptech.glide.Glide |
||||||
|
import com.zwy.nsfw.kotlin.getNsfwScore |
||||||
|
|
||||||
|
import kotlinx.android.synthetic.main.activity_main2.* |
||||||
|
|
||||||
|
class Main2Activity : AppCompatActivity() { |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_main2) |
||||||
|
bt.setOnClickListener { |
||||||
|
if (et.text.toString().isNotBlank()) { |
||||||
|
Thread(Runnable { |
||||||
|
try { |
||||||
|
val file = Glide.with(this) |
||||||
|
.load(et.text.toString()) |
||||||
|
.downloadOnly(120, 120).get() |
||||||
|
val nsfwBean = file.getNsfwScore(assets) |
||||||
|
runOnUiThread { |
||||||
|
iv.setImageBitmap(BitmapFactory.decodeFile(file.path)) |
||||||
|
tv.text = "nsfw:${nsfwBean.nsfw} \n sfw:${nsfwBean.sfw} " |
||||||
|
} |
||||||
|
} catch (e: Exception) { |
||||||
|
runOnUiThread { |
||||||
|
Toast.makeText(this, "图片载入失败,请重试", 0).show() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
}).start() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:orientation="vertical" |
||||||
|
tools:context=".Main2Activity"> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:orientation="horizontal"> |
||||||
|
|
||||||
|
<EditText |
||||||
|
android:id="@+id/et" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="50dp" |
||||||
|
android:layout_weight="1" |
||||||
|
android:background="@null" |
||||||
|
android:hint="粘贴网络图片路径" |
||||||
|
android:padding="15dp" /> |
||||||
|
|
||||||
|
<Button |
||||||
|
android:id="@+id/bt" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="50dp" |
||||||
|
android:layout_weight="0.3" |
||||||
|
android:text="识别" /> |
||||||
|
</LinearLayout> |
||||||
|
|
||||||
|
<View |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="1dp" |
||||||
|
android:background="#504d4d4d" /> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/tv" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:gravity="center" |
||||||
|
android:textColor="#FA3C00" |
||||||
|
android:padding="20dp" |
||||||
|
android:text="这里显示检测结果" /> |
||||||
|
|
||||||
|
<ImageView |
||||||
|
android:id="@+id/iv" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:padding="15dp"/> |
||||||
|
</LinearLayout> |
After Width: | Height: | Size: 83 KiB |
@ -0,0 +1,3 @@ |
|||||||
|
<resources> |
||||||
|
<dimen name="fab_margin">16dp</dimen> |
||||||
|
</resources> |
@ -1,4 +1,5 @@ |
|||||||
<resources> |
<resources> |
||||||
<string name="app_name">离线鉴黄</string> |
<string name="app_name">离线鉴黄</string> |
||||||
<string name="str_bt1">识别Assets下图片</string> |
<string name="str_bt1">识别Assets下图片</string> |
||||||
|
<string name="title_activity_main2">网络图片识别,你懂的</string> |
||||||
</resources> |
</resources> |
||||||
|
Loading…
Reference in new issue