use rounded widget background
This commit is contained in:
parent
fc373024bf
commit
0204369302
|
@ -13,8 +13,8 @@ import com.simplemobiletools.calculator.extensions.config
|
|||
import com.simplemobiletools.calculator.helpers.MyWidgetProvider
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beVisible
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -65,8 +65,10 @@ class WidgetConfigureActivity : SimpleActivity() {
|
|||
|
||||
private fun saveConfig() {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(this)
|
||||
val views = RemoteViews(packageName, R.layout.activity_main)
|
||||
views.setBackgroundColor(R.id.calculator_holder, mBgColor)
|
||||
val views = RemoteViews(packageName, R.layout.widget).apply {
|
||||
applyColorFilter(R.id.widget_background, mBgColor)
|
||||
}
|
||||
|
||||
appWidgetManager.updateAppWidget(mWidgetId, views)
|
||||
|
||||
storeWidgetColors()
|
||||
|
@ -95,7 +97,7 @@ class WidgetConfigureActivity : SimpleActivity() {
|
|||
|
||||
private fun updateBackgroundColor() {
|
||||
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
|
||||
config_calc.setBackgroundColor(mBgColor)
|
||||
widget_background.applyColorFilter(mBgColor)
|
||||
config_save.setBackgroundColor(mBgColor)
|
||||
config_bg_color.setFillWithStroke(mBgColor, Color.BLACK)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.RemoteViews
|
|||
import com.simplemobiletools.calculator.R
|
||||
import com.simplemobiletools.calculator.activities.MainActivity
|
||||
import com.simplemobiletools.calculator.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.setText
|
||||
|
||||
|
@ -20,14 +21,9 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
|
|||
}
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
performUpdate(context)
|
||||
}
|
||||
|
||||
private fun performUpdate(context: Context) {
|
||||
val config = context.config
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
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, ZERO, R.id.btn_0)
|
||||
setupIntent(context, views, ONE, R.id.btn_1)
|
||||
|
@ -55,7 +51,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
|
|||
setupAppOpenIntent(context, views, R.id.result)
|
||||
|
||||
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)
|
||||
appWidgetManager.updateAppWidget(it, views)
|
||||
|
@ -123,7 +119,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
|
|||
override fun setValue(value: String, context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
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)
|
||||
appWidgetManager.partiallyUpdateAppWidget(it, views)
|
||||
}
|
||||
|
@ -135,7 +131,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
|
|||
override fun setFormula(value: String, context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
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)
|
||||
appWidgetManager.partiallyUpdateAppWidget(it, views)
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -6,6 +6,16 @@
|
|||
android:layout_margin="@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
|
||||
android:id="@+id/config_calc"
|
||||
layout="@layout/activity_main"
|
||||
|
|
Loading…
Reference in New Issue