Skip to content

Instantly share code, notes, and snippets.

View xalexchen's full-sized avatar
🤖

Alex.Chen xalexchen

🤖
View GitHub Profile
@xalexchen
xalexchen / LayoutTransChanging.java
Created September 17, 2013 03:44
This example shows how to use LayoutTransition to animate simple changes in a layout
import android.animation.LayoutTransition;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
@xalexchen
xalexchen / KeyframeAnimation.java
Created September 17, 2013 05:44
This example shows how to use AnimationDrawable to construct a keyframe animation where each frame is shown for a specified duration.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
@xalexchen
xalexchen / new_gist_file
Created September 22, 2013 08:59
python Chinese character
.decode('unicode_escape').encode('iso8859-1').decode('utf8')
@xalexchen
xalexchen / BitmapAllocation.java
Created September 28, 2013 02:09
This example shows how to speed up bitmap loading and reduce garbage collection by reusing existing bitmaps.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
/**
@xalexchen
xalexchen / LiveButton.java
Created September 28, 2013 02:14
This app shows a simple application of anticipation and follow-through techniques as the button animates into its pressed state and animates back out of it, overshooting end state before resolving.
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.Button;
/**
* This app shows a simple application of anticipation and follow-through techniques as
@xalexchen
xalexchen / sync.py
Created October 18, 2013 08:15
This is a small python script to help you synchronize two folders
#coding=utf-8
# This is a small python script to help you synchronize two folders
# Compatible with Python 2.x and Python 3.x
import filecmp, shutil, os, sys
SRC = r'C:/a'
DEST = r'C:/b'
IGNORE = ['Thumbs.db']
@xalexchen
xalexchen / external.java
Created November 13, 2013 06:04
Checks if external storage is available for read and write
/* Checks if external storage is available for read and write */public boolean isExternalStorageWritable() {    String state = Environment.getExternalStorageState();    if (Environment.MEDIA_MOUNTED.equals(state)) {        return true;    }    return false;}/* Checks if external storage is available to at least read */public boolean isExternalStorageReadable() {    String state = Environment.getExternalStorageState();    if (Environment.MEDIA_MOUNTED.equals(state) ||        Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {        return true;    }    return false;}
private View mContentView;
private View mLoadingView;
private int mShortAnimationDuration;
...
private void crossfade() {
// Set the content view to 0% opacity but visible, so that it is visible
// (but fully transparent) during the animation.
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);