Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ecaf7a11a | |||
2578566659 | |||
61fc0da8d0 | |||
7edb0635a7 | |||
d72ddd6d85 | |||
5d07cc8d73 | |||
1ac53e09a8 | |||
3412e044df | |||
80023da430 | |||
e2a2d17506 | |||
b93443b736 | |||
9842ba3ea9 | |||
75aba66987 |
180
.idea/assetWizardSettings.xml
generated
@ -19,6 +19,29 @@
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="clipArt">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
<entry key="imagePath" value="/private/var/folders/cw/tkrg0g5j6lzcqwr0tfkph8w80000gn/T/ic_android_black_24dp.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="text">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="textAsset">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
@ -45,14 +68,47 @@
|
||||
<PersistentState>
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="foregroundClipArt">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="imagePath" value="/private/var/folders/cw/tkrg0g5j6lzcqwr0tfkph8w80000gn/T/ic_android_black_24dp.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundImage">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
<entry key="imagePath" value="$USER_HOME$/Desktop/logo-white.png" />
|
||||
<entry key="scalingPercent" value="70" />
|
||||
<entry key="trimmed" value="true" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundText">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundTextAsset">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
@ -64,7 +120,6 @@
|
||||
<map>
|
||||
<entry key="backgroundAssetType" value="COLOR" />
|
||||
<entry key="backgroundColor" value="ffffff" />
|
||||
<entry key="foregroundImage" value="$USER_HOME$/Desktop/Artboard Copy 3.png" />
|
||||
<entry key="legacyIconShape" value="CIRCLE" />
|
||||
</map>
|
||||
</option>
|
||||
@ -77,6 +132,29 @@
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="clipArt">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
<entry key="imagePath" value="/private/var/folders/cw/tkrg0g5j6lzcqwr0tfkph8w80000gn/T/ic_android_black_24dp.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="text">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="textAsset">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
@ -98,6 +176,104 @@
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="clipArt">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
<entry key="imagePath" value="/private/var/folders/cw/tkrg0g5j6lzcqwr0tfkph8w80000gn/T/ic_android_black_24dp.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="text">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="textAsset">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="tvBanner">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="foregroundText">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="tvChannel">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="foregroundClipArt">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="imagePath" value="/private/var/folders/cw/tkrg0g5j6lzcqwr0tfkph8w80000gn/T/ic_android_black_24dp.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundImage">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundText">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="000000" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="foregroundTextAsset">
|
||||
<value>
|
||||
<PersistentState>
|
||||
<option name="values">
|
||||
|
BIN
.idea/caches/build_file_checksums.ser
generated
2
.idea/misc.xml
generated
@ -61,7 +61,7 @@
|
||||
</profile-state>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
1
.idea/runConfigurations.xml
generated
@ -3,6 +3,7 @@
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
|
@ -22,8 +22,8 @@ android {
|
||||
applicationId "com.tommasoberlose.anotherwidget"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 130
|
||||
versionName "2.3.1"
|
||||
versionCode 138
|
||||
versionName "2.3.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
buildConfigField("String", "GOOGLE_API_KEY", apikeyProperties['GOOGLE_API_KEY'])
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 45 KiB |
@ -3,40 +3,30 @@ package com.tommasoberlose.anotherwidget.components
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.GridLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.ColorInt
|
||||
import android.widget.FrameLayout
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuHorBinding
|
||||
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuListBinding
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.copyToClipboard
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isClipboardColor
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.utils.expand
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.pasteFromClipboard
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import com.tommasoberlose.anotherwidget.utils.reveal
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import com.warkiz.widget.IndicatorSeekBar
|
||||
import com.warkiz.widget.OnSeekChangeListener
|
||||
import com.warkiz.widget.SeekParams
|
||||
import kotlinx.coroutines.*
|
||||
import net.idik.lib.slimadapter.SlimAdapter
|
||||
import java.lang.Exception
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
class BottomSheetColorPicker(
|
||||
context: Context,
|
||||
@ -46,20 +36,45 @@ class BottomSheetColorPicker(
|
||||
private val onColorSelected: ((selectedValue: Int) -> Unit)? = null,
|
||||
private val showAlphaSelector: Boolean = false,
|
||||
private val alpha: Int = 0,
|
||||
private val onAlphaChangeListener: ((alpha: Int) -> Unit)? = null
|
||||
private val onAlphaChangeListener: ((alpha: Int) -> Unit)? = null,
|
||||
private val hideCopyPaste: Boolean = false,
|
||||
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
private var loadingJobs: ArrayList<Job> = ArrayList()
|
||||
private lateinit var adapter: SlimAdapter
|
||||
private var alphaDebouncing: Job? = null
|
||||
|
||||
private var binding: BottomSheetMenuHorBinding = BottomSheetMenuHorBinding.inflate(LayoutInflater.from(context))
|
||||
private var listBinding: BottomSheetMenuListBinding = BottomSheetMenuListBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
override fun show() {
|
||||
window?.setDimAmount(0f)
|
||||
|
||||
// Header
|
||||
binding.header.isVisible = header != null
|
||||
binding.headerText.text = header ?: ""
|
||||
|
||||
if (hideCopyPaste) {
|
||||
binding.actionContainer.isVisible = false
|
||||
} else {
|
||||
binding.actionContainer.isVisible = true
|
||||
binding.actionCopy.setOnClickListener {
|
||||
context.copyToClipboard(getSelected?.invoke(), alpha)
|
||||
}
|
||||
binding.actionPaste.setOnClickListener {
|
||||
context.pasteFromClipboard { color, alpha ->
|
||||
binding.alphaSelector.setProgress(alpha.toIntValue().toFloat())
|
||||
|
||||
adapter.notifyItemChanged(adapter.data.indexOf(getSelected?.invoke()))
|
||||
onColorSelected?.invoke(Color.parseColor(color))
|
||||
val idx = colors.toList().indexOf(getSelected?.invoke())
|
||||
adapter.notifyItemChanged(idx)
|
||||
(listBinding.root.layoutManager as GridLayoutManager).scrollToPositionWithOffset(idx,0)
|
||||
}
|
||||
}
|
||||
binding.actionPaste.isVisible = context.isClipboardColor()
|
||||
}
|
||||
|
||||
// Alpha
|
||||
binding.alphaSelectorContainer.isVisible = showAlphaSelector
|
||||
binding.alphaSelector.setProgress(alpha.toFloat())
|
||||
@ -67,10 +82,17 @@ class BottomSheetColorPicker(
|
||||
binding.alphaSelector.onSeekChangeListener = object : OnSeekChangeListener {
|
||||
override fun onSeeking(seekParams: SeekParams?) {
|
||||
seekParams?.let {
|
||||
binding.textAlpha.text = "%s: %s%%".format(context.getString(R.string.alpha), it.progress)
|
||||
binding.textAlpha.text =
|
||||
"%s: %s%%".format(context.getString(R.string.alpha), it.progress)
|
||||
alphaDebouncing?.cancel()
|
||||
alphaDebouncing = GlobalScope.launch(Dispatchers.IO) {
|
||||
delay(150)
|
||||
withContext(Dispatchers.Main) {
|
||||
onAlphaChangeListener?.invoke(it.progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onStartTrackingTouch(seekBar: IndicatorSeekBar?) {
|
||||
}
|
||||
override fun onStopTrackingTouch(seekBar: IndicatorSeekBar?) {
|
||||
@ -78,7 +100,6 @@ class BottomSheetColorPicker(
|
||||
}
|
||||
|
||||
// List
|
||||
|
||||
adapter = SlimAdapter.create()
|
||||
|
||||
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
||||
@ -120,10 +141,13 @@ class BottomSheetColorPicker(
|
||||
adapter.updateData(colors.toList())
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.colorLoader.isVisible = false
|
||||
binding.loader.isVisible = false
|
||||
binding.listContainer.addView(listBinding.root)
|
||||
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
binding.listContainer.isVisible = true
|
||||
|
||||
val idx = colors.toList().indexOf(getSelected?.invoke())
|
||||
(listBinding.root.layoutManager as GridLayoutManager).scrollToPositionWithOffset(idx,0)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
|
@ -0,0 +1,108 @@
|
||||
package com.tommasoberlose.anotherwidget.components
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuHorBinding
|
||||
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuListBinding
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.copyToClipboard
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isClipboardColor
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.pasteFromClipboard
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import com.warkiz.widget.IndicatorSeekBar
|
||||
import com.warkiz.widget.OnSeekChangeListener
|
||||
import com.warkiz.widget.SeekParams
|
||||
import kotlinx.coroutines.*
|
||||
import net.idik.lib.slimadapter.SlimAdapter
|
||||
|
||||
class BottomSheetPicker<T>(
|
||||
context: Context,
|
||||
private val items: List<MenuItem<T>> = arrayListOf(),
|
||||
private val getSelected: (() -> T)? = null,
|
||||
private val header: String? = null,
|
||||
private val onItemSelected: ((selectedValue: T?) -> Unit)? = null,
|
||||
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
private var loadingJobs: ArrayList<Job> = ArrayList()
|
||||
private lateinit var adapter: SlimAdapter
|
||||
|
||||
private var binding: BottomSheetMenuHorBinding = BottomSheetMenuHorBinding.inflate(
|
||||
LayoutInflater.from(context))
|
||||
private var listBinding: BottomSheetMenuListBinding = BottomSheetMenuListBinding.inflate(
|
||||
LayoutInflater.from(context))
|
||||
|
||||
override fun show() {
|
||||
window?.setDimAmount(0f)
|
||||
|
||||
// Header
|
||||
binding.header.isVisible = header != null
|
||||
binding.headerText.text = header ?: ""
|
||||
|
||||
// Alpha
|
||||
binding.alphaSelectorContainer.isVisible = false
|
||||
binding.actionContainer.isVisible = false
|
||||
|
||||
// List
|
||||
adapter = SlimAdapter.create()
|
||||
|
||||
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
||||
listBinding.root.setHasFixedSize(true)
|
||||
val mLayoutManager = LinearLayoutManager(context)
|
||||
listBinding.root.layoutManager = mLayoutManager
|
||||
|
||||
adapter
|
||||
.register<Int>(R.layout.bottom_sheet_menu_item) { position, injector ->
|
||||
val item = items[position]
|
||||
val isSelected = item.value == getSelected?.invoke()
|
||||
injector
|
||||
.text(R.id.label, item.title)
|
||||
.textColor(R.id.label, ContextCompat.getColor(context, if (isSelected) R.color.colorAccent else R.color.colorSecondaryText))
|
||||
.selected(R.id.item, isSelected)
|
||||
.clicked(R.id.item) {
|
||||
val oldIdx = items.toList().indexOfFirst { it.value == getSelected?.invoke() }
|
||||
onItemSelected?.invoke(item.value)
|
||||
adapter.notifyItemChanged(position)
|
||||
adapter.notifyItemChanged(oldIdx)
|
||||
(listBinding.root.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position,0)
|
||||
}
|
||||
}
|
||||
.attachTo(listBinding.root)
|
||||
|
||||
adapter.updateData((items.indices).toList())
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.loader.isVisible = false
|
||||
binding.listContainer.addView(listBinding.root)
|
||||
this@BottomSheetPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
binding.listContainer.isVisible = true
|
||||
|
||||
val idx = items.toList().indexOfFirst { it.value == getSelected?.invoke() }
|
||||
(listBinding.root.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(idx,0)
|
||||
}
|
||||
})
|
||||
|
||||
setContentView(binding.root)
|
||||
super.show()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
loadingJobs.forEach { it.cancel() }
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
class MenuItem<T>(val title: String, val value: T? = null)
|
||||
|
||||
}
|
@ -83,7 +83,7 @@ object Constants {
|
||||
|
||||
enum class WidgetAlign(val rawValue: Int) {
|
||||
LEFT(0),
|
||||
// RIGHT(1),
|
||||
RIGHT(1),
|
||||
CENTER(2)
|
||||
}
|
||||
}
|
@ -110,6 +110,7 @@ object Preferences : KotprefModel() {
|
||||
var customFontName by stringPref(default = "")
|
||||
var customFontVariant by stringPref(default = "regular")
|
||||
var showNextEvent by booleanPref(key = "PREF_SHOW_NEXT_EVENT", default = true)
|
||||
var showNextEventOnMultipleLines by booleanPref(default = false)
|
||||
|
||||
var showDividers by booleanPref(default = true)
|
||||
|
||||
|
@ -1,10 +1,20 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Context.CLIPBOARD_SERVICE
|
||||
import android.graphics.Color
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
object ColorHelper {
|
||||
fun getFontColor(isDark: Boolean): Int {
|
||||
return try {
|
||||
@ -144,4 +154,40 @@ object ColorHelper {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
fun Context.copyToClipboard(color: Int?, alpha: Int) {
|
||||
if (color == null) return toast(getString(R.string.error_copy_color))
|
||||
with(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager) {
|
||||
try {
|
||||
val colorString = Integer.toHexString(color)
|
||||
val clip = "#%s%s".format(
|
||||
alpha.toHexValue(),
|
||||
if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
).toUpperCase()
|
||||
setPrimaryClip(ClipData.newPlainText(clip, clip))
|
||||
toast(getString(R.string.color_copied))
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
toast(getString(R.string.error_copy_color))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isClipboardColor(): Boolean {
|
||||
with(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager) {
|
||||
return try { primaryClip?.getItemAt(0)?.text?.toString()?.isColor() ?: false } catch (ex: Exception) { false }
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.pasteFromClipboard(pasteColor: (color: String, alpha: String) -> Unit) {
|
||||
with(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager) {
|
||||
primaryClip?.let {
|
||||
val item = it.getItemAt(0).text.toString().replace("#", "")
|
||||
val color = if (item.length > 6) item.substring(2) else item
|
||||
val alpha = if (item.length > 6) item.substring(0, 2) else "00"
|
||||
pasteColor("#$color", alpha)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.receivers.NotificationListener
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.ignoreExceptions
|
||||
import java.lang.Exception
|
||||
|
||||
object MediaPlayerHelper {
|
||||
@ -69,17 +70,26 @@ object MediaPlayerHelper {
|
||||
isSomeonePlaying = true
|
||||
if (metadata != null) {
|
||||
Preferences.bulk {
|
||||
ignoreExceptions {
|
||||
mediaPlayerTitle =
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_TITLE)?.toString()
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_TITLE)
|
||||
?.toString()
|
||||
?: ""
|
||||
}
|
||||
ignoreExceptions {
|
||||
mediaPlayerArtist =
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_ARTIST)?.toString()
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_ARTIST)
|
||||
?.toString()
|
||||
?: ""
|
||||
}
|
||||
ignoreExceptions {
|
||||
mediaPlayerAlbum =
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_ALBUM)?.toString()
|
||||
metadata.getText(MediaMetadata.METADATA_KEY_ALBUM)
|
||||
?.toString()
|
||||
?: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Preferences.mediaPlayerPackage = mc.packageName
|
||||
}
|
||||
|
@ -53,12 +53,12 @@ class CustomLocationActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
.register<Address>(R.layout.custom_location_item) { item, injector ->
|
||||
injector.text(R.id.text, item.getAddressLine(0))
|
||||
injector.text(R.id.text, item.getAddressLine(0) ?: "")
|
||||
injector.clicked(R.id.item) {
|
||||
Preferences.bulk {
|
||||
customLocationLat = item.latitude.toString()
|
||||
customLocationLon = item.longitude.toString()
|
||||
customLocationAdd = item.getAddressLine(0)
|
||||
customLocationAdd = item.getAddressLine(0) ?: ""
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
@ -74,7 +74,11 @@ class TimeZoneSelectorActivity : AppCompatActivity() {
|
||||
if (id != null) {
|
||||
Preferences.bulk {
|
||||
altTimezoneId = id
|
||||
altTimezoneLabel = item.locality
|
||||
altTimezoneLabel = try {
|
||||
item.locality
|
||||
} catch (ex: Exception) {
|
||||
item.getAddressLine(0)
|
||||
}
|
||||
}
|
||||
MainWidget.updateWidget(this@TimeZoneSelectorActivity)
|
||||
setResult(Activity.RESULT_OK)
|
||||
|
@ -16,6 +16,7 @@ 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 androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@ -183,8 +184,6 @@ class MainFragment : Fragment() {
|
||||
private var uiJob: Job? = null
|
||||
|
||||
private fun updateUI() {
|
||||
uiJob?.cancel()
|
||||
|
||||
if (Preferences.showPreview) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val bgColor: Int = ContextCompat.getColor(
|
||||
@ -207,24 +206,28 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
|
||||
WidgetHelper.runWithCustomTypeface(requireContext()) { typeface ->
|
||||
uiJob?.cancel()
|
||||
uiJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
val generatedView = MainWidget.getWidgetView(requireContext(), typeface).root
|
||||
val generatedView = MainWidget.getWidgetView(requireContext(), typeface)?.root
|
||||
|
||||
if (generatedView != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
generatedView.measure(0, 0)
|
||||
binding.preview.measure(0, 0)
|
||||
}
|
||||
|
||||
val bitmap = BitmapHelper.getBitmapFromView(
|
||||
generatedView,
|
||||
if (binding.preview.width > 0) binding.preview.width else generatedView.measuredWidth,
|
||||
generatedView.measuredHeight
|
||||
binding.widgetDetail.content.removeAllViews()
|
||||
val container = LinearLayout(requireContext()).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.widgetDetail.bitmapContainer.apply {
|
||||
setImageBitmap(bitmap)
|
||||
}
|
||||
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)
|
||||
|
||||
binding.widgetLoader.animate().scaleX(0f).scaleY(0f).alpha(0f)
|
||||
.setDuration(200L).start()
|
||||
@ -234,6 +237,7 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateClock() {
|
||||
// Clock
|
||||
@ -287,7 +291,35 @@ class MainFragment : Fragment() {
|
||||
|
||||
// Align
|
||||
binding.widgetDetail.timeContainer.layoutParams = (binding.widgetDetail.timeContainer.layoutParams as LinearLayout.LayoutParams).apply {
|
||||
gravity = if (Preferences.widgetAlign == Constants.WidgetAlign.CENTER.rawValue) Gravity.CENTER_HORIZONTAL else Gravity.NO_GRAVITY
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,7 +342,7 @@ class MainFragment : Fragment() {
|
||||
if (showClock) 0f else 1f,
|
||||
if (showClock) 1f else 0f
|
||||
).apply {
|
||||
duration = 300L
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Float
|
||||
binding.widgetDetail.timeContainer.layoutParams =
|
||||
@ -318,6 +350,10 @@ class MainFragment : Fragment() {
|
||||
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()
|
||||
}
|
||||
@ -334,7 +370,7 @@ class MainFragment : Fragment() {
|
||||
requireContext()
|
||||
) else 0)
|
||||
).apply {
|
||||
duration = 300L
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = binding.preview.layoutParams
|
||||
|
@ -35,6 +35,7 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.settings.SupportDevActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.ignoreExceptions
|
||||
import com.tommasoberlose.anotherwidget.utils.openURI
|
||||
import com.tommasoberlose.anotherwidget.utils.setOnSingleClickListener
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -206,10 +207,14 @@ class SettingsFragment : Fragment() {
|
||||
.rotation((binding.actionRefreshIcon.rotation - binding.actionRefreshIcon.rotation % 360f) + 360f)
|
||||
.withEndAction {
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
WeatherHelper.updateWeather(requireContext())
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
MediaPlayerHelper.updatePlayingMediaInfo(requireContext())
|
||||
ActiveNotificationsHelper.clearLastNotification(requireContext())
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
.start()
|
||||
|
@ -63,6 +63,7 @@ class CalendarFragment : Fragment() {
|
||||
binding.showAllDayToggle.setCheckedImmediatelyNoEvent(Preferences.calendarAllDay)
|
||||
binding.showOnlyBusyEventsToggle.setCheckedImmediatelyNoEvent(Preferences.showOnlyBusyEvents)
|
||||
binding.showDiffTimeToggle.setCheckedImmediatelyNoEvent(Preferences.showDiffTime)
|
||||
binding.showNextEventOnMultipleLinesToggle.setCheckedImmediatelyNoEvent(Preferences.showNextEventOnMultipleLines)
|
||||
|
||||
setupListener()
|
||||
|
||||
@ -90,6 +91,12 @@ class CalendarFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.showNextEventOnMultipleLines.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.showNextEventOnMultipleLinesLabel.text = if (it) getString(R.string.settings_enabled) else getString(R.string.settings_disabled)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.showDiffTime.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.showDiffTimeLabel.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
@ -231,6 +238,14 @@ class CalendarFragment : Fragment() {
|
||||
Preferences.showDiffTime = isChecked
|
||||
}
|
||||
|
||||
binding.actionShowNextEventOnMultipleLines.setOnClickListener {
|
||||
binding.showNextEventOnMultipleLinesToggle.isChecked = !binding.showNextEventOnMultipleLinesToggle.isChecked
|
||||
}
|
||||
|
||||
binding.showNextEventOnMultipleLinesToggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
Preferences.showNextEventOnMultipleLines = isChecked
|
||||
}
|
||||
|
||||
binding.actionWidgetUpdateFrequency.setOnClickListener {
|
||||
if (Preferences.showEvents && Preferences.showDiffTime) {
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_widget_update_frequency_title), message = getString(R.string.settings_widget_update_frequency_subtitle)).setSelectedValue(Preferences.widgetUpdateFrequency)
|
||||
|
@ -101,12 +101,14 @@ class LayoutFragment : Fragment() {
|
||||
maintainScrollPosition {
|
||||
binding.widgetAlignIcon.setImageDrawable(when (it) {
|
||||
Constants.WidgetAlign.LEFT.rawValue -> ContextCompat.getDrawable(requireContext(), R.drawable.round_align_horizontal_left_24)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> ContextCompat.getDrawable(requireContext(), R.drawable.round_align_horizontal_right_24)
|
||||
Constants.WidgetAlign.CENTER.rawValue -> ContextCompat.getDrawable(requireContext(), R.drawable.round_align_horizontal_center_24)
|
||||
else -> ContextCompat.getDrawable(requireContext(), R.drawable.round_align_horizontal_center_24)
|
||||
})
|
||||
|
||||
binding.widgetAlignLabel.text = when (it) {
|
||||
Constants.WidgetAlign.LEFT.rawValue -> getString(R.string.settings_widget_align_left_subtitle)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> getString(R.string.settings_widget_align_right_subtitle)
|
||||
Constants.WidgetAlign.CENTER.rawValue -> getString(R.string.settings_widget_align_center_subtitle)
|
||||
else -> getString(R.string.settings_widget_align_center_subtitle)
|
||||
}
|
||||
@ -210,6 +212,10 @@ class LayoutFragment : Fragment() {
|
||||
getString(R.string.settings_widget_align_left_subtitle),
|
||||
Constants.WidgetAlign.LEFT.rawValue
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_widget_align_right_subtitle),
|
||||
Constants.WidgetAlign.RIGHT.rawValue
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.widgetAlign = value
|
||||
}.show()
|
||||
|
@ -15,6 +15,7 @@ import com.google.android.material.transition.MaterialSharedAxis
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetPicker
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentTabTypographyBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -167,25 +168,27 @@ class TypographyFragment : Fragment() {
|
||||
|
||||
private fun setupListener() {
|
||||
binding.actionMainTextSize.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_main_text_size)).setSelectedValue(
|
||||
Preferences.textMainSize)
|
||||
(40 downTo 10).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
BottomSheetPicker(
|
||||
requireContext(),
|
||||
items = (40 downTo 10).map { BottomSheetPicker.MenuItem("${it}sp", it.toFloat()) },
|
||||
getSelected = { Preferences.textMainSize },
|
||||
header = getString(R.string.title_main_text_size),
|
||||
onItemSelected = {value ->
|
||||
if (value != null) Preferences.textMainSize = value
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.textMainSize = value
|
||||
}.show()
|
||||
).show()
|
||||
}
|
||||
|
||||
binding.actionSecondTextSize.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_second_text_size)).setSelectedValue(
|
||||
Preferences.textSecondSize)
|
||||
(40 downTo 10).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
BottomSheetPicker(
|
||||
requireContext(),
|
||||
items = (40 downTo 10).map { BottomSheetPicker.MenuItem("${it}sp", it.toFloat()) },
|
||||
getSelected = { Preferences.textSecondSize },
|
||||
header = getString(R.string.title_second_text_size),
|
||||
onItemSelected = {value ->
|
||||
if (value != null) Preferences.textSecondSize = value
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.textSecondSize = value
|
||||
}.show()
|
||||
).show()
|
||||
}
|
||||
|
||||
binding.actionFontColor.setOnClickListener {
|
||||
@ -209,7 +212,7 @@ class TypographyFragment : Fragment() {
|
||||
} else {
|
||||
Preferences.textGlobalAlpha = alpha.toHexValue()
|
||||
}
|
||||
}
|
||||
},
|
||||
).show()
|
||||
}
|
||||
|
||||
@ -236,7 +239,7 @@ class TypographyFragment : Fragment() {
|
||||
} else {
|
||||
Preferences.textSecondaryAlpha = alpha.toHexValue()
|
||||
}
|
||||
}
|
||||
},
|
||||
).show()
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ class MainViewModel(context: Application) : AndroidViewModel(context) {
|
||||
val showUntil = Preferences.asLiveData(Preferences::showUntil)
|
||||
val showDiffTime = Preferences.asLiveData(Preferences::showDiffTime)
|
||||
val showNextEvent = Preferences.asLiveData(Preferences::showNextEvent)
|
||||
val showNextEventOnMultipleLines = Preferences.asLiveData(Preferences::showNextEventOnMultipleLines)
|
||||
val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails)
|
||||
val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName)
|
||||
val widgetUpdateFrequency = Preferences.asLiveData(Preferences::widgetUpdateFrequency)
|
||||
@ -144,6 +145,7 @@ class MainViewModel(context: Application) : AndroidViewModel(context) {
|
||||
addSource(Preferences.asLiveData(Preferences::calendarAllDay)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showDiffTime)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showNextEvent)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showNextEventOnMultipleLines)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showDeclinedEvents)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showInvitedEvents)) { value = true }
|
||||
addSource(Preferences.asLiveData(Preferences::showAcceptedEvents)) { value = true }
|
||||
|
@ -0,0 +1,939 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.widgets
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.text.format.DateUtils
|
||||
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.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateMargins
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.databinding.LeftAlignedWidgetBinding
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ImageHelper.applyShadow
|
||||
import com.tommasoberlose.anotherwidget.receivers.CrashlyticsReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.NewCalendarEventReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.WidgetClickListenerReceiver
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.convertDpToPixel
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class AlignedWidget(val context: Context, val rightAligned: Boolean = false) {
|
||||
fun generateWidget(appWidgetId: Int, w: Int, typeface: Typeface? = null): RemoteViews? {
|
||||
|
||||
var views = RemoteViews(context.packageName, if (!rightAligned) R.layout.left_aligned_widget_sans else R.layout.right_aligned_widget_sans)
|
||||
|
||||
try {
|
||||
// Background
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setColorFilter",
|
||||
ColorHelper.getBackgroundColorRgb(context.isDarkTheme())
|
||||
)
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setImageAlpha",
|
||||
ColorHelper.getBackgroundAlpha(context.isDarkTheme())
|
||||
)
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
IntentHelper.getWidgetUpdateIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
// Clock
|
||||
views = ClockWidget(context).updateClockView(views, appWidgetId)
|
||||
|
||||
// Setup listener
|
||||
try {
|
||||
val generatedBinding = generateWidgetView(typeface) ?: return null
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.bitmap_container,
|
||||
BitmapHelper.getBitmapFromView(generatedBinding.root, width = w)
|
||||
)
|
||||
views = updateGridView(generatedBinding, views, appWidgetId)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
return views
|
||||
}
|
||||
|
||||
private fun updateGridView(bindingView: LeftAlignedWidgetBinding, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
try {
|
||||
val eventRepository = EventRepository(context)
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val eventsCount = eventRepository.getEventsCount()
|
||||
eventRepository.close()
|
||||
|
||||
// Weather
|
||||
if (Preferences.showWeather && Preferences.weatherIcon != "") {
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_sub_line, View.GONE)
|
||||
|
||||
val i = Intent(context, WidgetClickListenerReceiver::class.java)
|
||||
i.action = Actions.ACTION_OPEN_WEATHER_INTENT
|
||||
val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, i, 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather_rect, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.weather_sub_line_rect, weatherPIntent)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherDateLine, draw = false, width = bindingView.weatherDateLine.width, height = bindingView.weatherDateLine.height)
|
||||
)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherSubLine, draw = false, width = bindingView.weatherSubLine.width, height = bindingView.weatherSubLine.height)
|
||||
)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.weather_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line, View.GONE)
|
||||
}
|
||||
|
||||
|
||||
// Calendar
|
||||
views.setImageViewBitmap(
|
||||
R.id.date_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height)
|
||||
)
|
||||
|
||||
val calPIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getCalendarIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.date_rect, calPIntent)
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
|
||||
val nextAlarm = AlarmHelper.getNextAlarm(context)
|
||||
|
||||
// Spacing
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_small_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_medium_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_large_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
|
||||
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
|
||||
if (Preferences.showNextEvent && eventsCount > 1) {
|
||||
|
||||
// Action next event
|
||||
views.setImageViewBitmap(
|
||||
R.id.action_next_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionNext, draw = false, width = bindingView.actionNext.width, height = bindingView.actionNext.height)
|
||||
)
|
||||
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.action_next_rect,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
widgetID,
|
||||
Intent(
|
||||
context,
|
||||
NewCalendarEventReceiver::class.java
|
||||
).apply { action = Actions.ACTION_GO_TO_NEXT_EVENT },
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
|
||||
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.action_next_rect, View.GONE)
|
||||
}
|
||||
|
||||
// Event intent
|
||||
val eventIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(context, nextEvent),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.next_event_rect, eventIntent)
|
||||
views.setImageViewBitmap(
|
||||
R.id.next_event_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = false, width = bindingView.nextEvent.width, height = bindingView.nextEvent.height)
|
||||
)
|
||||
views.setViewVisibility(R.id.next_event_rect, View.VISIBLE)
|
||||
|
||||
// Event time difference
|
||||
if (Preferences.showDiffTime && Calendar.getInstance().timeInMillis < nextEvent.startDate) {
|
||||
views.setImageViewBitmap(
|
||||
R.id.next_event_difference_time_rect,
|
||||
BitmapHelper.getBitmapFromView(
|
||||
bindingView.nextEventDifferenceTime,
|
||||
draw = false,
|
||||
width = bindingView.nextEventDifferenceTime.width,
|
||||
height = bindingView.nextEventDifferenceTime.height
|
||||
)
|
||||
)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time_rect, eventIntent)
|
||||
if (!Preferences.showNextEventOnMultipleLines) {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.GONE)
|
||||
}
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.GONE)
|
||||
}
|
||||
|
||||
// Event information
|
||||
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
|
||||
val mapIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent)
|
||||
} else {
|
||||
val pIntentDetail = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(
|
||||
context,
|
||||
nextEvent,
|
||||
forceEventDetails = true
|
||||
),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail)
|
||||
}
|
||||
|
||||
views.setViewVisibility(R.id.calendar_layout_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.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_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
var showSomething = false
|
||||
loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
if (MediaPlayerHelper.isSomeonePlaying(context)) {
|
||||
val musicIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getMusicIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, musicIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
if (Preferences.showNextAlarm && nextAlarm != "") {
|
||||
val alarmIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getClockIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging || Preferences.isBatteryLevelLow) {
|
||||
val batteryIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getBatteryIntent(),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, batteryIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
if (Preferences.customNotes.isNotEmpty()) {
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
|
||||
val fitIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getFitIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, fitIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||
try {
|
||||
if (Preferences.lastNotificationIcon != 0) {
|
||||
val remotePackageContext = context.createPackageContext(
|
||||
Preferences.lastNotificationPackage, 0)
|
||||
ContextCompat.getDrawable(
|
||||
remotePackageContext,
|
||||
Preferences.lastNotificationIcon)
|
||||
}
|
||||
val notificationIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getNotificationIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.sub_line_rect,
|
||||
notificationIntent
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
} catch (ex: Exception) {}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
if (Preferences.showGreetings && GreetingsHelper.showGreetings() && GreetingsHelper.getRandomString(context).isNotBlank()) {
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.EVENTS -> {
|
||||
if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR) && nextEvent != null) {
|
||||
val pIntentDetail = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(
|
||||
context,
|
||||
nextEvent,
|
||||
forceEventDetails = true
|
||||
),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.sub_line_rect,
|
||||
pIntentDetail
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (showSomething) {
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE)
|
||||
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
|
||||
} else {
|
||||
// Spacing
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
}
|
||||
} else {
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
|
||||
// Spacing
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
}
|
||||
|
||||
// Second row
|
||||
views.setImageViewBitmap(
|
||||
R.id.sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false, width = bindingView.subLine.width, height = bindingView.subLine.height)
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
return views
|
||||
}
|
||||
|
||||
|
||||
// Generates the widget bitmap from the view
|
||||
fun generateWidgetView(typeface: Typeface? = null): LeftAlignedWidgetBinding? {
|
||||
try {
|
||||
val eventRepository = EventRepository(context)
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val eventsCount = eventRepository.getEventsCount()
|
||||
eventRepository.close()
|
||||
|
||||
val bindingView = LeftAlignedWidgetBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
bindingView.loader.isVisible = false
|
||||
|
||||
// Weather
|
||||
if (Preferences.showWeather && Preferences.weatherIcon != "") {
|
||||
bindingView.weatherDateLine.isVisible = true
|
||||
val currentTemp = String.format(
|
||||
Locale.getDefault(),
|
||||
"%d°%s",
|
||||
Preferences.weatherTemp.roundToInt(),
|
||||
Preferences.weatherRealTempUnit
|
||||
)
|
||||
|
||||
val icon: String = Preferences.weatherIcon
|
||||
if (icon == "") {
|
||||
bindingView.weatherSubLineWeatherIcon.isVisible = false
|
||||
bindingView.weatherDateLineWeatherIcon.isVisible = false
|
||||
} else {
|
||||
bindingView.weatherSubLineWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
|
||||
bindingView.weatherDateLineWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
|
||||
bindingView.weatherSubLineWeatherIcon.isVisible = true
|
||||
bindingView.weatherDateLineWeatherIcon.isVisible = true
|
||||
}
|
||||
|
||||
bindingView.weatherDateLineTemperature.text = currentTemp
|
||||
bindingView.weatherSubLineTemperature.text = currentTemp
|
||||
|
||||
if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
}
|
||||
} else {
|
||||
bindingView.weatherDateLine.isVisible = false
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
}
|
||||
|
||||
val now = Calendar.getInstance().apply {
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
|
||||
bindingView.dateLayout.isVisible = true
|
||||
bindingView.calendarLayout.isVisible = false
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
bindingView.actionNext.isVisible = false
|
||||
|
||||
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) {
|
||||
// Multiple counter
|
||||
bindingView.actionNext.isVisible =
|
||||
Preferences.showNextEvent && eventsCount > 1
|
||||
|
||||
bindingView.nextEvent.text = nextEvent.title
|
||||
|
||||
if (Preferences.showNextEventOnMultipleLines) {
|
||||
bindingView.nextEvent.apply {
|
||||
isSingleLine = false
|
||||
maxLines = 3
|
||||
gravity = if (rightAligned) Gravity.END else Gravity.START
|
||||
}
|
||||
}
|
||||
|
||||
if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
|
||||
val diffTime = if (!nextEvent.allDay) {
|
||||
SettingsStringHelper.getDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
)
|
||||
.toLowerCase(Locale.getDefault())
|
||||
} else {
|
||||
SettingsStringHelper.getAllDayEventDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
).toLowerCase(Locale.getDefault())
|
||||
}
|
||||
bindingView.nextEventDifferenceTime.text = diffTime
|
||||
|
||||
if (!Preferences.showNextEventOnMultipleLines) {
|
||||
bindingView.nextEventDifferenceTime.isVisible = true
|
||||
} else {
|
||||
bindingView.nextEvent.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, diffTime)
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
}
|
||||
} else {
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
}
|
||||
|
||||
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_place_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = nextEvent.address
|
||||
} else {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_today_24
|
||||
)
|
||||
)
|
||||
if (!nextEvent.allDay) {
|
||||
val startHour =
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
|
||||
.format(nextEvent.startDate)
|
||||
val endHour =
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
|
||||
.format(nextEvent.endDate)
|
||||
|
||||
var dayDiff =
|
||||
TimeUnit.MILLISECONDS.toDays(nextEvent.endDate - nextEvent.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
startCal.timeInMillis = nextEvent.startDate
|
||||
|
||||
val endCal = Calendar.getInstance()
|
||||
endCal.timeInMillis = nextEvent.endDate
|
||||
|
||||
if (startCal.get(Calendar.HOUR_OF_DAY) > endCal.get(Calendar.HOUR_OF_DAY)) {
|
||||
dayDiff++
|
||||
} else if (startCal.get(Calendar.HOUR_OF_DAY) == endCal.get(Calendar.HOUR_OF_DAY) && startCal.get(
|
||||
Calendar.MINUTE
|
||||
) > endCal.get(Calendar.MINUTE)
|
||||
) {
|
||||
dayDiff++
|
||||
}
|
||||
var multipleDay = ""
|
||||
if (dayDiff > 0) {
|
||||
multipleDay = String.format(
|
||||
" (+%s%s)",
|
||||
dayDiff,
|
||||
context.getString(R.string.day_char)
|
||||
)
|
||||
}
|
||||
|
||||
if (nextEvent.startDate != nextEvent.endDate) {
|
||||
bindingView.subLineText.text =
|
||||
String.format("%s - %s%s", startHour, endHour, multipleDay)
|
||||
} else {
|
||||
bindingView.subLineText.text =
|
||||
String.format("%s", startHour)
|
||||
}
|
||||
|
||||
} 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 }
|
||||
|
||||
bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(
|
||||
Calendar.DAY_OF_YEAR)) {
|
||||
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
|
||||
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(
|
||||
Calendar.YEAR) > start.get(Calendar.YEAR)) {
|
||||
DateUtils.formatDateTime(context, now.timeInMillis, flags)
|
||||
} else {
|
||||
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bindingView.dateLayout.isVisible = false
|
||||
bindingView.calendarLayout.isVisible = true
|
||||
bindingView.subLine.isVisible = true
|
||||
bindingView.weatherSubLine.isVisible = true
|
||||
|
||||
bindingView.subLineTopMarginSmall.visibility = View.GONE
|
||||
bindingView.subLineTopMarginMedium.visibility = View.GONE
|
||||
bindingView.subLineTopMarginLarge.visibility = View.GONE
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
var showSomething = false
|
||||
loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(
|
||||
context
|
||||
)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
if (MediaPlayerHelper.isSomeonePlaying(context)) {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_music_note_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = MediaPlayerHelper.getMediaInfo()
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
if (Preferences.showNextAlarm && nextAlarm != "") {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_alarm_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = AlarmHelper.getNextAlarm(context)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
val batteryLevel = BatteryHelper.getBatteryLevel(context)
|
||||
if (batteryLevel != 100) {
|
||||
bindingView.subLineText.text = context.getString(R.string.charging)
|
||||
} else {
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.charged)
|
||||
}
|
||||
showSomething = true
|
||||
break@loop
|
||||
} else if (Preferences.isBatteryLevelLow) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.battery_low_warning)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
if (Preferences.customNotes.isNotEmpty()) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text = Preferences.customNotes
|
||||
bindingView.subLineText.maxLines = 2
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.daily_steps_counter)
|
||||
.format(Preferences.googleFitSteps)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||
try {
|
||||
if (Preferences.lastNotificationIcon != 0) {
|
||||
val remotePackageContext = context.createPackageContext(
|
||||
Preferences.lastNotificationPackage, 0)
|
||||
val icon = ContextCompat.getDrawable(remotePackageContext,
|
||||
Preferences.lastNotificationIcon)
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
bindingView.subLineIcon.setImageDrawable(icon)
|
||||
} else {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
}
|
||||
bindingView.subLineText.text = Preferences.lastNotificationTitle
|
||||
showSomething = true
|
||||
break@loop
|
||||
} catch (ex: Exception) {}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
val greetingsText = GreetingsHelper.getRandomString(context)
|
||||
if (Preferences.showGreetings && GreetingsHelper.showGreetings() && greetingsText.isNotBlank()) {
|
||||
bindingView.subLineText.text = greetingsText
|
||||
bindingView.subLineText.maxLines = 2
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.EVENTS -> {
|
||||
if (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR) && nextEvent != null) {
|
||||
bindingView.subLineText.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
|
||||
if (!nextEvent.allDay) {
|
||||
SettingsStringHelper.getDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
)
|
||||
.toLowerCase(Locale.getDefault())
|
||||
} else {
|
||||
SettingsStringHelper.getAllDayEventDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
).toLowerCase(Locale.getDefault())
|
||||
}
|
||||
} else "").trimEnd()
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_today_24
|
||||
)
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showSomething) {
|
||||
bindingView.dateLayout.isVisible = true
|
||||
bindingView.calendarLayout.isVisible = false
|
||||
bindingView.subLine.isVisible = true
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
|
||||
bindingView.subLineTopMarginSmall.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE
|
||||
bindingView.subLineTopMarginMedium.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.rawValue) View.VISIBLE else View.GONE
|
||||
bindingView.subLineTopMarginLarge.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.rawValue) View.VISIBLE else View.GONE
|
||||
} else {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Color
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
).forEach {
|
||||
it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme()))
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.rawValue) {
|
||||
listOf<ImageView>(bindingView.actionNext)
|
||||
} else {
|
||||
listOf<ImageView>(
|
||||
bindingView.actionNext,
|
||||
bindingView.weatherDateLineWeatherIcon,
|
||||
bindingView.weatherSubLineWeatherIcon
|
||||
)
|
||||
}.forEach {
|
||||
it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme()))
|
||||
it.alpha =
|
||||
(if (context.isDarkTheme()) Preferences.textGlobalAlphaDark.toIntValue()
|
||||
.toFloat() else Preferences.textGlobalAlpha.toIntValue()
|
||||
.toFloat()) / 100
|
||||
}
|
||||
|
||||
listOf<TextView>(bindingView.subLineText, bindingView.weatherSubLineDivider, bindingView.weatherSubLineTemperature).forEach {
|
||||
it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme()))
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.rawValue) {
|
||||
listOf<ImageView>(bindingView.subLineIcon, bindingView.subLineIconShadow)
|
||||
} else {
|
||||
listOf<ImageView>(bindingView.subLineIcon, bindingView.weatherSubLineWeatherIcon, bindingView.subLineIconShadow)
|
||||
}.forEach {
|
||||
it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme()))
|
||||
it.alpha =
|
||||
(if (context.isDarkTheme()) Preferences.textSecondaryAlphaDark.toIntValue()
|
||||
.toFloat() else Preferences.textSecondaryAlpha.toIntValue()
|
||||
.toFloat()) / 100
|
||||
}
|
||||
|
||||
// Text Size
|
||||
listOf<Pair<TextView, Float>>(
|
||||
bindingView.date to Preferences.textMainSize,
|
||||
bindingView.weatherDateLineTemperature to ((Preferences.textMainSize + Preferences.textSecondSize) / 2),
|
||||
bindingView.nextEvent to Preferences.textMainSize,
|
||||
bindingView.nextEventDifferenceTime to Preferences.textMainSize,
|
||||
bindingView.subLineText to Preferences.textSecondSize,
|
||||
bindingView.weatherSubLineDivider to (Preferences.textSecondSize - 2),
|
||||
bindingView.weatherSubLineTemperature to Preferences.textSecondSize,
|
||||
).forEach {
|
||||
it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second)
|
||||
}
|
||||
|
||||
// Icons scale
|
||||
bindingView.subLineIcon.scaleX = Preferences.textSecondSize / 18f
|
||||
bindingView.subLineIcon.scaleY = Preferences.textSecondSize / 18f
|
||||
|
||||
bindingView.weatherSubLineWeatherIcon.scaleX = Preferences.textSecondSize / 18f
|
||||
bindingView.weatherSubLineWeatherIcon.scaleY = Preferences.textSecondSize / 18f
|
||||
|
||||
bindingView.weatherDateLineWeatherIcon.scaleX = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f
|
||||
bindingView.weatherDateLineWeatherIcon.scaleY = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f
|
||||
|
||||
bindingView.actionNext.scaleX = Preferences.textMainSize / 28f
|
||||
bindingView.actionNext.scaleY = Preferences.textMainSize / 28f
|
||||
|
||||
|
||||
// Shadows
|
||||
val shadowRadius =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
2 -> 5f
|
||||
else -> 5f
|
||||
}
|
||||
val shadowColor =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> Color.TRANSPARENT
|
||||
1 -> R.color.black_50
|
||||
2 -> Color.BLACK
|
||||
else -> R.color.black_50
|
||||
}
|
||||
val shadowDy =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> 0f
|
||||
1 -> 0f
|
||||
2 -> 1f
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
}
|
||||
|
||||
// Icons shadow
|
||||
|
||||
listOf(
|
||||
Pair(bindingView.subLineIcon, bindingView.subLineIconShadow),
|
||||
).forEach {
|
||||
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
|
||||
it.second.isVisible = false
|
||||
} else {
|
||||
it.second.isVisible = it.first.isVisible
|
||||
it.second.scaleX = it.first.scaleX
|
||||
it.second.scaleY = it.first.scaleY
|
||||
it.second.applyShadow(it.first)
|
||||
}
|
||||
}
|
||||
|
||||
listOf(
|
||||
Pair(bindingView.actionNext, bindingView.actionNextShadow),
|
||||
).forEach {
|
||||
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
|
||||
it.second.isVisible = false
|
||||
} else {
|
||||
it.second.isVisible = it.first.isVisible
|
||||
it.second.scaleX = it.first.scaleX
|
||||
it.second.scaleY = it.first.scaleY
|
||||
it.second.applyShadow(it.first, 0.6f)
|
||||
}
|
||||
}
|
||||
|
||||
// Custom Font
|
||||
if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) {
|
||||
val googleSans: Typeface = when (Preferences.customFontVariant) {
|
||||
"100" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_thin.ttf")
|
||||
"200" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_light.ttf")
|
||||
"500" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_medium.ttf")
|
||||
"700" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_bold.ttf")
|
||||
"800" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_black.ttf")
|
||||
else -> Typeface.createFromAsset(context.assets, "fonts/google_sans_regular.ttf")
|
||||
}
|
||||
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.typeface = googleSans
|
||||
}
|
||||
} else if (Preferences.customFont == Constants.CUSTOM_FONT_DOWNLOADED && typeface != null) {
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.typeface = typeface
|
||||
}
|
||||
}
|
||||
|
||||
// Dividers
|
||||
arrayOf(bindingView.weatherSubLineDivider).forEach {
|
||||
it.visibility = if (Preferences.showDividers) View.VISIBLE else View.INVISIBLE
|
||||
it.layoutParams = (it.layoutParams as ViewGroup.MarginLayoutParams).apply {
|
||||
this.marginEnd = if (Preferences.showDividers) 8f.convertDpToPixel(context).toInt() else 0
|
||||
}
|
||||
}
|
||||
|
||||
// Right Aligned
|
||||
if (rightAligned) {
|
||||
bindingView.mainContent.layoutParams = (bindingView.mainContent.layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
addRule(RelativeLayout.ALIGN_PARENT_END)
|
||||
}
|
||||
bindingView.mainContent.gravity = Gravity.END
|
||||
bindingView.dateLayout.gravity = Gravity.END
|
||||
bindingView.calendarLayout.gravity = Gravity.END or Gravity.CENTER_VERTICAL
|
||||
bindingView.subLineContainer.gravity = Gravity.END or Gravity.CENTER_VERTICAL
|
||||
}
|
||||
|
||||
return bindingView
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.tommasoberlose.anotherwidget.ui.widgets
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
@ -24,6 +25,7 @@ class ClockWidget(val context: Context) {
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_small, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_medium, View.GONE)
|
||||
views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE)
|
||||
views.setViewVisibility(R.id.timezones_container, View.GONE)
|
||||
} else {
|
||||
views.setTextColor(R.id.time, ColorHelper.getClockFontColor(context.isDarkTheme()))
|
||||
views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor(context.isDarkTheme()))
|
||||
|
@ -1,890 +0,0 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.widgets
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateMargins
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.databinding.LeftAlignedWidgetBinding
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ImageHelper.applyShadow
|
||||
import com.tommasoberlose.anotherwidget.receivers.CrashlyticsReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.NewCalendarEventReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.WidgetClickListenerReceiver
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.convertDpToPixel
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class LeftAlignedWidget(val context: Context) {
|
||||
fun generateWidget(appWidgetId: Int, w: Int, typeface: Typeface? = null): RemoteViews {
|
||||
|
||||
var views = RemoteViews(context.packageName, R.layout.left_aligned_widget_sans)
|
||||
|
||||
try {
|
||||
// Background
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setColorFilter",
|
||||
ColorHelper.getBackgroundColorRgb(context.isDarkTheme())
|
||||
)
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setImageAlpha",
|
||||
ColorHelper.getBackgroundAlpha(context.isDarkTheme())
|
||||
)
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
IntentHelper.getWidgetUpdateIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
// Clock
|
||||
views = ClockWidget(context).updateClockView(views, appWidgetId)
|
||||
|
||||
// Setup listener
|
||||
try {
|
||||
val generatedBinding = generateWidgetView(typeface)
|
||||
views.setImageViewBitmap(
|
||||
R.id.bitmap_container,
|
||||
BitmapHelper.getBitmapFromView(generatedBinding.root, width = w)
|
||||
)
|
||||
views = updateGridView(generatedBinding, views, appWidgetId)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
return views
|
||||
}
|
||||
|
||||
private fun updateGridView(bindingView: LeftAlignedWidgetBinding, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val eventRepository = EventRepository(context)
|
||||
try {
|
||||
// Weather
|
||||
if (Preferences.showWeather && Preferences.weatherIcon != "") {
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_sub_line, View.GONE)
|
||||
|
||||
val i = Intent(context, WidgetClickListenerReceiver::class.java)
|
||||
i.action = Actions.ACTION_OPEN_WEATHER_INTENT
|
||||
val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, i, 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather_rect, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.weather_sub_line_rect, weatherPIntent)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherDateLine, draw = false)
|
||||
)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherSubLine, draw = false)
|
||||
)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.weather_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line, View.GONE)
|
||||
}
|
||||
|
||||
|
||||
// Calendar
|
||||
views.setImageViewBitmap(
|
||||
R.id.date_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.date, draw = false)
|
||||
)
|
||||
|
||||
val calPIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getCalendarIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.date_rect, calPIntent)
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val nextAlarm = AlarmHelper.getNextAlarm(context)
|
||||
|
||||
// Spacing
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_small_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_medium_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
views.setViewVisibility(
|
||||
R.id.sub_line_top_margin_large_sans,
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.rawValue) View.VISIBLE else View.GONE
|
||||
)
|
||||
|
||||
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
|
||||
if (Preferences.showNextEvent && eventRepository.getEventsCount() > 1) {
|
||||
|
||||
// Action next event
|
||||
views.setImageViewBitmap(
|
||||
R.id.action_next_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionNext, draw = false)
|
||||
)
|
||||
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.action_next_rect,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
widgetID,
|
||||
Intent(
|
||||
context,
|
||||
NewCalendarEventReceiver::class.java
|
||||
).apply { action = Actions.ACTION_GO_TO_NEXT_EVENT },
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
|
||||
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.action_next_rect, View.GONE)
|
||||
}
|
||||
|
||||
// Event intent
|
||||
val eventIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(context, nextEvent),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.next_event_rect, eventIntent)
|
||||
views.setViewVisibility(R.id.next_event_rect, View.VISIBLE)
|
||||
|
||||
// Event time difference
|
||||
if (Preferences.showDiffTime && Calendar.getInstance().timeInMillis < nextEvent.startDate) {
|
||||
views.setImageViewBitmap(
|
||||
R.id.next_event_difference_time_rect,
|
||||
BitmapHelper.getBitmapFromView(
|
||||
bindingView.nextEventDifferenceTime,
|
||||
draw = false
|
||||
)
|
||||
)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time_rect, eventIntent)
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.GONE)
|
||||
}
|
||||
|
||||
// Event information
|
||||
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
|
||||
val mapIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, mapIntent)
|
||||
} else {
|
||||
val pIntentDetail = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(
|
||||
context,
|
||||
nextEvent,
|
||||
forceEventDetails = true
|
||||
),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, pIntentDetail)
|
||||
}
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.next_event_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = 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.weather_sub_line_rect, View.VISIBLE)
|
||||
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_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
var showSomething = false
|
||||
loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
if (MediaPlayerHelper.isSomeonePlaying(context)) {
|
||||
val musicIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getMusicIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, musicIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
if (Preferences.showNextAlarm && nextAlarm != "") {
|
||||
val alarmIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getClockIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, alarmIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging || Preferences.isBatteryLevelLow) {
|
||||
val batteryIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getBatteryIntent(),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, batteryIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
if (Preferences.customNotes.isNotEmpty()) {
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
|
||||
val fitIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getFitIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.sub_line_rect, fitIntent)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||
try {
|
||||
if (Preferences.lastNotificationIcon != 0) {
|
||||
val remotePackageContext = context.createPackageContext(
|
||||
Preferences.lastNotificationPackage, 0)
|
||||
ContextCompat.getDrawable(
|
||||
remotePackageContext,
|
||||
Preferences.lastNotificationIcon)
|
||||
}
|
||||
val notificationIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getNotificationIntent(context),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.sub_line_rect,
|
||||
notificationIntent
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
} catch (ex: Exception) {}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
if (Preferences.showGreetings && GreetingsHelper.showGreetings() && GreetingsHelper.getRandomString(context).isNotBlank()) {
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.EVENTS -> {
|
||||
if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR) && nextEvent != null) {
|
||||
val pIntentDetail = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(
|
||||
context,
|
||||
nextEvent,
|
||||
forceEventDetails = true
|
||||
),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.sub_line_rect,
|
||||
pIntentDetail
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (showSomething) {
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE)
|
||||
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
|
||||
} else {
|
||||
// Spacing
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
}
|
||||
}
|
||||
|
||||
// Second row
|
||||
views.setImageViewBitmap(
|
||||
R.id.sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false)
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
} finally {
|
||||
eventRepository.close()
|
||||
}
|
||||
|
||||
return views
|
||||
}
|
||||
|
||||
|
||||
// Generates the widget bitmap from the view
|
||||
fun generateWidgetView(typeface: Typeface? = null): LeftAlignedWidgetBinding {
|
||||
val eventRepository = EventRepository(context)
|
||||
val bindingView = LeftAlignedWidgetBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
bindingView.loader.isVisible = false
|
||||
|
||||
// Weather
|
||||
if (Preferences.showWeather && Preferences.weatherIcon != "") {
|
||||
bindingView.weatherDateLine.isVisible = true
|
||||
val currentTemp = String.format(
|
||||
Locale.getDefault(),
|
||||
"%d°%s",
|
||||
Preferences.weatherTemp.roundToInt(),
|
||||
Preferences.weatherRealTempUnit
|
||||
)
|
||||
|
||||
val icon: String = Preferences.weatherIcon
|
||||
if (icon == "") {
|
||||
bindingView.weatherSubLineWeatherIcon.isVisible = false
|
||||
bindingView.weatherDateLineWeatherIcon.isVisible = false
|
||||
} else {
|
||||
bindingView.weatherSubLineWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
|
||||
bindingView.weatherDateLineWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
|
||||
bindingView.weatherSubLineWeatherIcon.isVisible = true
|
||||
bindingView.weatherDateLineWeatherIcon.isVisible = true
|
||||
}
|
||||
|
||||
bindingView.weatherDateLineTemperature.text = currentTemp
|
||||
bindingView.weatherSubLineTemperature.text = currentTemp
|
||||
|
||||
if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
}
|
||||
} else {
|
||||
bindingView.weatherDateLine.isVisible = false
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
}
|
||||
|
||||
val now = Calendar.getInstance().apply {
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
|
||||
bindingView.dateLayout.isVisible = true
|
||||
bindingView.calendarLayout.isVisible = false
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
bindingView.actionNext.isVisible = false
|
||||
|
||||
bindingView.date.text = DateHelper.getDateText(context, now)
|
||||
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val nextAlarm = AlarmHelper.getNextAlarm(context)
|
||||
|
||||
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
|
||||
// Multiple counter
|
||||
bindingView.actionNext.isVisible =
|
||||
Preferences.showNextEvent && eventRepository.getEventsCount() > 1
|
||||
|
||||
bindingView.nextEvent.text = nextEvent.title
|
||||
|
||||
if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
|
||||
bindingView.nextEventDifferenceTime.text = if (!nextEvent.allDay) {
|
||||
SettingsStringHelper.getDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
)
|
||||
.toLowerCase(Locale.getDefault())
|
||||
} else {
|
||||
SettingsStringHelper.getAllDayEventDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
).toLowerCase(Locale.getDefault())
|
||||
}
|
||||
bindingView.nextEventDifferenceTime.isVisible = true
|
||||
} else {
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
}
|
||||
|
||||
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_place_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = nextEvent.address
|
||||
} else {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_today_24
|
||||
)
|
||||
)
|
||||
if (!nextEvent.allDay) {
|
||||
val startHour =
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
|
||||
.format(nextEvent.startDate)
|
||||
val endHour =
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
|
||||
.format(nextEvent.endDate)
|
||||
|
||||
var dayDiff =
|
||||
TimeUnit.MILLISECONDS.toDays(nextEvent.endDate - nextEvent.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
startCal.timeInMillis = nextEvent.startDate
|
||||
|
||||
val endCal = Calendar.getInstance()
|
||||
endCal.timeInMillis = nextEvent.endDate
|
||||
|
||||
if (startCal.get(Calendar.HOUR_OF_DAY) > endCal.get(Calendar.HOUR_OF_DAY)) {
|
||||
dayDiff++
|
||||
} else if (startCal.get(Calendar.HOUR_OF_DAY) == endCal.get(Calendar.HOUR_OF_DAY) && startCal.get(
|
||||
Calendar.MINUTE
|
||||
) > endCal.get(Calendar.MINUTE)
|
||||
) {
|
||||
dayDiff++
|
||||
}
|
||||
var multipleDay = ""
|
||||
if (dayDiff > 0) {
|
||||
multipleDay = String.format(
|
||||
" (+%s%s)",
|
||||
dayDiff,
|
||||
context.getString(R.string.day_char)
|
||||
)
|
||||
}
|
||||
|
||||
if (nextEvent.startDate != nextEvent.endDate) {
|
||||
bindingView.subLineText.text =
|
||||
String.format("%s - %s%s", startHour, endHour, multipleDay)
|
||||
} else {
|
||||
bindingView.subLineText.text =
|
||||
String.format("%s", startHour)
|
||||
}
|
||||
|
||||
} 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 }
|
||||
|
||||
bindingView.subLineText.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(
|
||||
Calendar.DAY_OF_YEAR)) {
|
||||
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
|
||||
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(
|
||||
Calendar.YEAR) > start.get(Calendar.YEAR)) {
|
||||
DateUtils.formatDateTime(context, now.timeInMillis, flags)
|
||||
} else {
|
||||
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bindingView.dateLayout.isVisible = false
|
||||
bindingView.calendarLayout.isVisible = true
|
||||
bindingView.subLine.isVisible = true
|
||||
bindingView.weatherSubLine.isVisible = true
|
||||
|
||||
bindingView.subLineTopMarginSmall.visibility = View.GONE
|
||||
bindingView.subLineTopMarginMedium.visibility = View.GONE
|
||||
bindingView.subLineTopMarginLarge.visibility = View.GONE
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
var showSomething = false
|
||||
loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(
|
||||
context
|
||||
)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
if (MediaPlayerHelper.isSomeonePlaying(context)) {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_music_note_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = MediaPlayerHelper.getMediaInfo()
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
if (Preferences.showNextAlarm && nextAlarm != "") {
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_alarm_24
|
||||
)
|
||||
)
|
||||
bindingView.subLineText.text = AlarmHelper.getNextAlarm(context)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
val batteryLevel = BatteryHelper.getBatteryLevel(context)
|
||||
if (batteryLevel != 100) {
|
||||
bindingView.subLineText.text = context.getString(R.string.charging)
|
||||
} else {
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.charged)
|
||||
}
|
||||
showSomething = true
|
||||
break@loop
|
||||
} else if (Preferences.isBatteryLevelLow) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.battery_low_warning)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
if (Preferences.customNotes.isNotEmpty()) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text = Preferences.customNotes
|
||||
bindingView.subLineText.maxLines = 2
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
bindingView.subLineText.text =
|
||||
context.getString(R.string.daily_steps_counter)
|
||||
.format(Preferences.googleFitSteps)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||
try {
|
||||
if (Preferences.lastNotificationIcon != 0) {
|
||||
val remotePackageContext = context.createPackageContext(
|
||||
Preferences.lastNotificationPackage, 0)
|
||||
val icon = ContextCompat.getDrawable(remotePackageContext,
|
||||
Preferences.lastNotificationIcon)
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
bindingView.subLineIcon.setImageDrawable(icon)
|
||||
} else {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
}
|
||||
bindingView.subLineText.text = Preferences.lastNotificationTitle
|
||||
showSomething = true
|
||||
break@loop
|
||||
} catch (ex: Exception) {}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
val greetingsText = GreetingsHelper.getRandomString(context)
|
||||
if (Preferences.showGreetings && GreetingsHelper.showGreetings() && greetingsText.isNotBlank()) {
|
||||
bindingView.subLineText.text = greetingsText
|
||||
bindingView.subLineText.maxLines = 2
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.EVENTS -> {
|
||||
if (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR) && nextEvent != null) {
|
||||
bindingView.subLineText.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
|
||||
if (!nextEvent.allDay) {
|
||||
SettingsStringHelper.getDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
)
|
||||
.toLowerCase(Locale.getDefault())
|
||||
} else {
|
||||
SettingsStringHelper.getAllDayEventDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
nextEvent.startDate
|
||||
).toLowerCase(Locale.getDefault())
|
||||
}
|
||||
} else "").trimEnd()
|
||||
bindingView.subLineIcon.isVisible = true
|
||||
bindingView.subLineIcon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_today_24
|
||||
)
|
||||
)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showSomething) {
|
||||
bindingView.dateLayout.isVisible = true
|
||||
bindingView.calendarLayout.isVisible = false
|
||||
bindingView.subLine.isVisible = true
|
||||
bindingView.weatherSubLine.isVisible = false
|
||||
|
||||
bindingView.subLineTopMarginSmall.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE
|
||||
bindingView.subLineTopMarginMedium.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.rawValue) View.VISIBLE else View.GONE
|
||||
bindingView.subLineTopMarginLarge.visibility =
|
||||
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.rawValue) View.VISIBLE else View.GONE
|
||||
} else {
|
||||
bindingView.subLineIcon.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Color
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
).forEach {
|
||||
it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme()))
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.rawValue) {
|
||||
listOf<ImageView>(bindingView.actionNext)
|
||||
} else {
|
||||
listOf<ImageView>(
|
||||
bindingView.actionNext,
|
||||
bindingView.weatherDateLineWeatherIcon,
|
||||
bindingView.weatherSubLineWeatherIcon
|
||||
)
|
||||
}.forEach {
|
||||
it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme()))
|
||||
it.alpha =
|
||||
(if (context.isDarkTheme()) Preferences.textGlobalAlphaDark.toIntValue()
|
||||
.toFloat() else Preferences.textGlobalAlpha.toIntValue()
|
||||
.toFloat()) / 100
|
||||
}
|
||||
|
||||
listOf<TextView>(bindingView.subLineText, bindingView.weatherSubLineDivider, bindingView.weatherSubLineTemperature).forEach {
|
||||
it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme()))
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.rawValue) {
|
||||
listOf<ImageView>(bindingView.subLineIcon, bindingView.subLineIconShadow)
|
||||
} else {
|
||||
listOf<ImageView>(bindingView.subLineIcon, bindingView.weatherSubLineWeatherIcon, bindingView.subLineIconShadow)
|
||||
}.forEach {
|
||||
it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme()))
|
||||
it.alpha =
|
||||
(if (context.isDarkTheme()) Preferences.textSecondaryAlphaDark.toIntValue()
|
||||
.toFloat() else Preferences.textSecondaryAlpha.toIntValue()
|
||||
.toFloat()) / 100
|
||||
}
|
||||
|
||||
// Text Size
|
||||
listOf<Pair<TextView, Float>>(
|
||||
bindingView.date to Preferences.textMainSize,
|
||||
bindingView.weatherDateLineTemperature to ((Preferences.textMainSize + Preferences.textSecondSize) / 2),
|
||||
bindingView.nextEvent to Preferences.textMainSize,
|
||||
bindingView.nextEventDifferenceTime to Preferences.textMainSize,
|
||||
bindingView.subLineText to Preferences.textSecondSize,
|
||||
bindingView.weatherSubLineDivider to (Preferences.textSecondSize - 2),
|
||||
bindingView.weatherSubLineTemperature to Preferences.textSecondSize,
|
||||
).forEach {
|
||||
it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second)
|
||||
}
|
||||
|
||||
// Icons scale
|
||||
bindingView.subLineIcon.scaleX = Preferences.textSecondSize / 18f
|
||||
bindingView.subLineIcon.scaleY = Preferences.textSecondSize / 18f
|
||||
|
||||
bindingView.weatherSubLineWeatherIcon.scaleX = Preferences.textSecondSize / 18f
|
||||
bindingView.weatherSubLineWeatherIcon.scaleY = Preferences.textSecondSize / 18f
|
||||
|
||||
bindingView.weatherDateLineWeatherIcon.scaleX = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f
|
||||
bindingView.weatherDateLineWeatherIcon.scaleY = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f
|
||||
|
||||
bindingView.actionNext.scaleX = Preferences.textMainSize / 28f
|
||||
bindingView.actionNext.scaleY = Preferences.textMainSize / 28f
|
||||
|
||||
|
||||
// Shadows
|
||||
val shadowRadius =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
2 -> 5f
|
||||
else -> 5f
|
||||
}
|
||||
val shadowColor =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> Color.TRANSPARENT
|
||||
1 -> R.color.black_50
|
||||
2 -> Color.BLACK
|
||||
else -> R.color.black_50
|
||||
}
|
||||
val shadowDy =
|
||||
when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
|
||||
0 -> 0f
|
||||
1 -> 0f
|
||||
2 -> 1f
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
}
|
||||
|
||||
// Icons shadow
|
||||
|
||||
listOf(
|
||||
Pair(bindingView.subLineIcon, bindingView.subLineIconShadow),
|
||||
).forEach {
|
||||
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
|
||||
it.second.isVisible = false
|
||||
} else {
|
||||
it.second.isVisible = it.first.isVisible
|
||||
it.second.scaleX = it.first.scaleX
|
||||
it.second.scaleY = it.first.scaleY
|
||||
it.second.applyShadow(it.first)
|
||||
}
|
||||
}
|
||||
|
||||
listOf(
|
||||
Pair(bindingView.actionNext, bindingView.actionNextShadow),
|
||||
).forEach {
|
||||
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
|
||||
it.second.isVisible = false
|
||||
} else {
|
||||
it.second.isVisible = it.first.isVisible
|
||||
it.second.scaleX = it.first.scaleX
|
||||
it.second.scaleY = it.first.scaleY
|
||||
it.second.applyShadow(it.first, 0.6f)
|
||||
}
|
||||
}
|
||||
|
||||
// Custom Font
|
||||
if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) {
|
||||
val googleSans: Typeface = when (Preferences.customFontVariant) {
|
||||
"100" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_thin.ttf")
|
||||
"200" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_light.ttf")
|
||||
"500" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_medium.ttf")
|
||||
"700" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_bold.ttf")
|
||||
"800" -> Typeface.createFromAsset(context.assets, "fonts/google_sans_black.ttf")
|
||||
else -> Typeface.createFromAsset(context.assets, "fonts/google_sans_regular.ttf")
|
||||
}
|
||||
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.typeface = googleSans
|
||||
}
|
||||
} else if (Preferences.customFont == Constants.CUSTOM_FONT_DOWNLOADED && typeface != null) {
|
||||
listOf<TextView>(
|
||||
bindingView.date,
|
||||
bindingView.weatherDateLineTemperature,
|
||||
bindingView.nextEvent,
|
||||
bindingView.nextEventDifferenceTime,
|
||||
bindingView.subLineText,
|
||||
bindingView.weatherSubLineDivider,
|
||||
bindingView.weatherSubLineTemperature,
|
||||
).forEach {
|
||||
it.typeface = typeface
|
||||
}
|
||||
}
|
||||
|
||||
// Dividers
|
||||
arrayOf(bindingView.weatherSubLineDivider).forEach {
|
||||
it.visibility = if (Preferences.showDividers) View.VISIBLE else View.INVISIBLE
|
||||
it.layoutParams = (it.layoutParams as ViewGroup.MarginLayoutParams).apply {
|
||||
this.marginEnd = if (Preferences.showDividers) 8f.convertDpToPixel(context).toInt() else 0
|
||||
}
|
||||
}
|
||||
|
||||
eventRepository.close()
|
||||
|
||||
return bindingView
|
||||
}
|
||||
}
|
@ -1,47 +1,20 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.widgets
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.databinding.LeftAlignedWidgetBinding
|
||||
import com.tommasoberlose.anotherwidget.databinding.TheWidgetBinding
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ImageHelper.applyShadow
|
||||
import com.tommasoberlose.anotherwidget.receivers.*
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.convertDpToPixel
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.lang.Exception
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
class MainWidget : AppWidgetProvider() {
|
||||
@ -98,16 +71,22 @@ class MainWidget : AppWidgetProvider() {
|
||||
|
||||
WidgetHelper.runWithCustomTypeface(context) {
|
||||
val views = when (Preferences.widgetAlign) {
|
||||
Constants.WidgetAlign.LEFT.rawValue -> LeftAlignedWidget(context).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it)
|
||||
Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(context, rightAligned = true).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it)
|
||||
else -> StandardWidget(context).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it)
|
||||
}
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
try {
|
||||
if (views != null) appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getWidgetView(context: Context, typeface: Typeface?): ViewBinding {
|
||||
fun getWidgetView(context: Context, typeface: Typeface?): ViewBinding? {
|
||||
return when (Preferences.widgetAlign) {
|
||||
Constants.WidgetAlign.LEFT.rawValue -> LeftAlignedWidget(context).generateWidgetView(typeface)
|
||||
Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidgetView(typeface)
|
||||
Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(context, rightAligned = true).generateWidgetView(typeface)
|
||||
else -> StandardWidget(context).generateWidgetView(typeface)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.graphics.Typeface
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -40,7 +41,7 @@ import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class StandardWidget(val context: Context) {
|
||||
fun generateWidget(appWidgetId: Int, w: Int, typeface: Typeface? = null): RemoteViews {
|
||||
fun generateWidget(appWidgetId: Int, w: Int, typeface: Typeface? = null): RemoteViews? {
|
||||
|
||||
var views = RemoteViews(context.packageName, R.layout.the_widget_sans)
|
||||
|
||||
@ -73,7 +74,8 @@ class StandardWidget(val context: Context) {
|
||||
|
||||
// Setup listener
|
||||
try {
|
||||
val generatedBinding = generateWidgetView(typeface)
|
||||
val generatedBinding = generateWidgetView(typeface) ?: return null
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.bitmap_container,
|
||||
BitmapHelper.getBitmapFromView(generatedBinding.root, width = w)
|
||||
@ -88,8 +90,12 @@ class StandardWidget(val context: Context) {
|
||||
}
|
||||
|
||||
private fun updateGridView(bindingView: TheWidgetBinding, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val eventRepository = EventRepository(context)
|
||||
try {
|
||||
val eventRepository = EventRepository(context)
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val eventsCount = eventRepository.getEventsCount()
|
||||
eventRepository.close()
|
||||
|
||||
// Weather
|
||||
if (Preferences.showWeather && Preferences.weatherIcon != "") {
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
@ -104,12 +110,12 @@ class StandardWidget(val context: Context) {
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherDateLine, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherDateLine, draw = false, width = bindingView.weatherDateLine.width, height = bindingView.weatherDateLine.height)
|
||||
)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.weather_sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherSubLine, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.weatherSubLine, draw = false, width = bindingView.weatherSubLine.width, height = bindingView.weatherSubLine.height)
|
||||
)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.weather_rect, View.GONE)
|
||||
@ -120,7 +126,7 @@ class StandardWidget(val context: Context) {
|
||||
// Calendar
|
||||
views.setImageViewBitmap(
|
||||
R.id.date_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.date, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.date, draw = false, width = bindingView.date.width, height = bindingView.date.height)
|
||||
)
|
||||
|
||||
val calPIntent = PendingIntent.getActivity(
|
||||
@ -135,10 +141,9 @@ class StandardWidget(val context: Context) {
|
||||
// Second row
|
||||
views.setImageViewBitmap(
|
||||
R.id.sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false, width = bindingView.subLine.width, height = bindingView.subLine.height)
|
||||
)
|
||||
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val nextAlarm = AlarmHelper.getNextAlarm(context)
|
||||
|
||||
// Spacing
|
||||
@ -156,12 +161,12 @@ class StandardWidget(val context: Context) {
|
||||
)
|
||||
|
||||
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
|
||||
if (Preferences.showNextEvent && eventRepository.getEventsCount() > 1) {
|
||||
if (Preferences.showNextEvent && eventsCount > 1) {
|
||||
|
||||
// Action next event
|
||||
views.setImageViewBitmap(
|
||||
R.id.action_next_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionNext, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionNext, draw = false, width = bindingView.actionNext.width, height = bindingView.actionNext.height)
|
||||
)
|
||||
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
|
||||
views.setOnClickPendingIntent(
|
||||
@ -180,7 +185,7 @@ class StandardWidget(val context: Context) {
|
||||
// Action previous event
|
||||
views.setImageViewBitmap(
|
||||
R.id.action_previous_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionPrevious, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.actionPrevious, draw = false, width = bindingView.actionPrevious.width, height = bindingView.actionPrevious.height)
|
||||
)
|
||||
views.setViewVisibility(R.id.action_previous_rect, View.VISIBLE)
|
||||
views.setOnClickPendingIntent(
|
||||
@ -219,11 +224,18 @@ class StandardWidget(val context: Context) {
|
||||
R.id.next_event_difference_time_rect,
|
||||
BitmapHelper.getBitmapFromView(
|
||||
bindingView.nextEventDifferenceTime,
|
||||
draw = false
|
||||
draw = false,
|
||||
width = bindingView.nextEventDifferenceTime.width,
|
||||
height = bindingView.nextEventDifferenceTime.height
|
||||
)
|
||||
)
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.VISIBLE)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time_rect, eventIntent)
|
||||
if (!Preferences.showNextEventOnMultipleLines) {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.GONE)
|
||||
}
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time_rect, View.GONE)
|
||||
}
|
||||
@ -253,7 +265,7 @@ class StandardWidget(val context: Context) {
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.next_event_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = false, width = bindingView.nextEvent.width, height = bindingView.nextEvent.height)
|
||||
)
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE)
|
||||
@ -384,7 +396,7 @@ class StandardWidget(val context: Context) {
|
||||
if (showSomething) {
|
||||
views.setImageViewBitmap(
|
||||
R.id.sub_line_rect,
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false)
|
||||
BitmapHelper.getBitmapFromView(bindingView.subLine, draw = false, width = bindingView.subLine.width, height = bindingView.subLine.height)
|
||||
)
|
||||
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
@ -398,12 +410,21 @@ class StandardWidget(val context: Context) {
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
}
|
||||
} else {
|
||||
views.setViewVisibility(R.id.first_line_rect, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
|
||||
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.weather_sub_line_rect, View.GONE)
|
||||
// Spacing
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE)
|
||||
views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
} finally {
|
||||
eventRepository.close()
|
||||
}
|
||||
|
||||
return views
|
||||
@ -411,8 +432,13 @@ class StandardWidget(val context: Context) {
|
||||
|
||||
|
||||
// Generates the widget bitmap from the view
|
||||
fun generateWidgetView(typeface: Typeface? = null): TheWidgetBinding {
|
||||
fun generateWidgetView(typeface: Typeface? = null): TheWidgetBinding? {
|
||||
try {
|
||||
val eventRepository = EventRepository(context)
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val eventsCount = eventRepository.getEventsCount()
|
||||
eventRepository.close()
|
||||
|
||||
val bindingView = TheWidgetBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
bindingView.loader.isVisible = false
|
||||
@ -462,20 +488,27 @@ class StandardWidget(val context: Context) {
|
||||
|
||||
bindingView.date.text = DateHelper.getDateText(context, now)
|
||||
|
||||
val nextEvent = eventRepository.getNextEvent()
|
||||
val nextAlarm = AlarmHelper.getNextAlarm(context)
|
||||
|
||||
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
|
||||
// Multiple counter
|
||||
bindingView.actionNext.isVisible =
|
||||
Preferences.showNextEvent && eventRepository.getEventsCount() > 1
|
||||
Preferences.showNextEvent && eventsCount > 1
|
||||
bindingView.actionPrevious.isVisible =
|
||||
Preferences.showNextEvent && eventRepository.getEventsCount() > 1
|
||||
Preferences.showNextEvent && eventsCount > 1
|
||||
|
||||
bindingView.nextEvent.text = nextEvent.title
|
||||
|
||||
if (Preferences.showNextEventOnMultipleLines) {
|
||||
bindingView.nextEvent.apply {
|
||||
isSingleLine = false
|
||||
maxLines = 3
|
||||
gravity = Gravity.CENTER
|
||||
}
|
||||
}
|
||||
|
||||
if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
|
||||
bindingView.nextEventDifferenceTime.text = if (!nextEvent.allDay) {
|
||||
val diffTime = if (!nextEvent.allDay) {
|
||||
SettingsStringHelper.getDifferenceText(
|
||||
context,
|
||||
now.timeInMillis,
|
||||
@ -489,7 +522,14 @@ class StandardWidget(val context: Context) {
|
||||
nextEvent.startDate
|
||||
).toLowerCase(Locale.getDefault())
|
||||
}
|
||||
bindingView.nextEventDifferenceTime.text = diffTime
|
||||
|
||||
if (!Preferences.showNextEventOnMultipleLines) {
|
||||
bindingView.nextEventDifferenceTime.isVisible = true
|
||||
} else {
|
||||
bindingView.nextEvent.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, diffTime)
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
}
|
||||
} else {
|
||||
bindingView.nextEventDifferenceTime.isVisible = false
|
||||
}
|
||||
@ -923,8 +963,13 @@ class StandardWidget(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
eventRepository.close()
|
||||
|
||||
return bindingView
|
||||
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
@ -265,3 +265,11 @@ fun View.setOnSingleClickListener(l: View.OnClickListener) {
|
||||
fun View.setOnSingleClickListener(l: (View) -> Unit) {
|
||||
setOnClickListener(OnSingleClickListener(l))
|
||||
}
|
||||
|
||||
fun ignoreExceptions(function: () -> Unit) = run {
|
||||
try {
|
||||
function.invoke()
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 674 B After Width: | Height: | Size: 750 B |
BIN
app/src/main/res/drawable-hdpi/round_more_time_white_18.png
Normal file
After Width: | Height: | Size: 428 B |
BIN
app/src/main/res/drawable-hdpi/round_more_time_white_20.png
Normal file
After Width: | Height: | Size: 448 B |
BIN
app/src/main/res/drawable-hdpi/round_more_time_white_24.png
Normal file
After Width: | Height: | Size: 436 B |
BIN
app/src/main/res/drawable-hdpi/round_more_time_white_36.png
Normal file
After Width: | Height: | Size: 779 B |
BIN
app/src/main/res/drawable-hdpi/round_more_time_white_48.png
Normal file
After Width: | Height: | Size: 867 B |
BIN
app/src/main/res/drawable-hdpi/round_subtitles_white_18.png
Normal file
After Width: | Height: | Size: 224 B |
BIN
app/src/main/res/drawable-hdpi/round_subtitles_white_20.png
Normal file
After Width: | Height: | Size: 195 B |
BIN
app/src/main/res/drawable-hdpi/round_subtitles_white_24.png
Normal file
After Width: | Height: | Size: 170 B |
BIN
app/src/main/res/drawable-hdpi/round_subtitles_white_36.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
app/src/main/res/drawable-hdpi/round_subtitles_white_48.png
Normal file
After Width: | Height: | Size: 267 B |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 381 B After Width: | Height: | Size: 563 B |
BIN
app/src/main/res/drawable-mdpi/round_more_time_white_18.png
Normal file
After Width: | Height: | Size: 261 B |
BIN
app/src/main/res/drawable-mdpi/round_more_time_white_20.png
Normal file
After Width: | Height: | Size: 213 B |
BIN
app/src/main/res/drawable-mdpi/round_more_time_white_24.png
Normal file
After Width: | Height: | Size: 288 B |
BIN
app/src/main/res/drawable-mdpi/round_more_time_white_36.png
Normal file
After Width: | Height: | Size: 436 B |
BIN
app/src/main/res/drawable-mdpi/round_more_time_white_48.png
Normal file
After Width: | Height: | Size: 564 B |
BIN
app/src/main/res/drawable-mdpi/round_subtitles_white_18.png
Normal file
After Width: | Height: | Size: 160 B |
BIN
app/src/main/res/drawable-mdpi/round_subtitles_white_20.png
Normal file
After Width: | Height: | Size: 141 B |
BIN
app/src/main/res/drawable-mdpi/round_subtitles_white_24.png
Normal file
After Width: | Height: | Size: 123 B |
BIN
app/src/main/res/drawable-mdpi/round_subtitles_white_36.png
Normal file
After Width: | Height: | Size: 170 B |
BIN
app/src/main/res/drawable-mdpi/round_subtitles_white_48.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
app/src/main/res/drawable-night-hdpi/round_more_time_24.png
Normal file
After Width: | Height: | Size: 445 B |
BIN
app/src/main/res/drawable-night-hdpi/round_subtitles_24.png
Normal file
After Width: | Height: | Size: 178 B |
BIN
app/src/main/res/drawable-night-mdpi/round_more_time_24.png
Normal file
After Width: | Height: | Size: 295 B |
BIN
app/src/main/res/drawable-night-mdpi/round_subtitles_24.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
app/src/main/res/drawable-night-xhdpi/round_more_time_24.png
Normal file
After Width: | Height: | Size: 566 B |
BIN
app/src/main/res/drawable-night-xhdpi/round_subtitles_24.png
Normal file
After Width: | Height: | Size: 205 B |
BIN
app/src/main/res/drawable-night-xxhdpi/round_more_time_24.png
Normal file
After Width: | Height: | Size: 871 B |
BIN
app/src/main/res/drawable-night-xxhdpi/round_subtitles_24.png
Normal file
After Width: | Height: | Size: 288 B |
BIN
app/src/main/res/drawable-night-xxxhdpi/round_more_time_24.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-night-xxxhdpi/round_subtitles_24.png
Normal file
After Width: | Height: | Size: 352 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 796 B After Width: | Height: | Size: 1.2 KiB |
BIN
app/src/main/res/drawable-xhdpi/round_more_time_white_18.png
Normal file
After Width: | Height: | Size: 436 B |
BIN
app/src/main/res/drawable-xhdpi/round_more_time_white_20.png
Normal file
After Width: | Height: | Size: 371 B |
BIN
app/src/main/res/drawable-xhdpi/round_more_time_white_24.png
Normal file
After Width: | Height: | Size: 564 B |
BIN
app/src/main/res/drawable-xhdpi/round_more_time_white_36.png
Normal file
After Width: | Height: | Size: 867 B |
BIN
app/src/main/res/drawable-xhdpi/round_more_time_white_48.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xhdpi/round_subtitles_white_18.png
Normal file
After Width: | Height: | Size: 170 B |
BIN
app/src/main/res/drawable-xhdpi/round_subtitles_white_20.png
Normal file
After Width: | Height: | Size: 183 B |
BIN
app/src/main/res/drawable-xhdpi/round_subtitles_white_24.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
app/src/main/res/drawable-xhdpi/round_subtitles_white_36.png
Normal file
After Width: | Height: | Size: 267 B |
BIN
app/src/main/res/drawable-xhdpi/round_subtitles_white_48.png
Normal file
After Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_more_time_white_18.png
Normal file
After Width: | Height: | Size: 779 B |
BIN
app/src/main/res/drawable-xxhdpi/round_more_time_white_20.png
Normal file
After Width: | Height: | Size: 590 B |
BIN
app/src/main/res/drawable-xxhdpi/round_more_time_white_24.png
Normal file
After Width: | Height: | Size: 867 B |
BIN
app/src/main/res/drawable-xxhdpi/round_more_time_white_36.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_more_time_white_48.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_subtitles_white_18.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
app/src/main/res/drawable-xxhdpi/round_subtitles_white_20.png
Normal file
After Width: | Height: | Size: 288 B |
BIN
app/src/main/res/drawable-xxhdpi/round_subtitles_white_24.png
Normal file
After Width: | Height: | Size: 267 B |
BIN
app/src/main/res/drawable-xxhdpi/round_subtitles_white_36.png
Normal file
After Width: | Height: | Size: 398 B |
BIN
app/src/main/res/drawable-xxhdpi/round_subtitles_white_48.png
Normal file
After Width: | Height: | Size: 518 B |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_more_time_white_18.png
Normal file
After Width: | Height: | Size: 867 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_more_time_white_20.png
Normal file
After Width: | Height: | Size: 791 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_more_time_white_24.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_more_time_white_36.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_more_time_white_48.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_subtitles_white_18.png
Normal file
After Width: | Height: | Size: 267 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_subtitles_white_20.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_subtitles_white_24.png
Normal file
After Width: | Height: | Size: 344 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_subtitles_white_36.png
Normal file
After Width: | Height: | Size: 518 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_subtitles_white_48.png
Normal file
After Width: | Height: | Size: 674 B |
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:color="@color/colorAccent_op30" />
|
||||
<item android:state_selected="true" android:color="@color/colorAccent_op10" />
|
||||
<item android:color="@color/colorPrimary" />
|
||||
</selector>
|
16
app/src/main/res/drawable/round_more_time_20.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<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="M8.5,8.53v3.24c0,0.18 0.09,0.34 0.24,0.43l2.52,1.51c0.23,0.14 0.52,0.06 0.66,-0.16l0,0c0.14,-0.23 0.06,-0.53 -0.16,-0.66L9.5,11.55V8.53c0,-0.26 -0.21,-0.48 -0.48,-0.48H8.98C8.71,8.05 8.5,8.26 8.5,8.53z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M13.9,10c0.07,0.32 0.1,0.66 0.1,1c0,2.76 -2.24,5 -5,5s-5,-2.24 -5,-5s2.24,-5 5,-5c0.71,0 1.39,0.15 2,0.42V5.35C10.37,5.13 9.7,5 9,5c-3.31,0 -6,2.69 -6,6s2.69,6 6,6s6,-2.69 6,-6c0,-0.34 -0.04,-0.67 -0.09,-1H13.9z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15,6V4.5C15,4.22 14.78,4 14.5,4h0C14.22,4 14,4.22 14,4.5V6h0h-1.5C12.22,6 12,6.22 12,6.5v0C12,6.78 12.22,7 12.5,7H14v1.5C14,8.78 14.22,9 14.5,9h0C14.78,9 15,8.78 15,8.5V7v0h1.5C16.78,7 17,6.78 17,6.5v0C17,6.22 16.78,6 16.5,6H15z"/>
|
||||
</vector>
|