Skip to content

Commit a574fe5

Browse files
committed
Reached reveal effect as transition of an activity
1 parent 53c60e0 commit a574fe5

File tree

7 files changed

+119
-29
lines changed

7 files changed

+119
-29
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<activity
1111
android:name=".activities.TransitionFirstActivity"
1212
android:label="" >
13+
14+
15+
1316
</activity>
1417
<activity
1518
android:name=".activities.TransitionSecondActivity"
@@ -28,7 +31,6 @@
2831

2932
<intent-filter>
3033
<action android:name="android.intent.action.MAIN" />
31-
3234
<category android:name="android.intent.category.LAUNCHER" />
3335
</intent-filter>
3436

app/src/main/java/com/saulmm/material/Utils.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.saulmm.material;
22

3+
import android.content.Context;
34
import android.graphics.Outline;
45
import android.transition.Explode;
6+
import android.transition.Fade;
57
import android.transition.Slide;
68
import android.view.View;
79
import android.view.Window;
810
import android.view.animation.PathInterpolator;
911

1012
public class Utils {
1113

12-
public static void configureWindowEnterExitTransition (Window w) {
14+
public static void configureWindowEnterExitExplodeTransition(Window w) {
1315

14-
Explode ex = new Explode();
16+
Fade ex = new Fade();
1517
ex.setInterpolator(new PathInterpolator(0.4f, 0, 1, 1));
18+
ex.setDuration(5000);
1619
w.setExitTransition(ex);
1720
w.setEnterTransition(ex);
1821
}
@@ -25,4 +28,14 @@ public static void configureFab (View fabButton) {
2528
Outline fabOutLine = new Outline();
2629
fabOutLine.setOval(0, 0, fabSize, fabSize);
2730
}
31+
32+
public static int getStatusBarHeight(Context c) {
33+
34+
int result = 0;
35+
int resourceId = c.getResources().getIdentifier("status_bar_height", "dimen", "android");
36+
if (resourceId > 0) {
37+
result = c.getResources().getDimensionPixelSize(resourceId);
38+
}
39+
return result;
40+
}
2841
}

app/src/main/java/com/saulmm/material/activities/ColorActivity.java

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,148 @@
11
package com.saulmm.material.activities;
22

33
import android.animation.Animator;
4+
import android.animation.AnimatorListenerAdapter;
45
import android.app.Activity;
6+
import android.app.ActivityOptions;
57
import android.content.Context;
68
import android.content.Intent;
79
import android.content.SharedPreferences;
810
import android.os.Bundle;
11+
import android.transition.Slide;
12+
import android.transition.Transition;
913
import android.util.DisplayMetrics;
1014
import android.util.Log;
15+
import android.util.Pair;
16+
import android.util.TypedValue;
1117
import android.view.View;
1218
import android.view.ViewAnimationUtils;
1319
import android.widget.CompoundButton;
1420
import android.widget.Switch;
1521

1622
import com.saulmm.material.R;
23+
import com.saulmm.material.Utils;
1724

1825
public class ColorActivity extends Activity {
1926

2027
private SharedPreferences sharedpreferences;
2128
private View revealView;
2229
private View circleHolder;
30+
private View fabButton;
2331

2432
@Override
2533
protected void onCreate(final Bundle savedInstanceState) {
34+
35+
super.onCreate(savedInstanceState);
36+
37+
// Set the saved theme
2638
sharedpreferences = getSharedPreferences("test", Context.MODE_PRIVATE);
39+
// sharedpreferences.edit().clear().apply();
2740
setTheme(sharedpreferences.getInt("theme", R.style.AppTheme));
2841

2942
setContentView(R.layout.activity_color);
3043

44+
// Views
3145
Switch themeSwitch = (Switch) findViewById(R.id.theme_switch);
3246
themeSwitch.setChecked(sharedpreferences.getBoolean("switch", false));
3347
revealView = findViewById(R.id.reveal_view);
34-
48+
fabButton = findViewById(R.id.fab_button);
3549
circleHolder = findViewById(R.id.circle_holder);
3650

3751
themeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
3852
@Override
3953
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
4054

55+
// Save the state of the switch
4156
SharedPreferences.Editor ed = sharedpreferences.edit();
4257
ed.putInt("theme", (isChecked) ? R.style.Base_Theme_AppCompat : R.style.Base_Theme_AppCompat_Light);
43-
4458
ed.putBoolean("switch", isChecked);
4559
ed.apply();
4660
}
4761
});
4862

