package mprog.nl.mars_weather_explorer;

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

/**
 * Created Pointer Null edited on 24 oct. 2011, found on stackoverflow.com
 * @ link: http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android/7855852#7855852
 *
 * Class to convert a textView to a vertical textView.
 * By giving the textView a gravity attribute of bottom the text will be rotated -90 degrees,
 * with the start letter at the bottom.
 * When no gravity is specified the text is rotated 90 degrees in the other direction,
 * resulting in the start letter at the top.
 */
public class VerticalTextView extends TextView {
    final boolean topDown;

    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);
            topDown = false;
        }else{
            topDown = true;
        }
    }

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

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

        canvas.save();

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


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

        getLayout().draw(canvas);
        canvas.restore();
    }
}

@@ -38,201 +38,38 @@
 r;%0A%0A
-import android.content.Context;%0Aimport android.graphics.Canvas;%0Aimport android.text.TextPaint;%0Aimport android.util.AttributeSet;%0Aimport android.view.Gravity;%0Aimport android.widget.TextView;%0A%0A/*
+/**%0A * VerticalTextView.java%0A 
 *%0A *
@@ -251,328 +251,308 @@
 2%0A *
-%0A
  *
- Class to convert a textView to a vertical textView.%0A * By giving the textView a gravity attribute of bottom the text will be rotated -90 degrees,%0A * with the start letter at the bottom.%0A * When no gravity is specified the text is rotated 90 degrees in the other direction,%0A * resulting in the start letter at the top
+/%0Aimport android.content.Context;%0Aimport android.graphics.Canvas;%0Aimport android.text.TextPaint;%0Aimport android.util.AttributeSet;%0Aimport android.view.Gravity;%0Aimport android.widget.TextView;%0A%0A/**%0A * This class is an implementation of a custom view.%0A * It converts a textView to a vertical textView
 .%0A *
@@ -602,16 +602,17 @@
 tView %7B%0A
+%0A
     fina
@@ -769,16 +769,134 @@
 avity();
+%0A%0A        // When the textView has a gravity attribute of bottom the start letter will be on the bottom after rotating
 %0A       
@@ -1614,24 +1614,88 @@
 as.save();%0A%0A
+        // rotate the textView with the start letter at the top%0A
         if(t
@@ -1784,24 +1784,100 @@
 );%0A        %7D
+%0A        // rotate the textView with the start letter at the bottom%0A        
 else %7B%0A     
@@ -1960,17 +1960,16 @@
      %7D%0A%0A
-%0A
         

Refactor and comments added to VerticalTextView.