Add am/pm indicator, add tab badges, add widget background, add text color alpha
This commit is contained in:
@ -3,6 +3,7 @@ package com.tommasoberlose.anotherwidget.helpers
|
||||
import android.app.AlarmManager
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import android.util.Log
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
@ -2,14 +2,14 @@ package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.core.view.drawToBitmap
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
object BitmapHelper {
|
||||
|
||||
@ -26,9 +26,9 @@ object BitmapHelper {
|
||||
val btm = Bitmap.createBitmap(
|
||||
view.measuredWidth,
|
||||
view.measuredHeight,
|
||||
if (draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
||||
if (true || draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
||||
)
|
||||
if (draw) {
|
||||
if (true || draw) {
|
||||
//Bind a canvas to it
|
||||
val canvas = Canvas(btm)
|
||||
// draw the view on the canvas
|
||||
@ -76,4 +76,30 @@ object BitmapHelper {
|
||||
|
||||
return resultBitmap
|
||||
}
|
||||
|
||||
fun drawableToBitmap(drawable: Drawable): Bitmap? {
|
||||
var bitmap: Bitmap? = null
|
||||
if (drawable is BitmapDrawable) {
|
||||
if (drawable.bitmap != null) {
|
||||
return drawable.bitmap
|
||||
}
|
||||
}
|
||||
bitmap = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) {
|
||||
Bitmap.createBitmap(
|
||||
1,
|
||||
1,
|
||||
Bitmap.Config.ARGB_8888
|
||||
) // Single color bitmap will be created of 1x1 pixel
|
||||
} else {
|
||||
Bitmap.createBitmap(
|
||||
drawable.intrinsicWidth,
|
||||
drawable.intrinsicHeight,
|
||||
Bitmap.Config.ARGB_8888
|
||||
)
|
||||
}
|
||||
val canvas = Canvas(bitmap)
|
||||
drawable.setBounds(0, 0, canvas.width, canvas.height)
|
||||
drawable.draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
}
|
@ -1,14 +1,41 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object ColorHelper {
|
||||
fun getFontColor(): Int {
|
||||
return try {
|
||||
Color.parseColor(Preferences.textGlobalColor)
|
||||
Color.parseColor("#%s%s".format(Preferences.textGlobalAlpha, Preferences.textGlobalColor.replace("#", "")))
|
||||
} catch (e: Exception) {
|
||||
Color.parseColor("#FFFFFF")
|
||||
Color.parseColor("#FFFFFFFF")
|
||||
}
|
||||
}
|
||||
|
||||
fun getBackgroundColor(): Int {
|
||||
return try {
|
||||
Color.parseColor("#%s%s".format(Preferences.backgroundCardAlpha, Preferences.backgroundCardColor.replace("#", "")))
|
||||
} catch (e: Exception) {
|
||||
Color.parseColor("#00000000")
|
||||
}
|
||||
}
|
||||
|
||||
fun getBackgroundAlpha(): Int {
|
||||
return try {
|
||||
Preferences.backgroundCardAlpha.toIntValue().toDouble() * 255 / 100
|
||||
} catch (e: Exception) {
|
||||
"00".toIntValue().toDouble() * 255 / 100
|
||||
}.roundToInt()
|
||||
}
|
||||
|
||||
fun getBackgroundColorRgb(): Int {
|
||||
return try {
|
||||
Color.parseColor(Preferences.backgroundCardColor)
|
||||
} catch (e: Exception) {
|
||||
Color.parseColor("#000000")
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,4 +47,16 @@ object ColorHelper {
|
||||
1 - (0.299 * Color.red(this) + 0.587 * Color.green(this) + 0.114 * Color.blue(this)) / 255
|
||||
return darkness >= threshold
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
fun Int.toHexValue(): String {
|
||||
val intValue = (this * 255 / 100).toDouble().roundToInt()
|
||||
val hexValue = intValue.toString(16)
|
||||
return hexValue.padStart(2, '0').toUpperCase()
|
||||
}
|
||||
|
||||
fun String.toIntValue(): Int {
|
||||
val hexValue = this.toInt(16).toDouble()
|
||||
return (hexValue * 100 / 255).roundToInt()
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ object WeatherHelper {
|
||||
|
||||
fun removeWeather(context: Context) {
|
||||
Preferences.remove(Preferences::weatherTemp)
|
||||
Preferences.remove(Preferences::weatherTempUnit)
|
||||
Preferences.remove(Preferences::weatherRealTempUnit)
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user