Skip to content

Commit

Permalink
Constraint layout 2.0.4
Browse files Browse the repository at this point in the history
Target SDK 30 and Build tools 30.0.3.
Notifiy page change events for custom callback.
  • Loading branch information
pranavpandey committed May 22, 2021
1 parent bc1ff11 commit a0aa84e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.pranavpandey.android.dynamic.motion.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;

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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
});

Expand Down

0 comments on commit a0aa84e

Please sign in to comment.