Skip to content

Instantly share code, notes, and snippets.

@gabornovakp
gabornovakp / AnimationUtils.java
Last active December 12, 2019 06:47
Circular reveal animation
public class AnimationUtils {
public static void registerCircularRevealAnimation(final Context context, final View view, final RevealAnimationSetting revealSettings, final int startColor, final int endColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
int cx = revealSettings.getCenterX();
int cy = revealSettings.getCenterY();
public class DetailFragment extends Fragment {
//...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//..
AnimationUtils.registerCircularRevealAnimation(getContext(), view, (RevealAnimationSetting) getArguments().getParcelable(ARG_REVEAL_SETTINGS), getColor(R.color.prezi_blue), getColor(R.color.white));
//...
}
}
@gabornovakp
gabornovakp / SwipeableRecycleView.java
Last active January 21, 2017 17:50
Swipe gestures in a RecycleView
public class SwipeableRecycleView extends RecyclerView {
interface OnSwipeActionListener {
@Retention(RetentionPolicy.SOURCE)
@IntDef({LEFT, RIGHT})
@interface SwipeDirection {}
int LEFT = 0;
int RIGHT = 1;
void onSwipe(int position, @SwipeDirection int direction);
@gabornovakp
gabornovakp / ViewHolder.java
Created December 29, 2016 15:41
ViewHolder for swipe gesture
static class ViewHolder extends RecyclerView.ViewHolder {
private Interpolator interpolator = new DecelerateInterpolator(2f);
private TextView nameTextView;
private View leftImage;
private View rightImage;
private View view;
public ViewHolder(View view) {
super(view);
this.view = view;
//...
//Won't show the events fully, only "peek" into it
final float maxX = getResources().getDimensionPixelSize(R.dimen.share_link_swipe_action_size) * 0.75f;
final ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setInterpolator(new CycleInterpolator(1));
animator.setDuration(1000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = animation.getAnimatedFraction() * maxX;
@gabornovakp
gabornovakp / RevocableShareLinkInfoDiffUtilCallback.java
Created December 29, 2016 16:06
RevocableShareLink DiffUtilCallback
public class RevocableShareLinkInfoDiffUtilCallback extends DiffUtil.Callback {
List<RevocableShareLinkInfo> oldList;
List<RevocableShareLinkInfo> newList;
RevocableShareLinkInfoDiffUtilCallback(List<RevocableShareLinkInfo> newList, List<RevocableShareLinkInfo> oldList) {
this.newList = newList;
this.oldList = oldList;
}
@Override
@gabornovakp
gabornovakp / ShareLinkListAdapter.java
Created December 29, 2016 16:09
DiffUtils in Adapter
public class ShareLinkListAdapter extends RecyclerView.Adapter<ShareLinkListAdapter.ViewHolder> {
//...
private List<RevocableShareLinkInfo> list = new ArrayList<>();
//...
public void setList(List<RevocableShareLinkInfo> newList) {
List<RevocableShareLinkInfo> oldList = this.list;
this.list = newList;
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new RevocableShareLinkInfoDiffUtilCallback(newList, oldList), true);
diffResult.dispatchUpdatesTo(this);
@gabornovakp
gabornovakp / AnimationUtils.java
Last active January 5, 2017 13:52
Circular exit animation
public class AnimationUtils {
//...
public static void startCircularExitAnimation(final Context context, final View view, final RevealAnimationSetting revealSettings, final int startColor, final int endColor, final Dismissible.OnDismissedListener listener) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int cx = revealSettings.getCenterX();
int cy = revealSettings.getCenterY();
int width = revealSettings.getWidth();
int height = revealSettings.getHeight();
int duration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);
@gabornovakp
gabornovakp / DetailFragment.java
Last active January 13, 2017 19:17
DetailFragment dismiss
public class DetailFragment extends Fragment implements Dismissible, ... {
public static final String ARG_REVEAL_SETTINGS = "ARG_REVEAL_SETTINGS";
//...
@Override
public void dismiss(OnDismissedListener listener) {
AnimationUtils.startCircularRevealExitAnimation(getContext(), getView(), (RevealAnimationSetting) getArguments().getParcelable(ARG_REVEAL_SETTINGS), getColor(R.color.white), getColor(R.color.prezi_blue), new AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
listener.onDismissed();
}