<commit_before>package com.datdo.mobilib.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;

import junit.framework.Assert;

import org.json.JSONArray;

import com.datdo.mobilib.base.MblDecorView;
import com.datdo.mobilib.event.MblCommonEvents;
import com.datdo.mobilib.event.MblEventCenter;
import com.datdo.mobilib.event.MblStrongEventListener;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class MblUtils {
    private static final String TAG = getTag(MblUtils.class);
    private static float density = 0;
    private static final String EMAIL_TYPE = "message/rfc822";

    private static Handler sMainThread = new Handler(Looper.getMainLooper());
    private static Map<String, Object> sCommonBundle = new ConcurrentHashMap<String, Object>();

    private static SharedPreferences sPrefs;
    private static Context sCurrentContext;

    public static void init(Context context) {
        sCurrentContext = context;
    }

    /**
     * <pre>
     * Get {@link Handler} for main thread.
     * </pre>
     */
    public static Handler getMainThreadHandler() {
        return sMainThread;
    }

    /**
     * <pre>
     * Get default {@link SharedPreferences} of the app.
     * </pre>
     */
    public static SharedPreferences getPrefs() {
        if (sPrefs == null) {
            sPrefs = PreferenceManager.getDefaultSharedPreferences(getCurrentContext());
        }
        return sPrefs;
    }

    /**
     * <pre>
     * Get current context of the app. This method resolves the inconvenience of Android which requires context for most of its API.
     * If no activity is resumed, this method returns application context. Otherwise, this method returns last resumed activity.
     * </pre>
     */
    public static Context getCurrentContext() {
        return sCurrentContext;
    }

    public static void setCurrentContext(Context context) {
        sCurrentContext = context;
    }

    /**
     * <pre>
     * Get {@link Locale} from device 's configuration.
     * Return {@link Locale#JAPAN} if configuration is not found.
     * </pre>
     */
    public static Locale getLocale() {
        if (sCurrentContext != null) {
            return sCurrentContext.getResources().getConfiguration().locale;
        } else {
            return Locale.JAPAN;
        }
    }

    /**
     * <pre>
     * Execute the action in a thread which is not main thread.
     * If current thread is not main thread, execute the action immediately.
     * Otherwise, create new {@link AsyncTask} to execute the action. {@link AsyncTask} is created using {@link AsyncTask#THREAD_POOL_EXECUTOR}.
     * If max number of threads exceeds, wait 1000 milliseconds and call this method again to ensure that the action will be executed.
     * </pre>
     */
    @SuppressLint("NewApi")
    public static void executeOnAsyncThread(final Runnable action) {
        Assert.assertNotNull(action);
        if (!MblUtils.isMainThread()) {
            action.run();
            return;
        }
        MblAsyncTask task = new MblAsyncTask() {
            @Override
            protected Void doInBackground(Void... params) {
                action.run();
                return null;
            }
        };
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {<commit_msg>MblUtils: add getLayoutInflater() to get LayoutInflater instance globally<commit_after>package com.datdo.mobilib.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;

import junit.framework.Assert;

import org.json.JSONArray;

import com.datdo.mobilib.base.MblDecorView;
import com.datdo.mobilib.event.MblCommonEvents;
import com.datdo.mobilib.event.MblEventCenter;
import com.datdo.mobilib.event.MblStrongEventListener;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class MblUtils {
    private static final String TAG = getTag(MblUtils.class);
    private static float density = 0;
    private static final String EMAIL_TYPE = "message/rfc822";

    private static Handler sMainThread = new Handler(Looper.getMainLooper());
    private static Map<String, Object> sCommonBundle = new ConcurrentHashMap<String, Object>();

    private static SharedPreferences sPrefs;
    private static Context sCurrentContext;
    private static LayoutInflater sLayoutInflater;

    public static void init(Context context) {
        sCurrentContext = context;
    }

    /**
     * <pre>
     * Get {@link Handler} for main thread.
     * </pre>
     */
    public static Handler getMainThreadHandler() {
        return sMainThread;
    }

    /**
     * <pre>
     * Get default {@link SharedPreferences} of the app.
     * </pre>
     */
    public static SharedPreferences getPrefs() {
        if (sPrefs == null) {
            sPrefs = PreferenceManager.getDefaultSharedPreferences(getCurrentContext());
        }
        return sPrefs;
    }

    /**
     * <pre>
     * Get current context of the app. This method resolves the inconvenience of Android which requires context for most of its API.
     * If no activity is resumed, this method returns application context. Otherwise, this method returns last resumed activity.
     * </pre>
     */
    public static Context getCurrentContext() {
        return sCurrentContext;
    }

    public static void setCurrentContext(Context context) {
        sCurrentContext = context;
    }

    /**
     * <pre>
     * Get {@link Locale} from device 's configuration.
     * Return {@link Locale#JAPAN} if configuration is not found.
     * </pre>
     */
    public static Locale getLocale() {
        if (sCurrentContext != null) {
            return sCurrentContext.getResources().getConfiguration().locale;
        } else {
            return Locale.JAPAN;
        }
    }

    /**
     * <pre>
     * Get {@link LayoutInflater} instance which is essential for adapters.
     * </pre>
     */
    public static LayoutInflater getLayoutInflater() {
        if (sLayoutInflater == null) {
            sLayoutInflater = LayoutInflater.from(getCurrentContext());
        }
        return sLayoutInflater;
    }

    /**
     * <pre>
     * Execute the action in a thread which is not main thread.
     * If current thread is not main thread, execute the action immediately.
     * Otherwise, create new {@link AsyncTask} to execute the action. {@link AsyncTask} is created using {@link AsyncTask#THREAD_POOL_EXECUTOR}.
     * If max number of threads exceeds, wait 1000 milliseconds and call this method again to ensure that the action will be executed.
     * </pre>
     */
    @SuppressLint("NewApi")
    public static void executeOnAsyncThread(final Runnable action) {
        Assert.assertNotNull(action);
        if (!MblUtils.isMainThread()) {
            action.run();
            return;
        }
        MblAsyncTask task = new MblAsyncTask() {
            @Override
            protected Void doInBackground(Void... params) {
                action.run();
                return null;
            }
        };
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
{'fraction_non_alphanumeric': 0.09094687837725497, 'fraction_numerical': 0.001662648599218555, 'mean_word_length': 3.579368100494861, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4547691', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3228, 'n_words': 857}