data) {
19 | super(data);
20 | }
21 |
22 | @Override
23 | public void onBindView(ViewHolder holder, String data, final int position) {
24 | ImageView itemView = (ImageView) holder.itemView;
25 | Glide.with(itemView.getContext())
26 | .load(data)
27 | .into(itemView);
28 | if (mClickListener != null) {
29 | holder.itemView.setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | mClickListener.onPageClick(v, position);
33 | }
34 | });
35 | }
36 |
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 | .idea/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # IntelliJ
37 | *.iml
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/gradle.xml
41 | .idea/assetWizardSettings.xml
42 | .idea/dictionaries
43 | .idea/libraries
44 | .idea/caches
45 |
46 | # Keystore files
47 | # Uncomment the following line if you do not want to check your keystore files in.
48 | #*.jks
49 |
50 | # External native build folder generated in Android Studio 2.2 and later
51 | .externalNativeBuild
52 |
53 | # Google Services (e.g. APIs or Firebase)
54 | google-services.json
55 |
56 | # Freeline
57 | freeline.py
58 | freeline/
59 | freeline_project_description.json
60 |
61 | # fastlane
62 | fastlane/report.xml
63 | fastlane/Preview.html
64 | fastlane/screenshots
65 | fastlane/test_output
66 | fastlane/readme.md
67 |
--------------------------------------------------------------------------------
/loopbanner/src/main/java/com/wenjian/loopbanner/indicator/IndicatorAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wenjian.loopbanner.indicator;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.view.View;
5 | import android.widget.LinearLayout;
6 |
7 | /**
8 | * Description: IndicatorAdapter
9 | * Date: 2018/12/6
10 | *
11 | * @author jian.wen@ubtrobot.com
12 | */
13 | public interface IndicatorAdapter {
14 |
15 | /**
16 | * 添加子indicator
17 | *
18 | * @param container 父布局
19 | * @param drawable 配置的Drawable
20 | * @param size 配置的指示器大小
21 | * @param margin 配置的指示器margin值
22 | */
23 | void addIndicator(LinearLayout container, Drawable drawable, int size, int margin);
24 |
25 | /**
26 | * 应用选中效果
27 | *
28 | * @param prev 上一个
29 | * @param current 当前
30 | * @param reverse 是否逆向滑动
31 | */
32 | void applySelectState(View prev, View current, boolean reverse);
33 |
34 | /**
35 | * 应用为选中效果
36 | *
37 | * @param indicator 指示器
38 | */
39 | void applyUnSelectState(View indicator);
40 |
41 |
42 | /**
43 | * 是否需要对某个位置进行特殊处理
44 | *
45 | * @param container 指示器容器
46 | * @param position 第一个或最后一个
47 | * @return 返回true代表处理好了
48 | */
49 | boolean handleSpecial(LinearLayout container, int position);
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/loopbanner/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | lintOptions {
26 | abortOnError false
27 | }
28 |
29 | }
30 |
31 | tasks.withType(Javadoc) {
32 | options {
33 | options.addStringOption('Xdoclint:none', '-quiet')
34 | options.addStringOption('encoding', 'UTF-8')
35 | options.addStringOption('charSet', 'UTF-8')
36 | }
37 | }
38 |
39 |
40 | dependencies {
41 | implementation fileTree(dir: 'libs', include: ['*.jar'])
42 | api "com.github.bumptech.glide:glide:4.8.0"
43 | implementation 'com.android.support:appcompat-v7:27.1.1'
44 | implementation 'com.android.support:recyclerview-v7:27.1.1'
45 | testImplementation 'junit:junit:4.12'
46 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
47 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
48 | }
49 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 27
9 | defaultConfig {
10 | applicationId "com.wenjian.loopbannerdemo"
11 | minSdkVersion 14
12 | targetSdkVersion 27
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | implementation 'com.android.support:appcompat-v7:27.1.1'
29 | implementation 'com.android.support:cardview-v7:27.1.1'
30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
31 | implementation 'com.android.support:recyclerview-v7:27.1.1'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | implementation "com.github.bumptech.glide:glide:3.7.0"
36 | implementation project(':loopbanner')
37 | // implementation 'com.github.wenjiangit:LoopBanner:1.0.3'
38 | }
39 |
--------------------------------------------------------------------------------
/loopbanner/src/main/java/com/wenjian/loopbanner/LoopScroller.java:
--------------------------------------------------------------------------------
1 | package com.wenjian.loopbanner;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.view.animation.Interpolator;
6 | import android.widget.Scroller;
7 |
8 | import java.lang.reflect.Field;
9 |
10 | /**
11 | * Description LoopScroller
12 | *
13 | * Date 2019/2/28
14 | *
15 | * @author wenjianes@163.com
16 | */
17 | public class LoopScroller extends Scroller {
18 |
19 | private static final Interpolator sInterpolator = new Interpolator() {
20 | @Override
21 | public float getInterpolation(float t) {
22 | t -= 1.0f;
23 | return t * t * t * t * t + 1.0f;
24 | }
25 | };
26 |
27 | private int mScrollerDuration;
28 |
29 | void setScrollerDuration(int mScrollerDuration) {
30 | this.mScrollerDuration = mScrollerDuration;
31 | }
32 |
33 | LoopScroller(Context context) {
34 | super(context, sInterpolator);
35 | }
36 |
37 | @Override
38 | public void startScroll(int startX, int startY, int dx, int dy) {
39 | this.startScroll(startX, startY, dx, dy, mScrollerDuration);
40 | }
41 |
42 | @Override
43 | public void startScroll(int startX, int startY, int dx, int dy, int duration) {
44 | super.startScroll(startX, startY, dx, dy, mScrollerDuration);
45 | }
46 |
47 | void linkViewPager(ViewPager viewPager) {
48 | try {
49 | Field mScroller = ViewPager.class.getDeclaredField("mScroller");
50 | mScroller.setAccessible(true);
51 | mScroller.set(viewPager, this);
52 | } catch (Exception e) {
53 | e.printStackTrace();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
21 |
22 |
23 |
29 |
30 |
31 |
32 |
33 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/loopbanner/src/main/java/com/wenjian/loopbanner/transformer/ScalePageTransformer.java:
--------------------------------------------------------------------------------
1 | package com.wenjian.loopbanner.transformer;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v4.view.ViewPager;
5 | import android.view.View;
6 |
7 | /**
8 | * Description: ScalePageTransformer
9 | * Date: 2018/12/10
10 | *
11 | * @author jian.wen@ubtrobot.com
12 | */
13 | public class ScalePageTransformer implements ViewPager.PageTransformer {
14 |
15 | private static final float DEFAULT_SCALE = 0.85f;
16 | private float mScale;
17 |
18 | public ScalePageTransformer(float mScale) {
19 | this.mScale = mScale;
20 | }
21 |
22 | public ScalePageTransformer() {
23 | this(DEFAULT_SCALE);
24 | }
25 |
26 | @Override
27 | public void transformPage(@NonNull View view, float position) {
28 | int width = view.getWidth();
29 | int height = view.getHeight();
30 | view.setPivotX(width / 2);
31 | view.setPivotY(height / 2);
32 | if (position < -1) {
33 | view.setScaleX(mScale);
34 | view.setScaleY(mScale);
35 | view.setPivotX(width);
36 | } else if (position <= 1) {
37 | if (position < 0) {
38 | float scaleFactor = (1 + position) * (1 - mScale) + mScale;
39 | view.setScaleX(scaleFactor);
40 | view.setScaleY(scaleFactor);
41 | view.setPivotX(width * (1 + (1 * -position)));
42 | } else {
43 | float scaleFactor = (1 - position) * (1 - mScale) + mScale;
44 | view.setScaleX(scaleFactor);
45 | view.setScaleY(scaleFactor);
46 | view.setPivotX(width * ((1 - position) * 1));
47 | }
48 | } else {
49 | view.setPivotX(0);
50 | view.setScaleX(mScale);
51 | view.setScaleY(mScale);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/loopbanner/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |