Skip to content

Commit

Permalink
Support padding
Browse files Browse the repository at this point in the history
  • Loading branch information
typeqwerty authored and Kora committed Mar 14, 2019
1 parent 9fcf7c0 commit 2f242e7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
21 changes: 18 additions & 3 deletions app/src/main/java/io/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ protected void onCreate(Bundle savedInstanceState) {
calendarCustomObjects.add(calendarCustomObject);


LocalDate dateStart = new LocalDate("2019-3-13");
LocalDate dateEnd = new LocalDate("2019-3-16");
LocalDate dateStart = new LocalDate("2019-3-26");
LocalDate dateEnd = new LocalDate("2019-3-28");
while (dateStart.isBefore(dateEnd) || dateStart.equals(dateEnd)) {

calendarCustomObject = new CalendarCustomObject();

calendarCustomObject.setType(Arrays.asList(types).get(1));
calendarCustomObject.setType(Arrays.asList(types).get(2));
calendarCustomObject.setColorBackground("#e4fffd");
calendarCustomObject.setColorStroke("#00aa9c");

Expand All @@ -80,6 +80,21 @@ protected void onCreate(Bundle savedInstanceState) {
dateStart = dateStart.plusDays(1);
}

LocalDate dateStart1 = new LocalDate("2019-3-29");
LocalDate dateEnd1 = new LocalDate("2019-3-29");
while (dateStart1.isBefore(dateEnd1) || dateStart1.equals(dateEnd1)) {

calendarCustomObject = new CalendarCustomObject();

calendarCustomObject.setType(Arrays.asList(types).get(1));
calendarCustomObject.setColorBackground("#e4fffd");
calendarCustomObject.setColorStroke("#00aa9c");

calendarCustomObject.setUNCalendar(new UNCalendar(dateStart1.getYear(), dateStart1.getMonthOfYear(), dateStart1.getDayOfMonth()));
calendarCustomObjects.add(calendarCustomObject);
dateStart1 = dateStart1.plusDays(1);
}


unMultiRangeCalendarView.setCommonDatesDataInAMonth(calendarCustomObjects);
unMultiRangeCalendarView.setColorBackgroundCalendar("#ffffff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -94,10 +93,12 @@ public View getView(int i, View view, ViewGroup viewGroup) {
if (customObjectNext == null) {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_right));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 0, 0, 5, 0);
}
if (customObjectPre == null) {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_left));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 5, 0, 0, 0);
}

if (customObjectNext != null && customObjectPre == null) {
Expand All @@ -107,16 +108,18 @@ public View getView(int i, View view, ViewGroup viewGroup) {
} else {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_right));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 0, 0, 5, 0);
}
}
if (customObjectPre != null && customObjectNext == null) {
if (customObjectPre.getType().equals(calendarCustomObject.getType())) {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_right));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 0, 0, 5, 0);
} else {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_rounded));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 5);
setMarginForView(viewHolder.container, 5, 0, 5, 0);
}
}
if (customObjectNext != null && customObjectPre != null) {
Expand All @@ -125,14 +128,16 @@ public View getView(int i, View view, ViewGroup viewGroup) {
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
} else if (customObjectNext.getType().equals(calendarCustomObject.getType()) && !customObjectPre.getType().equals(calendarCustomObject.getType())) {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_left));
setMarginForView(viewHolder.container, 5, 0, 0, 0);
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
} else if (!customObjectNext.getType().equals(calendarCustomObject.getType()) && customObjectPre.getType().equals(calendarCustomObject.getType())) {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_right));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 0, 0, 5, 0);
} else {
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.circle_rounded));
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
setMarginForView(viewHolder.container, 5);
setMarginForView(viewHolder.container, 5, 0, 5, 0);
}
}
}
Expand All @@ -144,15 +149,15 @@ public View getView(int i, View view, ViewGroup viewGroup) {
return view;
}

private void setMarginForView(View view, int marginSide) {
private void setMarginForView(View view, int left, int top, int right, int bottom) {
if (view instanceof LinearLayout) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
params.setMargins(marginSide, 0, marginSide, 0);
params.setMargins(left, top, right, bottom);
view.setLayoutParams(params);
}
if (view instanceof FrameLayout) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.setMargins(marginSide, 0, marginSide, 0);
params.setMargins(left, top, right, bottom);
view.setLayoutParams(params);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void initComponent() {
gridDate = findViewById(R.id.gridDate);

gridDate.setBackgroundColor(Color.parseColor(getColorBackgroundCalendar()));
gridDate.setVerticalSpacing(getVerticalSpacing());
gridDate.setVerticalSpacing((int) UIUtils.convertDpToPixel(getVerticalSpacing(), getContext()));
initData();
regEvents();
}
Expand Down
10 changes: 5 additions & 5 deletions uranashel_multirangecalendarview/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10">
android:weightSum="7">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_weight="1"
android:gravity="center">

<Button
Expand All @@ -31,7 +31,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="6"
android:layout_weight="5"
android:gravity="center">

<TextView
Expand All @@ -48,7 +48,7 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_weight="1"
android:gravity="center">

<Button
Expand Down Expand Up @@ -106,7 +106,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/we"
android:text="@string/th"
android:textColor="@color/date_index"
android:textStyle="bold"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<string name="fr">Fr</string>
<string name="sa">Sa</string>
<string name="su">Su</string>
<string name="today">Today</string>
<string name="today">Calendar</string>
</resources>

0 comments on commit 2f242e7

Please sign in to comment.