add a settings item for customizing widget colors without recreating

This commit is contained in:
tibbi 2018-05-15 23:36:12 +02:00
parent 0d5c8a5a81
commit da386687f0
4 changed files with 41 additions and 5 deletions

View File

@ -43,7 +43,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:4.0.14'
implementation 'com.simplemobiletools:commons:4.0.15'
implementation 'me.grantland:autofittextview:0.2.1'
testImplementation 'junit:junit:4.12'

View File

@ -1,10 +1,12 @@
package com.simplemobiletools.calculator.activities
import android.content.Intent
import android.os.Bundle
import com.simplemobiletools.calculator.R
import com.simplemobiletools.calculator.extensions.config
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
@ -23,6 +25,7 @@ class SettingsActivity : SimpleActivity() {
setupAvoidWhatsNew()
setupVibrate()
setupPreventPhoneFromSleeping()
setupCustomizeWidgetColors()
updateTextColors(settings_scrollview)
}
@ -65,4 +68,13 @@ class SettingsActivity : SimpleActivity() {
config.preventPhoneFromSleeping = settings_prevent_phone_from_sleeping.isChecked
}
}
private fun setupCustomizeWidgetColors() {
settings_customize_widget_colors_holder.setOnClickListener {
Intent(this, WidgetConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
startActivity(this)
}
}
}
}

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
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.*
import kotlinx.android.synthetic.main.widget_config.*
@ -25,6 +26,7 @@ class WidgetConfigureActivity : SimpleActivity() {
private var mWidgetId = 0
private var mTextColor = 0
private var mBgAlpha = 0f
private var mIsCustomizingColors = false
public override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false
@ -33,12 +35,12 @@ class WidgetConfigureActivity : SimpleActivity() {
setContentView(R.layout.widget_config)
initVariables()
val extras = intent.extras
if (extras != null)
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
mIsCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
mWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID && !mIsCustomizingColors) {
finish()
}
config_save.setOnClickListener { saveConfig() }
config_bg_color.setOnClickListener { pickBackgroundColor() }

View File

@ -33,6 +33,28 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_customize_widget_colors_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_customize_widget_colors_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/customize_widget_colors"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_use_english_holder"
android:layout_width="match_parent"