allow changing the widgets background color
This commit is contained in:
parent
53a3c76299
commit
24efdfda9b
|
@ -6,5 +6,6 @@ public class Constants {
|
||||||
public static final float HIGH_ALPHA = 0.9f;
|
public static final float HIGH_ALPHA = 0.9f;
|
||||||
|
|
||||||
public static final String PREFS = "prefs";
|
public static final String PREFS = "prefs";
|
||||||
|
public static final String WIDGET_BG_COLOR = "widget_bg_color";
|
||||||
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
|
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -27,7 +28,10 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
@Bind(R.id.left_arrow) ImageView leftArrow;
|
@Bind(R.id.left_arrow) ImageView leftArrow;
|
||||||
@Bind(R.id.right_arrow) ImageView rightArrow;
|
@Bind(R.id.right_arrow) ImageView rightArrow;
|
||||||
@Bind(R.id.table_month) TextView monthTV;
|
@Bind(R.id.table_month) TextView monthTV;
|
||||||
|
@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_text_color) View textColorPicker;
|
||||||
|
@Bind(R.id.config_calendar) View widgetBackground;
|
||||||
@BindDimen(R.dimen.day_text_size) float dayTextSize;
|
@BindDimen(R.dimen.day_text_size) float dayTextSize;
|
||||||
@BindDimen(R.dimen.today_text_size) float todayTextSize;
|
@BindDimen(R.dimen.today_text_size) float todayTextSize;
|
||||||
|
|
||||||
|
@ -36,9 +40,13 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
private Resources res;
|
private Resources res;
|
||||||
private String packageName;
|
private String packageName;
|
||||||
private List<Day> days;
|
private List<Day> days;
|
||||||
private static int textColorWithoutTransparency;
|
private int bgColorWithoutTransparency;
|
||||||
private static int textColor;
|
private int bgColor;
|
||||||
private static int weakTextColor;
|
private float bgAlpha;
|
||||||
|
|
||||||
|
private int textColorWithoutTransparency;
|
||||||
|
private int textColor;
|
||||||
|
private int weakTextColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -67,6 +75,13 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
textColorWithoutTransparency = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
|
textColorWithoutTransparency = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
|
||||||
updateTextColors();
|
updateTextColors();
|
||||||
|
|
||||||
|
bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, Color.BLACK);
|
||||||
|
bgColorWithoutTransparency = Color.rgb(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
|
||||||
|
bgAlpha = Color.alpha(bgColor) / (float) 255;
|
||||||
|
bgSeekBar.setOnSeekBarChangeListener(bgSeekbarChangeListener);
|
||||||
|
bgSeekBar.setProgress((int) (bgAlpha * 100));
|
||||||
|
updateBgColor();
|
||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
calendar = new CalendarImpl(this);
|
||||||
calendar.updateCalendar(new DateTime());
|
calendar.updateCalendar(new DateTime());
|
||||||
}
|
}
|
||||||
|
@ -88,9 +103,27 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
|
|
||||||
private void storeWidgetColors() {
|
private void storeWidgetColors() {
|
||||||
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_TEXT_COLOR, textColorWithoutTransparency).apply();
|
prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, textColorWithoutTransparency).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
updateBgColor();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.config_text_color)
|
@OnClick(R.id.config_text_color)
|
||||||
public void pickTextColor() {
|
public void pickTextColor() {
|
||||||
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, textColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, textColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
|
@ -126,6 +159,12 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateBgColor() {
|
||||||
|
bgColor = Helpers.adjustAlpha(bgColorWithoutTransparency, bgAlpha);
|
||||||
|
widgetBackground.setBackgroundColor(bgColor);
|
||||||
|
bgColorPicker.setBackgroundColor(bgColor);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateDays() {
|
private void updateDays() {
|
||||||
final int len = days.size();
|
final int len = days.size();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
|
@ -148,6 +187,24 @@ public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SeekBar.OnSeekBarChangeListener bgSeekbarChangeListener = new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
bgAlpha = (float) progress / (float) 100;
|
||||||
|
updateBgColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@OnClick(R.id.left_arrow)
|
@OnClick(R.id.left_arrow)
|
||||||
public void leftArrowClicked() {
|
public void leftArrowClicked() {
|
||||||
calendar.getPrevMonth();
|
calendar.getPrevMonth();
|
||||||
|
|
|
@ -34,7 +34,6 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
private static Resources res;
|
private static Resources res;
|
||||||
private static float dayTextSize;
|
private static float dayTextSize;
|
||||||
private static float todayTextSize;
|
private static float todayTextSize;
|
||||||
private static int bgColor;
|
|
||||||
private static int textColor;
|
private static int textColor;
|
||||||
private static int weakTextColor;
|
private static int weakTextColor;
|
||||||
|
|
||||||
|
@ -46,13 +45,13 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
private void initVariables(Context context) {
|
private void initVariables(Context context) {
|
||||||
cxt = context;
|
cxt = context;
|
||||||
res = cxt.getResources();
|
res = cxt.getResources();
|
||||||
bgColor = Color.BLACK;
|
|
||||||
|
|
||||||
final SharedPreferences prefs = initPrefs(cxt);
|
final SharedPreferences prefs = initPrefs(cxt);
|
||||||
final int storedTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
|
final int storedTextColor = prefs.getInt(Constants.WIDGET_TEXT_COLOR, Color.WHITE);
|
||||||
textColor = Helpers.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA);
|
textColor = Helpers.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA);
|
||||||
weakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
weakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
||||||
|
|
||||||
|
|
||||||
dayTextSize = res.getDimension(R.dimen.day_text_size) / res.getDisplayMetrics().density;
|
dayTextSize = res.getDimension(R.dimen.day_text_size) / res.getDisplayMetrics().density;
|
||||||
todayTextSize = res.getDimension(R.dimen.today_text_size) / res.getDisplayMetrics().density;
|
todayTextSize = res.getDimension(R.dimen.today_text_size) / res.getDisplayMetrics().density;
|
||||||
|
|
||||||
|
@ -66,6 +65,9 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
updateLabelColor();
|
updateLabelColor();
|
||||||
updateTopViews();
|
updateTopViews();
|
||||||
|
|
||||||
|
final int bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, Color.BLACK);
|
||||||
|
remoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", bgColor);
|
||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
calendar = new CalendarImpl(this);
|
||||||
calendar.updateCalendar(new DateTime());
|
calendar.updateCalendar(new DateTime());
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_below="@+id/table_month"
|
android:layout_below="@+id/table_month"
|
||||||
android:layout_marginTop="@dimen/activity_margin"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
|
@ -11,28 +11,47 @@
|
||||||
layout="@layout/activity_main"
|
layout="@layout/activity_main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_above="@+id/config_bottom"
|
android:layout_above="@+id/config_bg_color"
|
||||||
android:layout_marginBottom="@dimen/activity_margin"/>
|
android:layout_marginBottom="@dimen/activity_margin"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/config_bg_color"
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_above="@+id/config_text_color"/>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/config_bottom"
|
android:id="@+id/config_bg_seekbar_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignBottom="@+id/config_bg_color"
|
||||||
|
android:layout_alignTop="@+id/config_bg_color"
|
||||||
|
android:layout_toRightOf="@+id/config_bg_color"
|
||||||
|
android:background="@android:color/white">
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/config_bg_seekbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true">
|
android:layout_centerVertical="true"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/config_text_color"
|
android:id="@+id/config_text_color"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"/>
|
android:layout_height="50dp"
|
||||||
|
android:layout_alignParentBottom="true"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/config_save"
|
android:id="@+id/config_save"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
android:text="Save"
|
android:text="OK"
|
||||||
android:textSize="18sp"/>
|
android:textSize="18sp"/>
|
||||||
</RelativeLayout>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
android:configure="calendar.simplemobiletools.com.MyWidgetConfigure"
|
android:configure="calendar.simplemobiletools.com.MyWidgetConfigure"
|
||||||
android:initialLayout="@layout/activity_main"
|
android:initialLayout="@layout/activity_main"
|
||||||
android:minHeight="250dp"
|
android:minHeight="250dp"
|
||||||
android:minWidth="250dp">
|
android:minWidth="250dp"
|
||||||
|
android:updatePeriodMillis="18000000">
|
||||||
</appwidget-provider>
|
</appwidget-provider>
|
||||||
|
|
Loading…
Reference in New Issue