11package yalantis .com .sidemenu .util ;
22
3- import android .graphics .drawable .BitmapDrawable ;
43import android .os .Handler ;
54import android .support .v4 .widget .DrawerLayout ;
65import android .support .v7 .app .ActionBarActivity ;
1312import java .util .ArrayList ;
1413import java .util .List ;
1514
16- import io .codetail .animation .SupportAnimator ;
17- import io .codetail .animation .ViewAnimationUtils ;
1815import yalantis .com .sidemenu .R ;
1916import yalantis .com .sidemenu .animation .FlipAnimation ;
20- import yalantis .com .sidemenu .fragment .ContentFragment ;
2117import yalantis .com .sidemenu .interfaces .Resourceble ;
2218import yalantis .com .sidemenu .interfaces .ScreenShotable ;
2319
@@ -30,30 +26,22 @@ public class ViewAnimator<T extends Resourceble> {
3026
3127 private ActionBarActivity actionBarActivity ;
3228 private List <T > list ;
33- private LinearLayout linearLayout ;
29+
3430 private List <View > viewList = new ArrayList <>();
3531 private ScreenShotable screenShotable ;
3632 private DrawerLayout drawerLayout ;
37-
38- private int res = R .drawable .content_music ;
39-
33+ private ViewAnimatorListener animatorListener ;
4034
4135 public ViewAnimator (ActionBarActivity activity ,
4236 List <T > items ,
43- LinearLayout linearLayout ,
4437 ScreenShotable screenShotable ,
45- final DrawerLayout drawerLayout ) {
38+ final DrawerLayout drawerLayout ,
39+ ViewAnimatorListener animatorListener ) {
4640 this .actionBarActivity = activity ;
4741 this .list = items ;
48- this .linearLayout = linearLayout ;
49- this .linearLayout .setOnClickListener (new View .OnClickListener () {
50- @ Override
51- public void onClick (View v ) {
52- drawerLayout .closeDrawers ();
53- }
54- });
5542 this .screenShotable = screenShotable ;
5643 this .drawerLayout = drawerLayout ;
44+ this .animatorListener = animatorListener ;
5745 }
5846
5947 public void showMenuContent () {
@@ -75,7 +63,7 @@ public void onClick(View v) {
7563 viewMenu .setVisibility (View .GONE );
7664 viewMenu .setEnabled (false );
7765 viewList .add (viewMenu );
78- linearLayout . addView (viewMenu );
66+ animatorListener . addViewToContainer (viewMenu );
7967 final double position = i ;
8068 final double delay = 3 * ANIMATION_DURATION * (position / size );
8169 new Handler ().postDelayed (new Runnable () {
@@ -111,7 +99,7 @@ public void run() {
11199 }
112100
113101 private void setViewsClickable (boolean clickable ) {
114- actionBarActivity . getSupportActionBar (). setHomeButtonEnabled ( false );
102+ animatorListener . disableHomeButton ( );
115103 for (View view : viewList ) {
116104 view .setEnabled (clickable );
117105 }
@@ -163,7 +151,7 @@ public void onAnimationEnd(Animation animation) {
163151 view .clearAnimation ();
164152 view .setVisibility (View .INVISIBLE );
165153 if (position == viewList .size () - 1 ) {
166- actionBarActivity . getSupportActionBar (). setHomeButtonEnabled ( true );
154+ animatorListener . enableHomeButton ( );
167155 drawerLayout .closeDrawers ();
168156 }
169157 }
@@ -178,53 +166,19 @@ public void onAnimationRepeat(Animation animation) {
178166 }
179167
180168 private void switchItem (Resourceble slideMenuItem , int topPosition ) {
181- switch (slideMenuItem .getName ()) {
182- case ContentFragment .CLOSE :
183- break ;
184- case ContentFragment .BUILDING :
185- replaceFragment (topPosition );
186- break ;
187- case ContentFragment .BOOK :
188- replaceFragment (topPosition );
189- break ;
190- case ContentFragment .PAINT :
191- replaceFragment (topPosition );
192- break ;
193- case ContentFragment .CASE :
194- replaceFragment (topPosition );
195- break ;
196- case ContentFragment .SHOP :
197- replaceFragment (topPosition );
198- break ;
199- case ContentFragment .PARTY :
200- replaceFragment (topPosition );
201- break ;
202- case ContentFragment .MOVIE :
203- replaceFragment (topPosition );
204- break ;
205- }
169+ this .screenShotable = animatorListener .onSwitch (slideMenuItem , screenShotable , topPosition );
206170 hideMenuContent ();
207171 }
208172
209- private void replaceFragment (int topPosition ) {
210- this .res = this .res == R .drawable .content_music ? R .drawable .content_films : R .drawable .content_music ;
211- View view = actionBarActivity .findViewById (R .id .content_frame );
212- int finalRadius = Math .max (view .getWidth (), view .getHeight ());
213- SupportAnimator animator =
214- ViewAnimationUtils .createCircularReveal (view , 0 , topPosition , 0 , finalRadius );
215- animator .setInterpolator (new AccelerateInterpolator ());
216- animator .setDuration (ViewAnimator .CIRCULAR_REVEAL_ANIMATION_DURATION );
217-
218- actionBarActivity .findViewById (R .id .content_overlay ).setBackgroundDrawable (new BitmapDrawable (actionBarActivity .getResources (), screenShotable .getBitmap ()));
219- animator .start ();
220- ContentFragment contentFragment = ContentFragment .newInstance (this .res );
221- actionBarActivity .getSupportFragmentManager ().beginTransaction ()
222- .replace (R .id .content_frame , contentFragment )
223- .commit ();
224- this .screenShotable = contentFragment ;
225- }
173+ public interface ViewAnimatorListener {
174+
175+ public ScreenShotable onSwitch (Resourceble slideMenuItem , ScreenShotable screenShotable , int position );
176+
177+ public void disableHomeButton ();
178+
179+ public void enableHomeButton ();
180+
181+ public void addViewToContainer (View view );
226182
227- public LinearLayout getLinearLayout () {
228- return linearLayout ;
229183 }
230184}
0 commit comments