mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-08-08 08:58:41 +00:00
Various animation improvements
This commit is contained in:
parent
fca080bb7f
commit
ff23a603cb
3 changed files with 37 additions and 10 deletions
|
@ -26,12 +26,12 @@ import com.afollestad.nocknock.api.ServerStatus;
|
||||||
public class AddSiteActivity extends AppCompatActivity implements View.OnClickListener {
|
public class AddSiteActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
private View rootLayout;
|
private View rootLayout;
|
||||||
private Toolbar toolbar;
|
|
||||||
|
|
||||||
private EditText inputName;
|
private EditText inputName;
|
||||||
private EditText inputUrl;
|
private EditText inputUrl;
|
||||||
private EditText inputInterval;
|
private EditText inputInterval;
|
||||||
private Spinner spinnerInterval;
|
private Spinner spinnerInterval;
|
||||||
|
private boolean isClosing;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
@ -44,7 +44,7 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
inputInterval = (EditText) findViewById(R.id.checkIntervalInput);
|
inputInterval = (EditText) findViewById(R.id.checkIntervalInput);
|
||||||
spinnerInterval = (Spinner) findViewById(R.id.checkIntervalSpinner);
|
spinnerInterval = (Spinner) findViewById(R.id.checkIntervalSpinner);
|
||||||
|
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
toolbar.setNavigationOnClickListener(view -> {
|
toolbar.setNavigationOnClickListener(view -> {
|
||||||
closeFromNavWithReveal();
|
closeFromNavWithReveal();
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,14 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
findViewById(R.id.doneBtn).setOnClickListener(this);
|
findViewById(R.id.doneBtn).setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
closeFromCenterWithReveal();
|
||||||
|
}
|
||||||
|
|
||||||
private void closeFromNavWithReveal() {
|
private void closeFromNavWithReveal() {
|
||||||
|
if (isClosing) return;
|
||||||
|
isClosing = true;
|
||||||
final int offset = (int) getResources().getDimension(R.dimen.content_inset);
|
final int offset = (int) getResources().getDimension(R.dimen.content_inset);
|
||||||
final int cx = rootLayout.getMeasuredWidth();
|
final int cx = rootLayout.getMeasuredWidth();
|
||||||
final int cy = rootLayout.getMeasuredHeight();
|
final int cy = rootLayout.getMeasuredHeight();
|
||||||
|
@ -83,6 +90,30 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
super.onAnimationEnd(animation);
|
super.onAnimationEnd(animation);
|
||||||
|
rootLayout.setVisibility(View.INVISIBLE);
|
||||||
|
finish();
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
circularReveal.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeFromCenterWithReveal() {
|
||||||
|
if (isClosing) return;
|
||||||
|
isClosing = true;
|
||||||
|
final int cx = rootLayout.getMeasuredWidth() / 2;
|
||||||
|
final int cy = rootLayout.getMeasuredHeight() / 2;
|
||||||
|
float initialRadius = Math.max(cx, cy);
|
||||||
|
|
||||||
|
final Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, initialRadius, 0);
|
||||||
|
circularReveal.setDuration(300);
|
||||||
|
circularReveal.setInterpolator(new AccelerateInterpolator());
|
||||||
|
circularReveal.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
super.onAnimationEnd(animation);
|
||||||
|
rootLayout.setVisibility(View.INVISIBLE);
|
||||||
finish();
|
finish();
|
||||||
overridePendingTransition(0, 0);
|
overridePendingTransition(0, 0);
|
||||||
}
|
}
|
||||||
|
@ -94,23 +125,21 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
private void circularRevealActivity() {
|
private void circularRevealActivity() {
|
||||||
final int cx = rootLayout.getMeasuredWidth() / 2;
|
final int cx = rootLayout.getMeasuredWidth() / 2;
|
||||||
final int cy = rootLayout.getMeasuredHeight() / 2;
|
final int cy = rootLayout.getMeasuredHeight() / 2;
|
||||||
final int animDuration = 300;
|
|
||||||
final float finalRadius = Math.max(cx, cy);
|
final float finalRadius = Math.max(cx, cy);
|
||||||
final Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, 0, finalRadius);
|
final Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, 0, finalRadius);
|
||||||
|
|
||||||
circularReveal.setDuration(animDuration);
|
circularReveal.setDuration(300);
|
||||||
circularReveal.setInterpolator(new DecelerateInterpolator());
|
circularReveal.setInterpolator(new DecelerateInterpolator());
|
||||||
|
|
||||||
toolbar.setAlpha(0f);
|
|
||||||
rootLayout.setVisibility(View.VISIBLE);
|
rootLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
toolbar.animate().alpha(1f).setDuration(animDuration).start();
|
|
||||||
circularReveal.start();
|
circularReveal.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done button
|
// Done button
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
isClosing = true;
|
||||||
|
|
||||||
ServerModel model = new ServerModel();
|
ServerModel model = new ServerModel();
|
||||||
model.name = inputName.getText().toString().trim();
|
model.name = inputName.getText().toString().trim();
|
||||||
model.url = inputUrl.getText().toString().trim();
|
model.url = inputUrl.getText().toString().trim();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
android:fillAfter="true">
|
android:fillAfter="true">
|
||||||
|
|
||||||
<alpha
|
<alpha
|
||||||
android:duration="1000"
|
android:duration="400"
|
||||||
android:fromAlpha="1.0"
|
android:fromAlpha="1.0"
|
||||||
android:interpolator="@android:anim/accelerate_interpolator"
|
android:interpolator="@android:anim/accelerate_interpolator"
|
||||||
android:toAlpha="0.0" />
|
android:toAlpha="0.0" />
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?colorPrimary"
|
|
||||||
android:elevation="@dimen/fab_elevation"
|
|
||||||
app:navigationIcon="@drawable/ic_action_close"
|
app:navigationIcon="@drawable/ic_action_close"
|
||||||
app:title="@string/add_site"
|
app:title="@string/add_site"
|
||||||
app:titleTextColor="?android:textColorPrimary" />
|
app:titleTextColor="?android:textColorPrimary" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue