Skip to content

Commit

Permalink
Merge pull request #208 from Ryosuke839/develop
Browse files Browse the repository at this point in the history
Release 2.16.0
  • Loading branch information
Ryosuke839 authored Jan 4, 2025
2 parents 29ed6f3 + 743de7d commit c7de70e
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 232 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 21
targetSdkVersion 34
versionCode 68
versionName "2.15.1"
versionCode 69
versionName "2.16.0"
}

compileOptions {
Expand Down
Binary file modified app/src/main/assets/namedb.zip
Binary file not shown.
182 changes: 98 additions & 84 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/CharacterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.view.*
import android.view.View.MeasureSpec
import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.core.widget.NestedScrollView
Expand All @@ -31,7 +30,7 @@ import java.util.*
import kotlin.math.max
import kotlin.math.min

internal class CharacterAdapter(private val activity: UnicodeActivity, private val adapter: UnicodeAdapter, private val tf: Typeface?, private val locale: Locale, private val db: NameDatabase, private val afav: FavoriteAdapter) : PagerAdapter() {
internal class CharacterAdapter(private val activity: UnicodeActivity, private val adapter: UnicodeAdapter, private var typeface: Typeface?, private var locale: Locale, private val db: NameDatabase, private val afav: FavoriteAdapter) : PagerAdapter() {
var index = 0
private set
private val reslist = TypedValue().also {
Expand All @@ -49,7 +48,7 @@ internal class CharacterAdapter(private val activity: UnicodeActivity, private v
val text = CharacterView(activity)
text.text = adapter.getItem(position)
text.setTextSize(fontsize)
text.setTypeface(tf, locale)
text.setTypeface(typeface, locale)
text.drawSlash(false)
text.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
text.setTextColor(Color.BLACK)
Expand All @@ -68,8 +67,7 @@ internal class CharacterAdapter(private val activity: UnicodeActivity, private v
val str = StringBuilder()
if (!emoji) str.append(adapter.getItem(position))
val textPadding = (6 * activity.resources.displayMetrics.scaledDensity).toInt()
for (i in 0 until if (!emoji) 10 else 7) {
if (emoji && i == 5) continue
for (i in 0 until if (!emoji) 4 else 5) {
if (i == 2) {
val v = if (!emoji) db.getInt(itemid, cols[i]) else db.getInt(adapter.getItemString(position), emjs[i])
val desc = TextView(activity)
Expand All @@ -96,7 +94,7 @@ internal class CharacterAdapter(private val activity: UnicodeActivity, private v
break
}
if (r == null) continue
val l = r.split(if (emoji && i == 6) " " else "\n").toTypedArray()
val l = r.split("\n").toTypedArray()
for (s in l) {
if (i == 0) {
layout.addView(LinearLayout(activity).apply {
Expand Down Expand Up @@ -132,85 +130,92 @@ internal class CharacterAdapter(private val activity: UnicodeActivity, private v
hl.orientation = LinearLayout.HORIZONTAL
val it = TextView(activity)
it.gravity = Gravity.CENTER_VERTICAL
it.text = (if (!emoji) mods else mode)[i]
hl.addView(it, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
if (i < 6) {
val desc = TextView(activity)
desc.text = s
desc.setTextIsSelectable(true)
hl.addView(desc, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
} else {
var cs = ""
var ps = ""
var ns: String? = null
Scanner(s).use { sc ->
var j = 0
while (sc.hasNext()) {
if (i == 9 && j == 0 && s[0] == '<') {
ns = sc.next()
++j
continue
if (!emoji && i == 3) {
val charMap = mapOf(
"*" to "\u2022 ",
"=" to "= ",
"%" to "\u203B ",
"x" to "\u2192 ",
"~" to "~ ",
":" to "\u2261 ",
"#" to "\u2248 ",
"@" to "\u2022 ",
)
it.text = charMap[s.substring(0, 1)] ?: s.substring(0, 1)
hl.addView(it, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
if (s.startsWith("*") || s.startsWith("=") || s.startsWith("%") || s.startsWith("@")) {
it.gravity = Gravity.TOP
val desc = TextView(activity)
desc.text = s.substring(2)
desc.setTextIsSelectable(true)
hl.addView(desc, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
} else {
var cs = ""
var ps = ""
val ns = mutableListOf<String>()
Scanner(s.substring(2)).use { sc ->
while (sc.hasNext()) {
val ss = sc.next()
if (Regex("[0-9A-Fa-f]{4,6}").matches(ss)) {
val tgt = Integer.parseInt(ss, 16)
cs += String(Character.toChars(tgt))
ps += String.format("U+%04X ", tgt)
} else {
ns.add(ss)
}
}
val tgt = sc.nextInt(16)
cs += String(Character.toChars(tgt))
ps += String.format("U+%04X ", tgt)
if (i == 6) {
val n = db[tgt, "name"]
ns = n ?: "<not a character>"
break
}
if (i == 7 && j == 1) {
sc.useDelimiter("\n")
sc.skip(" ")
ns = if (sc.hasNext()) sc.next() else ""
break
}
if (ps.isEmpty()) continue
ps = ps.substring(0, ps.length - 1)
val ct = CharacterView(activity, null, android.R.attr.textAppearanceLarge)
ct.setPadding(0, 0, 0, 0)
ct.setPadding(UnicodeAdapter.padding, UnicodeAdapter.padding, UnicodeAdapter.padding, UnicodeAdapter.padding)
ct.drawSlash(false)
ct.setTextSize(UnicodeAdapter.fontsize)
ct.text = cs
ct.setTypeface(typeface, locale)
hl.addView(ct, LinearLayout.LayoutParams((activity.resources.displayMetrics.scaledDensity * UnicodeAdapter.fontsize * 2 + UnicodeAdapter.padding * 2).toInt(), ViewGroup.LayoutParams.MATCH_PARENT))
val pt = TextView(activity, null, android.R.attr.textAppearanceSmall)
pt.setPadding(0, 0, 0, 0)
pt.gravity = Gravity.CENTER_VERTICAL
pt.text = ps
if (ns.isNotEmpty()) {
val nt = TextView(activity, null, android.R.attr.textAppearanceSmall)
nt.setPadding(0, 0, 0, 0)
nt.gravity = Gravity.CENTER_VERTICAL
nt.text = ns.joinToString(" ")
val vl = LinearLayout(activity)
vl.orientation = LinearLayout.VERTICAL
vl.addView(pt, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
vl.addView(nt, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
hl.addView(vl, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
} else hl.addView(pt, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
hl.id = 0x3F000000 + str.codePointCount(0, str.length)
str.append(cs)
hl.isEnabled = true
hl.isClickable = true
hl.isFocusable = true
hl.setOnClickListener { view ->
var j = 0
while (j < cs.length) {
val code = cs.codePointAt(j)
activity.adpPage.onItemClick(null, view, -1, code.toLong())
j += Character.charCount(code)
}
++j
}
}
if (ps.isEmpty()) continue
ps = ps.substring(0, ps.length - 1)
val ct = CharacterView(activity, null, android.R.attr.textAppearanceLarge)
ct.setPadding(0, 0, 0, 0)
ct.setPadding(UnicodeAdapter.padding, UnicodeAdapter.padding, UnicodeAdapter.padding, UnicodeAdapter.padding)
ct.drawSlash(false)
ct.setTextSize(UnicodeAdapter.fontsize)
ct.text = cs
ct.setTypeface(tf, locale)
hl.addView(ct, LinearLayout.LayoutParams((activity.resources.displayMetrics.scaledDensity * UnicodeAdapter.fontsize * 2 + UnicodeAdapter.padding * 2).toInt(), ViewGroup.LayoutParams.MATCH_PARENT))
val pt = TextView(activity, null, android.R.attr.textAppearanceSmall)
pt.setPadding(0, 0, 0, 0)
pt.gravity = Gravity.CENTER_VERTICAL
pt.text = ps
if (ns != null) {
val nt = TextView(activity, null, android.R.attr.textAppearanceSmall)
nt.setPadding(0, 0, 0, 0)
nt.gravity = Gravity.CENTER_VERTICAL
nt.text = ns
val vl = LinearLayout(activity)
vl.orientation = LinearLayout.VERTICAL
vl.addView(pt, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
vl.addView(nt, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
hl.addView(vl, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
} else hl.addView(pt, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
hl.id = 0x3F000000 + str.codePointCount(0, str.length)
str.append(cs)
hl.isEnabled = true
hl.isClickable = true
hl.isFocusable = true
hl.setOnClickListener { view ->
var j = 0
while (j < cs.length) {
val code = cs.codePointAt(j)
activity.adpPage.onItemClick(null, view, -1, code.toLong())
j += Character.charCount(code)
hl.setOnLongClickListener { view ->
activity.adpPage.showDesc(null, view.id - 0x3F000000, StringAdapter(str.toString(), activity, db))
true
}
hl.setBackgroundResource(reslist)
}
hl.setOnLongClickListener { view ->
activity.adpPage.showDesc(null, view.id - 0x3F000000, StringAdapter(str.toString(), activity, db))
true
}
hl.setBackgroundResource(reslist)
} else {
it.text = (if (!emoji) mods else mode)[i]
hl.addView(it, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
val desc = TextView(activity)
desc.text = s
desc.setTextIsSelectable(true)
hl.addView(desc, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f))
}
hl.setPadding(textPadding, 0, textPadding, 0)
layout.addView(hl, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
Expand Down Expand Up @@ -239,14 +244,23 @@ internal class CharacterAdapter(private val activity: UnicodeActivity, private v
val id: Long
get() = adapter.getItemCodePoint(index)

fun getItemId(position: Int): Long {
return adapter.getItemCodePoint(position)
}

fun setTypeface(typeface: Typeface?, locale: Locale) {
this.typeface = typeface
this.locale = locale
}

companion object {
var fontsize = 160f
var checker = 10f
var lines = true
var shrink = true
private val cols = arrayOf("name", "utf8", "version", "comment", "alias", "formal", "xref", "vari", "decomp", "compat")
private val mods = arrayOf(null, "UTF-8: ", "from Unicode ", "\u2022 ", "= ", "\u203B ", "\u2192 ", "~ ", "\u2261 ", "\u2248 ")
private val emjs = arrayOf("name", "utf8", "version", "grp", "subgrp", "", "id")
private val mode = arrayOf(null, "UTF-8: ", "from Unicode Emoji ", "Group: ", "Subgroup: ", null, "")
private val cols = arrayOf("name", "utf8", "version", "lines")
private val mods = arrayOf(null, "UTF-8: ", "from Unicode ", "")
private val emjs = arrayOf("name", "utf8", "version", "grp", "subgrp")
private val mode = arrayOf(null, "UTF-8: ", "from Unicode Emoji ", "Group: ", "Subgroup: ")
}
}
5 changes: 4 additions & 1 deletion app/src/main/java/jp/ddo/hotmist/unicodepad/CharacterView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class CharacterView @JvmOverloads constructor(context: Context, attrs: Attribute
}

fun setTypeface(tf: Typeface?, locale: Locale) {
if (paint.typeface != tf) invalid = true
if (paint.typeface != tf || paint.textLocale != locale) {
invalid = true
invalidate()
}
paint.typeface = tf
paint.textLocale = locale
requestLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ListPopupWindow.INPUT_METHOD_FROM_FOCUSABLE
import android.widget.SpinnerAdapter
import android.widget.ThemedSpinnerAdapter
import androidx.appcompat.widget.AppCompatEditText
Expand All @@ -32,7 +31,8 @@ class FilterableSpinner(context: Context, attrs: AttributeSet?, defStyle: Int) :
popupField.isAccessible = true
val popup = popupField.get(this as AppCompatSpinner)
if (popup is ListPopupWindow) {
popup.inputMethodMode = INPUT_METHOD_FROM_FOCUSABLE
popup.inputMethodMode = ListPopupWindow.INPUT_METHOD_FROM_FOCUSABLE
popup.show()
}
} catch (e: NoSuchFieldException) {
e.printStackTrace()
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/FindAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class FindAdapter(activity: Activity, private val pref: SharedPreferenc

override fun instantiate(view: View): View {
super.instantiate(view)
val view = view as RecyclerView
check(view is RecyclerView)
val layout = LinearLayout(activity)
layout.orientation = LinearLayout.VERTICAL
val find = ImageButton(activity)
Expand Down Expand Up @@ -104,10 +104,6 @@ internal class FindAdapter(activity: Activity, private val pref: SharedPreferenc

override fun destroy() {
adapter = null
curList?.close()
curList = null
curEmoji?.close()
curEmoji = null
super.destroy()
}

Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,6 @@ internal class ListAdapter(activity: Activity, pref: SharedPreferences, db: Name
}
layout.addView(this.view, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
(this.view as RecyclerView?)?.also { view ->
view.setOnTouchListener { _, _ ->
runOnUiThread {
highTarget?.setBackgroundColor(resnormal)
highTarget = null
if (highlight != -1) {
notifyItemChanged(highlight)
highlight = -1
}
}
false
}
val e = fromCodePoint.floorEntry(scroll) ?: fromCodePoint.firstEntry()
if (e.value.end < scroll) scroll = e.value.end
scrollToItem(scroll - e.key + e.value.index)
Expand Down Expand Up @@ -827,6 +816,17 @@ internal class ListAdapter(activity: Activity, pref: SharedPreferences, db: Name
return (i - e.key + e.value.codePoint).toLong()
}

override fun onTouch() {
runOnUiThread {
highTarget?.setBackgroundColor(resnormal)
highTarget = null
if (highlight != -1) {
notifyItemChanged(highlight)
highlight = -1
}
}
}

init {
val str = pref.getString("mark", null) ?: ""
for (s in str.split("\n").toTypedArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class NameDatabase(context: Context) {
try {
db.rawQuery("SELECT * FROM version_code;", null).use { cur ->
cur.moveToFirst()
if (cur.getInt(0) != 59) throw SQLiteException()
if (cur.getInt(0) != 60) throw SQLiteException()
}
} catch (e: SQLiteException) {
db.close()
Expand Down
Loading

0 comments on commit c7de70e

Please # to comment.