63+
// Show the unreveal effect
64+
final int cx = sharedpreferences.getInt("x", 0);
65+
final int cy = sharedpreferences.getInt("y", 0);
4966

50-
super.onCreate(savedInstanceState);
67+
if (cx != 0 && cy != 0) {
68+
69+
// Show the unreveal effect when the view is attached to the window
70+
revealView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
71+
@Override
72+
public void onViewAttachedToWindow(View v) {
73+
74+
// Get the accent color
75+
TypedValue outValue = new TypedValue();
76+
getTheme().resolveAttribute(android.R.attr.colorPrimary, outValue, true);
77+
revealView.setBackgroundColor(outValue.data);
78+
79+
hideRevealEffect(cx, cy);
80+
}
81+
82+
@Override
83+
public void onViewDetachedFromWindow(View v) {}
84+
});
85+
}
5186

5287
}
5388

5489
public void showRevealEffect(View v, int primaryColor) {
5590
revealView.setVisibility(View.VISIBLE);
5691

57-
5892
int [] location = new int[2];
5993
revealView.setBackgroundColor(primaryColor);
6094
v.getLocationOnScreen(location);
6195

6296
int cx = (location[0] + (v.getWidth() / 2));
63-
int cy = location[1];
97+
int cy = location[1] + (Utils.getStatusBarHeight(this) / 2);
6498

65-
int height = revealView.getHeight();
6699

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();
67106

68107
Animator anim = ViewAnimationUtils.createCircularReveal(
69108
revealView, cx, cy, 0, height);
70109

71110

72111
anim.addListener(revealAnimationListener);
73112
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+
141+
private void hideNavigationStatus() {
142+
View decorView = getWindow().getDecorView();
143+
144+
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
145+
decorView.setSystemUiVisibility(uiOptions);
74146
}
75147

76148
Animator.AnimatorListener revealAnimationListener = new Animator.AnimatorListener() {
@@ -81,7 +153,6 @@ public void onAnimationStart(Animator animation) {
81153

82154
@Override
83155
public void onAnimationEnd(Animator animation) {
84-
revealView.setVisibility(View.INVISIBLE);
85156

86157
Intent i = new Intent(ColorActivity.this, ColorActivity.class);
87158
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
@@ -99,6 +170,7 @@ public void onAnimationCancel(Animator animation) {
99170
@Override
100171
public void onAnimationRepeat(Animator animation) {
101172

173+
102174
}
103175
};
104176

app/src/main/java/com/saulmm/material/activities/TransitionFirstActivity.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.app.ActivityOptions;
55
import android.content.Intent;
66
import android.os.Bundle;
7-
import android.transition.Scene;
87
import android.util.Pair;
98
import android.view.View;
109

@@ -22,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
2221
setContentView(R.layout.activity_transition_first);
2322

2423
// Set explode animation when enter and exit the activity
25-
Utils.configureWindowEnterExitTransition(getWindow());
24+
Utils.configureWindowEnterExitExplodeTransition(getWindow());
2625

2726
// Fab Button
2827
fabButton = findViewById(R.id.fab_button);
@@ -40,8 +39,6 @@ public void onClick(View view) {
4039
ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(TransitionFirstActivity.this,
4140
Pair.create(fabButton, "fab"));
4241

43-
44-
4542
startActivity(i, transitionActivityOptions.toBundle());
4643
}
4744
};

app/src/main/java/com/saulmm/material/activities/TransitionSecondActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {
2525

2626
rowContainer = (LinearLayout) findViewById(R.id.row_container2);
2727

28-
Utils.configureWindowEnterExitTransition(getWindow());
28+
Utils.configureWindowEnterExitExplodeTransition(getWindow());
2929

3030
getWindow().getEnterTransition().addListener(new Transition.TransitionListener() {
3131
@Override

app/src/main/res/layout/activity_color.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,21 @@
134134

135135

136136
</LinearLayout>
137-
138-
139-
140-
141-
142137
</LinearLayout>
143138

139+
<Button
140+
xmlns:android="http://schemas.android.com/apk/res/android"
141+
android:id="@+id/fab_button"
142+
android:transitionName="fab"
143+
android:layout_width="@dimen/fab_size"
144+
android:layout_height="@dimen/fab_size"
145+
android:layout_marginRight="@dimen/activity_horizontal_margin"
146+
android:background="@drawable/ripple_round"
147+
android:stateListAnimator="@anim/fab_anim"
148+
android:elevation="4dp"
149+
android:layout_below="@+id/holder_view"
150+
android:layout_marginTop="-26dp"
151+
android:layout_alignParentEnd="true"
152+
/>
153+
144154
</RelativeLayout>

app/src/main/res/values-v21/styles.xml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,44 @@
77
<!-- android theme colors -->
88
<item name="android:colorPrimary">@color/theme_default_primary</item>
99
<item name="android:colorPrimaryDark">@color/theme_default_primary_dark</item>
10-
<item name="android:statusBarColor">@color/theme_default_primary_dark</item>
10+
<item name="android:windowTranslucentStatus">true</item>
11+
<item name="android:windowTranslucentNavigation">true</item>
1112
<item name="android:colorControlActivated">@color/accent</item>
1213
<item name="android:colorAccent">@color/accent</item>
1314

1415
<!-- android transitions -->
1516
<item name="android:windowContentTransitions">true</item>
17+
<item name="android:windowAllowEnterTransitionOverlap">true</item>
18+
<item name="android:windowAllowReturnTransitionOverlap">true</item>
19+
1620
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
1721
</style>
1822

1923

2024
<style name="theme1" parent="AppTheme">
2125
<item name="android:colorPrimary">@color/color_set_1_primary</item>
2226
<item name="android:colorPrimaryDark">@color/color_set_1_primary_dark</item>
23-
<item name="android:statusBarColor">@color/color_set_1_primary_dark</item>
24-
<item name="android:navigationBarColor">@color/color_set_1_primary</item>
2527
<item name="android:colorControlActivated">@color/color_set_1_accent</item>
2628
<item name="android:colorAccent">@color/color_set_1_accent</item>
2729
</style>
2830

2931
<style name="theme2" parent="AppTheme">
3032
<item name="android:colorPrimary">@color/color_set_2_primary</item>
3133
<item name="android:colorPrimaryDark">@color/color_set_2_primary_dark</item>
32-
<item name="android:statusBarColor">@color/color_set_2_primary_dark</item>
33-
<item name="android:navigationBarColor">@color/color_set_2_primary</item>
3434
<item name="android:colorControlActivated">@color/color_set_2_accent</item>
3535
<item name="android:colorAccent">@color/color_set_2_accent</item>
3636
</style>
3737

3838
<style name="theme3" parent="AppTheme">
3939
<item name="android:colorPrimary">@color/color_set_3_primary</item>
4040
<item name="android:colorPrimaryDark">@color/color_set_3_primary_dark</item>
41-
<item name="android:statusBarColor">@color/color_set_3_primary_dark</item>
42-
<item name="android:navigationBarColor">@color/color_set_3_primary</item>
4341
<item name="android:colorControlActivated">@color/color_set_3_accent</item>
4442
<item name="android:colorAccent">@color/color_set_3_accent</item>
4543
</style>
4644

4745
<style name="theme4" parent="AppTheme">
4846
<item name="android:colorPrimary">@color/color_set_4_primary</item>
4947
<item name="android:colorPrimaryDark">@color/color_set_4_primary_dark</item>
50-
<item name="android:statusBarColor">@color/color_set_4_primary_dark</item>
51-
<item name="android:navigationBarColor">@color/color_set_4_primary</item>
5248
<item name="android:colorControlActivated">@color/color_set_4_accent</item>
5349
<item name="android:colorAccent">@color/color_set_4_accent</item>
5450
</style>

0 commit comments

Comments
 (0)