Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian authored and Kora committed Mar 14, 2019
1 parent baea2db commit 21de4f1
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 26 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.ngoctan95:CustomCalendarView:v1.0.3'
// implementation project(':uranashel_multirangecalendarview')
implementation project(':uranashel_multirangecalendarview')

//Joda time
implementation 'joda-time:joda-time:2.10.1'
}
18 changes: 18 additions & 0 deletions app/src/main/java/io/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import org.joda.time.LocalDate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -63,6 +65,22 @@ protected void onCreate(Bundle savedInstanceState) {
calendarCustomObjects.add(calendarCustomObject);


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

calendarCustomObject = new CalendarCustomObject();

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

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


unMultiRangeCalendarView.setCommonDatesDataInAMonth(calendarCustomObjects);
unMultiRangeCalendarView.setColorBackgroundCalendar("#ffffff");
unMultiRangeCalendarView.setTextSize(13);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nguyenngoctan44.io.uranashel_multirangecalendarview;

import android.content.Context;
import android.util.DisplayMetrics;

public class CalculateUtils {
public static float convertDpToPixel(float dp, Context context) {
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package nguyenngoctan44.io.uranashel_multirangecalendarview;

import android.util.Log;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;

Expand Down Expand Up @@ -33,6 +36,48 @@ static boolean checkIfDateInRange(List<CalendarCustomObject> calendars, Calendar
return false;
}

/**
* Check if dates contains one date is first date
*
* @param calendar
* @param calendars
* @return
*/
static boolean checkIfDateIsHeadOfListDates(List<CalendarCustomObject> calendars, CalendarCustomObject calendar) {
if (calendars == null) {
return false;
}
if (calendars.isEmpty()) {
return true;
}
List<CalendarCustomObject> calendarCustomObjects = getFirstAvailabilityData(calendars);
UNCalendar unCalendar = calendarCustomObjects.get(0).getUNCalendar();
return unCalendar.getDate() == calendar.getUNCalendar().getDate() &&
unCalendar.getMonth() == calendar.getUNCalendar().getMonth() &&
unCalendar.getYear() == calendar.getUNCalendar().getYear();
}

/**
* Check if dates contains one date is latest date
*
* @param calendar
* @param calendars
* @return
*/
static boolean checkIfDateIsTailOfListDates(List<CalendarCustomObject> calendars, CalendarCustomObject calendar) {
if (calendars == null) {
return false;
}
if (calendars.isEmpty()) {
return true;
}
UNCalendar unCalendar = calendars.get(calendars.size() - 1).getUNCalendar();
return unCalendar.getDate() == calendar.getUNCalendar().getDate() &&
unCalendar.getMonth() == calendar.getUNCalendar().getMonth() &&
unCalendar.getYear() == calendar.getUNCalendar().getYear();
}


private static List<CalendarCustomObject> getFirstAvailabilityData(List<CalendarCustomObject> calendarCustomObjects) {
List<CalendarCustomObject> calendarCustomObjects1 = new ArrayList<>();
for (CalendarCustomObject calendarCustomObject : calendarCustomObjects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
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;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -57,7 +60,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view == null) {
viewHolder = new ViewHolder();
view = layoutInflater.inflate(R.layout.item_date, null);
view = layoutInflater.inflate(R.layout.item_layout, null);
viewHolder.date = view.findViewById(R.id.dateNumber);
viewHolder.containerCircle = view.findViewById(R.id.containerCircle);
viewHolder.container = view.findViewById(R.id.container);
Expand All @@ -73,15 +76,18 @@ public View getView(int i, View view, ViewGroup viewGroup) {
viewHolder.date.setTextSize(dateSize);
viewHolder.date.setTextColor(Color.parseColor(dateColor));
setCircle(viewHolder, calendarCustomObject.getUNCalendar());
setColorStroke(viewHolder.date, strokeCircleColor);
List<CalendarCustomObject> calendarCustomObjectList = getCurrentCalendarObjectBelongTo(rangeDates, calendarCustomObject);
if (calendarCustomObjectList != null) {
try {
if (DateUtils.checkIfDateInRange(calendarCustomObjectList, calendarCustomObject)) {
CalendarCustomObject tempCal = calendarCustomObjectList.get(0);
viewHolder.container.setBackground(ContextCompat.getDrawable(context, R.drawable.square));
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) viewHolder.container.getLayoutParams();
layoutParams.height = (int) UIUtils.convertDpToPixel(25, context);
layoutParams.gravity = Gravity.CENTER;
viewHolder.container.setLayoutParams(layoutParams);
setColorForBackgroundAndStroke(viewHolder.container, tempCal);
viewHolder.container.setPadding(0, -15, 0, -15);

CalendarCustomObject customObjectNext = (i + 1 >= dateNumber.size() ? null : dateNumber.get(i + 1));
CalendarCustomObject customObjectPre = (i - 1 < 0 ? null : dateNumber.get(i - 1));

Expand Down Expand Up @@ -142,6 +148,12 @@ private void setMarginForView(View view, int marginSide) {
if (view instanceof LinearLayout) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
params.setMargins(marginSide, 0, marginSide, 0);
view.setLayoutParams(params);
}
if (view instanceof FrameLayout) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.setMargins(marginSide, 0, marginSide, 0);
view.setLayoutParams(params);
}
}

Expand Down Expand Up @@ -174,7 +186,7 @@ private void setColorStroke(View view, String strokeColor) {
if (strokeColor == null) {
return;
}
UIUtils.setColorBackground(view, "#FFFFFF", strokeColor);
UIUtils.setColorBackground(view, null, strokeColor);
}

private void setCircle(ViewHolder viewHolder, UNCalendar compareDate) {
Expand All @@ -189,8 +201,7 @@ private void setCircle(ViewHolder viewHolder, UNCalendar compareDate) {

private static class ViewHolder {
TextView date;
LinearLayout containerCircle;
LinearLayout container;
FrameLayout containerCircle;
FrameLayout container;
}
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package nguyenngoctan44.io.uranashel_multirangecalendarview;

import android.content.Context;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

class UIUtils {
Expand All @@ -30,5 +33,15 @@ static void setColorBackground(View view, String colorBackground, String colorSt
Log.e("UraNashel Error: ", e.getMessage());
}
}
public static void setMarginForView(View view, int marginSide) {
if (view instanceof FrameLayout) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.setMargins(marginSide, 0, marginSide, 0);
view.setLayoutParams(params);
}
}
public static float convertDpToPixel(float dp, Context context) {
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public int getDate() {
public void setDate(int date) {
this.date = date;
}

@Override
public String toString() {
return "UNCalendar{" +
"year=" + year +
", month=" + month +
", date=" + date +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public void setCommonDatesDataInAMonth(List<CalendarCustomObject> calendarCustom
//Set string map
calendarCustomObjectArrayListWillBeDrawn.clear();
for (CalendarCustomObject calendarCustomObject : calendarCustomObjectsHasBeenMarked) {
Log.d("======Common", calendarCustomObject.getUNCalendar().getDate() + "_" + (calendarCustomObject.getUNCalendar().getMonth()) + "_" + calendarCustomObject.getUNCalendar().getYear() + "_" +
calendarCustomObject.getType());
calendarCustomObjectArrayListWillBeDrawn.add(addNewCalendarCustomObject(calendarCustomObject.getUNCalendar().getDate(), calendarCustomObject.getUNCalendar().getMonth(),
calendarCustomObject.getUNCalendar().getYear(), calendarCustomObject.getType(), calendarCustomObject.getColorBackground(), calendarCustomObject.getColorStroke()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
android:clickable="false"
android:adjustViewBounds="true"
android:focusable="false"
android:orientation="vertical">


<FrameLayout
android:id="@+id/containerDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">

<LinearLayout
<FrameLayout
android:id="@+id/containerCircle"
android:layout_width="match_parent"
android:layout_height="40dp"
Expand All @@ -28,23 +28,22 @@
android:gravity="center"
android:orientation="vertical">

<LinearLayout
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/dateNumber"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="normal"/>
</LinearLayout>

</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/dateNumber"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="normal"/>
</FrameLayout>
</FrameLayout>
</LinearLayout>

0 comments on commit 21de4f1

Please sign in to comment.