Giter Club home page Giter Club logo

android-vertically-scrollable-calendar-prototype's Introduction

Android Vertically Scrollable Calendar Prototype

This is the Android sample project making the Vertically scrollable calendar for study. You can see sample video.

Check logic point 1

I create the base date to sync page position with particular date. And I also create the base position in middle of thousands pages.

/** Default year to calculate the page position */
final static int BASE_YEAR = 2015;
/** Default month to calculate the page position */
final static int BASE_MONTH = Calendar.JANUARY;
/** Calendar instance based on default year and month */
final Calendar BASE_CAL;
/** Page numbers to reuse */
final static int PAGES = 5;
/** Loops, I think 1000 may be infinite scroll. */
final static int LOOPS = 1000;
/** position basis */
final static int BASE_POSITION = PAGES * LOOPS / 2;
...
Calendar base = Calendar.getInstance();
base.set(BASE_YEAR, BASE_MONTH, 1);
BASE_CAL = base;
...

Check logic point 2

Then, we can get the particular date by page position.

public YearMonth getYearMonth(int position) {
  Calendar cal = (Calendar)BASE_CAL.clone();
  cal.add(Calendar.MONTH, position - BASE_POSITION);
  return new YearMonth(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH));
}

Check logic point 3

We can get the particular page position by given date.

/**
* Get the page position by given date
* @param year 4 digits number of year
* @param month month number
* @return page position
*/
public int getPosition(int year, int month) {
  Calendar cal = Calendar.getInstance();
  cal.set(year, month, 1);
  return BASE_POSITION + howFarFromBase(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH));
}

/**
* How many months exist from the base month to the given values?
* @param year the year to compare with the base year
* @param month the month to compare with the base month
* @return counts of month
*/
private int howFarFromBase(int year, int month) {
  int disY = (year - BASE_YEAR) * 12;
  int disM = month - BASE_MONTH;
  return disY + disM;
}

In this project, I use VerticalViewPager-1 for just vertical view pager. And I refer to 'SimpleInfiniteCarousel' to make a simple infinite carousel with ViewPager on Android.

Sorry

I am not good at english. please let me know the misspelled comments in my code.^^;

세로 스크롤 달력 프로토타입 안드로이드 예제

이 저장소는 안드로이드에서 세로 스크롤이 가능한 달력을 만들기 위해 만든 목업샘플입니다. 관련 내용을 제 블로그에서 더 확인하실 수 있습니다. 한수댁 작업실

android-vertically-scrollable-calendar-prototype's People

Contributors

brownsoo avatar

Watchers

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