From a0aa84e04b2b027f3c62274418af54d9dc59190f Mon Sep 17 00:00:00 2001 From: Pranav Pandey Date: Sat, 22 May 2021 10:09:24 +0530 Subject: [PATCH] Constraint layout 2.0.4 Target SDK 30 and Build tools 30.0.3. Notifiy page change events for custom callback. --- .travis.yml | 14 ++++----- README.md | 2 +- build.gradle | 10 +++---- .../motion/widget/DynamicMotionLayout.java | 30 +++++++++++++++++-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6169504..0527419 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,17 @@ language: android -jdk: oraclejdk8 +jdk: oraclejdk11 before_install: - mkdir "$ANDROID_HOME/licenses" || true - - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" + - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" android: components: - tools - platform-tools - - build-tools-29.0.3 - - android-29 + - build-tools-30.0.3 + - android-30 - extra-android-support - extra-android-m2repository - extra-google-m2repository @@ -21,14 +21,14 @@ script: - ./gradlew build after_success: - - ./gradlew javadocRelease + - ./gradlew generateJavadoc deploy: - provider: pages:git + provider: pages token: $GITHUB_TOKEN edge: true keep_history: true local_dir: dynamic-motion/build/docs/javadoc/release on: - all_branches: true + branch: master tags: true diff --git a/README.md b/README.md index d0f12c1..f3f5c53 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Set page count for `ViewPager` to divide the `transition` between different page ```java // At runtime -dynamicMotionLayout.setPageCount(int, @Nullable ViewPager.OnPageChangeListener); +dynamicMotionLayout.setPageCount(int, @Nullable ViewPager2.OnPageChangeCallback); ``` ### Motion scene diff --git a/build.gradle b/build.gradle index f1a4bdf..c367655 100644 --- a/build.gradle +++ b/build.gradle @@ -16,12 +16,12 @@ buildscript { ext.versions = [ - 'compileSdk' : 29, + 'compileSdk' : 30, 'minSdk' : 18, - 'targetSdk' : 29, - 'buildTools' : '29.0.3', - 'appcompat' : '1.2.0-alpha03', - 'constraintlayout': '2.0.0-beta4', + 'targetSdk' : 30, + 'buildTools' : '30.0.3', + 'appcompat' : '1.2.0', + 'constraintlayout': '2.0.4', 'kotlin' : '1.5.0', 'viewpager2' : '1.0.0' ] diff --git a/dynamic-motion/src/main/java/com/pranavpandey/android/dynamic/motion/widget/DynamicMotionLayout.java b/dynamic-motion/src/main/java/com/pranavpandey/android/dynamic/motion/widget/DynamicMotionLayout.java index 982fadb..d33a030 100644 --- a/dynamic-motion/src/main/java/com/pranavpandey/android/dynamic/motion/widget/DynamicMotionLayout.java +++ b/dynamic-motion/src/main/java/com/pranavpandey/android/dynamic/motion/widget/DynamicMotionLayout.java @@ -16,6 +16,7 @@ package com.pranavpandey.android.dynamic.motion.widget; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; @@ -23,7 +24,6 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.motion.widget.MotionLayout; -import androidx.viewpager.widget.ViewPager; import androidx.viewpager2.widget.ViewPager2; import com.pranavpandey.android.dynamic.motion.R; @@ -98,10 +98,11 @@ public void initialize() { * Set the page count for the view pager. * * @param pageCount The page count to be set. - * @param onPageChangeListener The page change listener to receive page change events. + * @param onPageChangeCallback The callback to receive page change events. */ + @SuppressLint("NotifyDataSetChanged") public void setPageCount(int pageCount, - @Nullable ViewPager.OnPageChangeListener onPageChangeListener) { + @Nullable ViewPager2.OnPageChangeCallback onPageChangeCallback) { this.mPageCount = pageCount; if (mViewPager == null) { @@ -118,6 +119,29 @@ public void onPageScrolled(int position, super.onPageScrolled(position, positionOffset, positionOffsetPixels); setProgress((position + positionOffset) / (mPageCount - 1)); + + if (onPageChangeCallback != null) { + onPageChangeCallback.onPageScrolled(position, + positionOffset, positionOffsetPixels); + } + } + + @Override + public void onPageSelected(int position) { + super.onPageSelected(position); + + if (onPageChangeCallback != null) { + onPageChangeCallback.onPageSelected(position); + } + } + + @Override + public void onPageScrollStateChanged(@ViewPager2.ScrollState int state) { + super.onPageScrollStateChanged(state); + + if (onPageChangeCallback != null) { + onPageChangeCallback.onPageScrollStateChanged(state); + } } });