Giter Site home page Giter Site logo

android-calendarview's Introduction

Android-CalendarView

There are two different modes as the pictures above show.

The former is in the normal calendar mode.

The latter is in the record mode, aiming to record the completion of your plans in the current month.

Support API LEVEL >= 7.

Including In Your Project

Gradle

Add the following code in the build.gradle of your module.

dependencies {
    compile 'cn.zhikaizhang.calendar:library:1.0.0'
}

Download the source code

You can also download the source code of the project and import the library module into your project as a module so that you can modify the source code.

Usage

For a working implementation of this project see the sample/ folder.

Step1. Include one of the widgets in your xml. You can set the mode 0 for the normal calendar mode and 1 for the record mode. You can also the mode in your java code.

<cn.zhikaizhang.calendarview.CalendarView
        android:id="@+id/calendarView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:mode="0">
</cn.zhikaizhang.calendarview.CalendarView>

Step2. Refresh the CalendarView. You will use refresh0() for the normal calendar mode and refresh1() for the record mode.

calendarView.setMode(0);
//refresh the CalendarView with new values of year and month
calendarView.refresh0(year, month);

calendarView.setMode(1);
//simulate to get data
int days = calendarView.daysOfCurrentMonth();
boolean data[] = new boolean[days+1];
int today = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
for(int i = 1; i <= days; i++){
	if(i <= today){
		data[i] = (Math.random() > 0.5);
	}else{
		data[i] = false;
	}
}
calendarView.refresh1(data);

Step3. Set the appearance you like. You can set the language to English or Chinese. You can also modify the color and size of the text.

/**
 * modify the language of head of the calendar
 * legal values of style : 0 - 3
 * 0, 1, 2 : Chinese, 3 : English
 */
calendarView.setWeekTextStyle(style);

//set the text color of the head
calendarView.setWeekTextColor(Color.BLACK);

/**
 * set the scale of text size of the head
 * legal values : 0.0f - 1.0f
 */
calendarView.setWeekTextSizeScale(0.5f);

//set the text color of the calendar cell
calendarView.setCalendarTextColor(Color.BLACK);

/**
 * set the scale of text size of the calendar cell
 * legal values : 0.0f - 1.0f
 */
calendarView.setTextSizeScale(0.5f);

Step4. Implement the callback. Set the OnRefreshListener to do what you want after you refresh the calendar and set the OnItemClickListener to do what you want after you click a day.

calendarView.setOnRefreshListener(new ICalendarView.OnRefreshListener() {
	@Override
	public void onRefresh() {
		yearMonthTextView.setText(getYearMonthText(calendarView.getYear(), calendarView.getMonth()));
	}
});

calendarView.setOnItemClickListener(new ICalendarView.OnItemClickListener() {
	@Override
	public void onItemClick(int day) {
		int year = calendarView.getYear();
		int month = calendarView.getMonth();
		Toast.makeText(Demo0.this, year + "-" + month + "-" + day, Toast.LENGTH_SHORT).show();
	}
});

Author

License

Copyright 2016 ZhikaiZhang 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-calendarview's People

Contributors

laserwave avatar ravidsrk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.