Skip to content

Instantly share code, notes, and snippets.

@code4lifevn
code4lifevn / AppConfig.java
Created June 27, 2017 15:27
Thread-safe Singleton
public class AppConfig {
private static AppConfig INSTANCE = null;
private Context context;
private AppConfig(Context context) {
this.context = context;
}
public static AppConfig get(Context context) {
@code4lifevn
code4lifevn / 1) Install
Created December 14, 2015 15:26 — forked from nghuuphuoc/1) Install
Install Redis on Centos 6
// --- Compiling ---
$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz
$ tar xzvf redis-2.8.3.tar.gz
$ cd redis-2.8.3
$ make
$ make install
// --- or using yum ---
$ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
//
// !!WARNING: Not recommended for production code!!
//
public class ClassLoaderActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
// file.jar has a dex'd "classes.dex" entry that you can generate with "dx" from any number of JARs or class files
ClassLoader dexLoader = new DexClassLoader("/path/to/file.jar", getCacheDir().getAbsolutePath(), null, getClassLoader());
setAPKClassLoader(dexLoader);
@code4lifevn
code4lifevn / ApkBackup.java
Created August 22, 2014 03:42
Copy Apk File From Installed App
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
int z = 0;
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
File f1 = new File(info.activityInfo.applicationInfo.publicSourceDir);
Log.v("file--", " " + f1.getName().toString() + "----" + info.loadLabel(getPackageManager()));
import java.util.concurrent.atomic.AtomicInteger;
import android.annotation.SuppressLint;
import android.os.Build;
import android.view.View;
/**
* {@link View#generateViewId()}要求API Level >= 17,而本工具类可兼容所有API Level
* <p>
* 自动判断当前API Level,并优先调用{@link View#generateViewId()},即使本工具类与{@link View#generateViewId()}
@code4lifevn
code4lifevn / BitmapUtils.java
Created July 2, 2014 03:39
Image Util Classes
import android.graphics.Bitmap;
import android.graphics.Matrix;
/**
* Various bitmap utilities
*
* @author alessandro
*
*/
public class BitmapUtils {
@code4lifevn
code4lifevn / ColorUtils.java
Last active August 29, 2015 14:03
ColorUtils.java
public static String makeColorWithAlpha(String originalColor, double alpha) {
long alphaFixed = Math.round(alpha * 255);
String alphaHex = Long.toHexString(alphaFixed);
if (alphaHex.length() == 1) {
alphaHex = "0" + alphaHex;
}
originalColor = originalColor.replace("#", "#" + alphaHex);
return originalColor;
@code4lifevn
code4lifevn / AndroidManifest.xml
Last active August 29, 2015 14:03
Cấu hình file AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{package_name}" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@code4lifevn
code4lifevn / BaseItemAdapter.java
Last active August 29, 2015 14:02
BaseItemAdapter
package com.appplus.apptrain.adapters;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;