Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7a02f09
ColorUtil: treat empty color strings the same as null ones
AlvaroBrey Sep 7, 2022
c4d7e8f
ui: AndroidViewThemeUtils: add primary coloring method for progressbar
AlvaroBrey Sep 7, 2022
a421fca
ui: AndroidViewThemeUtils: more methods regarding buttons
AlvaroBrey Sep 7, 2022
7d83873
AndroidViewThemeUtils: use gray for disabled checkboxes
AlvaroBrey Sep 7, 2022
2bb8097
Add MaterialSchemes implementation from color
AlvaroBrey Sep 8, 2022
9dc69a6
Fix detekt/ktlint
AlvaroBrey Sep 8, 2022
a6f7b9e
AndroidViewThemeUtils: themeProgressBar: null-check both drawables
AlvaroBrey Sep 8, 2022
d0d5347
MaterialViewThemeUtils: themeTextInputLayout: also color editText hig…
AlvaroBrey Sep 8, 2022
733db63
AndroidViewThemeUtils: alternate coloring for menu items
AlvaroBrey Sep 8, 2022
5b1e562
AndroidViewThemeUtils: better name for imageview method
AlvaroBrey Sep 12, 2022
ba371b8
Add NavigationView theming
AndyScherzinger Sep 12, 2022
114c019
remove unneeded theming methods
AndyScherzinger Sep 12, 2022
2d4985d
Add legacy action bar theming
AndyScherzinger Sep 12, 2022
44134ec
add toolbar drawable tinting
AndyScherzinger Sep 12, 2022
73e16f2
AndroidViewThemeUtils: restore colorToolbarMenuIcon
AlvaroBrey Sep 13, 2022
b6222c6
Fix detekt and ktlint
AlvaroBrey Sep 13, 2022
b22b6a1
Move themeActionBar to AndroidX theme utils, since it's an appcompat …
AlvaroBrey Sep 13, 2022
ef115b5
add drawable tinting theme methods
AndyScherzinger Sep 13, 2022
5c533ef
ViewThemeUtilsBase: schemes should be private
AlvaroBrey Sep 13, 2022
a7853a1
AndroidViewThemeUtils: deprecate useless parameter in themeStatusBar
AlvaroBrey Sep 13, 2022
1371ce1
Add a TODO
AlvaroBrey Sep 13, 2022
f3ab41a
tabLayout: add icon tinting and non-surface theming method
AndyScherzinger Sep 14, 2022
83f7f02
MaterialViewThemeUtils: theme snackbars
AlvaroBrey Sep 14, 2022
48b598c
ViewThemeUtilsBase: let withScheme return the block result
AlvaroBrey Sep 14, 2022
740280b
AppCompatTextView theming
AndyScherzinger Sep 14, 2022
ffc0af2
ui: More utilities for tinting drawables and toolbars
AlvaroBrey Sep 15, 2022
1bbfb51
MaterialViewThemeUtils: deprecate duplicated function
AlvaroBrey Sep 16, 2022
ad6fd92
general theming for toolbar search field
AndyScherzinger Sep 16, 2022
d82cbe5
Primary color ColorDrawable
AndyScherzinger Sep 16, 2022
56e3af6
add primaryColor access
AndyScherzinger Sep 20, 2022
91842d0
extend outlined buttons primary coloring for all defined states
AndyScherzinger Sep 25, 2022
e961162
Add theming for CheckedTextView
AndyScherzinger Sep 25, 2022
f974f9b
add color option for progress bar
AndyScherzinger Sep 27, 2022
226ef60
Add tonal button, cadview stroke coloring and onSecondaryContainer te…
AndyScherzinger Sep 29, 2022
e0f9bca
Introduce ColorRole abstraction to deduplicate logic while allowing c…
AlvaroBrey Oct 3, 2022
10a5159
ui: Add function to theme notification builder
AlvaroBrey Oct 3, 2022
87322df
ui: add utilities to tint platform Switch
AlvaroBrey Oct 3, 2022
ae9ca8b
Rework status bar coloring
AlvaroBrey Oct 4, 2022
071ec0b
PlatformThemeUtil: make isDarkMode accessible from Java
AlvaroBrey Oct 4, 2022
6d96f4c
Some more drawable coloring
AlvaroBrey Oct 4, 2022
40bf8e8
AndroidViewThemeUtils: fix navbar colors
AlvaroBrey Oct 4, 2022
d677e4b
ui: mark SwitchColorUtils as internal
AlvaroBrey Oct 5, 2022
83ffde8
ColorUtil: add utility function to convert color to hex
AlvaroBrey Oct 10, 2022
ba07300
Reduce a lot of boilerplate by creating a ColorStateList build function
AlvaroBrey Oct 10, 2022
1f49e6a
MaterialViewThemeUtils: deduplicate ripple color
AlvaroBrey Oct 11, 2022
17f5d6c
Remove unneeded TODO
AlvaroBrey Oct 13, 2022
783c4b7
Add disabled state to FAB
AndyScherzinger Oct 13, 2022
ed7019a
MaterialViewThemeUtils: simplify colorstatelist
AlvaroBrey Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ class ColorUtil @Inject constructor(private val context: Context) {

@ColorInt
fun getForegroundColorForBackgroundColor(@ColorInt color: Int): Int {
val hsl = FloatArray(HSL_SIZE)
ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl)

return if (hsl[INDEX_LIGHTNESS] < LIGHTNESS_DARK_THRESHOLD) {
return if (isDarkBackground(color)) {
Color.WHITE
} else {
ContextCompat.getColor(context, R.color.grey_900)
}
}

fun isDarkBackground(@ColorInt color: Int): Boolean {
val hsl = FloatArray(HSL_SIZE)
ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl)

return hsl[INDEX_LIGHTNESS] < LIGHTNESS_DARK_THRESHOLD
}

fun setLightness(@ColorInt color: Int, lightness: Float): Int {
require(lightness in 0.0..1.0) { "Lightness must be between 0 and 1" }
val hsl = FloatArray(HSL_SIZE)
Expand All @@ -71,9 +75,17 @@ class ColorUtil @Inject constructor(private val context: Context) {
return ColorUtils.HSLToColor(hsl)
}

fun colorToHexString(@ColorInt color: Int): String {
return String.format(null, "#%06X", HEX_WHITE and color)
}

@ColorInt
private fun String?.parseColorOrFallback(fallback: () -> Int): Int {
return this?.let { Color.parseColor(this) } ?: fallback()
return if (this?.isNotBlank() == true) {
Color.parseColor(this)
} else {
fallback()
}
}

@ColorInt
Expand All @@ -90,5 +102,6 @@ class ColorUtil @Inject constructor(private val context: Context) {
private const val HSL_SIZE: Int = 3
private const val INDEX_LIGHTNESS: Int = 2
private const val LIGHTNESS_DARK_THRESHOLD: Float = 0.6f
private const val HEX_WHITE = 0xFFFFFF
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package com.nextcloud.android.common.ui.theme

import androidx.annotation.ColorInt
import scheme.Scheme

interface MaterialSchemes {
Expand All @@ -36,5 +37,6 @@ interface MaterialSchemes {

companion object {
fun fromServerTheme(theme: ServerTheme): MaterialSchemes = MaterialSchemesImpl(theme)
fun fromColor(@ColorInt color: Int): MaterialSchemes = MaterialSchemesImpl(color)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@

package com.nextcloud.android.common.ui.theme

import androidx.annotation.ColorInt
import scheme.Scheme

internal class MaterialSchemesImpl(serverTheme: ServerTheme) :
internal class MaterialSchemesImpl :
MaterialSchemes {
override val lightScheme: Scheme
override val darkScheme: Scheme

init {
lightScheme = Scheme.light(serverTheme.primaryColor)
darkScheme = Scheme.dark(serverTheme.primaryColor)
constructor(@ColorInt primaryColor: Int) {
lightScheme = Scheme.light(primaryColor)
darkScheme = Scheme.dark(primaryColor)
}

constructor(serverTheme: ServerTheme) : this(serverTheme.primaryColor)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import android.view.View
import com.nextcloud.android.common.ui.util.PlatformThemeUtil
import scheme.Scheme

open class ViewThemeUtilsBase(val schemes: MaterialSchemes) {
open class ViewThemeUtilsBase(private val schemes: MaterialSchemes) {
/**
* Scheme for painting elements
*/
Expand All @@ -40,20 +40,15 @@ open class ViewThemeUtilsBase(val schemes: MaterialSchemes) {
fun getScheme(context: Context): Scheme = getSchemeInternal(context)

@Suppress("MemberVisibilityCanBePrivate")
// TODO cache by context hashcode
protected fun getSchemeInternal(context: Context): Scheme = when {
PlatformThemeUtil.isDarkMode(context) -> schemes.darkScheme
else -> schemes.lightScheme
}

protected fun withScheme(view: View, block: (Scheme) -> Unit) {
block(getSchemeInternal(view.context))
}
protected fun <R> withScheme(view: View, block: (Scheme) -> R): R = block(getSchemeInternal(view.context))

protected fun withScheme(context: Context, block: (Scheme) -> Unit) {
block(getSchemeInternal(context))
}
protected fun <R> withScheme(context: Context, block: (Scheme) -> R): R = block(getSchemeInternal(context))

protected fun withSchemeDark(block: (Scheme) -> Unit) {
block(schemes.darkScheme)
}
protected fun <R> withSchemeDark(block: (Scheme) -> R): R = block(schemes.darkScheme)
}
Loading