Created
February 19, 2019 14:04
-
-
Save Ferfalk/79c1774a6ce1b408dd06305f227d28e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.graphics.Point; | |
import android.os.Bundle; | |
import android.view.View; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.databinding.ViewDataBinding; | |
public abstract class RevealBaseActivity<T extends ViewDataBinding, V extends BaseViewModel> extends BaseActivity<T, V> { | |
public static final String EXTRA_REVEAL_CENTER = "EXTRA_REVEAL_CENTER"; | |
private static final int revealDuration = 350; | |
private static final int hideDuration = 250; | |
private Point revealCenter; | |
public static void startRevealWithOrigin(@NonNull Context context, @Nullable Bundle extras, @NonNull Class<? extends RevealBaseActivity> activityClass, @NonNull Point revealCenter) { | |
startBaseActivity(context, getExtras(extras, revealCenter), activityClass); | |
} | |
public static void startRevealWithOriginForResult(@NonNull Activity activity, @Nullable Bundle extras, @NonNull Class<? extends RevealBaseActivity> activityClass, int requestCode, @NonNull Point revealCenter) { | |
startBaseActivityForResult(activity, getExtras(extras, revealCenter), activityClass, requestCode); | |
} | |
@NonNull | |
private static Bundle getExtras(@Nullable Bundle extras, @NonNull Point revealCenter) { | |
Bundle originExtras = new Bundle(); | |
originExtras.putParcelable(EXTRA_REVEAL_CENTER, revealCenter); | |
if (extras != null) { | |
originExtras.putAll(extras); | |
} | |
return originExtras; | |
} | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
overridePendingTransition(0, 0); | |
super.onCreate(savedInstanceState); | |
getView().getRoot().setVisibility(View.INVISIBLE); | |
} | |
@Override | |
protected void startEnterAnimations() { | |
Intent intent = getIntent(); | |
if (intent.hasExtra(EXTRA_REVEAL_CENTER)) { | |
revealCenter = intent.getParcelableExtra(EXTRA_REVEAL_CENTER); | |
SimpleAnimationUtils.revealOrFadeIn(getView().getRoot(), revealDuration, revealCenter).start(); | |
return; | |
} | |
SimpleAnimationUtils.revealOrFadeIn(getView().getRoot(), revealDuration).start(); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
if (isFinishing()) { | |
overridePendingTransition(0, 0); | |
} | |
} | |
@Override | |
public void finish() { | |
SimpleAnimationListener listener = new SimpleAnimationListener() { | |
@Override | |
public boolean onAnimationEnd(@NonNull View view) { | |
RevealBaseActivity.super.finish(); | |
return false; | |
} | |
}; | |
if (revealCenter != null) { | |
SimpleAnimationUtils.hideOrFadeOut(getView().getRoot(), hideDuration, listener, revealCenter).start(); | |
return; | |
} | |
SimpleAnimationUtils.hideOrFadeOut(getView().getRoot(), hideDuration, listener).start(); | |
} | |
public void finishWithoutUnreveal() { | |
super.finish(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://gist.github.com/Ferfalk/1c9687be9f4fba3cf6ecc79b1871fdf5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment