Skip to content

Instantly share code, notes, and snippets.

@loeschg
Last active August 29, 2015 14:08
Show Gist options
  • Save loeschg/4db9bd8a2b4055c064fc to your computer and use it in GitHub Desktop.
Save loeschg/4db9bd8a2b4055c064fc to your computer and use it in GitHub Desktop.
Android snippets

New View/Activity/Fragment animation

private void setupAnimation(View view) {
    if (view.getViewTreeObserver().isAlive()) {
        ViewTreeObserver observer = view.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (view.getViewTreeObserver().isAlive()) {

                    view.setY(view.getHeight());
                    view.animate().translationY(0).setDuration(1000).start();

                    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                        view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    } else {
                        view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                }
            }
        });
    }
}

Output test failures to the console instead of needing to navigate to the test report. Super helpful when running on Travis or similar CI system (outside of android block):

// Show full stack trace in the console
tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment