diff --git a/app/build.gradle b/app/build.gradle
index 8cfd197..73a7166 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -34,8 +34,11 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'me.grantland:autofittextview:0.2.1'
+ compile 'com.github.yukuku:ambilwarna:2.0.1'
+
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
+
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
diff --git a/app/src/main/java/calculator/simplemobiletools/com/Constants.java b/app/src/main/java/calculator/simplemobiletools/com/Constants.java
index 0f9f3df..e738821 100644
--- a/app/src/main/java/calculator/simplemobiletools/com/Constants.java
+++ b/app/src/main/java/calculator/simplemobiletools/com/Constants.java
@@ -28,4 +28,5 @@ public class Constants {
public static final String PREFS = "prefs";
public static final String CALC_VALUE = "calc_value";
public static final String WIDGET_BG_COLOR = "widget_bg_color";
+ public static final String WIDGET_TEXT_COLOR = "widget_text_color";
}
diff --git a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java
index a364d77..63164a7 100644
--- a/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java
+++ b/app/src/main/java/calculator/simplemobiletools/com/MyWidgetConfigure.java
@@ -8,19 +8,28 @@ import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
+import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.SeekBar;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
+import yuku.ambilwarna.AmbilWarnaDialog;
-public class MyWidgetConfigure extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
+public class MyWidgetConfigure extends AppCompatActivity {
@Bind(R.id.btn_reset) View resetBtn;
- @Bind(R.id.config_seekbar) SeekBar seekBar;
+ @Bind(R.id.config_bg_color) View bgColorPicker;
+ @Bind(R.id.config_bg_seekbar) SeekBar bgSeekBar;
+ @Bind(R.id.config_text_color) View textColorPicker;
@Bind(R.id.config_calc) View background;
+ @Bind(R.id.config_save) Button saveBtn;
private int widgetId;
- private int newBgColor;
+
+ private int bgColor;
+ private int bgColorWithoutTransparency;
+ private float bgAlpha;
+ private int textColor;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -28,10 +37,7 @@ public class MyWidgetConfigure extends AppCompatActivity implements SeekBar.OnSe
setResult(RESULT_CANCELED);
setContentView(R.layout.widget_config);
ButterKnife.bind(this);
-
- resetBtn.setVisibility(View.VISIBLE);
- seekBar.setOnSeekBarChangeListener(this);
- seekBar.setProgress(50);
+ initVariables();
final Intent intent = getIntent();
final Bundle extras = intent.getExtras();
@@ -42,11 +48,37 @@ public class MyWidgetConfigure extends AppCompatActivity implements SeekBar.OnSe
finish();
}
+ private void initVariables() {
+ final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
+ bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 0);
+ if (bgColor == 0) {
+ bgColor = Color.BLACK;
+ bgAlpha = .5f;
+ } else {
+ bgAlpha = Color.alpha(bgColor) / (float) 255;
+ }
+
+ resetBtn.setVisibility(View.VISIBLE);
+ bgColorWithoutTransparency = Color.rgb(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
+ bgSeekBar.setOnSeekBarChangeListener(bgSeekbarChangeListener);
+ bgSeekBar.setProgress((int) (bgAlpha * 100));
+ updateBackgroundColor();
+
+ textColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
+ updateTextColor();
+ }
+
+ private void updateTextColor() {
+ textColorPicker.setBackgroundColor(textColor);
+
+ saveBtn.setTextColor(textColor);
+ }
+
@OnClick(R.id.config_save)
public void saveConfig() {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
final RemoteViews views = new RemoteViews(getPackageName(), R.layout.activity_main);
- views.setInt(R.id.calculator_holder, "setBackgroundColor", newBgColor);
+ views.setInt(R.id.calculator_holder, "setBackgroundColor", bgColor);
appWidgetManager.updateAppWidget(widgetId, views);
storeWidgetBackground();
@@ -60,7 +92,7 @@ public class MyWidgetConfigure extends AppCompatActivity implements SeekBar.OnSe
private void storeWidgetBackground() {
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
- prefs.edit().putInt(Constants.WIDGET_BG_COLOR, newBgColor).apply();
+ prefs.edit().putInt(Constants.WIDGET_BG_COLOR, bgColor).apply();
}
private void requestWidgetUpdate() {
@@ -69,19 +101,70 @@ public class MyWidgetConfigure extends AppCompatActivity implements SeekBar.OnSe
sendBroadcast(intent);
}
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- final float percent = (float) progress / (float) 100;
- final int alpha = (int) (255 * percent);
- newBgColor = Color.argb(alpha, 0, 0, 0);
- background.setBackgroundColor(newBgColor);
+ private void updateBackgroundColor() {
+ bgColor = adjustAlpha(bgColorWithoutTransparency, bgAlpha);
+ background.setBackgroundColor(bgColor);
+ bgColorPicker.setBackgroundColor(bgColor);
+ saveBtn.setBackgroundColor(bgColor);
}
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
+ @OnClick(R.id.config_bg_color)
+ public void pickBackgroundColor() {
+ AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, bgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
+ @Override
+ public void onCancel(AmbilWarnaDialog dialog) {
+ }
+
+ @Override
+ public void onOk(AmbilWarnaDialog dialog, int color) {
+ bgColorWithoutTransparency = color;
+ updateBackgroundColor();
+ }
+ });
+
+ dialog.show();
}
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
+ @OnClick(R.id.config_text_color)
+ public void pickTextColor() {
+ AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, textColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
+ @Override
+ public void onCancel(AmbilWarnaDialog dialog) {
+ }
+
+ @Override
+ public void onOk(AmbilWarnaDialog dialog, int color) {
+ textColor = color;
+ updateTextColor();
+ }
+ });
+
+ dialog.show();
+ }
+
+ private SeekBar.OnSeekBarChangeListener bgSeekbarChangeListener = new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ bgAlpha = (float) progress / (float) 100;
+ updateBackgroundColor();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+ };
+
+ private int adjustAlpha(int color, float factor) {
+ final int alpha = Math.round(Color.alpha(color) * factor);
+ final int red = Color.red(color);
+ final int green = Color.green(color);
+ final int blue = Color.blue(color);
+ return Color.argb(alpha, red, green, blue);
}
}
diff --git a/app/src/main/res/drawable/config_button.xml b/app/src/main/res/drawable/config_button.xml
deleted file mode 100644
index a76abc0..0000000
--- a/app/src/main/res/drawable/config_button.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
diff --git a/app/src/main/res/drawable/config_button_normal.xml b/app/src/main/res/drawable/config_button_normal.xml
deleted file mode 100644
index e42ad7d..0000000
--- a/app/src/main/res/drawable/config_button_normal.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
diff --git a/app/src/main/res/drawable/config_button_pressed.xml b/app/src/main/res/drawable/config_button_pressed.xml
deleted file mode 100644
index 4953286..0000000
--- a/app/src/main/res/drawable/config_button_pressed.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
diff --git a/app/src/main/res/layout/widget_config.xml b/app/src/main/res/layout/widget_config.xml
index b6edd2f..47b5efb 100644
--- a/app/src/main/res/layout/widget_config.xml
+++ b/app/src/main/res/layout/widget_config.xml
@@ -4,42 +4,58 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
- android:layout_margin="@dimen/activity_margin">
+ android:layout_margin="@dimen/activity_margin"
+ android:paddingBottom="@dimen/activity_margin">
+
+
-
-
+ android:paddingLeft="@dimen/activity_margin"
+ android:paddingRight="@dimen/activity_margin"/>
+
+
+
+
+