Add am/pm indicator, add tab badges, add widget background, add text color alpha
This commit is contained in:
@ -8,6 +8,7 @@ import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.GridLayout
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
@ -19,6 +20,9 @@ import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.utils.expand
|
||||
import com.tommasoberlose.anotherwidget.utils.reveal
|
||||
import com.warkiz.widget.IndicatorSeekBar
|
||||
import com.warkiz.widget.OnSeekChangeListener
|
||||
import com.warkiz.widget.SeekParams
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.color_loader
|
||||
@ -32,7 +36,10 @@ class BottomSheetColorPicker(
|
||||
private val colors: IntArray = intArrayOf(),
|
||||
private val selected: Int? = null,
|
||||
private val header: String? = null,
|
||||
private val onColorSelected: ((selectedValue: Int) -> Unit)? = null
|
||||
private val onColorSelected: ((selectedValue: Int) -> Unit)? = null,
|
||||
private val showAlphaSelector: Boolean = false,
|
||||
private val alpha: Int = 0,
|
||||
private val onAlphaChangeListener: ((alpha: Int) -> Unit)? = null
|
||||
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
private val loadingJob: Job? = null
|
||||
@ -44,6 +51,22 @@ class BottomSheetColorPicker(
|
||||
view.header.isVisible = header != null
|
||||
view.header_text.text = header ?: ""
|
||||
|
||||
view.alpha_selector_container.isVisible = showAlphaSelector
|
||||
view.alpha_selector.setProgress(alpha.toFloat())
|
||||
view.text_alpha.text = "%s: %s%%".format(context.getString(R.string.alpha), alpha)
|
||||
view.alpha_selector.onSeekChangeListener = object : OnSeekChangeListener {
|
||||
override fun onSeeking(seekParams: SeekParams?) {
|
||||
seekParams?.let {
|
||||
view.text_alpha.text = "%s: %s%%".format(context.getString(R.string.alpha), it.progress)
|
||||
onAlphaChangeListener?.invoke(it.progress)
|
||||
}
|
||||
}
|
||||
override fun onStartTrackingTouch(seekBar: IndicatorSeekBar?) {
|
||||
}
|
||||
override fun onStopTrackingTouch(seekBar: IndicatorSeekBar?) {
|
||||
}
|
||||
}
|
||||
|
||||
val itemViews: ArrayList<View> = ArrayList()
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
|
@ -40,6 +40,11 @@ object Preferences : KotprefModel() {
|
||||
var eventAppPackage by stringPref(key = "PREF_EVENT_APP_PACKAGE", default = "")
|
||||
var openEventDetails by booleanPref(default = true)
|
||||
var textGlobalColor by stringPref(key = "PREF_TEXT_COLOR", default = "#FFFFFF")
|
||||
var textGlobalAlpha by stringPref(default = "FF")
|
||||
|
||||
var backgroundCardColor by stringPref(default = "#000000")
|
||||
var backgroundCardAlpha by stringPref(default = "00")
|
||||
|
||||
var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f)
|
||||
var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f)
|
||||
var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
class WeatherWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
|
||||
override fun doWork(): Result {
|
||||
Log.d("ciao1", "weather ok")
|
||||
WeatherHelper.updateWeather(applicationContext)
|
||||
return Result.success()
|
||||
}
|
||||
|
@ -1,24 +1,27 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.activities
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.animation.addListener
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.badge.BadgeDrawable
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
|
||||
@ -33,6 +36,7 @@ import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.adapters.ViewPagerAdapter
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
@ -73,7 +77,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
// Init clock
|
||||
time.setTextColor(ColorHelper.getFontColor())
|
||||
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(this@MainActivity))
|
||||
time.isVisible = Preferences.showClock
|
||||
time_am_pm.setTextColor(ColorHelper.getFontColor())
|
||||
time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(this@MainActivity) / 5 * 2)
|
||||
time_container.isVisible = Preferences.showClock
|
||||
|
||||
preview.layoutParams = preview.layoutParams.apply {
|
||||
height = 160.toPixel(this@MainActivity) + if (Preferences.showClock) 100.toPixel(this@MainActivity) else 0
|
||||
@ -85,6 +91,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
|
||||
WeatherHelper.updateWeather(this)
|
||||
|
||||
|
||||
// Warnings
|
||||
if (getString(R.string.xiaomi_manufacturer).equals(Build.MANUFACTURER, ignoreCase = true) && Preferences.showXiaomiWarning) {
|
||||
MaterialBottomSheetDialog(this, getString(R.string.xiaomi_warning_title), getString(R.string.xiaomi_warning_message))
|
||||
.setNegativeButton(getString(R.string.action_ignore)) {
|
||||
@ -114,6 +122,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
) android.R.color.white else R.color.colorAccent
|
||||
)
|
||||
)
|
||||
widget_shape_background.setImageDrawable(BitmapHelper.getTintedDrawable(this, R.drawable.card_background, ColorHelper.getBackgroundColor()))
|
||||
uiJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
delay(200)
|
||||
val generatedView = MainWidget.generateWidgetView(this@MainActivity)
|
||||
@ -131,11 +140,15 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
withContext(Dispatchers.Main) {
|
||||
// Clock
|
||||
time.setTextColor(ColorHelper.getFontColor())
|
||||
time_am_pm.setTextColor(ColorHelper.getFontColor())
|
||||
time.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(this@MainActivity)
|
||||
)
|
||||
time.format12Hour = "hh:mm"
|
||||
time_am_pm.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(this@MainActivity) / 5 * 2
|
||||
)
|
||||
|
||||
// Clock bottom margin
|
||||
clock_bottom_margin_none.isVisible =
|
||||
@ -147,14 +160,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
clock_bottom_margin_large.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value
|
||||
|
||||
if ((Preferences.showClock && !time.isVisible) || (!Preferences.showClock && time.isVisible)) {
|
||||
if ((Preferences.showClock && !time_container.isVisible) || (!Preferences.showClock && time_container.isVisible)) {
|
||||
if (Preferences.showClock) {
|
||||
time.layoutParams = time.layoutParams.apply {
|
||||
time_container.layoutParams = time_container.layoutParams.apply {
|
||||
height = RelativeLayout.LayoutParams.WRAP_CONTENT
|
||||
}
|
||||
time.measure(0, 0)
|
||||
time_container.measure(0, 0)
|
||||
}
|
||||
val initialHeight = time.measuredHeight
|
||||
val initialHeight = time_container.measuredHeight
|
||||
ValueAnimator.ofFloat(
|
||||
if (Preferences.showClock) 0f else 1f,
|
||||
if (Preferences.showClock) 1f else 0f
|
||||
@ -162,19 +175,19 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Float
|
||||
time.layoutParams = time.layoutParams.apply {
|
||||
time_container.layoutParams = time_container.layoutParams.apply {
|
||||
height = (initialHeight * animatedValue).toInt()
|
||||
}
|
||||
}
|
||||
addListener(
|
||||
onStart = {
|
||||
if (Preferences.showClock) {
|
||||
time.isVisible = true
|
||||
time_container.isVisible = true
|
||||
}
|
||||
},
|
||||
onEnd = {
|
||||
if (!Preferences.showClock) {
|
||||
time.isVisible = false
|
||||
time_container.isVisible = false
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -195,10 +208,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
}.start()
|
||||
} else {
|
||||
time.layoutParams = time.layoutParams.apply {
|
||||
time_container.layoutParams = time_container.layoutParams.apply {
|
||||
height = RelativeLayout.LayoutParams.WRAP_CONTENT
|
||||
}
|
||||
time.measure(0, 0)
|
||||
time_container.measure(0, 0)
|
||||
}
|
||||
|
||||
if (preview.height == 0) {
|
||||
@ -237,6 +250,19 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
||||
// Calendar error indicator
|
||||
tabs.getTabAt(1)?.orCreateBadge?.apply {
|
||||
backgroundColor = ContextCompat.getColor(this@MainActivity, R.color.errorColorText)
|
||||
badgeGravity = BadgeDrawable.TOP_END
|
||||
}?.isVisible = Preferences.showEvents && !checkGrantedPermission(Manifest.permission.READ_CALENDAR)
|
||||
|
||||
// Weather error indicator
|
||||
tabs.getTabAt(2)?.orCreateBadge?.apply {
|
||||
backgroundColor = ContextCompat.getColor(this@MainActivity, R.color.errorColorText)
|
||||
badgeGravity = BadgeDrawable.TOP_END
|
||||
}?.isVisible = Preferences.showWeather && (Preferences.weatherProviderApi == "" || (Preferences.customLocationAdd == "" && !checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION)))
|
||||
}
|
||||
|
||||
private fun subscribeUi(viewModel: MainViewModel) {
|
||||
|
@ -79,21 +79,31 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
) {
|
||||
viewModel.darkThemePreference.observe(viewLifecycleOwner, Observer {
|
||||
AppCompatDelegate.setDefaultNightMode(it)
|
||||
theme?.text = when (it) {
|
||||
AppCompatDelegate.MODE_NIGHT_NO -> getString(R.string.settings_subtitle_dark_theme_light)
|
||||
AppCompatDelegate.MODE_NIGHT_YES -> getString(R.string.settings_subtitle_dark_theme_dark)
|
||||
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> getString(R.string.settings_subtitle_dark_theme_by_battery_saver)
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> getString(R.string.settings_subtitle_dark_theme_follow_system)
|
||||
else -> ""
|
||||
maintainScrollPosition {
|
||||
theme?.text = when (it) {
|
||||
AppCompatDelegate.MODE_NIGHT_NO -> getString(R.string.settings_subtitle_dark_theme_light)
|
||||
AppCompatDelegate.MODE_NIGHT_YES -> getString(R.string.settings_subtitle_dark_theme_dark)
|
||||
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> getString(R.string.settings_subtitle_dark_theme_by_battery_saver)
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> getString(R.string.settings_subtitle_dark_theme_follow_system)
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.showPreview.observe(viewLifecycleOwner, Observer {
|
||||
show_widget_preview_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
maintainScrollPosition {
|
||||
show_widget_preview_label?.text =
|
||||
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.showWallpaper.observe(viewLifecycleOwner, Observer {
|
||||
show_wallpaper_label?.text = if (it && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
maintainScrollPosition {
|
||||
show_wallpaper_label?.text =
|
||||
if (it && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true) getString(
|
||||
R.string.settings_visible
|
||||
) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,12 @@ package com.tommasoberlose.anotherwidget.ui.fragments
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -42,7 +40,6 @@ import kotlinx.android.synthetic.main.fragment_calendar_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
|
||||
@ -89,7 +86,6 @@ class CalendarSettingsFragment : Fragment() {
|
||||
binding.isCalendarEnabled = it
|
||||
|
||||
if (it) {
|
||||
requirePermission()
|
||||
CalendarHelper.setEventUpdatesAndroidN(requireContext())
|
||||
} else {
|
||||
CalendarHelper.removeEventUpdatesAndroidN(requireContext())
|
||||
@ -321,12 +317,12 @@ class CalendarSettingsFragment : Fragment() {
|
||||
private fun checkReadEventsPermission(showEvents: Boolean = Preferences.showEvents) {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.READ_CALENDAR) == true) {
|
||||
show_events_label?.text = if (showEvents) getString(R.string.show_events_visible) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert_icon?.isVisible = false
|
||||
read_calendar_permission_alert?.isVisible = false
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
} else {
|
||||
show_events_label?.text = if (showEvents) getString(R.string.description_permission_calendar) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert_icon?.isVisible = showEvents
|
||||
read_calendar_permission_alert_icon?.setOnClickListener {
|
||||
read_calendar_permission_alert?.isVisible = showEvents
|
||||
read_calendar_permission_alert?.setOnClickListener {
|
||||
requirePermission()
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -18,6 +20,9 @@ import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentGeneralSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toHexValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
@ -71,6 +76,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
private fun subscribeUi(
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
@ -89,12 +95,45 @@ class GeneralSettingsFragment : Fragment() {
|
||||
|
||||
viewModel.textGlobalColor.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
try {
|
||||
Color.parseColor(it)
|
||||
} catch (e: Exception) {
|
||||
Preferences.textGlobalColor = "#FFFFFF"
|
||||
if (Preferences.textGlobalAlpha == "00") {
|
||||
font_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
font_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.textGlobalAlpha.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.textGlobalAlpha == "00") {
|
||||
font_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
font_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.backgroundCardColor.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.backgroundCardAlpha == "00") {
|
||||
background_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
background_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.backgroundCardAlpha.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.backgroundCardAlpha == "00") {
|
||||
background_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
background_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase()
|
||||
}
|
||||
font_color_label?.text = it.toUpperCase()
|
||||
}
|
||||
})
|
||||
|
||||
@ -142,19 +181,35 @@ class GeneralSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_font_color.setOnClickListener {
|
||||
val textColor = try {
|
||||
Color.parseColor(Preferences.textGlobalColor)
|
||||
} catch (e: Exception) {
|
||||
Preferences.textGlobalColor = "#FFFFFF"
|
||||
Color.parseColor(Preferences.textGlobalColor)
|
||||
}
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
selected = textColor,
|
||||
selected = ColorHelper.getFontColor(),
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
},
|
||||
showAlphaSelector = true,
|
||||
alpha = Preferences.textGlobalAlpha.toIntValue(),
|
||||
onAlphaChangeListener = { alpha ->
|
||||
Preferences.textGlobalAlpha = alpha.toHexValue()
|
||||
}
|
||||
).show()
|
||||
}
|
||||
|
||||
action_background_color.setOnClickListener {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_background_color_title),
|
||||
selected = ColorHelper.getBackgroundColor(),
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.backgroundCardColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
},
|
||||
showAlphaSelector = true,
|
||||
alpha = Preferences.backgroundCardAlpha.toIntValue(),
|
||||
onAlphaChangeListener = { alpha ->
|
||||
Preferences.backgroundCardAlpha = alpha.toHexValue()
|
||||
}
|
||||
).show()
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -98,7 +99,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
if (it == "") getString(R.string.settings_weather_provider_api_key_subtitle_not_set) else getString(
|
||||
R.string.settings_weather_provider_api_key_subtitle_all_set
|
||||
)
|
||||
api_key_alert_icon?.isVisible = it == ""
|
||||
label_weather_provider_api_key?.setTextColor(ContextCompat.getColor(requireContext(), if (it == "") R.color.errorColorText else R.color.colorSecondaryText))
|
||||
}
|
||||
checkLocationPermission()
|
||||
})
|
||||
@ -135,12 +136,17 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkLocationPermission() {
|
||||
// Background permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && activity?.checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
||||
requirePermission()
|
||||
}
|
||||
|
||||
if (activity?.checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
||||
location_permission_alert_icon?.isVisible = false
|
||||
location_permission_alert?.isVisible = false
|
||||
WeatherWorker.setUpdates(requireContext())
|
||||
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
||||
location_permission_alert_icon?.isVisible = true
|
||||
location_permission_alert_icon?.setOnClickListener {
|
||||
location_permission_alert?.isVisible = true
|
||||
location_permission_alert?.setOnClickListener {
|
||||
requirePermission()
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ class MainViewModel : ViewModel() {
|
||||
|
||||
// General Settings
|
||||
val textGlobalColor = Preferences.asLiveData(Preferences::textGlobalColor)
|
||||
val textGlobalAlpha = Preferences.asLiveData(Preferences::textGlobalAlpha)
|
||||
val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor)
|
||||
val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha)
|
||||
val textMainSize = Preferences.asLiveData(Preferences::textMainSize)
|
||||
val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize)
|
||||
val textShadow = Preferences.asLiveData(Preferences::textShadow)
|
||||
|
@ -12,6 +12,7 @@ import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
@ -35,6 +36,7 @@ import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.getCapWordString
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import kotlinx.android.synthetic.main.the_widget.view.*
|
||||
import kotlinx.android.synthetic.main.the_widget_sans.*
|
||||
import java.lang.Exception
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
@ -95,7 +97,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
val displayMetrics = Resources.getSystem().displayMetrics
|
||||
val width = displayMetrics.widthPixels
|
||||
|
||||
val dimensions = WidgetHelper.WidgetSizeProvider(context, appWidgetManager).getWidgetsSize(appWidgetId).reduceDimensionWithMaxWidth(1200)
|
||||
val dimensions = WidgetHelper.WidgetSizeProvider(context, appWidgetManager).getWidgetsSize(appWidgetId)
|
||||
generateWidgetView(context, appWidgetId, appWidgetManager, dimensions.first - 8.toPixel(context) /*width - 16.toPixel(context)*/)
|
||||
}
|
||||
|
||||
@ -105,6 +107,10 @@ class MainWidget : AppWidgetProvider() {
|
||||
val generatedView = generateWidgetView(context)
|
||||
views.setImageViewBitmap(R.id.bitmap_container, BitmapHelper.getBitmapFromView(generatedView, width = w))
|
||||
|
||||
// Background
|
||||
views.setInt(R.id.widget_shape_background, "setColorFilter", ColorHelper.getBackgroundColorRgb())
|
||||
views.setInt(R.id.widget_shape_background, "setImageAlpha", ColorHelper.getBackgroundAlpha())
|
||||
|
||||
// Clock
|
||||
views = updateClockView(context, views, appWidgetId)
|
||||
|
||||
@ -262,6 +268,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
}
|
||||
|
||||
@ -295,6 +302,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
views.setViewVisibility(R.id.calendar_weather_rect, View.GONE)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
}
|
||||
return views
|
||||
@ -304,17 +312,24 @@ class MainWidget : AppWidgetProvider() {
|
||||
try {
|
||||
if (!Preferences.showClock) {
|
||||
views.setViewVisibility(R.id.time, View.GONE)
|
||||
views.setViewVisibility(R.id.time_am_pm, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_none, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_small, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_medium, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE)
|
||||
} else {
|
||||
views.setTextColor(R.id.time, ColorHelper.getFontColor())
|
||||
views.setTextColor(R.id.time_am_pm, ColorHelper.getFontColor())
|
||||
views.setTextViewTextSize(
|
||||
R.id.time,
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(context)
|
||||
)
|
||||
views.setTextViewTextSize(
|
||||
R.id.time_am_pm,
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(context) / 5 * 2
|
||||
)
|
||||
val clockPIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
@ -322,7 +337,9 @@ class MainWidget : AppWidgetProvider() {
|
||||
0
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.time, clockPIntent)
|
||||
views.setOnClickPendingIntent(R.id.time_am_pm, clockPIntent)
|
||||
views.setViewVisibility(R.id.time, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.time_am_pm, View.VISIBLE)
|
||||
|
||||
views.setViewVisibility(
|
||||
R.id.clock_bottom_margin_none,
|
||||
@ -342,6 +359,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user