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 top and bottom compound drawables
     *
     * @param tv
     */
    public static void vertical(TextView tv) {
        Drawable[] drawables = tv.getCompoundDrawables();
        Drawable top = drawables[TOP];
        Drawable bottom = drawables[BOTTOM];
        if ((top != null && bottom != null) || (top == null && bottom == null)) {
            return;
        }
        if (top == null) {
            top = createPlaceholder(bottom);
        }
        if (bottom == null) {
            bottom = createPlaceholder(top);
        }
        tv.setCompoundDrawables(drawables[LEFT], top, drawables[RIGHT], bottom);
    }

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