国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

Android 自定義view仿微信相機單擊拍照長按錄視頻按鈕

2024-07-22 01:17:57
字體:
供稿:網(wǎng)友

Android仿微信相機的拍照按鈕單擊拍照,長按錄視頻。先上效果圖。

這里寫圖片描述
這里寫圖片描述

項目地址:https://github.com/c786909486/PhotoButton2/tree/v1.0

添加依賴

allprojects {    repositories {      ...      maven { url 'https://jitpack.io' }    }  }dependencies {      compile compile 'com.github.c786909486:PhotoButton2:v1.1'  }

長按效果分析

判斷是否為長按,如果是,則擴大外圓,縮小內(nèi)圓。由于要擴大外圓,所以在繪制常態(tài)的外圓時不可將圓的直徑設(shè)置為view的寬度或高度。

outRoundPaint.setAntiAlias(true);    outRoundPaint.setColor(outCircleColor);    if (isLongClick){      canvas.scale(1.2f,1.2f,width/2,height/2);    }    canvas.drawCircle(width/2,height/2, outRaduis, outRoundPaint);if (isLongClick){      canvas.drawCircle(width/2,height/2, innerRaduis /2.0f, innerRoundPaint);      //畫外原環(huán)      mCPaint.setAntiAlias(true);      mCPaint.setColor(progressColor);      mCPaint.setStyle(Paint.Style.STROKE);      mCPaint.setStrokeWidth(circleWidth/2);      RectF rectF = new RectF(0+circleWidth,0+circleWidth,width-circleWidth,height-circleWidth);      canvas.drawArc(rectF,startAngle,mSweepAngle,false,mCPaint);    }else {      canvas.drawCircle(width/2,height/2, innerRaduis, innerRoundPaint);    }

然后通過手勢識別判斷單擊、長按、長按抬起。

mDetector = new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() {      @Override      public boolean onSingleTapConfirmed(MotionEvent e) {        //單擊        isLongClick = false;        if (listener != null) {          listener.onClick(TakePhotoButton.this);        }        return super.onSingleTapConfirmed(e);      }      @Override      public void onLongPress(MotionEvent e) {        //長按        isLongClick = true;        postInvalidate();        if (listener != null) {          listener.onLongClick(TakePhotoButton.this);        }      }    });    mDetector.setIsLongpressEnabled(true); @Override  public boolean onTouchEvent(MotionEvent event) {    mDetector.onTouchEvent(event);    switch(MotionEventCompat.getActionMasked(event)) {      case MotionEvent.ACTION_DOWN:        isLongClick = false;        break;      case MotionEvent.ACTION_UP:      case MotionEvent.ACTION_CANCEL:        if (isLongClick) {          isLongClick = false;          postInvalidate();          if (this.listener != null) {            this.listener.onLongClickUp(this);          }        }        break;    }    return true;  }

自定義接口對各個狀態(tài)進行監(jiān)聽

public interface OnProgressTouchListener {    /**     * 單擊     * @param photoButton     */    void onClick(TakePhotoButton photoButton);    /**     * 長按     * @param photoButton     */    void onLongClick(TakePhotoButton photoButton);    /**     * 長按抬起     * @param photoButton     */    void onLongClickUp(TakePhotoButton photoButton);    void onFinish();  }            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 巫山县| 屏东市| 沁源县| 德州市| 刚察县| 繁峙县| 上饶县| 孝昌县| 平顶山市| 绥化市| 怀宁县| 长春市| 右玉县| 上犹县| 周至县| 慈溪市| 洪湖市| 丽江市| 温州市| 从化市| 筠连县| 高平市| 浮山县| 花莲县| 万宁市| 岳池县| 焦作市| 汝城县| 顺平县| 东乡族自治县| 鹤山市| 大石桥市| 景德镇市| 营口市| 毕节市| 和林格尔县| 荔浦县| 巫山县| 西充县| 金乡县| 开阳县|