728x90
반응형
SMALL
OneDayDecorator
오늘 날짜를 커스텀할 수 있다.
package com.example.myapplication.decorators;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.Date;
/**
* Decorate a day by making the text big and bold
*/
public class OneDayDecorator implements DayViewDecorator {
private CalendarDay date;
public OneDayDecorator() {
date = CalendarDay.today();
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return date != null && day.equals(date);
}
@Override
public void decorate(DayViewFacade view) {
view.addSpan(new StyleSpan(Typeface.BOLD));
view.addSpan(new RelativeSizeSpan(2.f));
view.addSpan(new ForegroundColorSpan(Color.GREEN));
}
/**
* We're changing the internals, so make sure to call {@linkplain MaterialCalendarView#invalidateDecorators()}
*/
public void setDate(Date date) {
this.date = CalendarDay.from(date);
}
}
Main은 다음과 같다.
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.myapplication.decorators.FridayDecorator;
import com.example.myapplication.decorators.MondayDecorator;
import com.example.myapplication.decorators.OneDayDecorator;
import com.example.myapplication.decorators.SaturdayDecorator;
import com.example.myapplication.decorators.SundayDecorator;
import com.example.myapplication.decorators.ThursdayDecorator;
import com.example.myapplication.decorators.TuesdayDecorator;
import com.example.myapplication.decorators.WednesdayDecorator;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MaterialCalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setSelectedDate(CalendarDay.today());
OneDayDecorator oneDayDecorator = new OneDayDecorator();
calendarView.addDecorators(
oneDayDecorator
);;
calendarView.addDecorators(
new SundayDecorator(),
new SaturdayDecorator(),
new MondayDecorator(),
new TuesdayDecorator(),
new ThursdayDecorator(),
new WednesdayDecorator(),
new FridayDecorator()
);
}
}
EventDecorator
특정 날짜에 점을 표시하는 decorator이다.
package com.example.myapplication.decorators;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.spans.DotSpan;
import java.util.Collection;
import java.util.HashSet;
/**
* Decorate several days with a dot
*/
public class EventDecorator implements DayViewDecorator {
private final int color;
private final HashSet<CalendarDay> dates;
public EventDecorator(int color, Collection<CalendarDay> dates) {
this.color = color;
this.dates = new HashSet<>(dates);
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return dates.contains(day);
}
@Override
public void decorate(DayViewFacade view) {
view.addSpan(new DotSpan(5, color));
}
}
Main은 다음과 같다.
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import com.example.myapplication.decorators.EventDecorator;
import com.example.myapplication.decorators.FridayDecorator;
import com.example.myapplication.decorators.MondayDecorator;
import com.example.myapplication.decorators.OneDayDecorator;
import com.example.myapplication.decorators.SaturdayDecorator;
import com.example.myapplication.decorators.SundayDecorator;
import com.example.myapplication.decorators.ThursdayDecorator;
import com.example.myapplication.decorators.TuesdayDecorator;
import com.example.myapplication.decorators.WednesdayDecorator;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.Collections;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MaterialCalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setSelectedDate(CalendarDay.today());
OneDayDecorator oneDayDecorator = new OneDayDecorator();
calendarView.addDecorators(
oneDayDecorator
);
calendarView.addDecorator(new EventDecorator(Color.GREEN, Collections.singleton(CalendarDay.today())));
calendarView.addDecorators(
new SundayDecorator(),
new SaturdayDecorator(),
new MondayDecorator(),
new TuesdayDecorator(),
new ThursdayDecorator(),
new WednesdayDecorator(),
new FridayDecorator()
);
}
}
728x90
반응형
LIST
'App Programming > Android Studio' 카테고리의 다른 글
[Android Studio] 스피너 (Spinner) (0) | 2022.09.19 |
---|---|
[Android Studio] Material CalendarView (3) (0) | 2022.09.14 |
[Android Studio] Material CalendarView (1) (0) | 2022.09.13 |
[Android Studio] The application could not be installed: INSTALL_FAILED_INSUFFICIENT_STORAGE (0) | 2022.09.13 |
[Android Studio] 기본 카메라 사진 찍고 이미지뷰에 출력하기 (0) | 2022.09.05 |