├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── bg00.jpg │ │ │ │ ├── bg01.jpg │ │ │ │ ├── bg02.jpg │ │ │ │ ├── bg03.jpg │ │ │ │ ├── go_001.png │ │ │ │ ├── go_004.png │ │ │ │ ├── go_007.png │ │ │ │ ├── go_025.png │ │ │ │ └── circle.xml │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── dimens.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 │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── swipesectorlayout │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── swipesectorlayout │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── swipesectorlayout │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── swipesectorlayout ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ │ └── layout │ │ │ │ └── pager.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── tw │ │ │ └── lychee │ │ │ └── swipecurvelayout │ │ │ ├── ImageAdapter.java │ │ │ ├── CircularArrayList.java │ │ │ ├── CustomScroller.java │ │ │ ├── CustomPager.java │ │ │ ├── CustomPagerAdapter.java │ │ │ ├── CustomTransformer.java │ │ │ └── SwipeSectorLayout.java │ ├── test │ │ └── java │ │ │ └── tw │ │ │ └── lychee │ │ │ └── swipecurvelayout │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── tw │ │ └── lychee │ │ └── swipecurvelayout │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── images └── screenshot.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── LICENSE.txt ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /swipesectorlayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':swipesectorlayout' 2 | -------------------------------------------------------------------------------- /images/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/images/screenshot.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/bg00.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/bg01.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/bg02.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/bg03.jpg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SwipeSectorLayout 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/go_001.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/go_004.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/go_007.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_025.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/drawable/go_025.png -------------------------------------------------------------------------------- /swipesectorlayout/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SwipeSectorLayout 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 10 | 13 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/res/layout/pager.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/swipesectorlayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.swipesectorlayout; 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() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /swipesectorlayout/src/test/java/tw/lychee/swipecurvelayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 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() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea 38 | 39 | # Keystore files 40 | *.jks -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.widget.ImageView; 4 | 5 | public abstract class ImageAdapter { 6 | private CustomPagerAdapter mCustomAdapter; 7 | 8 | public abstract void setItemView(int position, ImageView view); 9 | public abstract void setBackgroundView(int position, ImageView view); 10 | public abstract int getCount(); 11 | public void notifyDataSetChanged() { 12 | mCustomAdapter.notifyDataSetChanged(); 13 | } 14 | 15 | void setCustomAdapter(CustomPagerAdapter adapter) { 16 | mCustomAdapter = adapter; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/CircularArrayList.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import java.util.ArrayList; 4 | 5 | 6 | class CircularArrayList { 7 | private ArrayList mItems; 8 | CircularArrayList() { 9 | mItems = new ArrayList<>(); 10 | } 11 | 12 | void add(T item) { 13 | mItems.add(item); 14 | } 15 | 16 | T get(int idx) { 17 | while (idx < 0) 18 | idx += mItems.size(); 19 | idx = idx % mItems.size(); 20 | return mItems.get(idx); 21 | } 22 | 23 | ArrayList getAll() { 24 | return mItems; 25 | } 26 | 27 | int size() { 28 | return mItems.size(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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 C:\Users\LCH\AppData\Local\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 | -------------------------------------------------------------------------------- /swipesectorlayout/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 C:\Users\LCH\AppData\Local\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 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/swipesectorlayout/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.swipesectorlayout; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.swipecurvelayout", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /swipesectorlayout/src/androidTest/java/tw/lychee/swipecurvelayout/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("tw.lychee.swipecurvelayout.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /swipesectorlayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 19 9 | targetSdkVersion 25 10 | versionCode 2 11 | versionName '1.1.0' 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.1.1' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/CustomScroller.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.content.Context; 4 | import android.view.animation.Interpolator; 5 | import android.widget.Scroller; 6 | 7 | class CustomScroller extends Scroller { 8 | 9 | private double mScrollFactor = 1; 10 | 11 | public CustomScroller(Context context) { 12 | super(context); 13 | } 14 | 15 | public CustomScroller(Context context, Interpolator interpolator) { 16 | super(context, interpolator); 17 | } 18 | 19 | 20 | public CustomScroller(Context context, Interpolator interpolator, boolean flywheel) { 21 | super(context, interpolator, flywheel); 22 | } 23 | 24 | public void setScrollDurationFactor(double scrollFactor) { 25 | mScrollFactor = scrollFactor; 26 | } 27 | 28 | @Override 29 | public void startScroll(int startX, int startY, int dx, int dy, int duration) { 30 | super.startScroll(startX, startY, dx, dy, (int) (duration * mScrollFactor)); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId 'com.example.swipesectorlayout' 8 | minSdkVersion 19 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | productFlavors { 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(include: ['*.jar'], dir: 'libs') 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.1.1' 30 | testCompile 'junit:junit:4.12' 31 | compile project(path: ':swipesectorlayout') 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Cheng-Han Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/CustomPager.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.animation.Interpolator; 7 | 8 | import java.lang.reflect.Field; 9 | 10 | public class CustomPager extends ViewPager { 11 | public CustomPager(Context context) { 12 | this(context, null); 13 | } 14 | 15 | public CustomPager(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | postInitViewPager(); 18 | } 19 | 20 | private CustomScroller mScroller = null; 21 | 22 | private void postInitViewPager() { 23 | try { 24 | Field scroller = ViewPager.class.getDeclaredField("mScroller"); 25 | scroller.setAccessible(true); 26 | Field interpolator = ViewPager.class.getDeclaredField("sInterpolator"); 27 | interpolator.setAccessible(true); 28 | mScroller = new CustomScroller(getContext(), 29 | (Interpolator) interpolator.get(null)); 30 | scroller.set(this, mScroller); 31 | } catch (Exception e) { 32 | } 33 | } 34 | 35 | public void setScrollDurationFactor(double scrollFactor) { 36 | mScroller.setScrollDurationFactor(scrollFactor); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/CustomPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.app.Activity; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | 9 | class CustomPagerAdapter extends PagerAdapter { 10 | private ImageAdapter mImageAdapter; 11 | CustomPagerAdapter(ImageAdapter adapter) { 12 | mImageAdapter = adapter; 13 | } 14 | 15 | @Override 16 | public int getCount() { 17 | return mImageAdapter.getCount(); 18 | } 19 | 20 | @Override 21 | public boolean isViewFromObject(View view, Object o) { 22 | return o == view; 23 | } 24 | 25 | 26 | @Override 27 | public CharSequence getPageTitle(int position) { 28 | return "Item " + (position); 29 | } 30 | 31 | @Override 32 | public Object instantiateItem(ViewGroup container, int position) { 33 | View view = ((Activity)container.getContext()).getLayoutInflater().inflate(R.layout.pager, null); 34 | ImageView imgView = (ImageView)view.findViewById(R.id.img); 35 | mImageAdapter.setBackgroundView(position, imgView); 36 | container.addView(view); 37 | return view; 38 | } 39 | 40 | @Override 41 | public void destroyItem(ViewGroup container, int position, Object object) { 42 | container.removeView((View) object); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/CustomTransformer.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.util.Log; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | 8 | class CustomTransformer implements ViewPager.PageTransformer{ 9 | private static final float MIN_ALPHA = 0.3f; 10 | private static final float DEFAULT_SCALE = 1.2f; 11 | 12 | @Override 13 | public void transformPage(View view, float position) { 14 | 15 | int pageWidth = view.getWidth(); 16 | ImageView imgView = (ImageView)view.findViewById(R.id.img); 17 | if (position < -1) { // [-Infinity,-1) 18 | // This page is way off-screen to the left. 19 | } else if (position <= 0) { // [-1,0] 20 | 21 | view.setAlpha((1 - MIN_ALPHA) * (1 - Math.abs(position)) + MIN_ALPHA); 22 | float transX = pageWidth * -position; 23 | view.setTranslationX(transX); 24 | float scale = (DEFAULT_SCALE - 1.0f) * (1 - Math.abs(position)) + 1; 25 | imgView.setScaleX(scale); 26 | imgView.setScaleY(scale); 27 | 28 | } else if (position <= 1) { // (0,1] 29 | imgView.setAlpha(1.0f); 30 | imgView.setScaleX(DEFAULT_SCALE); 31 | imgView.setScaleY(DEFAULT_SCALE); 32 | 33 | } else { // (1,+Infinity] 34 | // This page is way off-screen to the right. 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 20 | 21 | 31 | 32 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwipeSectorLayout 2 | The inspiration for this project comes from [Dima Panchenko's post on Dribbble](https://dribbble.com/shots/3272140-Jewelry-E-ommerce-Application). 3 | 4 | ## Screenshots 5 | ![alt tag](https://raw.githubusercontent.com/lycheetw/SwipeSectorLayout/master/images/screenshot.gif) 6 | 7 | ## Gradle 8 | ```groovy 9 | compile 'tw.lychee:SwipeSectorLayout:1.1.0' 10 | ``` 11 | 12 | ## Usage 13 | #### layout 14 | ```xml 15 | 22 | 23 | 33 | 34 | ``` 35 | 36 | #### code 37 | ```java 38 | SwipeSectorLayout swipeSectorLayout = (SwipeSectorLayout) findViewById(R.id.container); 39 | swipeSectorLayout.setAdapter(new ImageAdapter() { 40 | @Override 41 | public void setItemView(int position, ImageView view) { 42 | 43 | } 44 | 45 | @Override 46 | public void setBackgroundView(int position, ImageView view) { 47 | 48 | } 49 | 50 | @Override 51 | public int getCount() { 52 | return 0; 53 | } 54 | }); 55 | 56 | swipeSectorLayout.setOnPageChangeListener(new SwipeSectorLayout.OnPageChangeListener() { 57 | @Override 58 | public void onPageSelected(int position) { 59 | 60 | } 61 | }); 62 | 63 | ``` 64 | 65 | 66 | You can find complete demo code [here](https://github.com/lycheetw/SwipeSectorLayout/tree/master/app/src/main) 67 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/swipesectorlayout/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.swipesectorlayout; 2 | 3 | import android.support.annotation.DrawableRes; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import java.util.ArrayList; 10 | 11 | import tw.lychee.swipecurvelayout.ImageAdapter; 12 | import tw.lychee.swipecurvelayout.SwipeSectorLayout; 13 | 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | private ArrayList mPokemons; 17 | private TextView mNameTv; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | mPokemons = getPokemons(); 24 | mNameTv = (TextView) findViewById(R.id.pokemon_name); 25 | mNameTv.setText(mPokemons.get(0).getName()); 26 | 27 | SwipeSectorLayout swipeSectorLayout = (SwipeSectorLayout) findViewById(R.id.container); 28 | swipeSectorLayout.setAdapter(new MyAdapter(mPokemons)); 29 | 30 | swipeSectorLayout.setOnPageChangeListener(new SwipeSectorLayout.OnPageChangeListener() { 31 | @Override 32 | public void onPageSelected(int position) { 33 | mNameTv.setText(mPokemons.get(position).getName()); 34 | } 35 | }); 36 | 37 | } 38 | 39 | private ArrayList getPokemons() { 40 | ArrayList pokemons = new ArrayList<>(); 41 | pokemons.add(new Pokemon("Bulbasaur", Pokemon.TYPE_GRASS, R.drawable.go_001)); 42 | pokemons.add(new Pokemon("Charmander", Pokemon.TYPE_FIRE, R.drawable.go_004)); 43 | pokemons.add(new Pokemon("Squirtle", Pokemon.TYPE_WATER, R.drawable.go_007)); 44 | pokemons.add(new Pokemon("Pikachu", Pokemon.TYPE_ELECTRIC, R.drawable.go_025)); 45 | return pokemons; 46 | } 47 | 48 | class MyAdapter extends ImageAdapter { 49 | private ArrayList mItems; 50 | MyAdapter(ArrayList items) { 51 | mItems = items; 52 | } 53 | 54 | @Override 55 | public void setItemView(int position, ImageView view) { 56 | view.setImageResource(mItems.get(position).getResId()); 57 | } 58 | 59 | @Override 60 | public void setBackgroundView(int position, ImageView view) { 61 | switch (mItems.get(position).getType()) { 62 | case Pokemon.TYPE_GRASS: 63 | view.setImageResource(R.drawable.bg00); 64 | break; 65 | case Pokemon.TYPE_FIRE: 66 | view.setImageResource(R.drawable.bg01); 67 | break; 68 | case Pokemon.TYPE_WATER: 69 | view.setImageResource(R.drawable.bg02); 70 | break; 71 | case Pokemon.TYPE_ELECTRIC: 72 | view.setImageResource(R.drawable.bg03); 73 | break; 74 | } 75 | } 76 | 77 | @Override 78 | public int getCount() { 79 | return mItems.size(); 80 | } 81 | } 82 | 83 | class Pokemon { 84 | final static int TYPE_GRASS = 0; 85 | final static int TYPE_FIRE = 1; 86 | final static int TYPE_WATER = 2; 87 | final static int TYPE_ELECTRIC = 3; 88 | 89 | private String mName; 90 | private int mType; 91 | private int mResId; 92 | Pokemon(String name, int type, @DrawableRes int resId) { 93 | mName = name; 94 | mType = type; 95 | mResId = resId; 96 | } 97 | 98 | public String getName() { 99 | return mName; 100 | } 101 | 102 | public int getType() { 103 | return mType; 104 | } 105 | 106 | public int getResId() { 107 | return mResId; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /swipesectorlayout/src/main/java/tw/lychee/swipecurvelayout/SwipeSectorLayout.java: -------------------------------------------------------------------------------- 1 | package tw.lychee.swipecurvelayout; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | import android.widget.RelativeLayout; 10 | 11 | public class SwipeSectorLayout extends RelativeLayout { 12 | private CustomPager mViewPager; 13 | private CircularArrayList mReusableViews; 14 | private Context mContext; 15 | private OnPageChangeListener mListener; 16 | private int mItemViewWidth; 17 | private int mDegreeUnit; 18 | private boolean childViewInit = false; 19 | private ImageAdapter mAdapter; 20 | private final float DELAY = 0.05f; 21 | private final int ITEM_VIEW_COUNTS = 5; 22 | 23 | private final int PREVIEW_ITEM_COLOR = 0xFFAAAAAA; 24 | private final int PREVIEW_BG_COLOR = 0x60AAAAAA; 25 | 26 | 27 | public SwipeSectorLayout(Context context) { 28 | this(context, null); 29 | } 30 | 31 | public SwipeSectorLayout(Context context, AttributeSet attrs) { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public SwipeSectorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | TypedArray ta = context.obtainStyledAttributes(attrs, 38 | R.styleable.SwipeSectorLayout, 0, 0); 39 | int degree = ta.getInteger(R.styleable.SwipeSectorLayout_degree, 90); 40 | if(degree < 20){ 41 | throw new IllegalStateException("degree attribute cannot be less than 20"); 42 | } else if (degree > 180){ 43 | throw new IllegalStateException("degree attribute cannot be greater than 180"); 44 | } 45 | mDegreeUnit = degree / 2; 46 | mItemViewWidth = ta.getDimensionPixelSize(R.styleable.SwipeSectorLayout_item_width, 200); 47 | ta.recycle(); 48 | mContext = context; 49 | addViews(); 50 | setChildrenDrawingOrderEnabled(true); 51 | if(isInEditMode()) 52 | setPreviewColor(true); 53 | } 54 | @Override 55 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 56 | super.onLayout(changed, left, top, right, bottom); 57 | int n = getChildCount(); 58 | if(n > ITEM_VIEW_COUNTS + 2){ 59 | throw new IllegalStateException("SwipeSectorLayout can not have more than one child"); 60 | } 61 | //for preview in layout editor 62 | if(!childViewInit) 63 | setViewLocation(0); 64 | 65 | } 66 | 67 | @Override 68 | protected int getChildDrawingOrder(int childCount, int i) { 69 | if(i == 0) 70 | return 0; 71 | if(i == 1) 72 | return childCount - 1; 73 | return i - 1; 74 | } 75 | 76 | private void setPreviewColor(boolean isPreview) { 77 | if(isPreview){ 78 | for(View view: mReusableViews.getAll()){ 79 | view.setBackgroundColor(PREVIEW_ITEM_COLOR); 80 | } 81 | setBackgroundColor(PREVIEW_BG_COLOR); 82 | } else { 83 | for(View view: mReusableViews.getAll()){ 84 | view.setBackgroundColor(0); 85 | } 86 | setBackgroundColor(0); 87 | } 88 | 89 | } 90 | 91 | private void addViews() { 92 | LayoutParams pagerParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 93 | mViewPager = new CustomPager(mContext); 94 | mViewPager.setLayoutParams(pagerParams); 95 | mViewPager.setPageTransformer(false, new CustomTransformer()); 96 | mViewPager.setScrollDurationFactor(1.8); 97 | mViewPager.addOnPageChangeListener(new PageChangeListener()); 98 | addView(mViewPager); 99 | 100 | mReusableViews = new CircularArrayList<>(); 101 | for(int i = 0; i < ITEM_VIEW_COUNTS; i++){ 102 | ImageView view = new ImageView(mContext); 103 | LayoutParams itemParams = new LayoutParams(mItemViewWidth, mItemViewWidth); 104 | itemParams.addRule(ALIGN_PARENT_LEFT); 105 | itemParams.addRule(ALIGN_PARENT_BOTTOM); 106 | view.setLayoutParams(itemParams); 107 | addView(view); 108 | mReusableViews.add(view); 109 | } 110 | } 111 | 112 | public void setAdapter(ImageAdapter adapter) { 113 | mAdapter = adapter; 114 | CustomPagerAdapter customAdapter = new CustomPagerAdapter(mAdapter); 115 | mViewPager.setAdapter(customAdapter); 116 | adapter.setCustomAdapter(customAdapter); 117 | } 118 | 119 | public ImageAdapter getAdapter() { 120 | return mAdapter; 121 | } 122 | 123 | private void initChildView() { 124 | setViewLocation(0); 125 | setViewImage(0); 126 | childViewInit = true; 127 | } 128 | 129 | private void setViewLocation(float percentage) { 130 | final int windowWidth = getWidth(); 131 | final int halfWindowWidth = windowWidth / 2; 132 | final int radius = (int)Math.round(halfWindowWidth / Math.sin(Math.toRadians(mDegreeUnit))); 133 | final float HORIZON_SCALE = 1.1f; 134 | 135 | for(int i = 0; i < mReusableViews.size(); i++) { 136 | View view = mReusableViews.get(i); 137 | float degree = mDegreeUnit * i - mDegreeUnit * percentage; 138 | int threshold = mDegreeUnit * (mReusableViews.size() - 1); 139 | 140 | while(Math.abs(degree) >= threshold) { 141 | if(degree < 0) 142 | degree += (mReusableViews.size())* mDegreeUnit; 143 | else 144 | degree -= (mReusableViews.size()) * mDegreeUnit; 145 | } 146 | 147 | view.setRotation(degree); 148 | int left = (int)Math.round( 149 | halfWindowWidth + HORIZON_SCALE * radius * Math.sin(Math.toRadians(degree)) - mItemViewWidth / 2 150 | ); 151 | int bottom = (int)Math.round( 152 | radius * Math.cos(Math.toRadians(degree)) - radius * Math.cos(Math.toRadians(mDegreeUnit)) 153 | ); 154 | view.setTranslationX(left); 155 | view.setTranslationY(-bottom); 156 | 157 | //Log.d("setting", String.format("(%d) degree: %.4f, position: (%d, %d)", i, degree, left, bottom)); 158 | } 159 | } 160 | 161 | private void setViewImage(int currIdx) { 162 | int t = (mReusableViews.size() - 1) / 2; 163 | for(int i = currIdx - t; i <= currIdx + t; i++) { 164 | if(i < 0 || i > mAdapter.getCount() - 1) { 165 | mReusableViews.get(i).setImageResource(0); 166 | } else { 167 | mAdapter.setItemView(i, mReusableViews.get(i)); 168 | } 169 | } 170 | } 171 | 172 | public void setOnPageChangeListener(OnPageChangeListener listener) { 173 | mListener = listener; 174 | } 175 | 176 | class PageChangeListener implements ViewPager.OnPageChangeListener { 177 | private float mPreOffset = 0; 178 | private int mPrePosition = 0; 179 | @Override 180 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 181 | if(!childViewInit){ 182 | initChildView(); 183 | } 184 | 185 | if(positionOffset > 0.9999 || positionOffset == 0){ 186 | mPreOffset = 0; 187 | return; 188 | } 189 | 190 | if(mPrePosition != position) { 191 | setViewImage(position); 192 | mPrePosition = position; 193 | } 194 | 195 | if(mPreOffset == 0){ 196 | 197 | } else if(mPreOffset < positionOffset) { 198 | //right 199 | float percentage = positionOffset / (1 - DELAY); 200 | percentage = percentage >= 1 ? 1 : percentage; 201 | setViewLocation(position + percentage); 202 | } else { 203 | //left 204 | float percentage = (positionOffset - DELAY) / (1 - DELAY); 205 | percentage = percentage <= 0 ? 0 : percentage; 206 | setViewLocation(position + percentage); 207 | } 208 | mPreOffset = positionOffset; 209 | } 210 | 211 | @Override 212 | public void onPageSelected(int position) { 213 | if(mListener != null) 214 | mListener.onPageSelected(position); 215 | } 216 | 217 | @Override 218 | public void onPageScrollStateChanged(int state) { 219 | } 220 | } 221 | 222 | public interface OnPageChangeListener { 223 | void onPageSelected(int position); 224 | } 225 | } 226 | --------------------------------------------------------------------------------