Skip to content

Instantly share code, notes, and snippets.

@easternHong
easternHong / AndroidFullScreen.java
Created January 18, 2015 14:10
Android Setting Full Screen
if (Build.VERSION.SDK_INT >= 18) {
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled =
((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.i(TAG, "Turning immersive mode mode off. ");
@easternHong
easternHong / Encryption.java
Created January 13, 2015 10:31
java中常用的加密算法使用
package com.hunt.utils;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@easternHong
easternHong / SDCardUtils.java
Last active August 29, 2015 14:13
Android External Internal path获取
package com.cylan.efamily.utils;
import android.annotation.SuppressLint;
import android.os.Environment;
import android.os.StatFs;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@easternHong
easternHong / ImageProcessing.java
Created December 29, 2014 10:23
YUV420_to_RGB;decodeYUV420SPtoLuma;rgbToBitmap;lumaToGreyscale;
package com.jwetherell.motion_detection.image;
import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
/**
@easternHong
easternHong / test.java
Created November 19, 2014 13:06
startActivitySafely
void startActivitySafely(Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.activity_not_found,
Toast.LENGTH_SHORT).show();
} catch (SecurityException e) {
Toast.makeText(this, R.string.activity_not_found,
Toast.LENGTH_SHORT).show();
@easternHong
easternHong / SqliteUtils.java
Created October 22, 2014 13:32
SQLiteUtils_singleton_Pattern
public class SqliteUtils {
private static volatile SqliteUtils instance;
private DbHelper dbHelper;
private SQLiteDatabase db;
private SqliteUtils(Context context) {
dbHelper = new DbHelper(context);
db = dbHelper.getWritableDatabase();
@easternHong
easternHong / test.java
Created October 21, 2014 11:15
使用IMAGE_CACHE,大幅度提升ListView GridView性能
package com.hunt.listviewdemo;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.LayoutInflater;
@easternHong
easternHong / test.java
Created October 16, 2014 15:56
update_listview_item
public void updateItemView(final int index, Object o) {
int visibleposition = mlist.getFirstVisiblePosition();
View view = mlist.getChildAt(index - visibleposition);
TextView tView = (TextView) view.findViewById(R.id.item_define_word);
tView.setText((String) o);
}
@easternHong
easternHong / test.java
Created October 16, 2014 12:22
get_package_info
@Override
protected List<AppInfo> doInBackground(Void... params) {
// TODO Auto-generated method stub
List<AppInfo> list = new ArrayList<AppInfo>();
// 获取系统所有的应用
List<PackageInfo> appList = mContext.getPackageManager()
.getInstalledPackages(PackageManager.GET_META_DATA);
// 获取应用主activity
for (PackageInfo p : appList) {
// user app
@easternHong
easternHong / LRU_test.java
Created October 14, 2014 14:57
LRU——使用
private final BitmapCache mMemoryCache;
//一般在构造函数实现
mMemoryCache = new BitmapCache();
private Bitmap getBitmapFromMemCache(final int key) {
return mMemoryCache.get(key);
}
private void addBitmapToMemoryCache(final int key, final Bitmap bitmap) {