From 8928509e622b5abafd555c8c1225a1b0cfd16621 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 31 Jan 2016 22:00:44 +0100 Subject: [PATCH] allow changing the text color --- .../com/MyWidgetConfigure.java | 26 ++++++++++++++----- .../com/MyWidgetProvider.java | 16 +++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java index 63164a7..f976dbe 100644 --- a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java +++ b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java @@ -11,6 +11,7 @@ import android.view.View; import android.widget.Button; import android.widget.RemoteViews; import android.widget.SeekBar; +import android.widget.TextView; import butterknife.Bind; import butterknife.ButterKnife; @@ -68,12 +69,6 @@ public class MyWidgetConfigure extends AppCompatActivity { updateTextColor(); } - private void updateTextColor() { - textColorPicker.setBackgroundColor(textColor); - - saveBtn.setTextColor(textColor); - } - @OnClick(R.id.config_save) public void saveConfig() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); @@ -93,6 +88,7 @@ public class MyWidgetConfigure extends AppCompatActivity { private void storeWidgetBackground() { final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE); prefs.edit().putInt(Constants.WIDGET_BG_COLOR, bgColor).apply(); + prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, textColor).apply(); } private void requestWidgetUpdate() { @@ -108,6 +104,24 @@ public class MyWidgetConfigure extends AppCompatActivity { saveBtn.setBackgroundColor(bgColor); } + private void updateTextColor() { + textColorPicker.setBackgroundColor(textColor); + saveBtn.setTextColor(textColor); + + int[] viewIds = + new int[]{R.id.btn_0, R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6, R.id.btn_7, R.id.btn_8, + R.id.btn_9, R.id.btn_modulo, R.id.btn_power, R.id.btn_root, R.id.btn_clear, R.id.btn_reset, R.id.btn_divide, + R.id.btn_multiply, R.id.btn_minus, R.id.btn_plus, R.id.btn_decimal, R.id.btn_equals}; + final TextView result = (TextView) findViewById(R.id.result); + result.setTextColor(textColor); + + Button btn; + for (int i : viewIds) { + btn = (Button) findViewById(i); + btn.setTextColor(textColor); + } + } + @OnClick(R.id.config_bg_color) public void pickBackgroundColor() { AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, bgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() { diff --git a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetProvider.java b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetProvider.java index d29879f..e9fe835 100644 --- a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetProvider.java +++ b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetProvider.java @@ -7,6 +7,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.view.View; import android.widget.RemoteViews; @@ -59,14 +60,16 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator { private void initVariables(Context context) { prefs = initPrefs(context); + final ComponentName component = new ComponentName(context, MyWidgetProvider.class); final int defaultColor = context.getResources().getColor(R.color.dark_grey); final int newBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor); - final ComponentName component = new ComponentName(context, MyWidgetProvider.class); + final int newTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE); remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main); remoteViews.setViewVisibility(R.id.btn_reset, View.VISIBLE); remoteViews.setInt(R.id.calculator_holder, "setBackgroundColor", newBgColor); + updateTextColors(newTextColor); widgetManager = AppWidgetManager.getInstance(context); widgetIds = widgetManager.getAppWidgetIds(component); @@ -78,6 +81,17 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator { return context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE); } + private void updateTextColors(int color) { + int[] viewIds = + new int[]{R.id.formula, R.id.result, R.id.btn_0, R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6, + R.id.btn_7, R.id.btn_8, R.id.btn_9, R.id.btn_modulo, R.id.btn_power, R.id.btn_root, R.id.btn_clear, R.id.btn_reset, + R.id.btn_divide, R.id.btn_multiply, R.id.btn_minus, R.id.btn_plus, R.id.btn_decimal, R.id.btn_equals}; + + for (int i : viewIds) { + remoteViews.setInt(i, "setTextColor", color); + } + } + @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction();