├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jack │ │ └── loopviewpager │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jack │ │ │ └── loopviewpager │ │ │ ├── MainActivity.java │ │ │ ├── ViewPageFragment.java │ │ │ ├── ViewPagerAdapter.java │ │ │ └── transformer │ │ │ ├── ABaseTransformer.java │ │ │ └── AccordionTransformer.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── layout_view.xml │ │ └── view_pager1.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_banner1.jpg │ │ ├── ic_banner2.jpg │ │ ├── ic_banner3.jpg │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── mobile_navigation.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jack │ └── loopviewpager │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image ├── fragment.gif ├── image.gif └── view.gif ├── loopviewpagers ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jack │ │ └── loopviewpagers │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jack │ │ │ └── loopviewpagers │ │ │ ├── IndicatiorCanvasView.java │ │ │ ├── IndicatorView.java │ │ │ ├── LoopViewPager.java │ │ │ ├── adapter │ │ │ ├── LoopFragmentPagerAdapter.java │ │ │ └── LoopViewPagerAdapter.java │ │ │ ├── interfaces │ │ │ ├── CreateView.java │ │ │ ├── IndicatorAnimator.java │ │ │ ├── OnPageClickListener.java │ │ │ └── UpdateImage.java │ │ │ └── util │ │ │ ├── DensityUtils.java │ │ │ └── LoopViewPagerScroller.java │ └── res │ │ ├── drawable │ │ ├── ic_origin.png │ │ └── ic_un_origin.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_origin.png │ │ └── ic_un_origin.png │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── jack │ └── loopviewpagers │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## LoopViewPager 3 | 4 | >### 添加引用 5 | 6 | 7 | 8 | ``` 9 | //项目根目录 gradle 10 | allprojects { 11 | repositories { 12 | ... 13 | maven { url 'https://jitpack.io' } 14 | } 15 | } 16 | 17 | //app目录 gradle 18 | dependencies { 19 | implementation 'com.github.jack921:LoopViewPagers:1.2' 20 | } 21 | ``` 22 | 23 | 24 | 25 | --- 26 | 27 | >### 属性 28 | 29 | 属性 | 解释 30 | ---|--- 31 | loop_now_indicator_img | 指示器当前点的图片 32 | loop_indicator_img | 指示器未选点的图片 33 | loop_gravity | 指示器的位置(center:中间,left:左边,right:右边) 34 | 35 | 36 | --- 37 | 38 | 39 | > ### API说明 40 | 41 | api | 解释 42 | ---|--- 43 | startBanner() | 开始轮播 44 | startBanner(long delayTime) | 开始轮播同时设置滚动的时间间隔 45 | setAnimation() | 切换过度动画 46 | getViewPager | 得到原生的ViewPage 47 | setData(Context context, List mData, CreateView mCreatView) | 为LoopViewPager的View轮播设值, CreateView为View创建,刷新,删除的接口 48 | setData(final Context context, List mData,final UpdateImage updateImage) | 为LoopViewPager的简单图片轮播设值,UpdateImage返回ImageView和对应数据以便你用图片加载框架加载 49 | setOnPageChangeListener() | 设置viewpager滑动监听 50 | setOnPageClickListener() | 点击每个banner的监听 51 | setIndicatorType() | 设置指示器的类型,有IndicatorView()和IndicatiorCanvasView 52 | setDelayTime() | 设置滚动的时间间隔 53 | showIndicator(boolean show) | 是否显示指示器 54 | setIndicatorGravity() | 设置指示器的位置(IndicatorGravity.CENTER,IndicatorGravity.LEFT,IndicatorGravity.RIGHT) 55 | setIndicatorAnimator() | 当是IndicatorView指示器时,返回选择点的View,以便你那这个View进行各种动画操作 56 | 57 | --- 58 | 59 | 注:setData()方法最好放在最后面执行 60 | 61 | --- 62 | 63 | 64 | >#### View无限轮播demo 65 | 66 | ``` 67 | List data=new ArrayList<>(); 68 | final LayoutInflater layoutInflater=LayoutInflater.from(this); 69 | data.add("View1");data.add("View2"); 70 | data.add("View3"); data.add("View4"); 71 | data.add("View5"); data.add("View6"); 72 | viewPager.setData(this, data, new CreateView() { 73 | @Override 74 | public View createView(int position) { 75 | return layoutInflater.inflate(R.layout.layout_view,null); 76 | } 77 | @Override 78 | public void updateView(View view,int position, Object item) { 79 | ((TextView)view.findViewById(R.id.view_name)).setText((String)item); 80 | } 81 | @Override 82 | public void deleteView(int position){ 83 | //View销毁后的逻辑处理 84 | } 85 | }); 86 | ``` 87 | 88 | ###### 效果图: 89 | 90 | ![view.gif](https://upload-images.jianshu.io/upload_images/925576-c7c907916a7e5167.gif?imageMogr2/auto-orient/strip) 91 | 92 | 93 | --- 94 | 95 | 96 | >#### 懒人加载数据demo 97 | 98 | 99 | ``` 100 | List data=new ArrayList<>(); 101 | data.add(R.mipmap.ic_banner1); 102 | data.add(R.mipmap.ic_banner2); 103 | data.add(R.mipmap.ic_banner3); 104 | viewPager.setData(this, data, new UpdateImage() { 105 | @Override 106 | public void loadImage(ImageView view, int position, Integer item) { 107 | view.setScaleType(ImageView.ScaleType.FIT_XY); 108 | //加载图片,如gide 109 | Glide.with(MainActivity.this).load(item).into(view); 110 | } 111 | }); 112 | ``` 113 | 114 | 115 | ###### 效果图: 116 | 117 | ![image.gif](https://upload-images.jianshu.io/upload_images/925576-e1718da15129fc22.gif?imageMogr2/auto-orient/strip) 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion "28.0.1" 6 | defaultConfig { 7 | applicationId "com.jack.loopviewpager" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.0.0-beta01' 25 | implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05' 26 | implementation 'androidx.constraintlayout:constraintlayout:1.1.2' 27 | testImplementation 'junit:junit:4.12' 28 | androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' 29 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' 30 | implementation project(path: ':loopviewpagers') 31 | implementation 'com.github.bumptech.glide:glide:4.8.0' 32 | annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jack/loopviewpager/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.jack.loopviewpager", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/jack/loopviewpager/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import androidx.fragment.app.Fragment; 5 | 6 | import android.animation.ObjectAnimator; 7 | import android.animation.PropertyValuesHolder; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import com.bumptech.glide.Glide; 17 | import com.jack.loopviewpager.transformer.AccordionTransformer; 18 | import com.jack.loopviewpagers.IndicatiorCanvasView; 19 | import com.jack.loopviewpagers.LoopViewPager; 20 | import com.jack.loopviewpagers.interfaces.CreateView; 21 | import com.jack.loopviewpagers.interfaces.IndicatorAnimator; 22 | import com.jack.loopviewpagers.interfaces.OnPageClickListener; 23 | import com.jack.loopviewpagers.interfaces.UpdateImage; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * @author Jack 29 | */ 30 | public class MainActivity extends AppCompatActivity { 31 | 32 | public LoopViewPager viewPager; 33 | public List listFragment=new ArrayList<>(); 34 | ViewPageFragment viewPageFragment1=new ViewPageFragment(); 35 | ViewPageFragment viewPageFragment2=new ViewPageFragment(); 36 | ViewPageFragment viewPageFragment3=new ViewPageFragment(); 37 | ViewPageFragment viewPageFragment4=new ViewPageFragment(); 38 | ViewPageFragment viewPageFragment5=new ViewPageFragment(); 39 | ViewPageFragment viewPageFragment6=new ViewPageFragment(); 40 | ViewPageFragment viewPageFragment7=new ViewPageFragment(); 41 | ViewPageFragment viewPageFragment8=new ViewPageFragment(); 42 | 43 | 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.activity_main); 48 | String image="https://img4.duitang.com/uploads/item/201506/06/20150606155423_h5zyU.thumb.700_0.jpeg"; 49 | viewPager=findViewById(R.id.view_pager); 50 | 51 | // initData1(); 52 | // viewPager.setData(getSupportFragmentManager(),listFragment); 53 | 54 | List data=new ArrayList<>(); 55 | final LayoutInflater layoutInflater=LayoutInflater.from(this); 56 | data.add("View1");data.add("View2"); 57 | data.add("View3"); data.add("View4"); 58 | data.add("View5"); data.add("View6"); 59 | viewPager.setData(this, data, new CreateView() { 60 | @Override 61 | public View createView(int position) { 62 | Log.e("Main_Create",position+""); 63 | return layoutInflater.inflate(R.layout.layout_view,null); 64 | } 65 | @Override 66 | public void updateView(View view,int position, Object item) { 67 | Log.e("Main_Update",position+""); 68 | ((TextView)view.findViewById(R.id.view_name)).setText((String)item); 69 | } 70 | @Override 71 | public void deleteView(int position){ 72 | Log.e("Main_Delete",position+""); 73 | } 74 | }); 75 | viewPager.setAnimation(true,new AccordionTransformer()); 76 | 77 | 78 | // viewPager.setIndicatorAnimator(new IndicatorAnimator() { 79 | // @Override 80 | // public void indicatorView(View view) { 81 | // PropertyValuesHolder scaleYAnimator=PropertyValuesHolder.ofFloat("scaleY",1f,1.3f,1f); 82 | // PropertyValuesHolder scaleXAnimator=PropertyValuesHolder.ofFloat("scaleX",1f,1.3f,1f); 83 | // ObjectAnimator.ofPropertyValuesHolder(view, scaleYAnimator, scaleXAnimator).setDuration(1500).start(); 84 | // } 85 | // }); 86 | viewPager.setAnimation(true,new AccordionTransformer()); 87 | // viewPager.setIndicatorType(IndicatiorCanvasView.class); 88 | // viewPager.setIndicatorGravity(LoopViewPager.IndicatorGravity.CENTER); 89 | 90 | 91 | // List data=new ArrayList<>(); 92 | // data.add(R.mipmap.ic_banner1); 93 | // data.add(R.mipmap.ic_banner2); 94 | // data.add(R.mipmap.ic_banner3); 95 | // viewPager.setData(this, data, new UpdateImage() { 96 | // @Override 97 | // public void loadImage(ImageView view, int position, Integer item) { 98 | // view.setScaleType(ImageView.ScaleType.FIT_XY); 99 | // Glide.with(MainActivity.this).load(item).into(view); 100 | // } 101 | // }); 102 | 103 | 104 | 105 | // viewPager.startBanner(); 106 | 107 | } 108 | 109 | public void initData1(){ 110 | Bundle bundle=new Bundle(); 111 | bundle.putString("name","Fragment1"); 112 | viewPageFragment1.setArguments(bundle); 113 | listFragment.add(viewPageFragment1); 114 | 115 | Bundle bundle2=new Bundle(); 116 | bundle2.putString("name","Fragment2"); 117 | viewPageFragment2.setArguments(bundle2); 118 | listFragment.add(viewPageFragment2); 119 | 120 | Bundle bundle3=new Bundle(); 121 | bundle3.putString("name","Fragment3"); 122 | viewPageFragment3.setArguments(bundle3); 123 | listFragment.add(viewPageFragment3); 124 | 125 | Bundle bundle4=new Bundle(); 126 | bundle4.putString("name","Fragment4"); 127 | viewPageFragment4.setArguments(bundle4); 128 | listFragment.add(viewPageFragment4); 129 | 130 | Bundle bundle5=new Bundle(); 131 | bundle5.putString("name","Fragment5"); 132 | viewPageFragment5.setArguments(bundle5); 133 | listFragment.add(viewPageFragment5); 134 | 135 | Bundle bundle6=new Bundle(); 136 | bundle6.putString("name","Fragment6"); 137 | viewPageFragment6.setArguments(bundle6); 138 | listFragment.add(viewPageFragment6); 139 | 140 | Bundle bundle7=new Bundle(); 141 | bundle7.putString("name","Fragment7"); 142 | viewPageFragment7.setArguments(bundle7); 143 | listFragment.add(viewPageFragment7); 144 | 145 | Bundle bundle8=new Bundle(); 146 | bundle8.putString("name","Fragment8"); 147 | viewPageFragment8.setArguments(bundle8); 148 | listFragment.add(viewPageFragment8); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/jack/loopviewpager/ViewPageFragment.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import androidx.annotation.NonNull; 11 | import androidx.annotation.Nullable; 12 | import androidx.fragment.app.Fragment; 13 | 14 | public class ViewPageFragment extends Fragment { 15 | public TextView viewText; 16 | public String name; 17 | 18 | @Nullable 19 | @Override 20 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 21 | @Nullable Bundle savedInstanceState) { 22 | View view=inflater.inflate(R.layout.view_pager1,container,false); 23 | viewText=view.findViewById(R.id.view_text); 24 | Bundle bundle=getArguments(); 25 | name=bundle.getString("name"); 26 | viewText.setText(name); 27 | Log.e("ViewPageFragment_onCreate",name); 28 | return view; 29 | } 30 | 31 | @Override 32 | public void onDestroyView() { 33 | super.onDestroyView(); 34 | Log.e("ViewPageFragment_onDestroy",name); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/jack/loopviewpager/ViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager; 2 | 3 | 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import androidx.fragment.app.Fragment; 9 | import androidx.fragment.app.FragmentManager; 10 | import androidx.fragment.app.FragmentPagerAdapter; 11 | 12 | public class ViewPagerAdapter extends FragmentPagerAdapter { 13 | 14 | public List listFragment=new ArrayList<>(); 15 | 16 | public ViewPagerAdapter(FragmentManager fm, List listFragment) { 17 | super(fm); 18 | this.listFragment=listFragment; 19 | } 20 | 21 | @Override 22 | public Fragment getItem(int i) { 23 | return listFragment.get(i); 24 | } 25 | 26 | @Override 27 | public int getCount() { 28 | return listFragment.size(); 29 | } 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/jack/loopviewpager/transformer/ABaseTransformer.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager.transformer; 2 | 3 | import android.view.View; 4 | 5 | import androidx.viewpager.widget.ViewPager; 6 | 7 | public abstract class ABaseTransformer implements ViewPager.PageTransformer { 8 | 9 | /** 10 | * Called each {@link #transformPage(View, float)}. 11 | * 12 | * @param page 13 | * Apply the transformation to this page 14 | * @param position 15 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 16 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 17 | */ 18 | protected abstract void onTransform(View page, float position); 19 | 20 | /** 21 | * Apply a property transformation to the given page. For most use cases, this method should not be overridden. 22 | * Instead use {@link #transformPage(View, float)} to perform typical transformations. 23 | * 24 | * @param page 25 | * Apply the transformation to this page 26 | * @param position 27 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 28 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 29 | */ 30 | @Override 31 | public void transformPage(View page, float position) { 32 | onPreTransform(page, position); 33 | onTransform(page, position); 34 | onPostTransform(page, position); 35 | } 36 | 37 | /** 38 | * If the position offset of a fragment is less than negative one or greater than one, returning true will set the 39 | * fragment alpha to 0f. Otherwise fragment alpha is always defaulted to 1f. 40 | * 41 | * @return 42 | */ 43 | protected boolean hideOffscreenPages() { 44 | return true; 45 | } 46 | 47 | /** 48 | * Indicates if the default animations of the view pager should be used. 49 | * 50 | * @return 51 | */ 52 | protected boolean isPagingEnabled() { 53 | return false; 54 | } 55 | 56 | /** 57 | * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}. 58 | *

59 | * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do 60 | * not modify the same page properties. For instance changing from a transformation that applies rotation to a 61 | * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied 62 | * alpha. 63 | * 64 | * @param page 65 | * Apply the transformation to this page 66 | * @param position 67 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 68 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 69 | */ 70 | protected void onPreTransform(View page, float position) { 71 | final float width = page.getWidth(); 72 | 73 | page.setRotationX(0); 74 | page.setRotationY(0); 75 | page.setRotation(0); 76 | page.setScaleX(1); 77 | page.setScaleY(1); 78 | page.setPivotX(0); 79 | page.setPivotY(0); 80 | page.setTranslationY(0); 81 | page.setTranslationX(isPagingEnabled() ? 0f : -width * position); 82 | 83 | if (hideOffscreenPages()) { 84 | page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f); 85 | // page.setEnabled(false); 86 | } else { 87 | // page.setEnabled(true); 88 | page.setAlpha(1f); 89 | } 90 | } 91 | 92 | /** 93 | * Called each {@link #transformPage(View, float)} after {@link #onTransform(View, float)}. 94 | * 95 | * @param page 96 | * Apply the transformation to this page 97 | * @param position 98 | * Position of page relative to the current front-and-center position of the pager. 0 is front and 99 | * center. 1 is one full page position to the right, and -1 is one page position to the left. 100 | */ 101 | protected void onPostTransform(View page, float position) { 102 | } 103 | 104 | /** 105 | * Same as {@link Math#min(double, double)} without double casting, zero closest to infinity handling, or NaN support. 106 | * 107 | * @param val 108 | * @param min 109 | * @return 110 | */ 111 | protected static final float min(float val, float min) { 112 | return val < min ? min : val; 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /app/src/main/java/com/jack/loopviewpager/transformer/AccordionTransformer.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager.transformer; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * @author Jack 7 | */ 8 | public class AccordionTransformer extends ABaseTransformer { 9 | 10 | @Override 11 | protected void onTransform(View view, float position) { 12 | view.setPivotX(position < 0 ? 0 : view.getWidth()); 13 | view.setScaleX(position < 0 ? 1f + position : 1f - position); 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_pager1.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_banner1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xhdpi/ic_banner1.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_banner2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xhdpi/ic_banner2.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_banner3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xhdpi/ic_banner3.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/mobile_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LoopViewPager 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/jack/loopviewpager/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpager; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | jcenter() 7 | mavenCentral() 8 | google() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.3.0-alpha05' 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | jcenter() 22 | mavenCentral() 23 | google() 24 | maven { url 'https://jitpack.io' } 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Sep 06 15:11:12 CST 2018 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-4.9-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /image/fragment.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/image/fragment.gif -------------------------------------------------------------------------------- /image/image.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/image/image.gif -------------------------------------------------------------------------------- /image/view.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/image/view.gif -------------------------------------------------------------------------------- /loopviewpagers/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /loopviewpagers/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.jack921' 5 | 6 | 7 | android { 8 | compileSdkVersion 28 9 | buildToolsVersion "28.0.1" 10 | 11 | 12 | defaultConfig { 13 | minSdkVersion 15 14 | targetSdkVersion 28 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | 34 | implementation 'androidx.appcompat:appcompat:1.0.0-beta01' 35 | testImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' 38 | } 39 | -------------------------------------------------------------------------------- /loopviewpagers/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /loopviewpagers/src/androidTest/java/com/jack/loopviewpagers/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.jack.loopviewpagers.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/IndicatiorCanvasView.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.util.AttributeSet; 9 | import android.view.Gravity; 10 | import android.view.ViewGroup; 11 | import android.view.ViewTreeObserver; 12 | import android.widget.ImageView; 13 | import android.widget.LinearLayout; 14 | 15 | import androidx.annotation.Nullable; 16 | 17 | /** 18 | * @author Jack 19 | */ 20 | public class IndicatiorCanvasView extends LinearLayout { 21 | private int select_origin; 22 | private float positionOffsetData; 23 | private Bitmap originBitmap; 24 | private ImageView firstView; 25 | private ImageView secondView; 26 | private Context context; 27 | private int numView; 28 | 29 | private int[] firstViewLocation=new int[2]; 30 | private int[] secondViewLocation=new int[2]; 31 | private int originMargin=0; 32 | 33 | public IndicatiorCanvasView(Context context,int origin,int select_origin) { 34 | this(context,null); 35 | originBitmap=BitmapFactory.decodeResource(context.getResources(), origin); 36 | this.select_origin=select_origin; 37 | this.context=context; 38 | } 39 | 40 | public IndicatiorCanvasView(Context context, @Nullable AttributeSet attrs) { 41 | this(context, attrs,0); 42 | } 43 | 44 | public IndicatiorCanvasView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 45 | super(context, attrs, defStyleAttr); 46 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 47 | @Override 48 | public void onGlobalLayout() { 49 | firstView.getLocationInWindow(firstViewLocation); 50 | secondView.getLocationInWindow(secondViewLocation); 51 | originMargin=secondViewLocation[0]-firstViewLocation[0]; 52 | } 53 | }); 54 | } 55 | 56 | public void initView(int size){ 57 | this.numView=size; 58 | for(int i=0;i extends FrameLayout { 35 | private LoopFragmentPagerAdapter loopFragmentPagerAdapter; 36 | private LoopViewPagerScroller loopViewPagerScroller; 37 | private int gravity=Gravity.BOTTOM|Gravity.CENTER; 38 | private IndicatiorCanvasView indicatorCanvasView; 39 | private IndicatorView indicatorView; 40 | private ViewPager.OnPageChangeListener onPageChangeListener; 41 | private OnPageClickListener onClickListener; 42 | private IndicatorAnimator indicatorAnimator; 43 | 44 | private ViewPager viewPager; 45 | private Runnable loopRunnable; 46 | private Handler mHandler; 47 | private long delayTime=3000; 48 | private int currentItem=0; 49 | private int viewNumber=0; 50 | 51 | private int loopNowIndicatorImg=R.mipmap.ic_origin; 52 | private int loopIndicatorImg=R.mipmap.ic_un_origin; 53 | 54 | 55 | public enum IndicatorGravity { 56 | LEFT, 57 | RIGHT, 58 | CENTER, 59 | } 60 | 61 | public LoopViewPager(@NonNull Context context) { 62 | this(context,null); 63 | } 64 | 65 | public LoopViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { 66 | this(context,attrs,0); 67 | } 68 | 69 | public LoopViewPager(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 70 | super(context, attrs, defStyleAttr); 71 | TypedArray typedArray = context.getTheme().obtainStyledAttributes( 72 | attrs, R.styleable.LoopViewPage,defStyleAttr,0); 73 | int numCount = typedArray.getIndexCount(); 74 | for(int i=0;i listFragment){ 176 | viewNumber=listFragment.size(); 177 | initIndicator(getContext()); 178 | this.loopFragmentPagerAdapter=new LoopFragmentPagerAdapter(fragmentManager,listFragment); 179 | this.viewPager.setAdapter(this.loopFragmentPagerAdapter); 180 | } 181 | 182 | public void setData(Context context, List mData, CreateView mCreatView){ 183 | viewNumber=mData.size(); 184 | initIndicator(getContext()); 185 | LoopViewPagerAdapter loopViewPagerAdapter=new LoopViewPagerAdapter(context,mData,mCreatView,onClickListener); 186 | viewPager.setAdapter(loopViewPagerAdapter); 187 | } 188 | 189 | public void setData(final Context context, List mData,final UpdateImage updateImage){ 190 | viewNumber=mData.size(); 191 | initIndicator(getContext()); 192 | LoopViewPagerAdapter loopViewPagerAdapter=new LoopViewPagerAdapter(context, mData, new CreateView() { 193 | @Override 194 | public View createView(int position) { 195 | return new ImageView(context); 196 | } 197 | @Override 198 | public void updateView(View view, int position, Object item) { 199 | if(updateImage!=null){ 200 | updateImage.loadImage(((ImageView)view),position,item); 201 | } 202 | } 203 | @Override 204 | public void deleteView(int position){} 205 | },onClickListener); 206 | viewPager.setAdapter(loopViewPagerAdapter); 207 | } 208 | 209 | public void initIndicator(Context context){ 210 | if(indicatorCanvasView==null&&indicatorView==null){ 211 | indicatorView=new IndicatorView(context,loopNowIndicatorImg,loopIndicatorImg,indicatorAnimator); 212 | } 213 | LayoutParams layoutParams= new LayoutParams(-2,-2); 214 | layoutParams.gravity=gravity; 215 | int margins = DensityUtils.dp2px(context, 8.0F); 216 | layoutParams.setMargins(margins,0,margins,margins); 217 | if(indicatorCanvasView!=null){ 218 | addView(indicatorCanvasView,layoutParams); 219 | indicatorCanvasView.initView(viewNumber); 220 | } 221 | if(indicatorView!=null){ 222 | addView(indicatorView,layoutParams); 223 | indicatorView.initView(viewNumber); 224 | } 225 | } 226 | 227 | public void setDelayTime(long delayTime){ 228 | this.delayTime=delayTime; 229 | } 230 | 231 | public void startBanner(){ 232 | mHandler.postDelayed(loopRunnable,delayTime); 233 | } 234 | 235 | public void startBanner(long delayTime){ 236 | this.delayTime=delayTime; 237 | mHandler.postDelayed(loopRunnable,delayTime); 238 | } 239 | 240 | public void showIndicator(boolean show){ 241 | if(indicatorView!=null){ 242 | indicatorView.setVisibility(show==true?View.VISIBLE:View.GONE); 243 | } 244 | if(indicatorCanvasView!=null){ 245 | indicatorCanvasView.setVisibility(show==true?View.VISIBLE:View.GONE); 246 | } 247 | } 248 | 249 | public void setIndicatorGravity(IndicatorGravity indicatorGravity){ 250 | LayoutParams layoutParams= new LayoutParams(-2,-2); 251 | layoutParams.gravity=gravity; 252 | int margins = DensityUtils.dp2px(getContext(),8.0F); 253 | layoutParams.setMargins(margins,0,margins,margins); 254 | if(indicatorGravity== IndicatorGravity.LEFT){ 255 | gravity=Gravity.BOTTOM; 256 | }else if(indicatorGravity== IndicatorGravity.CENTER){ 257 | gravity=Gravity.BOTTOM|Gravity.CENTER; 258 | }else if(indicatorGravity== IndicatorGravity.RIGHT){ 259 | gravity=Gravity.BOTTOM|Gravity.RIGHT; 260 | } 261 | if(indicatorView!=null){ 262 | indicatorView.setLayoutParams(layoutParams); 263 | } 264 | if(indicatorCanvasView!=null){ 265 | indicatorCanvasView.setLayoutParams(layoutParams); 266 | } 267 | } 268 | 269 | } 270 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/adapter/LoopFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.adapter; 2 | 3 | import android.view.ViewGroup; 4 | import java.util.List; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.fragment.app.FragmentManager; 7 | import androidx.fragment.app.FragmentPagerAdapter; 8 | 9 | /** 10 | * @author Jack 11 | */ 12 | public class LoopFragmentPagerAdapter extends FragmentPagerAdapter { 13 | public List listFragment; 14 | 15 | public LoopFragmentPagerAdapter(FragmentManager fm, List listData) { 16 | super(fm); 17 | this.listFragment=listData; 18 | } 19 | 20 | @Override 21 | public Object instantiateItem(ViewGroup container, int position) { 22 | position = position % listFragment.size(); 23 | return super.instantiateItem(container, position); 24 | } 25 | 26 | @Override 27 | public Fragment getItem(int i) { 28 | return this.listFragment.get(i); 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return Integer.MAX_VALUE; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/adapter/LoopViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.view.ViewParent; 7 | import com.jack.loopviewpagers.interfaces.CreateView; 8 | import com.jack.loopviewpagers.interfaces.OnPageClickListener; 9 | import java.util.List; 10 | import androidx.annotation.NonNull; 11 | import androidx.viewpager.widget.PagerAdapter; 12 | 13 | public class LoopViewPagerAdapter extends PagerAdapter { 14 | private OnPageClickListener onClickListener; 15 | private CreateView mCreateView; 16 | private Context context; 17 | private List mData; 18 | 19 | public LoopViewPagerAdapter(Context context, List list, CreateView createView, OnPageClickListener onClickListener){ 20 | this.onClickListener=onClickListener; 21 | this.mCreateView=createView; 22 | this.context=context; 23 | this.mData=list; 24 | } 25 | 26 | @Override 27 | public Object instantiateItem(ViewGroup container, int position) { 28 | position=position%mData.size(); 29 | if(mCreateView==null){ 30 | return new View(context); 31 | } 32 | View view=mCreateView.createView(position); 33 | final int finalPosition = position; 34 | view.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View view) { 37 | if(onClickListener!=null){ 38 | onClickListener.onClick(view, finalPosition); 39 | } 40 | } 41 | }); 42 | ViewParent vp = view.getParent(); 43 | if (vp != null) { 44 | ViewGroup parent = (ViewGroup)vp; 45 | parent.removeView(view); 46 | } 47 | mCreateView.updateView(view,position,mData.get(position)); 48 | container.addView(view); 49 | return view; 50 | } 51 | 52 | @Override 53 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { 54 | container.removeView((View)object); 55 | mCreateView.deleteView(position); 56 | } 57 | 58 | @Override 59 | public int getCount() { 60 | return Integer.MAX_VALUE; 61 | } 62 | 63 | @Override 64 | public boolean isViewFromObject(@NonNull View arg0, @NonNull Object arg1) { 65 | return arg0==arg1; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/interfaces/CreateView.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.interfaces; 2 | 3 | import android.view.View; 4 | 5 | public interface CreateView { 6 | 7 | View createView(int position); 8 | 9 | void updateView(View view, int position, T item); 10 | 11 | void deleteView(int position); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/interfaces/IndicatorAnimator.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.interfaces; 2 | 3 | import android.view.View; 4 | 5 | public interface IndicatorAnimator { 6 | 7 | void indicatorView(View view); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/interfaces/OnPageClickListener.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.interfaces; 2 | 3 | import android.view.View; 4 | 5 | public interface OnPageClickListener { 6 | 7 | void onClick(View view,int position); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/interfaces/UpdateImage.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.interfaces; 2 | 3 | import android.widget.ImageView; 4 | 5 | public interface UpdateImage { 6 | 7 | void loadImage(ImageView view, int position, T item); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/util/DensityUtils.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.util; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | 6 | public class DensityUtils { 7 | private DensityUtils() { 8 | throw new UnsupportedOperationException("cannot be instantiated"); 9 | } 10 | 11 | public static int dp2px(Context context, float dpVal) { 12 | return (int)TypedValue.applyDimension(1, dpVal, context.getResources().getDisplayMetrics()); 13 | } 14 | 15 | public static int sp2px(Context context, float spVal) { 16 | return (int)TypedValue.applyDimension(2, spVal, context.getResources().getDisplayMetrics()); 17 | } 18 | 19 | public static float px2dp(Context context, float pxVal) { 20 | float scale = context.getResources().getDisplayMetrics().density; 21 | return pxVal / scale; 22 | } 23 | 24 | public static float px2sp(Context context, float pxVal) { 25 | return pxVal / context.getResources().getDisplayMetrics().scaledDensity; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/java/com/jack/loopviewpagers/util/LoopViewPagerScroller.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers.util; 2 | 3 | import android.content.Context; 4 | import android.view.animation.Interpolator; 5 | import android.widget.Scroller; 6 | 7 | import java.lang.reflect.Field; 8 | 9 | import androidx.viewpager.widget.ViewPager; 10 | 11 | public class LoopViewPagerScroller extends Scroller { 12 | // 滑动速度 13 | private int mScrollDuration = 2000; 14 | 15 | /** 16 | * 设置速度速度 17 | * @param duration 18 | */ 19 | public void setScrollDuration(int duration){ 20 | this.mScrollDuration = duration; 21 | } 22 | 23 | public LoopViewPagerScroller(Context context) { 24 | super(context); 25 | } 26 | 27 | public LoopViewPagerScroller(Context context, Interpolator interpolator) { 28 | super(context, interpolator); 29 | } 30 | 31 | public LoopViewPagerScroller(Context context, Interpolator interpolator, boolean flywheel) { 32 | super(context, interpolator, flywheel); 33 | } 34 | 35 | @Override 36 | public void startScroll(int startX, int startY, int dx, int dy, int duration) { 37 | super.startScroll(startX, startY, dx, dy, mScrollDuration); 38 | } 39 | 40 | @Override 41 | public void startScroll(int startX, int startY, int dx, int dy) { 42 | super.startScroll(startX, startY, dx, dy, mScrollDuration); 43 | } 44 | 45 | public void initViewPagerScroll(ViewPager viewPager) { 46 | try { 47 | Field mScroller = ViewPager.class.getDeclaredField("mScroller"); 48 | mScroller.setAccessible(true); 49 | mScroller.set(viewPager, this); 50 | } catch(Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/drawable/ic_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/drawable/ic_origin.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/drawable/ic_un_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/drawable/ic_un_origin.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/mipmap-xhdpi/ic_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/mipmap-xhdpi/ic_origin.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/mipmap-xhdpi/ic_un_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jack921/LoopViewPagers/015562653b9c794a92abaf7b0002799114324e17/loopviewpagers/src/main/res/mipmap-xhdpi/ic_un_origin.png -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /loopviewpagers/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LoopViewPagers 3 | 4 | -------------------------------------------------------------------------------- /loopviewpagers/src/test/java/com/jack/loopviewpagers/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jack.loopviewpagers; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':loopviewpagers' 2 | --------------------------------------------------------------------------------