// Path: saklib/src/main/java/com/wanjian/sak/utils/ScreenUtils.java
// public class ScreenUtils {
// 
//   public static int dp2px(Context context, int dip) {
//     float density = context.getResources().getDisplayMetrics().density;
//     return (int) (dip * density + 0.5);
//   }
// 
//   public static int px2dp(Context context, float pxValue) {
//     final float scale = context.getResources().getDisplayMetrics().density;
//     return (int) (pxValue / scale + 0.5f);
//   }
// 
// }


import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
import com.wanjian.sak.utils.ScreenUtils;

  @Override
  protected void onDraw(Canvas canvas, View view) {
    String txt = getTxt(view);
    if (txt == null) {
      txt = "";
    }
    drawTxt(txt, canvas, view);
  }

  protected abstract String getTxt(View view);

  private void drawTxt(String txt, Canvas canvas, View view) {
    mPaint.setTextSize(getTextSize());
    mPaint.getTextBounds(txt, 0, txt.length(), mRect);
    mPaint.setColor(getBackgroundColor());
    canvas.drawRect(0, 0, mRect.width(), mRect.height(), mPaint);
    mPaint.setColor(getColor());
    canvas.drawText(txt, 0, mRect.height(), mPaint);
  }

  protected int getColor() {
    return Color.BLACK;
  }

  protected int getBackgroundColor() {
    return 0x88ffffff;
  }

  public float getTextSize() {
// Path: saklib/src/main/java/com/wanjian/sak/utils/ScreenUtils.java
// public class ScreenUtils {
// 
//   public static int dp2px(Context context, int dip) {
//     float density = context.getResources().getDisplayMetrics().density;
//     return (int) (dip * density + 0.5);
//   }
// 
//   public static int px2dp(Context context, float pxValue) {
//     final float scale = context.getResources().getDisplayMetrics().density;
//     return (int) (pxValue / scale + 0.5f);
//   }
// 
// }


// Path: saklib/src/main/java/com/wanjian/sak/layer/impl/LayerTxtAdapter.java
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
import com.wanjian.sak.utils.ScreenUtils;


  @Override
  protected void onDraw(Canvas canvas, View view) {
    String txt = getTxt(view);
    if (txt == null) {
      txt = "";
    }
    drawTxt(txt, canvas, view);
  }

  protected abstract String getTxt(View view);

  private void drawTxt(String txt, Canvas canvas, View view) {
    mPaint.setTextSize(getTextSize());
    mPaint.getTextBounds(txt, 0, txt.length(), mRect);
    mPaint.setColor(getBackgroundColor());
    canvas.drawRect(0, 0, mRect.width(), mRect.height(), mPaint);
    mPaint.setColor(getColor());
    canvas.drawText(txt, 0, mRect.height(), mPaint);
  }

  protected int getColor() {
    return Color.BLACK;
  }

  protected int getBackgroundColor() {
    return 0x88ffffff;
  }

  public float getTextSize() {
    return ScreenUtils.dp2px(getContext(), 10);