Skip to content

Commit

Permalink
Feature - Vectors (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin41500 authored Aug 6, 2018
1 parent 699f4e3 commit af9ecab
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 72 deletions.
2 changes: 2 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ android {

versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME

vectorDrawables.useSupportLibrary = true
}

lintOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.prolificinteractive.materialcalendarview;

import android.content.Context;
import android.graphics.PorterDuff;
import android.os.Build;
import android.support.v7.widget.AppCompatImageView;
import android.util.TypedValue;
import android.widget.ImageView;

/**
* An {@linkplain android.widget.ImageView} to pragmatically set the color of arrows
* using a {@linkplain android.graphics.ColorFilter}
*/
class DirectionButton extends ImageView {
class DirectionButton extends AppCompatImageView {

public DirectionButton(Context context) {
super(context);

setBackgroundResource(getThemeSelectableBackgroundId(context));
}

public void setColor(int color) {
setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ArrayRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -229,9 +230,6 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse

CharSequence calendarContentDescription;
private int accentColor = 0;
private int arrowColor = Color.BLACK;
private Drawable leftArrowMask;
private Drawable rightArrowMask;
private int tileHeight = INVALID_TILE_DIMENSION;
private int tileWidth = INVALID_TILE_DIMENSION;
@SelectionMode
Expand Down Expand Up @@ -341,24 +339,18 @@ public void transformPage(View page, float position) {
setTileHeight(tileHeight);
}

setArrowColor(a.getColor(
R.styleable.MaterialCalendarView_mcv_arrowColor,
Color.BLACK
));
Drawable leftMask = a.getDrawable(
R.styleable.MaterialCalendarView_mcv_leftArrowMask
setLeftArrow(
a.getResourceId(
R.styleable.MaterialCalendarView_mcv_leftArrowMask,
R.drawable.mcv_action_previous
)
);
if (leftMask == null) {
leftMask = getResources().getDrawable(R.drawable.mcv_action_previous);
}
setLeftArrowMask(leftMask);
Drawable rightMask = a.getDrawable(
R.styleable.MaterialCalendarView_mcv_rightArrowMask
setRightArrow(
a.getResourceId(
R.styleable.MaterialCalendarView_mcv_rightArrowMask,
R.drawable.mcv_action_next
)
);
if (rightMask == null) {
rightMask = getResources().getDrawable(R.drawable.mcv_action_next);
}
setRightArrowMask(rightMask);

setSelectionColor(
a.getColor(
Expand Down Expand Up @@ -671,26 +663,6 @@ public void setSelectionColor(int color) {
invalidate();
}

/**
* @return color used to draw arrows
*/
public int getArrowColor() {
return arrowColor;
}

/**
* @param color the new color for the paging arrows
*/
public void setArrowColor(int color) {
if (color == 0) {
return;
}
arrowColor = color;
buttonPast.setColor(color);
buttonFuture.setColor(color);
invalidate();
}

/**
* Set content description for button past
*
Expand Down Expand Up @@ -741,31 +713,29 @@ public void setDayFormatterContentDescription(DayFormatter formatter) {
/**
* @return icon used for the left arrow
*/
public Drawable getLeftArrowMask() {
return leftArrowMask;
public Drawable getLeftArrow() {
return buttonPast.getDrawable();
}

/**
* @param icon the new icon to use for the left paging arrow
*/
public void setLeftArrowMask(Drawable icon) {
leftArrowMask = icon;
buttonPast.setImageDrawable(icon);
public void setLeftArrow(@DrawableRes final int icon) {
buttonPast.setImageResource(icon);
}

/**
* @return icon used for the right arrow
*/
public Drawable getRightArrowMask() {
return rightArrowMask;
public Drawable getRightArrow() {
return buttonFuture.getDrawable();
}

/**
* @param icon the new icon to use for the right paging arrow
*/
public void setRightArrowMask(Drawable icon) {
rightArrowMask = icon;
buttonFuture.setImageDrawable(icon);
public void setRightArrow(@DrawableRes final int icon) {
buttonFuture.setImageResource(icon);
}

/**
Expand Down
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions library/src/main/res/drawable/mcv_action_next.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
>
<path
android:fillColor="#000000"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"
/>
</vector>
11 changes: 11 additions & 0 deletions library/src/main/res/drawable/mcv_action_previous.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
>
<path
android:fillColor="#000000"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"
/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);

widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
widget.setArrowColor(getResources().getColor(R.color.sample_primary));
widget.setLeftArrowMask(getResources().getDrawable(R.drawable.ic_navigation_arrow_back));
widget.setRightArrowMask(getResources().getDrawable(R.drawable.ic_navigation_arrow_forward));
widget.setLeftArrow(R.drawable.ic_arrow_back);
widget.setRightArrow(R.drawable.ic_arrow_forward);
widget.setSelectionColor(getResources().getColor(R.color.sample_primary));
widget.setWeekDayTextAppearance(R.style.CustomTextAppearance);
widget.setHeaderTextAppearance(R.style.CustomTextAppearance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ void onColorsClicked() {
1f,
0.75f
});
widget.setArrowColor(color);
widget.setSelectionColor(color);
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions sample/src/main/res/drawable/ic_arrow_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
>
<path
android:fillColor="#0093FF"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"
/>
</vector>
11 changes: 11 additions & 0 deletions sample/src/main/res/drawable/ic_arrow_forward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
>
<path
android:fillColor="#0093FF"
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"
/>
</vector>
24 changes: 12 additions & 12 deletions sample/src/main/res/layout/activity_customization.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
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"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.prolificinteractive.materialcalendarview.sample.CustomizeXmlActivity"
>

<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_showOtherDates="all"
app:mcv_arrowColor="?attr/colorPrimary"
app:mcv_leftArrowMask="@drawable/ic_navigation_arrow_back"
app:mcv_rightArrowMask="@drawable/ic_navigation_arrow_forward"
app:mcv_selectionColor="?attr/colorPrimary"
app:mcv_headerTextAppearance="@style/CustomTextAppearance"
app:mcv_calendarMode="week"
app:mcv_dateTextAppearance="@style/CustomTextAppearance"
app:mcv_weekDayTextAppearance="@style/CustomTextAppearance"
app:mcv_weekDayLabels="@array/custom_weekdays"
app:mcv_firstDayOfWeek="thursday"
app:mcv_headerTextAppearance="@style/CustomTextAppearance"
app:mcv_leftArrowMask="@drawable/ic_arrow_back"
app:mcv_monthLabels="@array/custom_months"
app:mcv_rightArrowMask="@drawable/ic_arrow_forward"
app:mcv_selectionColor="?attr/colorPrimary"
app:mcv_showOtherDates="all"
app:mcv_tileSize="36dp"
app:mcv_firstDayOfWeek="thursday"
app:mcv_calendarMode="week"
app:mcv_titleAnimationOrientation="vertical"
app:mcv_weekDayLabels="@array/custom_weekdays"
app:mcv_weekDayTextAppearance="@style/CustomTextAppearance"
/>

</LinearLayout>

0 comments on commit af9ecab

Please sign in to comment.