44import android .net .Uri ;
55import android .os .Bundle ;
66import android .support .v7 .app .ActionBarActivity ;
7+ import android .util .Log ;
78import android .view .Menu ;
89import android .view .MenuInflater ;
910import android .view .MenuItem ;
1819import com .daimajia .slider .library .SliderLayout ;
1920import com .daimajia .slider .library .SliderTypes .BaseSliderView ;
2021import com .daimajia .slider .library .SliderTypes .TextSliderView ;
22+ import com .daimajia .slider .library .Tricks .ViewPagerEx ;
2123
2224import java .util .HashMap ;
2325
2426
25- public class MainActivity extends ActionBarActivity implements BaseSliderView .OnSliderClickListener {
27+ public class MainActivity extends ActionBarActivity implements BaseSliderView .OnSliderClickListener , ViewPagerEx . OnPageChangeListener {
2628
2729 private SliderLayout mDemoSlider ;
2830
@@ -54,15 +56,17 @@ protected void onCreate(Bundle savedInstanceState) {
5456 .setOnSliderClickListener (this );
5557
5658 //add your extra information
59+ textSliderView .bundle (new Bundle ());
5760 textSliderView .getBundle ()
58- .putString ("extra" ,name );
61+ .putString ("extra" ,name );
5962
6063 mDemoSlider .addSlider (textSliderView );
6164 }
6265 mDemoSlider .setPresetTransformer (SliderLayout .Transformer .Accordion );
6366 mDemoSlider .setPresetIndicator (SliderLayout .PresetIndicators .Center_Bottom );
6467 mDemoSlider .setCustomAnimation (new DescriptionAnimation ());
6568 mDemoSlider .setDuration (4000 );
69+ mDemoSlider .addOnPageChangeListener (this );
6670 ListView l = (ListView )findViewById (R .id .transformers );
6771 l .setAdapter (new TransformerAdapter (this ));
6872 l .setOnItemClickListener (new AdapterView .OnItemClickListener () {
@@ -76,6 +80,13 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
7680
7781 }
7882
83+ @ Override
84+ protected void onStop () {
85+ // To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed
86+ mDemoSlider .stopAutoCycle ();
87+ super .onStop ();
88+ }
89+
7990 @ Override
8091 public void onSliderClick (BaseSliderView slider ) {
8192 Toast .makeText (this ,slider .getBundle ().get ("extra" ) + "" ,Toast .LENGTH_SHORT ).show ();
@@ -108,4 +119,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
108119 }
109120 return super .onOptionsItemSelected (item );
110121 }
122+
123+ @ Override
124+ public void onPageScrolled (int position , float positionOffset , int positionOffsetPixels ) {}
125+
126+ @ Override
127+ public void onPageSelected (int position ) {
128+ Log .d ("Slider Demo" , "Page Changed: " + position );
129+ }
130+
131+ @ Override
132+ public void onPageScrollStateChanged (int state ) {}
111133}
0 commit comments