This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
187 changed files
with
184 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 90 additions & 15 deletions
105
app/src/main/java/com/example/open_nsfw_android/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,120 @@ | ||
package com.example.open_nsfw_android | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Intent | ||
import android.graphics.BitmapFactory | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.view.View | ||
import com.luck.picture.lib.PictureSelector | ||
import com.luck.picture.lib.config.PictureConfig | ||
import com.luck.picture.lib.config.PictureMimeType | ||
import com.luck.picture.lib.entity.LocalMedia | ||
import com.zwy.nsfw.api.NsfwHelper | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
class MainActivity : AppCompatActivity(), View.OnClickListener { | ||
|
||
var nsfwHelper: NsfwHelper? = null | ||
var mainAdapter: MainAdapter? = null | ||
var index = 0 | ||
val listData: ArrayList<MyNsfwBean> = ArrayList<MyNsfwBean>() | ||
@SuppressLint("SetTextI18n") | ||
var listData: ArrayList<MyNsfwBean> = ArrayList<MyNsfwBean>() | ||
var selectList: List<LocalMedia>? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
//assets 目录下的timg-10.jpeg为正常静态图片 ccc.gif 为动态正常图片 可用作测试 | ||
// val b = BitmapFactory.decodeStream(resources.assets.open("img/06 (1).jpg")) | ||
// iv.setImageBitmap(b) | ||
nsfwHelper = NsfwHelper.getInstance(this, true, 1) | ||
initNsfwHelper() | ||
initAdapter() | ||
initClickListener() | ||
} | ||
|
||
override fun onClick(v: View) { | ||
when (v.id) { | ||
R.id.bt_sc_assets -> { | ||
reScAssetsImgs() | ||
} | ||
R.id.bt_sc_from_other -> { | ||
PictureSelector.create(this) | ||
.openGallery(PictureMimeType.ofImage())//全部.ofAll()、图片.、视频.ofVideo()、音频.ofAudio() | ||
.maxSelectNum(20)// 最大图片选择数量 int | ||
.minSelectNum(1)// 最小选择数量 int | ||
.imageSpanCount(3)// 每行显示个数 int | ||
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 or PictureConfig.SINGLE | ||
.previewImage(true)// 是否可预览图片 true or false | ||
.isCamera(false)// 是否显示拍照按钮 true or false | ||
.isZoomAnim(true)// 图片列表点击 缩放效果 默认true | ||
.selectionMedia(selectList) | ||
.sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效 | ||
.previewEggs(true)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false | ||
.forResult(0x01);//结果回调onActivityResult code | ||
} | ||
} | ||
} | ||
|
||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
if (requestCode == 0x01 && resultCode == RESULT_OK) { | ||
selectList = PictureSelector.obtainMultipleResult(data) | ||
if (selectList != null && selectList?.size ?: 0 > 0) | ||
reScFromImgs(selectList!!) | ||
} | ||
} | ||
|
||
|
||
private fun initClickListener() { | ||
bt_sc_assets.setOnClickListener(this) | ||
bt_sc_from_other.setOnClickListener(this) | ||
} | ||
|
||
private fun initAdapter() { | ||
mainAdapter = MainAdapter(null) | ||
rv.layoutManager = LinearLayoutManager(this) | ||
rv.adapter = mainAdapter | ||
tv_start.setOnClickListener { | ||
for (a in resources.assets.list("img")) { | ||
val path = "img/${a}" | ||
val b = BitmapFactory.decodeStream(resources.assets.open(path)) | ||
listData.add(MyNsfwBean(0f, 0f, path, b)) | ||
nsfwHelper?.scanBitmap(b) { sfw, nsfw -> | ||
} | ||
|
||
private fun initNsfwHelper() { | ||
nsfwHelper = NsfwHelper.getInstance(this, false, 1) | ||
} | ||
|
||
private fun reScFromImgs(list: List<LocalMedia>) { | ||
index = 0 | ||
mainAdapter?.setNewData(null) | ||
listData = ArrayList<MyNsfwBean>() | ||
Thread(Runnable { | ||
for (lm in list) { | ||
val bitmap = BitmapFactory.decodeFile(lm.path) | ||
listData.add(MyNsfwBean(0.0f, 0.0f, lm.path, bitmap)) | ||
nsfwHelper?.scanBitmap(bitmap) { sfw, nsfw -> | ||
listData[index].sfw = sfw | ||
listData[index].nsfw = nsfw | ||
mainAdapter?.addData(listData[index]) | ||
mainAdapter?.notifyItemInserted(index) | ||
rv.scrollToPosition(index) | ||
index++ | ||
} | ||
} | ||
}).start() | ||
} | ||
|
||
private fun reScAssetsImgs() { | ||
index = 0 | ||
mainAdapter?.setNewData(null) | ||
listData = ArrayList<MyNsfwBean>() | ||
for (a in resources.assets.list("img")) { | ||
val path = "img/${a}" | ||
val b = BitmapFactory.decodeStream(resources.assets.open(path)) | ||
listData.add(MyNsfwBean(0f, 0f, path, b)) | ||
nsfwHelper?.scanBitmap(b) { sfw, nsfw -> | ||
listData[index].sfw = sfw | ||
listData[index].nsfw = nsfw | ||
mainAdapter?.addData(listData[index]) | ||
mainAdapter?.notifyItemInserted(index) | ||
rv.scrollToPosition(index) | ||
index++ | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<resources> | ||
<string name="app_name">离线鉴黄</string> | ||
<string name="str_bt1">识别Assets下图片</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
<manifest package="com.zwy.nsfw" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
</manifest> |
Oops, something went wrong.