Merge branch 'patch-2' into patch-develop

# Conflicts:
#	app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/AlignedWidget.kt
#	app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/StandardWidget.kt
This commit is contained in:
azuo 2021-09-14 13:39:30 +08:00
commit 6f125573e0
35 changed files with 283 additions and 206 deletions

View File

@ -143,7 +143,6 @@ class BottomSheetColorPicker(
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.loader.isVisible = false binding.loader.isVisible = false
binding.listContainer.addView(listBinding.root) binding.listContainer.addView(listBinding.root)
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
binding.listContainer.isVisible = true binding.listContainer.isVisible = true
val idx = colors.toList().indexOf(getSelected?.invoke()) val idx = colors.toList().indexOf(getSelected?.invoke())
@ -152,6 +151,10 @@ class BottomSheetColorPicker(
}) })
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }

View File

@ -108,6 +108,10 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
} }
} }
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }

View File

@ -86,7 +86,6 @@ class BottomSheetPicker<T>(
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.loader.isVisible = false binding.loader.isVisible = false
binding.listContainer.addView(listBinding.root) binding.listContainer.addView(listBinding.root)
this@BottomSheetPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
binding.listContainer.isVisible = true binding.listContainer.isVisible = true
val idx = items.toList().indexOfFirst { it.value == getSelected?.invoke() } val idx = items.toList().indexOfFirst { it.value == getSelected?.invoke() }
@ -95,6 +94,10 @@ class BottomSheetPicker<T>(
}) })
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }

View File

@ -61,5 +61,9 @@ class BottomSheetWeatherProviderSettings(context: Context, callback: () -> Unit)
} }
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
} }
} }

View File

@ -26,5 +26,9 @@ class CustomNotesDialog(context: Context, callback: (() -> Unit)?) : BottomSheet
binding.notes.requestFocus() binding.notes.requestFocus()
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
} }
} }

View File

@ -230,10 +230,16 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} }
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }
private fun checkNextAlarm() { private fun checkNextAlarm() {
if (!Preferences.showNextAlarm)
AlarmHelper.clearTimeout(context)
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) { with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
val alarm = nextAlarmClock val alarm = nextAlarmClock
if (alarm != null && alarm.showIntent != null) { if (alarm != null && alarm.showIntent != null) {

View File

@ -50,6 +50,10 @@ class IconPackSelector(context: Context, private val header: String? = null) : B
binding.menu.addView(itemBinding.root) binding.menu.addView(itemBinding.root)
} }
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }
} }

View File

@ -57,6 +57,10 @@ class MaterialBottomSheetDialog(
} }
setContentView(binding.root) setContentView(binding.root)
behavior.run {
skipCollapsed = true
state = com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
}
super.show() super.show()
} }

View File

@ -95,7 +95,7 @@ object Preferences : KotprefModel() {
// Global // Global
var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f) var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f)
var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f) var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f)
var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f) var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 26f)
var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.rawValue) var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.rawValue)
var secondRowTopMargin by intPref(default = Constants.SecondRowTopMargin.NONE.rawValue) var secondRowTopMargin by intPref(default = Constants.SecondRowTopMargin.NONE.rawValue)
var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false) var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false)

View File

@ -44,7 +44,6 @@ object AlarmHelper {
val intent = Intent(context, UpdatesReceiver::class.java).apply { val intent = Intent(context, UpdatesReceiver::class.java).apply {
action = Actions.ACTION_ALARM_UPDATE action = Actions.ACTION_ALARM_UPDATE
} }
cancel(PendingIntent.getBroadcast(context, ALARM_UPDATE_ID, intent, 0))
setExact( setExact(
AlarmManager.RTC, AlarmManager.RTC,
trigger, trigger,
@ -58,5 +57,14 @@ object AlarmHelper {
} }
} }
fun clearTimeout(context: Context) {
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
val intent = Intent(context, UpdatesReceiver::class.java).apply {
action = Actions.ACTION_ALARM_UPDATE
}
cancel(PendingIntent.getBroadcast(context, ALARM_UPDATE_ID, intent, 0))
}
}
private const val ALARM_UPDATE_ID = 24953 private const val ALARM_UPDATE_ID = 24953
} }

View File

@ -73,6 +73,9 @@ object ImageHelper {
allocationIn.destroy() allocationIn.destroy()
allocationOut.destroy() allocationOut.destroy()
colorMatrixScript.destroy()
blurScript.destroy()
//rs.destroy()
return bitmap return bitmap
} }

View File

