some refactoring, no functionality change
This commit is contained in:
parent
d021053075
commit
858fde96d8
|
@ -20,7 +20,7 @@
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MyWidgetConfigure"
|
android:name=".activities.WidgetConfigureActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:theme="@style/MyWidgetConfigTheme">
|
android:theme="@style/MyWidgetConfigTheme">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -11,27 +11,27 @@ public class CalendarImpl {
|
||||||
private static final String DATE_PATTERN = "ddMMYYYY";
|
private static final String DATE_PATTERN = "ddMMYYYY";
|
||||||
private static final String YEAR_PATTERN = "YYYY";
|
private static final String YEAR_PATTERN = "YYYY";
|
||||||
|
|
||||||
private final Calendar callback;
|
private final Calendar mCallback;
|
||||||
private final String today;
|
private final String mToday;
|
||||||
private DateTime targetDate;
|
private DateTime mTargetDate;
|
||||||
|
|
||||||
public CalendarImpl(Calendar callback) {
|
public CalendarImpl(Calendar callback) {
|
||||||
this.callback = callback;
|
this.mCallback = callback;
|
||||||
today = new DateTime().toString(DATE_PATTERN);
|
mToday = new DateTime().toString(DATE_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCalendar(DateTime targetDate) {
|
public void updateCalendar(DateTime targetDate) {
|
||||||
this.targetDate = targetDate;
|
this.mTargetDate = targetDate;
|
||||||
getMonthName();
|
getMonthName();
|
||||||
getDays(targetDate);
|
getDays(targetDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getPrevMonth() {
|
public void getPrevMonth() {
|
||||||
updateCalendar(targetDate.minusMonths(1));
|
updateCalendar(mTargetDate.minusMonths(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getNextMonth() {
|
public void getNextMonth() {
|
||||||
updateCalendar(targetDate.plusMonths(1));
|
updateCalendar(mTargetDate.plusMonths(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDays(DateTime targetDate) {
|
private void getDays(DateTime targetDate) {
|
||||||
|
@ -63,17 +63,17 @@ public class CalendarImpl {
|
||||||
value++;
|
value++;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.updateCalendar(getMonthName(), days);
|
mCallback.updateCalendar(getMonthName(), days);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isToday(DateTime targetDate, int curDayInMonth) {
|
private boolean isToday(DateTime targetDate, int curDayInMonth) {
|
||||||
return targetDate.withDayOfMonth(curDayInMonth).toString(DATE_PATTERN).equals(today);
|
return targetDate.withDayOfMonth(curDayInMonth).toString(DATE_PATTERN).equals(mToday);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMonthName() {
|
private String getMonthName() {
|
||||||
final String[] months = new DateFormatSymbols().getMonths();
|
final String[] months = new DateFormatSymbols().getMonths();
|
||||||
String month = (months[targetDate.getMonthOfYear() - 1]);
|
String month = (months[mTargetDate.getMonthOfYear() - 1]);
|
||||||
final String targetYear = targetDate.toString(YEAR_PATTERN);
|
final String targetYear = mTargetDate.toString(YEAR_PATTERN);
|
||||||
if (!targetYear.equals(new DateTime().toString(YEAR_PATTERN))) {
|
if (!targetYear.equals(new DateTime().toString(YEAR_PATTERN))) {
|
||||||
month += " " + targetYear;
|
month += " " + targetYear;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,6 @@ public class CalendarImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getTargetDate() {
|
public DateTime getTargetDate() {
|
||||||
return targetDate;
|
return mTargetDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
package com.simplemobiletools.calendar;
|
package com.simplemobiletools.calendar;
|
||||||
|
|
||||||
public class Day {
|
public class Day {
|
||||||
private final int value;
|
private final int mValue;
|
||||||
private final boolean isThisMonth;
|
private final boolean mIsThisMonth;
|
||||||
private final boolean isToday;
|
private final boolean mIsToday;
|
||||||
|
|
||||||
public Day(int value, boolean isThisMonth, boolean isToday) {
|
public Day(int value, boolean isThisMonth, boolean isToday) {
|
||||||
this.value = value;
|
this.mValue = value;
|
||||||
this.isThisMonth = isThisMonth;
|
this.mIsThisMonth = isThisMonth;
|
||||||
this.isToday = isToday;
|
this.mIsToday = isToday;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsThisMonth() {
|
public boolean getIsThisMonth() {
|
||||||
return isThisMonth;
|
return mIsThisMonth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsToday() {
|
public boolean getIsToday() {
|
||||||
return isToday;
|
return mIsToday;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,246 +0,0 @@
|
||||||
package com.simplemobiletools.calendar;
|
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.SeekBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindDimen;
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
import yuku.ambilwarna.AmbilWarnaDialog;
|
|
||||||
|
|
||||||
public class MyWidgetConfigure extends AppCompatActivity implements Calendar {
|
|
||||||
@BindView(R.id.left_arrow) ImageView leftArrow;
|
|
||||||
@BindView(R.id.right_arrow) ImageView rightArrow;
|
|
||||||
@BindView(R.id.table_month) TextView monthTV;
|
|
||||||
@BindView(R.id.config_bg_color) View bgColorPicker;
|
|
||||||
@BindView(R.id.config_bg_seekbar) SeekBar bgSeekBar;
|
|
||||||
@BindView(R.id.config_text_color) View textColorPicker;
|
|
||||||
@BindView(R.id.config_calendar) View widgetBackground;
|
|
||||||
@BindView(R.id.config_save) Button saveBtn;
|
|
||||||
@BindDimen(R.dimen.day_text_size) float dayTextSize;
|
|
||||||
@BindDimen(R.dimen.today_text_size) float todayTextSize;
|
|
||||||
|
|
||||||
private int widgetId;
|
|
||||||
private CalendarImpl calendar;
|
|
||||||
private Resources res;
|
|
||||||
private String packageName;
|
|
||||||
private List<Day> days;
|
|
||||||
private int bgColorWithoutTransparency;
|
|
||||||
private int bgColor;
|
|
||||||
private float bgAlpha;
|
|
||||||
|
|
||||||
private int textColorWithoutTransparency;
|
|
||||||
private int textColor;
|
|
||||||
private int weakTextColor;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
setContentView(R.layout.widget_config);
|
|
||||||
ButterKnife.bind(this);
|
|
||||||
initVariables();
|
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
|
||||||
final Bundle extras = intent.getExtras();
|
|
||||||
if (extras != null)
|
|
||||||
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
||||||
|
|
||||||
if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initVariables() {
|
|
||||||
res = getResources();
|
|
||||||
packageName = getPackageName();
|
|
||||||
dayTextSize /= res.getDisplayMetrics().density;
|
|
||||||
todayTextSize /= res.getDisplayMetrics().density;
|
|
||||||
|
|
||||||
final SharedPreferences prefs = initPrefs(this);
|
|
||||||
textColorWithoutTransparency = prefs.getInt(Constants.WIDGET_TEXT_COLOR, getResources().getColor(R.color.colorPrimary));
|
|
||||||
updateTextColors();
|
|
||||||
|
|
||||||
bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 1);
|
|
||||||
if (bgColor == 1) {
|
|
||||||
bgColor = Color.BLACK;
|
|
||||||
bgAlpha = .2f;
|
|
||||||
} else {
|
|
||||||
bgAlpha = Color.alpha(bgColor) / (float) 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
bgColorWithoutTransparency = Color.rgb(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
|
|
||||||
bgSeekBar.setOnSeekBarChangeListener(bgSeekbarChangeListener);
|
|
||||||
bgSeekBar.setProgress((int) (bgAlpha * 100));
|
|
||||||
updateBgColor();
|
|
||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
|
||||||
calendar.updateCalendar(new DateTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
private SharedPreferences initPrefs(Context context) {
|
|
||||||
return context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.config_save)
|
|
||||||
public void saveConfig() {
|
|
||||||
storeWidgetColors();
|
|
||||||
requestWidgetUpdate();
|
|
||||||
|
|
||||||
final Intent resultValue = new Intent();
|
|
||||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
|
|
||||||
setResult(RESULT_OK, resultValue);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeWidgetColors() {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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)
|
|
||||||
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) {
|
|
||||||
textColorWithoutTransparency = color;
|
|
||||||
updateTextColors();
|
|
||||||
updateDays();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requestWidgetUpdate() {
|
|
||||||
final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider.class);
|
|
||||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{widgetId});
|
|
||||||
sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTextColors() {
|
|
||||||
textColor = Helpers.adjustAlpha(textColorWithoutTransparency, Constants.HIGH_ALPHA);
|
|
||||||
weakTextColor = Helpers.adjustAlpha(textColorWithoutTransparency, Constants.LOW_ALPHA);
|
|
||||||
|
|
||||||
leftArrow.getDrawable().mutate().setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP);
|
|
||||||
rightArrow.getDrawable().mutate().setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP);
|
|
||||||
monthTV.setTextColor(textColor);
|
|
||||||
textColorPicker.setBackgroundColor(textColor);
|
|
||||||
saveBtn.setTextColor(textColor);
|
|
||||||
updateLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBgColor() {
|
|
||||||
bgColor = Helpers.adjustAlpha(bgColorWithoutTransparency, bgAlpha);
|
|
||||||
widgetBackground.setBackgroundColor(bgColor);
|
|
||||||
bgColorPicker.setBackgroundColor(bgColor);
|
|
||||||
saveBtn.setBackgroundColor(bgColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDays() {
|
|
||||||
final int len = days.size();
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
final Day day = days.get(i);
|
|
||||||
final TextView dayTV = (TextView) findViewById(res.getIdentifier("day_" + i, "id", packageName));
|
|
||||||
int curTextColor = weakTextColor;
|
|
||||||
float curTextSize = dayTextSize;
|
|
||||||
|
|
||||||
if (day.getIsThisMonth()) {
|
|
||||||
curTextColor = textColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (day.getIsToday()) {
|
|
||||||
curTextSize = todayTextSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
dayTV.setText(String.valueOf(day.getValue()));
|
|
||||||
dayTV.setTextColor(curTextColor);
|
|
||||||
dayTV.setTextSize(curTextSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
public void leftArrowClicked() {
|
|
||||||
calendar.getPrevMonth();
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnClick(R.id.right_arrow)
|
|
||||||
public void rightArrowClicked() {
|
|
||||||
calendar.getNextMonth();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateCalendar(String month, List<Day> days) {
|
|
||||||
this.days = days;
|
|
||||||
updateMonth(month);
|
|
||||||
updateDays();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateMonth(String month) {
|
|
||||||
monthTV.setText(month);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLabels() {
|
|
||||||
for (int i = 0; i < 7; i++) {
|
|
||||||
final TextView dayTV = (TextView) findViewById(res.getIdentifier("label_" + i, "id", packageName));
|
|
||||||
dayTV.setTextSize(dayTextSize);
|
|
||||||
dayTV.setTextColor(weakTextColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,16 +27,17 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
private static final String PREV = "prev";
|
private static final String PREV = "prev";
|
||||||
private static final String NEXT = "next";
|
private static final String NEXT = "next";
|
||||||
|
|
||||||
private static RemoteViews remoteViews;
|
private static RemoteViews mRemoteViews;
|
||||||
private static AppWidgetManager widgetManager;
|
private static AppWidgetManager mWidgetManager;
|
||||||
private static Intent intent;
|
private static Intent mIntent;
|
||||||
private static Context cxt;
|
private static Context mContext;
|
||||||
private static CalendarImpl calendar;
|
private static CalendarImpl mCalendar;
|
||||||
private static Resources res;
|
private static Resources mRes;
|
||||||
private static float dayTextSize;
|
|
||||||
private static float todayTextSize;
|
private static float mDayTextSize;
|
||||||
private static int textColor;
|
private static float mTodayTextSize;
|
||||||
private static int weakTextColor;
|
private static int mTextColor;
|
||||||
|
private static int mWeakTextColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
|
@ -46,46 +47,46 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initVariables(Context context) {
|
private void initVariables(Context context) {
|
||||||
cxt = context;
|
mContext = context;
|
||||||
res = cxt.getResources();
|
mRes = mContext.getResources();
|
||||||
|
|
||||||
final SharedPreferences prefs = initPrefs(cxt);
|
final SharedPreferences prefs = initPrefs(mContext);
|
||||||
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);
|
mTextColor = Helpers.adjustAlpha(storedTextColor, Constants.HIGH_ALPHA);
|
||||||
weakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
mWeakTextColor = Helpers.adjustAlpha(storedTextColor, Constants.LOW_ALPHA);
|
||||||
|
|
||||||
dayTextSize = res.getDimension(R.dimen.day_text_size) / res.getDisplayMetrics().density;
|
mDayTextSize = mRes.getDimension(R.dimen.day_text_size) / mRes.getDisplayMetrics().density;
|
||||||
todayTextSize = res.getDimension(R.dimen.today_text_size) / res.getDisplayMetrics().density;
|
mTodayTextSize = mRes.getDimension(R.dimen.today_text_size) / mRes.getDisplayMetrics().density;
|
||||||
widgetManager = AppWidgetManager.getInstance(cxt);
|
mWidgetManager = AppWidgetManager.getInstance(mContext);
|
||||||
|
|
||||||
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.activity_main);
|
mRemoteViews = new RemoteViews(mContext.getPackageName(), R.layout.activity_main);
|
||||||
intent = new Intent(cxt, MyWidgetProvider.class);
|
mIntent = new Intent(mContext, MyWidgetProvider.class);
|
||||||
setupButtons();
|
setupButtons();
|
||||||
updateLabelColor();
|
updateLabelColor();
|
||||||
updateTopViews();
|
updateTopViews();
|
||||||
|
|
||||||
final int bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, Color.BLACK);
|
final int bgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, Color.BLACK);
|
||||||
remoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", bgColor);
|
mRemoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", bgColor);
|
||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
mCalendar = new CalendarImpl(this);
|
||||||
calendar.updateCalendar(new DateTime());
|
mCalendar.updateCalendar(new DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWidget() {
|
private void updateWidget() {
|
||||||
final ComponentName thisWidget = new ComponentName(cxt, MyWidgetProvider.class);
|
final ComponentName thisWidget = new ComponentName(mContext, MyWidgetProvider.class);
|
||||||
AppWidgetManager.getInstance(cxt).updateAppWidget(thisWidget, remoteViews);
|
AppWidgetManager.getInstance(mContext).updateAppWidget(thisWidget, mRemoteViews);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIntent(String action, int id) {
|
private void setupIntent(String action, int id) {
|
||||||
intent.setAction(action);
|
mIntent.setAction(action);
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent, 0);
|
||||||
remoteViews.setOnClickPendingIntent(id, pendingIntent);
|
mRemoteViews.setOnClickPendingIntent(id, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupAppOpenIntent(int id) {
|
private void setupAppOpenIntent(int id) {
|
||||||
final Intent intent = new Intent(cxt, MainActivity.class);
|
final Intent intent = new Intent(mContext, MainActivity.class);
|
||||||
final PendingIntent pendingIntent = PendingIntent.getActivity(cxt, 0, intent, 0);
|
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
|
||||||
remoteViews.setOnClickPendingIntent(id, pendingIntent);
|
mRemoteViews.setOnClickPendingIntent(id, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupButtons() {
|
private void setupButtons() {
|
||||||
|
@ -100,16 +101,16 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (remoteViews == null || widgetManager == null || calendar == null || cxt == null)
|
if (mRemoteViews == null || mWidgetManager == null || mCalendar == null || mContext == null)
|
||||||
initVariables(context);
|
initVariables(context);
|
||||||
|
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PREV:
|
case PREV:
|
||||||
calendar.getPrevMonth();
|
mCalendar.getPrevMonth();
|
||||||
break;
|
break;
|
||||||
case NEXT:
|
case NEXT:
|
||||||
calendar.getNextMonth();
|
mCalendar.getNextMonth();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
|
@ -117,40 +118,40 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDays(List<Day> days) {
|
public void updateDays(List<Day> days) {
|
||||||
final String packageName = cxt.getPackageName();
|
final String packageName = mContext.getPackageName();
|
||||||
final int len = days.size();
|
final int len = days.size();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
final Day day = days.get(i);
|
final Day day = days.get(i);
|
||||||
final int id = res.getIdentifier("day_" + i, "id", packageName);
|
final int id = mRes.getIdentifier("day_" + i, "id", packageName);
|
||||||
int curTextColor = weakTextColor;
|
int curTextColor = mWeakTextColor;
|
||||||
float curTextSize = dayTextSize;
|
float curTextSize = mDayTextSize;
|
||||||
|
|
||||||
if (day.getIsThisMonth()) {
|
if (day.getIsThisMonth()) {
|
||||||
curTextColor = textColor;
|
curTextColor = mTextColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (day.getIsToday()) {
|
if (day.getIsToday()) {
|
||||||
curTextSize = todayTextSize;
|
curTextSize = mTodayTextSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteViews.setTextViewText(id, String.valueOf(day.getValue()));
|
mRemoteViews.setTextViewText(id, String.valueOf(day.getValue()));
|
||||||
remoteViews.setInt(id, "setTextColor", curTextColor);
|
mRemoteViews.setInt(id, "setTextColor", curTextColor);
|
||||||
remoteViews.setFloat(id, "setTextSize", curTextSize);
|
mRemoteViews.setFloat(id, "setTextSize", curTextSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTopViews() {
|
private void updateTopViews() {
|
||||||
remoteViews.setInt(R.id.table_month, "setTextColor", textColor);
|
mRemoteViews.setInt(R.id.table_month, "setTextColor", mTextColor);
|
||||||
|
|
||||||
Bitmap bmp = getColoredIcon(cxt, textColor, R.mipmap.arrow_left);
|
Bitmap bmp = getColoredIcon(mContext, mTextColor, R.mipmap.arrow_left);
|
||||||
remoteViews.setImageViewBitmap(R.id.left_arrow, bmp);
|
mRemoteViews.setImageViewBitmap(R.id.left_arrow, bmp);
|
||||||
|
|
||||||
bmp = getColoredIcon(cxt, textColor, R.mipmap.arrow_right);
|
bmp = getColoredIcon(mContext, mTextColor, R.mipmap.arrow_right);
|
||||||
remoteViews.setImageViewBitmap(R.id.right_arrow, bmp);
|
mRemoteViews.setImageViewBitmap(R.id.right_arrow, bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMonth(String month) {
|
public void updateMonth(String month) {
|
||||||
remoteViews.setTextViewText(R.id.table_month, month);
|
mRemoteViews.setTextViewText(R.id.table_month, month);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,10 +162,10 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLabelColor() {
|
private void updateLabelColor() {
|
||||||
final String packageName = cxt.getPackageName();
|
final String packageName = mContext.getPackageName();
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
final int id = res.getIdentifier("label_" + i, "id", packageName);
|
final int id = mRes.getIdentifier("label_" + i, "id", packageName);
|
||||||
remoteViews.setInt(id, "setTextColor", weakTextColor);
|
mRemoteViews.setInt(id, "setTextColor", mWeakTextColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.simplemobiletools.calendar.BuildConfig;
|
import com.simplemobiletools.calendar.BuildConfig;
|
||||||
import com.simplemobiletools.calendar.R;
|
import com.simplemobiletools.calendar.R;
|
||||||
import com.simplemobiletools.calendar.activities.LicenseActivity;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
@ -19,17 +18,18 @@ import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class AboutActivity extends AppCompatActivity {
|
public class AboutActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.about_copyright) TextView copyright;
|
@BindView(R.id.about_copyright) TextView mCopyright;
|
||||||
@BindView(R.id.about_version) TextView version;
|
@BindView(R.id.about_version) TextView mVersion;
|
||||||
@BindView(R.id.about_email) TextView emailTV;
|
@BindView(R.id.about_email) TextView mEmailTV;
|
||||||
private Resources res;
|
|
||||||
|
private static Resources mRes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
res = getResources();
|
mRes = getResources();
|
||||||
|
|
||||||
setupEmail();
|
setupEmail();
|
||||||
setupVersion();
|
setupVersion();
|
||||||
|
@ -37,23 +37,23 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupEmail() {
|
private void setupEmail() {
|
||||||
final String email = res.getString(R.string.email);
|
final String email = mRes.getString(R.string.email);
|
||||||
final String appName = res.getString(R.string.app_name);
|
final String appName = mRes.getString(R.string.app_name);
|
||||||
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
||||||
emailTV.setText(Html.fromHtml(href));
|
mEmailTV.setText(Html.fromHtml(href));
|
||||||
emailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
mEmailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupVersion() {
|
private void setupVersion() {
|
||||||
final String versionName = BuildConfig.VERSION_NAME;
|
final String versionName = BuildConfig.VERSION_NAME;
|
||||||
final String versionText = String.format(res.getString(R.string.version), versionName);
|
final String versionText = String.format(mRes.getString(R.string.version), versionName);
|
||||||
version.setText(versionText);
|
mVersion.setText(versionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCopyright() {
|
private void setupCopyright() {
|
||||||
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
||||||
final String copyrightText = String.format(res.getString(R.string.copyright), year);
|
final String copyrightText = String.format(mRes.getString(R.string.copyright), year);
|
||||||
copyright.setText(copyrightText);
|
mCopyright.setText(copyrightText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.about_license)
|
@OnClick(R.id.about_license)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class LicenseActivity extends AppCompatActivity {
|
public class LicenseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -9,7 +9,6 @@ import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
|
@ -36,19 +35,21 @@ import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements Calendar {
|
public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
@BindView(R.id.left_arrow) ImageView leftArrow;
|
@BindView(R.id.left_arrow) ImageView mLeftArrow;
|
||||||
@BindView(R.id.right_arrow) ImageView rightArrow;
|
@BindView(R.id.right_arrow) ImageView mRightArrow;
|
||||||
@BindView(R.id.table_month) TextView monthTV;
|
@BindView(R.id.table_month) TextView mMonthTV;
|
||||||
@BindView(R.id.calendar_holder) View calendarHolder;
|
@BindView(R.id.calendar_holder) View mCalendarHolder;
|
||||||
@BindDimen(R.dimen.day_text_size) float dayTextSize;
|
|
||||||
@BindDimen(R.dimen.today_text_size) float todayTextSize;
|
|
||||||
@BindDimen(R.dimen.activity_margin) int activityMargin;
|
|
||||||
|
|
||||||
private CalendarImpl calendar;
|
@BindDimen(R.dimen.day_text_size) float mDayTextSize;
|
||||||
private Resources res;
|
@BindDimen(R.dimen.today_text_size) float mTodayTextSize;
|
||||||
private String packageName;
|
@BindDimen(R.dimen.activity_margin) int mActivityMargin;
|
||||||
private int textColor;
|
|
||||||
private int weakTextColor;
|
private CalendarImpl mCalendar;
|
||||||
|
private Resources mRes;
|
||||||
|
private String mPackageName;
|
||||||
|
|
||||||
|
private int mTextColor;
|
||||||
|
private int mWeakTextColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -57,28 +58,27 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
Locale.setDefault(Locale.ENGLISH);
|
Locale.setDefault(Locale.ENGLISH);
|
||||||
textColor = Helpers.adjustAlpha(Color.BLACK, Constants.HIGH_ALPHA);
|
mTextColor = Helpers.adjustAlpha(Color.BLACK, Constants.HIGH_ALPHA);
|
||||||
weakTextColor = Helpers.adjustAlpha(Color.BLACK, Constants.LOW_ALPHA);
|
mWeakTextColor = Helpers.adjustAlpha(Color.BLACK, Constants.LOW_ALPHA);
|
||||||
leftArrow.getDrawable().mutate().setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP);
|
mLeftArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||||
rightArrow.getDrawable().mutate().setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP);
|
mRightArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
|
||||||
res = getResources();
|
mRes = getResources();
|
||||||
packageName = getPackageName();
|
mPackageName = getPackageName();
|
||||||
dayTextSize /= res.getDisplayMetrics().density;
|
mDayTextSize /= mRes.getDisplayMetrics().density;
|
||||||
todayTextSize /= res.getDisplayMetrics().density;
|
mTodayTextSize /= mRes.getDisplayMetrics().density;
|
||||||
setupLabels();
|
setupLabels();
|
||||||
|
|
||||||
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) calendarHolder.getLayoutParams();
|
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mCalendarHolder.getLayoutParams();
|
||||||
params.setMargins(activityMargin, activityMargin, activityMargin, activityMargin);
|
params.setMargins(mActivityMargin, mActivityMargin, mActivityMargin, mActivityMargin);
|
||||||
|
|
||||||
calendar = new CalendarImpl(this);
|
mCalendar = new CalendarImpl(this);
|
||||||
calendar.updateCalendar(new DateTime());
|
mCalendar.updateCalendar(new DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
getMenuInflater().inflate(R.menu.menu, menu);
|
||||||
inflater.inflate(R.menu.menu, menu);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,16 +99,16 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
final Day day = days.get(i);
|
final Day day = days.get(i);
|
||||||
final TextView dayTV = (TextView) findViewById(res.getIdentifier("day_" + i, "id", packageName));
|
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("day_" + i, "id", mPackageName));
|
||||||
int curTextColor = weakTextColor;
|
int curTextColor = mWeakTextColor;
|
||||||
float curTextSize = dayTextSize;
|
float curTextSize = mDayTextSize;
|
||||||
|
|
||||||
if (day.getIsThisMonth()) {
|
if (day.getIsThisMonth()) {
|
||||||
curTextColor = textColor;
|
curTextColor = mTextColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (day.getIsToday()) {
|
if (day.getIsToday()) {
|
||||||
curTextSize = todayTextSize;
|
curTextSize = mTodayTextSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
dayTV.setText(String.valueOf(day.getValue()));
|
dayTV.setText(String.valueOf(day.getValue()));
|
||||||
|
@ -119,12 +119,12 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
|
|
||||||
@OnClick(R.id.left_arrow)
|
@OnClick(R.id.left_arrow)
|
||||||
public void leftArrowClicked() {
|
public void leftArrowClicked() {
|
||||||
calendar.getPrevMonth();
|
mCalendar.getPrevMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.right_arrow)
|
@OnClick(R.id.right_arrow)
|
||||||
public void rightArrowClicked() {
|
public void rightArrowClicked() {
|
||||||
calendar.getNextMonth();
|
mCalendar.getNextMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.table_month)
|
@OnClick(R.id.table_month)
|
||||||
|
@ -134,7 +134,7 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
final DatePicker datePicker = (DatePicker) view.findViewById(R.id.date_picker);
|
final DatePicker datePicker = (DatePicker) view.findViewById(R.id.date_picker);
|
||||||
hideDayPicker(datePicker);
|
hideDayPicker(datePicker);
|
||||||
|
|
||||||
final DateTime dateTime = new DateTime(calendar.getTargetDate().toString());
|
final DateTime dateTime = new DateTime(mCalendar.getTargetDate().toString());
|
||||||
datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, 1, null);
|
datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, 1, null);
|
||||||
|
|
||||||
alertDialog.setView(view);
|
alertDialog.setView(view);
|
||||||
|
@ -142,7 +142,7 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final int month = datePicker.getMonth() + 1;
|
final int month = datePicker.getMonth() + 1;
|
||||||
final int year = datePicker.getYear();
|
final int year = datePicker.getYear();
|
||||||
calendar.updateCalendar(new DateTime().withMonthOfYear(month).withYear(year));
|
mCalendar.updateCalendar(new DateTime().withMonthOfYear(month).withYear(year));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -162,15 +162,15 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMonth(String month) {
|
private void updateMonth(String month) {
|
||||||
monthTV.setText(month);
|
mMonthTV.setText(month);
|
||||||
monthTV.setTextColor(textColor);
|
mMonthTV.setTextColor(mTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLabels() {
|
private void setupLabels() {
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
final TextView dayTV = (TextView) findViewById(res.getIdentifier("label_" + i, "id", packageName));
|
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("label_" + i, "id", mPackageName));
|
||||||
dayTV.setTextSize(dayTextSize);
|
dayTV.setTextSize(mDayTextSize);
|
||||||
dayTV.setTextColor(weakTextColor);
|
dayTV.setTextColor(mWeakTextColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,255 @@
|
||||||
|
package com.simplemobiletools.calendar.activities;
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.calendar.Calendar;
|
||||||
|
import com.simplemobiletools.calendar.CalendarImpl;
|
||||||
|
import com.simplemobiletools.calendar.Constants;
|
||||||
|
import com.simplemobiletools.calendar.Day;
|
||||||
|
import com.simplemobiletools.calendar.Helpers;
|
||||||
|
import com.simplemobiletools.calendar.MyWidgetProvider;
|
||||||
|
import com.simplemobiletools.calendar.R;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindDimen;
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import yuku.ambilwarna.AmbilWarnaDialog;
|
||||||
|
|
||||||
|
public class WidgetConfigureActivity extends AppCompatActivity implements Calendar {
|
||||||
|
@BindView(R.id.left_arrow) ImageView mLeftArrow;
|
||||||
|
@BindView(R.id.right_arrow) ImageView mRightArrow;
|
||||||
|
@BindView(R.id.table_month) TextView mMonthTV;
|
||||||
|
@BindView(R.id.config_bg_color) View mBgColorPicker;
|
||||||
|
@BindView(R.id.config_bg_seekbar) SeekBar mBgSeekBar;
|
||||||
|
@BindView(R.id.config_text_color) View mTextColorPicker;
|
||||||
|
@BindView(R.id.config_calendar) View mWidgetBackground;
|
||||||
|
@BindView(R.id.config_save) Button mSaveBtn;
|
||||||
|
|
||||||
|
@BindDimen(R.dimen.day_text_size) float mDayTextSize;
|
||||||
|
@BindDimen(R.dimen.today_text_size) float mTodayTextSize;
|
||||||
|
|
||||||
|
private static CalendarImpl mCalendar;
|
||||||
|
private static Resources mRes;
|
||||||
|
private static String mPackageName;
|
||||||
|
private List<Day> mDays;
|
||||||
|
|
||||||
|
private float mBgAlpha;
|
||||||
|
private int mWidgetId;
|
||||||
|
private int mBgColorWithoutTransparency;
|
||||||
|
private int mBgColor;
|
||||||
|
private int mTextColorWithoutTransparency;
|
||||||
|
private int mTextColor;
|
||||||
|
private int mWeakTextColor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
setContentView(R.layout.widget_config);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
initVariables();
|
||||||
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
final Bundle extras = intent.getExtras();
|
||||||
|
if (extras != null)
|
||||||
|
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||||
|
|
||||||
|
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initVariables() {
|
||||||
|
mRes = getResources();
|
||||||
|
mPackageName = getPackageName();
|
||||||
|
mDayTextSize /= mRes.getDisplayMetrics().density;
|
||||||
|
mTodayTextSize /= mRes.getDisplayMetrics().density;
|
||||||
|
|
||||||
|
final SharedPreferences prefs = initPrefs(this);
|
||||||
|
mTextColorWithoutTransparency = prefs.getInt(Constants.WIDGET_TEXT_COLOR, getResources().getColor(R.color.colorPrimary));
|
||||||
|
updateTextColors();
|
||||||
|
|
||||||
|
mBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 1);
|
||||||
|
if (mBgColor == 1) {
|
||||||
|
mBgColor = Color.BLACK;
|
||||||
|
mBgAlpha = .2f;
|
||||||
|
} else {
|
||||||
|
mBgAlpha = Color.alpha(mBgColor) / (float) 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
mBgColorWithoutTransparency = Color.rgb(Color.red(mBgColor), Color.green(mBgColor), Color.blue(mBgColor));
|
||||||
|
mBgSeekBar.setOnSeekBarChangeListener(bgSeekbarChangeListener);
|
||||||
|
mBgSeekBar.setProgress((int) (mBgAlpha * 100));
|
||||||
|
updateBgColor();
|
||||||
|
|
||||||
|
mCalendar = new CalendarImpl(this);
|
||||||
|
mCalendar.updateCalendar(new DateTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
private SharedPreferences initPrefs(Context context) {
|
||||||
|
return context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.config_save)
|
||||||
|
public void saveConfig() {
|
||||||
|
storeWidgetColors();
|
||||||
|
requestWidgetUpdate();
|
||||||
|
|
||||||
|
final Intent resultValue = new Intent();
|
||||||
|
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId);
|
||||||
|
setResult(RESULT_OK, resultValue);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeWidgetColors() {
|
||||||
|
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
||||||
|
prefs.edit().putInt(Constants.WIDGET_BG_COLOR, mBgColor).apply();
|
||||||
|
prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, mTextColorWithoutTransparency).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.config_bg_color)
|
||||||
|
public void pickBackgroundColor() {
|
||||||
|
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, mBgColorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(AmbilWarnaDialog dialog) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOk(AmbilWarnaDialog dialog, int color) {
|
||||||
|
mBgColorWithoutTransparency = color;
|
||||||
|
updateBgColor();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.config_text_color)
|
||||||
|
public void pickTextColor() {
|
||||||
|
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, mTextColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(AmbilWarnaDialog dialog) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOk(AmbilWarnaDialog dialog, int color) {
|
||||||
|
mTextColorWithoutTransparency = color;
|
||||||
|
updateTextColors();
|
||||||
|
updateDays();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestWidgetUpdate() {
|
||||||
|
final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider.class);
|
||||||
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{mWidgetId});
|
||||||
|
sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTextColors() {
|
||||||
|
mTextColor = Helpers.adjustAlpha(mTextColorWithoutTransparency, Constants.HIGH_ALPHA);
|
||||||
|
mWeakTextColor = Helpers.adjustAlpha(mTextColorWithoutTransparency, Constants.LOW_ALPHA);
|
||||||
|
|
||||||
|
mLeftArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
mRightArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
mMonthTV.setTextColor(mTextColor);
|
||||||
|
mTextColorPicker.setBackgroundColor(mTextColor);
|
||||||
|
mSaveBtn.setTextColor(mTextColor);
|
||||||
|
updateLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBgColor() {
|
||||||
|
mBgColor = Helpers.adjustAlpha(mBgColorWithoutTransparency, mBgAlpha);
|
||||||
|
mWidgetBackground.setBackgroundColor(mBgColor);
|
||||||
|
mBgColorPicker.setBackgroundColor(mBgColor);
|
||||||
|
mSaveBtn.setBackgroundColor(mBgColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDays() {
|
||||||
|
final int len = mDays.size();
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
final Day day = mDays.get(i);
|
||||||
|
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("day_" + i, "id", mPackageName));
|
||||||
|
int curTextColor = mWeakTextColor;
|
||||||
|
float curTextSize = mDayTextSize;
|
||||||
|
|
||||||
|
if (day.getIsThisMonth()) {
|
||||||
|
curTextColor = mTextColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (day.getIsToday()) {
|
||||||
|
curTextSize = mTodayTextSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
dayTV.setText(String.valueOf(day.getValue()));
|
||||||
|
dayTV.setTextColor(curTextColor);
|
||||||
|
dayTV.setTextSize(curTextSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SeekBar.OnSeekBarChangeListener bgSeekbarChangeListener = new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
mBgAlpha = (float) progress / (float) 100;
|
||||||
|
updateBgColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@OnClick(R.id.left_arrow)
|
||||||
|
public void leftArrowClicked() {
|
||||||
|
mCalendar.getPrevMonth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.right_arrow)
|
||||||
|
public void rightArrowClicked() {
|
||||||
|
mCalendar.getNextMonth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCalendar(String month, List<Day> days) {
|
||||||
|
this.mDays = days;
|
||||||
|
updateMonth(month);
|
||||||
|
updateDays();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMonth(String month) {
|
||||||
|
mMonthTV.setText(month);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLabels() {
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("label_" + i, "id", mPackageName));
|
||||||
|
dayTV.setTextSize(mDayTextSize);
|
||||||
|
dayTV.setTextColor(mWeakTextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:configure="com.simplemobiletools.calendar.MyWidgetConfigure"
|
android:configure="com.simplemobiletools.calendar.activities.WidgetConfigureActivity"
|
||||||
android:initialLayout="@layout/activity_main"
|
android:initialLayout="@layout/activity_main"
|
||||||
android:minHeight="250dp"
|
android:minHeight="250dp"
|
||||||
android:minWidth="250dp"
|
android:minWidth="250dp"
|
||||||
|
|
Loading…
Reference in New Issue