Skip to content

Instantly share code, notes, and snippets.

@tunjid
tunjid / NotifyingSwipeRefreshLayout.java
Created April 9, 2015 13:25
/** * A class that lets an activity know when the SwipeRefreshLayout has * been triggered, and when all finger's are off the device. */
package com.myfab5.mobile.myfab5.ui.helpers.customcomponents;
import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* A class that lets an activity know when the SwipeRefreshLayout has
@tunjid
tunjid / WordpressImport.Java
Created February 1, 2016 01:01
Embedding Github Gist using TextAngular
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.File;
import java.text.DateFormat;
package com.tunjid.demo.Util;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
@tunjid
tunjid / expand_fab.java
Last active October 16, 2018 19:03
Java snippet to extend a FAB
private void setExtended(boolean extended, boolean force) {
if (isAnimating || (extended && isExtended() && !force)) return;
ConstraintSet set = new ConstraintSet();
set.clone(container.getContext(), extended ? R.layout.fab_extended : R.layout.fab_collapsed);
TransitionManager.beginDelayedTransition(container, new AutoTransition()
.addListener(listener).setDuration(150));
if (extended) button.setText(currentText);
@tunjid
tunjid / FabIconAnimator.java
Created October 16, 2018 19:59
A simple utility class that creates an expandable Floating Action Button
package com.mainstreetcode.teammate.util;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.constraint.ConstraintLayout;
import android.support.constraint.ConstraintSet;
package com.mainstreetcode.teammate.util;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.view.View;
ViewPagerIndicatorAnimator indicatorAnimator = ViewPagerIndicatorAnimator.builder()
.setIndicatorWidth(indicatorSize)
.setIndicatorHeight(indicatorSize)
.setIndicatorPadding(indicatorPadding))
.setInActiveDrawable(R.drawable.ic_circle_24dp)
.setActiveDrawable(R.drawable.ic_doggo_24dp)
.setGuideLine(root.findViewById(R.id.guide))
.setContainer((ConstraintLayout) root)
.setViewPager(viewPager)
.build();
@FunctionalInterface
public interface IndicatorWatcher {
void onIndicatorMoved(ImageView indicator, int position, float fraction, float totalTranslation);
}
animator.addIndicatorWatcher((indicator, position, fraction, totalTranslation) -> {
double radians = Math.PI * fraction;
float sine = (float) -Math.sin(radians);
float cosine = (float) Math.cos(radians);
float maxScale = Math.max(Math.abs(cosine), 0.4F);
ImageView currentIndicator = animator.getIndicatorAt(position);
currentIndicator.setScaleX(maxScale);
currentIndicator.setScaleY(maxScale);
private class Animator extends DataSetObserver implements OnPageChangeListener, OnAdapterChangeListener, OnGlobalLayoutListener {
private float lastPositionOffset;
private Animator() {
PagerAdapter adapter = viewPager.getAdapter();
if (adapter != null) adapter.registerDataSetObserver(this);
viewPager.addOnPageChangeListener(this);
viewPager.addOnAdapterChangeListener(this);