Skip to content

Commit

Permalink
Chore - Getter Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin41500 committed Jul 25, 2018
1 parent e3d157e commit aae7843
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.support.annotation.NonNull;

import android.util.Log;
import java.util.Calendar;
import java.util.Collection;
import org.threeten.bp.DayOfWeek;
Expand Down
18 changes: 18 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@

</activity>

<activity
android:name="com.prolificinteractive.materialcalendarview.sample.GettersActivity"
android:label="@string/title_activity_getters"
android:parentActivityName="com.prolificinteractive.materialcalendarview.sample.MainActivity"
>

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.prolificinteractive.materialcalendarview.sample.MainActivity"
/>

<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="com.prolificinteractive.materialcalendarview.sample.SAMPLE" />
</intent-filter>

</activity>

<activity
android:name=".DisableDaysActivity"
android:label="@string/title_activity_disable"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.prolificinteractive.materialcalendarview.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.CalendarMode;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.List;

/**
* Because the calendar has a lot of getters method, this activity is here to demonstrate what each
* getter is returning. For more information, make sure to check the documentation.
*/
public class GettersActivity extends AppCompatActivity {
public static final CharSequence[] ITEMS =
new CharSequence[] { "NONE", "SINGLE", "MULTIPLE", "RANGE" };

@BindView(R.id.calendarView) MaterialCalendarView widget;

@Override protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_getters);
ButterKnife.bind(this);
}

@OnCheckedChanged(R.id.calendar_mode)
void onCalendarModeChanged(boolean checked) {
final CalendarMode mode = checked ? CalendarMode.WEEKS : CalendarMode.MONTHS;
widget.state().edit().setCalendarDisplayMode(mode).commit();
}

@OnClick(R.id.button_selection_mode) void onChangeSelectionMode() {
new AlertDialog.Builder(this)
.setTitle("Selection Mode")
.setSingleChoiceItems(ITEMS, widget.getSelectionMode(), (dialog, which) -> {
widget.setSelectionMode(which);
dialog.dismiss();
})
.show();
}

@OnClick(R.id.get_current_date) public void getCurrentDatesClick(final View v) {
Toast.makeText(this, widget.getCurrentDate().toString(), Toast.LENGTH_SHORT).show();
Log.e("GettersActivity", widget.getCurrentDate().toString());
}

@OnClick(R.id.get_selected_date) public void getSelectedDatesClick(final View v) {
final CalendarDay selectedDate = widget.getSelectedDate();
if (selectedDate != null) {
Toast.makeText(this, selectedDate.toString(), Toast.LENGTH_SHORT).show();
Log.e("GettersActivity", selectedDate.toString());
} else {
Toast.makeText(this, "No Selection", Toast.LENGTH_SHORT).show();
}
}

@OnClick(R.id.get_selected_dates) public void getSelectedDateClick(final View v) {
final List<CalendarDay> selectedDates = widget.getSelectedDates();
if (!selectedDates.isEmpty()) {
Toast.makeText(this, selectedDates.toString(), Toast.LENGTH_SHORT).show();
Log.e("GettersActivity", selectedDates.toString());
} else {
Toast.makeText(this, "No Selection", Toast.LENGTH_SHORT).show();
}
}

@OnClick(R.id.get_selection_mode) public void getSelectionModeClick(final View v) {
Toast.makeText(this, ITEMS[widget.getSelectionMode()], Toast.LENGTH_SHORT).show();
Log.e("GettersActivity", ITEMS[widget.getSelectionMode()].toString());
}
}
83 changes: 83 additions & 0 deletions sample/src/main/res/layout/activity_getters.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".BasicActivity"
>

<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<CheckBox
android:id="@+id/calendar_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:checked="false"
android:text="Week Calendar Mode"
/>


<Button
android:id="@+id/get_current_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Current Date"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/get_selected_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get Selected Date"
/>
<Button
android:id="@+id/get_selected_dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get Selected Dates"
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/button_selection_mode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Selection Mode"
/>
<Button
android:id="@+id/get_selection_mode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get Selection Mode"
/>
</LinearLayout>

</LinearLayout>
</android.support.v4.widget.NestedScrollView>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<string name="title_activity_decorators">Calendar with Decorators</string>
<string name="title_activity_selections">Calendar Selection Modes</string>
<string name="title_activity_basic_modes">Calendar with Dynamic Modes</string>
<string name="title_activity_getters">Calendar with Getters</string>
<string name="title_activity_multiple_view">Multiple Basic Calendars</string>
<string name="title_activity_multiple_size">Many-Sized Calendars</string>

Expand Down

0 comments on commit aae7843

Please sign in to comment.