Skip to content

Instantly share code, notes, and snippets.

@evant
evant / ViewPagerRemoveHardwareLayer.java
Created June 25, 2015 18:00
Disable ViewPager hardware layer if you are animating the items within while paging
public class ViewPagerRemoveHardwareLayer implements ViewPager.OnPageChangeListener {
private ViewPager mPager;
public ViewPagerRemoveHardwareLayer(ViewPager pager) {
mPager = pager;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@evant
evant / SnapTopLinearLayoutManager.java
Created July 16, 2015 19:33
Force item to top instead of just on screen when smooth scrolling with RecyclerView
public class SnapTopLinearLayoutManager extends LinearLayoutManager {
public SnapTopLinearLayoutManager(Context context) {
super(context);
}
public SnapTopLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
/**
* Abuse loaders to retain some state across rotations for a Fragment or Activity.
*/
public class RetainStateManager {
@evant
evant / AppBackgroundChecker.java
Created September 3, 2015 14:04
Check when app is in forground/background (api 14+)
public class AppBackgroundChecker implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 {
private boolean isBackground;
public void register(Application application) {
application.registerActivityLifecycleCallbacks(this);
application.registerComponentCallbacks(this);
}
@Override

Suggestions for the new Transform Api

Possibly the biggest issue I see with the current api is that it is very hard to extend it in the future without breaking current implementations. For example, I asked to be provided the LoggingManager for the task so I can redirect stdout output inside the transform. This cannot be done without changing the api. I have a couple suggestions to fix this issue, it would be better to do it now while it's still in beta.

  1. Provide the gradle task that performs the transform to the transform method.
public static void hideKeyboard(Activity context) {
View currentFocus = context.getCurrentFocus();
if (currentFocus != null) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}
}
@evant
evant / README.md
Created November 29, 2016 21:04
RxDiffUtil

Usage

Given a stream of collection of items to show, provide a diff callback which determines the size and differences in that collection.

Observable<List<String>> observable1 ...;
observable1.compose(RxDiffUtil.diff(new RxDiffUtil.Callback<List<String>>() {
    @Override
    public int getSize(List<String> list) {
        return list.size();
 }
@evant
evant / EvictableSingleCache.java
Last active May 14, 2017 17:03
A single cache that allows evicting the value or error. Subscriptions after the value is evicted will re-trigger the upstream observer.
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See

Keybase proof

I hereby claim:

  • I am evant on github.
  • I am evant (https://keybase.io/evant) on keybase.
  • I have a public key ASCeFjmQU8VV-Elouees8rKTCkk8tO7qjDFQBzL1J3umqgo

To claim this, I am signing this object:

// cue export --out text fizzbuzz.cue
import "strings"
_numbers: [1,2,3,4,5,6,7,8,9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,