use rounded widget background

This commit is contained in:
tibbi 2020-05-24 23:04:16 +02:00
parent fc373024bf
commit 0204369302
4 changed files with 44 additions and 13 deletions

View File

@ -13,8 +13,8 @@ import com.simplemobiletools.calculator.extensions.config
import com.simplemobiletools.calculator.helpers.MyWidgetProvider import com.simplemobiletools.calculator.helpers.MyWidgetProvider
import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisible import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setFillWithStroke import com.simplemobiletools.commons.extensions.setFillWithStroke
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -65,8 +65,10 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun saveConfig() { private fun saveConfig() {
val appWidgetManager = AppWidgetManager.getInstance(this) val appWidgetManager = AppWidgetManager.getInstance(this)
val views = RemoteViews(packageName, R.layout.activity_main) val views = RemoteViews(packageName, R.layout.widget).apply {
views.setBackgroundColor(R.id.calculator_holder, mBgColor) applyColorFilter(R.id.widget_background, mBgColor)
}
appWidgetManager.updateAppWidget(mWidgetId, views) appWidgetManager.updateAppWidget(mWidgetId, views)
storeWidgetColors() storeWidgetColors()
@ -95,7 +97,7 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun updateBackgroundColor() { private fun updateBackgroundColor() {
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha) mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
config_calc.setBackgroundColor(mBgColor) widget_background.applyColorFilter(mBgColor)
config_save.setBackgroundColor(mBgColor) config_save.setBackgroundColor(mBgColor)
config_bg_color.setFillWithStroke(mBgColor, Color.BLACK) config_bg_color.setFillWithStroke(mBgColor, Color.BLACK)
} }

View File

@ -11,6 +11,7 @@ import android.widget.RemoteViews
import com.simplemobiletools.calculator.R import com.simplemobiletools.calculator.R
import com.simplemobiletools.calculator.activities.MainActivity import com.simplemobiletools.calculator.activities.MainActivity
import com.simplemobiletools.calculator.extensions.config import com.simplemobiletools.calculator.extensions.config
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.setBackgroundColor import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setText import com.simplemobiletools.commons.extensions.setText
@ -20,14 +21,9 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
} }
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
performUpdate(context)
}
private fun performUpdate(context: Context) {
val config = context.config val config = context.config
val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.activity_main) val views = RemoteViews(context.packageName, R.layout.widget)
setupIntent(context, views, DECIMAL, R.id.btn_decimal) setupIntent(context, views, DECIMAL, R.id.btn_decimal)
setupIntent(context, views, ZERO, R.id.btn_0) setupIntent(context, views, ZERO, R.id.btn_0)
setupIntent(context, views, ONE, R.id.btn_1) setupIntent(context, views, ONE, R.id.btn_1)
@ -55,7 +51,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
setupAppOpenIntent(context, views, R.id.result) setupAppOpenIntent(context, views, R.id.result)
views.setViewVisibility(R.id.btn_reset, View.VISIBLE) views.setViewVisibility(R.id.btn_reset, View.VISIBLE)
views.setBackgroundColor(R.id.calculator_holder, config.widgetBgColor) views.applyColorFilter(R.id.widget_background, config.widgetBgColor)
updateTextColors(views, config.widgetTextColor) updateTextColors(views, config.widgetTextColor)
appWidgetManager.updateAppWidget(it, views) appWidgetManager.updateAppWidget(it, views)
@ -123,7 +119,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
override fun setValue(value: String, context: Context) { override fun setValue(value: String, context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.activity_main) val views = RemoteViews(context.packageName, R.layout.widget)
views.setText(R.id.result, value) views.setText(R.id.result, value)
appWidgetManager.partiallyUpdateAppWidget(it, views) appWidgetManager.partiallyUpdateAppWidget(it, views)
} }
@ -135,7 +131,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
override fun setFormula(value: String, context: Context) { override fun setFormula(value: String, context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.activity_main) val views = RemoteViews(context.packageName, R.layout.widget)
views.setText(R.id.formula, value) views.setText(R.id.formula, value)
appWidgetManager.partiallyUpdateAppWidget(it, views) appWidgetManager.partiallyUpdateAppWidget(it, views)
} }

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/widget_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/widget_content_holder"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:src="@drawable/widget_round_background" />
<include
android:id="@+id/widget_content_holder"
layout="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@ -6,6 +6,16 @@
android:layout_margin="@dimen/activity_margin" android:layout_margin="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin"> android:paddingBottom="@dimen/activity_margin">
<ImageView
android:id="@+id/widget_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/config_calc"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:src="@drawable/widget_round_background" />
<include <include
android:id="@+id/config_calc" android:id="@+id/config_calc"
layout="@layout/activity_main" layout="@layout/activity_main"