2
2
3
3
import android .content .res .Configuration ;
4
4
import android .graphics .Color ;
5
+ import android .graphics .drawable .BitmapDrawable ;
5
6
import android .os .Bundle ;
6
7
import android .support .v4 .widget .DrawerLayout ;
7
8
import android .support .v7 .app .ActionBarActivity ;
10
11
import android .view .Menu ;
11
12
import android .view .MenuItem ;
12
13
import android .view .View ;
14
+ import android .view .animation .AccelerateInterpolator ;
13
15
import android .widget .LinearLayout ;
14
16
15
17
import java .util .ArrayList ;
16
18
import java .util .List ;
17
19
20
+ import io .codetail .animation .SupportAnimator ;
21
+ import io .codetail .animation .ViewAnimationUtils ;
18
22
import yalantis .com .sidemenu .fragment .ContentFragment ;
23
+ import yalantis .com .sidemenu .interfaces .Resourceble ;
24
+ import yalantis .com .sidemenu .interfaces .ScreenShotable ;
19
25
import yalantis .com .sidemenu .model .SlideMenuItem ;
20
26
import yalantis .com .sidemenu .util .ViewAnimator ;
21
27
22
28
23
- public class MainActivity extends ActionBarActivity {
29
+ public class MainActivity extends ActionBarActivity implements ViewAnimator . ViewAnimatorListener {
24
30
private DrawerLayout drawerLayout ;
25
31
private ActionBarDrawerToggle drawerToggle ;
26
32
private List <SlideMenuItem > list = new ArrayList <>();
27
33
private ContentFragment contentFragment ;
28
34
private ViewAnimator viewAnimator ;
35
+ private int res = R .drawable .content_music ;
36
+ private LinearLayout linearLayout ;
37
+
29
38
30
39
@ Override
31
40
protected void onCreate (Bundle savedInstanceState ) {
@@ -39,10 +48,18 @@ protected void onCreate(Bundle savedInstanceState) {
39
48
}
40
49
drawerLayout = (DrawerLayout ) findViewById (R .id .drawer_layout );
41
50
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
+
42
59
43
60
setActionBar ();
44
61
createMenuList ();
45
- viewAnimator = new ViewAnimator <>(this , list , ( LinearLayout ) findViewById ( R . id . left_drawer ), contentFragment , drawerLayout );
62
+ viewAnimator = new ViewAnimator <>(this , list , contentFragment , drawerLayout , this );
46
63
}
47
64
48
65
private void createMenuList () {
@@ -81,14 +98,14 @@ private void setActionBar() {
81
98
/** Called when a drawer has settled in a completely closed state. */
82
99
public void onDrawerClosed (View view ) {
83
100
super .onDrawerClosed (view );
84
- viewAnimator . getLinearLayout () .removeAllViews ();
85
- viewAnimator . getLinearLayout () .invalidate ();
101
+ linearLayout .removeAllViews ();
102
+ linearLayout .invalidate ();
86
103
}
87
104
88
105
@ Override
89
106
public void onDrawerSlide (View drawerView , float slideOffset ) {
90
107
super .onDrawerSlide (drawerView , slideOffset );
91
- if (slideOffset > 0.6 && viewAnimator . getLinearLayout () .getChildCount () == 0 )
108
+ if (slideOffset > 0.6 && linearLayout .getChildCount () == 0 )
92
109
viewAnimator .showMenuContent ();
93
110
}
94
111
@@ -132,4 +149,46 @@ public boolean onOptionsItemSelected(MenuItem item) {
132
149
}
133
150
}
134
151
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
+ }
135
194
}
0 commit comments