mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
allow changing the text color
This commit is contained in:
@@ -11,6 +11,7 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@@ -68,12 +69,6 @@ public class MyWidgetConfigure extends AppCompatActivity {
|
|||||||
updateTextColor();
|
updateTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextColor() {
|
|
||||||
textColorPicker.setBackgroundColor(textColor);
|
|
||||||
|
|
||||||
saveBtn.setTextColor(textColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.config_save)
|
@OnClick(R.id.config_save)
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
||||||
@@ -93,6 +88,7 @@ public class MyWidgetConfigure extends AppCompatActivity {
|
|||||||
private void storeWidgetBackground() {
|
private void storeWidgetBackground() {
|
||||||
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
||||||
prefs.edit().putInt(Constants.WIDGET_BG_COLOR, bgColor).apply();
|
prefs.edit().putInt(Constants.WIDGET_BG_COLOR, bgColor).apply();
|
||||||
|
prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, textColor).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestWidgetUpdate() {
|
private void requestWidgetUpdate() {
|
||||||
@@ -108,6 +104,24 @@ public class MyWidgetConfigure extends AppCompatActivity {
|
|||||||
saveBtn.setBackgroundColor(bgColor);
|
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)
|
@OnClick(R.id.config_bg_color)
|
||||||
public void pickBackgroundColor() {
|
public void pickBackgroundColor() {
|
||||||
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, bgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, bgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
|
@@ -7,6 +7,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
@@ -59,14 +60,16 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||||||
|
|
||||||
private void initVariables(Context context) {
|
private void initVariables(Context context) {
|
||||||
prefs = initPrefs(context);
|
prefs = initPrefs(context);
|
||||||
|
final ComponentName component = new ComponentName(context, MyWidgetProvider.class);
|
||||||
final int defaultColor = context.getResources().getColor(R.color.dark_grey);
|
final int defaultColor = context.getResources().getColor(R.color.dark_grey);
|
||||||
final int newBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, defaultColor);
|
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 = new RemoteViews(context.getPackageName(), R.layout.activity_main);
|
||||||
remoteViews.setViewVisibility(R.id.btn_reset, View.VISIBLE);
|
remoteViews.setViewVisibility(R.id.btn_reset, View.VISIBLE);
|
||||||
remoteViews.setInt(R.id.calculator_holder, "setBackgroundColor", newBgColor);
|
remoteViews.setInt(R.id.calculator_holder, "setBackgroundColor", newBgColor);
|
||||||
|
|
||||||
|
updateTextColors(newTextColor);
|
||||||
widgetManager = AppWidgetManager.getInstance(context);
|
widgetManager = AppWidgetManager.getInstance(context);
|
||||||
widgetIds = widgetManager.getAppWidgetIds(component);
|
widgetIds = widgetManager.getAppWidgetIds(component);
|
||||||
|
|
||||||
@@ -78,6 +81,17 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||||||
return context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
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
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
|
Reference in New Issue
Block a user