Add clock text color
This commit is contained in:
@ -45,6 +45,9 @@ object Preferences : KotprefModel() {
|
||||
var backgroundCardColor by stringPref(default = "#000000")
|
||||
var backgroundCardAlpha by stringPref(default = "00")
|
||||
|
||||
var clockTextColor by stringPref(default = "#FFFFFF")
|
||||
var clockTextAlpha by stringPref(default = "FF")
|
||||
|
||||
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)
|
||||
|
@ -17,22 +17,41 @@ object BitmapHelper {
|
||||
//Define a bitmap with the same size as the view
|
||||
val measuredWidth = View.MeasureSpec.makeMeasureSpec(width ?: view.width, if (width != null) View.MeasureSpec.EXACTLY else View.MeasureSpec.AT_MOST)
|
||||
val measuredHeight = View.MeasureSpec.makeMeasureSpec(height ?: view.height, if (height != null) View.MeasureSpec.EXACTLY else View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(measuredWidth, measuredHeight)
|
||||
view.measure(
|
||||
if (measuredWidth > 0) measuredWidth else 0,
|
||||
if (measuredHeight > 0) measuredHeight else 0
|
||||
)
|
||||
|
||||
val calculatedWidth = view.measuredWidth
|
||||
val widgetWidth = if (calculatedWidth in 1..16000) {
|
||||
calculatedWidth
|
||||
} else if (width != null && width > 0) {
|
||||
width
|
||||
} else {
|
||||
1
|
||||
}
|
||||
val calculatedHeight = view.measuredHeight
|
||||
val widgetHeight = if (calculatedHeight in 1..16000) {
|
||||
calculatedHeight
|
||||
} else if (height != null && height > 0) {
|
||||
height
|
||||
} else {
|
||||
1
|
||||
}
|
||||
|
||||
if (draw) {
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("initialWidth", width ?: -1)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("initialHeight", height ?: -1)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("measuredWidth", view.measuredWidth)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("measuredWidth_spec", measuredWidth)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("measuredHeight", view.measuredHeight)
|
||||
FirebaseCrashlytics.getInstance()
|
||||
.setCustomKey("measuredHeight_spec", measuredHeight)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("WIDTH SPEC", measuredWidth)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("HEIGHT SPEC", measuredHeight)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("VIEW measuredWidth", view.measuredWidth)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("VIEW measuredHeight", view.measuredHeight)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final width", measuredWidth)
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final height", view.measuredHeight)
|
||||
}
|
||||
|
||||
return try {
|
||||
val btm = Bitmap.createBitmap(
|
||||
view.measuredWidth,
|
||||
view.measuredHeight,
|
||||
widgetWidth,
|
||||
widgetHeight,
|
||||
if (draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
||||
)
|
||||
if (draw) {
|
||||
|
@ -4,14 +4,12 @@ import android.Manifest
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.services.EventListenerJob
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.AppMainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import me.everything.providers.android.calendar.CalendarProvider
|
||||
@ -128,7 +126,7 @@ object CalendarHelper {
|
||||
UpdatesReceiver.setUpdates(context)
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
EventBus.getDefault().post(AppMainFragment.UpdateUiMessageEvent())
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
|
||||
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
||||
|
@ -30,6 +30,29 @@ object ColorHelper {
|
||||
Color.parseColor("#000000")
|
||||
}
|
||||
}
|
||||
fun getClockFontColor(): Int {
|
||||
return try {
|
||||
Color.parseColor("#%s%s".format(Preferences.clockTextAlpha, Preferences.clockTextColor.replace("#", "")))
|
||||
} catch (e: Exception) {
|
||||
Color.parseColor("#FFFFFFFF")
|
||||
}
|
||||
}
|
||||
|
||||
fun getClockFontColorAlpha(): Int {
|
||||
return try {
|
||||
Preferences.clockTextAlpha.toIntValue().toDouble() * 255 / 100
|
||||
} catch (e: Exception) {
|
||||
"FF".toIntValue().toDouble() * 255 / 100
|
||||
}.roundToInt()
|
||||
}
|
||||
|
||||
fun getClockFontColorRgb(): Int {
|
||||
return try {
|
||||
Color.parseColor(Preferences.clockTextColor)
|
||||
} catch (e: Exception) {
|
||||
Color.parseColor("#000000")
|
||||
}
|
||||
}
|
||||
|
||||
fun getBackgroundColor(): Int {
|
||||
return try {
|
||||
|
@ -3,18 +3,11 @@ package com.tommasoberlose.anotherwidget.helpers
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.EventLog
|
||||
import android.util.Log
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.kwabenaberko.openweathermaplib.constants.Units
|
||||
import com.kwabenaberko.openweathermaplib.implementation.OpenWeatherMapHelper
|
||||
import com.kwabenaberko.openweathermaplib.implementation.callbacks.CurrentWeatherCallback
|
||||
import com.kwabenaberko.openweathermaplib.models.currentweather.CurrentWeather
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.network.WeatherNetworkApi
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.AppMainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@ -39,7 +32,7 @@ object WeatherHelper {
|
||||
Preferences.customLocationLon = location.longitude.toString()
|
||||
|
||||
networkApi.updateWeather()
|
||||
EventBus.getDefault().post(AppMainFragment.UpdateUiMessageEvent())
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package com.tommasoberlose.anotherwidget.network
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.kwabenaberko.openweathermaplib.constants.Units
|
||||
import com.kwabenaberko.openweathermaplib.implementation.OpenWeatherMapHelper
|
||||
import com.kwabenaberko.openweathermaplib.implementation.callbacks.CurrentWeatherCallback
|
||||
import com.kwabenaberko.openweathermaplib.models.currentweather.CurrentWeather
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.AppMainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
@ -27,7 +25,7 @@ class WeatherNetworkApi(val context: Context) {
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
EventBus.getDefault().post(AppMainFragment.UpdateUiMessageEvent())
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,10 @@ class ViewPagerAdapter(fragmentActivity: FragmentActivity) :
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
1 -> CalendarSettingsFragment.newInstance()
|
||||
2 -> WeatherSettingsFragment.newInstance()
|
||||
3 -> ClockSettingsFragment.newInstance()
|
||||
else -> GeneralSettingsFragment.newInstance()
|
||||
1 -> CalendarTabFragment.newInstance()
|
||||
2 -> WeatherTabFragment.newInstance()
|
||||
3 -> ClockTabFragment.newInstance()
|
||||
else -> GeneralTabFragment.newInstance()
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ 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
|
||||
@ -43,10 +42,10 @@ import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
|
||||
class CalendarSettingsFragment : Fragment() {
|
||||
class CalendarTabFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = CalendarSettingsFragment()
|
||||
fun newInstance() = CalendarTabFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
@ -6,7 +6,6 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@ -20,29 +19,35 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentClockSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.helpers.AlarmHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toHexValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlinx.android.synthetic.main.fragment_clock_settings.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
class ClockSettingsFragment : Fragment() {
|
||||
class ClockTabFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = ClockSettingsFragment()
|
||||
fun newInstance() = ClockTabFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var colors: IntArray
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -67,6 +72,12 @@ class ClockSettingsFragment : Fragment() {
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val lazyColors = requireContext().resources.getIntArray(R.array.material_colors)
|
||||
withContext(Dispatchers.Main) {
|
||||
colors = lazyColors
|
||||
}
|
||||
}
|
||||
setupListener()
|
||||
updateNextAlarmWarningUi()
|
||||
}
|
||||
@ -94,6 +105,28 @@ class ClockSettingsFragment : Fragment() {
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.clockTextColor.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.clockTextAlpha == "00") {
|
||||
clock_text_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
clock_text_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.clockTextAlpha.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.clockTextAlpha == "00") {
|
||||
clock_text_color_label?.text = getString(R.string.transparent)
|
||||
} else {
|
||||
clock_text_color_label?.text =
|
||||
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.clockBottomMargin.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
clock_bottom_margin_label?.text = when (it) {
|
||||
@ -136,6 +169,23 @@ class ClockSettingsFragment : Fragment() {
|
||||
}.show()
|
||||
}
|
||||
|
||||
action_clock_text_color.setOnClickListener {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
getSelected = ColorHelper::getClockFontColorRgb,
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.clockTextColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
},
|
||||
showAlphaSelector = true,
|
||||
alpha = Preferences.clockTextAlpha.toIntValue(),
|
||||
onAlphaChangeListener = { alpha ->
|
||||
Preferences.clockTextAlpha = alpha.toHexValue()
|
||||
}
|
||||
).show()
|
||||
}
|
||||
|
||||
action_clock_bottom_margin_size.setOnClickListener {
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_show_next_alarm_title)).setSelectedValue(Preferences.clockBottomMargin)
|
||||
.addItem(getString(R.string.settings_clock_bottom_margin_subtitle_none), Constants.ClockBottomMargin.NONE.value)
|
@ -3,9 +3,7 @@ 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
|
||||
@ -33,10 +31,10 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class GeneralSettingsFragment : Fragment() {
|
||||
class GeneralTabFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = GeneralSettingsFragment()
|
||||
fun newInstance() = GeneralTabFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
@ -17,13 +17,11 @@ import android.widget.RelativeLayout
|
||||
import androidx.core.animation.addListener
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.navigation.fragment.FragmentNavigator
|
||||
import com.google.android.material.badge.BadgeDrawable
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
@ -50,10 +48,10 @@ import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
class AppMainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = AppMainFragment()
|
||||
fun newInstance() = MainFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
@ -91,9 +89,9 @@ class AppMainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeL
|
||||
}.attach()
|
||||
|
||||
// Init clock
|
||||
time.setTextColor(ColorHelper.getFontColor())
|
||||
time.setTextColor(ColorHelper.getClockFontColor())
|
||||
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()))
|
||||
time_am_pm.setTextColor(ColorHelper.getFontColor())
|
||||
time_am_pm.setTextColor(ColorHelper.getClockFontColor())
|
||||
time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2)
|
||||
time_container.isVisible = Preferences.showClock
|
||||
|
||||
@ -151,8 +149,8 @@ class AppMainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeL
|
||||
)
|
||||
withContext(Dispatchers.Main) {
|
||||
// Clock
|
||||
time.setTextColor(ColorHelper.getFontColor())
|
||||
time_am_pm.setTextColor(ColorHelper.getFontColor())
|
||||
time.setTextColor(ColorHelper.getClockFontColor())
|
||||
time_am_pm.setTextColor(ColorHelper.getClockFontColor())
|
||||
time.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(requireContext())
|
@ -41,10 +41,10 @@ import kotlinx.android.synthetic.main.fragment_weather_settings.scrollView
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class WeatherSettingsFragment : Fragment() {
|
||||
class WeatherTabFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = WeatherSettingsFragment()
|
||||
fun newInstance() = WeatherTabFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
@ -27,10 +27,11 @@ class MainViewModel : ViewModel() {
|
||||
val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails)
|
||||
val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName)
|
||||
|
||||
|
||||
// Clock Settings
|
||||
val showClock = Preferences.asLiveData(Preferences::showClock)
|
||||
val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize)
|
||||
val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor)
|
||||
val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha)
|
||||
|
||||
val clockAppName = Preferences.asLiveData(Preferences::clockAppName)
|
||||
val showNextAlarm = Preferences.asLiveData(Preferences::showNextAlarm)
|
||||
|
@ -334,8 +334,8 @@ class MainWidget : AppWidgetProvider() {
|
||||
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.setTextColor(R.id.time, ColorHelper.getClockFontColor())
|
||||
views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor())
|
||||
views.setTextViewTextSize(
|
||||
R.id.time,
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
|
Reference in New Issue
Block a user