├── .gitignore
├── AndroidManifest.xml
├── README.md
├── ic_launcher-web.png
├── libs
├── ViewHelperLib.jar
└── android-support-v4.jar
├── lint.xml
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── Thumbs.db
│ ├── asd.jpg
│ ├── ic_launcher.png
│ └── imgres.jpg
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ ├── activity_main.xml
│ └── mf.xml
├── menu
│ └── main.xml
├── values-hdpi
│ └── strings.xml
├── values-ldpi
│ └── strings.xml
├── values-mdpi
│ └── strings.xml
├── values-sw600dp
│ ├── dimens.xml
│ └── strings.xml
├── values-sw720dp-land
│ ├── dimens.xml
│ └── strings.xml
├── values-xhdpi
│ └── strings.xml
├── values-xxhdpi
│ ├── dimens.xml
│ └── strings.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── net
└── infratek
└── CarouselView
├── MainActivity.java
├── MyFragment.java
├── MyLinearLayout.java
└── MyPagerAdapter.java
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | .project
4 | .classpath
5 | .settings
6 | target
7 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Sample Carousel View
2 | ======================
3 |
4 | A sample project inspired from others.CarouselView with view pager android.
5 |
6 | You can find some explanation at :http://developwear.com/blog/2014/05/09/carousel-view-pager-for-android-example/
7 |
8 | ScreenShots : 
9 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/ViewHelperLib.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/libs/ViewHelperLib.jar
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-10
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-hdpi/Thumbs.db
--------------------------------------------------------------------------------
/res/drawable-hdpi/asd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-hdpi/asd.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/imgres.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-hdpi/imgres.jpg
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clkasd/CarouselViewProject/b90a337190be48d2c7e1a1785f497fb80f2e38e9/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/res/layout/mf.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/res/values-hdpi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -340
9 |
--------------------------------------------------------------------------------
/res/values-ldpi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -170
9 |
--------------------------------------------------------------------------------
/res/values-mdpi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -220
9 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values-sw600dp/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -680
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -680
9 |
--------------------------------------------------------------------------------
/res/values-xhdpi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -450
9 |
--------------------------------------------------------------------------------
/res/values-xxhdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values-xxhdpi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 | -680
9 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CarouselView
5 | Settings
6 | Hello world!
7 |
8 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
--------------------------------------------------------------------------------
/src/net/infratek/CarouselView/MainActivity.java:
--------------------------------------------------------------------------------
1 | package net.infratek.CarouselView;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentActivity;
5 | import android.support.v4.view.ViewPager;
6 | import com.arduandro.CarouselView.R;
7 |
8 | public class MainActivity extends FragmentActivity {
9 | public final static int PAGES = 10;
10 | // You can choose a bigger number for LOOPS, but you know, nobody will fling
11 | // more than 1000 times just in order to test your "infinite" ViewPager :D
12 | public final static int LOOPS = 10;
13 | public final static int FIRST_PAGE = 9;
14 | public final static float BIG_SCALE = 1.0f;
15 | public final static float SMALL_SCALE = 0.8f;
16 | public final static float DIFF_SCALE = BIG_SCALE - SMALL_SCALE;
17 |
18 | public MyPagerAdapter adapter;
19 | public ViewPager pager;
20 |
21 | public void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 |
25 | pager = (ViewPager) findViewById(R.id.myviewpager);
26 |
27 | adapter = new MyPagerAdapter(this, this.getSupportFragmentManager());
28 | pager.setAdapter(adapter);
29 | pager.setOnPageChangeListener(adapter);
30 |
31 |
32 |
33 | // Set current item to the middle page so we can fling to both
34 | // directions left and right
35 | pager.setCurrentItem(FIRST_PAGE);
36 |
37 | // Necessary or the pager will only have one extra page to show
38 | // make this at least however many pages you can see
39 | pager.setOffscreenPageLimit(3);
40 |
41 | // Set margin for pages as a negative number, so a part of next and
42 | // previous pages will be showed
43 |
44 | //
45 | pager.setPageMargin(Integer.parseInt(getString(R.string.pagermargin)));
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/net/infratek/CarouselView/MyFragment.java:
--------------------------------------------------------------------------------
1 | package net.infratek.CarouselView;
2 |
3 | import com.nineoldandroids.view.ViewHelper;
4 | import com.arduandro.CarouselView.R;
5 |
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.LinearLayout;
13 | import android.widget.TextView;
14 |
15 | public class MyFragment extends Fragment {
16 |
17 | public static Fragment newInstance(MainActivity context, int pos,
18 | float scale,boolean IsBlured)
19 | {
20 |
21 | Bundle b = new Bundle();
22 | b.putInt("pos", pos);
23 | b.putFloat("scale", scale);
24 | b.putBoolean("IsBlured", IsBlured);
25 | return Fragment.instantiate(context, MyFragment.class.getName(), b);
26 | }
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
30 | Bundle savedInstanceState) {
31 | if (container == null) {
32 | return null;
33 | }
34 |
35 | LinearLayout l = (LinearLayout)
36 | inflater.inflate(R.layout.mf, container, false);
37 |
38 | int pos = this.getArguments().getInt("pos");
39 |
40 | TextView tv = (TextView) l.findViewById(R.id.viewID);
41 | tv.setText("Position = " + pos);
42 |
43 | MyLinearLayout root = (MyLinearLayout) l.findViewById(R.id.root);
44 | float scale = this.getArguments().getFloat("scale");
45 | root.setScaleBoth(scale);
46 | boolean isBlured=this.getArguments().getBoolean("IsBlured");
47 | if(isBlured)
48 | {
49 | ViewHelper.setAlpha(root,MyPagerAdapter.getMinAlpha());
50 | ViewHelper.setRotationY(root, MyPagerAdapter.getMinDegree());
51 | }
52 | return l;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/net/infratek/CarouselView/MyLinearLayout.java:
--------------------------------------------------------------------------------
1 | package net.infratek.CarouselView;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.util.AttributeSet;
6 | import android.widget.LinearLayout;
7 |
8 | public class MyLinearLayout extends LinearLayout {
9 | private float scale = MainActivity.BIG_SCALE;
10 |
11 | public MyLinearLayout(Context context, AttributeSet attrs) {
12 | super(context, attrs);
13 | }
14 |
15 | public MyLinearLayout(Context context) {
16 | super(context);
17 | }
18 |
19 | public void setScaleBoth(float scale)
20 | {
21 | this.scale = scale;
22 | this.invalidate(); // If you want to see the scale every time you set
23 | // scale you need to have this line here,
24 | // invalidate() function will call onDraw(Canvas)
25 | // to redraw the view for you
26 | }
27 |
28 | @Override
29 | protected void onDraw(Canvas canvas) {
30 | // The main mechanism to display scale animation, you can customize it
31 | // as your needs
32 | int w = this.getWidth();
33 | int h = this.getHeight();
34 | canvas.scale(scale, scale, w/2, h/2);
35 |
36 | super.onDraw(canvas);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/net/infratek/CarouselView/MyPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package net.infratek.CarouselView;
2 |
3 |
4 | import com.nineoldandroids.animation.ObjectAnimator;
5 | import com.nineoldandroids.view.ViewHelper;
6 | import com.arduandro.CarouselView.R;
7 |
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentManager;
10 | import android.support.v4.app.FragmentPagerAdapter;
11 | import android.support.v4.view.ViewPager;
12 | import android.support.v4.view.ViewPager.OnPageChangeListener;
13 | import android.util.Log;
14 | import android.widget.TextView;
15 |
16 | public class MyPagerAdapter extends FragmentPagerAdapter implements
17 | ViewPager.OnPageChangeListener {
18 |
19 |
20 |
21 | private boolean swipedLeft=false;
22 | private int lastPage=9;
23 | private MyLinearLayout cur = null;
24 | private MyLinearLayout next = null;
25 | private MyLinearLayout prev = null;
26 | private MyLinearLayout prevprev = null;
27 | private MyLinearLayout nextnext = null;
28 | private MainActivity context;
29 | private FragmentManager fm;
30 | private float scale;
31 | private boolean IsBlured;
32 | private static float minAlpha=0.6f;
33 | private static float maxAlpha=1f;
34 | private static float minDegree=60.0f;
35 | private int counter=0;
36 |
37 | public static float getMinDegree()
38 | {
39 | return minDegree;
40 | }
41 | public static float getMinAlpha()
42 | {
43 | return minAlpha;
44 | }
45 | public static float getMaxAlpha()
46 | {
47 | return maxAlpha;
48 | }
49 |
50 | public MyPagerAdapter(MainActivity context, FragmentManager fm) {
51 | super(fm);
52 | this.fm = fm;
53 | this.context = context;
54 | }
55 |
56 | @Override
57 | public Fragment getItem(int position)
58 | {
59 |
60 |
61 |
62 | // make the first pager bigger than others
63 | if (position == MainActivity.FIRST_PAGE)
64 | scale = MainActivity.BIG_SCALE;
65 | else
66 | {
67 | scale = MainActivity.SMALL_SCALE;
68 | IsBlured=true;
69 |
70 | }
71 |
72 | Log.d("position", String.valueOf(position));
73 | Fragment curFragment= MyFragment.newInstance(context, position, scale,IsBlured);
74 | cur = getRootView(position);
75 | next = getRootView(position +1);
76 | prev = getRootView(position -1);
77 |
78 |
79 |
80 | return curFragment;
81 | }
82 |
83 | @Override
84 | public int getCount()
85 | {
86 | return 10;
87 | }
88 |
89 | @Override
90 | public void onPageScrolled(int position, float positionOffset,
91 | int positionOffsetPixels)
92 | {
93 | if (positionOffset >= 0f && positionOffset <= 1f)
94 | {
95 | positionOffset=positionOffset*positionOffset;
96 | cur = getRootView(position);
97 | next = getRootView(position +1);
98 | prev = getRootView(position -1);
99 | nextnext=getRootView(position +2);
100 |
101 | ViewHelper.setAlpha(cur, maxAlpha-0.5f*positionOffset);
102 | ViewHelper.setAlpha(next, minAlpha+0.5f*positionOffset);
103 | ViewHelper.setAlpha(prev, minAlpha+0.5f*positionOffset);
104 |
105 |
106 | if(nextnext!=null)
107 | {
108 | ViewHelper.setAlpha(nextnext, minAlpha);
109 | ViewHelper.setRotationY(nextnext, -minDegree);
110 | }
111 | if(cur!=null)
112 | {
113 | cur.setScaleBoth(MainActivity.BIG_SCALE
114 | - MainActivity.DIFF_SCALE * positionOffset);
115 |
116 | ViewHelper.setRotationY(cur, 0);
117 | }
118 |
119 | if(next!=null)
120 | {
121 | next.setScaleBoth(MainActivity.SMALL_SCALE
122 | + MainActivity.DIFF_SCALE * positionOffset);
123 | ViewHelper.setRotationY(next, -minDegree);
124 | }
125 | if(prev!=null)
126 | {
127 | ViewHelper.setRotationY(prev, minDegree);
128 | }
129 |
130 |
131 | /*To animate it properly we must understand swipe direction
132 | * this code adjusts the rotation according to direction.
133 | */
134 | if(swipedLeft)
135 | {
136 | if(next!=null)
137 | ViewHelper.setRotationY(next, -minDegree+minDegree*positionOffset);
138 | if(cur!=null)
139 | ViewHelper.setRotationY(cur, 0+minDegree*positionOffset);
140 | }
141 | else
142 | {
143 | if(next!=null)
144 | ViewHelper.setRotationY(next, -minDegree+minDegree*positionOffset);
145 | if(cur!=null)
146 | {
147 | ViewHelper.setRotationY(cur, 0+minDegree*positionOffset);
148 | }
149 | }
150 | }
151 | if(positionOffset>=1f)
152 | {
153 | ViewHelper.setAlpha(cur, maxAlpha);
154 | }
155 | }
156 |
157 | @Override
158 | public void onPageSelected(int position) {
159 |
160 | /*
161 | * to get finger swipe direction
162 | */
163 | if(lastPage<=position)
164 | {
165 | swipedLeft=true;
166 | }
167 | else if(lastPage>position)
168 | {
169 | swipedLeft=false;
170 | }
171 | lastPage=position;
172 | }
173 |
174 | @Override
175 | public void onPageScrollStateChanged(int state) {
176 | }
177 |
178 |
179 |
180 | private MyLinearLayout getRootView(int position)
181 | {
182 | MyLinearLayout ly;
183 | try {
184 | ly = (MyLinearLayout)
185 | fm.findFragmentByTag(this.getFragmentTag(position))
186 | .getView().findViewById(R.id.root);
187 | } catch (Exception e) {
188 | // TODO Auto-generated catch block
189 | return null;
190 | }
191 | if(ly!=null)
192 | return ly;
193 | return null;
194 | }
195 |
196 | private String getFragmentTag(int position)
197 | {
198 | return "android:switcher:" + context.pager.getId() + ":" + position;
199 | }
200 | }
201 |
--------------------------------------------------------------------------------