суббота, 8 июня 2013 г.

Вертикальный TextView в Android

VerticalTextView.java

public class VerticalTextView extends TextView {

 private int _width, _height;
 private final Rect _bounds = new Rect();

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

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

 public VerticalTextView(Context context) {
  super(context);
 }

 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  // vise versa
  _height = getMeasuredWidth();
  _width = getMeasuredHeight();
  setMeasuredDimension(_width, _height);
 }

 @Override
 protected void onDraw(Canvas canvas) {
  canvas.save();

  canvas.translate(_width, _height);
  canvas.rotate(-90);

  TextPaint paint = getPaint();
  paint.setColor(getTextColors().getDefaultColor());

  String text = text();

  paint.getTextBounds(text, 0, text.length(), _bounds);
  canvas.drawText(text, getCompoundPaddingLeft(), (_bounds.height() - _width) / 2, paint);

  canvas.restore();
 }

 private String text() {
  return super.getText().toString();
 }
}

xml:

    <com.my.namespace.VerticalTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:background="@color/feedback_background"
        android:padding="4dip"
        android:text="@string/feedback"
        android:textColor="@color/feedback_text_color"
        android:textSize="@dimen/text_xlarge" />

PS: начиная с API11 никакого огорода городить не надо. Используем setRotation

Поисковые системы в моём Google Chrome


Открываем chrome://settings/.  Затем управление поисковыми системами.

4pda: http://4pda.ru/forum/index.php?act=Search&source=all&forums[]=281&query=%s&x=17&y=16&subforums=1
dns: http://smolensk.dns-shop.ru/search/?q=%s
enter: http://www.enter.ru/search?q=%s
elmall67: http://elmall67.ru/search?l=1&search_field=%s&search_button=%CD%E0%E9%F2%E8
nnm-club: http://nnm-club.ru/forum/search.php?mode=results&show_results=topics&search_keywords=%s
pc67: http://pc67.ru/search?str=%s
rutracker: http://rutracker.org/forum/tracker.php?max=1&nm=%s
so: http://stackoverflow.com/search?q=%s
wiki: http://ru.wikipedia.org/wiki/%s
Перевод en > ru: http://translate.google.com/#en|ru|%s
Перевод ru > en http://translate.google.com/#ru|en|%s
yandex maps: http://maps.yandex.ru/?text=%s
yandex market: http://market.yandex.ru/search.xml?text=%s&from=os
Google play: https://play.google.com/store/search?q=%s