Skip to content

Instantly share code, notes, and snippets.

@kimukou
Created June 15, 2012 03:47
Show Gist options
  • Save kimukou/2934580 to your computer and use it in GitHub Desktop.
Save kimukou/2934580 to your computer and use it in GitHub Desktop.
1.6 verification_error_pass
import java.io.File;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.SharedPreferences.Editor;
@SuppressLint("NewApi")
public class ActivityUtil {
public static void StrictMode11(){
android.os.StrictMode.setThreadPolicy(new android.os.StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.penaltyFlashScreen()
.build());
android.os.StrictMode.setVmPolicy(new android.os.StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
public static void StrictMode09(){
android.os.StrictMode.setThreadPolicy(new android.os.StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
android.os.StrictMode.setVmPolicy(new android.os.StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
public static Bitmap createThumbnail(String src){
return ThumbnailUtils.createVideoThumbnail(src, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
}
public static Bitmap extractThumbnail(Bitmap source,int w,int h){
return ThumbnailUtils.extractThumbnail(source, w, h);
}
public static void IgnoreStrictMode(){
android.os.StrictMode.setThreadPolicy(new android.os.StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
}
public static void overridePendingTransition(Activity activity){
activity.overridePendingTransition(0,0);
}
public static File getExternalFilesDir(Activity activity,String type){
return activity.getExternalFilesDir(type);
}
public static boolean traceTotalSpace(String tag,File dir){
boolean deleteF = true;
try {
long df = dir.getTotalSpace();
if(df > 0 && df /(1024.0 * 1024.0) < 3.0 ){
LogUtil.trace(tag, "(size,sep):" + df/(1024 * 1024) + ","+3);
deleteF = false;
}
} catch (Exception e) {}
return deleteF;
}
public static void apply(Editor e ){
e.apply();
}
public static void setLoadWithOverviewMode(WebView webView,boolean mode){
webView.getSettings().setLoadWithOverviewMode(mode);
}
public static void setScrollbarFadingEnabled(WebView webView,boolean mode){
webView.setScrollbarFadingEnabled(mode);
}
}
import android.view.MotionEvent;
import android.annotation.SuppressLint;
@SuppressLint("NewApi")
public class MouseUtil {
public static int getPointerCount(MotionEvent event){
return event.getPointerCount();
}
public static float getX(MotionEvent event,int p){
return event.getX(p);
}
public static float getY(MotionEvent event,int p){
return event.getY(p);
}
}
import java.util.UUID;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.preference.PreferenceManager;
public class PrefUtil {
private final static String TAG = "PrefUtil";
private static Activity activity = null;
public static void init(Activity activity_){
activity = activity_;
}
/**
* uuidを取得する
*/
public static String create_uuid() {
String s2 = get_string("uuid",null);
if(s2!=null)return s2;
UUID uuid = UUID.randomUUID();
s2= uuid.toString();
LogUtil.trace(TAG, "uuid gen " + s2);
put_string("uuid",s2);
return s2;
}
public static void put_string(String name,String value){
LogUtil.trace(TAG, String.format("put_%s %s",name,value));
//SharedPreferences pref = getPreferences(MODE_PRIVATE);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
Editor e = pref.edit();
e.putString(activity.getPackageName()+"."+name, value); //put
if(Build.VERSION.SDK_INT>=9)ActivityUtil.apply(e);
else e.commit();
}
public static String get_string(String name,String default_str){
//SharedPreferences pref =getPreferences(MODE_PRIVATE);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
String str = pref.getString(activity.getPackageName()+"."+name, default_str); //get
if(str==null){
LogUtil.trace(TAG, String.format("get_%s null",name));
} else {
LogUtil.trace(TAG, String.format("get_%s %s",name,str));
}
return str;
}
public static void put_int(String name,int value){
LogUtil.trace(TAG, String.format("put_%s %s",name,value));
//SharedPreferences pref = getPreferences(MODE_PRIVATE);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
Editor e = pref.edit();
e.putInt(activity.getPackageName()+"."+name, value); //put
if(Build.VERSION.SDK_INT>=9)ActivityUtil.apply(e);
else e.commit();
}
public static int get_int(String name,int default_int){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
//SharedPreferences pref =getPreferences(MODE_PRIVATE);
int value = pref.getInt(activity.getPackageName()+"."+name, default_int); //get
LogUtil.trace(TAG, String.format("get_%s %s",name,value));
return value;
}
public static void put_long(String name,long value){
LogUtil.trace(TAG, String.format("put_%s %s",name,value));
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
//SharedPreferences pref = getPreferences(MODE_PRIVATE);
Editor e = pref.edit();
e.putLong(activity.getPackageName()+"."+name, value); //put
if(Build.VERSION.SDK_INT>=9)ActivityUtil.apply(e);
else e.commit();
}
public static long get_long(String name,long default_int){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
//SharedPreferences pref =getPreferences(MODE_PRIVATE);
long value = pref.getLong(activity.getPackageName()+"."+name, default_int); //get
LogUtil.trace(TAG, String.format("get_%s %s",name,value));
return value;
}
public static void put_boolean(String name,boolean flag){
LogUtil.trace(TAG, "put_"+name+" " + flag );
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
//SharedPreferences pref = getPreferences(MODE_PRIVATE);
Editor e = pref.edit();
e.putBoolean(activity.getPackageName()+"."+name, flag); //put
if(Build.VERSION.SDK_INT>=9)ActivityUtil.apply(e);
else e.commit();
}
public static boolean get_boolean(String name,boolean default_boolean){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
//SharedPreferences pref =getPreferences(MODE_PRIVATE);
boolean flag = pref.getBoolean(activity.getPackageName()+"."+name,default_boolean); LogUtil.trace(TAG, "get_" + name + " " + flag );
return flag;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_debug_flag = getResources().getBoolean(R.bool.debug_flag); //デバックフラグ
if (m_debug_flag) {
if(Build.VERSION.SDK_INT>=11){
ActivityUtil.StrictMode11();
}
else if(Build.VERSION.SDK_INT>=9){
ActivityUtil.StrictMode09();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment