Skip to content

Instantly share code, notes, and snippets.

@boxme
boxme / gist:659843a26e90ab76629128668bd8b97c
Created April 18, 2016 10:11 — forked from ixiyang/gist:7922825
difference between requestLayout() and forceLayout()
比喻很形象
Please note that the methods in Listing 1-10 are internal methods and are not part of the
public API, so they may change with newer releases. However, the underlying protocol would remain
the same.
In Listing 1-10, it is easier to first tell what forceLayout( ) is. It is like a touch command in build
environments. Usually when a file hasn’t changed, the build dependencies will ignore it. So, you
force that file to be compiled by “touch”ing, and thereby updating its time stamp. Just like touch,
the forceLayout( ) will not invoke any build commands by itself (unless your build environment is too
@boxme
boxme / Android Studio .gitignore
Created May 9, 2015 05:17
Android Studio Project .gitignore gist
*.iml
# generated files
bin/
gen/
# Ignore gradle files
.gradle
build/
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21.
To use the support version of these attributes, remove the android namespace.
For instance, "android:colorControlNormal" becomes "colorControlNormal".
These attributes will be propagated to their corresponding attributes within the android namespace
for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
@boxme
boxme / BaseFragment
Created March 24, 2015 02:48
BaseFragment that all Fragments should extend from in order to save state in all circumstances using argument
public abstract class BaseFragment extends Fragment {
static final String STATE = "saved_state";
Bundle mSavedState;
public BaseFragment() {}
public abstract void refreshData();
protected void showSoftKeyboard(View editText) {
@boxme
boxme / blurringTheBitmap
Created March 24, 2015 02:40
Blurring an image using Renderscript
public static Bitmap blendRenderScript(RenderScript rs, Bitmap originalBitmap) {
// Creates a matching Renderscript allocation object and
// copies the contents of the bitmap into the allocation
Allocation input = Allocation.createFromBitmap(rs, originalBitmap,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
// Generates an Allocation identical in structure to the first
Allocation output = Allocation.createTyped(rs, input.getType());
@boxme
boxme / CursorPagerAdapter
Created March 24, 2015 02:35
PagerAdapter that uses uses Cursor as its data format
public abstract class CursorPagerAdapter extends PagerAdapter {
public static final String TAG = CursorPagerAdapter.class.getSimpleName();
protected WeakReference<Context> ctxRef;
protected boolean mDataValid;
protected boolean mAutoRequery;
protected Cursor mCursor;
protected int mRowIDColumn;
@boxme
boxme / AbstractCursorRecyclerAdapter
Created March 24, 2015 02:32
CursorRecyclerView
public abstract class AbstractCursorRecyclerAdapter<VH extends RecyclerView.ViewHolder>
extends RecyclerView.Adapter<VH> {
protected Context mContext;
protected Cursor mCursor;
protected boolean mDataValid;
protected int mRowIDColumn;
protected ChangeObserver mChangeObserver;
@boxme
boxme / Simple Hide & Reveal Animation
Created March 12, 2015 02:48
Switching between views with reveal and hide animations
private void setupView() {
mViewStateIndicator.setImageResource(mIsRevealed
? R.drawable.revealed
: R.drawable.not_revealed);
int hideTranslateY = -mToBeRevealedViewContainer.getHeight() / 4; // last 25% of animation
if (mIsRevealed && mToBeRevealedViewContainer.getTranslationY() == 0) {
// initial setup
mToBeRevealedViewContainer.setAlpha(0);
mToBeRevealedViewContainer.setTranslationY(hideTranslateY);
}