Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MaterialDatePicker] Changed the header toggle to a MaterialButton #1712

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import androidx.annotation.RestrictTo;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.InsetDialogOnTouchListener;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.resources.MaterialAttributes;
Expand Down Expand Up @@ -125,7 +126,7 @@ public String getHeaderText() {
@InputMode private int inputMode;

private TextView headerSelectionText;
private CheckableImageButton headerToggleButton;
private MaterialButton headerToggleButton;
@Nullable private MaterialShapeDrawable background;
private Button confirmButton;

Expand Down Expand Up @@ -360,7 +361,7 @@ public void onIncompleteSelectionChanged() {

private void initHeaderToggle(Context context) {
headerToggleButton.setTag(TOGGLE_BUTTON_TAG);
headerToggleButton.setImageDrawable(createHeaderToggleDrawable(context));
headerToggleButton.setIcon(createHeaderToggleDrawable(context));
headerToggleButton.setChecked(inputMode != INPUT_MODE_CALENDAR);

// By default, CheckableImageButton adds a delegate that reads checked state.
Expand All @@ -374,14 +375,13 @@ public void onClick(View v) {
// Update confirm button in case in progress selection has been reset
confirmButton.setEnabled(dateSelector.isSelectionComplete());

headerToggleButton.toggle();
updateToggleContentDescription(headerToggleButton);
startPickerFragment();
}
});
}

private void updateToggleContentDescription(@NonNull CheckableImageButton toggle) {
private void updateToggleContentDescription(@NonNull MaterialButton toggle) {
String contentDescription =
headerToggleButton.isChecked()
? toggle.getContext().getString(R.string.mtrl_picker_toggle_to_calendar_input_mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
limitations under the License.
-->

<com.google.android.material.internal.CheckableImageButton
<com.google.android.material.button.MaterialButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mtrl_picker_header_toggle"
style="?attr/materialCalendarHeaderToggleButton"
android:checkable="true"
android:layout_width="@dimen/mtrl_min_touch_target_size"
android:layout_height="@dimen/mtrl_min_touch_target_size"
android:layout_marginBottom="@dimen/mtrl_calendar_header_toggle_margin_bottom"
android:layout_marginTop="@dimen/mtrl_calendar_header_toggle_margin_top"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="12dp"
app:rippleColor="@color/mtrl_btn_ripple_color"
gabrielemariotti marked this conversation as resolved.
Show resolved Hide resolved
gabrielemariotti marked this conversation as resolved.
Show resolved Hide resolved
android:layout_gravity="bottom|end"/>
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@
<item name="rippleColor">@color/mtrl_btn_ripple_color</item>
</style>

<style name="Widget.MaterialComponents.MaterialCalendar.HeaderToggleButton" parent="Widget.AppCompat.ImageButton">
<item name="android:background">?attr/actionBarItemBackground</item>
<item name="android:tint">?attr/colorOnPrimary</item>
<style name="Widget.MaterialComponents.MaterialCalendar.HeaderToggleButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="iconTint">?attr/colorOnPrimary</item>
</style>

<style name="Widget.MaterialComponents.MaterialCalendar.DayTextView" parent="Widget.AppCompat.TextView">
Expand Down