Android Open Source - treedo Utils






From Project

Back to project page treedo.

License

The source code is released under:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Everyone is permitted to copy and distribute verbatim or modified copies of this license document, ...

If you think the Android project treedo 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.mbonnin.treedo;
/*  w  w  w.j  a va 2 s .c  o m*/
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.CheckBox;

import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static android.util.TypedValue.applyDimension;

/**
 * Created by martin on 16/10/14.
 */
public class Utils {
    private static final String TAG = "Tree-Do";
    private static boolean sDebuggable;
    private static DisplayMetrics sDisplayMetrics;
    private static int mCheckBoxWidth;
    private static int mCheckBoxHeight;
    private static SparseArray<Bitmap> sCachedBitmaps = new SparseArray<Bitmap>();
    private static Context mContext;

    public static synchronized void log(String message) {
        if (sDebuggable)
            Log.d(TAG, message);
    }

    public static void init(Context context, boolean debuggable) {
        sDebuggable = debuggable;
        sDisplayMetrics = context.getResources().getDisplayMetrics();

        int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

        CheckBox checkBox = new CheckBox(context);
        checkBox.measure(widthSpec, heightSpec);
        mCheckBoxWidth = checkBox.getMeasuredWidth();
        mCheckBoxHeight = checkBox.getMeasuredHeight();

        mContext = context;
    }

    public static float toPixels(float dp) {
        return applyDimension(COMPLEX_UNIT_DIP, dp, sDisplayMetrics);
    }

    public static String encode(String string) {
        int i = 0;
        String result = "";

        if (string.equals("")) {
            return "";
        }

        while (string.charAt(i) == ' ') {
            result += "\\ ";
            i++;
        }

        return result + string.substring(i);
    }

    public static String decode(String string) {
        int i = 0;
        String result = "";

        if (string.equals("")) {
            return "";
        }

        while (string.startsWith("\\ ", i)) {
            result += " ";
            i += 2;
        }
        return result + string.substring(i);
    }

    public static int getCheckBoxHeight() {
        return mCheckBoxHeight;
    }

    public static Bitmap getBitmap(Context context, int id) {
        Bitmap b = sCachedBitmaps.get(id);
        if (b == null) {
            Resources resources = context.getResources();
            b = BitmapFactory.decodeResource(resources, id);
            sCachedBitmaps.put(id, b);
        }
        return b;
    }

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




Java Source Code List

com.mbonnin.treedo.ApplicationTest.java
com.mbonnin.treedo.BackupAdapter.java
com.mbonnin.treedo.BackupManager.java
com.mbonnin.treedo.Database.java
com.mbonnin.treedo.DialogBuilder.java
com.mbonnin.treedo.ItemAdapter.java
com.mbonnin.treedo.ItemDecorator.java
com.mbonnin.treedo.ItemEditText.java
com.mbonnin.treedo.ItemListView.java
com.mbonnin.treedo.ItemView2.java
com.mbonnin.treedo.ItemView.java
com.mbonnin.treedo.Item.java
com.mbonnin.treedo.MainActivity.java
com.mbonnin.treedo.ObservableScrollView.java
com.mbonnin.treedo.ProgressBar.java
com.mbonnin.treedo.SpacerView.java
com.mbonnin.treedo.TypeSpinnerAdapter.java
com.mbonnin.treedo.Utils.java