Skip to content

Instantly share code, notes, and snippets.

View xalexchen's full-sized avatar
🤖

Alex.Chen xalexchen

🤖
View GitHub Profile
@xalexchen
xalexchen / PhotoDownloadRunnable.java
Created March 13, 2014 07:26
Download image file into byte array
/*
* Copyright (C) ${year} The Android Open Source Project
*
* 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
@xalexchen
xalexchen / Constants.java
Created March 13, 2014 07:25
USER_AGENT
/*
* A user-agent string that's sent to the HTTP site. It includes information about the device
* and the build that the device is running.
*/
public static final String USER_AGENT = "Mozilla/5.0 (Linux; U; Android "
+ android.os.Build.VERSION.RELEASE + ";"
+ Locale.getDefault().toString() + "; " + android.os.Build.DEVICE
+ "/" + android.os.Build.ID + ")";
@xalexchen
xalexchen / DisplayActivity.java
Created March 12, 2014 02:26
Set full screen mode on the device
/**
* Sets full screen mode on the device, by setting parameters in the current
* window and View
* @param fullscreen
*/
public void setFullScreen(boolean fullscreen) {
// If full screen is set, sets the fullscreen flag in the Window manager
getWindow().setFlags(
fullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
private void flipCard() {
if (mShowingBack) {
getFragmentManager().popBackStack();
return;
}
// Flip to the back.
mShowingBack = true;
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);
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.
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.
@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;}
@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 / 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