16
16
import android .util .TypedValue ;
17
17
import android .view .View ;
18
18
import android .view .ViewAnimationUtils ;
19
+ import android .widget .CheckBox ;
19
20
import android .widget .CompoundButton ;
20
21
import android .widget .Switch ;
21
22
@@ -26,8 +27,6 @@ public class ColorActivity extends Activity {
26
27
27
28
private SharedPreferences sharedpreferences ;
28
29
private View revealView ;
29
- private View circleHolder ;
30
- private View fabButton ;
31
30
32
31
@ Override
33
32
protected void onCreate (final Bundle savedInstanceState ) {
@@ -36,37 +35,32 @@ protected void onCreate(final Bundle savedInstanceState) {
36
35
37
36
// Set the saved theme
38
37
sharedpreferences = getSharedPreferences ("test" , Context .MODE_PRIVATE );
39
- // sharedpreferences.edit().clear().apply();
40
38
setTheme (sharedpreferences .getInt ("theme" , R .style .AppTheme ));
41
39
42
40
setContentView (R .layout .activity_color );
43
41
44
42
// Views
45
43
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 );
50
46
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 );
54
50
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 );
62
52
63
- // Show the unreveal effect
53
+ // Show the unReveal effect
64
54
final int cx = sharedpreferences .getInt ("x" , 0 );
65
55
final int cy = sharedpreferences .getInt ("y" , 0 );
66
56
67
- if (cx != 0 && cy != 0 ) {
57
+ startHideRevealEffect (cx , cy );
58
+ }
68
59
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
70
64
revealView .addOnAttachStateChangeListener (new View .OnAttachStateChangeListener () {
71
65
@ Override
72
66
public void onViewAttachedToWindow (View v ) {
@@ -76,80 +70,29 @@ public void onViewAttachedToWindow(View v) {
76
70
getTheme ().resolveAttribute (android .R .attr .colorPrimary , outValue , true );
77
71
revealView .setBackgroundColor (outValue .data );
78
72
79
- hideRevealEffect (cx , cy );
73
+ Utils . hideRevealEffect (revealView , cx , cy , 1920 );
80
74
}
81
75
82
76
@ Override
83
77
public void onViewDetachedFromWindow (View v ) {}
84
78
});
85
79
}
86
-
87
80
}
88
81
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
- }
140
82
141
83
private void hideNavigationStatus () {
84
+
142
85
View decorView = getWindow ().getDecorView ();
143
86
144
87
int uiOptions = View .SYSTEM_UI_FLAG_HIDE_NAVIGATION ;
145
88
decorView .setSystemUiVisibility (uiOptions );
146
89
}
147
90
91
+
148
92
Animator .AnimatorListener revealAnimationListener = new Animator .AnimatorListener () {
149
- @ Override
150
- public void onAnimationStart (Animator animation ) {
151
93
152
- }
94
+ @ Override
95
+ public void onAnimationStart (Animator animation ) {}
153
96
154
97
@ Override
155
98
public void onAnimationEnd (Animator animation ) {
@@ -159,28 +102,22 @@ public void onAnimationEnd(Animator animation) {
159
102
startActivity (i );
160
103
overridePendingTransition (0 , 0 );
161
104
finish ();
162
-
163
105
}
164
106
165
107
@ Override
166
- public void onAnimationCancel (Animator animation ) {
167
-
168
- }
108
+ public void onAnimationCancel (Animator animation ) {}
169
109
170
110
@ Override
171
- public void onAnimationRepeat (Animator animation ) {
172
-
173
-
174
- }
111
+ public void onAnimationRepeat (Animator animation ) {}
175
112
};
176
113
177
114
178
115
public void view (View view ) {
116
+
179
117
int selectedTheme = 0 ;
180
118
int primaryColor = 0 ;
181
119
182
120
switch (view .getId ()) {
183
-
184
121
case R .id .circle1 :
185
122
selectedTheme = R .style .theme1 ;
186
123
primaryColor = getResources ().getColor (R .color .color_set_1_primary );
@@ -202,13 +139,32 @@ public void view(View view) {
202
139
break ;
203
140
}
204
141
142
+ int [] location = new int [2 ];
143
+ revealView .setBackgroundColor (primaryColor );
144
+ view .getLocationOnScreen (location );
205
145
206
- showRevealEffect (view , primaryColor );
146
+ int cx = (location [0 ] + (view .getWidth () / 2 ));
147
+ int cy = location [1 ] + (Utils .getStatusBarHeight (this ) / 2 );
207
148
208
149
SharedPreferences .Editor ed = sharedpreferences .edit ();
150
+ ed .putInt ("x" , cx );
151
+ ed .putInt ("y" , cy );
209
152
ed .putInt ("theme" , selectedTheme );
210
153
ed .apply ();
211
- //
212
- //
154
+
155
+ hideNavigationStatus ();
156
+ Utils .showRevealEFfect (revealView , cx , cy , revealAnimationListener );
213
157
}
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
+ };
214
170
}
0 commit comments