Android Open Source - XKCD-Reader Android Util






From Project

Back to project page XKCD-Reader.

License

The source code is released under:

Apache License

If you think the Android project XKCD-Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.davidtpate.xkcd.util;
//  w  w  w . j ava  2  s. com
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import com.davidtpate.xkcd.ui.ComicFragmentActivity;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Method;

public class AndroidUtil {
    public static boolean isUserAMonkey() {
        boolean isUserAMonkey = false;
        try {
            Class<?> pointClass = Class.forName("android.app.ActivityManager");
            Method monkey = pointClass.getMethod("isUserAMonkey");
            // no exception, so new method is available, just use it
            isUserAMonkey = (Boolean) monkey.invoke(pointClass);
        } catch (Exception e) {
            // Do nothing
        }
        return isUserAMonkey;
    }

    public static int dpToPx(Context context, int dp) {
        return (int) (dp * (context.getResources().getDisplayMetrics().densityDpi / 160f) + 0.5f);
    }

    public static int pxToDp(Context context, int px) {
        return (int) (px / (context.getResources().getDisplayMetrics().densityDpi / 160f) + 0.5f);
    }

    @TargetApi(11)
    public static void enableStrictMode() {
        if (AndroidUtil.hasGingerbread()) {
            StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
                new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog();
            StrictMode.VmPolicy.Builder vmPolicyBuilder =
                new StrictMode.VmPolicy.Builder().detectAll().penaltyLog();

            if (AndroidUtil.hasHoneycomb()) {
                threadPolicyBuilder.penaltyFlashScreen();
                vmPolicyBuilder.setClassInstanceLimit(ComicFragmentActivity.class, 1);
            }

            StrictMode.setThreadPolicy(threadPolicyBuilder.build());
            StrictMode.setVmPolicy(vmPolicyBuilder.build());
        }
    }

    public static boolean hasFroyo() {
        // Can use static final constants like FROYO, declared in later versions
        // of the OS since they are inlined at compile time. This is guaranteed behavior.
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
    }

    public static boolean hasGingerbread() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
    }

    public static boolean hasHoneycomb() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
    }

    public static boolean hasHoneycombMR1() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
    }

    public static boolean hasIcs() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
    }

    public static boolean hasJellyBean() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
    }

    public static byte parcelBoolean(boolean val) {
        return (byte) (val ? 1 : 0);
    }

    public static void closeQuietly(Closeable closeable) {
        try {
            if (closeable != null) {
                closeable.close();
            }
        } catch (IOException ioe) {
            // ignore
        }
    }
}




Java Source Code List

android.support.v4.app.FixedFragmentStatePagerAdapter.java
com.android.debug.hv.ViewServer.java
com.davidtpate.xkcd.BaseApplication.java
com.davidtpate.xkcd.adapter.ComicPagerAdapter.java
com.davidtpate.xkcd.model.Comic.java
com.davidtpate.xkcd.model.Constants.java
com.davidtpate.xkcd.preferences.SharedPreferencesHelper.java
com.davidtpate.xkcd.provider.SystemUiStateProvider.java
com.davidtpate.xkcd.ui.About.java
com.davidtpate.xkcd.ui.ComicFragmentActivity.java
com.davidtpate.xkcd.ui.ComicFragment.java
com.davidtpate.xkcd.ui.CurrentComic.java
com.davidtpate.xkcd.ui.base.BaseActivity.java
com.davidtpate.xkcd.ui.base.BaseFragmentActivity.java
com.davidtpate.xkcd.ui.base.BaseFragment.java
com.davidtpate.xkcd.ui.base.BaseListActivity.java
com.davidtpate.xkcd.ui.base.BaseListFragment.java
com.davidtpate.xkcd.ui.dialog.JumpToDialogFragment.java
com.davidtpate.xkcd.util.AndroidUtil.java
com.davidtpate.xkcd.util.ComicUtil.java
com.davidtpate.xkcd.util.Ln.java
com.davidtpate.xkcd.util.MathUtil.java
com.davidtpate.xkcd.util.Strings.java