View DpToPxAndPxToDp
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);
View SmoothInterpolator
//as per cyrilmottier.com/2012/05/22/the-making-of-prixing-fly-in-app-menu-part-1/
public class SmoothInterpolator extends LinearInterpolator {
@Override
public float getInterpolation(float input) {
return (float) Math.pow(input - 1, 5) + 1;
}
}
View ExpandCollapse.java
public void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
View WebViewNonLeakMemory
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import android.webkit.WebView;
import android.webkit.WebViewClient;
View ParcelableSparseArray.java
package com.zala.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
/**
* https://gist.github.com/kaushikgopal/9eea148a2188dc58fe37
*/
public class ParcelableSparseArray<T>
View ApiManager.java
import retrofit.RestAdapter;
/**
* Singleton class for Retrofit RestAdapter and API (Retrofit 1.9.0)
*/
public class ApiManager {
// interface containing HTTP methods as given by Retrofit
private static RegionApi regionApi;
// static adapter to be used in entire app
View GetActionBarHeight
public int getActionBarHeight() {
int actionBarHeight = 0;
TypedValue tv = new TypedValue();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv,
true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(
tv.data, getResources().getDisplayMetrics());
} else {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
View pull.sh
#!/bin/sh
# first argument pass the package name of the app
#echo $1
# the phone must be rooted for this to work
# this will dump the files directly in the location where this script is run
# ./pull.sh com.yourpackagename
adb shell "su -c 'chmod -R +rwx /data/data/$1;cp -r /data/data/$1/files /sdcard/;exit;'"
adb pull /sdcard/files
View SingleTon.java
public class DbManager {
static volatile DbManager singleton = null;
private DbManager() {
}
public static DbManager getInstance() {
if (singleton == null) {
synchronized (DbManager.class) {
if (singleton == null)
singleton = new DbManager();
View CheckConnection.java
public static boolean isConnectedToInternet(Context context) {
if (isConnectingToInternet(context)) {
return isNetworkAvailable();
}
return false;
}
public static boolean isConnectingToInternet(Context context) {