1616import android .util .TypedValue ;
1717import android .view .View ;
1818import android .view .ViewAnimationUtils ;
19+ import android .widget .CheckBox ;
1920import android .widget .CompoundButton ;
2021import android .widget .Switch ;
2122
@@ -26,8 +27,6 @@ public class ColorActivity extends Activity {
2627
2728 private SharedPreferences sharedpreferences ;
2829 private View revealView ;
29- private View circleHolder ;
30- private View fabButton ;
3130
3231 @ Override
3332 protected void onCreate (final Bundle savedInstanceState ) {
@@ -36,37 +35,32 @@ protected void onCreate(final Bundle savedInstanceState) {
3635
3736 // Set the saved theme
3837 sharedpreferences = getSharedPreferences ("test" , Context .MODE_PRIVATE );
39- // sharedpreferences.edit().clear().apply();
4038 setTheme (sharedpreferences .getInt ("theme" , R .style .AppTheme ));
4139
4240 setContentView (R .layout .activity_color );
4341
4442 // Views
4543 Switch themeSwitch = (Switch ) findViewById (R .id .theme_switch );
46- themeSwitch .setChecked (sharedpreferences .getBoolean ("switch" , false ));
47- revealView = findViewById (R .id .reveal_view );
48- fabButton = findViewById (R .id .fab_button );
49- circleHolder = findViewById (R .id .circle_holder );
44+ themeSwitch .setChecked (sharedpreferences .getBoolean (themeSwitch .getId ()+"" , false ));
45+ themeSwitch .setOnCheckedChangeListener (checkedListener );
5046
51- themeSwitch . setOnCheckedChangeListener ( new CompoundButton . OnCheckedChangeListener () {
52- @ Override
53- public void onCheckedChanged ( CompoundButton buttonView , boolean isChecked ) {
47+ CheckBox themeCheck = ( CheckBox ) findViewById ( R . id . theme_check );
48+ themeCheck . setChecked ( sharedpreferences . getBoolean ( themeCheck . getId ()+ "" , false ));
49+ themeCheck . setOnCheckedChangeListener ( checkedListener );
5450
55- // Save the state of the switch
56- SharedPreferences .Editor ed = sharedpreferences .edit ();
57- ed .putInt ("theme" , (isChecked ) ? R .style .Base_Theme_AppCompat : R .style .Base_Theme_AppCompat_Light );
58- ed .putBoolean ("switch" , isChecked );
59- ed .apply ();
60- }
61- });
51+ revealView = findViewById (R .id .reveal_view );
6252
63- // Show the unreveal effect
53+ // Show the unReveal effect
6454 final int cx = sharedpreferences .getInt ("x" , 0 );
6555 final int cy = sharedpreferences .getInt ("y" , 0 );
6656
67- if (cx != 0 && cy != 0 ) {
57+ startHideRevealEffect (cx , cy );
58+ }
6859
69- // Show the unreveal effect when the view is attached to the window
60+ private void startHideRevealEffect (final int cx , final int cy ) {
61+
62+ if (cx != 0 && cy != 0 ) {
63+ // Show the unReveal effect when the view is attached to the window
7064 revealView .addOnAttachStateChangeListener (new View .OnAttachStateChangeListener () {
7165 @ Override
7266 public void onViewAttachedToWindow (View v ) {
@@ -76,80 +70,29 @@ public void onViewAttachedToWindow(View v) {
7670 getTheme ().resolveAttribute (android .R .attr .colorPrimary , outValue , true );
7771 revealView .setBackgroundColor (outValue .data );
7872
79- hideRevealEffect (cx , cy );
73+ Utils . hideRevealEffect (revealView , cx , cy , 1920 );
8074 }
8175
8276 @ Override
8377 public void onViewDetachedFromWindow (View v ) {}
8478 });
8579 }
86-
8780 }
8881
89- public void showRevealEffect (View v , int primaryColor ) {
90- revealView .setVisibility (View .VISIBLE );
91-
92- int [] location = new int [2 ];
93- revealView .setBackgroundColor (primaryColor );
94- v .getLocationOnScreen (location );
95-
96- int cx = (location [0 ] + (v .getWidth () / 2 ));
97- int cy = location [1 ] + (Utils .getStatusBarHeight (this ) / 2 );
98-
99-
100- SharedPreferences .Editor ed = sharedpreferences .edit ();
101- ed .putInt ("x" , cx );
102- ed .putInt ("y" , cy );
103- ed .apply ();
104-
105- int height = revealView .getHeight ();
106-
107- Animator anim = ViewAnimationUtils .createCircularReveal (
108- revealView , cx , cy , 0 , height );
109-
110-
111- anim .addListener (revealAnimationListener );
112- anim .start ();
113-
114- hideNavigationStatus ();
115- }
116-
117-
118- public void hideRevealEffect (int x , int y ) {
119-
120- revealView .setVisibility (View .VISIBLE );
121- int initialRadius = 1920 ;
122-
123- // create the animation (the final radius is zero)
124- Animator anim = ViewAnimationUtils .createCircularReveal (
125- revealView , x , y , 1080 , 0 );
126-
127- Log .d ("WTF" , "X: " +x +" Y: " +y +" - " +initialRadius );
128-
129- // make the view invisible when the animation is done
130- anim .addListener (new AnimatorListenerAdapter () {
131- @ Override
132- public void onAnimationEnd (Animator animation ) {
133- super .onAnimationEnd (animation );
134- revealView .setVisibility (View .INVISIBLE );
135- }
136- });
137-
138- anim .start ();
139- }
14082
14183 private void hideNavigationStatus () {
84+
14285 View decorView = getWindow ().getDecorView ();
14386
14487 int uiOptions = View .SYSTEM_UI_FLAG_HIDE_NAVIGATION ;
14588 decorView .setSystemUiVisibility (uiOptions );
14689 }
14790
91+
14892 Animator .AnimatorListener revealAnimationListener = new Animator .AnimatorListener () {
149- @ Override
150- public void onAnimationStart (Animator animation ) {
15193
152- }
94+ @ Override
95+ public void onAnimationStart (Animator animation ) {}
15396
15497 @ Override
15598 public void onAnimationEnd (Animator animation ) {
@@ -159,28 +102,22 @@ public void onAnimationEnd(Animator animation) {
159102 startActivity (i );
160103 overridePendingTransition (0 , 0 );
161104 finish ();
162-
163105 }
164106
165107 @ Override
166- public void onAnimationCancel (Animator animation ) {
167-
168- }
108+ public void onAnimationCancel (Animator animation ) {}
169109
170110 @ Override
171- public void onAnimationRepeat (Animator animation ) {
172-
173-
174- }
111+ public void onAnimationRepeat (Animator animation ) {}
175112 };
176113
177114
178115 public void view (View view ) {
116+
179117 int selectedTheme = 0 ;
180118 int primaryColor = 0 ;
181119
182120 switch (view .getId ()) {
183-
184121 case R .id .circle1 :
185122 selectedTheme = R .style .theme1 ;
186123 primaryColor = getResources ().getColor (R .color .color_set_1_primary );
@@ -202,13 +139,32 @@ public void view(View view) {
202139 break ;
203140 }
204141
142+ int [] location = new int [2 ];
143+ revealView .setBackgroundColor (primaryColor );
144+ view .getLocationOnScreen (location );
205145
206- showRevealEffect (view , primaryColor );
146+ int cx = (location [0 ] + (view .getWidth () / 2 ));
147+ int cy = location [1 ] + (Utils .getStatusBarHeight (this ) / 2 );
207148
208149 SharedPreferences .Editor ed = sharedpreferences .edit ();
150+ ed .putInt ("x" , cx );
151+ ed .putInt ("y" , cy );
209152 ed .putInt ("theme" , selectedTheme );
210153 ed .apply ();
211- //
212- //
154+
155+ hideNavigationStatus ();
156+ Utils .showRevealEFfect (revealView , cx , cy , revealAnimationListener );
213157 }
158+
159+
160+ CompoundButton .OnCheckedChangeListener checkedListener = new CompoundButton .OnCheckedChangeListener () {
161+
162+ @ Override
163+ public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
164+ SharedPreferences .Editor ed = sharedpreferences .edit ();
165+ ed .putInt ("theme" , (isChecked ) ? R .style .Base_Theme_AppCompat : R .style .Base_Theme_AppCompat_Light );
166+ ed .putBoolean (buttonView .getId ()+"" , isChecked );
167+ ed .apply ();
168+ }
169+ };
214170}
0 commit comments