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

Feature - Sample Animating Month/Week Mode transition #813

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

}
9 changes: 9 additions & 0 deletions sample/src/main/res/layout/activity_dynamic_setters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
>

<LinearLayout
android:id="@+id/parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -231,6 +232,14 @@
android:layout_height="wrap_content"
>

<CheckBox
android:id="@+id/animate_mode_transition"
android:text="Animate Month/Week mode transition (KitKat and above)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:checked="true"
/>
<CheckBox
android:id="@+id/show_week_days"
android:text="Show week days"
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/layout/activity_selection_modes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>

<LinearLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down