public ScanMaskView(Context context, AttributeSet attrs) { super(context, attrs); // this.context = context; mFrameSpace = ScreenUtil.dp2px(FRAME_SPACE); mOutFrameStokeWidth = ScreenUtil.dp2px(OUT_FRAME_STROKE_WIDTH); mInnerFrameStokeWidth = ScreenUtil.dp2px(INNER_FRAME_STROKE_WIDTH); mTextMarginTop = ScreenUtil.dp2px(TEXT_MARGIN_TOP); // mTextMarginButtom = ScreenUtil.dp2px(TEXT_MARGIN_BUTTOM); mIntervalText = ScreenUtil.dp2px(INTERVAL_TEXT); mInnerFrameCornerLength = getResources().getDimensionPixelSize(R.dimen.scan_blueline_length); mTextSize = getResources().getDimension(R.dimen.textsize_18px); // mHintStr = getResources().getString(R.string.scan_hint); mScanLine = getResources().getDrawable(R.drawable.qrcode_move_line); textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextSize(mTextSize); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setColor(getResources().getColor(R.color.scan_text_color)); innerFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG); innerFramePaint.setStrokeWidth(mInnerFrameStokeWidth); innerFramePaint.setColor(getResources().getColor(R.color.scan_inner_frame)); innerFramePaint.setStyle(Paint.Style.STROKE); outFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG); outFramePaint.setStrokeWidth(mOutFrameStokeWidth); outFramePaint.setColor(getResources().getColor(R.color.scan_out_frame)); outFramePaint.setStyle(Paint.Style.STROKE); shadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG); shadowPaint.setColor(getResources().getColor(R.color.scan_mask_color)); shadowPaint.setStyle(Paint.Style.FILL); }
private void drawMutiText( Canvas canvas, Paint textPaint, Point startPoint, int maxLength, String text) { if (TextUtils.isEmpty(text)) return; String[] lines = getTextLines(textPaint, text, maxLength); int line_count = lines.length; canvas.save(); canvas.translate(startPoint.x, startPoint.y); for (int i = 0; i < line_count; i++) { canvas.drawText(lines[i], 0, 0, textPaint); canvas.translate(0, ScreenUtil.dp2px(INTERVAL_TEXT) + mTextSize); } canvas.restore(); }
/** * 压缩图片,防止oom * * @return */ public static Bitmap getBitmap(String path) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(path, opt); opt.inPreferredConfig = Bitmap.Config.ARGB_8888; opt.inPurgeable = true; opt.inInputShareable = true; opt.inJustDecodeBounds = false; int w = opt.outWidth; int h = opt.outHeight; float ww = ScreenUtil.getScreenInfo()[0]; float hh = ScreenUtil.getScreenInfo()[1]; int be = 1; if (w > h && w > ww) { // 如果宽度大的话根据宽度固定大小缩放 be = (int) (opt.outWidth / ww); } else if (w < h && h > hh) { // 如果高度高的话根据宽度固定大小缩放 be = (int) (opt.outHeight / hh); } if (be <= 0) be = 1; opt.inSampleSize = be; // 设置缩放比例 bitmap = BitmapFactory.decodeFile(path, opt); return bitmap; }
/** * 设置下方文本距扫描框的距离 * * @param distance */ public void setTextMarginTop(int distance) { mTextMarginTop = ScreenUtil.dp2px(distance); }