PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/views/VerticalTextView.java

68 lines
2.1 KiB
Java
Raw Normal View History

2019-03-03 09:29:03 +00:00
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
2018-07-27 13:07:33 +00:00
package code.name.monkey.retromusic.views;
import android.content.Context;
import android.graphics.Canvas;
2018-09-09 19:44:46 +00:00
import android.text.TextPaint;
2018-07-27 13:07:33 +00:00
import android.util.AttributeSet;
import android.view.Gravity;
2019-10-03 17:13:04 +00:00
import androidx.appcompat.widget.AppCompatTextView;
2018-09-09 19:44:46 +00:00
2019-10-03 17:13:04 +00:00
public class VerticalTextView extends AppCompatTextView {
2018-07-27 13:07:33 +00:00
final boolean topDown;
2019-10-03 17:13:04 +00:00
public VerticalTextView(Context context, AttributeSet attrs) {
2018-07-27 13:07:33 +00:00
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;
2019-10-03 17:13:04 +00:00
2018-07-27 13:07:33 +00:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2019-10-03 17:13:04 +00:00
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
2018-07-27 13:07:33 +00:00
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
2019-10-03 17:13:04 +00:00
protected void onDraw(Canvas canvas) {
2018-09-09 19:44:46 +00:00
TextPaint textPaint = getPaint();
textPaint.setColor(getCurrentTextColor());
textPaint.drawableState = getDrawableState();
canvas.save();
2018-07-27 13:07:33 +00:00
if (topDown) {
2018-09-09 19:44:46 +00:00
canvas.translate(getWidth(), 0);
2018-07-27 13:07:33 +00:00
canvas.rotate(90);
} else {
2018-09-09 19:44:46 +00:00
canvas.translate(0, getHeight());
2018-07-27 13:07:33 +00:00
canvas.rotate(-90);
}
2018-09-09 19:44:46 +00:00
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
getLayout().draw(canvas);
canvas.restore();
2018-07-27 13:07:33 +00:00
}
}