Git Product home page Git Product logo

tongzhou-j / calendarview1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angcyo/calendarview

0.0 0.0 0.0 126.7 MB

Android上一个优雅、万能自定义UI、支持周视图、自定义周起始、性能高效的日历控件,支持热插拔实现的UI定制!支持标记、自定义颜色、农历、自定义月视图各种显示模式等。Canvas绘制,速度快、占用内存低,你真的想不到日历居然还可以如此优雅!An elegant, highly customized and high-performance Calendar Widget on Android.

License: Apache License 2.0

Java 100.00%

calendarview1's Introduction

CalenderView

基于CalenderView3.7.1的版本修改, 实现了如下功能:

  • 垂直列表日历: 基于RecyclerView实现

月份的排列方式是上下结构, 上一个月 当前月 下一个月在垂直方向排列

  • 垂直滚动日历: 通过交换ViewPagerTouchEvent实现

可以通过下滑 上滑的方式, 切换上一个月 下一个月

  • touchDown时的效果提示支持, 需要在onDraw方法中自定义实现

通过此标识, 可以实现手指按下时缩放背景的效果

  • 周/月视图选择日历的动画在月/周视图中, 切换不同日的日历时的动画支持

日期切换时, 有动画效果

效果图

垂直滚动 垂直列表
月视图动画 周视图动画
按下效果 --
--

使用方式如下:

加入仓库地址

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

加入依赖

implementation 'com.github.angcyo:CalendarView:3.7.1.27'

垂直滚动日历使用方式

mCalendarView.getMonthViewPager().setOrientation(LinearLayout.VERTICAL);

垂直列表日历使用方式

使用VerticalCalendarView控件即可.

com.haibin.calendarview.VerticalCalendarView

按下效果实现参考代码

自定义MonthView控件, 实现如下方法:

@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
    int cx = x + mItemWidth / 2;
    int cy = y + mItemHeight / 2;
    if (isTouchDown && mCurrentItem == mItems.indexOf(getIndex())) {
        //点击当前选中的item, 缩放效果提示
        canvas.drawCircle(cx, cy, mRadius - dipToPx(getContext(), 4), mSelectedPaint);
    } else {
        canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
    }
    return true;
}

开源地址

感谢作者的开源库!

https://github.com/angcyo/CalendarView


周视图直接滚动到上一个月下一个月

上一个月

int currentItem = mWeekPager.getCurrentItem();
BaseView baseView = mWeekPager.findViewWithTag(currentItem);
Calendar firstCalendar = baseView.mItems.get(0);
int days = CalendarUtil.getMonthDaysCount(firstCalendar.getYear(), firstCalendar.getMonth());
Calendar targetCalendar = CalendarUtil.getCalendarWidthDiffer(firstCalendar, - days * ONE_DAY);
mWeekPager.scrollToCalendar(targetCalendar.getYear(), targetCalendar.getMonth(), targetCalendar.getDay(), smoothScroll, false);

下一个月

int currentItem = mWeekPager.getCurrentItem();
BaseView baseView = mWeekPager.findViewWithTag(currentItem);
Calendar firstCalendar = baseView.mItems.get(0);
int days = CalendarUtil.getMonthDaysCount(firstCalendar.getYear(), firstCalendar.getMonth());
Calendar targetCalendar = CalendarUtil.getCalendarWidthDiffer(firstCalendar, days * ONE_DAY);
mWeekPager.scrollToCalendar(targetCalendar.getYear(), targetCalendar.getMonth(), targetCalendar.getDay(), smoothScroll, false);

工具类

/**
 * 获取指定相差天数的日历
 * [millis] 相差的毫秒数
 * */
public static Calendar getCalendarWidthDiffer(Calendar calendar, long millis) {
    java.util.Calendar date = java.util.Calendar.getInstance();

    date.set(calendar.getYear(), calendar.getMonth() - 1, calendar.getDay(), 12, 0, 0);//

    long timeMills = date.getTimeInMillis();//获得起始时间戳

    date.setTimeInMillis(timeMills + millis);

    Calendar preCalendar = new Calendar();
    preCalendar.setYear(date.get(java.util.Calendar.YEAR));
    preCalendar.setMonth(date.get(java.util.Calendar.MONTH) + 1);
    preCalendar.setDay(date.get(java.util.Calendar.DAY_OF_MONTH));

    return preCalendar;
}

CalenderView

An elegant CalendarView on Android platform. Freely draw UI with canvas, fast、efficient and low memory. Support month view、 week view、year view、 custom week start、lunar calendar and so on. Hot plug UI customization! You can't think of the calendar can be so elegant!

温馨提醒 Warm tips

Github代码全部开源无限制使用,免费开源最终版本为3.7.1,垂直、水平切换日历、高仿iOS日历等源码不再开源。

The final version of the free and open source part is 3.7.1, the vertical and horizontal switching calendar liked iOS calendar are no longer open source.

          

          

AndroidStudio v3.5+

support version if using support package

implementation 'com.haibin:calendarview:3.6.8'

Androidx version if using Androidx

implementation 'com.haibin:calendarview:3.7.1'
<dependency>
  <groupId>com.haibin</groupId>
  <artifactId>calendarview</artifactId>
  <version>3.7.0</version>
  <type>pom</type>
</dependency>

How to use?

English Doc

中文使用文档

proguard-rules

-keepclasseswithmembers class * {
    public <init>(android.content.Context);
}

or using this proguard-rules

-keep class your project path.MonthView {
    public <init>(android.content.Context);
}
-keep class your project path.WeekBar {
    public <init>(android.content.Context);
}
-keep class your project path.WeekView {
    public <init>(android.content.Context);
}
-keep class your project path.YearView {
    public <init>(android.content.Context);
}

Effect Preview

func

     

YearView and Range Style

     

Beautiful Chinese style

     

Meizu mobile phone calendar

     

Colorful and Full style

     

Progress bar style

     

Galaxy style

     

Licenses

  • Copyright (C) 2013 huanghaibin_dev [email protected]

  • 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.

calendarview1's People

Contributors

huanghaibin-dev avatar angcyo avatar shuwnyuantee avatar stanllley avatar yccheok avatar qq157755587 avatar codingbooo avatar peterforme avatar wenhui-prudencemed 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.