add a settings button for customizing widget colors without recreating

This commit is contained in:
tibbi 2018-05-17 09:59:27 +02:00
parent 26c19f7aaa
commit 72968c6995
7 changed files with 85 additions and 21 deletions

View File

@ -45,7 +45,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.18.9' implementation 'com.simplemobiletools:commons:4.0.18'
implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.facebook.stetho:stetho:1.5.0'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

View File

@ -51,7 +51,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
appLaunched() appLaunched(BuildConfig.APPLICATION_ID)
initViewPager() initViewPager()

View File

@ -1,11 +1,14 @@
package com.simplemobiletools.notes.activities package com.simplemobiletools.notes.activities
import android.content.Intent
import android.content.res.Resources import android.content.res.Resources
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.notes.R import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.extensions.config import com.simplemobiletools.notes.extensions.config
@ -45,7 +48,16 @@ class SettingsActivity : SimpleActivity() {
setupGravity() setupGravity()
setupWidgetNote() setupWidgetNote()
setupCursorPlacement() setupCursorPlacement()
setupCustomizeWidgetColors()
updateTextColors(settings_scrollview) updateTextColors(settings_scrollview)
setupSectionColors()
}
private fun setupSectionColors() {
val adjustedPrimaryColor = getAdjustedPrimaryColor()
arrayListOf(widgets_label).forEach {
it.setTextColor(adjustedPrimaryColor)
}
} }
private fun setupCustomizeColors() { private fun setupCustomizeColors() {
@ -211,4 +223,13 @@ class SettingsActivity : SimpleActivity() {
private fun getCurrentWidgetNoteTitle(currentNoteId: Int, notes: List<Note>) = private fun getCurrentWidgetNoteTitle(currentNoteId: Int, notes: List<Note>) =
notes.firstOrNull { it.id == currentNoteId }?.title ?: "" notes.firstOrNull { it.id == currentNoteId }?.title ?: ""
private fun setupCustomizeWidgetColors() {
settings_customize_widget_colors_holder.setOnClickListener {
Intent(this, WidgetConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
startActivity(this)
}
}
}
} }

View File

@ -1,10 +1,12 @@
package com.simplemobiletools.notes.activities package com.simplemobiletools.notes.activities
import android.os.Bundle
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.notes.R
open class SimpleActivity : BaseSimpleActivity() { open class SimpleActivity : BaseSimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun getAppIconIDs() = arrayListOf(
super.onCreate(savedInstanceState) R.mipmap.ic_launcher
} )
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
} }

View File

@ -11,6 +11,8 @@ import android.widget.SeekBar
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.setBackgroundColor import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setFillWithStroke
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import com.simplemobiletools.notes.R import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.extensions.config import com.simplemobiletools.notes.extensions.config
import com.simplemobiletools.notes.extensions.getTextSize import com.simplemobiletools.notes.extensions.getTextSize
@ -31,12 +33,12 @@ class WidgetConfigureActivity : SimpleActivity() {
setContentView(R.layout.widget_config) setContentView(R.layout.widget_config)
initVariables() initVariables()
val extras = intent.extras val isCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
if (extras != null) mWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID && !isCustomizingColors) {
finish() finish()
}
config_save.setOnClickListener { saveConfig() } config_save.setOnClickListener { saveConfig() }
config_bg_color.setOnClickListener { pickBackgroundColor() } config_bg_color.setOnClickListener { pickBackgroundColor() }
@ -100,12 +102,12 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun updateBackgroundColor() { private fun updateBackgroundColor() {
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha) mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
notes_view.setBackgroundColor(mBgColor) notes_view.setBackgroundColor(mBgColor)
config_bg_color.setBackgroundColor(mBgColor) config_bg_color.setFillWithStroke(mBgColor, Color.BLACK)
config_save.setBackgroundColor(mBgColor) config_save.setBackgroundColor(mBgColor)
} }
private fun updateTextColor() { private fun updateTextColor() {
config_text_color.setBackgroundColor(mTextColor) config_text_color.setFillWithStroke(mTextColor, Color.BLACK)
config_save.setTextColor(mTextColor) config_save.setTextColor(mTextColor)
notes_view.setTextColor(mTextColor) notes_view.setTextColor(mTextColor)
} }

View File

@ -356,6 +356,46 @@
</RelativeLayout> </RelativeLayout>
<View
android:id="@+id/widgets_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_grey"
android:importantForAccessibility="no"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/widgets_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/widgets"
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>
<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 <RelativeLayout
android:id="@+id/settings_widget_note_holder" android:id="@+id/settings_widget_note_holder"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -5,8 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_margin="@dimen/activity_margin" android:layout_margin="@dimen/activity_margin">
android:paddingBottom="@dimen/activity_margin">
<TextView <TextView
android:id="@+id/notes_view" android:id="@+id/notes_view"
@ -19,10 +18,10 @@
android:padding="@dimen/activity_margin" android:padding="@dimen/activity_margin"
android:text="@string/widget_config"/> android:text="@string/widget_config"/>
<Button <ImageView
android:id="@+id/config_bg_color" android:id="@+id/config_bg_color"
android:layout_width="50dp" android:layout_width="@dimen/widget_colorpicker_size"
android:layout_height="50dp" android:layout_height="@dimen/widget_colorpicker_size"
android:layout_above="@+id/config_text_color"/> android:layout_above="@+id/config_text_color"/>
<RelativeLayout <RelativeLayout
@ -44,10 +43,10 @@
android:paddingRight="@dimen/activity_margin"/> android:paddingRight="@dimen/activity_margin"/>
</RelativeLayout> </RelativeLayout>
<Button <ImageView
android:id="@+id/config_text_color" android:id="@+id/config_text_color"
android:layout_width="50dp" android:layout_width="@dimen/widget_colorpicker_size"
android:layout_height="50dp" android:layout_height="@dimen/widget_colorpicker_size"
android:layout_alignParentBottom="true"/> android:layout_alignParentBottom="true"/>
<Button <Button
@ -61,7 +60,7 @@
android:fontFamily="sans-serif-light" android:fontFamily="sans-serif-light"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin" android:paddingRight="@dimen/activity_margin"
android:text="@android:string/ok" android:text="@string/ok"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="@dimen/big_text_size"/> android:textSize="@dimen/big_text_size"/>