Skip to content

Instantly share code, notes, and snippets.

@gabornovakp
gabornovakp / gist:675b45b0101779d1209ae72a62010438
Created February 7, 2017 14:18
Fragments on top of each other
<android.support.design.widget.CoordinatorLayout
android:id="@+id/activity_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--This will be the one we'll cover-->
<FrameLayout
android:id="@+id/list_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
@gabornovakp
gabornovakp / AlertDialogHelper.java
Created February 3, 2017 13:35
Basic AlertDialog animation
public class AlertDialogHelper {
public static void showMyDialog(final Context context) {
final AlertDialog dialog = new AlertDialog.Builder(context)
.setTitle("My dialog")
.setMessage("This is your dialog, where you explain why the user needs to press the \"yes\" here.")
.setNeutralButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//...
@gabornovakp
gabornovakp / AnimationUtils.java
Created January 5, 2017 19:17
Final version of AnimationUtils
public class AnimationUtils {
public interface AnimationFinishedListener {
void onAnimationFinished();
}
public static int getMediumDuration(Context context) {
int duration;
if (isAnimationEnabled()) {
duration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);
} else {
@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();
}
@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 / 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 / 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
//...
//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 / 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;