add "Switch button color" in App setting / Color
This commit is contained in:
parent
c3ed56c03a
commit
a69f7a2846
|
@ -40,7 +40,7 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -5,7 +5,7 @@ import androidx.test.runner.AndroidJUnit4
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import jp.juggler.subwaytooter.util.CharacterGroup
|
||||
import jp.juggler.util.CharacterGroup
|
||||
import jp.juggler.util.WordTrieTree
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
|
@ -31,6 +32,7 @@ import org.jetbrains.anko.backgroundDrawable
|
|||
import org.jetbrains.anko.textColor
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.text.NumberFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -88,6 +90,8 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
internal const val COLOR_DIALOG_ID_EVENT_BG_VOTE = 24
|
||||
internal const val COLOR_DIALOG_ID_EVENT_BG_FOLLOWREQUEST = 25
|
||||
|
||||
internal const val COLOR_DIALOG_ID_SWITCH_BUTTON = 26
|
||||
|
||||
internal const val REQUEST_CODE_TIMELINE_FONT = 1
|
||||
internal const val REQUEST_CODE_TIMELINE_FONT_BOLD = 2
|
||||
|
||||
|
@ -106,6 +110,8 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
|
||||
private val booleanViewList = ArrayList<BooleanViewInfo>()
|
||||
|
||||
private lateinit var svContent : View
|
||||
|
||||
private var spBackButtonAction : Spinner? = null
|
||||
private var spUITheme : Spinner? = null
|
||||
private var spResizeImage : Spinner? = null
|
||||
|
@ -138,6 +144,7 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
private var event_bg_color_quote : Int = 0
|
||||
private var event_bg_color_vote : Int = 0
|
||||
private var event_bg_color_follow_request : Int = 0
|
||||
private var switch_button_color = 0
|
||||
|
||||
private var color_column_header_bg : Int = 0
|
||||
private var color_column_header_fg : Int = 0
|
||||
|
@ -275,7 +282,11 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
|
||||
private fun initUI() {
|
||||
|
||||
Styler.fixHorizontalPadding(findViewById(R.id.svContent))
|
||||
svContent = findViewById(R.id.svContent)
|
||||
|
||||
setSwitchColor(svContent)
|
||||
|
||||
Styler.fixHorizontalPadding(svContent)
|
||||
|
||||
// initialize Switch and CheckBox
|
||||
for(info in Pref.map.values) {
|
||||
|
@ -432,6 +443,8 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
, R.id.btnCustomShare2Reset
|
||||
, R.id.btnCustomShare3Edit
|
||||
, R.id.btnCustomShare3Reset
|
||||
, R.id.btnSwitchButtonColorEdit
|
||||
, R.id.btnSwitchButtonColorReset
|
||||
).forEach {
|
||||
findViewById<View>(it)?.setOnClickListener(this)
|
||||
}
|
||||
|
@ -617,6 +630,7 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
event_bg_color_quote = Pref.ipEventBgColorQuote(pref)
|
||||
event_bg_color_vote = Pref.ipEventBgColorVote(pref)
|
||||
event_bg_color_follow_request = Pref.ipEventBgColorFollowRequest(pref)
|
||||
switch_button_color = Pref.ipSwitchOnColor(pref)
|
||||
|
||||
color_column_header_bg = Pref.ipCcdHeaderBg(pref)
|
||||
color_column_header_fg = Pref.ipCcdHeaderFg(pref)
|
||||
|
@ -792,6 +806,7 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
put(Pref.ipEventBgColorQuote, event_bg_color_quote)
|
||||
put(Pref.ipEventBgColorVote, event_bg_color_vote)
|
||||
put(Pref.ipEventBgColorFollowRequest, event_bg_color_follow_request)
|
||||
put(Pref.ipSwitchOnColor, switch_button_color)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1181,6 +1196,19 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
saveUIToData()
|
||||
}
|
||||
|
||||
R.id.btnSwitchButtonColorEdit -> openColorPicker(
|
||||
COLOR_DIALOG_ID_SWITCH_BUTTON,
|
||||
switch_button_color,
|
||||
true
|
||||
)
|
||||
|
||||
R.id.btnSwitchButtonColorReset -> {
|
||||
switch_button_color = Pref.ipSwitchOnColor.defVal
|
||||
saveUIToData()
|
||||
setSwitchColor(svContent)
|
||||
|
||||
}
|
||||
|
||||
R.id.btnTranslateAppComponentEdit -> openCustomShareChooser(CustomShareTarget.Translate)
|
||||
R.id.btnCustomShare1Edit -> openCustomShareChooser(CustomShareTarget.CustomShare1)
|
||||
R.id.btnCustomShare2Edit -> openCustomShareChooser(CustomShareTarget.CustomShare2)
|
||||
|
@ -1369,6 +1397,11 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
saveUIToData()
|
||||
}
|
||||
|
||||
COLOR_DIALOG_ID_SWITCH_BUTTON -> {
|
||||
switch_button_color = colorOpaque
|
||||
saveUIToData()
|
||||
setSwitchColor(svContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1522,7 +1555,7 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
|
||||
val tmp_file = File(dir, "$file_name.tmp")
|
||||
|
||||
val source = contentResolver.openInputStream(uri) // nullable
|
||||
val source : InputStream? = contentResolver.openInputStream(uri)
|
||||
if(source == null) {
|
||||
showToast(this, false, "openInputStream returns null. uri=%s", uri)
|
||||
return null
|
||||
|
@ -1819,4 +1852,72 @@ class ActAppSettingChild : AppCompatActivity()
|
|||
tv.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null)
|
||||
}
|
||||
|
||||
private fun setSwitchColor(root : View?) {
|
||||
|
||||
fun mixColor(col1 : Int, col2 : Int) : Int = Color.rgb(
|
||||
(Color.red(col1) + Color.red(col2)) ushr 1,
|
||||
(Color.green(col1) + Color.green(col2)) ushr 1,
|
||||
(Color.blue(col1) + Color.blue(col2)) ushr 1
|
||||
)
|
||||
|
||||
val colorBg = getAttributeColor(this, R.attr.colorWindowBackground)
|
||||
|
||||
val colorOn = Pref.ipSwitchOnColor(pref)
|
||||
|
||||
val colorOff = /* Pref.ipSwitchOffColor(pref).notZero() ?: */
|
||||
getAttributeColor(this, android.R.attr.colorPrimary)
|
||||
|
||||
val colorDisabled = mixColor(colorBg, colorOff)
|
||||
|
||||
|
||||
val colorTrackDisabled = mixColor( colorBg,colorDisabled)
|
||||
val colorTrackOn = mixColor( colorBg,colorOn)
|
||||
val colorTrackOff = mixColor( colorBg,colorOff)
|
||||
|
||||
// set Switch Color
|
||||
// https://stackoverflow.com/a/25635526/9134243
|
||||
val thumbStates = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(- android.R.attr.state_enabled),
|
||||
intArrayOf(android.R.attr.state_checked),
|
||||
intArrayOf()
|
||||
),
|
||||
intArrayOf(
|
||||
colorDisabled,
|
||||
colorOn,
|
||||
colorOff
|
||||
)
|
||||
)
|
||||
|
||||
val trackStates = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(- android.R.attr.state_enabled),
|
||||
intArrayOf(android.R.attr.state_checked),
|
||||
intArrayOf()
|
||||
),
|
||||
intArrayOf(
|
||||
colorTrackDisabled,
|
||||
colorTrackOn,
|
||||
colorTrackOff
|
||||
)
|
||||
)
|
||||
|
||||
root?.scan {
|
||||
if(it !is Switch) {
|
||||
} else if(Build.VERSION.SDK_INT < 23) {
|
||||
// android 5
|
||||
it.thumbDrawable?.setTintList(thumbStates)
|
||||
it.trackDrawable?.setTintList(thumbStates) // not trackState
|
||||
} else {
|
||||
// android 6
|
||||
it.thumbTintList = thumbStates
|
||||
if(Build.VERSION.SDK_INT >= 24) {
|
||||
// android 7
|
||||
it.trackTintList = trackStates
|
||||
it.trackTintMode = PorterDuff.Mode.SRC_OVER
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package jp.juggler.subwaytooter
|
|||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import android.preference.PreferenceManager
|
||||
import jp.juggler.util.optInt
|
||||
|
||||
|
@ -52,7 +53,7 @@ class BooleanPref(
|
|||
}
|
||||
}
|
||||
|
||||
class IntPref(key : String, private val defVal : Int) : BasePref<Int>(key) {
|
||||
class IntPref(key : String, val defVal : Int) : BasePref<Int>(key) {
|
||||
|
||||
override operator fun invoke(pref : SharedPreferences) : Int {
|
||||
return pref.getInt(key, defVal)
|
||||
|
@ -449,6 +450,8 @@ object Pref {
|
|||
|
||||
val ipLinkColor = IntPref("LinkColor", 0)
|
||||
|
||||
val ipSwitchOnColor = IntPref("SwitchOnColor", Color.BLACK or 0x0080ff)
|
||||
|
||||
val ipTootColorUnlisted = IntPref("ipTootColorUnlisted", 0)
|
||||
val ipTootColorFollower = IntPref("ipTootColorFollower", 0)
|
||||
val ipTootColorDirectUser = IntPref("ipTootColorDirectUser", 0)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package jp.juggler.subwaytooter.util
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package jp.juggler.subwaytooter.util
|
||||
package jp.juggler.util
|
||||
|
||||
import android.util.SparseBooleanArray
|
||||
import android.util.SparseIntArray
|
||||
|
@ -248,7 +248,10 @@ class CharacterGroup {
|
|||
addGroup(arrayOf("」", "」", "」"))
|
||||
|
||||
// チルダ
|
||||
addGroup(arrayOf("~", i2s(tmp, 0x301C), i2s(tmp, 0xFF5E)))
|
||||
addGroup(arrayOf("~",
|
||||
i2s(tmp, 0x301C),
|
||||
i2s(tmp, 0xFF5E)
|
||||
))
|
||||
|
||||
// 半角カナの濁音,半濁音は2文字になる
|
||||
addGroup(arrayOf("ガ", "が", "ガ"))
|
|
@ -1,6 +1,5 @@
|
|||
package jp.juggler.util
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
|
@ -14,14 +13,12 @@ import android.graphics.drawable.*
|
|||
import android.graphics.drawable.shapes.RectShape
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import androidx.core.content.ContextCompat
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.SparseArray
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import jp.juggler.subwaytooter.R
|
||||
import org.jetbrains.anko.backgroundDrawable
|
||||
import java.util.*
|
||||
|
||||
object UiUtils{
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package jp.juggler.util
|
||||
|
||||
import androidx.collection.SparseArrayCompat
|
||||
import jp.juggler.subwaytooter.util.CharacterGroup
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class WordTrieTree {
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle"
|
||||
>
|
||||
<solid android:color="@color/Dark_colorBackground" />
|
||||
<solid android:color="?attr/colorWindowBackground" />
|
||||
</shape>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle"
|
||||
>
|
||||
<solid android:color="@color/Light_colorBackground" />
|
||||
</shape>
|
|
@ -900,5 +900,29 @@
|
|||
|
||||
<View style="@style/setting_divider"/>
|
||||
|
||||
<TextView
|
||||
style="@style/setting_row_label"
|
||||
android:text="@string/switch_button_color"
|
||||
/>
|
||||
<LinearLayout style="@style/setting_row_form">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSwitchButtonColorEdit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/edit"
|
||||
android:textAllCaps="false"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSwitchButtonColorReset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/reset"
|
||||
android:textAllCaps="false"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -921,5 +921,6 @@
|
|||
<string name="additional_buttons_position">追加ボタンの位置(アプリ再起動が必要)</string>
|
||||
<string name="top">上</string>
|
||||
<string name="bottom">下</string>
|
||||
<string name="switch_button_color">Switch button color</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -91,4 +91,7 @@
|
|||
<!-- VectorDrawableのXMLに指定するfillColor -->
|
||||
<attr name="colorVectorDrawable" format="color"/>
|
||||
|
||||
<!-- @drawable/window_background_light と @drawable/window_background に指定した色をgetAttributeColorで取得したい -->
|
||||
<attr name="colorWindowBackground" format="color"/>
|
||||
|
||||
</resources>
|
|
@ -914,5 +914,6 @@
|
|||
<string name="additional_buttons_position">Additional buttons position (app restart required)</string>
|
||||
<string name="top">Top</string>
|
||||
<string name="bottom">Bottom</string>
|
||||
<string name="switch_button_color">Switch button color</string>
|
||||
|
||||
</resources>
|
|
@ -3,7 +3,7 @@
|
|||
<!-- light theme -->
|
||||
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
|
||||
<item name="android:windowBackground">@drawable/window_background_light</item>
|
||||
<item name="android:windowBackground">@drawable/window_background</item>
|
||||
<item name="android:textColor">?attr/colorContentText</item>
|
||||
|
||||
<item name="colorPrimary">@color/Light_colorPrimary</item>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<item name="colorButtonBgCw">@color/Light_colorButtonBgCw</item>
|
||||
<item name="colorRefreshErrorBg">@color/Light_colorRefreshErrorBg</item>
|
||||
<item name="colorVectorDrawable">@color/Light_colorVectorDrawable</item>
|
||||
|
||||
<item name="colorWindowBackground">@color/Light_colorBackground</item>
|
||||
|
||||
</style>
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
|||
<!-- dark theme -->
|
||||
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||
|
||||
<item name="android:windowBackground">@drawable/window_background_dark</item>
|
||||
<item name="android:windowBackground">@drawable/window_background</item>
|
||||
<item name="android:textColor">?attr/colorContentText</item>
|
||||
|
||||
<item name="android:navigationBarColor">@color/Dark_colorColumnStripBackground</item>
|
||||
|
@ -102,6 +102,7 @@
|
|||
<item name="colorRefreshErrorBg">@color/Dark_colorRefreshErrorBg</item>
|
||||
|
||||
<item name="colorVectorDrawable">@color/Dark_colorVectorDrawable</item>
|
||||
<item name="colorWindowBackground">@color/Dark_colorBackground</item>
|
||||
|
||||
</style>
|
||||
|
||||
|
|
Loading…
Reference in New Issue