handle widget properly too

This commit is contained in:
tibbi 2016-09-09 20:32:17 +02:00
parent 9d62e7710c
commit b5be24fb91
5 changed files with 31 additions and 10 deletions

View File

@ -45,7 +45,9 @@ public class CalendarImpl implements DBHelper.DBOperationsListener {
final List<Day> days = new ArrayList<>(DAYS_CNT);
final int currMonthDays = mTargetDate.dayOfMonth().getMaximumValue();
final int firstDayIndex = mTargetDate.withDayOfMonth(1).getDayOfWeek() - 1;
int firstDayIndex = mTargetDate.withDayOfMonth(1).getDayOfWeek();
if (!Config.newInstance(mContext).getIsSundayFirst())
firstDayIndex -= 1;
final int prevMonthDays = mTargetDate.minusMonths(1).dayOfMonth().getMaximumValue();
boolean isThisMonth = false;

View File

@ -182,10 +182,18 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
}
private void updateLabelColor() {
final boolean mSundayFirst = Config.newInstance(mContext).getIsSundayFirst();
final String packageName = mContext.getPackageName();
int letters[] = Utils.getLetterIDs();
for (int i = 0; i < 7; i++) {
final int id = mRes.getIdentifier("label_" + i, "id", packageName);
mRemoteViews.setInt(id, "setTextColor", mWeakTextColor);
int index = i;
if (!mSundayFirst)
index = (index + 1) % letters.length;
mRemoteViews.setTextViewText(id, mContext.getResources().getString(letters[index]));
}
}

View File

@ -42,4 +42,9 @@ public class Utils {
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, notifInMs, pendingIntent);
}
public static int[] getLetterIDs() {
return new int[]{R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter};
}
}

View File

@ -223,8 +223,7 @@ public class MainActivity extends SimpleActivity implements Calendar {
}
private void setupLabels() {
int letters[] = {R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter};
int letters[] = Utils.getLetterIDs();
for (int i = 0; i < 7; i++) {
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("label_" + i, "id", mPackageName));

View File

@ -11,48 +11,55 @@
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/monday_letter"/>
<TextView
android:id="@+id/label_1"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/tuesday_letter"/>
<TextView
android:id="@+id/label_2"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/wednesday_letter"/>
<TextView
android:id="@+id/label_3"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/thursday_letter"/>
<TextView
android:id="@+id/label_4"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/friday_letter"/>
<TextView
android:id="@+id/label_5"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/saturday_letter"/>
<TextView
android:id="@+id/label_6"
style="@style/DayView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1"
android:text="@string/sunday_letter"/>
</LinearLayout>