Skip to content

Commit

Permalink
calendar_padding_left & right,fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Nov 10, 2020
1 parent 171c09a commit 65f747a
Show file tree
Hide file tree
Showing 40 changed files with 1,171 additions and 104 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ implementation 'com.haibin:calendarview:3.6.8'

### Androidx version if using Androidx
```
implementation 'com.haibin:calendarview:3.6.9'
implementation 'com.haibin:calendarview:3.7.0'
```

```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.6.9</version>
<version>3.7.0</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ implementation 'com.haibin:calendarview:3.6.8

### Androidx版本使用
```
implementation 'com.haibin:calendarview:3.6.9'
implementation 'com.haibin:calendarview:3.7.0'
```

```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.6.6</version>
<version>3.7.0</version>
<type>pom</type>
</dependency>
```
Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.0.0'
//noinspection GradleDependency
implementation 'com.google.android.material:material:1.0.0'
//noinspection GradleDependency
implementation 'com.github.bumptech.glide:glide:3.7.0'
//implementation 'com.haibin:calendarview:3.6.7'

implementation 'androidx.appcompat:appcompat:1.2.0'

implementation 'com.google.android.material:material:1.2.1'

implementation 'com.github.bumptech.glide:glide:4.5.0'

testImplementation 'junit:junit:4.12'
implementation project(':calendarview')

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -30,6 +31,7 @@
<activity android:name=".single.SingleActivity" />
<activity android:name=".progress.ProgressActivity" />
<activity android:name=".custom.CustomActivity" />
<activity android:name=".mix.MixActivity" />
<activity android:name=".pager.ViewPagerActivity" />
<activity android:name=".full.FullActivity" />
<activity android:name=".TestActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ protected void onBindViewHolder(RecyclerView.ViewHolder holder, Article item, in
h.mTextTitle.setText(item.getTitle());
h.mTextContent.setText(item.getContent());
mLoader.load(item.getImgUrl())
.asBitmap()
.centerCrop()
.into(h.mImageView);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.haibin.calendarviewproject.meizu.MeiZuActivity;
import com.haibin.calendarviewproject.meizu.MeiZuMonthView;
import com.haibin.calendarviewproject.meizu.MeizuWeekView;
import com.haibin.calendarviewproject.mix.MixActivity;
import com.haibin.calendarviewproject.multi.MultiActivity;
import com.haibin.calendarviewproject.pager.ViewPagerActivity;
import com.haibin.calendarviewproject.progress.ProgressActivity;
Expand Down Expand Up @@ -195,8 +196,10 @@ protected void initData() {
Map<String, Calendar> map = new HashMap<>();
for (int y = 1997; y < 2082; y++) {
for (int m = 1; m <= 12; m++) {

map.put(getSchemeCalendar(y, m, 1, 0xFF40db25, "假").toString(),
getSchemeCalendar(y, m, 1, 0xFF40db25, "假"));

map.put(getSchemeCalendar(y, m, 2, 0xFFe69138, "游").toString(),
getSchemeCalendar(y, m, 2, 0xFFe69138, "游"));
map.put(getSchemeCalendar(y, m, 3, 0xFFdf1356, "事").toString(),
Expand Down Expand Up @@ -263,6 +266,7 @@ protected void initData() {
findViewById(R.id.ll_flyme).setOnClickListener(this);
findViewById(R.id.ll_simple).setOnClickListener(this);
findViewById(R.id.ll_range).setOnClickListener(this);
findViewById(R.id.ll_mix).setOnClickListener(this);
findViewById(R.id.ll_colorful).setOnClickListener(this);
findViewById(R.id.ll_index).setOnClickListener(this);
findViewById(R.id.ll_tab).setOnClickListener(this);
Expand Down Expand Up @@ -321,6 +325,9 @@ public void onClick(View v) {
case R.id.ll_custom:
CustomActivity.show(this);
break;
case R.id.ll_mix:
MixActivity.show(this);
break;
case R.id.ll_full:
FullActivity.show(this);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 11 * 5;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
Expand All @@ -110,7 +114,6 @@ protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y,
return true;
}

@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {

Expand Down
205 changes: 205 additions & 0 deletions app/src/main/java/com/haibin/calendarviewproject/mix/MixActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package com.haibin.calendarviewproject.mix;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarLayout;
import com.haibin.calendarview.CalendarView;
import com.haibin.calendarviewproject.Article;
import com.haibin.calendarviewproject.ArticleAdapter;
import com.haibin.calendarviewproject.R;
import com.haibin.calendarviewproject.base.activity.BaseActivity;
import com.haibin.calendarviewproject.colorful.ColorfulActivity;
import com.haibin.calendarviewproject.group.GroupItemDecoration;
import com.haibin.calendarviewproject.group.GroupRecyclerView;
import com.haibin.calendarviewproject.index.IndexActivity;
import com.haibin.calendarviewproject.simple.SimpleActivity;

import java.util.HashMap;
import java.util.Map;

public class MixActivity extends BaseActivity implements
CalendarView.OnCalendarSelectListener,
CalendarView.OnYearChangeListener,
View.OnClickListener {

TextView mTextMonthDay;

TextView mTextYear;

TextView mTextLunar;

TextView mTextCurrentDay;

CalendarView mCalendarView;

RelativeLayout mRelativeTool;
private int mYear;
CalendarLayout mCalendarLayout;
GroupRecyclerView mRecyclerView;

public static void show(Context context) {
context.startActivity(new Intent(context, MixActivity.class));
}


@Override
protected int getLayoutId() {
return R.layout.activity_mix;
}

@SuppressLint("SetTextI18n")
@Override
protected void initView() {
setStatusBarDarkMode();
mTextMonthDay = findViewById(R.id.tv_month_day);
mTextYear = findViewById(R.id.tv_year);
mTextLunar = findViewById(R.id.tv_lunar);
mRelativeTool = findViewById(R.id.rl_tool);
mCalendarView = findViewById(R.id.calendarView);
mTextCurrentDay = findViewById(R.id.tv_current_day);
mTextMonthDay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mCalendarLayout.isExpand()) {
mCalendarLayout.expand();
return;
}
mCalendarView.showYearSelectLayout(mYear);
mTextLunar.setVisibility(View.GONE);
mTextYear.setVisibility(View.GONE);
mTextMonthDay.setText(String.valueOf(mYear));
}
});
findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCalendarView.scrollToCurrent();
//mCalendarView.addSchemeDate(getSchemeCalendar(2019, 6, 1, 0xFF40db25, "假"));
// int year = 2019;
// int month = 6;
// Map<String, Calendar> map = new HashMap<>();
// map.put(getSchemeCalendar(year, month, 3, 0xFF40db25, "假").toString(),
// getSchemeCalendar(year, month, 3, 0xFF40db25, "假"));
// map.put(getSchemeCalendar(year, month, 6, 0xFFe69138, "事").toString(),
// getSchemeCalendar(year, month, 6, 0xFFe69138, "事"));
// map.put(getSchemeCalendar(year, month, 9, 0xFFdf1356, "议").toString(),
// getSchemeCalendar(year, month, 9, 0xFFdf1356, "议"));
// map.put(getSchemeCalendar(year, month, 13, 0xFFedc56d, "记").toString(),
// getSchemeCalendar(year, month, 13, 0xFFedc56d, "记"));
// mCalendarView.addSchemeDate(map);
}
});
mCalendarLayout = findViewById(R.id.calendarLayout);
mCalendarView.setOnCalendarSelectListener(this);
mCalendarView.setOnYearChangeListener(this);
mTextYear.setText(String.valueOf(mCalendarView.getCurYear()));
mYear = mCalendarView.getCurYear();
mTextMonthDay.setText(mCalendarView.getCurMonth() + "月" + mCalendarView.getCurDay() + "日");
mTextLunar.setText("今日");
mTextCurrentDay.setText(String.valueOf(mCalendarView.getCurDay()));
}

@Override
protected void initData() {
int year = mCalendarView.getCurYear();
int month = mCalendarView.getCurMonth();

Map<String, Calendar> map = new HashMap<>();
map.put(getSchemeCalendar(year, month, 3, 0xFF40db25, "假").toString(),
getSchemeCalendar(year, month, 3, 0xFF40db25, "假"));
map.put(getSchemeCalendar(year, month, 6, 0xFFe69138, "事").toString(),
getSchemeCalendar(year, month, 6, 0xFFe69138, "事"));
map.put(getSchemeCalendar(year, month, 9, 0xFFdf1356, "议").toString(),
getSchemeCalendar(year, month, 9, 0xFFdf1356, "议"));
map.put(getSchemeCalendar(year, month, 13, 0xFFedc56d, "记").toString(),
getSchemeCalendar(year, month, 13, 0xFFedc56d, "记"));
map.put(getSchemeCalendar(year, month, 14, 0xFFedc56d, "记").toString(),
getSchemeCalendar(year, month, 14, 0xFFedc56d, "记"));
map.put(getSchemeCalendar(year, month, 15, 0xFFaacc44, "假").toString(),
getSchemeCalendar(year, month, 15, 0xFFaacc44, "假"));
map.put(getSchemeCalendar(year, month, 18, 0xFFbc13f0, "记").toString(),
getSchemeCalendar(year, month, 18, 0xFFbc13f0, "记"));
map.put(getSchemeCalendar(year, month, 25, 0xFF13acf0, "假").toString(),
getSchemeCalendar(year, month, 25, 0xFF13acf0, "假"));
map.put(getSchemeCalendar(year, month, 27, 0xFF13acf0, "多").toString(),
getSchemeCalendar(year, month, 27, 0xFF13acf0, "多"));
//此方法在巨大的数据量上不影响遍历性能,推荐使用
mCalendarView.setSchemeDate(map);


mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new GroupItemDecoration<String, Article>());
mRecyclerView.setAdapter(new ArticleAdapter(this));
mRecyclerView.notifyDataSetChanged();
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ll_flyme:
MixActivity.show(this);
break;
case R.id.ll_simple:
SimpleActivity.show(this);
break;
case R.id.ll_colorful:
ColorfulActivity.show(this);
break;
case R.id.ll_index:
IndexActivity.show(this);
break;
}
}

private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
Calendar calendar = new Calendar();
calendar.setYear(year);
calendar.setMonth(month);
calendar.setDay(day);
calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
calendar.setScheme(text);
calendar.addScheme(new Calendar.Scheme());
calendar.addScheme(0xFF008800, "假");
calendar.addScheme(0xFF008800, "节");
return calendar;
}

@Override
public void onCalendarOutOfRange(Calendar calendar) {

}

@SuppressLint("SetTextI18n")
@Override
public void onCalendarSelect(Calendar calendar, boolean isClick) {
mTextLunar.setVisibility(View.VISIBLE);
mTextYear.setVisibility(View.VISIBLE);
mTextMonthDay.setText(calendar.getMonth() + "月" + calendar.getDay() + "日");
mTextYear.setText(String.valueOf(calendar.getYear()));
mTextLunar.setText(calendar.getLunar());
mYear = calendar.getYear();

Log.e("onDateSelected", " -- " + calendar.getYear() +
" -- " + calendar.getMonth() +
" -- " + calendar.getDay() +
" -- " + isClick + " -- " + calendar.getScheme());
}

@Override
public void onYearChange(int year) {
mTextMonthDay.setText(String.valueOf(year));
}


}
Loading

0 comments on commit 65f747a

Please sign in to comment.