mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-15 08:47:56 +01:00
more correcting of problems/suggestions
This commit is contained in:
parent
786214e0f5
commit
3cba8e8c31
2 changed files with 36 additions and 50 deletions
|
@ -112,6 +112,7 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
|
|||
return arr.getInteger(index, 0)
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) {
|
||||
if (!restoreValue) {
|
||||
persistInt((defaultValue as Int))
|
||||
|
@ -159,31 +160,26 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
|
|||
private fun onBindDialogView(view: View?) {
|
||||
LocUtils.xlateView(mContext, view)
|
||||
mCurColor = persistedColor
|
||||
setOneByte(view, 0)
|
||||
setOneByte(view, 1)
|
||||
setOneByte(view, 2)
|
||||
view!!.findViewById<View>(R.id.color_edit_sample)
|
||||
.setBackgroundColor(mCurColor)
|
||||
view?.let {
|
||||
setOneByte(it, 0)
|
||||
setOneByte(it, 1)
|
||||
setOneByte(it, 2)
|
||||
it.findViewById<View>(R.id.color_edit_sample)
|
||||
.setBackgroundColor(mCurColor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setOneByte(parent: View?, indx: Int) {
|
||||
private fun setOneByte(parent: View, indx: Int) {
|
||||
val shift = 16 - indx * 8
|
||||
val byt = mCurColor shr shift and 0xFF
|
||||
val seekbar = parent!!.findViewById<View>(m_seekbarIds[indx]) as SeekBar
|
||||
val edittext = parent.findViewById<View>(m_editIds[indx]) as EditText
|
||||
if (null != seekbar) {
|
||||
val seekbar = parent.findViewById<SeekBar>(m_seekbarIds[indx])
|
||||
val edittext = parent.findViewById<EditText>(m_editIds[indx])
|
||||
seekbar.progress = byt
|
||||
seekbar.setOnSeekBarChangeListener(
|
||||
SBCL(
|
||||
parent, edittext,
|
||||
indx
|
||||
)
|
||||
SBCL(parent, edittext, indx)
|
||||
)
|
||||
}
|
||||
if (null != edittext) {
|
||||
edittext.setText(String.format("%d", byt))
|
||||
edittext.addTextChangedListener(TCL(seekbar))
|
||||
}
|
||||
edittext.setText(String.format("%d", byt))
|
||||
edittext.addTextChangedListener(TCL(seekbar))
|
||||
}
|
||||
|
||||
private val persistedColor: Int
|
||||
|
@ -201,13 +197,10 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
|
|||
)
|
||||
|
||||
private fun getOneByte(parent: DialogInterface, id: Int): Int {
|
||||
var `val` = 0
|
||||
val dialog = parent as Dialog
|
||||
val seekbar = dialog.findViewById<View>(id) as SeekBar
|
||||
if (null != seekbar) {
|
||||
`val` = seekbar.progress
|
||||
}
|
||||
return `val`
|
||||
val seekbar = dialog.findViewById<SeekBar>(id)
|
||||
val result = seekbar.progress
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,19 +153,17 @@ open class XWPrefs {
|
|||
|
||||
fun getPrefsInt(context: Context, keyID: Int, defaultValue: Int): Int {
|
||||
var result = defaultValue
|
||||
if (null != context) {
|
||||
val key = context.getString(keyID)
|
||||
val sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(context)
|
||||
val key = context.getString(keyID)
|
||||
val sp = PreferenceManager
|
||||
.getDefaultSharedPreferences(context)
|
||||
try {
|
||||
result = sp.getInt(key, defaultValue)
|
||||
// If it's in a pref, it'll be a string (editable) So will get CCE
|
||||
} catch (cce: ClassCastException) {
|
||||
val asStr = sp.getString(key, String.format("%d", defaultValue))
|
||||
try {
|
||||
result = sp.getInt(key, defaultValue)
|
||||
// If it's in a pref, it'll be a string (editable) So will get CCE
|
||||
} catch (cce: ClassCastException) {
|
||||
val asStr = sp.getString(key, String.format("%d", defaultValue))
|
||||
try {
|
||||
result = asStr!!.toInt()
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
result = asStr!!.toInt()
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
@ -252,26 +250,21 @@ open class XWPrefs {
|
|||
|
||||
fun getSMSPhones(context: Context): JSONObject {
|
||||
val asStr = getPrefsString(context, R.string.key_sms_phones)
|
||||
var obj: JSONObject? = null
|
||||
|
||||
if (null != asStr) {
|
||||
obj = try {
|
||||
var obj =
|
||||
try {
|
||||
JSONObject(asStr)
|
||||
} catch (ex: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
if (null == obj) {
|
||||
obj = JSONObject()
|
||||
if (null != asStr) {
|
||||
val numbers = TextUtils.split(asStr, "\n")
|
||||
for (number in numbers) {
|
||||
try {
|
||||
obj.put(number, "") // null removes any entry
|
||||
} catch (ex: JSONException) {
|
||||
Log.ex(TAG, ex)
|
||||
}
|
||||
val numbers = TextUtils.split(asStr, "\n")
|
||||
for (number in numbers) {
|
||||
try {
|
||||
obj.put(number, "") // null removes any entry
|
||||
} catch (ex: JSONException) {
|
||||
Log.ex(TAG, ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +397,7 @@ open class XWPrefs {
|
|||
|
||||
protected fun getPrefsStringArray(context: Context, keyID: Int): Array<String>? {
|
||||
val asStr = getPrefsString(context, keyID)
|
||||
val result = if (null == asStr) null else TextUtils.split(asStr, "\n")
|
||||
val result = TextUtils.split(asStr, "\n")
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue