Skip to content

Commit

Permalink
Code structure improved:
Browse files Browse the repository at this point in the history
 - renamed: monthName to TopText, dayNumber ot MiddleText, dayName to BottomText.
 - separated configuration options from required configuration in Builder.
 - new feature: disable specific Dates and apply a custom style with CalendarPredicate.
 - new feature: change the color of each individual text (top, middle and bottom).
  • Loading branch information
muraee committed Dec 21, 2017
1 parent 24b1e55 commit d15b883
Show file tree
Hide file tree
Showing 14 changed files with 674 additions and 395 deletions.
15 changes: 9 additions & 6 deletions app/src/main/java/devs/mulham/raee/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ protected void onCreate(Bundle savedInstanceState) {
.startDate(startDate.getTime())
.endDate(endDate.getTime())
.datesNumberOnScreen(5)
.dayNameFormat("EEE")
.dayNumberFormat("dd")
.monthFormat("MMM")
.showDayName(true)
.showMonthName(true)
.configure()
.formatTopText("MMM")
.formatMiddleText("dd")
.formatBottomText("EEE")
.showTopText(true)
.showBottomText(true)
.textColor(Color.LTGRAY, Color.WHITE)
.colorTextMiddle(Color.LTGRAY, Color.parseColor("#ffd54f"))
.end()
.defaultSelectedDate(defaultDate)
.textColor(Color.LTGRAY, Color.WHITE)
.build();

Log.i("Default Date", DateFormat.getDateInstance().format(defaultDate));
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/devs/mulham/raee/sample/SampleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_sample, container, false);

/** end after 1 month from now */
/* end after 1 month from now */
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 1);

/** start before 1 month from now */
/* start before 1 month from now */
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.MONTH, -1);

horizontalCalendar = new HorizontalCalendar.Builder(rootView, R.id.calendarView)
.startDate(startDate.getTime())
.endDate(endDate.getTime())
.datesNumberOnScreen(5)
.dayNameFormat("EEE")
.dayNumberFormat("dd")
.monthFormat("MMM")
.textSize(14f, 24f, 14f)
.showDayName(true)
.showMonthName(true)
.textColor(Color.LTGRAY, Color.WHITE)
.configure()
.formatTopText("MMM")
.formatMiddleText("dd")
.formatBottomText("EEE")
.textSize(14f, 24f, 14f)
.showTopText(true)
.showBottomText(true)
.textColor(Color.LTGRAY, Color.WHITE)
.end()
.build();

horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:textColorSelected="#FFFF"
app:textSizeDayName="14sp"
app:textSizeDayNumber="20sp"/>
app:sizeBottomText="14sp"
app:sizeMiddleText="20sp"/>

</android.support.design.widget.AppBarLayout>

Expand Down
2 changes: 1 addition & 1 deletion horizontalcalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
siteUrl = 'https://github.com/Mulham-Raee/Horizontal-Calendar'
gitUrl = 'https://github.com/Mulham-Raee/Horizontal-Calendar.git'

libraryVersion = '1.2.2'
libraryVersion = '1.2.5'

developerId = 'mulham-raee'
developerName = 'Mulham Raee'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package devs.mulham.horizontalcalendar;

import android.graphics.drawable.Drawable;

import java.util.Calendar;

/**
* @author Mulham-Raee
* @since v1.2.5
*/
public class CalendarItemStyle {

private int colorTopText;
private int colorMiddleText;
private int colorBottomText;
private Drawable background;

public CalendarItemStyle(){
}

public CalendarItemStyle(int textColor, Drawable background) {
this(textColor, textColor, textColor, background);
}

public CalendarItemStyle(int colorTopText, int colorMiddleText, int colorBottomText, Drawable background) {
this.colorTopText = colorTopText;
this.colorMiddleText = colorMiddleText;
this.colorBottomText = colorBottomText;
this.background = background;
}

public int getColorTopText() {
return colorTopText;
}

public void setColorTopText(int colorTopText) {
this.colorTopText = colorTopText;
}

public int getColorMiddleText() {
return colorMiddleText;
}

public void setColorMiddleText(int colorMiddleText) {
this.colorMiddleText = colorMiddleText;
}

public int getColorBottomText() {
return colorBottomText;
}

public void setColorBottomText(int colorBottomText) {
this.colorBottomText = colorBottomText;
}

public Drawable getBackground() {
return background;
}

public void setBackground(Drawable background) {
this.background = background;
}

public void setupDefaultValues(CalendarItemStyle defaultValues) {
if (defaultValues == null) {
return;
}
if (colorTopText == 0) {
colorTopText = defaultValues.colorTopText;
}
if (colorMiddleText == 0) {
colorMiddleText = defaultValues.colorMiddleText;
}
if (colorBottomText == 0) {
colorBottomText = defaultValues.colorBottomText;
}
if (background == null) {
background = defaultValues.background;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package devs.mulham.horizontalcalendar;

import android.graphics.drawable.Drawable;

/**
* @author Mulham-Raee
* @since v1.2.5
*/
public class ConfigBuilder {

/* Format & Font Sizes*/
private float sizeTopText;
private float sizeMiddleText;
private float sizeBottomText;
private Integer selectorColor;
private String formatTopText;
private String formatMiddleText;
private String formatBottomText;
private boolean showTopText = true;
private boolean showBottomText = true;

/* Colors and Background*/
private int colorTextTop, colorTextTopSelected;
private int colorTextMiddle, colorTextMiddleSelected;
private int colorTextBottom, colorTextBottomSelected;
private Drawable selectedItemBackground;

private final HorizontalCalendar.Builder calendarBuilder;

public ConfigBuilder(HorizontalCalendar.Builder calendarBuilder) {
this.calendarBuilder = calendarBuilder;
}

/**
* Set the text size of the labels in scale-independent pixels
*
* @param sizeTopText the Top text size, in SP
* @param sizeMiddleText the Middle text size, in SP
* @param sizeBottomText the Bottom text size, in SP
*/
public ConfigBuilder textSize(float sizeTopText, float sizeMiddleText,
float sizeBottomText) {
this.sizeTopText = sizeTopText;
this.sizeMiddleText = sizeMiddleText;
this.sizeBottomText = sizeBottomText;
return this;
}

/**
* Set the text size of the top label in scale-independent pixels
*
* @param size the Top text size, in SP
*/
public ConfigBuilder sizeTopText(float size) {
this.sizeTopText = size;
return this;
}

/**
* Set the text size of the middle label in scale-independent pixels
*
* @param size the Middle text size, in SP
*/
public ConfigBuilder sizeMiddleText(float size) {
this.sizeMiddleText = size;
return this;
}

/**
* Set the text size of the bottom label in scale-independent pixels
*
* @param size the Bottom text size, in SP
*/
public ConfigBuilder sizeBottomText(float size) {
this.sizeBottomText = size;
return this;
}

public ConfigBuilder selectorColor(Integer selectorColor) {
this.selectorColor = selectorColor;
return this;
}

public ConfigBuilder formatTopText(String format) {
this.formatTopText = format;
return this;
}

public ConfigBuilder formatMiddleText(String format) {
this.formatMiddleText = format;
return this;
}

public ConfigBuilder formatBottomText(String format) {
this.formatBottomText = format;
return this;
}

public ConfigBuilder showTopText(boolean value) {
this.showTopText = value;
return this;
}

public ConfigBuilder showBottomText(boolean value) {
this.showBottomText = value;
return this;
}

public ConfigBuilder textColor(int textColorNormal, int textColorSelected) {
colorTextTop = textColorNormal;
colorTextMiddle = textColorNormal;
colorTextBottom = textColorNormal;

colorTextTopSelected = textColorSelected;
colorTextMiddleSelected = textColorSelected;
colorTextBottomSelected = textColorSelected;
return this;
}

public ConfigBuilder colorTextTop(int textColorNormal, int textColorSelected) {
colorTextTop = textColorNormal;
colorTextTopSelected = textColorSelected;
return this;
}

public ConfigBuilder colorTextMiddle(int textColorNormal, int textColorSelected) {
colorTextMiddle = textColorNormal;
colorTextMiddleSelected = textColorSelected;
return this;
}

public ConfigBuilder colorTextBottom(int textColorNormal, int textColorSelected) {
colorTextBottom = textColorNormal;
colorTextBottomSelected = textColorSelected;
return this;
}

public ConfigBuilder selectedDateBackground(Drawable background) {
this.selectedItemBackground = background;
return this;
}

public HorizontalCalendar.Builder end() {
if (formatMiddleText == null) {
formatMiddleText = HorizontalCalendarConfig.DEFAULT_FORMAT_TEXT_MIDDLE;
}
if ((formatTopText == null) && showTopText) {
formatTopText = HorizontalCalendarConfig.DEFAULT_FORMAT_TEXT_TOP;
}
if ((formatBottomText == null) && showBottomText) {
formatBottomText = HorizontalCalendarConfig.DEFAULT_FORMAT_TEXT_BOTTOM;
}
return calendarBuilder;
}

HorizontalCalendarConfig createConfig() {
HorizontalCalendarConfig config = new HorizontalCalendarConfig(sizeTopText, sizeMiddleText, sizeBottomText, selectorColor);
config.setFormatTopText(formatTopText);
config.setFormatMiddleText(formatMiddleText);
config.setFormatBottomText(formatBottomText);
config.setShowTopText(showTopText);
config.setShowBottomText(showBottomText);

return config;
}

CalendarItemStyle createDefaultStyle() {
return new CalendarItemStyle(colorTextTop, colorTextMiddle, colorTextBottom, null);
}

CalendarItemStyle createSelectedItemStyle() {
return new CalendarItemStyle(colorTextTopSelected, colorTextMiddleSelected, colorTextBottomSelected, selectedItemBackground);
}
}
Loading

0 comments on commit d15b883

Please sign in to comment.