Added custom widget margin and padding, added new preview manager
@ -31,22 +31,5 @@ class AWApplication : Application() {
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
Realm.setDefaultConfiguration(config)
|
||||
|
||||
calibrateVersions()
|
||||
}
|
||||
|
||||
private fun calibrateVersions() {
|
||||
// 2.0 Tolerance
|
||||
if (Preferences.clockTextSize > 50f) {
|
||||
Preferences.clockTextSize = 32f
|
||||
}
|
||||
|
||||
if (Preferences.textMainSize > 36f) {
|
||||
Preferences.textMainSize = 32f
|
||||
}
|
||||
|
||||
if (Preferences.textSecondSize > 28f) {
|
||||
Preferences.textSecondSize = 24f
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,13 @@ object Constants {
|
||||
LARGE(3)
|
||||
}
|
||||
|
||||
enum class Dimension(val rawValue: Float) {
|
||||
NONE(0f),
|
||||
SMALL(8f),
|
||||
MEDIUM(16f),
|
||||
LARGE(24f)
|
||||
}
|
||||
|
||||
enum class GlanceProviderId(val id: String) {
|
||||
PLAYING_SONG("PLAYING_SONG"),
|
||||
NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"),
|
||||
|
@ -84,6 +84,10 @@ object Preferences : KotprefModel() {
|
||||
|
||||
var weatherIconPack by intPref(default = Constants.WeatherIconPack.DEFAULT.rawValue)
|
||||
|
||||
// UI
|
||||
var widgetMargin by floatPref(default = Constants.Dimension.SMALL.rawValue)
|
||||
var widgetPadding by floatPref(default = Constants.Dimension.SMALL.rawValue)
|
||||
|
||||
// Clock
|
||||
var altTimezoneLabel by stringPref(default = "")
|
||||
var altTimezoneId by stringPref(default = "")
|
||||
|
@ -8,16 +8,10 @@ import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isVisible
|
||||
import android.widget.RemoteViews
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@ -30,23 +24,20 @@ import com.tommasoberlose.anotherwidget.databinding.FragmentAppMainBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.StandardWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
|
||||
class MainFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = MainFragment()
|
||||
private val PREVIEW_BASE_HEIGHT: Int
|
||||
get() = if (Preferences.widgetAlign == Constants.WidgetAlign.CENTER.rawValue) 120 else 180
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
@ -98,13 +89,7 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.actionSettings.setOnSingleClickListener {
|
||||
Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment,)
|
||||
}
|
||||
|
||||
binding.preview.layoutParams = binding.preview.layoutParams.apply {
|
||||
height = PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(
|
||||
requireContext()
|
||||
) else 0
|
||||
Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment)
|
||||
}
|
||||
|
||||
subscribeUi(viewModel)
|
||||
@ -156,79 +141,31 @@ class MainFragment : Fragment() {
|
||||
binding.toolbar.cardElevation = if (it > 0) 24f else 0f
|
||||
}
|
||||
|
||||
viewModel.widgetAlign.observe(viewLifecycleOwner) {
|
||||
updatePreviewVisibility()
|
||||
lifecycleScope.launch {
|
||||
delay(350)
|
||||
updateClock()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.showPreview.observe(viewLifecycleOwner) {
|
||||
updatePreviewVisibility()
|
||||
}
|
||||
|
||||
viewModel.clockPreferencesUpdate.observe(viewLifecycleOwner) {
|
||||
updateClock()
|
||||
onUpdateUiEvent(null)
|
||||
}
|
||||
|
||||
viewModel.widgetPreferencesUpdate.observe(viewLifecycleOwner) {
|
||||
onUpdateUiEvent(null)
|
||||
}
|
||||
|
||||
viewModel.showClock.observe(viewLifecycleOwner) {
|
||||
updateClockVisibility(it)
|
||||
}
|
||||
}
|
||||
|
||||
private var uiJob: Job? = null
|
||||
|
||||
private fun updateUI() {
|
||||
if (Preferences.showPreview) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val bgColor: Int = ContextCompat.getColor(
|
||||
requireContext(),
|
||||
if (ColorHelper.getFontColor(requireActivity().isDarkTheme())
|
||||
.isColorDark()
|
||||
) android.R.color.white else R.color.colorAccent
|
||||
)
|
||||
|
||||
val wallpaperDrawable = BitmapHelper.getTintedDrawable(
|
||||
requireContext(),
|
||||
R.drawable.card_background,
|
||||
ColorHelper.getBackgroundColor(requireActivity().isDarkTheme())
|
||||
)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.preview.setCardBackgroundColor(bgColor)
|
||||
binding.widgetDetail.widgetShapeBackground.setImageDrawable(wallpaperDrawable)
|
||||
}
|
||||
}
|
||||
|
||||
WidgetHelper.runWithCustomTypeface(requireContext()) { typeface ->
|
||||
uiJob?.cancel()
|
||||
uiJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
val generatedView = MainWidget.getWidgetView(requireContext(), typeface)?.root
|
||||
val generatedView = MainWidget.getWidgetView(requireContext(), binding.widget.width, typeface)
|
||||
|
||||
if (generatedView != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
binding.widgetDetail.content.removeAllViews()
|
||||
val container = LinearLayout(requireContext()).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
}
|
||||
container.gravity = when (Preferences.widgetAlign) {
|
||||
Constants.WidgetAlign.CENTER.rawValue -> Gravity.CENTER_HORIZONTAL
|
||||
Constants.WidgetAlign.LEFT.rawValue -> Gravity.START
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> Gravity.END
|
||||
else -> Gravity.NO_GRAVITY
|
||||
}
|
||||
container.addView(generatedView)
|
||||
binding.widgetDetail.content.addView(container)
|
||||
|
||||
val view: View = generatedView.apply(requireActivity().applicationContext, binding.widget)
|
||||
view.measure(0, 0)
|
||||
binding.widget.removeAllViews()
|
||||
binding.widget.addView(view)
|
||||
updatePreviewVisibility(view.measuredHeight)
|
||||
binding.widgetLoader.animate().scaleX(0f).scaleY(0f).alpha(0f)
|
||||
.setDuration(200L).start()
|
||||
binding.widget.animate().alpha(1f).start()
|
||||
@ -239,136 +176,13 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateClock() {
|
||||
// Clock
|
||||
binding.widgetDetail.time.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
|
||||
binding.widgetDetail.timeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
|
||||
binding.widgetDetail.time.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(requireContext())
|
||||
)
|
||||
binding.widgetDetail.timeAmPm.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2
|
||||
)
|
||||
binding.widgetDetail.timeAmPm.isVisible = Preferences.showAMPMIndicator
|
||||
|
||||
// Timezones
|
||||
if (Preferences.altTimezoneId != "" && Preferences.altTimezoneLabel != "") {
|
||||
// Clock
|
||||
binding.widgetDetail.altTimezoneTime.timeZone = Preferences.altTimezoneId
|
||||
binding.widgetDetail.altTimezoneTimeAmPm.timeZone = Preferences.altTimezoneId
|
||||
binding.widgetDetail.altTimezoneLabel.text = Preferences.altTimezoneLabel
|
||||
binding.widgetDetail.altTimezoneTime.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
|
||||
binding.widgetDetail.altTimezoneTimeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
|
||||
binding.widgetDetail.altTimezoneLabel.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
|
||||
binding.widgetDetail.altTimezoneTime.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
Preferences.clockTextSize.toPixel(requireContext()) / 3
|
||||
)
|
||||
binding.widgetDetail.altTimezoneTimeAmPm.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
(Preferences.clockTextSize.toPixel(requireContext()) / 3) / 5 * 2
|
||||
)
|
||||
binding.widgetDetail.altTimezoneLabel.setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
(Preferences.clockTextSize.toPixel(requireContext()) / 3) / 5 * 2
|
||||
)
|
||||
binding.widgetDetail.timezonesContainer.isVisible = true
|
||||
} else {
|
||||
binding.widgetDetail.timezonesContainer.isVisible = false
|
||||
}
|
||||
|
||||
// Clock bottom margin
|
||||
binding.widgetDetail.clockBottomMarginNone.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.NONE.rawValue
|
||||
binding.widgetDetail.clockBottomMarginSmall.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.SMALL.rawValue
|
||||
binding.widgetDetail.clockBottomMarginMedium.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.MEDIUM.rawValue
|
||||
binding.widgetDetail.clockBottomMarginLarge.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.rawValue
|
||||
|
||||
// Align
|
||||
binding.widgetDetail.timeContainer.layoutParams = (binding.widgetDetail.timeContainer.layoutParams as LinearLayout.LayoutParams).apply {
|
||||
gravity = when (Preferences.widgetAlign) {
|
||||
Constants.WidgetAlign.CENTER.rawValue -> Gravity.CENTER_HORIZONTAL
|
||||
Constants.WidgetAlign.LEFT.rawValue -> Gravity.START
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> Gravity.END
|
||||
else -> Gravity.NO_GRAVITY
|
||||
}
|
||||
}
|
||||
if (Preferences.widgetAlign == Constants.WidgetAlign.RIGHT.rawValue) {
|
||||
with (binding.widgetDetail.timeContainer) {
|
||||
val child = getChildAt(2)
|
||||
if (child.id == R.id.timezones_container) {
|
||||
removeViewAt(2)
|
||||
child.layoutParams = (child.layoutParams as ViewGroup.MarginLayoutParams).apply {
|
||||
marginEnd = 16f.convertDpToPixel(requireContext()).toInt()
|
||||
}
|
||||
addView(child, 0)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
with (binding.widgetDetail.timeContainer) {
|
||||
val child = getChildAt(0)
|
||||
if (child.id == R.id.timezones_container) {
|
||||
removeViewAt(0)
|
||||
child.layoutParams = (child.layoutParams as ViewGroup.MarginLayoutParams).apply {
|
||||
marginEnd = 0
|
||||
}
|
||||
addView(child, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateClockVisibility(showClock: Boolean) {
|
||||
binding.widgetDetail.timeContainer.clearAnimation()
|
||||
binding.widgetDetail.time.clearAnimation()
|
||||
|
||||
updatePreviewVisibility()
|
||||
|
||||
if (showClock) {
|
||||
binding.widgetDetail.timeContainer.layoutParams = (binding.widgetDetail.timeContainer.layoutParams as LinearLayout.LayoutParams).apply {
|
||||
height = RelativeLayout.LayoutParams.WRAP_CONTENT
|
||||
}
|
||||
binding.widgetDetail.timeContainer.measure(0, 0)
|
||||
}
|
||||
|
||||
if ((Preferences.showClock && binding.widgetDetail.time.alpha != 1f) || (!Preferences.showClock && binding.widgetDetail.time.alpha != 0f)) {
|
||||
val initialHeight = binding.widgetDetail.timeContainer.measuredHeight
|
||||
ValueAnimator.ofFloat(
|
||||
if (showClock) 0f else 1f,
|
||||
if (showClock) 1f else 0f
|
||||
).apply {
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Float
|
||||
binding.widgetDetail.timeContainer.layoutParams =
|
||||
binding.widgetDetail.timeContainer.layoutParams.apply {
|
||||
height = (initialHeight * animatedValue).toInt()
|
||||
}
|
||||
binding.widgetDetail.time.alpha = animatedValue
|
||||
binding.widgetDetail.timeAmPm.alpha = animatedValue
|
||||
binding.widgetDetail.altTimezoneTime.alpha = animatedValue
|
||||
binding.widgetDetail.altTimezoneTimeAmPm.alpha = animatedValue
|
||||
binding.widgetDetail.altTimezoneLabel.alpha = animatedValue
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePreviewVisibility() {
|
||||
binding.preview.clearAnimation()
|
||||
if (binding.preview.layoutParams.height != (if (Preferences.showPreview) PREVIEW_BASE_HEIGHT.toPixel(requireContext()) else 0) + (if (Preferences.showClock) 100.toPixel(
|
||||
requireContext()
|
||||
) else 0)) {
|
||||
private fun updatePreviewVisibility(widgetHeight: Int) {
|
||||
val newHeight = widgetHeight + 16f.convertDpToPixel(requireContext()).toInt()
|
||||
if (binding.preview.layoutParams.height != newHeight) {
|
||||
binding.preview.clearAnimation()
|
||||
ValueAnimator.ofInt(
|
||||
binding.preview.height,
|
||||
(if (Preferences.showPreview) PREVIEW_BASE_HEIGHT.toPixel(requireContext()) else 0) + (if (Preferences.showClock) 100.toPixel(
|
||||
requireContext()
|
||||
) else 0)
|
||||
newHeight
|
||||
).apply {
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
|
@ -86,6 +86,28 @@ class LayoutFragment : Fragment() {
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
|
||||
viewModel.widgetMargin.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.widgetMarginLabel.text = when (it) {
|
||||
Constants.Dimension.NONE.rawValue -> getString(R.string.settings_widget_dim_none)
|
||||
Constants.Dimension.SMALL.rawValue -> getString(R.string.settings_widget_dim_small)
|
||||
Constants.Dimension.LARGE.rawValue -> getString(R.string.settings_widget_dim_large)
|
||||
else -> getString(R.string.settings_widget_dim_medium)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.widgetPadding.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.widgetPaddingLabel.text = when (it) {
|
||||
Constants.Dimension.NONE.rawValue -> getString(R.string.settings_widget_dim_none)
|
||||
Constants.Dimension.SMALL.rawValue -> getString(R.string.settings_widget_dim_small)
|
||||
Constants.Dimension.LARGE.rawValue -> getString(R.string.settings_widget_dim_large)
|
||||
else -> getString(R.string.settings_widget_dim_medium)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.secondRowTopMargin.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.secondRowTopMarginLabel.text = when (it) {
|
||||
@ -147,6 +169,58 @@ class LayoutFragment : Fragment() {
|
||||
|
||||
private fun setupListener() {
|
||||
|
||||
binding.actionWidgetMargin.setOnClickListener {
|
||||
BottomSheetMenu<Float>(
|
||||
requireContext(),
|
||||
header = getString(R.string.settings_widget_margin_title)
|
||||
).setSelectedValue(Preferences.widgetMargin)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_none),
|
||||
Constants.Dimension.NONE.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_small),
|
||||
Constants.Dimension.SMALL.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_medium),
|
||||
Constants.Dimension.MEDIUM.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_large),
|
||||
Constants.Dimension.LARGE.rawValue
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.widgetMargin = value
|
||||
}.show()
|
||||
}
|
||||
|
||||
binding.actionWidgetPadding.setOnClickListener {
|
||||
BottomSheetMenu<Float>(
|
||||
requireContext(),
|
||||
header = getString(R.string.settings_widget_padding_title)
|
||||
).setSelectedValue(Preferences.widgetPadding)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_none),
|
||||
Constants.Dimension.NONE.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_small),
|
||||
Constants.Dimension.SMALL.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_medium),
|
||||
Constants.Dimension.MEDIUM.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_dim_large),
|
||||
Constants.Dimension.LARGE.rawValue
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.widgetPadding = value
|
||||
}.show()
|
||||
}
|
||||
|
||||
binding.actionSecondRowTopMarginSize.setOnClickListener {
|
||||
BottomSheetMenu<Int>(
|
||||
requireContext(),
|
||||
|
@ -50,6 +50,8 @@ class MainViewModel(context: Application) : AndroidViewModel(context) {
|
||||
val showDividers = Preferences.asLiveData(Preferences::showDividers)
|
||||
val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin)
|
||||
val widgetAlign = Preferences.asLiveData(Preferences::widgetAlign)
|
||||
val widgetMargin = Preferences.asLiveData(Preferences::widgetMargin)
|
||||
val widgetPadding = Preferences.asLiveData(Preferences::widgetPadding)
|
||||
|
||||
// Calendar Settings
|
||||
val showEvents = Preferences.asLiveData(Preferences::showEvents)
|
||||
@ -136,6 +138,8 @@ class MainViewModel(context: Application) : AndroidViewModel(context) {
|
||||
addSource(Preferences.asLiveData(Preferences::customFontVariant)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::secondRowInformation)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::widgetAlign)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::widgetMargin)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::widgetPadding)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showDividers)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::secondRowTopMargin)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::isDateCapitalize)) { value = true }
|
||||
|
@ -54,6 +54,8 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
|
||||
"setImageAlpha",
|
||||
ColorHelper.getBackgroundAlpha(context.isDarkTheme())
|
||||
)
|
||||
val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt()
|
||||
views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin)
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
@ -61,6 +63,10 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
|
||||
// Padding
|
||||
val padding = (Preferences.widgetPadding.convertDpToPixel(context) + Preferences.widgetMargin.convertDpToPixel(context)).toInt()
|
||||
views.setViewPadding(R.id.main_layout, padding, padding, padding, padding)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
|
@ -7,7 +7,7 @@ import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import android.widget.RemoteViews
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
@ -83,11 +83,18 @@ class MainWidget : AppWidgetProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getWidgetView(context: Context, typeface: Typeface?): ViewBinding? {
|
||||
fun getWidgetView(context: Context, width: Int, typeface: Typeface?): RemoteViews? {
|
||||
return when (Preferences.widgetAlign) {
|
||||
Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidgetView(typeface)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(context, rightAligned = true).generateWidgetView(typeface)
|
||||
else -> StandardWidget(context).generateWidgetView(typeface)
|
||||
Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidget(
|
||||
0,
|
||||
width,
|
||||
typeface
|
||||
)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(
|
||||
context,
|
||||
rightAligned = true
|
||||
).generateWidget(0, width, typeface)
|
||||
else -> StandardWidget(context).generateWidget(0, width, typeface)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ class StandardWidget(val context: Context) {
|
||||
"setImageAlpha",
|
||||
ColorHelper.getBackgroundAlpha(context.isDarkTheme())
|
||||
)
|
||||
val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt()
|
||||
views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin)
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
@ -64,6 +66,10 @@ class StandardWidget(val context: Context) {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
|
||||
// Padding
|
||||
val padding = (Preferences.widgetPadding.convertDpToPixel(context) + Preferences.widgetMargin.convertDpToPixel(context)).toInt()
|
||||
views.setViewPadding(R.id.main_layout, padding, padding, padding, padding)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
|
@ -24,11 +24,13 @@ import android.util.TypedValue
|
||||
import android.view.animation.AlphaAnimation
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||
import androidx.core.animation.addListener
|
||||
import androidx.core.view.isVisible
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.OnSingleClickListener
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import java.util.*
|
||||
|
||||
|
||||
@ -192,7 +194,7 @@ fun String.isValidEmail(): Boolean
|
||||
Patterns.EMAIL_ADDRESS.matcher(this).matches()
|
||||
|
||||
fun Context.isDarkTheme(): Boolean {
|
||||
return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
return Preferences.darkThemePreference == AppCompatDelegate.MODE_NIGHT_YES || Preferences.darkThemePreference == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
fun Activity.isNotificationAccessGranted(): Boolean = Settings.Secure.getString(this.contentResolver,"enabled_notification_listeners").contains(this.packageName)
|
||||
|
BIN
app/src/main/res/drawable-hdpi/round_border_outer_black_18.png
Normal file
After Width: | Height: | Size: 180 B |
BIN
app/src/main/res/drawable-hdpi/round_border_outer_black_20.png
Normal file
After Width: | Height: | Size: 186 B |
BIN
app/src/main/res/drawable-hdpi/round_border_outer_black_24.png
Normal file
After Width: | Height: | Size: 188 B |
BIN
app/src/main/res/drawable-hdpi/round_border_outer_black_36.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
app/src/main/res/drawable-hdpi/round_border_outer_black_48.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
app/src/main/res/drawable-hdpi/round_dark_mode_white_18.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
app/src/main/res/drawable-hdpi/round_dark_mode_white_20.png
Normal file
After Width: | Height: | Size: 281 B |
BIN
app/src/main/res/drawable-hdpi/round_dark_mode_white_24.png
Normal file
After Width: | Height: | Size: 325 B |
BIN
app/src/main/res/drawable-hdpi/round_dark_mode_white_36.png
Normal file
After Width: | Height: | Size: 451 B |
BIN
app/src/main/res/drawable-hdpi/round_dark_mode_white_48.png
Normal file
After Width: | Height: | Size: 571 B |
BIN
app/src/main/res/drawable-hdpi/round_select_all_black_18.png
Normal file
After Width: | Height: | Size: 217 B |
BIN
app/src/main/res/drawable-hdpi/round_select_all_black_20.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
app/src/main/res/drawable-hdpi/round_select_all_black_24.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
app/src/main/res/drawable-hdpi/round_select_all_black_36.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/drawable-hdpi/round_select_all_black_48.png
Normal file
After Width: | Height: | Size: 268 B |
BIN
app/src/main/res/drawable-mdpi/round_border_outer_black_18.png
Normal file
After Width: | Height: | Size: 158 B |
BIN
app/src/main/res/drawable-mdpi/round_border_outer_black_20.png
Normal file
After Width: | Height: | Size: 155 B |
BIN
app/src/main/res/drawable-mdpi/round_border_outer_black_24.png
Normal file
After Width: | Height: | Size: 133 B |
BIN
app/src/main/res/drawable-mdpi/round_border_outer_black_36.png
Normal file
After Width: | Height: | Size: 188 B |
BIN
app/src/main/res/drawable-mdpi/round_border_outer_black_48.png
Normal file
After Width: | Height: | Size: 187 B |
BIN
app/src/main/res/drawable-mdpi/round_dark_mode_white_18.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
app/src/main/res/drawable-mdpi/round_dark_mode_white_20.png
Normal file
After Width: | Height: | Size: 194 B |
BIN
app/src/main/res/drawable-mdpi/round_dark_mode_white_24.png
Normal file
After Width: | Height: | Size: 226 B |
BIN
app/src/main/res/drawable-mdpi/round_dark_mode_white_36.png
Normal file
After Width: | Height: | Size: 325 B |
BIN
app/src/main/res/drawable-mdpi/round_dark_mode_white_48.png
Normal file
After Width: | Height: | Size: 397 B |
BIN
app/src/main/res/drawable-mdpi/round_select_all_black_18.png
Normal file
After Width: | Height: | Size: 194 B |
BIN
app/src/main/res/drawable-mdpi/round_select_all_black_20.png
Normal file
After Width: | Height: | Size: 173 B |
BIN
app/src/main/res/drawable-mdpi/round_select_all_black_24.png
Normal file
After Width: | Height: | Size: 141 B |
BIN
app/src/main/res/drawable-mdpi/round_select_all_black_36.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
app/src/main/res/drawable-mdpi/round_select_all_black_48.png
Normal file
After Width: | Height: | Size: 202 B |
BIN
app/src/main/res/drawable-night-hdpi/round_border_outer_24.png
Normal file
After Width: | Height: | Size: 193 B |
BIN
app/src/main/res/drawable-night-hdpi/round_select_all_24.png
Normal file
After Width: | Height: | Size: 227 B |
BIN
app/src/main/res/drawable-night-mdpi/round_border_outer_24.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
app/src/main/res/drawable-night-mdpi/round_select_all_24.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
app/src/main/res/drawable-night-xhdpi/round_border_outer_24.png
Normal file
After Width: | Height: | Size: 203 B |
BIN
app/src/main/res/drawable-night-xhdpi/round_select_all_24.png
Normal file
After Width: | Height: | Size: 215 B |
BIN
app/src/main/res/drawable-night-xxhdpi/round_border_outer_24.png
Normal file
After Width: | Height: | Size: 286 B |
BIN
app/src/main/res/drawable-night-xxhdpi/round_select_all_24.png
Normal file
After Width: | Height: | Size: 307 B |
After Width: | Height: | Size: 323 B |
BIN
app/src/main/res/drawable-night-xxxhdpi/round_select_all_24.png
Normal file
After Width: | Height: | Size: 364 B |
BIN
app/src/main/res/drawable-xhdpi/round_border_outer_black_18.png
Normal file
After Width: | Height: | Size: 188 B |
BIN
app/src/main/res/drawable-xhdpi/round_border_outer_black_20.png
Normal file
After Width: | Height: | Size: 199 B |
BIN
app/src/main/res/drawable-xhdpi/round_border_outer_black_24.png
Normal file
After Width: | Height: | Size: 187 B |
BIN
app/src/main/res/drawable-xhdpi/round_border_outer_black_36.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
app/src/main/res/drawable-xhdpi/round_border_outer_black_48.png
Normal file
After Width: | Height: | Size: 323 B |
BIN
app/src/main/res/drawable-xhdpi/round_dark_mode_white_18.png
Normal file
After Width: | Height: | Size: 325 B |
BIN
app/src/main/res/drawable-xhdpi/round_dark_mode_white_20.png
Normal file
After Width: | Height: | Size: 339 B |
BIN
app/src/main/res/drawable-xhdpi/round_dark_mode_white_24.png
Normal file
After Width: | Height: | Size: 397 B |
BIN
app/src/main/res/drawable-xhdpi/round_dark_mode_white_36.png
Normal file
After Width: | Height: | Size: 571 B |
BIN
app/src/main/res/drawable-xhdpi/round_dark_mode_white_48.png
Normal file
After Width: | Height: | Size: 763 B |
BIN
app/src/main/res/drawable-xhdpi/round_select_all_black_18.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
app/src/main/res/drawable-xhdpi/round_select_all_black_20.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
app/src/main/res/drawable-xhdpi/round_select_all_black_24.png
Normal file
After Width: | Height: | Size: 202 B |
BIN
app/src/main/res/drawable-xhdpi/round_select_all_black_36.png
Normal file
After Width: | Height: | Size: 268 B |
BIN
app/src/main/res/drawable-xhdpi/round_select_all_black_48.png
Normal file
After Width: | Height: | Size: 332 B |
BIN
app/src/main/res/drawable-xxhdpi/round_border_outer_black_18.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
app/src/main/res/drawable-xxhdpi/round_border_outer_black_20.png
Normal file
After Width: | Height: | Size: 251 B |
BIN
app/src/main/res/drawable-xxhdpi/round_border_outer_black_24.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
app/src/main/res/drawable-xxhdpi/round_border_outer_black_36.png
Normal file
After Width: | Height: | Size: 388 B |
BIN
app/src/main/res/drawable-xxhdpi/round_border_outer_black_48.png
Normal file
After Width: | Height: | Size: 460 B |
BIN
app/src/main/res/drawable-xxhdpi/round_dark_mode_white_18.png
Normal file
After Width: | Height: | Size: 451 B |
BIN
app/src/main/res/drawable-xxhdpi/round_dark_mode_white_20.png
Normal file
After Width: | Height: | Size: 484 B |
BIN
app/src/main/res/drawable-xxhdpi/round_dark_mode_white_24.png
Normal file
After Width: | Height: | Size: 571 B |
BIN
app/src/main/res/drawable-xxhdpi/round_dark_mode_white_36.png
Normal file
After Width: | Height: | Size: 836 B |
BIN
app/src/main/res/drawable-xxhdpi/round_dark_mode_white_48.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_select_all_black_18.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/drawable-xxhdpi/round_select_all_black_20.png
Normal file
After Width: | Height: | Size: 324 B |
BIN
app/src/main/res/drawable-xxhdpi/round_select_all_black_24.png
Normal file
After Width: | Height: | Size: 268 B |
BIN
app/src/main/res/drawable-xxhdpi/round_select_all_black_36.png
Normal file
After Width: | Height: | Size: 429 B |
BIN
app/src/main/res/drawable-xxhdpi/round_select_all_black_48.png
Normal file
After Width: | Height: | Size: 476 B |
After Width: | Height: | Size: 252 B |
After Width: | Height: | Size: 276 B |
After Width: | Height: | Size: 323 B |
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 605 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_dark_mode_white_18.png
Normal file
After Width: | Height: | Size: 571 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_dark_mode_white_20.png
Normal file
After Width: | Height: | Size: 607 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_dark_mode_white_24.png
Normal file
After Width: | Height: | Size: 763 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_dark_mode_white_36.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_dark_mode_white_48.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_select_all_black_18.png
Normal file
After Width: | Height: | Size: 268 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_select_all_black_20.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_select_all_black_24.png
Normal file
After Width: | Height: | Size: 332 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_select_all_black_36.png
Normal file
After Width: | Height: | Size: 476 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_select_all_black_48.png
Normal file
After Width: | Height: | Size: 594 B |
25
app/src/main/res/drawable/round_border_outer_20.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="20"
|
||||
android:viewportHeight="20"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,4.5v11C3,16.33 3.67,17 4.5,17h11c0.83,0 1.5,-0.67 1.5,-1.5v-11C17,3.67 16.33,3 15.5,3h-11C3.67,3 3,3.67 3,4.5zM4.5,15.5v-11h11v11H4.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.25,6.17h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6.12,9.33h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.25,9.33h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12.38,9.33h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.25,12.5h1.5v1.5h-1.5z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/round_border_outer_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M13,7h-2v2h2L13,7zM13,11h-2v2h2v-2zM17,11h-2v2h2v-2zM3,5v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2L5,3c-1.1,0 -2,0.9 -2,2zM18,19L6,19c-0.55,0 -1,-0.45 -1,-1L5,6c0,-0.55 0.45,-1 1,-1h12c0.55,0 1,0.45 1,1v12c0,0.55 -0.45,1 -1,1zM13,15h-2v2h2v-2zM9,11L7,11v2h2v-2z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/round_dark_mode_20.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="20"
|
||||
android:viewportHeight="20"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.23,3.04C5.73,3.42 3,6.39 3,10c0,3.87 3.13,7 7,7c3.6,0 6.57,-2.72 6.96,-6.22c0.07,-0.61 -0.61,-1.1 -1.19,-0.74c-0.65,0.42 -1.43,0.66 -2.26,0.66c-2.32,0 -4.2,-1.88 -4.2,-4.2c0,-0.83 0.24,-1.6 0.65,-2.25C10.3,3.73 9.93,2.98 9.23,3.04z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/round_dark_mode_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.01,3.05C6.51,3.54 3,7.36 3,12c0,4.97 4.03,9 9,9c4.63,0 8.45,-3.5 8.95,-8c0.09,-0.79 -0.78,-1.42 -1.54,-0.95c-0.84,0.54 -1.84,0.85 -2.91,0.85c-2.98,0 -5.4,-2.42 -5.4,-5.4c0,-1.06 0.31,-2.06 0.84,-2.89C12.39,3.94 11.9,2.98 11.01,3.05z"/>
|
||||
</vector>
|
58
app/src/main/res/drawable/round_select_all_20.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="20"
|
||||
android:viewportHeight="20"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,14h6c0.55,0 1,-0.45 1,-1V7c0,-0.55 -0.45,-1 -1,-1H7C6.45,6 6,6.45 6,7v6C6,13.55 6.45,14 7,14zM7.5,7.5h5v5h-5V7.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6.12,3h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,4.5h1.5V3C3.67,3 3,3.67 3,4.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4.5,17v-1.5H3C3,16.33 3.67,17 4.5,17z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,12.38h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,9.25h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,6.12h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,12.38h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,9.25h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,6.12h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,3v1.5H17C17,3.67 16.33,3 15.5,3z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12.38,3h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.25,3h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6.12,15.5h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,17c0.83,0 1.5,-0.67 1.5,-1.5h-1.5V17z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12.38,15.5h1.5v1.5h-1.5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.25,15.5h1.5v1.5h-1.5z"/>
|
||||
</vector>
|