Skip to content

Commit

Permalink
增加月状态下拉伸功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Jul 25, 2019
1 parent 85333f7 commit c269cc0
Show file tree
Hide file tree
Showing 26 changed files with 563 additions and 172 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file added app/Stretch.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "4.2.0"
versionName "4.3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
<activity
android:name=".activity.TestGeneralActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.TestStretchActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.TestActviity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void general(View view) {
startActivity(new Intent(this, TestGeneralActivity.class));
}

public void stretch(View view) {
startActivity(new Intent(this, TestStretchActivity.class));
}


private Intent getNewIntent(Class<? extends BaseActivity> clazz, SelectedModel selectedModel, String title) {
Intent intent = new Intent(this, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.necer.listener.OnCalendarChangedListener;
import com.necer.listener.OnCalendarMultipleChangedListener;
import com.necer.ncalendar.R;
import com.necer.ncalendar.painter.LigaturePainter;
import com.necer.painter.InnerPainter;
import com.necer.utils.CalendarUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.necer.enumeration.CalendarState;
import com.necer.listener.OnCalendarChangedListener;
import com.necer.listener.OnCalendarMultipleChangedListener;
import com.necer.listener.OnCalendarScrollingListener;
import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.RecyclerViewAdapter;

Expand Down Expand Up @@ -66,6 +67,13 @@ public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, Lis
}
});

miui9Calendar.setOnCalendarScrollingListener(new OnCalendarScrollingListener() {
@Override
public void onCalendarScrolling(int dy) {
Log.d(TAG, "onCalendarScrolling::" + dy);
}
});

}

public void jump_2018_08_11(View view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.necer.ncalendar.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.necer.calendar.Miui10Calendar;
import com.necer.ncalendar.R;
import com.necer.ncalendar.painter.StretchPainter;
import com.necer.painter.InnerPainter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestStretchActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stretch);

Miui10Calendar miui10Calendar = findViewById(R.id.miui10Calendar);
miui10Calendar.setMonthStretchEnable(true);


List<String> pointList = Arrays.asList("2019-07-01", "2019-07-19", "2019-07-25", "2019-05-23", "2019-01-01", "2018-12-23");

InnerPainter innerPainter = (InnerPainter) miui10Calendar.getCalendarPainter();
innerPainter.setPointList(pointList);


Map<String, String> strMap = new HashMap<>();
strMap.put("2019-07-01", "测试");
strMap.put("2019-07-19", "测试1");
strMap.put("2019-07-25", "测试2");
strMap.put("2019-08-25", "测试3");
strMap.put("2019-08-28", "测试4");
strMap.put("2019-11-26", "测试5");
innerPainter.setStretchStrMap(strMap);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
recyclerView = findViewById(R.id.recyclerView);
miui9Calendar = findViewById(R.id.miui9Calendar);

miui9Calendar.setWeekHoldEnable(true);

recyclerView.setLayoutManager(new LinearLayoutManager(this));
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this);
Expand Down
70 changes: 70 additions & 0 deletions app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.necer.ncalendar.painter;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.TextUtils;

import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;

import org.joda.time.LocalDate;

import java.util.List;

public class StretchPainter implements CalendarPainter {
protected Paint mTextPaint;
protected Paint mBgPaint;

public StretchPainter(Context context) {
mBgPaint = getPaint();
mTextPaint = getPaint();
mBgPaint.setColor(Color.parseColor("#ff7575"));
mTextPaint.setTextSize(CalendarUtil.dp2px(context, 10));
mTextPaint.setColor(Color.parseColor("#000000"));
}


@Override
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
canvas.drawRect(rectF, mBgPaint);
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint);
}

@Override
public void onDrawCurrentMonthOrWeek(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
canvas.drawRect(rectF, mBgPaint);
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint);
}

@Override
public void onDrawLastOrNextMonth(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
canvas.drawRect(rectF, mBgPaint);
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint);
}

@Override
public void onDrawDisableDate(Canvas canvas, RectF rectF, LocalDate localDate) {
canvas.drawRect(rectF, mBgPaint);
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint);
}

private Paint getPaint() {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
paint.setTextAlign(Paint.Align.CENTER);
return paint;
}

private int getBaseLineY(RectF rectF) {
Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
float top = fontMetrics.top;
float bottom = fontMetrics.bottom;
int baseLineY = (int) (rectF.centerY() - top / 2 - bottom / 2);
return baseLineY;
}

}
81 changes: 42 additions & 39 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@
android:layout_height="match_parent"
android:orientation="vertical">

<!--<FrameLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="horizontal">-->

<!--<TextView-->
<!--android:id="@+id/tv_1"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:background="#000000" />-->

<!--<TextView-->
<!--android:id="@+id/tv_2"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="50dp"-->
<!--android:background="#111eee" />-->


<!--</FrameLayout>-->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand Down Expand Up @@ -168,31 +146,56 @@
android:text="周日历固定 hold" />

<Button
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="addView"
android:text="日历和子view之间添加view" />


<Button
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="custom_painter"
android:text="自定义页面(两种效果)" />
android:orientation="horizontal">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewpager"
android:text="嵌套ViewPager"
android:textAllCaps="false" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="viewpager"
android:text="嵌套ViewPager"
android:textAllCaps="false" />

<Button
android:layout_width="wrap_content"
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="general"
android:text="嵌套普通View"
android:textAllCaps="false" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="general"
android:text="嵌套普通View"
android:textAllCaps="false" />
android:orientation="horizontal">

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="custom_painter"
android:text="自定义页面(两种效果)" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="stretch"
android:text="日历拉伸"
android:textAllCaps="false" />


</LinearLayout>


<TextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_miui9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999"
android:tag="@string/factual_scroll_view" />


Expand Down
40 changes: 40 additions & 0 deletions app/src/main/res/layout/activity_stretch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<com.necer.calendar.Miui10Calendar
android:id="@+id/miui10Calendar"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="15dp"
android:text="测试月日历拉伸"
android:textColor="#ffffff"
android:textSize="18sp" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>


</com.necer.calendar.Miui10Calendar>

</LinearLayout>
12 changes: 5 additions & 7 deletions app/src/main/res/layout/activity_week_hold.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:layout_marginTop="30dp"
android:onClick="monthCalendar"
android:padding="15dp"
android:text="日历"
android:text="点击展开日历"
android:textColor="#ffffff" />


Expand All @@ -38,8 +38,6 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="@color/white" />


</RelativeLayout>


Expand All @@ -48,8 +46,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:calendarHeight="300dp"
app:defaultCalendar="month"
app:isWeekHold="true">
app:defaultCalendar="month">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
Expand All @@ -58,9 +55,10 @@

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:tag="@string/factual_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="#cccccc"
android:tag="@string/factual_scroll_view" />

</android.support.v4.widget.SwipeRefreshLayout>

Expand Down
Loading

0 comments on commit c269cc0

Please sign in to comment.