Android Open Source - intent-intercept Underlined Text View






From Project

Back to project page intent-intercept.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions f...

If you think the Android project intent-intercept 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

// Code from slide 64 at
// https://speakerdeck.com/u/cyrilmottier/p/optimizing-android-ui-pro-tips-for-creating-smooth-and-responsive-apps
//from www  .j  a v a  2s.c o  m
package uk.co.ashtonbrsc.intentexplode.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class UnderlinedTextView extends TextView {

  private final Paint mPaint = new Paint();
  private int mUnderlineHeight = 2;

  public UnderlinedTextView(Context context) {
    super(context);
    mPaint.setColor(getResources().getColor(android.R.color.holo_blue_light));
  }

  public UnderlinedTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mPaint.setColor(getResources().getColor(android.R.color.holo_blue_light));
  }

  public UnderlinedTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mPaint.setColor(getResources().getColor(android.R.color.holo_blue_light));
  }

  @Override
  public void setPadding(int left, int top, int right, int bottom) {
    super.setPadding(left, top, right, mUnderlineHeight + bottom);
  }

  public void setUnderlineHeight(int underlineHeight) {
    if (underlineHeight < 0)
      underlineHeight = 0;
    if (underlineHeight != mUnderlineHeight) {
      mUnderlineHeight = underlineHeight;
      setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
          getPaddingBottom() + mUnderlineHeight);
    }
  }

  public void setUnderlineColor(int underlineColor) {
    if (mPaint.getColor() != underlineColor) {
      mPaint.setColor(underlineColor);
      invalidate();
    }
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawRect(0, getHeight() - mUnderlineHeight, getWidth(),
        getHeight(), mPaint);
  }

}




Java Source Code List

uk.co.ashtonbrsc.intentexplode.Explode.java
uk.co.ashtonbrsc.intentexplode.Settings.java
uk.co.ashtonbrsc.intentexplode.widget.BlockEnterEditText.java
uk.co.ashtonbrsc.intentexplode.widget.UnderlinedTextView.java