android 自定義拍照錄像
自定義拍照和錄影功能。拍完照或錄完視訊後,彈出另一介面,顯示拍的照片或錄製的視訊:
拍照介面:
介面中的按鈕,點選是拍照,長按是攝像,攝像時,按鈕周圍有圓形進度條顯示進度
TakePicActivity.java
package com.haier.uhome.appliance.newVersion.module.messageboard;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class TakePicActivity extends AppCompatActivity {
private static final String TAG = "TakePicActivity";
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
RelativeLayout rl_btn;
@BindView(R.id.fl_content)
FrameLayout flContent;
//進度條
@BindView(R.id.circleProgress)
CircleProgressView circleProgress;
@BindView(R.id.iv_turn)
ImageView ivTurn;
private Camera camera;
private Camera.Parameters parameters = null;
Bundle bundle = null; // 宣告一個Bundle物件,用來儲存資料
Button takepicture;
RelativeLayout rl_playPic;
int w, h;
protected boolean isPreview;
private MediaRecorder mMediaRecorder;
private boolean isRecording = true; // true表示沒有錄影,點選開始;false表示正在錄影,點選暫停
private File mRecVedioPath;
private File mRecAudioFile;
//錄製視訊時的計時器
private TextView timer;
private int hour = 0;
private int minute = 0;
private int second = 0;
private boolean bool;
private Animator animator;
private boolean isRecordState = false;//是否是視訊錄製狀態
private int progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_pic);
ButterKnife.bind(this);
takepicture = (Button) findViewById(R.id.takepicture);
surfaceView = (SurfaceView) this
.findViewById(R.id.surfaceView);
rl_btn = (RelativeLayout) this.findViewById(R.id.buttonLayout);
timer = (TextView) this.findViewById(R.id.show_time);
// 設定計時器不可見
// timer.setVisibility(View.GONE);
// 設定快取路徑
mRecVedioPath = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/hfdatabase/video/temp/");
if (!mRecVedioPath.exists()) {
mRecVedioPath.mkdirs();
}
//圓形進度條設定
circleProgress.setBgColor(getResources().getColor(R.color.text_white));
circleProgress.setProgressColor(getResources().getColor(R.color.colorPrimaryDark));
ViewTreeObserver observerCircle = circleProgress.getViewTreeObserver();
observerCircle.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
progress = circleProgress.getmProgress();
return true;
}
});
surfaceView.getHolder()
.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceView.getHolder().setFixedSize(176, 144); //設定Surface解析度
surfaceView.getHolder().setKeepScreenOn(true);// 螢幕常亮
surfaceView.getHolder().addCallback(new SurfaceCallback());//為SurfaceView的控制代碼新增一個回撥函式
//長按錄製
takepicture.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
isRecordState = true;
if (isRecording) {
/*
* 點選開始錄影
*/
if (isPreview) {
camera.stopPreview();
camera.release();
camera = null;
}
second = 0;
minute = 0;
hour = 0;
bool = true;
if (mMediaRecorder == null)
mMediaRecorder = new MediaRecorder();
else
mMediaRecorder.reset();
//拍攝視訊時的相機配置
if (camera != null) {
freeCameraResource();
}
camera = Camera.open();
camera.setDisplayOrientation(90);
camera.startPreview();
camera.unlock();
mMediaRecorder.setCamera(camera);
mMediaRecorder.setOnErrorListener(null);
mMediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setMaxDuration(60 * 1000);
mMediaRecorder.setVideoSize(320, 240);
mMediaRecorder.setVideoEncodingBitRate(1 * 1024 * 1024);// 設定幀頻率,然後就清晰了
// mMediaRecorder.setVideoFrameRate(15);
mMediaRecorder.setOrientationHint(getPreviewDegree(TakePicActivity.this));// 輸出旋轉90度,保持豎屏錄製
try {
mRecAudioFile = File.createTempFile("Vedio", ".mp4", mRecVedioPath);
} catch (IOException e) {
e.printStackTrace();
}
mMediaRecorder.setOutputFile(mRecAudioFile.getAbsolutePath());
try {
mMediaRecorder.prepare();
timer.setVisibility(View.VISIBLE);
handler.postDelayed(task, 1000);
mMediaRecorder.start();
} catch (Exception e) {
e.printStackTrace();
}
showMsg("開始錄製");
// scalePic.setBackgroundDrawable(iconStop);
isRecording = !isRecording;
recordAnimater();
}
return false;
}
});
takepicture.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_UP:
Log.d(TAG, "onTouch: takepicture==setOnTouchListener==ACTION_UP");
if(isRecordState){
if(animator.isRunning()){
animator.end();
}
}
break;
}
return false;
}
});
}
/*
* 視訊錄製時的進度條動畫
* */
public void recordAnimater() {
//設定進度條
startAnimator();
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
Log.i("animator", "stop");
/*
* 點選停止
*/
try {
bool = false;
// isRecordState = false;
mMediaRecorder.stop();
timer.setText(format(hour) + ":" + format(minute) + ":" + format(second));
mMediaRecorder.release();
mMediaRecorder = null;
//錄製完成後播放攝像頭
freeCameraResource();
videoRename();
} catch (Exception e) {
e.printStackTrace();
}
isRecording = !isRecording;
// scalePic.setBackgroundDrawable(iconStart);
showMsg("錄製完成,已儲存");
// Intent backIntent = new Intent();
// backIntent.putExtra("path", mrv_wx.mVecordFile.getAbsoluteFile().toString());
// setResult(RESULT_OK, backIntent);
// finish();
Intent displayIntent = new Intent(TakePicActivity.this, ShowPicActivity.class);
bundle = new Bundle();
bundle.putBoolean("isRecord", isRecordState);
bundle.putString("video_path", out.getAbsolutePath());
displayIntent.putExtras(bundle);
startActivity(displayIntent);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
@OnClick(R.id.iv_turn)
public void onClick() {
}
private final class SurfaceCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
if (camera != null) {
freeCameraResource();
}
camera = Camera.open(); // 開啟攝像頭
parameters = camera.getParameters();
//加這句小米手機會黑屏
// parameters.setPreviewFrameRate(5); // 每秒5幀
parameters.setPictureFormat(PixelFormat.JPEG);// 設定照片的輸出格式
parameters.set("jpeg-quality", 85);// 照片質量
int PreviewWidth = 0;
int PreviewHeight = 0;
// 選擇合適的預覽尺寸
List<Camera.Size> sizeList = parameters.getSupportedPreviewSizes();
// 如果sizeList只有一個我們也沒有必要做什麼了,因為就他一個別無選擇
if (sizeList.size() > 1) {
Iterator<Camera.Size> itor = sizeList.iterator();
while (itor.hasNext()) {
Camera.Size cur = itor.next();
if (cur.width >= PreviewWidth
&& cur.height >= PreviewHeight) {
PreviewWidth = cur.width;
PreviewHeight = cur.height;
break;
}
}
}
parameters.setPreviewSize(PreviewWidth, PreviewHeight); // 獲得攝像區域的大小
parameters.setPictureSize(PreviewWidth, PreviewHeight); // 獲得儲存圖片的大小
// parameters.setPreviewSize(320, 240); // 設定預覽大小
// parameters.setPictureSize(320,240);
// parameters.set("orientation", "portrait");
camera.setParameters(parameters);
camera.setPreviewDisplay(holder); // 設定用於顯示拍照影像的SurfaceHolder物件
camera.setDisplayOrientation(getPreviewDegree(TakePicActivity.this));
camera.startPreview(); // 開始預覽
isPreview = true;
// camera.autoFocus(null);
} catch (Exception e) {
e.printStackTrace();
}
surfaceHolder = holder;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
surfaceHolder = holder;
LogUtil.d(TAG,"surfaceChanged======");
camera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
// camera.setOneShotPreviewCallback(null);
initCamera(width, height);
camera.cancelAutoFocus();//只有加上了這一句,才會自動對焦。
}
});
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (camera != null) {
if (isPreview) {
camera.stopPreview();
isPreview = false;
}
camera.release(); // 釋放照相機
camera = null;
}
surfaceHolder = null;
surfaceView = null;
mMediaRecorder = null;
}
}
// 提供一個靜態方法,用於根據手機方向獲得相機預覽畫面旋轉的角度
public static int getPreviewDegree(Activity activity) {
// 獲得手機的方向
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degree = 0;
// 根據手機的方向計算相機預覽畫面應該選擇的角度
switch (rotation) {
case Surface.ROTATION_0:
degree = 90;
break;
case Surface.ROTATION_90:
degree = 0;
break;
case Surface.ROTATION_180:
degree = 270;
break;
case Surface.ROTATION_270:
degree = 180;
break;
}
return degree;
}
/**
* 按鈕被點選觸發的事件
*
* @param v
*/
public void btnOnclick(View v) {
if (camera != null) {
switch (v.getId()) {
case R.id.takepicture:
// 拍照
camera.takePicture(null, null, new MyPictureCallback());
break;
}
}
}
byte[] picData;
private final class MyPictureCallback implements Camera.PictureCallback {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
bundle = new Bundle();
bundle.putByteArray("bytes", data);//將圖片位元組資料儲存在bundle中,實現資料交換
picData = data;
// saveToSDCard(data);
// camera.startPreview();//拍完照後,重新開始預覽
if (bundle == null) {
Toast.makeText(getApplicationContext(), "請先拍照",
Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent();
intent.setClass(getApplicationContext(), ShowPicActivity.class);
bundle.putBoolean("isRecord", isRecordState);
intent.putExtras(bundle);
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void initCamera(int width, int height) {
parameters = camera.getParameters(); // 獲取各項引數
parameters.setPictureFormat(PixelFormat.JPEG); // 設定圖片格式
parameters.setPreviewSize(width, height); // 設定預覽大小
// List<Camera.Size> sizes =parameters.getSupportedPreviewSizes();
// Camera.Size optimalSize = getOptimalPreviewSize(sizes, 320,240);
// parameters.setPreviewSize(optimalSize.width, optimalSize.height);
parameters.setPreviewFrameRate(5); //設定每秒顯示4幀
parameters.setPictureSize(width, height); // 設定儲存的圖片尺寸
parameters.setJpegQuality(80); // 設定照片質量
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);//1連續對焦
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.startPreview();
camera.cancelAutoFocus();// 2如果要實現連續的自動對焦,這一句必須加上
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (!isRecordState) {
camera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
if (success) {
Log.d("TakePicActivity", "success");
w = (int) event.getX();
h = (int) event.getY();
// setLayout(rlFocus,w-50,h-50);
// Rect focusRect = calculateTapArea(w,h,100);
mHandler.obtainMessage(0).sendToTarget();
initCamera(w, h);
camera.cancelAutoFocus();//只有加上了這一句,才會自動對焦。
}
}
});
}
}else if(event.getAction() == MotionEvent.ACTION_UP){
Log.d(TAG, "onTouchEvent: ACTION_UP");
}
else if(event.getAction() == MotionEvent.ACTION_MOVE){
Log.d(TAG, "onTouchEvent: ACTION_MOVE");
}
return super.onTouchEvent(event);
}
/*
* 覆寫返回鍵監聽
*/
@Override
public void onBackPressed() {
if (mMediaRecorder != null) {
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
// videoRename();
}
finish();
}
@Override
protected void onPause() {
super.onPause();
onBackPressed();
}
View view;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
flContent.invalidate();
view = new MyView(TakePicActivity.this, w, h);
flContent.addView(view);
mHandler.sendEmptyMessageDelayed(1, 1000);//使選框停留1秒後消失
break;
case 1:
flContent.removeView(view);
break;
}
}
};
/*
* 設定控制元件所在的位置YY,並且不改變寬高,
* XY為絕對位置
*/
public void setLayout(View view, int x, int y) {
ViewGroup.MarginLayoutParams margin = new ViewGroup.MarginLayoutParams(view.getLayoutParams());
margin.setMargins(x, y, x + margin.width, y + margin.height);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(margin);
view.setLayoutParams(layoutParams);
}
File out;
/*
* 生成video檔名字
*/
protected void videoRename() {
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/hfdatabase/video/0/";
String fileName = new SimpleDateFormat("yyyyMMddHHmmss")
.format(new Date()) + ".mp4";
out = new File(path);
if (!out.exists()) {
out.mkdirs();
}
out = new File(path, fileName);
if (mRecAudioFile.exists())
mRecAudioFile.renameTo(out);
}
/*
* 訊息提示
*/
private Toast toast;
public void showMsg(String arg) {
if (toast == null) {
toast = Toast.makeText(this, arg, Toast.LENGTH_SHORT);
} else {
toast.cancel();
toast.setText(arg);
}
toast.show();
}
/*
* 格式化時間
*/
public String format(int i) {
String s = i + "";
if (s.length() == 1) {
s = "0" + s;
}
return s;
}
/*
* 定時器設定,實現計時
*/
private Handler handler = new Handler();
private Runnable task = new Runnable() {
public void run() {
if (bool) {
handler.postDelayed(this, 1000);
second++;
if (second >= 60) {
minute++;
second = second % 60;
}
if (minute >= 60) {
hour++;
minute = minute % 60;
}
timer.setText(format(hour) + ":" + format(minute) + ":" + format(second));
}
}
};
private void startAnimator() {
circleProgress.setVisibility(View.VISIBLE);
animator = ObjectAnimator.ofInt(circleProgress, "progress", progress);
animator.setDuration(60000);
animator.setInterpolator(new LinearInterpolator());
animator.start();
}
/**
* 釋放攝像頭資源
*/
private void freeCameraResource() {
if (camera != null) {
camera.setPreviewCallback(null);
camera.stopPreview();
camera.lock();
camera.release();
camera = null;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
freeCameraResource();
if(mMediaRecorder != null){
mMediaRecorder.release();
mMediaRecorder = null;
}
}
}
顯示圖片或視訊:
ShowPicActivity.java
package com.haier.uhome.appliance.newVersion.module.messageboard;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class ShowPicActivity extends AppCompatActivity {
private final static String ALBUM_PATH = Environment.getExternalStorageDirectory() + "/download_img/";
private static final String TAG = "ShowPicActivity";
String imgName;
ImageView iv_play;
@BindView(R.id.iv_back2)
ImageView ivBack2;
@BindView(R.id.iv_confirm)
ImageView ivConfirm;
@BindView(R.id.tv_repeat)
TextView tvRepeat;
@BindView(R.id.rl_confirm)
RelativeLayout rlConfirm;
String videoPath;
@BindView(R.id.sfv_display)
SurfaceView sfvDisplay;
private SurfaceHolder sfh_display2;
MediaPlayer player;
boolean isRecord = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_pic);
ButterKnife.bind(this);
iv_play = (ImageView) findViewById(R.id.iv_playPic);
Intent intent = getIntent();
Bundle data = intent.getExtras();
if (data.getBoolean("isRecord")) {
isRecord = true;
videoPath = data.getString("video_path");
iv_play.setVisibility(View.GONE);
sfvDisplay.setVisibility(View.VISIBLE);
Log.d(TAG, "videoPath=" + videoPath);
showVideo();
} else {
isRecord = false;
iv_play.setVisibility(View.VISIBLE);
sfvDisplay.setVisibility(View.GONE);
setImageBitmap(data.getByteArray("bytes"));
}
}
/**
* 將MainActivity傳過來的圖片顯示在介面當中
*
* @param bytes
*/
public void setImageBitmap(byte[] bytes) {
Bitmap cameraBitmap = byte2Bitmap();
// 根據拍攝的方向旋轉影象(縱向拍攝時要需要將影象選擇90度)
Matrix matrix = new Matrix();
matrix.setRotate(TakePicActivity.getPreviewDegree(this));
cameraBitmap = Bitmap
.createBitmap(cameraBitmap, 0, 0, cameraBitmap.getWidth(),
cameraBitmap.getHeight(), matrix, true);
imgName = Calendar.getInstance().getTimeInMillis() + ".jpg";
saveFile(cameraBitmap, imgName);
iv_play.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv_play.setImageBitmap(cameraBitmap);
}
//儲存圖片到本地
public void saveFile(Bitmap bm, String imgName) {
File dirFile = new File(ALBUM_PATH);
if (!dirFile.exists()) {
dirFile.mkdir();
}
File myFile = new File(ALBUM_PATH + imgName);
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myFile));
bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* 從Bundle物件中獲取資料
*
* @return
*/
public byte[] getImageFormBundle() {
Intent intent = getIntent();
Bundle data = intent.getExtras();
byte[] bytes = data.getByteArray("bytes");
return bytes;
}
/**
* 將位元組陣列的圖形資料轉換為Bitmap
*
* @return
*/
private Bitmap byte2Bitmap() {
byte[] data = getImageFormBundle();
// 將byte陣列轉換成Bitmap物件
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
return bitmap;
}
@OnClick({R.id.iv_back2, R.id.iv_confirm, R.id.tv_repeat})
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv_back2:
finish();
break;
case R.id.iv_confirm:
Intent i = new Intent(this, MainMessageBoard.class);
if(isRecord){
i.putExtra("toMainPath", videoPath);
}else{
i.putExtra("toMainPath", ALBUM_PATH + imgName);
}
i.putExtra("isRecord",isRecord);
//要啟動的activity已經在當前的任務中,那麼在該activity之上的activity都會關閉,並且intent會傳遞給在棧頂的activity
//如果 Activity 已經是執行在 Task 的 top,則該 Activity 將不會再被啟動
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
break;
case R.id.tv_repeat:
finish();
break;
}
}
//顯示並播放錄製的視訊
public void showVideo(){
sfh_display2 = sfvDisplay.getHolder();
sfh_display2.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDisplay(sfh_display2);
try {
player.setDataSource(videoPath);
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
});
sfh_display2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
圓形進度條
package com.haier.uhome.appliance.newVersion.module.messageboard.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by wangchm on 2017/1/23 0023.
*/
public class CircleProgressView extends View {
private static final String TAG = "CircleProgressView";
private int mMaxProgress = 100;
private int mProgress = 100;
private final int mCircleLineStrokeWidth = 22;
private final int mTxtStrokeWidth = 2;
// 畫圓所在的距形區域
private final RectF mRectF;
private final Paint mPaint;
private final Context mContext;
private String mTxtHint1;
private String mTxtHint2;
private int bgColor;
private int progressColor;
public CircleProgressView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mRectF = new RectF();
mPaint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = this.getWidth();
int height = this.getHeight();
if (width != height) {
int min = Math.min(width, height);
width = min;
height = min;
}
// 設定畫筆相關屬性
mPaint.setAntiAlias(true);
// mPaint.setColor(Color.GRAY);
mPaint.setColor(bgColor);
canvas.drawColor(Color.TRANSPARENT);
mPaint.setStrokeWidth(mCircleLineStrokeWidth);
mPaint.setStyle(Paint.Style.STROKE);
// 位置
mRectF.left = mCircleLineStrokeWidth / 2; // 左上角x
mRectF.top = mCircleLineStrokeWidth / 2; // 左上角y
mRectF.right = width - mCircleLineStrokeWidth / 2; // 左下角x
mRectF.bottom = height - mCircleLineStrokeWidth / 2; // 右下角y
// 繪製圓圈,進度條背景
canvas.drawArc(mRectF, -90, 360, false, mPaint);
// mPaint.setColor(Color.RED);
mPaint.setColor(progressColor);
canvas.drawArc(mRectF, -90, ((float) mProgress / mMaxProgress) * 360, false, mPaint);
// 繪製進度文案顯示
mPaint.setStrokeWidth(mTxtStrokeWidth);
String text = mProgress + "%";
int textHeight = height / 4;
mPaint.setTextSize(textHeight);
int textWidth = (int) mPaint.measureText(text, 0, text.length());
mPaint.setStyle(Paint.Style.FILL);
canvas.drawText(text, width / 2 - textWidth / 2, height / 2 + textHeight / 2, mPaint);
if (!TextUtils.isEmpty(mTxtHint1)) {
mPaint.setStrokeWidth(mTxtStrokeWidth);
text = mTxtHint1;
textHeight = height / 8;
mPaint.setTextSize(textHeight);
mPaint.setColor(Color.rgb(0x99, 0x99, 0x99));
textWidth = (int) mPaint.measureText(text, 0, text.length());
mPaint.setStyle(Paint.Style.FILL);
canvas.drawText(text, width / 2 - textWidth / 2, height / 4 + textHeight / 2, mPaint);
}
if (!TextUtils.isEmpty(mTxtHint2)) {
mPaint.setStrokeWidth(mTxtStrokeWidth);
text = mTxtHint2;
textHeight = height / 8;
mPaint.setTextSize(textHeight);
textWidth = (int) mPaint.measureText(text, 0, text.length());
mPaint.setStyle(Paint.Style.FILL);
canvas.drawText(text, width / 2 - textWidth / 2, 3 * height / 4 + textHeight / 2, mPaint);
}
}
public int getMaxProgress() {
return mMaxProgress;
}
public void setMaxProgress(int maxProgress) {
this.mMaxProgress = maxProgress;
}
public void setProgress(int progress) {
this.mProgress = progress;
this.invalidate();
}
public int getmProgress(){
return mProgress;
}
public void setProgressNotInUiThread(int progress) {
this.mProgress = progress;
this.postInvalidate();
}
public String getmTxtHint1() {
return mTxtHint1;
}
public void setmTxtHint1(String mTxtHint1) {
this.mTxtHint1 = mTxtHint1;
}
public String getmTxtHint2() {
return mTxtHint2;
}
public void setmTxtHint2(String mTxtHint2) {
this.mTxtHint2 = mTxtHint2;
}
public int getBgColor() {
return bgColor;
}
public void setBgColor(int bgColor) {
this.bgColor = bgColor;
}
public int getProgressColor() {
return progressColor;
}
public void setProgressColor(int progressColor) {
this.progressColor = progressColor;
}
}