Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

public class Main {
    private static final int LEFT = 0;
    private static final int TOP = 1;
    private static final int RIGHT = 2;
    private static final int BOTTOM = 3;

    /**
     * Fixes the left and right compound drawables
     *
     * @param tv
     */
    public static void horizontal(TextView tv) {
        Drawable[] drawables = tv.getCompoundDrawables();
        Drawable left = drawables[LEFT];
        Drawable right = drawables[RIGHT];
        if ((left != null && right != null) || (left == null && right == null)) {
            return;
        }
        if (right == null) {
            right = createPlaceholder(left);

            // create a placeholder drawable of the same size on the right
        }
        if (left == null) {
            left = createPlaceholder(right);
        }
        tv.setCompoundDrawables(left, drawables[TOP], right, drawables[BOTTOM]);
    }

    private static Drawable createPlaceholder(Drawable original) {
        Drawable placeholder = new ColorDrawable();
        placeholder.setBounds(original.getBounds());
        return placeholder;
    }
}