From dd537c63f3fbbc0bf75a372b0618f179ba6b1bef Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Dec 2018 19:31:59 +0100 Subject: [PATCH] adding a text color changer at the widget config screen --- .../pro/activities/WidgetConfigureActivity.kt | 28 +++++++++++++++++-- .../gallery/pro/helpers/Config.kt | 4 +++ .../gallery/pro/helpers/Constants.kt | 1 + .../gallery/pro/helpers/MyWidgetProvider.kt | 3 +- .../res/layout/activity_widget_config.xml | 6 ++++ app/src/main/res/values/dimens.xml | 2 +- app/src/main/res/xml/widget_info.xml | 4 +-- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt index 572f2cca5..eebddb6a6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt @@ -22,6 +22,7 @@ class WidgetConfigureActivity : SimpleActivity() { private var mWidgetId = 0 private var mBgColor = 0 private var mBgColorWithoutTransparency = 0 + private var mTextColor = 0 private var mFolderPath = "" private var mDirectories = ArrayList() @@ -40,10 +41,11 @@ class WidgetConfigureActivity : SimpleActivity() { config_save.setOnClickListener { saveConfig() } config_bg_color.setOnClickListener { pickBackgroundColor() } + config_text_color.setOnClickListener { pickTextColor() } folder_picker_value.setOnClickListener { changeSelectedFolder() } config_image_holder.setOnClickListener { changeSelectedFolder() } - folder_picker_show_folder_name_holder.setOnClickListener { } - config_save.setTextColor(getAdjustedPrimaryColor()) + folder_picker_show_folder_name.isChecked = config.showWidgetFolderName + folder_picker_show_folder_name_holder.setOnClickListener { toggleFolderNameDisplay() } updateTextColors(folder_picker_holder) folder_picker_holder.background = ColorDrawable(config.backgroundColor) @@ -75,12 +77,16 @@ class WidgetConfigureActivity : SimpleActivity() { } } updateBackgroundColor() + + mTextColor = config.widgetTextColor + updateTextColor() } private fun saveConfig() { val views = RemoteViews(packageName, R.layout.widget) views.setBackgroundColor(R.id.widget_holder, mBgColor) AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views) + config.showWidgetFolderName = folder_picker_show_folder_name.isChecked val widget = Widget(null, mWidgetId, mFolderPath) Thread { widgetsDB.insertOrUpdate(widget) @@ -116,6 +122,11 @@ class WidgetConfigureActivity : SimpleActivity() { config_bg_color.setFillWithStroke(mBgColor, Color.BLACK) } + private fun updateTextColor() { + config_save.setTextColor(mTextColor) + config_text_color.setFillWithStroke(mTextColor, Color.BLACK) + } + private fun pickBackgroundColor() { ColorPickerDialog(this, mBgColorWithoutTransparency) { wasPositivePressed, color -> if (wasPositivePressed) { @@ -125,6 +136,15 @@ class WidgetConfigureActivity : SimpleActivity() { } } + private fun pickTextColor() { + ColorPickerDialog(this, mTextColor) { wasPositivePressed, color -> + if (wasPositivePressed) { + mTextColor = color + updateTextColor() + } + } + } + private fun changeSelectedFolder() { PickDirectoryDialog(this, mFolderPath, false) { updateFolderImage(it) @@ -142,4 +162,8 @@ class WidgetConfigureActivity : SimpleActivity() { } }.start() } + + private fun toggleFolderNameDisplay() { + folder_picker_show_folder_name.toggle() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index 3016cf54f..cdb7ef840 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -427,4 +427,8 @@ class Config(context: Context) : BaseConfig(context) { var groupDirectSubfolders: Boolean get() = prefs.getBoolean(GROUP_DIRECT_SUBFOLDERS, false) set(groupDirectSubfolders) = prefs.edit().putBoolean(GROUP_DIRECT_SUBFOLDERS, groupDirectSubfolders).apply() + + var showWidgetFolderName: Boolean + get() = prefs.getBoolean(SHOW_WIDGET_FOLDER_NAME, true) + set(showWidgetFolderName) = prefs.edit().putBoolean(SHOW_WIDGET_FOLDER_NAME, showWidgetFolderName).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 03d5b8436..95a068eb0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -72,6 +72,7 @@ const val LAST_EDITOR_CROP_ASPECT_RATIO = "last_editor_crop_aspect_ratio" const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X = "last_editor_crop_other_aspect_ratio_x" const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y = "last_editor_crop_other_aspect_ratio_y" const val GROUP_DIRECT_SUBFOLDERS = "group_direct_subfolders" +const val SHOW_WIDGET_FOLDER_NAME = "show_widget_folder_name" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt index 1affe0ec4..eb88404f7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt @@ -8,7 +8,6 @@ import android.content.Context import android.content.Intent import android.os.Handler import android.os.Looper -import android.util.Log import android.widget.RemoteViews import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy @@ -47,7 +46,7 @@ class MyWidgetProvider : AppWidgetProvider() { if (context.config.cropThumbnails) options.centerCrop() else options.fitCenter() Handler(Looper.getMainLooper()).post { - val widgetSize = context.resources.getDimension(R.dimen.widget_initial_width).toInt() + val widgetSize = context.resources.getDimension(R.dimen.widget_initial_size).toInt() val componentName = ComponentName(context, MyWidgetProvider::class.java) val appWidgetTarget = object : AppWidgetTarget(context, widgetSize, widgetSize, R.id.widget_imageview, views, componentName) {} diff --git a/app/src/main/res/layout/activity_widget_config.xml b/app/src/main/res/layout/activity_widget_config.xml index a8d277b1d..cda0e7f48 100644 --- a/app/src/main/res/layout/activity_widget_config.xml +++ b/app/src/main/res/layout/activity_widget_config.xml @@ -96,6 +96,12 @@ android:paddingRight="@dimen/activity_margin"/> + +