Skip to content

Commit

Permalink
Merge pull request #109 from Ryosuke839/develop
Browse files Browse the repository at this point in the history
Release 2.12.0
  • Loading branch information
Ryosuke839 authored Dec 30, 2022
2 parents 4e84f54 + cf0e1c9 commit 0026b68
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 213 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "jp.ddo.hotmist.unicodepad"
minSdkVersion 16
targetSdkVersion 32
versionCode 52
versionName "2.11.0"
versionCode 53
versionName "2.12.0"
}

compileOptions {
Expand Down
Binary file removed app/src/main/assets/namedb.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ internal class CompleteAdapter(context: Context, pref: SharedPreferences) : Base
private var current = ""
fun update(str: String) {
synchronized(lock) {
for (s in str.split(" ").toTypedArray()) if (s.isNotEmpty()) {
for (s in str.split(" ", "\n").toTypedArray()) if (s.isNotEmpty()) {
(temp ?: list).let {
it.remove(s)
if (it.size == 255) it.removeAt(254)
while (it.size >= 255) it.removeAt(254)
it.add(0, s)
}
}
Expand Down
99 changes: 52 additions & 47 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/EmojiAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private
private lateinit var grp: MutableList<String>
private lateinit var idx: MutableList<Int>
private var current = pref.getInt("emoji", 0)
private var modifier = pref.getBoolean("modifier", true)
private var tone = pref.getInt("tone", 11034)
private var guard = 0
private val scrollListener = object : AbsListView.OnScrollListener {
override fun onScrollStateChanged(view: AbsListView, scrollState: Int) {}
Expand Down Expand Up @@ -78,14 +78,59 @@ internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private
val jump = Spinner(activity)
this.jump = jump
hl.addView(jump, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
val modc = CheckBox(activity)
modc.setText(R.string.modifier)
modc.setPadding(0, 0, (activity.resources.displayMetrics.density * 8f).toInt(), 0)
hl.addView(modc, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
hl.addView(Spinner(activity).apply {
val adp = ArrayAdapter(activity, android.R.layout.simple_spinner_item, listOf("", "\uD83C\uDFFB", "\uD83C\uDFFC", "\uD83C\uDFFD", "\uD83C\uDFFE", "\uD83C\uDFFF")).apply {
setDropDownViewResource(R.layout.spinner_drop_down_item)
}
adapter = adp
setSelection(adp.getPosition(Character.toChars(tone).concatToString()))
onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, v: View?, position: Int, id: Long) {
val item = adp.getItem(position)!!.codePointAt(0)
if (tone == item) return
tone = item
++guard
view.setOnScrollListener(null)
jump.onItemSelectedListener = null
jump.adapter = null
cur?.close()
cur = db.emoji(UnicodeActivity.univer, item)
map = TreeMap()
grp = ArrayList()
idx = ArrayList()
var last2 = ""
cur?.let {
it.moveToFirst()
while (!it.isAfterLast) {
val curr = it.getString(1) + " / " + it.getString(2)
if (curr == last2) {
it.moveToNext()
continue
}
last2 = curr
map[it.position] = map.size
grp.add(curr)
idx.add(it.position)
it.moveToNext()
}
}
if (current >= grp.size) current = grp.size - 1
view.invalidateViews()
jump.adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, grp).also {
it.setDropDownViewResource(R.layout.spinner_drop_down_item)
}
jump.setSelection(current)
view.setSelection(idx[current])
view.setOnScrollListener(scrollListener)
jump.onItemSelectedListener = selectListener
view.post { --guard }
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
} }, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
if (Build.VERSION.SDK_INT >= 21) hl.setPadding(0, (activity.resources.displayMetrics.density * 8f).toInt(), 0, (activity.resources.displayMetrics.density * 8f).toInt())
layout.addView(hl, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
layout.addView(this.view, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
cur = db.emoji(UnicodeActivity.univer, modifier)
cur = db.emoji(UnicodeActivity.univer, tone)
map = TreeMap()
grp = ArrayList()
idx = ArrayList()
Expand Down Expand Up @@ -113,46 +158,6 @@ internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private
jump.setSelection(current)
view.setOnScrollListener(scrollListener)
jump.onItemSelectedListener = selectListener
modc.isChecked = modifier
modc.setOnCheckedChangeListener { _: CompoundButton, isChecked: Boolean ->
if (modifier == isChecked) return@setOnCheckedChangeListener
modifier = isChecked
++guard
view.setOnScrollListener(null)
jump.onItemSelectedListener = null
jump.adapter = null
cur?.close()
cur = db.emoji(UnicodeActivity.univer, modifier)
map = TreeMap()
grp = ArrayList()
idx = ArrayList()
var last2 = ""
cur?.let {
it.moveToFirst()
while (!it.isAfterLast) {
val curr = it.getString(1) + " / " + it.getString(2)
if (curr == last2) {
it.moveToNext()
continue
}
last2 = curr
map[it.position] = map.size
grp.add(curr)
idx.add(it.position)
it.moveToNext()
}
}
if (current >= grp.size) current = grp.size - 1
view.invalidateViews()
jump.adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, grp).also {
it.setDropDownViewResource(R.layout.spinner_drop_down_item)
}
jump.setSelection(current)
view.setSelection(idx[current])
view.setOnScrollListener(scrollListener)
jump.onItemSelectedListener = selectListener
view.post { --guard }
}
return layout
}

Expand All @@ -172,7 +177,7 @@ internal class EmojiAdapter(activity: Activity, pref: SharedPreferences, private

override fun save(edit: SharedPreferences.Editor) {
edit.putInt("emoji", current)
edit.putBoolean("modifier", modifier)
edit.putInt("tone", tone)
}

override fun getCount(): Int {
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/NameDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class NameDatabase(context: Context) {
operator fun get(code: Int, column: String): String? {
if (column == "name") {
if (code in 0xE000..0xF8FF || code in 0xFFF80..0xFFFFD || code in 0x10FF80..0x10FFFD) return "Private Use"
if (code in 0x3400..0x4DBF || code in 0x4E00..0x9FFF || code in 0x20000..0x2A6DF || code in 0x2A700..0x2B738 || code in 0x2B740..0x2B81D || code in 0x2B820..0x2CEA1 || code in 0x2CEB0..0x2EBE0 || code in 0x30000..0x3134A) return "CJK Unified Ideograph"
if (code in 0x3400..0x4DBF || code in 0x4E00..0x9FFF || code in 0x20000..0x2A6DF || code in 0x2A700..0x2B738 || code in 0x2B740..0x2B81D || code in 0x2B820..0x2CEA1 || code in 0x2CEB0..0x2EBE0 || code in 0x30000..0x3134A || code in 0x31350 .. 0x323AF) return "CJK Unified Ideograph"
if (code in 0xAC00..0xD7A3) return "Hangul Syllable"
if (code in 0x17000..0x187F7) return "Tangut Character"
}
return get("name_table", code.toString(), column)
}

operator fun get(code: String, column: String): String? {
return get("emoji_table", "'$code'", column)
return get("emoji_table2", "'$code'", column)
}

private operator fun get(table: String, code: String, column: String): String? {
Expand Down Expand Up @@ -73,7 +73,7 @@ class NameDatabase(context: Context) {
}

fun getInt(code: String, column: String): Int {
return getInt("emoji_table", "'$code'", column)
return getInt("emoji_table2", "'$code'", column)
}

private fun getInt(table: String, code: String, column: String): Int {
Expand All @@ -100,22 +100,22 @@ class NameDatabase(context: Context) {
else -> version
}
return try {
db.rawQuery("SELECT id FROM name_table WHERE " + list.joinToString(" ") { "words LIKE '%$it%' AND " } + "version <= $version UNION ALL SELECT id FROM emoji_table WHERE " + list.joinToString(" ") { "name LIKE '%$it%' AND " } + "version <= $emojiVersion;", null)
db.rawQuery("SELECT id FROM name_table WHERE " + list.joinToString(" ") { "words LIKE '%$it%' AND " } + "version <= $version UNION ALL SELECT id FROM emoji_table2 WHERE " + list.joinToString(" ") { "name LIKE '%$it%' AND " } + "version <= $emojiVersion;", null)
} catch (e: SQLiteException) {
null
}
}

@SuppressLint("Recycle")
fun emoji(version: Int, mod: Boolean): Cursor? {
fun emoji(version: Int, tone: Int): Cursor? {
val emojiVersion = when (version) {
600, 610, 620, 630 -> 60
700 -> 70
800 -> 100
else -> version
}
return try {
db.rawQuery("SELECT id, grp, subgrp FROM emoji_table WHERE version <= $emojiVersion" + if (mod) ";" else " AND mod = 0;", null)
db.rawQuery("SELECT id, grp, subgrp FROM emoji_table2 WHERE version <= $emojiVersion AND (tone = $tone OR tone = 0);", null)
} catch (e: SQLiteException) {
null
}
Expand All @@ -129,15 +129,15 @@ class NameDatabase(context: Context) {
return try {
val db = SQLiteDatabase.openDatabase(context.getFileStreamPath(dbpath).absolutePath, null, SQLiteDatabase.OPEN_READONLY or SQLiteDatabase.NO_LOCALIZED_COLLATORS)
try {
db.rawQuery("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='name_table' OR name='emoji_table';", null).use { cur ->
db.rawQuery("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='name_table' OR name='emoji_table2';", null).use { cur ->
cur.moveToFirst()
if (cur.getInt(0) != 2) throw SQLiteException()
}
db.rawQuery("SELECT COUNT(*) FROM 'name_table';", null).use { cur ->
cur.moveToFirst()
if (cur.getInt(0) != 34930) throw SQLiteException()
}
db.rawQuery("SELECT COUNT(*) FROM 'emoji_table';", null).use { cur ->
db.rawQuery("SELECT COUNT(*) FROM 'emoji_table2';", null).use { cur ->
cur.moveToFirst()
if (cur.getInt(0) != 3655) throw SQLiteException()
}
Expand Down
Loading

0 comments on commit 0026b68

Please sign in to comment.