Source code | Practical calendar control

Source code | Practical calendar control

Source code introduction: A practical calendar control modified by myself, with pop effect and animation.

Download address: http://download..com/data/2194851

Source code effect:

Source code snippet:

  1. public   static   synchronized PopCalendar getInstance(Context context, View parent, int gravity, OnCellClickListener onClickdate,
  2. OnClickListener onConfirm, OnDismissListener onDismiss) {
  3. if (gravity != - 1 ) {
  4. GRAVITY_FOR_POP = gravity;
  5. }
  6. if (context == null ) {
  7. return   null ;
  8. }
  9. if (parent == null ) {
  10. return   null ;
  11. }
  12.   
  13. if ( null == instance) {
  14. View view = LayoutInflater.from(context).inflate(R.layout.layout_calendar, null );
  15. mViewPager = (ViewPager) view.findViewById(R.id.activity_user_calendar_Viewpager);
  16. preImgBtn = (ImageButton) view.findViewById(R.id.activity_user_calendar_PreMonthBtn);
  17. nextImgBtn = (ImageButton) view.findViewById(R.id.activity_user_calendar_NextMonthBtn);
  18. slide_time = (TextView) view.findViewById(R.id.slide_time);
  19. TextView btn_confirm = (TextView) view.findViewById(R.id.tv_confirm);
  20. // Here are two ways to get the width and height getWindow().getDecorView().getWidth()  
  21. instance = new PopCalendar(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, parent);
  22.   
  23. final OnCellClickListener listener = onClickdate;
  24.   
  25. preImgBtn.setOnClickListener( new View.OnClickListener() {
  26.   
  27. @Override  
  28. public   void onClick(View v) {
  29. mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1 );
  30. }
  31. });
  32. nextImgBtn.setOnClickListener( new View.OnClickListener() {
  33.   
  34. @Override  
  35. public   void onClick(View v) {
  36. mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1 );
  37. }
  38. });
  39.   
  40. Calendar c = Calendar.getInstance();
  41.   
  42. CalendarCard[] views = new CalendarCard[ 3 ];
  43. for ( int i = 0 ; i < 3 ; i++) {
  44. views[i] = new CalendarCard(context, new OnCellClickListener() {
  45.   
  46. @Override  
  47. public   void clickDate(CustomDate date) {
  48. if (listener != null ) {
  49. listener.clickDate(date);
  50. }
  51. // window.dismiss();  
  52. }
  53.   
  54. @Override  
  55. public   void changeDate(CustomDate date) {
  56. slide_time.setText(date.year + "year" + date.month + "month" );
  57. }
  58. },liang);
  59. }
  60.   
  61. adapter = new CalendarViewAdapter<calendarcard>(views);
  62. setViewPager();
  63.   
  64. // Set the popWindow pop-up form to be clickable. This sentence must be added and must be true  
  65. instance.setFocusable( true );
  66.   
  67. // Instantiate a ColorDrawable with a semi-transparent color  
  68. ColorDrawable dw = new ColorDrawable( 0xffffffff );
  69. instance.setBackgroundDrawable(dw);
  70. final OnClickListener onclick = onConfirm;
  71. btn_confirm.setOnClickListener( new View.OnClickListener() {
  72.   
  73. @Override  
  74. public   void onClick(View v) {
  75. if (onclick != null ) {
  76. onclick.onClick(v);
  77. }
  78. instance.dismiss();
  79. }
  80. });
  81.   
  82. // Set the display and disappearance animation of popWindow  
  83. instance.setAnimationStyle(R.style.mypopwindow_anim_style);
  84. // Display at the bottom  
  85. // View parent = activity.findViewById(R.id.contact_main);  
  86. // window.showAtLocation(parent, GRAVITY_FOR_POP, X_LOCATION,  
  87. // Y_LOCATION);  
  88. final OnDismissListener dListener = onDismiss;
  89. // popWindow disappearance monitoring method  
  90. instance.setOnDismissListener( new OnDismissListener() {
  91.   
  92. @Override  
  93. public   void onDismiss() {
  94. if (dListener != null ) {
  95. dListener.onDismiss();
  96. }
  97. System.out.println( "popWindow disappears" );
  98. }
  99. });
  100. }
  101. return instance;
  102. }</calendarcard>

<<:  15 interesting facts about mobile apps

>>:  Source code | Uber's welcome screen

Recommend

Can medication be taken with coffee or milk? The truth is…

Coffee and medicine For China, a country with a l...

After teasing 22 apps, Wandoujia launched a grand art marketing campaign...

As one of the earlier Android app stores to be la...

How to activate the massive Qianchuan delivery on Douyin?

On April 9, Douyin's Juliang Qianchuan was of...

Why do deep space probes circle before reaching their destination?

According to foreign media reports, the BepiColom...

Textile in Idioms

The Xujiayao Ancient Human Site in Datong, Shanxi...

Baijiahao operation, how can Baijiahao novices improve the Baijia index?

1. What is the Baijiahao Index? The Baijiahao Ind...

Nexus 7 second generation MIUI experience

Google Nexus 7 2nd generation is the benchmark of ...

WeChat Reading: 5 APP fission growth methods based on paid membership

WeChat Reading has made good use of its product t...

Analysis of advertising in the education and training industry from March to May

Due to the impact of delayed resumption of work, ...

Which cooking oil reduces the risk of cancer? Harvard's latest research reveals

As an important part of our daily diet, the healt...

How to reason decently?

Communication, discussion, debate, expounding opi...

Wen Xiaogang: What is a quantum bit? | The Door to Wonders

A bit is something that has two values: 0 and 1. ...