Skip to content

Commit

Permalink
Setting to allow multiline text in edit box
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryosuke839 committed Jul 12, 2024
1 parent c46de8d commit 4998a99
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class SettingActivity : BaseActivity() {
it.put("column", pref.getString("column", null))
it.put("columnl", pref.getString("columnl", null))
it.put("textsize", pref.getString("textsize", null))
it.put("multiline", if (pref.contains("multiline")) pref.getBoolean("multiline", false) else null)
it.put("viewsize", pref.getString("viewsize", null))
it.put("lines", if (pref.contains("lines")) pref.getBoolean("lines", true) else null)
it.put("shrink", if (pref.contains("shrink")) pref.getBoolean("shrink", true) else null)
Expand Down Expand Up @@ -373,6 +374,7 @@ class SettingActivity : BaseActivity() {
(it.opt("column") as? String)?.let { str -> edit.putString("column", str) }
(it.opt("columnl") as? String)?.let { str -> edit.putString("columnl", str) }
(it.opt("textsize") as? String)?.let { str -> edit.putString("textsize", str) }
(it.opt("multiline") as? Boolean)?.let { bool -> edit.putBoolean("multiline", bool) }
(it.opt("viewsize") as? String)?.let { str -> edit.putString("viewsize", str) }
(it.opt("lines") as? Boolean)?.let { bool -> edit.putBoolean("lines", bool) }
(it.opt("shrink") as? Boolean)?.let { bool -> edit.putBoolean("shrink", bool) }
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/jp/ddo/hotmist/unicodepad/UnicodeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.AppCompatEditText
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
Expand All @@ -54,6 +54,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.res.getResourceIdOrThrow
Expand Down Expand Up @@ -134,11 +135,11 @@ class UnicodeActivity : BaseActivity() {
) {
Row(
modifier = Modifier
.fillMaxWidth()
.height(IntrinsicSize.Min),
.fillMaxWidth(),
) {
val multiline = pref.getBoolean("multiline", false)
Box(
modifier = Modifier.weight(1f),
modifier = Modifier.weight(1f).heightIn(max = if (multiline) fontsize.dp * 4 else Dp.Unspecified),
) {
AndroidView(
factory = { context ->
Expand All @@ -152,8 +153,8 @@ class UnicodeActivity : BaseActivity() {
true
}
textSize = fontsize
maxLines = 1
inputType = InputType.TYPE_CLASS_TEXT
maxLines = if (multiline) 3 else 1
inputType = InputType.TYPE_CLASS_TEXT or if (multiline) InputType.TYPE_TEXT_FLAG_MULTI_LINE else 0
setOnEditorActionListener { _, actionId, keyEvent ->
if (keyEvent?.keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_DOWN || actionId == EditorInfo.IME_ACTION_DONE) {
btnFinish.performClick()
Expand Down Expand Up @@ -278,7 +279,7 @@ class UnicodeActivity : BaseActivity() {
} },
modifier = Modifier
.align(Alignment.CenterVertically)
.fillMaxHeight(),
.height(fontsize.dp * 2),
)
}
@Composable
Expand Down Expand Up @@ -845,6 +846,9 @@ class UnicodeActivity : BaseActivity() {
editText.textSize = fontsize
adpPage.notifyDataSetChanged()
scrollUi = (pref.getString("scroll", null)?.toIntOrNull() ?: 1) + (if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) 1 else 0) > 1
val multiline = pref.getBoolean("multiline", false)
editText.maxLines = if (multiline) 3 else 1
editText.inputType = InputType.TYPE_CLASS_TEXT or if (multiline) InputType.TYPE_TEXT_FLAG_MULTI_LINE else 0
}
if (requestCode != -1) {
adCompat.renderAdToContainer(this, pref)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
<string name="appearance">外観</string>
<string name="behaviour">動作</string>
<string name="textsize_desc">エディットボックスのフォントサイズ</string>
<string name="multiline_desc">エディットボックスで改行</string>
<string name="column_desc">表の列数</string>
<string name="columnl_desc">表の列数 (横位置)</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
<string name="appearance">Appearance</string>
<string name="behaviour">Behavior</string>
<string name="textsize_desc">Text size of edit box</string>
<string name="multiline_desc">Multiline edit box</string>
<string name="column_desc">Columns in grid</string>
<string name="columnl_desc">Columns in grid (landscape)</string>

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
android:inputType="numberDecimal"
android:summary=""
android:title="@string/textsize_desc" />
<CheckBoxPreference
android:defaultValue="false"
android:key="multiline"
android:title="@string/multiline_desc" />
<EditTextPreference
android:defaultValue="@string/viewsize_def"
android:dialogTitle="@string/viewsize_desc"
Expand Down

0 comments on commit 4998a99

Please sign in to comment.