Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 997c081a authored by Annie Chin's avatar Annie Chin Committed by Android (Google) Code Review
Browse files

Merge "Refactor DaysOfWeek to receive firstday as an argument." into ub-deskclock-army

parents 42335aaa 15734572
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -682,8 +682,9 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements
            for (int i = 0; i < 7; i++) {
                final CompoundButton dayButton = (CompoundButton) mFactory.inflate(
                        R.layout.day_button, holder.repeatDays, false /* attachToRoot */);
                dayButton.setText(Utils.getShortWeekday(mContext, i));
                dayButton.setContentDescription(Utils.getLongWeekday(mContext, i));
                final int firstDay = Utils.getZeroIndexedFirstDayOfWeek(mContext);
                dayButton.setText(Utils.getShortWeekday(i, firstDay));
                dayButton.setContentDescription(Utils.getLongWeekday(i, firstDay));
                holder.repeatDays.addView(dayButton);
                holder.dayButtons[i] = dayButton;
            }
@@ -786,11 +787,11 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements

            // Set the repeat text or leave it blank if it does not repeat.
            final String daysOfWeekStr =
                    alarm.daysOfWeek.toString(AlarmClockFragment.this.getActivity());
                    alarm.daysOfWeek.toString(context, Utils.getFirstDayOfWeek(context));
            if (daysOfWeekStr != null && daysOfWeekStr.length() != 0) {
                itemHolder.daysOfWeek.setText(daysOfWeekStr);
                itemHolder.daysOfWeek.setContentDescription(alarm.daysOfWeek.toAccessibilityString(
                        AlarmClockFragment.this.getActivity()));
                        context, Utils.getFirstDayOfWeek(context)));
                itemHolder.daysOfWeek.setVisibility(View.VISIBLE);
                itemHolder.daysOfWeek.setOnClickListener(new View.OnClickListener() {
                    @Override
+9 −9
Original line number Diff line number Diff line
@@ -652,21 +652,21 @@ public class Utils {
    }

    /**
     * @param firstDay is the result from getZeroIndexedFirstDayOfWeek
     * @return Single-char version of day name, e.g.: 'S', 'M', 'T', 'W', 'T', 'F', 'S'
     */
    public static String getShortWeekday(Context context, int position) {
        generateShortAndLongWeekdaysIfNeeded(context);
        return sShortWeekdays[(position + getZeroIndexedFirstDayOfWeek(context)) %
                DaysOfWeek.DAYS_IN_A_WEEK];
    public static String getShortWeekday(int position, int firstDay) {
        generateShortAndLongWeekdaysIfNeeded();
        return sShortWeekdays[(position + firstDay) % DaysOfWeek.DAYS_IN_A_WEEK];
    }

    /**
     * @param firstDay is the result from getZeroIndexedFirstDayOfWeek
     * @return Long-version of day name, e.g.: 'Sunday', 'Monday', 'Tuesday', etc
     */
    public static String getLongWeekday(Context context, int position) {
        generateShortAndLongWeekdaysIfNeeded(context);
        return sLongWeekdays[(position + getZeroIndexedFirstDayOfWeek(context)) %
                DaysOfWeek.DAYS_IN_A_WEEK];
    public static String getLongWeekday(int position, int firstDay) {
        generateShortAndLongWeekdaysIfNeeded();
        return sLongWeekdays[(position + firstDay) % DaysOfWeek.DAYS_IN_A_WEEK];
    }

    // Return the first day of the week value corresponding to Calendar.<WEEKDAY> value, which is
@@ -689,7 +689,7 @@ public class Utils {
    /**
     * Generate arrays of short and long weekdays, starting from Sunday
     */
    private static void generateShortAndLongWeekdaysIfNeeded(Context context) {
    private static void generateShortAndLongWeekdaysIfNeeded() {
        if (sShortWeekdays != null && sLongWeekdays != null && !localeHasChanged()) {
            // nothing to do
            return;
+6 −7
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.deskclock.provider;
import android.content.Context;

import com.android.deskclock.R;
import com.android.deskclock.Utils;

import java.text.DateFormatSymbols;
import java.util.Calendar;
@@ -69,15 +68,15 @@ public final class DaysOfWeek {
        mBitSet = bitSet;
    }

    public String toString(Context context) {
        return toString(context, false /* forAccessibility */);
    public String toString(Context context, int firstDay) {
        return toString(context, firstDay, false /* forAccessibility */);
    }

    public String toAccessibilityString(Context context) {
        return toString(context, true /* forAccessibility */);
    public String toAccessibilityString(Context context, int firstDay) {
        return toString(context, firstDay, true /* forAccessibility */);
    }

    private String toString(Context context, boolean forAccessibility) {
    private String toString(Context context, int firstDay, boolean forAccessibility) {
        StringBuilder ret = new StringBuilder();

        // no days
@@ -106,7 +105,7 @@ public final class DaysOfWeek {

        // In this system, Mon = 0, Sun = 6, etc.
        // startDay is stored corresponding to Calendar.DAY_OF_WEEK where Sun = 0, Mon = 2, etc.
        final int startDay = convertDayToBitIndex(Utils.getFirstDayOfWeek(context));
        final int startDay = convertDayToBitIndex(firstDay);

        // selected days, starting from user-selected start day of week
        // iterate starting from user-selected start of day