From bc02c56d252525c554a51c25c904f8526c039ad7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 30 Aug 2016 20:07:53 +0200 Subject: [PATCH] use the picked color as the active color of the widget --- .../simplemobiletools/flashlight/MyWidgetProvider.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/simplemobiletools/flashlight/MyWidgetProvider.java b/app/src/main/java/com/simplemobiletools/flashlight/MyWidgetProvider.java index 4a0b2a7..c273fdb 100644 --- a/app/src/main/java/com/simplemobiletools/flashlight/MyWidgetProvider.java +++ b/app/src/main/java/com/simplemobiletools/flashlight/MyWidgetProvider.java @@ -6,6 +6,7 @@ import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Bitmap; import android.widget.RemoteViews; @@ -44,8 +45,10 @@ public class MyWidgetProvider extends AppWidgetProvider { mRemoteViews.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent); mCameraImpl = new MyCameraImpl(context); + final SharedPreferences prefs = initPrefs(context); final Resources res = context.getResources(); - final int appColor = res.getColor(R.color.colorPrimary); + final int defaultColor = res.getColor(R.color.colorPrimary); + final int appColor = prefs.getInt(Constants.WIDGET_COLOR, defaultColor); mColoredBmp = Utils.getColoredIcon(context.getResources(), appColor, R.mipmap.flashlight_small); if (mBus == null) { @@ -81,6 +84,10 @@ public class MyWidgetProvider extends AppWidgetProvider { } } + private SharedPreferences initPrefs(Context context) { + return context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); + } + @Subscribe public void cameraUnavailable(Events.CameraUnavailable event) { if (mContext != null) {