├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── yyydjk
│ │ └── sliderlayoutdemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── yyydjk
│ │ │ └── sliderlayoutdemo
│ │ │ ├── MainActivity.java
│ │ │ └── imageloader
│ │ │ ├── GlideImageLoader.java
│ │ │ └── PicassoImageLoader.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── yyydjk
│ └── sliderlayoutdemo
│ └── ExampleUnitTest.java
├── art
├── 1453087757.png
└── bannerLayoutDemo1.gif
├── bannerlayoutsimple.apk
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── yyydjk
│ │ └── library
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── yyydjk
│ │ │ └── library
│ │ │ └── BannerLayout.java
│ └── res
│ │ └── values
│ │ └── attr.xml
│ └── test
│ └── java
│ └── com
│ └── yyydjk
│ └── library
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.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 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://jitpack.io/#dongjunkun/BannerLayout)
2 |
3 | 一款简洁实用的android广告栏,参考了[AndroidImageSlider](https://github.com/daimajia/AndroidImageSlider)和[BGABanner-Android](https://github.com/bingoogolapple/BGABanner-Android)结合自己的理解而成
4 |
5 | ### 预览
6 |
7 |
8 | DownLoad APK
9 |
10 | 或者扫描二维码下载
11 |
12 |
13 |
14 | ## Gradle Dependency
15 | ```
16 | allprojects {
17 | repositories {
18 | ...
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile 'com.github.dongjunkun:BannerLayout:1.0.6'
25 | }
26 |
27 | ```
28 |
29 | ### 使用
30 | **xml**
31 | ```
32 |
48 | ```
49 |
50 | **代码中使用**
51 | ```
52 | //网络地址
53 | bannerLayout.setViewUrls(urls);
54 |
55 | //设置加载器
56 | bannerLayout.setImageLoader(new GlideImageLoader());
57 |
58 |
59 | //添加点击监听
60 | bannerLayout.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
61 | @Override
62 | public void onItemClick(int position) {
63 | Toast.makeText(MainActivity.this, String.valueOf(position), Toast.LENGTH_SHORT).show();
64 | }
65 | });
66 | ```
67 |
68 | ### 关于我
69 | 简书:[dongjunkun](http://www.jianshu.com/users/f07458c1a8f3/latest_articles)
70 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion '25.0.2'
6 |
7 | defaultConfig {
8 | applicationId "com.yyydjk.bannerlayout"
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_7
22 | targetCompatibility JavaVersion.VERSION_1_7
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(include: ['*.jar'], dir: 'libs')
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | compile 'com.github.bumptech.glide:glide:3.7.0'
31 | compile 'com.squareup.picasso:picasso:2.5.2'
32 | compile project(':library')
33 | }
34 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android1\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yyydjk/sliderlayoutdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.sliderlayoutdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyydjk/sliderlayoutdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.sliderlayoutdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.Toast;
6 |
7 | import com.yyydjk.library.BannerLayout;
8 | import com.yyydjk.sliderlayoutdemo.imageloader.GlideImageLoader;
9 | import com.yyydjk.sliderlayoutdemo.imageloader.PicassoImageLoader;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class MainActivity extends AppCompatActivity{
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 | BannerLayout bannerLayout = (BannerLayout) findViewById(R.id.banner);
22 | BannerLayout bannerLayout2 = (BannerLayout) findViewById(R.id.banner2);
23 |
24 | final List urls = new ArrayList<>();
25 | urls.add("http://img3.imgtn.bdimg.com/it/u=2674591031,2960331950&fm=23&gp=0.jpg");
26 | urls.add("http://img5.imgtn.bdimg.com/it/u=3639664762,1380171059&fm=23&gp=0.jpg");
27 | urls.add("http://img0.imgtn.bdimg.com/it/u=1095909580,3513610062&fm=23&gp=0.jpg");
28 | urls.add("http://img4.imgtn.bdimg.com/it/u=1030604573,1579640549&fm=23&gp=0.jpg");
29 | urls.add("http://img5.imgtn.bdimg.com/it/u=2583054979,2860372508&fm=23&gp=0.jpg");
30 | bannerLayout.setImageLoader(new GlideImageLoader());
31 | bannerLayout.setViewUrls(urls);
32 |
33 | //添加监听事件
34 | bannerLayout.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
35 | @Override
36 | public void onItemClick(int position) {
37 | Toast.makeText(MainActivity.this, String.valueOf(position), Toast.LENGTH_SHORT).show();
38 | }
39 | });
40 |
41 | //低于三张
42 | final List urls2 = new ArrayList<>();
43 | urls2.add("http://img3.imgtn.bdimg.com/it/u=2674591031,2960331950&fm=23&gp=0.jpg");
44 | urls2.add("http://img5.imgtn.bdimg.com/it/u=3639664762,1380171059&fm=23&gp=0.jpg");
45 | bannerLayout2.setImageLoader(new PicassoImageLoader());
46 | bannerLayout2.setViewUrls(urls2);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyydjk/sliderlayoutdemo/imageloader/GlideImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.sliderlayoutdemo.imageloader;
2 |
3 | import android.content.Context;
4 | import android.widget.ImageView;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.yyydjk.library.BannerLayout;
8 |
9 | /**
10 | * Created by Administrator on 2016/12/21 0021.
11 | */
12 |
13 | public class GlideImageLoader implements BannerLayout.ImageLoader {
14 | @Override
15 | public void displayImage(Context context, String path, ImageView imageView) {
16 | Glide.with(context).load(path).centerCrop().into(imageView);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyydjk/sliderlayoutdemo/imageloader/PicassoImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.sliderlayoutdemo.imageloader;
2 |
3 | import android.content.Context;
4 | import android.widget.ImageView;
5 |
6 | import com.squareup.picasso.Picasso;
7 | import com.yyydjk.library.BannerLayout;
8 |
9 | /**
10 | * Created by Administrator on 2016/12/21 0021.
11 | */
12 |
13 | public class PicassoImageLoader implements BannerLayout.ImageLoader {
14 | @Override
15 | public void displayImage(Context context, String path, ImageView imageView) {
16 | Picasso.with(context).load(path).into(imageView);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
33 |
34 |
39 |
40 |
43 |
44 |
60 |
61 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BannerLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/yyydjk/sliderlayoutdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.sliderlayoutdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/art/1453087757.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/art/1453087757.png
--------------------------------------------------------------------------------
/art/bannerLayoutDemo1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/art/bannerLayoutDemo1.gif
--------------------------------------------------------------------------------
/bannerlayoutsimple.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/bannerlayoutsimple.apk
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.1'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Mon Jan 25 17:47:43 CST 2016
16 | systemProp.http.proxyHost=127.0.0.1
17 | systemProp.http.proxyPort=8580
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dongjunkun/BannerLayout/5afe14aeaffdcc0e27af7cd5c57ac63cec3ea9cc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 02 09:31:21 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | group='com.github.dongjunkun'
6 |
7 |
8 | android {
9 | compileSdkVersion 25
10 | buildToolsVersion '25.0.2'
11 |
12 | defaultConfig {
13 | minSdkVersion 14
14 | targetSdkVersion 25
15 | versionCode 1
16 | versionName "1.0"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_7
26 | targetCompatibility JavaVersion.VERSION_1_7
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(include: ['*.jar'], dir: 'libs')
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.android.support:appcompat-v7:25.3.1'
34 | }
35 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/yyydjk/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/yyydjk/library/BannerLayout.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.library;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.graphics.drawable.GradientDrawable;
7 | import android.graphics.drawable.LayerDrawable;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.os.Parcel;
11 | import android.os.Parcelable;
12 | import android.support.annotation.NonNull;
13 | import android.support.v4.view.PagerAdapter;
14 | import android.support.v4.view.ViewPager;
15 | import android.util.AttributeSet;
16 | import android.view.Gravity;
17 | import android.view.MotionEvent;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.view.animation.Interpolator;
21 | import android.widget.ImageView;
22 | import android.widget.LinearLayout;
23 | import android.widget.RelativeLayout;
24 | import android.widget.Scroller;
25 |
26 | import java.io.Serializable;
27 | import java.lang.reflect.Field;
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 |
32 | /**
33 | * Created by dongjunkun on 2015/8/9.
34 | */
35 | public class BannerLayout extends RelativeLayout {
36 |
37 | private ViewPager pager;
38 | //指示器容器
39 | private LinearLayout indicatorContainer;
40 |
41 | private Drawable unSelectedDrawable;
42 | private Drawable selectedDrawable;
43 |
44 | private int WHAT_AUTO_PLAY = 1000;
45 |
46 | private boolean isAutoPlay = true;
47 |
48 | private int itemCount;
49 |
50 | private int selectedIndicatorColor = 0xffff0000;
51 | private int unSelectedIndicatorColor = 0x88888888;
52 |
53 | private Shape indicatorShape = Shape.oval;
54 | private int selectedIndicatorHeight = 6;
55 | private int selectedIndicatorWidth = 6;
56 | private int unSelectedIndicatorHeight = 6;
57 | private int unSelectedIndicatorWidth = 6;
58 |
59 | private Position indicatorPosition = Position.centerBottom;
60 | private int autoPlayDuration = 4000;
61 | private int scrollDuration = 900;
62 |
63 | private int indicatorSpace = 3;
64 | private int indicatorMargin = 10;
65 |
66 | private int currentPosition;
67 |
68 | private ImageLoader imageLoader;
69 |
70 | private enum Shape {
71 | rect, oval
72 | }
73 |
74 | private enum Position {
75 | centerBottom,
76 | rightBottom,
77 | leftBottom,
78 | centerTop,
79 | rightTop,
80 | leftTop
81 | }
82 |
83 | @Override
84 | protected void onAttachedToWindow() {
85 | super.onAttachedToWindow();
86 | startAutoPlay();
87 | }
88 |
89 | @Override
90 | protected void onDetachedFromWindow() {
91 | super.onDetachedFromWindow();
92 | stopAutoPlay();
93 | }
94 |
95 | private OnBannerItemClickListener onBannerItemClickListener;
96 |
97 | private Handler handler = new Handler(new Handler.Callback() {
98 | @Override
99 | public boolean handleMessage(Message msg) {
100 | if (msg.what == WHAT_AUTO_PLAY) {
101 | if (pager != null && isAutoPlay) {
102 | pager.setCurrentItem(pager.getCurrentItem() + 1, true);
103 | handler.sendEmptyMessageDelayed(WHAT_AUTO_PLAY, autoPlayDuration);
104 | }
105 | }
106 | return false;
107 | }
108 | });
109 |
110 | public BannerLayout(Context context) {
111 | this(context, null);
112 | }
113 |
114 | public BannerLayout(Context context, AttributeSet attrs) {
115 | this(context, attrs, 0);
116 | }
117 |
118 | public BannerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
119 | super(context, attrs, defStyleAttr);
120 | init(attrs, defStyleAttr);
121 | }
122 |
123 | private void init(AttributeSet attrs, int defStyle) {
124 |
125 | TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.BannerLayoutStyle, defStyle, 0);
126 | selectedIndicatorColor = array.getColor(R.styleable.BannerLayoutStyle_selectedIndicatorColor, selectedIndicatorColor);
127 | unSelectedIndicatorColor = array.getColor(R.styleable.BannerLayoutStyle_unSelectedIndicatorColor, unSelectedIndicatorColor);
128 |
129 | int shape = array.getInt(R.styleable.BannerLayoutStyle_indicatorShape, Shape.oval.ordinal());
130 | for (Shape shape1 : Shape.values()) {
131 | if (shape1.ordinal() == shape) {
132 | indicatorShape = shape1;
133 | break;
134 | }
135 | }
136 | selectedIndicatorHeight = (int) array.getDimension(R.styleable.BannerLayoutStyle_selectedIndicatorHeight, selectedIndicatorHeight);
137 | selectedIndicatorWidth = (int) array.getDimension(R.styleable.BannerLayoutStyle_selectedIndicatorWidth, selectedIndicatorWidth);
138 | unSelectedIndicatorHeight = (int) array.getDimension(R.styleable.BannerLayoutStyle_unSelectedIndicatorHeight, unSelectedIndicatorHeight);
139 | unSelectedIndicatorWidth = (int) array.getDimension(R.styleable.BannerLayoutStyle_unSelectedIndicatorWidth, unSelectedIndicatorWidth);
140 |
141 | int position = array.getInt(R.styleable.BannerLayoutStyle_indicatorPosition, Position.centerBottom.ordinal());
142 | for (Position position1 : Position.values()) {
143 | if (position == position1.ordinal()) {
144 | indicatorPosition = position1;
145 | }
146 | }
147 | indicatorSpace = (int) array.getDimension(R.styleable.BannerLayoutStyle_indicatorSpace, indicatorSpace);
148 | indicatorMargin = (int) array.getDimension(R.styleable.BannerLayoutStyle_indicatorMargin, indicatorMargin);
149 | autoPlayDuration = array.getInt(R.styleable.BannerLayoutStyle_autoPlayDuration, autoPlayDuration);
150 | scrollDuration = array.getInt(R.styleable.BannerLayoutStyle_scrollDuration, scrollDuration);
151 | isAutoPlay = array.getBoolean(R.styleable.BannerLayoutStyle_isAutoPlay, isAutoPlay);
152 | array.recycle();
153 |
154 | //绘制未选中状态图形
155 | LayerDrawable unSelectedLayerDrawable;
156 | LayerDrawable selectedLayerDrawable;
157 | GradientDrawable unSelectedGradientDrawable;
158 | unSelectedGradientDrawable = new GradientDrawable();
159 |
160 | //绘制选中状态图形
161 | GradientDrawable selectedGradientDrawable;
162 | selectedGradientDrawable = new GradientDrawable();
163 | switch (indicatorShape) {
164 | case rect:
165 | unSelectedGradientDrawable.setShape(GradientDrawable.RECTANGLE);
166 | selectedGradientDrawable.setShape(GradientDrawable.RECTANGLE);
167 | break;
168 | case oval:
169 | unSelectedGradientDrawable.setShape(GradientDrawable.OVAL);
170 | selectedGradientDrawable.setShape(GradientDrawable.OVAL);
171 | break;
172 | }
173 | unSelectedGradientDrawable.setColor(unSelectedIndicatorColor);
174 | unSelectedGradientDrawable.setSize(unSelectedIndicatorWidth, unSelectedIndicatorHeight);
175 | unSelectedLayerDrawable = new LayerDrawable(new Drawable[]{unSelectedGradientDrawable});
176 | unSelectedDrawable = unSelectedLayerDrawable;
177 |
178 | selectedGradientDrawable.setColor(selectedIndicatorColor);
179 | selectedGradientDrawable.setSize(selectedIndicatorWidth, selectedIndicatorHeight);
180 | selectedLayerDrawable = new LayerDrawable(new Drawable[]{selectedGradientDrawable});
181 | selectedDrawable = selectedLayerDrawable;
182 |
183 | }
184 |
185 |
186 | //添加网络图片路径
187 | public void setViewUrls(List urls) {
188 | List views = new ArrayList<>();
189 | itemCount = urls.size();
190 | //主要是解决当item为小于3个的时候滑动有问题,这里将其拼凑成3个以上
191 | if (itemCount < 1) {//当item个数0
192 | throw new IllegalStateException("item count not equal zero");
193 | } else if (itemCount < 2) { //当item个数为1
194 | views.add(getImageView(urls.get(0), 0));
195 | views.add(getImageView(urls.get(0), 0));
196 | views.add(getImageView(urls.get(0), 0));
197 | } else if (itemCount < 3) {//当item个数为2
198 | views.add(getImageView(urls.get(0), 0));
199 | views.add(getImageView(urls.get(1), 1));
200 | views.add(getImageView(urls.get(0), 0));
201 | views.add(getImageView(urls.get(1), 1));
202 | } else {
203 | for (int i = 0; i < urls.size(); i++) {
204 | views.add(getImageView(urls.get(i), i));
205 | }
206 | }
207 | setViews(views);
208 | }
209 |
210 | @NonNull
211 | private ImageView getImageView(String url, final int position) {
212 | ImageView imageView = new ImageView(getContext());
213 | imageView.setOnClickListener(new OnClickListener() {
214 | @Override
215 | public void onClick(View v) {
216 | if (onBannerItemClickListener != null) {
217 | onBannerItemClickListener.onItemClick(position);
218 | }
219 | }
220 | });
221 | imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
222 | imageLoader.displayImage(getContext(), url, imageView);
223 | return imageView;
224 | }
225 |
226 |
227 | public void setImageLoader(ImageLoader imageLoader) {
228 | this.imageLoader = imageLoader;
229 | }
230 |
231 | public ViewPager getPager() {
232 | if (pager != null) {
233 | return pager;
234 | }
235 | return null;
236 | }
237 |
238 | //添加任意View视图
239 | public void setViews(final List views) {
240 | //初始化pager
241 | pager = new ViewPager(getContext());
242 | //添加viewpager到SliderLayout
243 | addView(pager);
244 | setSliderTransformDuration(scrollDuration);
245 | //初始化indicatorContainer
246 | indicatorContainer = new LinearLayout(getContext());
247 | indicatorContainer.setGravity(Gravity.CENTER_VERTICAL);
248 | RelativeLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
249 |
250 | switch (indicatorPosition) {
251 | case centerBottom:
252 | params.addRule(RelativeLayout.CENTER_HORIZONTAL);
253 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
254 | break;
255 | case centerTop:
256 | params.addRule(RelativeLayout.CENTER_HORIZONTAL);
257 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
258 | break;
259 | case leftBottom:
260 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
261 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
262 | break;
263 | case leftTop:
264 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
265 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
266 | break;
267 | case rightBottom:
268 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
269 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
270 | break;
271 | case rightTop:
272 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
273 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
274 | break;
275 | }
276 | //设置margin
277 | params.setMargins(indicatorMargin, indicatorMargin, indicatorMargin, indicatorMargin);
278 | //添加指示器容器布局到SliderLayout
279 | addView(indicatorContainer, params);
280 |
281 | //初始化指示器,并添加到指示器容器布局
282 | for (int i = 0; i < itemCount; i++) {
283 | ImageView indicator = new ImageView(getContext());
284 | indicator.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
285 | indicator.setPadding(indicatorSpace, indicatorSpace, indicatorSpace, indicatorSpace);
286 | indicator.setImageDrawable(unSelectedDrawable);
287 | indicatorContainer.addView(indicator);
288 | }
289 | LoopPagerAdapter pagerAdapter = new LoopPagerAdapter(views);
290 | pager.setAdapter(pagerAdapter);
291 | //设置当前item到Integer.MAX_VALUE中间的一个值,看起来像无论是往前滑还是往后滑都是ok的
292 | //如果不设置,用户往左边滑动的时候已经划不动了
293 | int targetItemPosition = Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2 % itemCount;
294 | currentPosition = targetItemPosition;
295 | pager.setCurrentItem(targetItemPosition);
296 | switchIndicator(targetItemPosition % itemCount);
297 | pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
298 | @Override
299 | public void onPageSelected(int position) {
300 | currentPosition = position;
301 | switchIndicator(position % itemCount);
302 | }
303 | });
304 | if (isAutoPlay) {
305 | startAutoPlay();
306 | }
307 |
308 | }
309 |
310 | public void setSliderTransformDuration(int duration) {
311 | try {
312 | Field mScroller = ViewPager.class.getDeclaredField("mScroller");
313 | mScroller.setAccessible(true);
314 | FixedSpeedScroller scroller = new FixedSpeedScroller(pager.getContext(), null, duration);
315 | mScroller.set(pager, scroller);
316 | } catch (Exception e) {
317 | e.printStackTrace();
318 |
319 | }
320 | }
321 |
322 | /**
323 | * 开始自动轮播
324 | */
325 | private void startAutoPlay() {
326 | stopAutoPlay(); // 避免重复消息
327 | if (isAutoPlay) {
328 | handler.sendEmptyMessageDelayed(WHAT_AUTO_PLAY, autoPlayDuration);
329 | }
330 | }
331 |
332 | @Override
333 | protected void onWindowVisibilityChanged(int visibility) {
334 | super.onWindowVisibilityChanged(visibility);
335 |
336 | if (visibility == VISIBLE) {
337 | startAutoPlay();
338 | } else {
339 | stopAutoPlay();
340 | }
341 | }
342 |
343 |
344 | /**
345 | * 停止自动轮播
346 | */
347 | private void stopAutoPlay() {
348 | if (pager != null) {
349 | pager.setCurrentItem(pager.getCurrentItem(), false);
350 | }
351 | if (isAutoPlay) {
352 | handler.removeMessages(WHAT_AUTO_PLAY);
353 | if (pager != null) {
354 | pager.setCurrentItem(pager.getCurrentItem(), false);
355 | }
356 | }
357 | }
358 |
359 | /**
360 | * @param autoPlay 是否自动轮播
361 | */
362 | public void setAutoPlay(boolean autoPlay) {
363 | isAutoPlay = autoPlay;
364 | }
365 |
366 |
367 | @Override
368 | public boolean dispatchTouchEvent(MotionEvent ev) {
369 | switch (ev.getAction()) {
370 | case MotionEvent.ACTION_DOWN:
371 | stopAutoPlay();
372 | break;
373 | case MotionEvent.ACTION_CANCEL:
374 | case MotionEvent.ACTION_UP:
375 | startAutoPlay();
376 | break;
377 | }
378 | return super.dispatchTouchEvent(ev);
379 | }
380 |
381 | /**
382 | * 切换指示器状态
383 | *
384 | * @param currentPosition 当前位置
385 | */
386 | private void switchIndicator(int currentPosition) {
387 | for (int i = 0; i < indicatorContainer.getChildCount(); i++) {
388 | ((ImageView) indicatorContainer.getChildAt(i)).setImageDrawable(i == currentPosition ? selectedDrawable : unSelectedDrawable);
389 | }
390 | }
391 |
392 |
393 | public void setOnBannerItemClickListener(OnBannerItemClickListener onBannerItemClickListener) {
394 | this.onBannerItemClickListener = onBannerItemClickListener;
395 | }
396 |
397 | public interface OnBannerItemClickListener {
398 | void onItemClick(int position);
399 | }
400 |
401 | @Override
402 | public void onRestoreInstanceState(Parcelable state) {
403 | SavedState savedState = (SavedState) state;
404 | super.onRestoreInstanceState(savedState.getSuperState());
405 | currentPosition = savedState.currentPosition;
406 | requestLayout();
407 | }
408 |
409 | @Override
410 | public Parcelable onSaveInstanceState() {
411 | Parcelable superState = super.onSaveInstanceState();
412 | SavedState savedState = new SavedState(superState);
413 | savedState.currentPosition = currentPosition;
414 | return savedState;
415 | }
416 |
417 | private static class SavedState extends BaseSavedState {
418 | int currentPosition;
419 |
420 | SavedState(Parcelable superState) {
421 | super(superState);
422 | }
423 |
424 | private SavedState(Parcel in) {
425 | super(in);
426 | currentPosition = in.readInt();
427 | }
428 |
429 | @Override
430 | public void writeToParcel(Parcel dest, int flags) {
431 | super.writeToParcel(dest, flags);
432 | dest.writeInt(currentPosition);
433 | }
434 |
435 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
436 | @Override
437 | public SavedState createFromParcel(Parcel in) {
438 | return new SavedState(in);
439 | }
440 |
441 | @Override
442 | public SavedState[] newArray(int size) {
443 | return new SavedState[size];
444 | }
445 | };
446 | }
447 |
448 |
449 | private class LoopPagerAdapter extends PagerAdapter {
450 | private List views;
451 |
452 | LoopPagerAdapter(List views) {
453 | this.views = views;
454 | }
455 |
456 | @Override
457 | public int getCount() {
458 | //Integer.MAX_VALUE = 2147483647
459 | return Integer.MAX_VALUE;
460 | }
461 |
462 | @Override
463 | public boolean isViewFromObject(View view, Object object) {
464 | return view == object;
465 | }
466 |
467 | @Override
468 | public Object instantiateItem(ViewGroup container, int position) {
469 | if (views.size() > 0) {
470 | //position % view.size()是指虚拟的position会在[0,view.size())之间循环
471 | View view = views.get(position % views.size());
472 | if (container.equals(view.getParent())) {
473 | container.removeView(view);
474 | }
475 | container.addView(view);
476 | return view;
477 | }
478 | return null;
479 | }
480 |
481 | @Override
482 | public void destroyItem(ViewGroup container, int position, Object object) {
483 | }
484 | }
485 |
486 | public class FixedSpeedScroller extends Scroller {
487 |
488 | private int mDuration = 1000;
489 |
490 | public FixedSpeedScroller(Context context) {
491 | super(context);
492 | }
493 |
494 | public FixedSpeedScroller(Context context, Interpolator interpolator) {
495 | super(context, interpolator);
496 | }
497 |
498 | public FixedSpeedScroller(Context context, Interpolator interpolator, int duration) {
499 | this(context, interpolator);
500 | mDuration = duration;
501 | }
502 |
503 | @Override
504 | public void startScroll(int startX, int startY, int dx, int dy, int duration) {
505 | // Ignore received duration, use fixed one instead
506 | super.startScroll(startX, startY, dx, dy, mDuration);
507 | }
508 |
509 | @Override
510 | public void startScroll(int startX, int startY, int dx, int dy) {
511 | // Ignore received duration, use fixed one instead
512 | super.startScroll(startX, startY, dx, dy, mDuration);
513 | }
514 | }
515 |
516 | public interface ImageLoader extends Serializable {
517 | void displayImage(Context context, String path, ImageView imageView);
518 | }
519 | }
520 |
521 |
522 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attr.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 |
--------------------------------------------------------------------------------
/library/src/test/java/com/yyydjk/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yyydjk.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------