Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…aterial-calendarview into qc_naming_documentation
  • Loading branch information
quentin41500 committed Feb 16, 2017
2 parents 57ee7b1 + 30da68b commit 6fb9730
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
4 changes: 4 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ android {
versionCode project.ext.versionCodeInt
versionName version
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ protected void setupSelection(@ShowOtherDates int showOtherDates, boolean inRang
}

private final Rect tempRect = new Rect();
private final Rect circleDrawableRect = new Rect();

@Override
protected void onDraw(@NonNull Canvas canvas) {
Expand All @@ -176,7 +177,7 @@ protected void onDraw(@NonNull Canvas canvas) {
customBackground.draw(canvas);
}

mCircleDrawable.setBounds(tempRect);
mCircleDrawable.setBounds(circleDrawableRect);

super.onDraw(canvas);
}
Expand All @@ -185,7 +186,7 @@ private void regenerateBackground() {
if (selectionDrawable != null) {
setBackgroundDrawable(selectionDrawable);
} else {
mCircleDrawable = generateBackground(selectionColor, fadeTime, tempRect);
mCircleDrawable = generateBackground(selectionColor, fadeTime, circleDrawableRect);
setBackgroundDrawable(mCircleDrawable);
}
}
Expand Down Expand Up @@ -265,14 +266,17 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto

private void calculateBounds(int width, int height) {
final int radius = Math.min(height, width);
// Lollipop platform bug. Rect offset needs to be divided by 4 instead of 2
final int offsetDivisor = Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP ? 4 : 2;
final int offset = Math.abs(height - width) / offsetDivisor;
final int offset = Math.abs(height - width) / 2;

// Lollipop platform bug. Circle drawable offset needs to be half of normal offset
final int circleOffset = Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP ? offset / 2 : offset;

if (width >= height) {
tempRect.set(offset, 0, radius + offset, height);
circleDrawableRect.set(circleOffset, 0, radius + circleOffset, height);
} else {
tempRect.set(0, offset, width, radius + offset);
circleDrawableRect.set(0, circleOffset, width, radius + circleOffset);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
private OnMonthChangedListener monthListener;
private OnRangeSelectedListener rangeListener;


CharSequence calendarContentDescription;
private int accentColor = 0;
private int arrowColor = Color.BLACK;
Expand Down Expand Up @@ -262,7 +261,6 @@ public MaterialCalendarView(Context context, AttributeSet attrs) {
buttonFuture.setContentDescription(getContext().getString(R.string.next));
pager = new CalendarPager(getContext());

title.setOnClickListener(onClickListener);
buttonPast.setOnClickListener(onClickListener);
buttonFuture.setOnClickListener(onClickListener);

Expand Down Expand Up @@ -1357,6 +1355,15 @@ public void setOnRangeSelectedListener(OnRangeSelectedListener listener) {
this.rangeListener = listener;
}

/**
* Add listener to the title or null to remove it.
*
* @param listener Listener to be notified.
*/
public void setOnTitleClickListener(final OnClickListener listener) {
title.setOnClickListener(listener);
}

/**
* Dispatch date change events to a listener, if set
*
Expand Down
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ android {
versionCode project.ext.versionCodeInt
versionName version
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.prolificinteractive.materialcalendarview.sample;

import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.NumberPicker;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;

import butterknife.Bind;
Expand All @@ -33,6 +37,8 @@ protected void onCreate(Bundle savedInstanceState) {

currentTileWidth = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;
currentTileHeight = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;

widget.addDecorator(new TodayDecorator());
}

@OnClick(R.id.custom_tile_match_parent)
Expand Down Expand Up @@ -87,4 +93,25 @@ public void onClick(@NonNull DialogInterface dialog, int which) {
})
.show();
}

private class TodayDecorator implements DayViewDecorator {

private final CalendarDay today;
private final Drawable backgroundDrawable;

public TodayDecorator() {
today = CalendarDay.today();
backgroundDrawable = getResources().getDrawable(R.drawable.today_circle_background);
}

@Override
public boolean shouldDecorate(CalendarDay day) {
return today.equals(day);
}

@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(backgroundDrawable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
Expand Down Expand Up @@ -43,6 +44,14 @@ protected void onCreate(Bundle savedInstanceState) {
currentTileSize = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;
currentTileWidth = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;
currentTileHeight = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;

widget.setOnTitleClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
Toast.makeText(DynamicSettersActivity.this, R.string.today, Toast.LENGTH_SHORT)
.show();
}
});
}

@OnClick(R.id.button_other_dates)
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/res/drawable/today_circle_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="#44afcc" />

</shape>
2 changes: 2 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
<string name="label_thin">Tile width and height specified (thin)</string>
<string name="label_wide">Tile width and height specified (wide)</string>


<string name="today">Today is the day</string>
</resources>

0 comments on commit 6fb9730

Please sign in to comment.