Skip to content

Commit 72968c6

Browse files
committed
add a settings button for customizing widget colors without recreating
1 parent 26c19f7 commit 72968c6

File tree

7 files changed

+85
-21
lines changed

7 files changed

+85
-21
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ext {
4545
}
4646

4747
dependencies {
48-
implementation 'com.simplemobiletools:commons:3.18.9'
48+
implementation 'com.simplemobiletools:commons:4.0.18'
4949
implementation 'com.facebook.stetho:stetho:1.5.0'
5050

5151
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
5151
override fun onCreate(savedInstanceState: Bundle?) {
5252
super.onCreate(savedInstanceState)
5353
setContentView(R.layout.activity_main)
54-
appLaunched()
54+
appLaunched(BuildConfig.APPLICATION_ID)
5555

5656
initViewPager()
5757

app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.simplemobiletools.notes.activities
22

3+
import android.content.Intent
34
import android.content.res.Resources
45
import android.os.Bundle
56
import android.view.View
67
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
78
import com.simplemobiletools.commons.extensions.beVisibleIf
9+
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
810
import com.simplemobiletools.commons.extensions.updateTextColors
11+
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
912
import com.simplemobiletools.commons.models.RadioItem
1013
import com.simplemobiletools.notes.R
1114
import com.simplemobiletools.notes.extensions.config
@@ -45,7 +48,16 @@ class SettingsActivity : SimpleActivity() {
4548
setupGravity()
4649
setupWidgetNote()
4750
setupCursorPlacement()
51+
setupCustomizeWidgetColors()
4852
updateTextColors(settings_scrollview)
53+
setupSectionColors()
54+
}
55+
56+
private fun setupSectionColors() {
57+
val adjustedPrimaryColor = getAdjustedPrimaryColor()
58+
arrayListOf(widgets_label).forEach {
59+
it.setTextColor(adjustedPrimaryColor)
60+
}
4961
}
5062

5163
private fun setupCustomizeColors() {
@@ -211,4 +223,13 @@ class SettingsActivity : SimpleActivity() {
211223

212224
private fun getCurrentWidgetNoteTitle(currentNoteId: Int, notes: List<Note>) =
213225
notes.firstOrNull { it.id == currentNoteId }?.title ?: ""
226+
227+
private fun setupCustomizeWidgetColors() {
228+
settings_customize_widget_colors_holder.setOnClickListener {
229+
Intent(this, WidgetConfigureActivity::class.java).apply {
230+
putExtra(IS_CUSTOMIZING_COLORS, true)
231+
startActivity(this)
232+
}
233+
}
234+
}
214235
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.simplemobiletools.notes.activities
22

3-
import android.os.Bundle
43
import com.simplemobiletools.commons.activities.BaseSimpleActivity
4+
import com.simplemobiletools.notes.R
55

66
open class SimpleActivity : BaseSimpleActivity() {
7-
override fun onCreate(savedInstanceState: Bundle?) {
8-
super.onCreate(savedInstanceState)
9-
}
7+
override fun getAppIconIDs() = arrayListOf(
8+
R.mipmap.ic_launcher
9+
)
10+
11+
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
1012
}

app/src/main/kotlin/com/simplemobiletools/notes/activities/WidgetConfigureActivity.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import android.widget.SeekBar
1111
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
1212
import com.simplemobiletools.commons.extensions.adjustAlpha
1313
import com.simplemobiletools.commons.extensions.setBackgroundColor
14+
import com.simplemobiletools.commons.extensions.setFillWithStroke
15+
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
1416
import com.simplemobiletools.notes.R
1517
import com.simplemobiletools.notes.extensions.config
1618
import com.simplemobiletools.notes.extensions.getTextSize
@@ -31,12 +33,12 @@ class WidgetConfigureActivity : SimpleActivity() {
3133
setContentView(R.layout.widget_config)
3234
initVariables()
3335

34-
val extras = intent.extras
35-
if (extras != null)
36-
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
36+
val isCustomizingColors = intent.extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
37+
mWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
3738

38-
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
39+
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID && !isCustomizingColors) {
3940
finish()
41+
}
4042

4143
config_save.setOnClickListener { saveConfig() }
4244
config_bg_color.setOnClickListener { pickBackgroundColor() }
@@ -100,12 +102,12 @@ class WidgetConfigureActivity : SimpleActivity() {
100102
private fun updateBackgroundColor() {
101103
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
102104
notes_view.setBackgroundColor(mBgColor)
103-
config_bg_color.setBackgroundColor(mBgColor)
105+
config_bg_color.setFillWithStroke(mBgColor, Color.BLACK)
104106
config_save.setBackgroundColor(mBgColor)
105107
}
106108

107109
private fun updateTextColor() {
108-
config_text_color.setBackgroundColor(mTextColor)
110+
config_text_color.setFillWithStroke(mTextColor, Color.BLACK)
109111
config_save.setTextColor(mTextColor)
110112
notes_view.setTextColor(mTextColor)
111113
}

app/src/main/res/layout/activity_settings.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,46 @@
356356

357357
</RelativeLayout>
358358

359+
<View
360+
android:id="@+id/widgets_divider"
361+
android:layout_width="match_parent"
362+
android:layout_height="1px"
363+
android:background="@color/divider_grey"
364+
android:importantForAccessibility="no"/>
365+
366+
<com.simplemobiletools.commons.views.MyTextView
367+
android:id="@+id/widgets_label"
368+
android:layout_width="wrap_content"
369+
android:layout_height="wrap_content"
370+
android:layout_marginLeft="@dimen/bigger_margin"
371+
android:layout_marginStart="@dimen/bigger_margin"
372+
android:layout_marginTop="@dimen/activity_margin"
373+
android:text="@string/widgets"
374+
android:textAllCaps="true"
375+
android:textSize="@dimen/smaller_text_size"/>
376+
377+
<RelativeLayout
378+
android:id="@+id/settings_customize_widget_colors_holder"
379+
android:layout_width="match_parent"
380+
android:layout_height="wrap_content"
381+
android:layout_marginTop="@dimen/medium_margin"
382+
android:background="?attr/selectableItemBackground"
383+
android:paddingBottom="@dimen/activity_margin"
384+
android:paddingLeft="@dimen/normal_margin"
385+
android:paddingRight="@dimen/normal_margin"
386+
android:paddingTop="@dimen/activity_margin">
387+
388+
<com.simplemobiletools.commons.views.MyTextView
389+
android:id="@+id/settings_customize_widget_colors_label"
390+
android:layout_width="wrap_content"
391+
android:layout_height="wrap_content"
392+
android:layout_centerVertical="true"
393+
android:paddingLeft="@dimen/medium_margin"
394+
android:paddingStart="@dimen/medium_margin"
395+
android:text="@string/customize_widget_colors"/>
396+
397+
</RelativeLayout>
398+
359399
<RelativeLayout
360400
android:id="@+id/settings_widget_note_holder"
361401
android:layout_width="match_parent"

app/src/main/res/layout/widget_config.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
77
android:layout_centerHorizontal="true"
8-
android:layout_margin="@dimen/activity_margin"
9-
android:paddingBottom="@dimen/activity_margin">
8+
android:layout_margin="@dimen/activity_margin">
109

1110
<TextView
1211
android:id="@+id/notes_view"
@@ -19,10 +18,10 @@
1918
android:padding="@dimen/activity_margin"
2019
android:text="@string/widget_config"/>
2120

22-
<Button
21+
<ImageView
2322
android:id="@+id/config_bg_color"
24-
android:layout_width="50dp"
25-
android:layout_height="50dp"
23+
android:layout_width="@dimen/widget_colorpicker_size"
24+
android:layout_height="@dimen/widget_colorpicker_size"
2625
android:layout_above="@+id/config_text_color"/>
2726

2827
<RelativeLayout
@@ -44,10 +43,10 @@
4443
android:paddingRight="@dimen/activity_margin"/>
4544
</RelativeLayout>
4645

47-
<Button
46+
<ImageView
4847
android:id="@+id/config_text_color"
49-
android:layout_width="50dp"
50-
android:layout_height="50dp"
48+
android:layout_width="@dimen/widget_colorpicker_size"
49+
android:layout_height="@dimen/widget_colorpicker_size"
5150
android:layout_alignParentBottom="true"/>
5251

5352
<Button
@@ -61,7 +60,7 @@
6160
android:fontFamily="sans-serif-light"
6261
android:paddingLeft="@dimen/activity_margin"
6362
android:paddingRight="@dimen/activity_margin"
64-
android:text="@android:string/ok"
63+
android:text="@string/ok"
6564
android:textColor="@android:color/white"
6665
android:textSize="@dimen/big_text_size"/>
6766

0 commit comments

Comments
 (0)