Layout changes to expanded alarm item. Create ColorStateList for day toggles in code.
This commit is contained in:
parent
52b2f7ed90
commit
331f012190
@ -2,9 +2,11 @@ package com.philliphsu.clock2.alarms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
@ -16,6 +18,7 @@ import com.philliphsu.clock2.Alarm;
|
||||
import com.philliphsu.clock2.DaysOfWeek;
|
||||
import com.philliphsu.clock2.OnListItemInteractionListener;
|
||||
import com.philliphsu.clock2.R;
|
||||
import com.philliphsu.clock2.aospdatetimepicker.Utils;
|
||||
import com.philliphsu.clock2.util.AlarmController;
|
||||
|
||||
import butterknife.Bind;
|
||||
@ -34,6 +37,8 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
|
||||
@Bind({R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6})
|
||||
ToggleButton[] mDays;
|
||||
|
||||
private final ColorStateList mDayToggleColors;
|
||||
|
||||
public ExpandedAlarmViewHolder(ViewGroup parent, final OnListItemInteractionListener<Alarm> listener,
|
||||
AlarmController controller) {
|
||||
super(parent, R.layout.item_expanded_alarm, listener, controller);
|
||||
@ -51,6 +56,24 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
|
||||
listener.onListItemUpdate(getAlarm(), getAdapterPosition());
|
||||
}
|
||||
});
|
||||
|
||||
// https://code.google.com/p/android/issues/detail?id=177282
|
||||
// https://stackoverflow.com/questions/15673449/is-it-confirmed-that-i-cannot-use-themed-color-attribute-in-color-state-list-res
|
||||
// Programmatically create the ColorStateList for our day toggles using themed color
|
||||
// attributes, "since prior to M you can't create a themed ColorStateList from XML but you
|
||||
// can from code." (quote from google)
|
||||
// The first array level is analogous to an XML node defining an item with a state list.
|
||||
// The second level lists all the states considered by the item from the first level.
|
||||
// An empty list of states represents the default stateless item.
|
||||
int[][] states = {
|
||||
/*item 1*/{/*states*/android.R.attr.state_checked},
|
||||
/*item 2*/{/*states*/}
|
||||
};
|
||||
int[] colors = {
|
||||
/*item 1*/Utils.getTextColorFromThemeAttr(getContext(), R.attr.colorAccent),
|
||||
/*item 2*/Utils.getTextColorFromThemeAttr(getContext(), android.R.attr.textColorHint)
|
||||
};
|
||||
mDayToggleColors = new ColorStateList(states, colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,11 +141,13 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
|
||||
@OnCheckedChanged({ R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6 })
|
||||
void onDayToggled() {
|
||||
// TODO
|
||||
Log.d("yooo", "Hello!");
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void bindDays(Alarm alarm) {
|
||||
for (int i = 0; i < mDays.length; i++) {
|
||||
mDays[i].setTextColor(mDayToggleColors);
|
||||
int weekDay = DaysOfWeek.getInstance(getContext()).weekDayAt(i);
|
||||
String label = DaysOfWeek.getLabel(weekDay);
|
||||
mDays[i].setTextOn(label);
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_checked="true" android:color="@color/colorAccent" />
|
||||
<!-- Default state -->
|
||||
<item android:color="@android:color/secondary_text_dark"/>
|
||||
<!-- DEPRECATED -->
|
||||
</selector>
|
||||
@ -11,6 +11,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.AppCompat"
|
||||
android:text="12:00"
|
||||
android:textSize="@dimen/text_size_display_3"
|
||||
android:fontFamily="sans-serif-light"/>
|
||||
|
||||
|
||||
@ -23,11 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?textAppearanceListItem"
|
||||
style="@style/BaseLabel"
|
||||
android:textStyle="bold"
|
||||
android:text="Label"
|
||||
android:layout_below="@id/time_layout"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||
|
||||
@ -35,8 +32,7 @@
|
||||
android:id="@+id/countdown"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?textAppearanceListItem"
|
||||
android:text="in %dh %dm"
|
||||
android:textSize="@dimen/text_size_subhead"
|
||||
android:layout_marginStart="@dimen/item_margin_between_elements"
|
||||
android:layout_below="@id/time_layout"
|
||||
android:layout_toEndOf="@id/label"/>
|
||||
|
||||
@ -17,12 +17,12 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardElevation="2dp"
|
||||
app:cardElevation="@dimen/expanded_alarm_elevation"
|
||||
app:cardCornerRadius="0dp"
|
||||
android:foreground="?selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
android:layout_marginTop="@dimen/cardview_margin"
|
||||
android:layout_marginBottom="@dimen/cardview_margin">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -47,88 +47,40 @@
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/day6"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:background="?selectableItemBackground"
|
||||
android:textColor="@color/toggle_alarm_days"
|
||||
/>
|
||||
style="@style/AlarmDayToggle"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
style="@style/BaseLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:hint="Add label"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_height="@dimen/label_height"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"/>
|
||||
|
||||
@ -136,7 +88,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="8dp">
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements">
|
||||
|
||||
<Button
|
||||
android:id="@+id/ringtone"
|
||||
@ -147,10 +99,11 @@
|
||||
android:text="Ringtone"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"
|
||||
android:textSize="18sp"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:drawableStart="@drawable/ic_ringtone_black_24dp"
|
||||
android:drawablePadding="@dimen/text_compound_drawable_padding"/>
|
||||
|
||||
<!--TODO: See CheckableImageButton-->
|
||||
<CheckBox
|
||||
android:id="@id/vibrate"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@ -60,6 +60,10 @@
|
||||
<!-- TimerViewHolder -->
|
||||
<dimen name="add_one_minute_text_size">18dp</dimen>
|
||||
|
||||
<!--ExpandedAlarmViewHolder-->
|
||||
<dimen name="expanded_alarm_elevation">2dp</dimen> <!--TODO: Increase for v21-->
|
||||
<dimen name="label_height">48dp</dimen>
|
||||
|
||||
<dimen name="text_size_body_1">14sp</dimen>
|
||||
<dimen name="text_size_body_2">14sp</dimen>
|
||||
<dimen name="text_size_button">14sp</dimen>
|
||||
|
||||
@ -166,11 +166,12 @@
|
||||
</style>
|
||||
|
||||
<!--Style for a button that opens an AddLabelDialog-->
|
||||
<style name="BaseLabel" parent="TextAppearance.AppCompat.Subhead">
|
||||
<style name="BaseLabel" parent="TextAppearance.AppCompat">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:hint">@string/label</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:maxLines">1</item>
|
||||
<item name="android:textSize">@dimen/text_size_subhead</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
10
app/src/main/res/values/styles_alarm.xml
Normal file
10
app/src/main/res/values/styles_alarm.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="AlarmDayToggle">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:textAllCaps">true</item>
|
||||
<item name="android:background">?selectableItemBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user