Skip to content

Instantly share code, notes, and snippets.

View feromakovi's full-sized avatar

Richard Samela feromakovi

View GitHub Profile
@feromakovi
feromakovi / FocusWatcher
Created October 12, 2016 14:22
Watcher class used to handle and observe focus changes of selected views. If none of these views has focus, defined fallback view will try to acquire focus. Helpful when code app for device with keyboard/arrows navigation.
/**
* Created by feromakovi <feromakovi@gmail.com> on 12/10/16.
*/
@UiThread
public final class FocusWatcher implements View.OnFocusChangeListener {
private final List<WeakReference<View>> mWatchedViews = new ArrayList<>();
private WeakReference<View> mFallBackView;
public class FilterPageTransformer implements ViewPager.PageTransformer {
public void transformPage(View view, float position) {
ImageView im = (ImageView) view;
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
im.setPadding(pageWidth, 0, 0, 0);