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 9fe3b8d commit e3588be
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
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.3.0"
versionName "4.3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

public class TestStretchActivity extends AppCompatActivity {


private Miui10Calendar miui10Calendar;

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

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


Expand All @@ -42,4 +45,5 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
innerPainter.setStretchStrMap(strMap);

}

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

<com.necer.view.WeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"/>

<com.necer.calendar.Miui10Calendar
android:id="@+id/miui10Calendar"
Expand Down
4 changes: 2 additions & 2 deletions ncalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "4.3.0"
versionName "4.3.1"
}
}

Expand All @@ -23,7 +23,7 @@ publish {
repoName = 'maven'//bintray仓库
groupId = 'com.necer.ncalendar'//jcenter上的路径
artifactId = 'ncalendar'//项目名称
publishVersion = '4.3.0'//版本号
publishVersion = '4.3.1'//版本号
desc = 'NCalendar'
website = 'https://github.com/yannecer/NCalendar'
}
7 changes: 5 additions & 2 deletions ncalendar/src/main/java/com/necer/calendar/IICalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
*/
public interface IICalendar extends ICalendar {

//回到周状态
//回到周状态 只能从月->周
void toWeek();

//回到月状态
//回到月状态 可以从周回到月或者从拉伸回到周
void toMonth();

//回到拉伸状态 只能从月->拉伸
void toStretch();

//设置周滑动到周位置固定
void setWeekHoldEnable(boolean isWeekHoldEnable);

Expand Down
36 changes: 21 additions & 15 deletions ncalendar/src/main/java/com/necer/calendar/NCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
Expand All @@ -13,7 +12,6 @@
import android.support.annotation.Nullable;
import android.support.v4.view.NestedScrollingParent;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -205,21 +203,21 @@ private void autoScroll() {
int childLayoutY = (int) childView.getY();

if ((calendarState == CalendarState.MONTH || calendarState == CalendarState.MONTH_STRETCH) && childLayoutY <= monthHeight && childLayoutY >= monthHeight * 4 / 5) {
autoToMonthState();
autoToMonthBySetY();
} else if ((calendarState == CalendarState.MONTH || calendarState == CalendarState.MONTH_STRETCH) && childLayoutY <= monthHeight * 4 / 5) {
autoToWeekState();
autoToWeekBySetY();
} else if ((calendarState == CalendarState.WEEK || calendarState == CalendarState.MONTH_STRETCH) && childLayoutY < weekHeight * 2) {
autoToWeekState();
autoToWeekBySetY();
} else if ((calendarState == CalendarState.WEEK || calendarState == CalendarState.MONTH_STRETCH) && childLayoutY >= weekHeight * 2 && childLayoutY <= monthHeight) {
autoToMonthState();
autoToMonthBySetY();
} else if (childLayoutY < monthHeight + (stretchMonthHeight - monthHeight) / 2 && childLayoutY >= monthHeight) {
autoToMonthFromStretch();
} else if (childLayoutY >= monthHeight + (stretchMonthHeight - monthHeight) / 2) {
autoToStretchFromMonth();
}
}

//自动从拉伸到月状态
//自动从拉伸到月状态 通过改变高度
private void autoToMonthFromStretch() {
float monthCalendarStart = monthCalendar.getLayoutParams().height;
float monthCalendarEnd = monthHeight;
Expand All @@ -233,7 +231,7 @@ private void autoToMonthFromStretch() {

}

//自动从月到拉伸状态
//自动从月到拉伸状态 通过改变高度
private void autoToStretchFromMonth() {
float monthCalendarStart = monthCalendar.getLayoutParams().height;
float monthCalendarEnd = stretchMonthHeight;
Expand All @@ -248,8 +246,8 @@ private void autoToStretchFromMonth() {
}


//自动滑动到周
private void autoToWeekState() {
//自动滑动到周 通过setY 月->周
private void autoToWeekBySetY() {
float monthCalendarStart = monthCalendar.getY();//起始位置
float monthCalendarEnd = getMonthCalendarAutoWeekEndY();

Expand All @@ -263,8 +261,8 @@ private void autoToWeekState() {

}

//自动滑动到月
private void autoToMonthState() {
//自动滑动到月 通过setY 周->月
private void autoToMonthBySetY() {
float monthCalendarStart = monthCalendar.getY();//起始位置
float monthCalendarEnd = 0;
monthValueAnimator.setFloatValues(monthCalendarStart, monthCalendarEnd);
Expand Down Expand Up @@ -515,14 +513,23 @@ public void toToday() {
@Override
public void toWeek() {
if (calendarState == CalendarState.MONTH) {
autoToWeekState();
autoToWeekBySetY();
}
}

@Override
public void toMonth() {
if (calendarState == CalendarState.WEEK) {
autoToMonthState();
autoToMonthBySetY();
} else if (calendarState == CalendarState.MONTH_STRETCH) {
autoToMonthFromStretch();
}
}

@Override
public void toStretch() {
if (calendarState == CalendarState.MONTH) {
autoToStretchFromMonth();
}
}

Expand Down Expand Up @@ -684,7 +691,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
if (animation == monthValueAnimator) {
float animatedValue = (float) animation.getAnimatedValue();
monthCalendar.setY(animatedValue);

} else if (animation == monthStretchValueAnimator) {
float animatedValue = (float) animation.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = monthCalendar.getLayoutParams();
Expand Down

0 comments on commit e3588be

Please sign in to comment.