forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28e324d
commit 67d617f
Showing
13 changed files
with
172 additions
and
37 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/nmc/android/utils/CheckableThemeUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.nmc.android.utils | ||
|
||
import android.content.res.ColorStateList | ||
import androidx.appcompat.widget.AppCompatCheckBox | ||
import androidx.appcompat.widget.SwitchCompat | ||
import androidx.core.graphics.drawable.DrawableCompat | ||
import androidx.core.widget.CompoundButtonCompat | ||
import com.owncloud.android.MainApp | ||
import com.owncloud.android.R | ||
|
||
object CheckableThemeUtils { | ||
@JvmStatic | ||
fun tintCheckbox(vararg checkBoxes: AppCompatCheckBox) { | ||
for (checkBox in checkBoxes) { | ||
val checkEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_enabled) | ||
val checkDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_checked_disabled) | ||
val uncheckEnabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_enabled) | ||
val uncheckDisabled = MainApp.getAppContext().resources.getColor(R.color.checkbox_unchecked_disabled) | ||
|
||
val states = arrayOf( | ||
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked), | ||
intArrayOf(-android.R.attr.state_enabled, android.R.attr.state_checked), | ||
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked), | ||
intArrayOf(-android.R.attr.state_enabled, -android.R.attr.state_checked) | ||
) | ||
val colors = intArrayOf( | ||
checkEnabled, | ||
checkDisabled, | ||
uncheckEnabled, | ||
uncheckDisabled | ||
) | ||
val checkColorStateList = ColorStateList(states, colors) | ||
CompoundButtonCompat.setButtonTintList(checkBox, checkColorStateList) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
@JvmOverloads | ||
fun tintSwitch(switchView: SwitchCompat, color: Int = 0, colorText: Boolean = false) { | ||
if (colorText) { | ||
switchView.setTextColor(color) | ||
} | ||
val thumbColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_enabled) | ||
val thumbColorUncheckedEnabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_enabled) | ||
val thumbColorCheckedDisabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_checked_disabled) | ||
val thumbColorUncheckedDisabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_thumb_unchecked_disabled) | ||
|
||
val states = arrayOf( | ||
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked), | ||
intArrayOf(-android.R.attr.state_enabled, android.R.attr.state_checked), | ||
intArrayOf(android.R.attr.state_enabled, -android.R.attr.state_checked), | ||
intArrayOf(-android.R.attr.state_enabled, -android.R.attr.state_checked) | ||
) | ||
val thumbColors = intArrayOf( | ||
thumbColorCheckedEnabled, | ||
thumbColorCheckedDisabled, | ||
thumbColorUncheckedEnabled, | ||
thumbColorUncheckedDisabled | ||
) | ||
val thumbColorStateList = ColorStateList(states, thumbColors) | ||
val trackColorCheckedEnabled = MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_enabled) | ||
val trackColorUncheckedEnabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_enabled) | ||
val trackColorCheckedDisabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_track_checked_disabled) | ||
val trackColorUncheckedDisabled = | ||
MainApp.getAppContext().resources.getColor(R.color.switch_track_unchecked_disabled) | ||
|
||
val trackColors = intArrayOf( | ||
trackColorCheckedEnabled, | ||
trackColorCheckedDisabled, | ||
trackColorUncheckedEnabled, | ||
trackColorUncheckedDisabled | ||
) | ||
val trackColorStateList = ColorStateList(states, trackColors) | ||
|
||
// setting the thumb color | ||
DrawableCompat.setTintList(switchView.thumbDrawable, thumbColorStateList) | ||
|
||
// setting the track color | ||
DrawableCompat.setTintList(switchView.trackDrawable, trackColorStateList) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/nmc/android/utils/SearchViewThemeUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.nmc.android.utils | ||
|
||
import android.content.Context | ||
import android.widget.ImageView | ||
import androidx.appcompat.widget.SearchView | ||
import com.owncloud.android.R | ||
|
||
object SearchViewThemeUtils { | ||
fun themeSearchView(context: Context, searchView: SearchView) { | ||
val fontColor = context.resources.getColor(R.color.fontAppbar, null) | ||
val editText: SearchView.SearchAutoComplete = searchView.findViewById(R.id.search_src_text) | ||
editText.textSize = 16F | ||
editText.setTextColor(fontColor) | ||
editText.highlightColor = context.resources.getColor(R.color.search_et_highlight_color, null) | ||
editText.setHintTextColor(context.resources.getColor(R.color.fontSecondaryAppbar, null)) | ||
val closeButton: ImageView = searchView.findViewById(R.id.search_close_btn) | ||
closeButton.setColorFilter(fontColor) | ||
val searchButton: ImageView = searchView.findViewById(R.id.search_button) | ||
searchButton.setImageResource(R.drawable.ic_search) | ||
searchButton.setColorFilter(fontColor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.