1
0
mirror of https://github.com/fumiama/simple-dict-android.git synced 2026-06-12 14:10:26 +08:00
This commit is contained in:
fumiama
2021-02-18 00:27:11 +08:00
parent 85428c591c
commit c82f715f55
8 changed files with 41 additions and 30 deletions

View File

@@ -13,8 +13,8 @@ android {
applicationId "top.fumiama.simpledict" applicationId "top.fumiama.simpledict"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
versionCode 3 versionCode 4
versionName '1.1.1' versionName '1.2'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -54,7 +54,6 @@ android {
} }
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
@@ -82,7 +81,6 @@ andResGuard {
// it's always better to remove duplicated resource from repo // it's always better to remove duplicated resource from repo
mergeDuplicatedRes = true mergeDuplicatedRes = true
whiteList = [ whiteList = [
"R.drawable.load",
// your icon // your icon
"R.drawable.icon", "R.drawable.icon",
// for fabric // for fabric
@@ -94,14 +92,9 @@ andResGuard {
"R.string.ga_trackingId", "R.string.ga_trackingId",
"R.string.firebase_database_url", "R.string.firebase_database_url",
"R.string.google_api_key", "R.string.google_api_key",
"R.string.google_crash_reporting_api_key", "R.string.google_crash_reporting_api_key"
"R.font.*"
] ]
compressFilePattern = [ compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
"resources.arsc" "resources.arsc"
] ]
sevenzip { sevenzip {

View File

@@ -57,27 +57,27 @@ class Client(val ip: String, val port: Int) {
} }
} }
fun receiveRawMessage()= try { fun receiveRawMessage() : ByteArray {
var re = byteArrayOf()
try {
if (isConnect) { if (isConnect) {
Log.d("MyC", "开始接收服务端信息") Log.d("MyC", "开始接收服务端信息")
val inMessage = ByteArray(1024) //设置接受缓冲,避免接受数据过长占用过多内存 val inMessage = ByteArray(4096) //设置接受缓冲,避免接受数据过长占用过多内存
val a = din?.read(inMessage) //a存储返回消息的长度 var a: Int
if (a == null || a <= -1) null do {
else { a = din?.read(inMessage)?:0 //a存储返回消息的长度
Log.d("MyC", "reply length:$a") Log.d("MyC", "reply length:$a: ${inMessage.decodeToString()}")
inMessage.copyOf(a) re += inMessage.copyOf(a)
} } while (a == 4096)
} else { } else Log.d("MyC", "no connect to receive message")
Log.d("MyC", "no connect to receive message")
null
}
} catch (e: IOException) { } catch (e: IOException) {
Log.d("MyC", "receive message failed") Log.d("MyC", "receive message failed")
e.printStackTrace() e.printStackTrace()
null
} }
return re
}
fun receiveMessage() = receiveRawMessage()?.decodeToString() fun receiveMessage() = receiveRawMessage().decodeToString()
/** /**
* 关闭连接 * 关闭连接

View File

@@ -6,13 +6,13 @@ import java.lang.Thread.sleep
class SimpleDict(private val client: Client, private val pwd: String) { //must run in thread class SimpleDict(private val client: Client, private val pwd: String) { //must run in thread
private var dict = HashMap<String, String?>() private var dict = HashMap<String, String?>()
val keys get() = dict.keys val keys get() = dict.keys
val values get() = dict.values //val values get() = dict.values
//val size get() = dict.size //val size get() = dict.size
private val raw: ByteArray? private val raw: ByteArray
get() { get() {
initDict() initDict()
client.sendMessage("cat") client.sendMessage("cat")
sleep(233) sleep(2333)
val re = client.receiveRawMessage() val re = client.receiveRawMessage()
closeDict() closeDict()
return re return re
@@ -47,7 +47,7 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
fun fetchDict() { fun fetchDict() {
val dictBlock = ByteArray(128) val dictBlock = ByteArray(128)
raw?.inputStream()?.let { raw.inputStream().let {
var c = '1' var c = '1'
while (!it.read().toChar().isDigit()) Log.d("MySD", "Skip banner.") while (!it.read().toChar().isDigit()) Log.d("MySD", "Skip banner.")
while (c.isDigit()) { while (c.isDigit()) {

View File

@@ -18,6 +18,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:contentScrim="?attr/colorSurface" app:contentScrim="?attr/colorSurface"
app:layout_scrollFlags="scroll"
app:toolbarId="@+id/toolbar"> app:toolbarId="@+id/toolbar">
<com.lapism.search.widget.MaterialSearchView <com.lapism.search.widget.MaterialSearchView

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"

View File

@@ -10,7 +10,7 @@
<item name="colorSecondaryVariant">@color/teal_200</item> <item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item> <item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
</style> </style>
</resources> </resources>

Binary file not shown.

View File

@@ -0,0 +1,18 @@
{
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "top.fumiama.simpledict",
"variantName": "processWinreleaseResources",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 4,
"versionName": "1.2",
"outputFile": "app-winrelease.apk"
}
]
}