package com.gh4a.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;

public class VerticalTextView extends TextView {
    private final boolean mTopDown;

    public VerticalTextView(Context context, AttributeSet attrs) {
       super(context, attrs);

       final int gravity = getGravity();
       if (Gravity.isVertical(gravity) && (gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
          setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
          mTopDown = false;
       } else {
          mTopDown = true;
       }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
       super.onMeasure(heightMeasureSpec, widthMeasureSpec);
       setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }

    @Override
    public void onDraw(Canvas canvas) {
        TextPaint textPaint = getPaint();
        textPaint.setColor(getCurrentTextColor());
        textPaint.drawableState = getDrawableState();

        canvas.save();

        if (mTopDown) {
            canvas.translate(getWidth(), 0);
            canvas.rotate(90);
        } else {
            canvas.translate(0, getHeight());
            canvas.rotate(-90);
        }

        canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
        getLayout().draw(canvas);

        canvas.restore();
    }
}

@@ -83,16 +83,44 @@
 Canvas;%0A
+import android.text.Layout;%0A
 import a
@@ -1014,24 +1014,122 @@
 s canvas) %7B%0A
+        Layout layout = getLayout();%0A        if (layout == null) %7B%0A            return;%0A        %7D%0A%0A
         Text
@@ -1579,27 +1579,22 @@
         
-getL
+l
 ayout
-()
 .draw(ca

Fix Bugsense-reported NPE.