Skip to content

Instantly share code, notes, and snippets.

View xalexchen's full-sized avatar
🤖

Alex.Chen xalexchen

🤖
View GitHub Profile
@xalexchen
xalexchen / changelocale
Created December 13, 2012 06:32
when we want to change android system default language on our own application,we can use java reflection mechanism to invoke android non public methods
updateLanguage(Locale.SIMPLIFIED_CHINESE);
updateLanguage(Locale.ENGLISH);
..
..
..
..
private void updateLanguage(Locale locale) {
Log.d("ANDROID_LAB", locale.toString());
@xalexchen
xalexchen / SDUtil.java
Last active September 30, 2017 20:43
Android: Finding the SD Card Path “In devices with multiple ‘external’ storage directories (such as both secure app storage and mountable shared storage), this directory represents the ‘primary’ external storage that the user will interact with.” replace method Environment.getExternalStoreDirectory()
File file = new File("/system/etc/vold.fstab");
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
@xalexchen
xalexchen / preferences.xml
Created August 30, 2013 08:48
perform a action to start an activity on preference xml file
<PreferenceScreen
android:title="@string/system_info"
android:summary="@string/system_info_summary">
<intent android:action=".ui.SystemInfo" />
</PreferenceScreen>
@xalexchen
xalexchen / Util.java
Last active December 22, 2015 08:59
safety use implicit intent
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
@xalexchen
xalexchen / build.gradle
Created September 12, 2013 06:46
copy android so library into apk on android stuido
task nativeLibsToJar(
type: Zip,
description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
extension 'jar'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
@xalexchen
xalexchen / build.gradle
Last active December 22, 2015 21:29
rename final apk accoring to build time
String VERSION_NAME = "v0.0.1"
int VERSION_CODE = 1
String APK_NAME = "Hello"
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
@xalexchen
xalexchen / PictureViewer.java
Last active December 23, 2015 04:29
imageview cross-fade effect by using ViewPropertyAnimator
/**
* This example shows how to use ViewPropertyAnimator to get a cross-fade effect as new
* bitmaps get installed in an ImageView.
*
* Watch the associated video for this demo on the DevBytes channel of developer.android.com
* or on YouTube at https://www.youtube.com/watch?v=9XbKMUtVnJA.
*/
public class PictureViewer extends Activity {
int mCurrentDrawable = 0;
@xalexchen
xalexchen / VPADemo.java
Last active December 23, 2015 05:39
Android ViewPropertyAnimatior demo
public class VPADemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LinearLayout container = (LinearLayout) findViewById(R.id.container);
final Button fadeOut = (Button) findViewById(R.id.fadeOut);
final Button fadeIn = (Button) findViewById(R.id.fadeIn);
@xalexchen
xalexchen / ShadowLayout.java
Last active June 14, 2021 23:30
Android custom layout paints a drop shadow behind all children
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
@xalexchen
xalexchen / MultiPropertyAnimations.java
Last active December 23, 2015 05:49
This example shows various ways of animating android view multiple properties in parallel
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
/**
* This example shows various ways of animating multiple properties in parallel.