@ -1,5 +1,6 @@
package com.tommasoberlose.anotherwidget.helpers package com.tommasoberlose.anotherwidget.helpers
import android.app.PendingIntent
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.content.ComponentName import android.content.ComponentName
import android.content.ContentUris import android.content.ContentUris
@ -27,6 +28,13 @@ object IntentHelper {
const val DO_NOTHING_OPTION = "DO_NOTHING" const val DO_NOTHING_OPTION = "DO_NOTHING"
const val REFRESH_WIDGET_OPTION = "REFRESH_WIDGET" const val REFRESH_WIDGET_OPTION = "REFRESH_WIDGET"
fun getPendingIntent(context: Context, requestCode: Int, intent: Intent, flags: Int): PendingIntent {
return if (intent.flags and Intent.FLAG_ACTIVITY_NEW_TASK == Intent.FLAG_ACTIVITY_NEW_TASK)
PendingIntent.getActivity(context, requestCode, intent, flags)
else
PendingIntent.getBroadcast(context, requestCode, intent, 0)
}
fun getWidgetUpdateIntent(context: Context): Intent { fun getWidgetUpdateIntent(context: Context): Intent {
val widgetManager = AppWidgetManager.getInstance(context) val widgetManager = AppWidgetManager.getInstance(context)
val widgetComponent = ComponentName(context, MainWidget::class.java) val widgetComponent = ComponentName(context, MainWidget::class.java)
@ -40,21 +48,19 @@ object IntentHelper {
private fun getWidgetRefreshIntent(context: Context): Intent { private fun getWidgetRefreshIntent(context: Context): Intent {
return Intent(context, UpdatesReceiver::class.java).apply { return Intent(context, UpdatesReceiver::class.java).apply {
action = Actions.ACTION_REFRESH action = Actions.ACTION_REFRESH
flags = Intent.FLAG_ACTIVITY_NEW_TASK
} }
} }
fun getGoogleMapsIntentFromAddress(context: Context, address: String): Intent { fun getGoogleMapsIntentFromAddress(context: Context, address: String): Intent {
val gmmIntentUri: Uri = Uri.parse("geo:0,0?q=$address") val gmmIntentUri: Uri = Uri.parse("geo:0,0?q=${Uri.encode(address)}")
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.`package` = "com.google.android.apps.maps" //mapIntent.`package` = "com.google.android.apps.maps"
return if (mapIntent.resolveActivity(context.packageManager) != null) { return if (mapIntent.resolveActivity(context.packageManager) != null) {
mapIntent mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
} else { } else {
val map = "http://maps.google.co.in/maps?q=$address" val map = "https://www.google.com/maps/search/?api=1&query=${Uri.encode(address)}"
val i = Intent(Intent.ACTION_VIEW, Uri.parse(map)); Intent(Intent.ACTION_VIEW, Uri.parse(map)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i
} }
} }
@ -62,7 +68,6 @@ object IntentHelper {
return when (Preferences.weatherAppPackage) { return when (Preferences.weatherAppPackage) {
DEFAULT_OPTION -> { DEFAULT_OPTION -> {
Intent(Intent.ACTION_VIEW).apply { Intent(Intent.ACTION_VIEW).apply {
addCategory(Intent.CATEGORY_DEFAULT)
flags = Intent.FLAG_ACTIVITY_NEW_TASK flags = Intent.FLAG_ACTIVITY_NEW_TASK
data = Uri.parse("dynact://velour/weather/ProxyActivity") data = Uri.parse("dynact://velour/weather/ProxyActivity")
component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline") component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
@ -89,15 +94,16 @@ object IntentHelper {
} }
} }
fun getCalendarIntent(context: Context): Intent { fun getCalendarIntent(context: Context, time: Long? = null): Intent {
val calendarUri = CalendarContract.CONTENT_URI val calendarUri = CalendarContract.CONTENT_URI
.buildUpon() .buildUpon()
.appendPath("time") .appendPath("time")
.appendPath(Calendar.getInstance().timeInMillis.toString()) .appendPath((time ?: Calendar.getInstance().timeInMillis).toString())
.build() .build()
return when (Preferences.calendarAppPackage) { return when (Preferences.calendarAppPackage) {
DEFAULT_OPTION -> { DEFAULT_OPTION -> {
Intent(Intent.ACTION_VIEW).apply { Intent(Intent.ACTION_VIEW).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
data = calendarUri data = calendarUri
} }
} }
@ -111,6 +117,8 @@ object IntentHelper {
val pm: PackageManager = context.packageManager val pm: PackageManager = context.packageManager
try { try {
pm.getLaunchIntentForPackage(Preferences.calendarAppPackage)!!.apply { pm.getLaunchIntentForPackage(Preferences.calendarAppPackage)!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
action = Intent.ACTION_VIEW action = Intent.ACTION_VIEW
data = calendarUri data = calendarUri
} }
@ -177,7 +185,7 @@ object IntentHelper {
} }
} }
false -> { false -> {
getCalendarIntent(context) getCalendarIntent(context, e.startDate)
} }
} }
} }
@ -209,7 +217,7 @@ object IntentHelper {
} }
fun getBatteryIntent(): Intent { fun getBatteryIntent(): Intent {
return Intent(Intent.ACTION_POWER_USAGE_SUMMARY) return Intent(Intent.ACTION_POWER_USAGE_SUMMARY).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
} }
fun getMusicIntent(context: Context): Intent { fun getMusicIntent(context: Context): Intent {
@ -222,6 +230,7 @@ object IntentHelper {
try { try {
pm.getLaunchIntentForPackage(Preferences.mediaPlayerPackage)!!.apply { pm.getLaunchIntentForPackage(Preferences.mediaPlayerPackage)!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER) addCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
} }
} catch (e: Exception) { } catch (e: Exception) {
Intent() Intent()
@ -235,6 +244,7 @@ object IntentHelper {
return try { return try {
pm.getLaunchIntentForPackage("com.google.android.apps.fitness")!!.apply { pm.getLaunchIntentForPackage("com.google.android.apps.fitness")!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER) addCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
} }
} catch (e: Exception) { } catch (e: Exception) {
Intent() Intent()
@ -246,6 +256,7 @@ object IntentHelper {
return try { return try {
pm.getLaunchIntentForPackage(Preferences.lastNotificationPackage)!!.apply { pm.getLaunchIntentForPackage(Preferences.lastNotificationPackage)!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER) addCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
} }
} catch (e: Exception) { } catch (e: Exception) {
Intent() Intent()

View File

@ -63,21 +63,23 @@ object WidgetHelper {
R.array.com_google_android_gms_fonts_certs R.array.com_google_android_gms_fonts_certs
) )
val handlerThread = HandlerThread("generateView")
val callback = object : FontsContractCompat.FontRequestCallback() { val callback = object : FontsContractCompat.FontRequestCallback() {
override fun onTypefaceRetrieved(typeface: Typeface) { override fun onTypefaceRetrieved(typeface: Typeface) {
handlerThread.quit()
function.invoke(typeface) function.invoke(typeface)
} }
override fun onTypefaceRequestFailed(reason: Int) { override fun onTypefaceRequestFailed(reason: Int) {
handlerThread.quit()
function.invoke(null) function.invoke(null)
} }
} }
val handlerThread = HandlerThread("generateView")
handlerThread.start() handlerThread.start()
if (Looper.myLooper() == null) { //if (Looper.myLooper() == null) {
Looper.prepare() // Looper.prepare()
} //}
Handler(handlerThread.looper).run { Handler(handlerThread.looper).run {
FontsContractCompat.requestFont(context, request, callback, this) FontsContractCompat.requestFont(context, request, callback, this)

View File

@ -16,14 +16,15 @@ class WidgetClickListenerReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Actions.ACTION_OPEN_WEATHER_INTENT) { if (intent.action == Actions.ACTION_OPEN_WEATHER_INTENT) {
try { try {
if (Preferences.weatherAppPackage == IntentHelper.REFRESH_WIDGET_OPTION) { IntentHelper.getWeatherIntent(context).run {
context.sendBroadcast(IntentHelper.getWeatherIntent(context)) if (flags and Intent.FLAG_ACTIVITY_NEW_TASK == Intent.FLAG_ACTIVITY_NEW_TASK)
} else { context.startActivity(this)
context.startActivity(IntentHelper.getWeatherIntent(context)) else
context.sendBroadcast(this)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
val uri = Uri.parse("http://www.google.com/search?q=weather") val uri = Uri.parse("https://www.google.com/search?q=weather")
val i = Intent(Intent.ACTION_VIEW, uri) val i = Intent(Intent.ACTION_VIEW, uri)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
try { try {

View File

@ -38,12 +38,15 @@ class CustomFontActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: CustomFontViewModel private lateinit var viewModel: CustomFontViewModel
private lateinit var binding: ActivityCustomFontBinding private lateinit var binding: ActivityCustomFontBinding
private lateinit var handlerThread: HandlerThread
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(CustomFontViewModel::class.java) viewModel = ViewModelProvider(this).get(CustomFontViewModel::class.java)
binding = ActivityCustomFontBinding.inflate(layoutInflater) binding = ActivityCustomFontBinding.inflate(layoutInflater)
handlerThread = HandlerThread("listCustomFonts")
handlerThread.start()
binding.listView.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
@ -64,14 +67,17 @@ class CustomFontActivity : AppCompatActivity() {
injector injector
.text(R.id.text, item) .text(R.id.text, item)
.with<TextView>(R.id.text) { .with<TextView>(R.id.text) {
val googleSans: Typeface = when (Preferences.customFontVariant) { val googleSans: Typeface? = androidx.core.content.res.ResourcesCompat.getFont(
"100" -> Typeface.createFromAsset(this.assets, "fonts/google_sans_thin.ttf") this,
"200" -> Typeface.createFromAsset(this.assets, "fonts/google_sans_light.ttf") when (Preferences.customFontVariant) {
"500" -> Typeface.createFromAsset(this.assets, "fonts/google_sans_medium.ttf") "100" -> R.font.google_sans_thin
"700" -> Typeface.createFromAsset(this.assets, "fonts/google_sans_bold.ttf") "200" -> R.font.google_sans_light
"800" -> Typeface.createFromAsset(this.assets, "fonts/google_sans_black.ttf") "500" -> R.font.google_sans_medium
else -> Typeface.createFromAsset(this.assets, "fonts/google_sans_regular.ttf") "700" -> R.font.google_sans_bold
} "800" -> R.font.google_sans_black
else -> R.font.google_sans_regular
}
)
it.typeface = googleSans it.typeface = googleSans
} }
@ -97,32 +103,49 @@ class CustomFontActivity : AppCompatActivity() {
) )
val callback = object : FontsContractCompat.FontRequestCallback() { class Callback : FontsContractCompat.FontRequestCallback() {
override fun onTypefaceRetrieved(typeface: Typeface) { var handler: Handler? = Handler(handlerThread.looper)
it.typeface = typeface
it.isVisible = true
it.measure( fun cancel() {
ViewGroup.LayoutParams.MATCH_PARENT, if (handler != null) {
ViewGroup.LayoutParams.WRAP_CONTENT handler!!.removeCallbacksAndMessages(null)
) handler = null
}
}
protected fun finalize() {
cancel()
}
override fun onTypefaceRetrieved(typeface: Typeface) {
if (it.tag == this) {
it.tag = null
it.typeface = typeface
it.setTextColor(getColor(R.color.colorPrimaryText))
}
} }
override fun onTypefaceRequestFailed(reason: Int) { override fun onTypefaceRequestFailed(reason: Int) {
it.isVisible = false if (it.tag == this) {
it.layoutParams = it.layoutParams.apply { it.tag = null
height = 0 //it.text = item.fontFamily + " ($reason)"
it.setTextColor(getColor(R.color.errorColorText))
} }
} }
} }
val handlerThread = HandlerThread(item.fontFamily) (it.tag as Callback?)?.cancel()
handlerThread.start() val callback = Callback()
val mHandler = Handler(handlerThread.looper) it.tag = callback
it.typeface = null
it.setTextColor(getColor(R.color.colorSecondaryText))
val mHandler = callback.handler!!
FontsContractCompat.requestFont(this, request, callback, mHandler) FontsContractCompat.requestFont(this, request, callback, mHandler)
} }
injector.clicked(R.id.text) { injector.clicked(R.id.text) {
if ((it as TextView).typeface == null) return@clicked
val dialog = BottomSheetMenu<Int>(this, header = item.fontFamily) val dialog = BottomSheetMenu<Int>(this, header = item.fontFamily)
if (item.fontVariants.isEmpty()) { if (item.fontVariants.isEmpty()) {
dialog.addItem(SettingsStringHelper.getVariantLabel(this, "regular"), -1) dialog.addItem(SettingsStringHelper.getVariantLabel(this, "regular"), -1)
@ -147,6 +170,12 @@ class CustomFontActivity : AppCompatActivity() {
setContentView(binding.root) setContentView(binding.root)
} }
override fun onDestroy() {
handlerThread.quit()
filterJob?.cancel()
super.onDestroy()
}
private var filterJob: Job? = null private var filterJob: Job? = null
private fun subscribeUi(binding: ActivityCustomFontBinding, viewModel: CustomFontViewModel) { private fun subscribeUi(binding: ActivityCustomFontBinding, viewModel: CustomFontViewModel) {
@ -204,6 +233,13 @@ class CustomFontActivity : AppCompatActivity() {
adapter.updateData(filteredList) adapter.updateData(filteredList)
binding.loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} else {
delay(200)
withContext(Dispatchers.Main) {
adapter.updateData(listOf(getString(R.string.custom_font_subtitle_1)).filter {
it.contains(search ?: "", ignoreCase = true)
})
}
} }
} }
} }

View File

@ -17,7 +17,7 @@ import com.chibatching.kotpref.bulk
import com.google.android.material.transition.MaterialSharedAxis import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetPicker
import com.tommasoberlose.anotherwidget.databinding.FragmentTabClockBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabClockBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
@ -144,16 +144,15 @@ class ClockFragment : Fragment() {
private fun setupListener() { private fun setupListener() {
binding.actionClockTextSize.setOnClickListener { binding.actionClockTextSize.setOnClickListener {
val dialog = BottomSheetMenu<Float>( BottomSheetPicker(
requireContext(), requireContext(),
header = getString(R.string.settings_clock_text_size_title) items = (46 downTo 12).map { BottomSheetPicker.MenuItem("${it}sp", it.toFloat()) },
).setSelectedValue(Preferences.clockTextSize) getSelected = { Preferences.clockTextSize },
(46 downTo 12).filter { it % 2 == 0 }.forEach { header = getString(R.string.settings_clock_text_size_title),
dialog.addItem("${it}sp", it.toFloat()) onItemSelected = {value ->
} if (value != null) Preferences.clockTextSize = value
dialog.addOnSelectItemListener { value -> }
Preferences.clockTextSize = value ).show()
}.show()
} }
binding.actionAltTimezoneClock.setOnClickListener { binding.actionAltTimezoneClock.setOnClickListener {

View File

@ -102,15 +102,7 @@ class GesturesFragment : Fragment() {
it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing) it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing)
it == IntentHelper.REFRESH_WIDGET_OPTION -> getString(R.string.gestures_refresh_widget) it == IntentHelper.REFRESH_WIDGET_OPTION -> getString(R.string.gestures_refresh_widget)
it != IntentHelper.DEFAULT_OPTION -> it it != IntentHelper.DEFAULT_OPTION -> it
else -> { else -> getString(R.string.default_calendar_app)
if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) {
getString(
R.string.default_calendar_app
)
} else {
getString(R.string.gestures_do_nothing)
}
}
} }
} }
} }
@ -127,15 +119,7 @@ class GesturesFragment : Fragment() {
it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing) it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing)
it == IntentHelper.REFRESH_WIDGET_OPTION -> getString(R.string.gestures_refresh_widget) it == IntentHelper.REFRESH_WIDGET_OPTION -> getString(R.string.gestures_refresh_widget)
it != IntentHelper.DEFAULT_OPTION -> it it != IntentHelper.DEFAULT_OPTION -> it
else -> { else -> getString(R.string.default_clock_app)
if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
getString(
R.string.default_clock_app
)
} else {
getString(R.string.gestures_do_nothing)
}
}
} }
} }
} }
@ -173,9 +157,12 @@ class GesturesFragment : Fragment() {
} }
binding.actionCalendarApp.setOnClickListener { binding.actionCalendarApp.setOnClickListener {
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java).apply { startActivityForResult(
putExtra(Constants.RESULT_APP_PACKAGE, Preferences.calendarAppPackage) Intent(requireContext(), ChooseApplicationActivity::class.java).apply {
}, RequestCode.CALENDAR_APP_REQUEST_CODE.code) putExtra(Constants.RESULT_APP_PACKAGE, Preferences.calendarAppPackage)
},
RequestCode.CALENDAR_APP_REQUEST_CODE.code
)
} }
binding.actionClockApp.setOnClickListener { binding.actionClockApp.setOnClickListener {

View File

@ -276,7 +276,7 @@ class TypographyFragment : Fragment() {
Intent(requireContext(), CustomFontActivity::class.java), Intent(requireContext(), CustomFontActivity::class.java),
RequestCode.CUSTOM_FONT_CHOOSER_REQUEST_CODE.code RequestCode.CUSTOM_FONT_CHOOSER_REQUEST_CODE.code
) )
} else if (value != Constants.CUSTOM_FONT_DOWNLOADED) { } else if (value != Preferences.customFont) {
Preferences.bulk { Preferences.bulk {
customFont = value customFont = value
customFontFile = "" customFontFile = ""

View File

@ -56,7 +56,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
) )
val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt() val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt()
views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin) views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin)
val refreshIntent = PendingIntent.getActivity( val refreshIntent = IntentHelper.getPendingIntent(
context, context,
appWidgetId, appWidgetId,
IntentHelper.getWidgetUpdateIntent(context), IntentHelper.getWidgetUpdateIntent(context),
@ -102,7 +102,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
// Weather // Weather
if (Preferences.showWeather && Preferences.weatherIcon != "") { if (Preferences.showWeather && Preferences.weatherIcon != "") {
views.setViewVisibility(R.id.weather_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
views.setViewVisibility(R.id.weather_sub_line, View.GONE) views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
val i = Intent(context, WidgetClickListenerReceiver::class.java) val i = Intent(context, WidgetClickListenerReceiver::class.java)
i.action = Actions.ACTION_OPEN_WEATHER_INTENT i.action = Actions.ACTION_OPEN_WEATHER_INTENT
@ -122,7 +122,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
) )
} else { } else {
views.setViewVisibility(R.id.weather_rect, View.GONE) views.setViewVisibility(R.id.weather_rect, View.GONE)
views.setViewVisibility(R.id.weather_sub_line, View.GONE) views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
} }
@ -132,7 +132,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height) BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height)
) )
val calPIntent = PendingIntent.getActivity( val calPIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getCalendarIntent(context), IntentHelper.getCalendarIntent(context),
@ -141,8 +141,6 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
views.setOnClickPendingIntent(R.id.date_rect, calPIntent) views.setOnClickPendingIntent(R.id.date_rect, calPIntent)
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE) views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
val nextAlarm = AlarmHelper.getNextAlarm(context)
// Spacing // Spacing
views.setViewVisibility( views.setViewVisibility(
R.id.sub_line_top_margin_small_sans, R.id.sub_line_top_margin_small_sans,
@ -185,7 +183,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
} }
// Event intent // Event intent
val eventIntent = PendingIntent.getActivity( val eventIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent(context, nextEvent), IntentHelper.getEventIntent(context, nextEvent),
@ -222,7 +220,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
// Event information // Event information
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) { if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
val mapIntent = PendingIntent.getActivity( val mapIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address), IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address),
@ -230,14 +228,10 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
) )
views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent) views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent)
} else { } else {
val pIntentDetail = PendingIntent.getActivity( val pIntentDetail = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent( IntentHelper.getCalendarIntent(context, nextEvent.startDate),
context,
nextEvent,
forceEventDetails = true
),
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail) views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail)
@ -245,7 +239,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE) views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE)
views.setViewVisibility(R.id.weather_sub_line_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_sub_line_rect, if (Preferences.showWeather && Preferences.weatherIcon != "") View.VISIBLE else View.GONE)
views.setViewVisibility(R.id.first_line_rect, View.GONE) views.setViewVisibility(R.id.first_line_rect, View.GONE)
views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE) views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE)
@ -258,7 +252,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
when (provider) { when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
if (MediaPlayerHelper.isSomeonePlaying(context)) { if (MediaPlayerHelper.isSomeonePlaying(context)) {
val musicIntent = PendingIntent.getActivity( val musicIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getMusicIntent(context), IntentHelper.getMusicIntent(context),
@ -270,23 +264,26 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
} }
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
if (Preferences.showNextAlarm && nextAlarm != "") { if (Preferences.showNextAlarm) {
val alarmIntent = PendingIntent.getActivity( val nextAlarm = AlarmHelper.getNextAlarm(context)
context, if (nextAlarm != "") {
widgetID, val alarmIntent = IntentHelper.getPendingIntent(
IntentHelper.getClockIntent(context), context,
PendingIntent.FLAG_UPDATE_CURRENT widgetID,
) IntentHelper.getClockIntent(context),
views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent) PendingIntent.FLAG_UPDATE_CURRENT
showSomething = true )
break@loop views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent)
showSomething = true
break@loop
}
} }
} }
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
if (Preferences.showBatteryCharging) { if (Preferences.showBatteryCharging) {
BatteryHelper.updateBatteryInfo(context) BatteryHelper.updateBatteryInfo(context)
if (Preferences.isCharging || Preferences.isBatteryLevelLow) { if (Preferences.isCharging || Preferences.isBatteryLevelLow) {
val batteryIntent = PendingIntent.getActivity( val batteryIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getBatteryIntent(), IntentHelper.getBatteryIntent(),
@ -305,7 +302,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
} }
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> { Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) { if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
val fitIntent = PendingIntent.getActivity( val fitIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getFitIntent(context), IntentHelper.getFitIntent(context),
@ -326,7 +323,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
remotePackageContext, remotePackageContext,
Preferences.lastNotificationIcon) Preferences.lastNotificationIcon)
} }
val notificationIntent = PendingIntent.getActivity( val notificationIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getNotificationIntent(context), IntentHelper.getNotificationIntent(context),
@ -350,7 +347,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
Constants.GlanceProviderId.EVENTS -> { Constants.GlanceProviderId.EVENTS -> {
if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission( if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission(
Manifest.permission.READ_CALENDAR) && nextEvent != null) { Manifest.permission.READ_CALENDAR) && nextEvent != null) {
val pIntentDetail = PendingIntent.getActivity( val pIntentDetail = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent( IntentHelper.getEventIntent(
@ -485,8 +482,6 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
bindingView.date.text = DateHelper.getDateText(context, now) bindingView.date.text = DateHelper.getDateText(context, now)
val nextAlarm = AlarmHelper.getNextAlarm(context)
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) { if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
// Multiple counter // Multiple counter
bindingView.actionNext.isVisible = bindingView.actionNext.isVisible =
@ -587,18 +582,16 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
} }
} else { } else {
val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate } val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate }
bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get( bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(
Calendar.DAY_OF_YEAR)) { Calendar.DAY_OF_YEAR)) {
DateUtils.formatDateTime(context, nextEvent.startDate, flags) DateHelper.getDateText(context, start)
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get( } else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(
Calendar.YEAR) > start.get(Calendar.YEAR)) { Calendar.YEAR) > start.get(Calendar.YEAR)) {
DateUtils.formatDateTime(context, now.timeInMillis, flags) DateHelper.getDateText(context, now)
} else { } else {
DateUtils.formatDateTime(context, nextEvent.startDate, flags) DateHelper.getDateText(context, start)
} }
} }
} }
@ -606,7 +599,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
bindingView.dateLayout.isVisible = false bindingView.dateLayout.isVisible = false
bindingView.calendarLayout.isVisible = true bindingView.calendarLayout.isVisible = true
bindingView.subLine.isVisible = true bindingView.subLine.isVisible = true
bindingView.weatherSubLine.isVisible = true bindingView.weatherSubLine.isVisible = Preferences.showWeather && Preferences.weatherIcon != ""
bindingView.subLineTopMarginSmall.visibility = View.GONE bindingView.subLineTopMarginSmall.visibility = View.GONE
bindingView.subLineTopMarginMedium.visibility = View.GONE bindingView.subLineTopMarginMedium.visibility = View.GONE
@ -632,16 +625,19 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
} }
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
if (Preferences.showNextAlarm && nextAlarm != "") { if (Preferences.showNextAlarm) {
bindingView.subLineIcon.setImageDrawable( val nextAlarm = AlarmHelper.getNextAlarm(context)
ContextCompat.getDrawable( if (nextAlarm != "") {
context, bindingView.subLineIcon.setImageDrawable(
R.drawable.round_alarm_24 ContextCompat.getDrawable(
context,
R.drawable.round_alarm_24
)
) )
) bindingView.subLineText.text = nextAlarm
bindingView.subLineText.text = AlarmHelper.getNextAlarm(context) showSomething = true
showSomething = true break@loop
break@loop }
} }
} }
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
@ -933,14 +929,17 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
// Custom Font // Custom Font
if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) { if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) {
val googleSans: Typeface = when (Preferences.customFontVariant) { val googleSans: Typeface? = androidx.core.content.res.ResourcesCompat.getFont(
"100" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_thin.ttf") context,
"200" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_light.ttf") when (Preferences.customFontVariant) {
"500" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_medium.ttf") "100" -> R.font.google_sans_thin
"700" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_bold.ttf") "200" -> R.font.google_sans_light
"800" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_black.ttf") "500" -> R.font.google_sans_medium
else -> Typeface.createFromAsset(context.assets, "fonts/google_sans_regular.ttf") "700" -> R.font.google_sans_bold
} "800" -> R.font.google_sans_black
else -> R.font.google_sans_regular
}
)
listOf<TextView>( listOf<TextView>(
bindingView.date, bindingView.date,

View File

@ -39,7 +39,7 @@ class ClockWidget(val context: Context) {
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(context) / 5 * 2 Preferences.clockTextSize.toPixel(context) / 5 * 2
) )
val clockPIntent = PendingIntent.getActivity( val clockPIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getClockIntent(context), IntentHelper.getClockIntent(context),

View File

@ -59,7 +59,7 @@ class StandardWidget(val context: Context) {
) )
val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt() val margin = Preferences.widgetMargin.convertDpToPixel(context).toInt()
views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin) views.setViewPadding(R.id.widget_shape_background, margin, margin, margin, margin)
val refreshIntent = PendingIntent.getActivity( val refreshIntent = IntentHelper.getPendingIntent(
context, context,
appWidgetId, appWidgetId,
IntentHelper.getWidgetUpdateIntent(context), IntentHelper.getWidgetUpdateIntent(context),
@ -105,7 +105,7 @@ class StandardWidget(val context: Context) {
// Weather // Weather
if (Preferences.showWeather && Preferences.weatherIcon != "") { if (Preferences.showWeather && Preferences.weatherIcon != "") {
views.setViewVisibility(R.id.weather_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
views.setViewVisibility(R.id.weather_sub_line, View.GONE) views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
val i = Intent(context, WidgetClickListenerReceiver::class.java) val i = Intent(context, WidgetClickListenerReceiver::class.java)
i.action = Actions.ACTION_OPEN_WEATHER_INTENT i.action = Actions.ACTION_OPEN_WEATHER_INTENT
@ -125,7 +125,7 @@ class StandardWidget(val context: Context) {
) )
} else { } else {
views.setViewVisibility(R.id.weather_rect, View.GONE) views.setViewVisibility(R.id.weather_rect, View.GONE)
views.setViewVisibility(R.id.weather_sub_line, View.GONE) views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
} }
@ -135,7 +135,7 @@ class StandardWidget(val context: Context) {
BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height) BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height)
) )
val calPIntent = PendingIntent.getActivity( val calPIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getCalendarIntent(context), IntentHelper.getCalendarIntent(context),
@ -150,8 +150,6 @@ class StandardWidget(val context: Context) {
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false, width = bindingView.subLine.width, height = bindingView.subLine.height) BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false, width = bindingView.subLine.width, height = bindingView.subLine.height)
) )
val nextAlarm = AlarmHelper.getNextAlarm(context)
// Spacing // Spacing
views.setViewVisibility( views.setViewVisibility(
R.id.sub_line_top_margin_small_sans, R.id.sub_line_top_margin_small_sans,
@ -215,7 +213,7 @@ class StandardWidget(val context: Context) {
} }
// Event intent // Event intent
val eventIntent = PendingIntent.getActivity( val eventIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent(context, nextEvent), IntentHelper.getEventIntent(context, nextEvent),
@ -248,7 +246,7 @@ class StandardWidget(val context: Context) {
// Event information // Event information
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) { if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
val mapIntent = PendingIntent.getActivity( val mapIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address), IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address),
@ -256,14 +254,10 @@ class StandardWidget(val context: Context) {
) )
views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent) views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent)
} else { } else {
val pIntentDetail = PendingIntent.getActivity( val pIntentDetail = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent( IntentHelper.getCalendarIntent(context, nextEvent.startDate),
context,
nextEvent,
forceEventDetails = true
),
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail) views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail)
@ -275,7 +269,7 @@ class StandardWidget(val context: Context) {
) )
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE) views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE)
views.setViewVisibility(R.id.weather_sub_line_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_sub_line_rect, if (Preferences.showWeather && Preferences.weatherIcon != "") View.VISIBLE else View.GONE)
views.setViewVisibility(R.id.first_line_rect, View.GONE) views.setViewVisibility(R.id.first_line_rect, View.GONE)
@ -286,7 +280,7 @@ class StandardWidget(val context: Context) {
when (provider) { when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
if (MediaPlayerHelper.isSomeonePlaying(context)) { if (MediaPlayerHelper.isSomeonePlaying(context)) {
val musicIntent = PendingIntent.getActivity( val musicIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getMusicIntent(context), IntentHelper.getMusicIntent(context),
@ -298,23 +292,26 @@ class StandardWidget(val context: Context) {
} }
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
if (Preferences.showNextAlarm && nextAlarm != "") { if (Preferences.showNextAlarm) {
val alarmIntent = PendingIntent.getActivity( val nextAlarm = AlarmHelper.getNextAlarm(context)
context, if (nextAlarm != "") {
widgetID, val alarmIntent = IntentHelper.getPendingIntent(
IntentHelper.getClockIntent(context), context,
PendingIntent.FLAG_UPDATE_CURRENT widgetID,
) IntentHelper.getClockIntent(context),
views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent) PendingIntent.FLAG_UPDATE_CURRENT
showSomething = true )
break@loop views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent)
showSomething = true
break@loop
}
} }
} }
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
if (Preferences.showBatteryCharging) { if (Preferences.showBatteryCharging) {
BatteryHelper.updateBatteryInfo(context) BatteryHelper.updateBatteryInfo(context)
if (Preferences.isCharging || Preferences.isBatteryLevelLow) { if (Preferences.isCharging || Preferences.isBatteryLevelLow) {
val batteryIntent = PendingIntent.getActivity( val batteryIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getBatteryIntent(), IntentHelper.getBatteryIntent(),
@ -333,7 +330,7 @@ class StandardWidget(val context: Context) {
} }
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> { Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) { if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
val fitIntent = PendingIntent.getActivity( val fitIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getFitIntent(context), IntentHelper.getFitIntent(context),
@ -354,7 +351,7 @@ class StandardWidget(val context: Context) {
remotePackageContext, remotePackageContext,
Preferences.lastNotificationIcon) Preferences.lastNotificationIcon)
} }
val notificationIntent = PendingIntent.getActivity( val notificationIntent = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getNotificationIntent(context), IntentHelper.getNotificationIntent(context),
@ -378,7 +375,7 @@ class StandardWidget(val context: Context) {
Constants.GlanceProviderId.EVENTS -> { Constants.GlanceProviderId.EVENTS -> {
if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission( if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission(
Manifest.permission.READ_CALENDAR) && nextEvent != null) { Manifest.permission.READ_CALENDAR) && nextEvent != null) {
val pIntentDetail = PendingIntent.getActivity( val pIntentDetail = IntentHelper.getPendingIntent(
context, context,
widgetID, widgetID,
IntentHelper.getEventIntent( IntentHelper.getEventIntent(
@ -512,8 +509,6 @@ class StandardWidget(val context: Context) {
bindingView.date.text = DateHelper.getDateText(context, now) bindingView.date.text = DateHelper.getDateText(context, now)
val nextAlarm = AlarmHelper.getNextAlarm(context)
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) { if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
// Multiple counter // Multiple counter
bindingView.actionNext.isVisible = bindingView.actionNext.isVisible =
@ -616,18 +611,16 @@ class StandardWidget(val context: Context) {
} }
} else { } else {
val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate } val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate }
bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get( bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(
Calendar.DAY_OF_YEAR)) { Calendar.DAY_OF_YEAR)) {
DateUtils.formatDateTime(context, nextEvent.startDate, flags) DateHelper.getDateText(context, start)
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get( } else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(
Calendar.YEAR) > start.get(Calendar.YEAR)) { Calendar.YEAR) > start.get(Calendar.YEAR)) {
DateUtils.formatDateTime(context, now.timeInMillis, flags) DateHelper.getDateText(context, now)
} else { } else {
DateUtils.formatDateTime(context, nextEvent.startDate, flags) DateHelper.getDateText(context, start)
} }
} }
} }
@ -635,7 +628,7 @@ class StandardWidget(val context: Context) {
bindingView.dateLayout.isVisible = false bindingView.dateLayout.isVisible = false
bindingView.calendarLayout.isVisible = true bindingView.calendarLayout.isVisible = true
bindingView.subLine.isVisible = true bindingView.subLine.isVisible = true
bindingView.weatherSubLine.isVisible = true bindingView.weatherSubLine.isVisible = Preferences.showWeather && Preferences.weatherIcon != ""
bindingView.subLineTopMarginSmall.visibility = bindingView.subLineTopMarginSmall.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE
@ -664,16 +657,19 @@ class StandardWidget(val context: Context) {
} }
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
if (Preferences.showNextAlarm && nextAlarm != "") { if (Preferences.showNextAlarm) {
bindingView.subLineIcon.setImageDrawable( val nextAlarm = AlarmHelper.getNextAlarm(context)
ContextCompat.getDrawable( if (nextAlarm != "") {
context, bindingView.subLineIcon.setImageDrawable(
R.drawable.round_alarm_24 ContextCompat.getDrawable(
context,
R.drawable.round_alarm_24
)
) )
) bindingView.subLineText.text = nextAlarm
bindingView.subLineText.text = AlarmHelper.getNextAlarm(context) showSomething = true
showSomething = true break@loop
break@loop }
} }
} }
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
@ -976,14 +972,17 @@ class StandardWidget(val context: Context) {
// Custom Font // Custom Font
if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) { if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) {
val googleSans: Typeface = when (Preferences.customFontVariant) { val googleSans: Typeface? = androidx.core.content.res.ResourcesCompat.getFont(
"100" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_thin.ttf") context,
"200" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_light.ttf") when (Preferences.customFontVariant) {
"500" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_medium.ttf") "100" -> R.font.google_sans_thin
"700" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_bold.ttf") "200" -> R.font.google_sans_light
"800" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_black.ttf") "500" -> R.font.google_sans_medium
else -> Typeface.createFromAsset(context.assets, "fonts/google_sans_regular.ttf") "700" -> R.font.google_sans_bold
} "800" -> R.font.google_sans_black
else -> R.font.google_sans_regular
}
)
listOf<TextView>( listOf<TextView>(
bindingView.date, bindingView.date,

View File

@ -9,6 +9,14 @@
app:fontStyle="italic" app:fontStyle="italic"
app:fontWeight="400" app:fontWeight="400"
app:font="@font/google_sans_italic" /> app:font="@font/google_sans_italic" />
<font
app:fontStyle="normal"
app:fontWeight="100"
app:font="@font/google_sans_thin" />
<font
app:fontStyle="italic"
app:fontWeight="100"
app:font="@font/google_sans_thin_italic" />
<font <font
app:fontStyle="normal" app:fontStyle="normal"
app:fontWeight="200" app:fontWeight="200"
@ -19,34 +27,26 @@
app:font="@font/google_sans_light_italic" /> app:font="@font/google_sans_light_italic" />
<font <font
app:fontStyle="normal" app:fontStyle="normal"
app:fontWeight="300" app:fontWeight="500"
app:font="@font/google_sans_thin" />
<font
app:fontStyle="italic"
app:fontWeight="300"
app:font="@font/google_sans_thin_italic" />
<font
app:fontStyle="normal"
app:fontWeight="700"
app:font="@font/google_sans_medium" /> app:font="@font/google_sans_medium" />
<font <font
app:fontStyle="italic" app:fontStyle="italic"
app:fontWeight="700" app:fontWeight="500"
app:font="@font/google_sans_medium_italic" /> app:font="@font/google_sans_medium_italic" />
<font <font
app:fontStyle="normal" app:fontStyle="normal"
app:fontWeight="800" app:fontWeight="700"
app:font="@font/google_sans_bold" /> app:font="@font/google_sans_bold" />
<font <font
app:fontStyle="italic" app:fontStyle="italic"
app:fontWeight="800" app:fontWeight="700"
app:font="@font/google_sans_bold_italic" /> app:font="@font/google_sans_bold_italic" />
<font <font
app:fontStyle="normal" app:fontStyle="normal"
app:fontWeight="900" app:fontWeight="800"
app:font="@font/google_sans_black" /> app:font="@font/google_sans_black" />
<font <font
app:fontStyle="italic" app:fontStyle="italic"
app:fontWeight="900" app:fontWeight="800"
app:font="@font/google_sans_black_italic" /> app:font="@font/google_sans_black_italic" />
</font-family> </font-family>

View File

@ -139,10 +139,10 @@
<item name="android:gravity">center_horizontal</item> <item name="android:gravity">center_horizontal</item>
</style> </style>
<style name="AnotherWidget.Widget.Date" parent="AnotherWidget.Subtitle"> <style name="AnotherWidget.Widget.Date" parent="AnotherWidget.Widget.Subtitle">
</style> </style>
<style name="AnotherWidget.Widget.Date.Big" parent="AnotherWidget.Title"> <style name="AnotherWidget.Widget.Date.Big" parent="AnotherWidget.Widget.Title">
<item name="android:textSize">22sp</item> <item name="android:textSize">22sp</item>
</style> </style>