From ad3631d945a44fde64094eb2cd2a144205c33a78 Mon Sep 17 00:00:00 2001 From: Quentin Colle Date: Fri, 20 Jul 2018 10:15:56 -0400 Subject: [PATCH] Feature - Sample Animating Month/Week Mode transition (#813) --- .../sample/DynamicSettersActivity.java | 27 +++++++++++-------- .../sample/SelectionModesActivity.java | 8 +++++- .../res/layout/activity_dynamic_setters.xml | 9 +++++++ .../res/layout/activity_selection_modes.xml | 1 + 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java index aaec19ca..14f0cd11 100644 --- a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java +++ b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java @@ -4,11 +4,15 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.transition.TransitionManager; import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; import android.widget.DatePicker; import android.widget.LinearLayout; import android.widget.NumberPicker; @@ -33,8 +37,9 @@ public class DynamicSettersActivity extends AppCompatActivity implements OnDateL private static final DateFormat FORMATTER = SimpleDateFormat.getDateInstance(); - @BindView(R.id.calendarView) - MaterialCalendarView widget; + @BindView(R.id.calendarView) MaterialCalendarView widget; + @BindView(R.id.animate_mode_transition) CheckBox animateModeTransition; + @BindView(R.id.parent) ViewGroup parent; private int currentTileSize; private int currentTileWidth; @@ -303,24 +308,24 @@ void onButtonChangeOrientation() { @OnClick(R.id.button_set_first_day) void onFirstDayOfWeekClicked() { int index = random.nextInt(DAYS_OF_WEEK.length); - widget.state().edit() - .setFirstDayOfWeek(DAYS_OF_WEEK[index]) - .commit(); + widget.state().edit().setFirstDayOfWeek(DAYS_OF_WEEK[index]).commit(); } @OnClick(R.id.button_weeks) public void onSetWeekMode() { - widget.state().edit() - .setCalendarDisplayMode(CalendarMode.WEEKS) - .commit(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && animateModeTransition.isChecked()) { + TransitionManager.beginDelayedTransition(parent); + } + widget.state().edit().setCalendarDisplayMode(CalendarMode.WEEKS).commit(); } @OnClick(R.id.button_months) public void onSetMonthMode() { - widget.state().edit() - .setCalendarDisplayMode(CalendarMode.MONTHS) - .commit(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && animateModeTransition.isChecked()) { + TransitionManager.beginDelayedTransition(parent); + } + widget.state().edit().setCalendarDisplayMode(CalendarMode.MONTHS).commit(); } diff --git a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/SelectionModesActivity.java b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/SelectionModesActivity.java index faa7bca0..26cb69f7 100644 --- a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/SelectionModesActivity.java +++ b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/SelectionModesActivity.java @@ -1,8 +1,11 @@ package com.prolificinteractive.materialcalendarview.sample; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; +import android.transition.TransitionManager; +import android.view.ViewGroup; import android.widget.Toast; import butterknife.BindView; import butterknife.ButterKnife; @@ -25,6 +28,7 @@ public class SelectionModesActivity extends AppCompatActivity private static final DateFormat FORMATTER = SimpleDateFormat.getDateInstance(); + @BindView(R.id.parent) ViewGroup parent; @BindView(R.id.calendar_view_single) MaterialCalendarView single; @BindView(R.id.calendar_view_multi) MaterialCalendarView multi; @BindView(R.id.calendar_view_range) MaterialCalendarView range; @@ -66,11 +70,13 @@ public class SelectionModesActivity extends AppCompatActivity @OnCheckedChanged(R.id.calendar_mode) void onCalendarModeChanged(boolean checked) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + TransitionManager.beginDelayedTransition(parent); + } final CalendarMode mode = checked ? CalendarMode.WEEKS : CalendarMode.MONTHS; single.state().edit().setCalendarDisplayMode(mode).commit(); multi.state().edit().setCalendarDisplayMode(mode).commit(); range.state().edit().setCalendarDisplayMode(mode).commit(); none.state().edit().setCalendarDisplayMode(mode).commit(); } - } diff --git a/sample/src/main/res/layout/activity_dynamic_setters.xml b/sample/src/main/res/layout/activity_dynamic_setters.xml index bec3e99c..bdd0ceb1 100644 --- a/sample/src/main/res/layout/activity_dynamic_setters.xml +++ b/sample/src/main/res/layout/activity_dynamic_setters.xml @@ -6,6 +6,7 @@ > +