Android Open Source - AdoreLib Vertical Text View






From Project

Back to project page AdoreLib.

License

The source code is released under:

MIT License

If you think the Android project AdoreLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ylinval.adore.adorelib.AndroidViews;
//w ww . j  ava  2 s.c om
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 by jdourlens on 5/17/14.
 */
//Credits go to http://blog.stylingandroid.com/archives/796
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();
    }
}




Java Source Code List

com.ylinval.adore.adorelib.AdoreActivity.java
com.ylinval.adore.adorelib.AdoreFragment.java
com.ylinval.adore.adorelib.AdoreLoop.java
com.ylinval.adore.adorelib.AdoreView.java
com.ylinval.adore.adorelib.AdoreGraphics.Circle.java
com.ylinval.adore.adorelib.AdoreGraphics.Image.java
com.ylinval.adore.adorelib.AdoreGraphics.Line.java
com.ylinval.adore.adorelib.AdoreGraphics.Point.java
com.ylinval.adore.adorelib.AdoreGraphics.Rectangle.java
com.ylinval.adore.adorelib.AdoreGraphics.RoundRectangle.java
com.ylinval.adore.adorelib.AdoreGraphics.RoundSquare.java
com.ylinval.adore.adorelib.AdoreGraphics.Square.java
com.ylinval.adore.adorelib.AdoreGraphics.TextOutlined.java
com.ylinval.adore.adorelib.AdoreGraphics.Text.java
com.ylinval.adore.adorelib.AndroidViews.VerticalTextView.java
com.ylinval.adore.adorelib.Libs.Atlas.Circ.java
com.ylinval.adore.adorelib.Libs.Atlas.Pos.java
com.ylinval.adore.adorelib.Libs.Atlas.Rect.java
com.ylinval.adore.adorelib.Libs.State.StateManager.java
com.ylinval.adore.adorelib.Libs.State.State.java
com.ylinval.adore.adorelib.Libs.Tween.Tween.java
com.ylinval.adore.adorelib.Mobile.Accelerometer.java
com.ylinval.adore.adorelib.Sound.Music.java
com.ylinval.adore.adorelib.Sound.SoundEffect.java