22
33import android .content .res .Configuration ;
44import android .graphics .Color ;
5+ import android .graphics .drawable .BitmapDrawable ;
56import android .os .Bundle ;
67import android .support .v4 .widget .DrawerLayout ;
78import android .support .v7 .app .ActionBarActivity ;
1011import android .view .Menu ;
1112import android .view .MenuItem ;
1213import android .view .View ;
14+ import android .view .animation .AccelerateInterpolator ;
1315import android .widget .LinearLayout ;
1416
1517import java .util .ArrayList ;
1618import java .util .List ;
1719
20+ import io .codetail .animation .SupportAnimator ;
21+ import io .codetail .animation .ViewAnimationUtils ;
1822import yalantis .com .sidemenu .fragment .ContentFragment ;
23+ import yalantis .com .sidemenu .interfaces .Resourceble ;
24+ import yalantis .com .sidemenu .interfaces .ScreenShotable ;
1925import yalantis .com .sidemenu .model .SlideMenuItem ;
2026import yalantis .com .sidemenu .util .ViewAnimator ;
2127
2228
23- public class MainActivity extends ActionBarActivity {
29+ public class MainActivity extends ActionBarActivity implements ViewAnimator . ViewAnimatorListener {
2430 private DrawerLayout drawerLayout ;
2531 private ActionBarDrawerToggle drawerToggle ;
2632 private List <SlideMenuItem > list = new ArrayList <>();
2733 private ContentFragment contentFragment ;
2834 private ViewAnimator viewAnimator ;
35+ private int res = R .drawable .content_music ;
36+ private LinearLayout linearLayout ;
37+
2938
3039 @ Override
3140 protected void onCreate (Bundle savedInstanceState ) {
@@ -39,10 +48,18 @@ protected void onCreate(Bundle savedInstanceState) {
3948 }
4049 drawerLayout = (DrawerLayout ) findViewById (R .id .drawer_layout );
4150 drawerLayout .setScrimColor (Color .TRANSPARENT );
51+ linearLayout = (LinearLayout ) findViewById (R .id .left_drawer );
52+ linearLayout .setOnClickListener (new View .OnClickListener () {
53+ @ Override
54+ public void onClick (View v ) {
55+ drawerLayout .closeDrawers ();
56+ }
57+ });
58+
4259
4360 setActionBar ();
4461 createMenuList ();
45- viewAnimator = new ViewAnimator <>(this , list , ( LinearLayout ) findViewById ( R . id . left_drawer ), contentFragment , drawerLayout );
62+ viewAnimator = new ViewAnimator <>(this , list , contentFragment , drawerLayout , this );
4663 }
4764
4865 private void createMenuList () {
@@ -81,14 +98,14 @@ private void setActionBar() {
8198 /** Called when a drawer has settled in a completely closed state. */
8299 public void onDrawerClosed (View view ) {
83100 super .onDrawerClosed (view );
84- viewAnimator . getLinearLayout () .removeAllViews ();
85- viewAnimator . getLinearLayout () .invalidate ();
101+ linearLayout .removeAllViews ();
102+ linearLayout .invalidate ();
86103 }
87104
88105 @ Override
89106 public void onDrawerSlide (View drawerView , float slideOffset ) {
90107 super .onDrawerSlide (drawerView , slideOffset );
91- if (slideOffset > 0.6 && viewAnimator . getLinearLayout () .getChildCount () == 0 )
108+ if (slideOffset > 0.6 && linearLayout .getChildCount () == 0 )
92109 viewAnimator .showMenuContent ();
93110 }
94111
@@ -132,4 +149,46 @@ public boolean onOptionsItemSelected(MenuItem item) {
132149 }
133150 }
134151
152+ private ScreenShotable replaceFragment (ScreenShotable screenShotable , int topPosition ) {
153+ this .res = this .res == R .drawable .content_music ? R .drawable .content_films : R .drawable .content_music ;
154+ View view = findViewById (R .id .content_frame );
155+ int finalRadius = Math .max (view .getWidth (), view .getHeight ());
156+ SupportAnimator animator = ViewAnimationUtils .createCircularReveal (view , 0 , topPosition , 0 , finalRadius );
157+ animator .setInterpolator (new AccelerateInterpolator ());
158+ animator .setDuration (ViewAnimator .CIRCULAR_REVEAL_ANIMATION_DURATION );
159+
160+ findViewById (R .id .content_overlay ).setBackgroundDrawable (new BitmapDrawable (getResources (), screenShotable .getBitmap ()));
161+ animator .start ();
162+ ContentFragment contentFragment = ContentFragment .newInstance (this .res );
163+ getSupportFragmentManager ().beginTransaction ().replace (R .id .content_frame , contentFragment ).commit ();
164+ return contentFragment ;
165+ }
166+
167+ @ Override
168+ public ScreenShotable onSwitch (Resourceble slideMenuItem , ScreenShotable screenShotable , int position ) {
169+ switch (slideMenuItem .getName ()) {
170+ case ContentFragment .CLOSE :
171+ return screenShotable ;
172+ default :
173+ return replaceFragment (screenShotable , position );
174+ }
175+ }
176+
177+ @ Override
178+ public void disableHomeButton () {
179+ getSupportActionBar ().setHomeButtonEnabled (false );
180+
181+ }
182+
183+ @ Override
184+ public void enableHomeButton () {
185+ getSupportActionBar ().setHomeButtonEnabled (true );
186+ drawerLayout .closeDrawers ();
187+
188+ }
189+
190+ @ Override
191+ public void addViewToContainer (View view ) {
192+ linearLayout .addView (view );
193+ }
135194}
0 commit comments