package com.yinli.ylscrollview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Yin Li on 18/03/15.
 */
public class YLVerticalTextLabelView extends TextView{

    private boolean isTopDown;

    public YLVerticalTextLabelView(Context context) {
        this(context, null);
    }

    public YLVerticalTextLabelView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public YLVerticalTextLabelView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        /* Retrieve styles attributes */
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.YLVerticalTextLabelView, defStyleAttr, 0);
        try {
            isTopDown = typedArray.getBoolean(R.styleable.YLVerticalTextLabelView_topDown, true);
        } finally {
            typedArray.recycle();
        }

        init();
    }

    private void init() {

    }

    @Override
    protected void onDraw(Canvas canvas) {

        TextPaint textPaint = getPaint();
        /* Use the original text color */
        textPaint.setColor(getCurrentTextColor());
        /* Use the original drawable states  */
        textPaint.drawableState = getDrawableState();

        canvas.save();

        if (isTopDown) {
            canvas.translate(getMeasuredWidth(), 0);
            canvas.rotate(90);
        } else {
            canvas.translate(0, getMeasuredHeight());
            canvas.rotate(-90);
        }

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

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        /* Exchange width with height */
        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }
}

@@ -974,11 +974,12 @@
 wn, 
-tru
+fals
 e);%0A
@@ -1441,24 +1441,56 @@
 sTopDown) %7B%0A
+            canvas.rotate(-90);%0A
             
@@ -1506,16 +1506,17 @@
 anslate(
+-
 getMeasu
@@ -1522,21 +1522,22 @@
 ured
-Width
+Height
 (), 0);%0A
     
@@ -1528,24 +1528,41 @@
 ight(), 0);%0A
+        %7D else %7B%0A
             
@@ -1578,39 +1578,24 @@
 tate(90);%0A  
-      %7D else %7B%0A
             
@@ -1584,34 +1584,32 @@
 0);%0A            
-  
 canvas.translate
@@ -1612,16 +1612,17 @@
 late(0, 
+-
 getMeasu
@@ -1628,48 +1628,15 @@
 ured
-Height());%0A            canvas.rotate(-90
+Width()
 );%0A 

Version 5 Add Graphic Label / Indicator