mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-05 18:20:32 +08:00
v1.2
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
||||
applicationId "top.fumiama.base16384"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 5
|
||||
versionName '1.1.2.1'
|
||||
versionCode 6
|
||||
versionName '1.2'
|
||||
resConfigs "zh", "en"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -22,7 +22,6 @@ android {
|
||||
cppFlags ""
|
||||
}
|
||||
}
|
||||
multiDexEnabled = false
|
||||
}
|
||||
|
||||
/*signingConfigs {
|
||||
@@ -68,4 +67,4 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Rect
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
@@ -25,39 +26,16 @@ class MainActivity : Activity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
sv.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val h = sv.getChildAt(0).height
|
||||
tti.visibility = if(h > resources.displayMetrics.heightPixels) View.GONE else View.VISIBLE
|
||||
}
|
||||
sv.viewTreeObserver.addOnGlobalLayoutListener { setTitleVisibility() }
|
||||
fab.setOnClickListener { if(checkReadPermission()) pickFile() }
|
||||
ben.setOnClickListener {
|
||||
ten.text?.let {
|
||||
if(it.isNotEmpty()){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
inputFile.writeText(it.toString(), Charsets.UTF_16BE)
|
||||
encode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
tde.setText(outputFile.readText(Charsets.UTF_16BE))
|
||||
copyText(tde, cm)
|
||||
}
|
||||
}
|
||||
}
|
||||
bde.setOnClickListener {
|
||||
tde.text?.let {
|
||||
if(it.isNotEmpty()){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
inputFile.writeText(it.toString(), Charsets.UTF_16BE)
|
||||
decode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
ten.setText(outputFile.readText(Charsets.UTF_16BE))
|
||||
copyText(ten, cm)
|
||||
}
|
||||
}
|
||||
}
|
||||
ben.setOnClickListener { clickButton(true, cm) }
|
||||
bde.setOnClickListener { clickButton(false, cm) }
|
||||
tti.setOnLongClickListener {
|
||||
AlertDialog.Builder(this).setTitle(R.string.info).setMessage(R.string.info_content).setIcon(R.mipmap.ic_launcher).show()
|
||||
true
|
||||
}
|
||||
setLongPress2Paste(ten, cm)
|
||||
setLongPress2Paste(tde, cm)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@@ -81,19 +59,6 @@ class MainActivity : Activity() {
|
||||
}
|
||||
}
|
||||
|
||||
/*private fun packZip(zipf: File, outf: File){
|
||||
zipf.parentFile?.let { if(!it.exists()) it.mkdirs() }
|
||||
if(zipf.exists()) zipf.delete()
|
||||
zipf.createNewFile()
|
||||
val zip = ZipOutputStream(CheckedOutputStream(zipf.outputStream(), CRC32()))
|
||||
zip.setLevel(9)
|
||||
zip.putNextEntry(ZipEntry("output"))
|
||||
zip.write(outf.readBytes())
|
||||
zip.flush()
|
||||
zip.close()
|
||||
}*/
|
||||
|
||||
|
||||
private fun doFromFile(uri: Uri){
|
||||
val inputFile = generateCacheFile("input")
|
||||
val outputFile = generateCacheFile("output")
|
||||
@@ -147,21 +112,6 @@ class MainActivity : Activity() {
|
||||
startActivityForResult(intent, 2)
|
||||
}
|
||||
|
||||
/*private fun shareFile(file: File, type: String) {
|
||||
if (file.exists()) {
|
||||
val share = Intent(Intent.ACTION_SEND)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val contentUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider", file)
|
||||
share.putExtra(Intent.EXTRA_STREAM, contentUri)
|
||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}else share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
|
||||
share.type = type //此处可发送多种文件
|
||||
share.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(Intent.createChooser(share, getString(R.string.share)))
|
||||
} else Toast.makeText(this, getString(R.string.read_file_err), Toast.LENGTH_SHORT).show()
|
||||
}*/
|
||||
|
||||
private fun checkReadPermission(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N && ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
@@ -186,12 +136,41 @@ class MainActivity : Activity() {
|
||||
|
||||
private fun copyText(t: TextInputEditText, cm: ClipboardManager){
|
||||
if(t.text?.isNotEmpty() == true) {
|
||||
//t.selectAll()
|
||||
ClipData.newPlainText(getString(R.string.app_name), t.text)?.let { cm.setPrimaryClip(it) }
|
||||
Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, getString(R.string.copied)+t.text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setLongPress2Paste(t: TextInputEditText, cm: ClipboardManager){
|
||||
t.setOnLongClickListener {
|
||||
if(t.text?.isEmpty() == true) t.setText(cm.primaryClip?.getItemAt(0)?.text)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun clickButton(isEncode: Boolean, cm:ClipboardManager){
|
||||
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)
|
||||
if(isEncode) encode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
else decode(inputFile.absolutePath, outputFile.absolutePath)
|
||||
tou.setText(outputFile.readText(Charsets.UTF_16BE))
|
||||
copyText(tou, cm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTitleVisibility(){
|
||||
val h = sv.getChildAt(0).height
|
||||
val r = Rect()
|
||||
window.decorView.rootView.getWindowVisibleDisplayFrame(r)
|
||||
tti.visibility = if(h > r.bottom) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'native-lib' native library,
|
||||
* which is packaged with this application.
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout2"
|
||||
<ScrollView
|
||||
android:id="@+id/sv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@@ -15,61 +16,51 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/sv"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/stxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_original" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/ben"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
android:text="@string/encode" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/stxt"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/dtxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/tde"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_original" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/ben"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/encode" />
|
||||
android:hint="@string/text_encoded" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/dtxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/tde"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_encoded" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bde"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/decode" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<Button
|
||||
android:id="@+id/bde"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/decode" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tti"
|
||||
@@ -79,7 +70,7 @@
|
||||
android:text="@string/app_name"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="36sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/constraintLayout2"
|
||||
app:layout_constraintBottom_toTopOf="@+id/sv"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
9
app/src/main/res/values-night/styles.xml
Normal file
9
app/src/main/res/values-night/styles.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:fitsSystemWindows">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorAccent">#F6837A</color>
|
||||
</resources>
|
||||
@@ -2,13 +2,9 @@
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:colorAccent">@color/colorAccent</item>
|
||||
<item name="colorPrimarySurface">@color/colorAccent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<item name="android:fitsSystemWindows">false</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:fitsSystemWindows">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user