mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-05 18:20:32 +08:00
v1.3
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
||||
applicationId "top.fumiama.base16384"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 6
|
||||
versionName '1.2'
|
||||
versionCode 7
|
||||
versionName '1.3'
|
||||
resConfigs "zh", "en"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -10,8 +10,8 @@
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"versionCode": 6,
|
||||
"versionName": "1.2",
|
||||
"versionCode": 7,
|
||||
"versionName": "1.3",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -13,23 +13,36 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ListAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import top.fumiama.base16384.tools.PropertiesTools
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class MainActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val pCharsets = PropertiesTools(File(filesDir, "charsets.prop"))
|
||||
sv.viewTreeObserver.addOnGlobalLayoutListener { setTitleVisibility() }
|
||||
fab.setOnClickListener { if(checkReadPermission()) pickFile() }
|
||||
ben.setOnClickListener { clickButton(true, cm) }
|
||||
bde.setOnClickListener { clickButton(false, cm) }
|
||||
fab.setOnClickListener { pickFile() }
|
||||
ben.setOnClickListener { clickButton(true, cm, pCharsets) }
|
||||
bde.setOnClickListener { clickButton(false, cm, pCharsets) }
|
||||
ben.setOnLongClickListener {
|
||||
callCharsetSelectList(true, pCharsets)
|
||||
false
|
||||
}
|
||||
bde.setOnLongClickListener {
|
||||
callCharsetSelectList(false, pCharsets)
|
||||
false
|
||||
}
|
||||
tti.setOnLongClickListener {
|
||||
AlertDialog.Builder(this).setTitle(R.string.info).setMessage(R.string.info_content).setIcon(R.mipmap.ic_launcher).show()
|
||||
true
|
||||
@@ -46,19 +59,6 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<String?>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
when (requestCode) {
|
||||
1 -> {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) pickFile()
|
||||
else Toast.makeText(this, R.string.permissionDenied, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun doFromFile(uri: Uri){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
@@ -112,20 +112,6 @@ class MainActivity : Activity() {
|
||||
startActivityForResult(intent, 2)
|
||||
}
|
||||
|
||||
private fun checkReadPermission(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N && ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
|
||||
1
|
||||
)
|
||||
false
|
||||
} else true
|
||||
}
|
||||
|
||||
private fun pickFile() {
|
||||
val i = Intent(Intent.ACTION_GET_CONTENT)
|
||||
i.type = "*/*"
|
||||
@@ -148,17 +134,17 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun clickButton(isEncode: Boolean, cm:ClipboardManager){
|
||||
private fun clickButton(isEncode: Boolean, cm:ClipboardManager, pc: PropertiesTools){
|
||||
val tin = if(isEncode)ten else tde
|
||||
val tou = if(isEncode)tde else ten
|
||||
tin.text?.let {
|
||||
if(it.isNotEmpty()){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
inputFile.writeText(it.toString(), Charsets.UTF_16BE)
|
||||
inputFile.writeText(it.toString(), getCharset(getCustomCharsetPosition(isEncode, pc)))
|
||||
if(isEncode) encode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
else decode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
tou.setText(outputFile.readText(Charsets.UTF_16BE))
|
||||
tou.setText(outputFile.readText(getCharset(getCustomCharsetPosition(!isEncode, pc))))
|
||||
copyText(tou, cm)
|
||||
}
|
||||
}
|
||||
@@ -171,6 +157,41 @@ class MainActivity : Activity() {
|
||||
tti.visibility = if(h > r.bottom) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
private fun callCharsetSelectList(isEncode: Boolean, pc: PropertiesTools){
|
||||
val charsetsArr = resources.getStringArray(R.array.charsets)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.select_charset)
|
||||
.setIcon(R.mipmap.ic_launcher)
|
||||
.setSingleChoiceItems(ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, charsetsArr), getCustomCharsetPosition(isEncode, pc)){ d, p ->
|
||||
setCustomCharsetPosition(p, isEncode, pc)
|
||||
d.cancel()
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun getCustomCharsetPosition(isEncode: Boolean, pc: PropertiesTools): Int{
|
||||
val cs = if(isEncode) pc["encode"] else pc["decode"]
|
||||
return if(cs == "null"){
|
||||
if(isEncode) 8 else 3
|
||||
}else cs.toInt()
|
||||
}
|
||||
|
||||
private fun setCustomCharsetPosition(p: Int, isEncode: Boolean, pc: PropertiesTools){
|
||||
pc[if(isEncode) "encode" else "decode"] = p.toString()
|
||||
}
|
||||
|
||||
private fun getCharset(p: Int) = when (p) {
|
||||
0 -> Charsets.ISO_8859_1
|
||||
1 -> Charsets.US_ASCII
|
||||
2 -> Charsets.UTF_16
|
||||
3 -> Charsets.UTF_16BE
|
||||
4 -> Charsets.UTF_16LE
|
||||
5 -> Charsets.UTF_32
|
||||
6 -> Charsets.UTF_32BE
|
||||
7 -> Charsets.UTF_32LE
|
||||
8 -> Charsets.UTF_8
|
||||
else -> Charset.defaultCharset()
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'native-lib' native library,
|
||||
* which is packaged with this application.
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package top.fumiama.base16384.tools
|
||||
//PropertiesTools.kt
|
||||
//created by fumiama 20200724
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
class PropertiesTools(private val f: File):Properties() {
|
||||
private val propfile:File
|
||||
get() {
|
||||
if(!f.exists()) {
|
||||
if(f.parentFile?.exists() != true) f.parentFile?.mkdirs()
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
createNew(f)
|
||||
}else if(f.isDirectory) {
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
f.delete()
|
||||
createNew(f)
|
||||
}
|
||||
if(f.parentFile?.canWrite() != true) f.parentFile?.setWritable(true)
|
||||
if(f.parentFile?.canRead() != true) f.parentFile?.setReadable(true)
|
||||
return f
|
||||
}
|
||||
private fun createNew(f: File){
|
||||
f.createNewFile()
|
||||
val o = f.outputStream()
|
||||
this.storeToXML(o, "store")
|
||||
Log.d("MyPT", "Generate new prop.")
|
||||
o.close()
|
||||
}
|
||||
private fun loadFromXml(`in`: InputStream?): PropertiesTools {
|
||||
this.loadFromXML(`in`)
|
||||
return this
|
||||
}
|
||||
private fun setProp(key: String?, value: String?): PropertiesTools {
|
||||
this.setProperty(key, value)
|
||||
return this
|
||||
}
|
||||
operator fun get(key: String): String{
|
||||
val i = propfile.inputStream()
|
||||
val re = this.loadFromXml(i).getProperty(key)?:"null"
|
||||
Log.d("MyPT", "Get $key = $re")
|
||||
i.close()
|
||||
return re
|
||||
}
|
||||
operator fun set(key: String, value: String){
|
||||
val o = propfile.outputStream()
|
||||
this.setProp(key, value).storeToXML(o, "store")
|
||||
Log.d("MyPT", "Set $key = $value")
|
||||
o.close()
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,5 @@
|
||||
<string name="info">关于</string>
|
||||
<string name="info_content">作者:源文雨。感谢咲桜动漫社成员的支持。</string>
|
||||
<string name="copied">已复制</string>
|
||||
<string name="select_charset">选择字符集</string>
|
||||
</resources>
|
||||
14
app/src/main/res/values/charsets.xml
Normal file
14
app/src/main/res/values/charsets.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="charsets">
|
||||
<item>ISO_8859_1</item>
|
||||
<item>US_ASCII</item>
|
||||
<item>UTF_16</item>
|
||||
<item>UTF_16BE</item>
|
||||
<item>UTF_16LE</item>
|
||||
<item>UTF_32</item>
|
||||
<item>UTF_32BE</item>
|
||||
<item>UTF_32LE</item>
|
||||
<item>UTF_8</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -13,6 +13,7 @@
|
||||
<string name="decode_succeed">Decode Succeed</string>
|
||||
<string name="encode_succeed">Encode Succeed</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="info_content">Author: Fumiama, with precious supports of the members in Sakura Anime Club.</string>
|
||||
<string name="info_content">Author: Fumiama, with precious supports from the members in Sakura Anime Club.</string>
|
||||
<string name="copied">Copied Text</string>
|
||||
<string name="select_charset">Select Charset</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user