diff --git a/README.md b/README.md index 7e59606..3c9bb24 100644 --- a/README.md +++ b/README.md @@ -1 +1,222 @@ -# VRCalendarView \ No newline at end of file +# VRCalendarView + +# Usage + +*For a working implementation, Have a look at the Sample Project - app* + +1. Include the library as local library project. +```gradle +allprojects { + repositories { + maven { url 'https://jitpack.io' } + } +} + +dependencies { + + compile 'com.github.VRGsoftUA:not ready yet' + +} +``` +2. Include the VRCalendarView widget in your layout. + + ```xml + + ``` +3. You can do same with java + ```java + vrCalendarView.getSettings().setOtherMonthTextStyle(VRCalendarView.BOLD) + .setCurrentMonthBackgroundColor(Color.CYAN) + .updateCalendar(); + ``` +or + ```java + vrCalendarView.getSettings() + .setOnCalendarClickListener(this) + .setOnCalendarLongClickListener(this) + .setVRCalendarMonthCallback(this); + ``` + +4. You can update all days by calling VRCalendarView.getSettings().updateCalendar(); + + ```java + vrCalendarView.getSettings().setOtherMonthTextStyle(VRCalendarView.BOLD) + .setCurrentMonthBackgroundColor(Color.CYAN) + .updateCalendar(); + ``` + if VRCalendarView.getSettings().updateCalendar(); is called and you want to save some custom day + List getCustomizeDayView(Calendar calendar) method should be overridden + getCustomizeDayView(Calendar calendar) is return all days you need to make custom. + With parameter calendar you can get the year and the month to return customised days from specific month + ```java + @Override + public List getCustomizeDayView(Calendar calendar) { + List vrCalendarDays = new ArrayList<>(); + VrCalendarDay today = new VrCalendarDay(); + today.setDate(new Date()); + + VrCalendarDaySettings todaySettings = new VrCalendarDaySettings(); + todaySettings.setDayTextColor(Color.CYAN); + today.setVrCalendarDaySettings(todaySettings); + today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() { + @Override + public View getNewCustomiseView() { + ImageView imageView = new ImageView(MainActivity.this); + imageView.setImageResource(R.drawable.ic_stat_name); + return imageView; + } + }); + + vrCalendarDays.add(today); + + VrCalendarDay tomorrow = new VrCalendarDay(); + Date d = new Date(1513435110633L);// December 16, 2017 + tomorrow.setDate(d); + VrCalendarDaySettings vrtomorCalendarDaySettings = new VrCalendarDaySettings(); + vrtomorCalendarDaySettings.setDayTextStyle(VRCalendarView.BOLD); + vrtomorCalendarDaySettings.setDayBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent)); + vrtomorCalendarDaySettings.setDayTextColor(ContextCompat.getColor(this, R.color.colorYellow)); + tomorrow.setVrCalendarDaySettings(vrtomorCalendarDaySettings); + + vrCalendarDays.add(tomorrow); + + return vrCalendarDays; + } + ``` + You can set set whatever view you want and customise it like you want if standard customisation does not fit + Attention!!! + View getNewCustomiseView() should always return new View. other wise it doesn't work properly + ```java + today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() { + @Override + public View getNewCustomiseView() { + ImageView imageView = new ImageView(MainActivity.this); + imageView.setImageResource(R.drawable.ic_stat_name); + return imageView; + } + }); + ``` + + but if you need to update specific day it is better to call + + ```java + vrCalendarView.getSettings().updateCalendarDay(VrCalendarDay today, boolean hasToSelect); + ``` + where VrCalendarDay has settings to customise specific day - hasToSelect should be false than + and hasToSelect is boolean that sets specific customisation + not from VrCalendarDay settings but from default settings that has attribute "chosen". Like below + ```xml + app:vr_chosen_day_background_color="@color/colorGreen" + app:vr_chosen_day_background_drawable="@drawable/background" + ``` + to update specific day you have to set VRCalendarDay.setDate(Date date); - it is required + ```java + VrCalendarDay today = new VrCalendarDay(); + today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() { + @Override + public View getNewCustomiseView() { + ImageView imageView = new ImageView(MainActivity.this); + imageView.setImageResource(R.drawable.ic_stat_name); + return imageView; + } + }); + today.setDate(day.getDate()); + ``` + + + +5. There is onClick listener and onLongClick + ```java + + public interface OnCalendarLongClickListener { + void onCalendarDayLongClick(VrCalendarDay day); + } + ``` + + and + + ```java + public interface OnCalendarClickListener { + void onCalendarDayClick(VrCalendarDay day); + } + + ``` +that returns VrCalendarDay you click on + + #### Customisation + You can add fields via xml or VrCalendarView or VrCalendarView.getSettings(). +Supported fields: + ```xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ``` + #### Contributing +* Contributions are always welcome +* If you want a feature and can code, feel free to fork and add the change yourself and make a pull request diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..51856ea --- /dev/null +++ b/app/app.iml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..0370acb --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + buildToolsVersion "27.0.2" + defaultConfig { + applicationId "com.vrgsoft.calendarview" + minSdkVersion 16 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:27.0.2' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' + compile project(path: ':calendar') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..ce3149c --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e3b2c75 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/vrgsoft/calendarview/MainActivity.java b/app/src/main/java/com/vrgsoft/calendarview/MainActivity.java new file mode 100644 index 0000000..1409f96 --- /dev/null +++ b/app/src/main/java/com/vrgsoft/calendarview/MainActivity.java @@ -0,0 +1,143 @@ +package com.vrgsoft.calendarview; + +import android.graphics.Color; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; + +import com.vrgsoft.calendar.VRCalendarCustomViewCallback; +import com.vrgsoft.calendar.calendar_listeners.OnCalendarClickListener; +import com.vrgsoft.calendar.calendar_listeners.OnCalendarLongClickListener; +import com.vrgsoft.calendar.VRCalendarView; +import com.vrgsoft.calendar.calendar_listeners.VRCalendarMonthCallback; +import com.vrgsoft.calendar.VrCalendarDay; +import com.vrgsoft.calendar.VrCalendarDaySettings; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class MainActivity extends AppCompatActivity implements OnCalendarClickListener, OnCalendarLongClickListener, VRCalendarMonthCallback { + + private VRCalendarView vrCalendarView; + private DateFormat df = new SimpleDateFormat("yyyy-MMMM-dd", Locale.getDefault()); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + vrCalendarView = findViewById(R.id.calendar); + vrCalendarView.getSettings() + .setOnCalendarClickListener(this) + .setOnCalendarLongClickListener(this) + .setVRCalendarMonthCallback(this); + + findViewById(R.id.prev).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, 2019); + calendar.set(Calendar.MONTH, 6); + calendar.set(Calendar.DAY_OF_MONTH, 27); + vrCalendarView.moveToDate(new Date(calendar.getTimeInMillis())); + } + }); + findViewById(R.id.next).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, 2015); + calendar.set(Calendar.MONTH, 6); + calendar.set(Calendar.DAY_OF_MONTH, 27); + vrCalendarView.moveToDate(new Date(calendar.getTimeInMillis())); + } + }); + + findViewById(R.id.update).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + vrCalendarView.getSettings() + .setOtherMonthTextStyle(VRCalendarView.BOLD) + .setCurrentMonthBackgroundColor(Color.CYAN) + .updateCalendar(); + } + }); + } + + @Override + public void onCalendarDayClick(VrCalendarDay day) { + Toast.makeText(MainActivity.this, " " + df.format(day.getDate()), Toast.LENGTH_SHORT).show(); + + VrCalendarDay today = new VrCalendarDay(); + today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() { + @Override + public View getNewCustomiseView() { + ImageView imageView = new ImageView(MainActivity.this); + imageView.setImageResource(R.drawable.ic_stat_name); + return imageView; + } + }); + today.setDate(day.getDate()); + + vrCalendarView.getSettings().updateCalendarDay(today, true); + + } + + @Override + public void onCalendarDayLongClick(VrCalendarDay day) { + Toast.makeText(MainActivity.this, "Long " + df.format(day.getDate()), Toast.LENGTH_SHORT).show(); + + VrCalendarDay today = new VrCalendarDay(); + today.setDate(day.getDate()); + VrCalendarDaySettings vrCalendarDaySettings = new VrCalendarDaySettings(); + vrCalendarDaySettings.setDayTextStyle(VRCalendarView.BOLD); + vrCalendarDaySettings.setDayTextSize(13); + vrCalendarDaySettings.setDayBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)); + vrCalendarDaySettings.setDayTextColor(ContextCompat.getColor(this, R.color.colorToday)); + today.setVrCalendarDaySettings(vrCalendarDaySettings); + + vrCalendarView.getSettings().updateCalendarDay(today, false); + } + + @Override + public List getCustomizeDayView(Calendar calendar) { + List vrCalendarDays = new ArrayList<>(); + VrCalendarDay today = new VrCalendarDay(); + today.setDate(new Date()); + + VrCalendarDaySettings todaySettings = new VrCalendarDaySettings(); + todaySettings.setDayTextColor(Color.CYAN); + today.setVrCalendarDaySettings(todaySettings); + today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() { + @Override + public View getNewCustomiseView() { + ImageView imageView = new ImageView(MainActivity.this); + imageView.setImageResource(R.drawable.ic_stat_name); + return imageView; + } + }); + + vrCalendarDays.add(today); + + VrCalendarDay tomorrow = new VrCalendarDay(); + Date d = new Date(1513435110633L); + tomorrow.setDate(d); + VrCalendarDaySettings vrtomorCalendarDaySettings = new VrCalendarDaySettings(); + vrtomorCalendarDaySettings.setDayTextStyle(VRCalendarView.BOLD); + vrtomorCalendarDaySettings.setDayBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent)); + vrtomorCalendarDaySettings.setDayTextColor(ContextCompat.getColor(this, R.color.colorYellow)); + tomorrow.setVrCalendarDaySettings(vrtomorCalendarDaySettings); + + vrCalendarDays.add(tomorrow); + + return vrCalendarDays; + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_next.png b/app/src/main/res/drawable-hdpi/ic_next.png new file mode 100644 index 0000000..a2e65ab Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_next.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_previous.png b/app/src/main/res/drawable-hdpi/ic_previous.png new file mode 100644 index 0000000..d8e3c16 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_previous.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_stat_name.png b/app/src/main/res/drawable-hdpi/ic_stat_name.png new file mode 100644 index 0000000..718075b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_stat_name.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_next.png b/app/src/main/res/drawable-mdpi/ic_next.png new file mode 100644 index 0000000..f940c5d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_next.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_previous.png b/app/src/main/res/drawable-mdpi/ic_previous.png new file mode 100644 index 0000000..5b76f5f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_previous.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_stat_name.png b/app/src/main/res/drawable-mdpi/ic_stat_name.png new file mode 100644 index 0000000..c156b9b Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_stat_name.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_next.png b/app/src/main/res/drawable-xhdpi/ic_next.png new file mode 100644 index 0000000..7b2caeb Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_next.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_previous.png b/app/src/main/res/drawable-xhdpi/ic_previous.png new file mode 100644 index 0000000..763b889 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_previous.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_stat_name.png b/app/src/main/res/drawable-xhdpi/ic_stat_name.png new file mode 100644 index 0000000..3bef406 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_stat_name.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_next.png b/app/src/main/res/drawable-xxhdpi/ic_next.png new file mode 100644 index 0000000..32c55d9 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_next.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_previous.png b/app/src/main/res/drawable-xxhdpi/ic_previous.png new file mode 100644 index 0000000..248ef5f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_previous.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_stat_name.png b/app/src/main/res/drawable-xxhdpi/ic_stat_name.png new file mode 100644 index 0000000..ee55f08 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_stat_name.png differ diff --git a/app/src/main/res/drawable/background.xml b/app/src/main/res/drawable/background.xml new file mode 100644 index 0000000..9128c3a --- /dev/null +++ b/app/src/main/res/drawable/background.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..8ac66c3 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,58 @@ + + + + + + +