Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android official alarm clock week style

I'm looking to mimic the week style of the official Android application. Do you know which kind of views are used in this application? Are they custom? Ret

See this screenshot to know what I'm talking about:

See this screenshot to know what I'm talking about

This screenshot is the Alarm part of an alarm clock. What I want to use is the part in red, which displays the weekd in a nice way as small buttons with the name and a small blue/gray bar depending on the status of the button.

like image 811
MagicMicky Avatar asked Jun 01 '13 00:06

MagicMicky


1 Answers

Ok, to answer myself, we can find the source code of the application here : https://android.googlesource.com/platform/packages/apps/DeskClock/+/master/

And these buttons are created programmatically (as mentioned here: https://android.googlesource.com/platform/packages/apps/DeskClock/+/master/res/layout/alarm_time.xml), that way:

        holder.repeatDays = (LinearLayout) view.findViewById(R.id.repeat_days);

        // Build button for each day.
        for (int i = 0; i < 7; i++) {
            final ViewGroup viewgroup = (ViewGroup) mFactory.inflate(R.layout.day_button,
                    holder.repeatDays, false);
            final ToggleButton button = (ToggleButton) viewgroup.getChildAt(0);
            final int dayToShowIndex = DAY_ORDER[i];
            button.setText(mShortWeekDayStrings[dayToShowIndex]);
            button.setTextOn(mShortWeekDayStrings[dayToShowIndex]);
            button.setTextOff(mShortWeekDayStrings[dayToShowIndex]);
            button.setContentDescription(mLongWeekDayStrings[dayToShowIndex]);
            holder.repeatDays.addView(viewgroup);
            holder.dayButtons[i] = button;
            holder.dayButtonParents[i] = viewgroup;
        }

and in R.layout.day_button:

<ToggleButton
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_gravity="center"
    android:padding="0dp"
    style="@style/body"
    android:textColor="@color/clock_gray"
    android:background="@drawable/toggle_underline"
    android:clickable="false"
    android:singleLine="true"/>

So, these are just stylised ToggleButton

I hope it will help someone!

like image 192
MagicMicky Avatar answered Nov 01 '22 17:11

MagicMicky