├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── loopeer │ │ └── android │ │ └── librarys │ │ └── cyclepager │ │ └── cyclepager │ │ └── MainActivity.java │ └── res │ ├── drawable │ ├── drawable_selected.xml │ └── drawable_unselected.xml │ ├── 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 ├── build.gradle ├── cycylepager ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── loopeer │ │ └── android │ │ └── librarys │ │ └── autolooppager │ │ ├── AutoLoopLayout.java │ │ ├── ILoopAdapter.java │ │ ├── ImageAdapter.java │ │ ├── LoopPageChangeListener.java │ │ └── PageIndicator.java │ └── res │ ├── drawable │ ├── cycle_pager_shape_selected.xml │ └── cycle_pager_shape_unselected.xml │ ├── layout │ ├── view_auto_loop_layout.xml │ └── view_pager_item.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ └── strings.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot └── screenshot.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Specific files to exclude 2 | dist 3 | com_crashlytics_export_strings.xml 4 | keys.xml 5 | #*.keystore 6 | 7 | ### Android 8 | ########### 9 | # built application files 10 | *.apk 11 | *.ap_ 12 | 13 | # files for the dex VM 14 | *.dex 15 | 16 | # Java class files 17 | *.class 18 | 19 | # generated files 20 | bin/ 21 | gen/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | gradle.properties 26 | keystore.properties 27 | 28 | ### Mac 29 | .DS_store 30 | 31 | ### Linux 32 | ######### 33 | !.gitignore 34 | *~ 35 | 36 | ### Windows 37 | ############ 38 | # Windows image file caches 39 | Thumbs.db 40 | ehthumbs.db 41 | 42 | # Folder config file 43 | Desktop.ini 44 | 45 | # Recycle Bin used on file shares 46 | $RECYCLE.BIN/ 47 | 48 | ### IntelliJ 49 | *.iml 50 | *.ipr 51 | *.iws 52 | .idea/ 53 | 54 | ### Gradle 55 | .gradle/ 56 | build/ 57 | out/ 58 | 59 | #Maven 60 | target 61 | release.properties 62 | pom.xml.* 63 | 64 | ### AppEngine 65 | google_generated/ 66 | datanucleus.log 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoLoopPager 2 | 3 | Screeshot 4 | ==== 5 | ![](/screenshot/screenshot.gif) 6 | 7 | Usage 8 | ==== 9 | 10 | ```xml 11 | 16 | ``` 17 | And java 18 | ```java 19 | mAutoLoopLayout = (AutoLoopLayout) findViewById(R.id.pager_main); 20 | mAutoLoopLayout.setILoopAdapter(new ILoopAdapter() { 21 | @Override 22 | public View createView(ViewGroup viewGroup, LayoutInflater inflater, Context context) { 23 | FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.view_pager_item, viewGroup, false); 24 | return layout; 25 | } 26 | 27 | @Override 28 | public void bindItem(View view, int position, Integer s) { 29 | view.setBackgroundColor(ContextCompat.getColor(view.getContext(), s)); 30 | ((TextView) view.findViewById(R.id.text_pager_item_title)).setText(String.valueOf(position + 1)); 31 | view.setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | mAutoLoopLayout.updateData(Arrays.asList(COLOR)); 35 | } 36 | }); 37 | } 38 | }); 39 | mAutoLoopLayout.updateData(Arrays.asList(COLOR)); 40 | ``` 41 | Also can set some values 42 | 43 | ```xml 44 | 45 | 56 | 57 | ``` 58 | 59 | And you can 60 | * **startLoop()** 61 | * **stopLoop()** 62 | * **setPageIndicator()** 63 | * **setLoopPageChangeListener()** 64 | 65 | 66 | License 67 | ==== 68 |
69 | Copyright 2015 Loopeer
70 | 
71 | Licensed under the Apache License, Version 2.0 (the "License");
72 | you may not use this file except in compliance with the License.
73 | You may obtain a copy of the License at
74 | 
75 |     http://www.apache.org/licenses/LICENSE-2.0
76 | 
77 | Unless required by applicable law or agreed to in writing, software
78 | distributed under the License is distributed on an "AS IS" BASIS,
79 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80 | See the License for the specific language governing permissions and
81 | limitations under the License.
82 | 
83 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion configs.compileSdkVersion 5 | buildToolsVersion configs.buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId "com.loopeer.android.librarys.cyclepager.cyclepager" 9 | minSdkVersion configs.minSdkVersion 10 | targetSdkVersion configs.targetSdkVersion 11 | versionCode configs.versionCode 12 | versionName configs.versionName 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile libs.appcompatV7 25 | compile project(':cycylepager') 26 | 27 | } 28 | -------------------------------------------------------------------------------- /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 /Users/todou/Library/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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/loopeer/android/librarys/cyclepager/cyclepager/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.cyclepager.cyclepager; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v4.content.ContextCompat; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | import android.widget.TextView; 12 | 13 | import com.loopeer.android.librarys.autolooppager.AutoLoopLayout; 14 | import com.loopeer.android.librarys.autolooppager.ILoopAdapter; 15 | 16 | import java.util.Arrays; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | private AutoLoopLayout mAutoLoopLayout; 21 | 22 | private final Integer[] COLOR = new Integer[]{ 23 | Integer.valueOf(android.R.color.holo_blue_light), 24 | Integer.valueOf(android.R.color.holo_red_light), 25 | Integer.valueOf(android.R.color.holo_green_light), 26 | }; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | 33 | mAutoLoopLayout = (AutoLoopLayout) findViewById(R.id.pager_main); 34 | mAutoLoopLayout.setILoopAdapter(new ILoopAdapter() { 35 | @Override 36 | public View createView(ViewGroup viewGroup, LayoutInflater inflater, Context context) { 37 | FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.view_pager_item, viewGroup, false); 38 | return layout; 39 | } 40 | 41 | @Override 42 | public void bindItem(View view, int position, Integer s) { 43 | view.setBackgroundColor(ContextCompat.getColor(view.getContext(), s)); 44 | ((TextView) view.findViewById(R.id.text_pager_item_title)).setText(String.valueOf(position + 1)); 45 | view.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | mAutoLoopLayout.updateData(Arrays.asList(COLOR)); 49 | } 50 | }); 51 | } 52 | }); 53 | mAutoLoopLayout.updateData(Arrays.asList(COLOR)); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/drawable_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/drawable_unselected.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /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 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CyclePager 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /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.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | 25 | ext { 26 | configs = [compileSdkVersion : 25, 27 | buildToolsVersion : '25.0.2', 28 | minSdkVersion : 16, 29 | targetSdkVersion : 25, 30 | versionCode : 1, 31 | versionName : '1.0.0'] 32 | 33 | supportLibraryVersion = '25.3.1' 34 | 35 | libs = [ 36 | appcompatV7 : "com.android.support:appcompat-v7:$supportLibraryVersion" 37 | ] 38 | } -------------------------------------------------------------------------------- /cycylepager/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /cycylepager/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion configs.compileSdkVersion 5 | buildToolsVersion configs.buildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion configs.minSdkVersion 9 | targetSdkVersion configs.targetSdkVersion 10 | versionCode configs.versionCode 11 | versionName configs.versionName 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile libs.appcompatV7 24 | } 25 | -------------------------------------------------------------------------------- /cycylepager/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 /Users/todou/Library/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 | -------------------------------------------------------------------------------- /cycylepager/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cycylepager/src/main/java/com/loopeer/android/librarys/autolooppager/AutoLoopLayout.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.autolooppager; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.support.v4.view.ViewPager; 8 | import android.util.AttributeSet; 9 | import android.view.Gravity; 10 | import android.view.KeyEvent; 11 | import android.view.LayoutInflater; 12 | import android.view.MotionEvent; 13 | import android.view.ViewGroup; 14 | import android.widget.FrameLayout; 15 | 16 | import java.util.List; 17 | import java.util.Timer; 18 | import java.util.TimerTask; 19 | 20 | public class AutoLoopLayout extends FrameLayout implements ViewPager.OnPageChangeListener { 21 | protected final static int TMP_AMOUNT = 1200; 22 | private final static int DEFAULT_PERIOD = 5000; 23 | private final static int DEFAULT_START_DELAY = 2000; 24 | 25 | private ViewPager mViewPager; 26 | private PageIndicator mPageIndicator; 27 | private LoopPageChangeListener mLoopPageChangeListener; 28 | private ImageAdapter mImageAdapter; 29 | private Timer mTimer; 30 | private TimerTask mTask; 31 | private boolean mCanAutoLoop; 32 | private boolean mShowIndicator; 33 | private int mLoopPeriod; 34 | 35 | public AutoLoopLayout(Context context) { 36 | this(context, null); 37 | } 38 | 39 | public AutoLoopLayout(Context context, AttributeSet attrs) { 40 | this(context, attrs, 0); 41 | } 42 | 43 | public AutoLoopLayout(Context context, AttributeSet attrs, int defStyleAttr) { 44 | super(context, attrs, defStyleAttr); 45 | 46 | init(context, attrs, defStyleAttr); 47 | } 48 | 49 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 50 | if (attrs == null) return; 51 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoLoopLayout, defStyleAttr, 0); 52 | if (a == null) return; 53 | 54 | mCanAutoLoop = a.getBoolean(R.styleable.AutoLoopLayout_autoLoop, true); 55 | mShowIndicator = a.getBoolean(R.styleable.AutoLoopLayout_showIndicator, true); 56 | mLoopPeriod = a.getInteger(R.styleable.AutoLoopLayout_loopPeriod, DEFAULT_PERIOD); 57 | int indicatorMargin = a.getDimensionPixelSize(R.styleable.AutoLoopLayout_indicatorMargin, 58 | getResources().getDimensionPixelSize(R.dimen.cyclepager_inline_margin)); 59 | Drawable selectDrawable = a.getDrawable(R.styleable.AutoLoopLayout_selectDrawable); 60 | Drawable unSelectDrawable = a.getDrawable(R.styleable.AutoLoopLayout_unSelectDrawable); 61 | a.recycle(); 62 | 63 | LayoutInflater.from(getContext()).inflate(R.layout.view_auto_loop_layout, this, true); 64 | mImageAdapter = new ImageAdapter(); 65 | if (mShowIndicator) createDefaultIndicator(unSelectDrawable, selectDrawable, indicatorMargin); 66 | } 67 | 68 | private void createDefaultIndicator(Drawable unSelectDrawable, Drawable selectDrawable, int indicatorMargin) { 69 | mPageIndicator = new PageIndicator(getContext()); 70 | mPageIndicator.setIndicatorMargin(indicatorMargin); 71 | mPageIndicator.updateDrawable(unSelectDrawable, selectDrawable); 72 | FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( 73 | ViewGroup.LayoutParams.WRAP_CONTENT, 74 | ViewGroup.LayoutParams.WRAP_CONTENT); 75 | layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; 76 | int margin = getResources().getDimensionPixelSize(R.dimen.cyclepager_list_horizontal_margin); 77 | layoutParams.rightMargin = margin; 78 | layoutParams.bottomMargin = margin; 79 | addView(mPageIndicator, layoutParams); 80 | } 81 | 82 | @Override 83 | protected void onFinishInflate() { 84 | super.onFinishInflate(); 85 | 86 | mViewPager = (ViewPager) this.findViewById(R.id.pager_auto_loop_layout); 87 | mViewPager.setAdapter(mImageAdapter); 88 | setUpPageListener(); 89 | } 90 | 91 | private void setUpPageListener() { 92 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { 93 | mViewPager.setOnPageChangeListener(this); 94 | } else { 95 | mViewPager.addOnPageChangeListener(this); 96 | } 97 | } 98 | 99 | @Override 100 | protected void onDetachedFromWindow() { 101 | super.onDetachedFromWindow(); 102 | 103 | stopTimer(); 104 | } 105 | 106 | @Override 107 | public boolean dispatchTouchEvent(MotionEvent ev) { 108 | int action = ev.getAction(); 109 | switch (action) { 110 | case MotionEvent.ACTION_DOWN: 111 | stopTimer(); 112 | break; 113 | case MotionEvent.ACTION_UP: 114 | startTimer(); 115 | break; 116 | case MotionEvent.ACTION_CANCEL: 117 | startTimer(); 118 | break; 119 | } 120 | 121 | return super.dispatchTouchEvent(ev); 122 | } 123 | 124 | private void startTimer() { 125 | if (mTimer == null) { 126 | mTimer = new Timer(); 127 | } 128 | if (mTask == null) { 129 | mTask = new TimerTask() { 130 | public void run() { 131 | mViewPager.post(new Runnable() { 132 | @Override 133 | public void run() { 134 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1); 135 | } 136 | }); 137 | } 138 | }; 139 | mTimer.schedule(mTask, DEFAULT_START_DELAY, mLoopPeriod); 140 | } 141 | } 142 | 143 | private void stopTimer() { 144 | if (mTimer != null) { 145 | mTimer.cancel(); 146 | mTimer = null; 147 | } 148 | if (mTask != null) { 149 | mTask.cancel(); 150 | mTask = null; 151 | } 152 | } 153 | 154 | private void doNormalShow() { 155 | mViewPager.setCurrentItem(TMP_AMOUNT); 156 | if (mCanAutoLoop) startLoop(); 157 | } 158 | 159 | private void doOneSimpleImageShow() { 160 | mViewPager.setCurrentItem(0); 161 | stopLoop(); 162 | } 163 | 164 | private int getAdapterRealCount() { 165 | return mImageAdapter.getRealCount(); 166 | } 167 | 168 | @Override 169 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 170 | doOnPageScrolled(getRealPosition(position), positionOffset, positionOffsetPixels); 171 | } 172 | 173 | @Override 174 | public void onPageSelected(int position) { 175 | doOnPageSelected(getRealPosition(position)); 176 | } 177 | 178 | @Override 179 | public void onPageScrollStateChanged(int state) { 180 | doOnPageScrollStateChanged(state); 181 | } 182 | 183 | private void doOnPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 184 | if (mLoopPageChangeListener != null) { 185 | mLoopPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); 186 | } 187 | } 188 | 189 | private void doOnPageSelected(int position) { 190 | if (mLoopPageChangeListener != null) { 191 | mLoopPageChangeListener.onPageSelected(position); 192 | } 193 | updateIndicatorPosition(position); 194 | } 195 | 196 | private void updateIndicatorPosition(int position) { 197 | if (mPageIndicator == null) return; 198 | mPageIndicator.updatePosition(position); 199 | } 200 | 201 | private void doOnPageScrollStateChanged(int state) { 202 | if (mLoopPageChangeListener != null) { 203 | mLoopPageChangeListener.onPageScrollStateChanged(state); 204 | } 205 | } 206 | 207 | private int getRealPosition(int position) { 208 | return position == 0 ? 0 : position % getAdapterRealCount(); 209 | } 210 | 211 | public void setLoopPageChangeListener(LoopPageChangeListener listener) { 212 | mLoopPageChangeListener = listener; 213 | } 214 | 215 | public void setPageIndicator(PageIndicator pageIndicator) { 216 | mShowIndicator = true; 217 | if (mPageIndicator != null) { 218 | ((ViewGroup)mPageIndicator.getParent()).removeView(mPageIndicator); 219 | mPageIndicator = null; 220 | } 221 | mPageIndicator = pageIndicator; 222 | updateImageIndicator(); 223 | } 224 | 225 | private void updateImageIndicator() { 226 | if (mPageIndicator == null) return; 227 | mPageIndicator.setVisibility(mImageAdapter.getRealCount() == 1 ? GONE : VISIBLE); 228 | mPageIndicator.updateCount(mImageAdapter.getRealCount()); 229 | updateIndicatorPosition(getRealPosition(mViewPager.getCurrentItem())); 230 | } 231 | 232 | public void setILoopAdapter(ILoopAdapter loopImager) { 233 | mImageAdapter.setILoopAdapter(loopImager); 234 | } 235 | 236 | public void startLoop() { 237 | startTimer(); 238 | } 239 | 240 | @SuppressWarnings("unused") 241 | public void stopLoop() { 242 | stopTimer(); 243 | } 244 | 245 | public void updateData(List data) { 246 | boolean isAddDataFromEmptyState = mImageAdapter.getCount() == 0; 247 | mImageAdapter.updateData(data); 248 | if (isAddDataFromEmptyState) { 249 | mViewPager.setCurrentItem(mImageAdapter.getRealCount() == 1 ? 0 : TMP_AMOUNT); 250 | if (mImageAdapter.getRealCount() == 1) { 251 | doOneSimpleImageShow(); 252 | } else { 253 | doNormalShow(); 254 | } 255 | } 256 | updateImageIndicator(); 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /cycylepager/src/main/java/com/loopeer/android/librarys/autolooppager/ILoopAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.autolooppager; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | public interface ILoopAdapter { 9 | 10 | View createView(ViewGroup viewGroup, LayoutInflater inflater, Context context); 11 | 12 | void bindItem(View view, int position, T t); 13 | } 14 | -------------------------------------------------------------------------------- /cycylepager/src/main/java/com/loopeer/android/librarys/autolooppager/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.autolooppager; 2 | 3 | import android.support.v4.view.PagerAdapter; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class ImageAdapter extends PagerAdapter{ 12 | 13 | private ILoopAdapter mILoopAdapter; 14 | private List mData; 15 | private List mHolderViews = new ArrayList<>(); 16 | 17 | public ImageAdapter() { 18 | mData = new ArrayList<>(); 19 | } 20 | 21 | public void updateData(List data) { 22 | setData(data); 23 | notifyDataSetChanged(); 24 | } 25 | 26 | private void setData(List data) { 27 | mData.clear(); 28 | if (data != null) { 29 | mData.addAll(data); 30 | } 31 | } 32 | 33 | @Override 34 | public Object instantiateItem(ViewGroup collection, int position) { 35 | position = position % getRealCount(); 36 | LayoutInflater inflater = LayoutInflater.from(collection.getContext()); 37 | View view = getView(collection, inflater, position); 38 | mILoopAdapter.bindItem(view, position, mData.get(position)); 39 | collection.addView(view); 40 | return view; 41 | } 42 | 43 | private View getView(ViewGroup collection, LayoutInflater inflater, int position) { 44 | View view; 45 | if (mHolderViews.size() == 0) { 46 | view = mILoopAdapter.createView(collection, inflater, collection.getContext()); 47 | view.setTag("position" + position); 48 | } else { 49 | view = mHolderViews.get(0); 50 | mHolderViews.remove(0); 51 | } 52 | return view; 53 | } 54 | 55 | 56 | public void setILoopAdapter(ILoopAdapter loopAdapter) { 57 | mILoopAdapter = loopAdapter; 58 | } 59 | 60 | @Override 61 | public void destroyItem(ViewGroup collection, int position, Object view) { 62 | View v = (View) view; 63 | mHolderViews.add(v); 64 | collection.removeView(v); 65 | } 66 | 67 | @Override 68 | public int getCount() { 69 | return mData == null ? 0 : mData.size() == 1 ? 1 : mData.size() * AutoLoopLayout.TMP_AMOUNT; 70 | } 71 | 72 | @Override 73 | public boolean isViewFromObject(View view, Object object) { 74 | return view == object; 75 | } 76 | 77 | public int getRealCount() { 78 | return mData.size(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /cycylepager/src/main/java/com/loopeer/android/librarys/autolooppager/LoopPageChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.autolooppager; 2 | 3 | public interface LoopPageChangeListener { 4 | 5 | void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); 6 | 7 | void onPageSelected(int position); 8 | 9 | void onPageScrollStateChanged(int state); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /cycylepager/src/main/java/com/loopeer/android/librarys/autolooppager/PageIndicator.java: -------------------------------------------------------------------------------- 1 | package com.loopeer.android.librarys.autolooppager; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.support.v4.content.ContextCompat; 6 | import android.util.AttributeSet; 7 | import android.view.Gravity; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.LinearLayout; 11 | 12 | public class PageIndicator extends LinearLayout { 13 | 14 | private int mCount; 15 | private Drawable mUnSelectDrawable; 16 | private Drawable mSelectDrawable; 17 | private int mPreSelectPosition; 18 | private int mItemMargin; 19 | 20 | public PageIndicator(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public PageIndicator(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public PageIndicator(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | 31 | init(context, attrs, defStyleAttr); 32 | } 33 | 34 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 35 | setOrientation(HORIZONTAL); 36 | setGravity(Gravity.BOTTOM | Gravity.RIGHT); 37 | 38 | mUnSelectDrawable = mUnSelectDrawable == null ? createUnSelectDefaultDrawable() : null; 39 | mSelectDrawable = mSelectDrawable == null ? createSelectDefaultDrawable() : null; 40 | } 41 | 42 | private Drawable createUnSelectDefaultDrawable() { 43 | return createDefaultDrawable(false); 44 | } 45 | 46 | private Drawable createSelectDefaultDrawable() { 47 | return createDefaultDrawable(true); 48 | } 49 | 50 | private Drawable createDefaultDrawable(boolean isSelected) { 51 | return ContextCompat.getDrawable(getContext(), isSelected 52 | ? R.drawable.cycle_pager_shape_selected 53 | : R.drawable.cycle_pager_shape_unselected); 54 | } 55 | 56 | public void updateDrawable(Drawable unSelectDrawable, Drawable selectDrawable) { 57 | if (unSelectDrawable != null) mUnSelectDrawable = unSelectDrawable; 58 | if (selectDrawable != null) mSelectDrawable = selectDrawable; 59 | } 60 | 61 | public void updateCount(int realCount) { 62 | mCount = realCount; 63 | resetView(); 64 | } 65 | 66 | private void resetView() { 67 | removeAllViews(); 68 | for (int i = 0; i < mCount; i++) { 69 | ImageView imageView = new ImageView(getContext()); 70 | imageView.setImageDrawable(mUnSelectDrawable); 71 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( 72 | ViewGroup.LayoutParams.WRAP_CONTENT, 73 | ViewGroup.LayoutParams.WRAP_CONTENT); 74 | layoutParams.rightMargin = mItemMargin; 75 | if (i == mCount - 1) layoutParams.rightMargin = 0; 76 | addView(imageView, layoutParams); 77 | } 78 | updatePosition(mPreSelectPosition); 79 | } 80 | 81 | protected void updatePosition(int realPosition) { 82 | if (getChildAt(mPreSelectPosition) == null) return; 83 | ImageView imageView = (ImageView) getChildAt(mPreSelectPosition); 84 | imageView.setImageDrawable(mUnSelectDrawable); 85 | 86 | ImageView imageViewSelect = (ImageView) getChildAt(realPosition); 87 | imageViewSelect.setImageDrawable(mSelectDrawable); 88 | mPreSelectPosition = realPosition; 89 | } 90 | 91 | public void setIndicatorMargin(int indicatorMargin) { 92 | mItemMargin = indicatorMargin; 93 | resetView(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/drawable/cycle_pager_shape_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/drawable/cycle_pager_shape_unselected.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/layout/view_auto_loop_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/layout/view_pager_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | 5 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12dp 5 | 12dp 6 | 4dp 7 | 8 | -------------------------------------------------------------------------------- /cycylepager/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | cycylepager 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 09 12:00:50 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 | -------------------------------------------------------------------------------- /screenshot/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loopeer/AutoLoopPager/ea1fb95b0715b68ebc774dfa27b22d50434183d0/screenshot/screenshot.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':cycylepager' 2 | --------------------------------------------------------------------------------