Skip to content

Commit a5011f0

Browse files
committed
android widget (misc): support light colors
1 parent 098196e commit a5011f0

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

  • android/app/src/main/java/org/toni/customfetch_android_lib

android/app/src/main/java/org/toni/customfetch_android_lib/Parse.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.text.style.StrikethroughSpan
1111
import android.text.style.StyleSpan
1212
import android.text.style.UnderlineSpan
1313
import android.util.Log
14+
import androidx.core.graphics.ColorUtils
1415
import androidx.core.graphics.toColorInt
1516
import org.toni.customfetch_android_lib.ParserFunctions.getAndColorPercentage
1617
import org.toni.customfetch_android_lib.ParserFunctions.parse
@@ -135,10 +136,14 @@ object ParserFunctions {
135136
if (color[0] != '#')
136137
color.delete(0, color.indexOf('#'))
137138

138-
if ((n in 100..107) || (n in 40..47))
139-
currentSpans?.add(BackgroundColorSpan(Color.parseColor(color.toString())))
140-
else
141-
currentSpans?.add(ForegroundColorSpan(Color.parseColor(color.toString())))
139+
val colorInt = Color.parseColor(color.toString())
140+
val lighterColorInt = ColorUtils.blendARGB(colorInt, Color.WHITE, 0.5f)
141+
when (n) {
142+
in 100..107 -> currentSpans?.add(BackgroundColorSpan(lighterColorInt))
143+
in 90..97 -> currentSpans?.add(ForegroundColorSpan(lighterColorInt))
144+
in 40..47 -> currentSpans?.add(BackgroundColorSpan(colorInt))
145+
else -> currentSpans?.add(ForegroundColorSpan(colorInt))
146+
}
142147
}
143148

144149
private fun convertAnsiEscapeRgb(parseArgs: ParseArgs, noescStr: String): String {
@@ -228,14 +233,14 @@ object ParserFunctions {
228233
private fun parseInfoTag(parser: Parser, parseArgs: ParseArgs, evaluate: Boolean = true): SpannableStringBuilder? {
229234
if (!parser.tryRead('<')) return null
230235

231-
val module = parse(parser, parseArgs, evaluate, '>')
236+
val module = parse(parser, parseArgs, evaluate, '>').toString()
232237

233238
if (!evaluate) return null
234239

235240
val dotPos = module.indexOf('.')
236241
if (dotPos == -1) {
237-
addValueFromModule(module.toString(), parseArgs)
238-
val info = getInfoFromName(parseArgs.systemInfo, module.toString(), "module-$module")
242+
addValueFromModule(module, parseArgs)
243+
val info = getInfoFromName(parseArgs.systemInfo, module, "module-$module")
239244

240245
if (parser.dollarPos != -1) {
241246
parseArgs.pureOutput.replace(
@@ -253,14 +258,14 @@ object ParserFunctions {
253258
addValueFromModuleMember(moduleName, moduleMemberName, parseArgs)
254259

255260
val info = getInfoFromName(parseArgs.systemInfo, moduleName, moduleMemberName)
256-
257261
if (parser.dollarPos != -1) {
258262
parseArgs.pureOutput.replace(
259263
parser.dollarPos,
260264
parser.dollarPos + module.length + "$<>".length,
261265
info.toString()
262266
)
263267
}
268+
264269
return info
265270
}
266271

@@ -305,7 +310,7 @@ object ParserFunctions {
305310

306311
if (color == "0") {
307312
parseArgs.spansDisabled = true
308-
currentSpans?.clear()
313+
currentSpans = null
309314
}
310315
else if (color == "1") {
311316
parseArgs.spansDisabled = true

0 commit comments

Comments
 (0)