# Caldroid **Repository Path**: trigger/Caldroid ## Basic Information - **Project Name**: Caldroid - **Description**: A better calendar for Android - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2015-05-23 - **Last Updated**: 2024-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Caldroid ======== Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User can also swipe left/right to navigate to different months. It's very easy to customize look and feel of Caldroid using your own theme, thanks to [@crocodile2u](https://github.com/crocodile2u) contribution. There are two default themes in Caldroid (Light and Dark). You can provide your own theme based on these default themes as well. Caldroid is fully localized. You can customize start day of the week for different countries. By default calendar start on Sunday. Caldroid can be used with Android 2.2 and above. It is extracted from [official Roomorama application](https://play.google.com/store/apps/details?id=com.roomorama) If you found bugs specific to Caldroid, please open a new issue on Github. However for general Android questions (about layout, drawable, etc), you probably can find more information on StackOverflow. Setup ===== **For Eclipse/ADT user**: please see tag [eclipse_project](https://github.com/roomorama/Caldroid/releases/tag/eclipse_project), download the source codes, check out the CaldroidSample to see how the library works. However you are strongly recommended to use Maven or gradle, because this tag is no longer supported. To use in your project, reference the child library project as a library. If you see JAR mismatched error, replace your android-support-v4.jar to the jar inside Caldroid. Make sure you compile the project against Android 4.2 and above to allow nested fragment. See more at http://developer.android.com/about/versions/android-4.2.html#NestedFragments **For Android Studio user**: add `compile 'com.roomorama:caldroid:2.0.0'` to your gradle build file. **For Maven user**: ``` com.roomorama caldroid 2.0.0 ``` Features ======== ##Flexible setup: can be embedded or shown as dialog If you support Android 2.2 and above, you can embed caldroid fragment in your activity with below code: ``` java CaldroidFragment caldroidFragment = new CaldroidFragment(); Bundle args = new Bundle(); Calendar cal = Calendar.getInstance(); args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1); args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR)); caldroidFragment.setArguments(args); FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.calendar1, caldroidFragment); t.commit(); ``` If your app only target minSdkVersion 16 and above, you can use Caldroid too. First, you need to change your `Activity` class to `FragmentActivity`, and add support library to your project. You don't have to change how you use `android.app.Fragment`. ```java CaldroidFragment caldroidFragment = new CaldroidFragment(); Bundle args = new Bundle(); Calendar cal = Calendar.getInstance(); args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1); args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR)); caldroidFragment.setArguments(args); android.support.v4.app.FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.cal, caldroidFragment); t.commit(); ``` You can also embed caldroid fragment as a child in your fragment. Caldroid accepts numerous arguments during start up: ``` java public final static String DIALOG_TITLE = "dialogTitle", MONTH = "month", YEAR = "year", SHOW_NAVIGATION_ARROWS = "showNavigationArrows", DISABLE_DATES = "disableDates", SELECTED_DATES = "selectedDates", MIN_DATE = "minDate", MAX_DATE = "maxDate", ENABLE_SWIPE = "enableSwipe", START_DAY_OF_WEEK = "startDayOfWeek", SIX_WEEKS_IN_CALENDAR = "sixWeeksInCalendar", ENABLE_CLICK_ON_DISABLED_DATES = "enableClickOnDisabledDates", SQUARE_TEXT_VIEW_CELL = "squareTextViewCell", THEME_RESOURCE = "themeResource"; ``` To customize the startDayOfWeek, just use ``` java Bundle args = new Bundle(); args.putInt(CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.TUESDAY); // Tuesday caldroidFragment.setArguments(args); ``` If you want to know when user clicks on disabled dates: ```java Bundle args = new Bundle(); args.putBoolean(CaldroidFragment.ENABLE_CLICK_ON_DISABLED_DATES, true); caldroidFragment.setArguments(args); ``` By default, Caldroid use square TextView to display date. However when the screen has limited space, user can switch to normal TextView instead: ```java Bundle args = new Bundle(); args.putBoolean(CaldroidFragment.SQUARE_TEXT_VIEW_CELL, false); caldroidFragment.setArguments(args); ``` Caldroid uses `SQUARE_TEXT_VIEW_CELL` parameter internally as well. When the phone is in portrait mode, it will default `SQUARE_TEXT_VIEW_CELL` to `true`, and on landscape, `SQUARE_TEXT_VIEW_CELL` is set to `false`. If your app provides different value, Caldroid will use your value instead of the default one. To show the caldroid fragment as a dialog, you might want to set the dialog title. There is a convenient method for that: ``` java CaldroidFragment dialogCaldroidFragment = CaldroidFragment.newInstance("Select a date", 3, 2013); dialogCaldroidFragment.show(getSupportFragmentManager(),"TAG"); ``` ## Custom theme You can define your own theme to change the look and feel of Caldroid without having to subclass it. You should inherit from base theme `CaldroidDefault`. Here's how to create a dark theme: ```xml