Skip to content

Commit

Permalink
Support nested scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
wisnukurniawan committed Mar 6, 2019
1 parent 907eb2f commit 3309694
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ protected void onCreate(Bundle savedInstanceState) {
CalendarPickerView cal = findViewById(R.id.calendar_view);
cal.init(
DateTime.now(DateTimeZone.UTC).minusYears(1).toDate(),
DateTime.now(DateTimeZone.UTC).toDate()
DateTime.now(DateTimeZone.UTC).plusDays(4).toDate()
)
.inMode(CalendarPickerView.SelectionMode.RANGE)
.withSelectedDate(DateTime.now(DateTimeZone.UTC).minusDays(1).toDate());
.withSelectedDate(DateTime.now(DateTimeZone.UTC).minusDays(1).plusDays(4).toDate());
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<com.wisnu.datetimerangepickerandroid.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="360dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />

Expand Down
2 changes: 1 addition & 1 deletion datetimerangepickerandroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ android {
}

dependencies {

implementation 'com.android.support:appcompat-v7:28.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
Expand All @@ -40,7 +42,7 @@
* Android component to allow picking a date from a calendar view (a list of months). Must be initialized after inflation with {@link #init(Date, Date)} and can be customized with any of the {@link
* FluentInitializer} methods returned. The currently selected date can be retrieved with {@link #getSelectedDate()}.
*/
public class CalendarPickerView extends ListView {
public class CalendarPickerView extends ListView implements NestedScrollingChild {

public enum SelectionMode {
/**
Expand Down Expand Up @@ -106,6 +108,8 @@ public enum SelectionMode {

private boolean monthsReverseOrder;

private final NestedScrollingChildHelper scrollingChildHelper;

private final StringBuilder monthBuilder = new StringBuilder(50);
private Formatter monthFormatter;

Expand Down Expand Up @@ -161,6 +165,8 @@ public CalendarPickerView(Context context, AttributeSet attrs) {
weekdayNameFormat.setTimeZone(timeZone);
fullDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
fullDateFormat.setTimeZone(timeZone);
scrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);

if (isInEditMode()) {
Calendar nextYear = Calendar.getInstance(timeZone, locale);
Expand Down Expand Up @@ -1112,4 +1118,50 @@ public void onInvalidDateSelected(Date date) {
// Toast.makeText(getContext(), errMessage, Toast.LENGTH_SHORT).show();
}
}

@Override
public void setNestedScrollingEnabled(boolean enabled) {
scrollingChildHelper.setNestedScrollingEnabled(true);
}

@Override
public boolean isNestedScrollingEnabled() {
return scrollingChildHelper.isNestedScrollingEnabled();
}

@Override
public boolean startNestedScroll(int axes) {
return scrollingChildHelper.startNestedScroll(axes);
}

@Override
public void stopNestedScroll() {
scrollingChildHelper.stopNestedScroll();
}

@Override
public boolean hasNestedScrollingParent() {
return scrollingChildHelper.hasNestedScrollingParent();
}

@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
return scrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
}

@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
return scrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}

@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
return scrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
}

@Override
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
return scrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY);
}

}
21 changes: 0 additions & 21 deletions datetimerangepickerandroid/src/main/res/layout/example.xml

This file was deleted.

0 comments on commit 3309694

Please sign in to comment.