├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── attr.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── zhang
│ │ └── myapplication
│ │ ├── MainActivity.java
│ │ └── VideoControlView.java
├── build.gradle
├── proguard-rules.pro
└── app.iml
├── .gradle
├── buildOutputCleanup
│ ├── built.bin
│ ├── cache.properties.lock
│ └── cache.properties
└── 4.1
│ ├── fileChanges
│ └── last-build.bin
│ ├── javaCompile
│ ├── taskJars.bin
│ ├── classAnalysis.bin
│ ├── jarAnalysis.bin
│ ├── javaCompile.lock
│ └── taskHistory.bin
│ ├── fileHashes
│ ├── fileHashes.bin
│ ├── fileHashes.lock
│ └── resourceHashesCache.bin
│ ├── fileContent
│ └── fileContent.lock
│ └── taskHistory
│ ├── fileSnapshots.bin
│ ├── taskHistory.bin
│ └── taskHistory.lock
├── settings.gradle
├── 1.gif
├── .gitattributes
├── .idea
├── encodings.xml
├── vcs.xml
├── modules.xml
├── libraries
│ ├── com_android_support_support_v4_25_3_1.xml
│ ├── com_android_support_appcompat_v7_25_3_1.xml
│ ├── com_zhang_lamemp3_lib_lame_1_0_0.xml
│ ├── com_android_support_support_compat_25_3_1.xml
│ ├── com_android_support_support_core_ui_25_3_1.xml
│ ├── com_android_support_support_fragment_25_3_1.xml
│ ├── com_android_support_support_core_utils_25_3_1.xml
│ ├── com_android_support_support_media_compat_25_3_1.xml
│ ├── com_android_support_support_vector_drawable_25_3_1.xml
│ ├── com_android_support_animated_vector_drawable_25_3_1.xml
│ └── com_android_support_support_annotations_25_3_1_jar.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── .gitignore
├── local.properties
├── gradle.properties
├── demoa.iml
├── gradlew.bat
├── gradlew
├── LICENSE
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/built.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.gradle/4.1/fileChanges/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties.lock:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/1.gif
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 23 17:12:14 GMT+08:00 2018
2 | gradle.version=4.1
3 |
--------------------------------------------------------------------------------
/.gradle/4.1/javaCompile/taskJars.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/javaCompile/taskJars.bin
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/.gradle/4.1/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/4.1/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/.gradle/4.1/fileContent/fileContent.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/fileContent/fileContent.lock
--------------------------------------------------------------------------------
/.gradle/4.1/javaCompile/classAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/javaCompile/classAnalysis.bin
--------------------------------------------------------------------------------
/.gradle/4.1/javaCompile/jarAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/javaCompile/jarAnalysis.bin
--------------------------------------------------------------------------------
/.gradle/4.1/javaCompile/javaCompile.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/javaCompile/javaCompile.lock
--------------------------------------------------------------------------------
/.gradle/4.1/javaCompile/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/javaCompile/taskHistory.bin
--------------------------------------------------------------------------------
/.gradle/4.1/taskHistory/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/taskHistory/fileSnapshots.bin
--------------------------------------------------------------------------------
/.gradle/4.1/taskHistory/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/taskHistory/taskHistory.bin
--------------------------------------------------------------------------------
/.gradle/4.1/taskHistory/taskHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/taskHistory/taskHistory.lock
--------------------------------------------------------------------------------
/.gradle/4.1/fileHashes/resourceHashesCache.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/.gradle/4.1/fileHashes/resourceHashesCache.bin
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangYanGitHub/demoa/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 23 17:12:04 GMT+08:00 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 |
21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22 | hs_err_pid*
23 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_v4_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Tue Jan 23 17:12:04 GMT+08:00 2018
11 | ndk.dir=D\:\\android\\ndk-bundle
12 | sdk.dir=D\:\\android
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_appcompat_v7_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_zhang_lamemp3_lib_lame_1_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_compat_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_core_ui_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_fragment_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_core_utils_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_media_compat_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.zhang.myapplication"
7 | minSdkVersion 17
8 | targetSdkVersion 25
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.zhang.lamemp3:lib_lame:1.0.0'
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_vector_drawable_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_animated_vector_drawable_25_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_annotations_25_3_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/demoa.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhang/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhang.myapplication;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | private final String TAG = MainActivity.class.getName();
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | VideoControlView controlView = (VideoControlView) findViewById(R.id.control_view);
18 |
19 | controlView.setOnRecordListener(new VideoControlView.OnRecordListener() {
20 | @Override
21 | public void onShortClick() {
22 | Toast.makeText(MainActivity.this, "点击事件", Toast.LENGTH_SHORT).show();
23 | Log.i(TAG,"点击事件");
24 |
25 | }
26 |
27 | @Override
28 | public void OnRecordStartClick() {
29 | Toast.makeText(MainActivity.this, "开始录制", Toast.LENGTH_SHORT).show();
30 | Log.i(TAG,"开始录制");
31 | }
32 |
33 | @Override
34 | public void OnFinish(int resultCode) {
35 | switch (resultCode) {
36 | case 0:
37 | Toast.makeText(MainActivity.this, "录制时间过短", Toast.LENGTH_SHORT).show();
38 | Log.i(TAG,"录制时间过短");
39 | break;
40 | case 1:
41 | Toast.makeText(MainActivity.this, "录制结束", Toast.LENGTH_SHORT).show();
42 | Log.i(TAG,"录制结束");
43 | break;
44 | }
45 |
46 | }
47 | });
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/app/src/main/java/com/zhang/myapplication/VideoControlView.java:
--------------------------------------------------------------------------------
1 | package com.zhang.myapplication;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.RectF;
12 | import android.os.Message;
13 | import android.support.annotation.Nullable;
14 | import android.util.AttributeSet;
15 | import android.util.Log;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 |
19 | import java.lang.ref.WeakReference;
20 |
21 | /**
22 | * Created by 张俨 on 2018/1/24.
23 | */
24 |
25 | public class VideoControlView extends View {
26 |
27 | private static final String TAG = VideoControlView.class.getName();
28 | /**
29 | * 视频录制最长时间 秒
30 | */
31 | private static final int VIDEO_RECORD_DEFAULT_MAX_TIME = 10;
32 | /**
33 | * 视频录制最小时间 秒
34 | */
35 | private final int VIDEO_RECORD_DEFAULT_MIN_TIME = 1;
36 | /**
37 | * 视频录制内圆半径
38 | */
39 | private final float VIDEO_RECORD_DEFAULT_INNER_CIRCLE_RADIUS = 5f;
40 | /**
41 | * 视频录制外圆半径
42 | */
43 | private final float VIDEO_RECORD_DEFAULT_EXCIRCLE_RADIUS = 12f;
44 | /**
45 | * 视频录制圆环默认颜色
46 | */
47 | private final int VIDEO_RECORD_DEFAULT_ANNULUS_COLOR = Color.parseColor("#FFFFFF");
48 | /**
49 | * 视频录制内圆默认颜色
50 | */
51 | private final int VIDEO_RECORD_DEFAULT_INNER_CIRCLE_COLOR = Color.parseColor("#F5F5F5");
52 | /**
53 | * 视频录制进度默认颜色
54 | */
55 | private final int VIDEO_RECORD_DEFAULT_PROGRESS_COLOR = Color.parseColor("#00A653");
56 |
57 | /**
58 | * 外圆放大倍数
59 | */
60 | private final float EXCICLE_MAGNIFICATION = 1.25f;
61 | private float excicleMagnification;
62 |
63 | /**
64 | * 内圆缩小倍数
65 | */
66 | private final float INNER_CIRCLE_SHRINKS = 0.75f;
67 | private float innerCircleShrinks;
68 | /**
69 | * 视频实际录制最大时间
70 | */
71 | private int mMaxTime;
72 | /**
73 | * 视频实际录制最小时间
74 | */
75 | private int mMinTime;
76 | /**
77 | * 外圆半径
78 | */
79 | private float mExCircleRadius, mInitExCircleRadius;
80 | /**
81 | * 内圆半径
82 | */
83 | private float mInnerCircleRadius, mInitInnerRadius;
84 | /**
85 | * 外圆颜色
86 | */
87 | private int mAnnulusColor;
88 | /**
89 | * 内圆颜色
90 | */
91 | private int mInnerCircleColor;
92 | /**
93 | * 进度条颜色
94 | */
95 | private int mProgressColor;
96 | /**
97 | * 外圆画笔
98 | */
99 | private Paint mExCirclePaint;
100 | /**
101 | * 内圆画笔
102 | */
103 | private Paint mInnerCirclePaint;
104 | /**
105 | * 进度条画笔
106 | */
107 | private Paint mProgressPaint;
108 |
109 | /**
110 | * 是否正在录制
111 | */
112 | private boolean isRecording = false;
113 | /**
114 | * 进度条值动画
115 | */
116 | private ValueAnimator mProgressAni;
117 |
118 | /**
119 | * 开始录制时间
120 | */
121 | private long mStartTime = 0;
122 | /**
123 | * 录制 结束时间
124 | */
125 | private long mEndTime = 0;
126 | /**
127 | * 长按最短时间 单位毫秒
128 | */
129 | public long LONG_CLICK_MIN_TIME = 800;
130 | private Context context;
131 | private int mWidth;
132 | private int mHeight;
133 | private float mCurrentProgress;
134 | private MHandler handler = new MHandler(this);
135 |
136 | public VideoControlView(Context context) {
137 | this(context, null);
138 | }
139 |
140 |
141 | public VideoControlView(Context context, @Nullable AttributeSet attrs) {
142 | this(context, attrs, 0);
143 | }
144 |
145 | public VideoControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
146 | super(context, attrs, defStyleAttr);
147 | initData(context, attrs);
148 | }
149 |
150 | /**
151 | * 获取布局属性
152 | *
153 | * @param context
154 | * @param attrs
155 | */
156 | private void initData(Context context, AttributeSet attrs) {
157 | this.context = context;
158 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VideoControlView);
159 | mMaxTime = a.getInt(R.styleable.VideoControlView_maxTime, VIDEO_RECORD_DEFAULT_MAX_TIME);
160 | mMinTime = a.getInt(R.styleable.VideoControlView_minTime, VIDEO_RECORD_DEFAULT_MIN_TIME);
161 |
162 | excicleMagnification = a.getFloat(R.styleable.VideoControlView_excicleMagnification
163 | , EXCICLE_MAGNIFICATION);
164 | innerCircleShrinks = a.getFloat(R.styleable.VideoControlView_excicleMagnification
165 | , INNER_CIRCLE_SHRINKS);
166 | if (excicleMagnification < 1) {
167 | throw new RuntimeException("外圆放大倍数必须大于1");
168 | }
169 | if (innerCircleShrinks > 1) {
170 | throw new RuntimeException("内圆缩小倍数必须小于1");
171 | }
172 |
173 | mInitExCircleRadius = mExCircleRadius = a.getDimension(R.styleable.VideoControlView_excircleRadius
174 | , VIDEO_RECORD_DEFAULT_EXCIRCLE_RADIUS);
175 | mInitInnerRadius = mInnerCircleRadius = a.getDimension(R.styleable.VideoControlView_innerCircleRadius
176 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_RADIUS);
177 |
178 | mAnnulusColor = a.getColor(R.styleable.VideoControlView_annulusColor
179 | , VIDEO_RECORD_DEFAULT_ANNULUS_COLOR);
180 | mInnerCircleColor = a.getColor(R.styleable.VideoControlView_innerCircleColor
181 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_COLOR);
182 | mProgressColor = a.getColor(R.styleable.VideoControlView_progressColor
183 | , VIDEO_RECORD_DEFAULT_PROGRESS_COLOR);
184 | a.recycle();
185 | //初始化外圆画笔
186 | mExCirclePaint = new Paint();
187 | mExCirclePaint.setColor(mAnnulusColor);
188 |
189 | //初始化内圆画笔
190 | mInnerCirclePaint = new Paint();
191 | mInnerCirclePaint.setColor(mInnerCircleColor);
192 |
193 | //初始化进度条画笔
194 | mProgressPaint = new Paint();
195 | mProgressPaint.setColor(mProgressColor);
196 | mProgressPaint.setStrokeWidth(mExCircleRadius - mInnerCircleRadius);
197 | mProgressPaint.setStyle(Paint.Style.STROKE);
198 | //进度条的属性动画
199 | mProgressAni = ValueAnimator.ofFloat(0, 360f);
200 | mProgressAni.setDuration(mMaxTime * 1000);
201 |
202 | }
203 |
204 | @Override
205 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
206 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
207 | mWidth = MeasureSpec.getSize(widthMeasureSpec);
208 | mHeight = MeasureSpec.getSize(heightMeasureSpec);
209 |
210 | if (mExCircleRadius * 2 * excicleMagnification > Math.min(mWidth, mHeight)) {
211 | throw new RuntimeException("设置的半径的2 * " + excicleMagnification + "倍要小于宽和高中的最小值的");
212 | }
213 | if (mInnerCircleRadius > mExCircleRadius) {
214 | throw new RuntimeException("设置的内圆半径要小于外圆半径");
215 | } else if (mInnerCircleRadius == mExCircleRadius) {
216 | Log.e(TAG, "mInnerCircleRadius == mExCircleRadius 你将看不到进度条");
217 | }
218 | }
219 |
220 | @Override
221 | protected void onDraw(Canvas canvas) {
222 | super.onDraw(canvas);
223 | //画外圆
224 | canvas.drawCircle(mWidth / 2, mHeight / 2, mExCircleRadius, mExCirclePaint);
225 | //画内圆
226 | canvas.drawCircle(mWidth / 2, mHeight / 2, mInnerCircleRadius, mInnerCirclePaint);
227 | if (isRecording) {
228 | drawProgress(canvas);
229 | }
230 | }
231 |
232 | /**
233 | * 绘制圆形进度条
234 | * Draw a circular progress bar.
235 | *
236 | * @param canvas
237 | */
238 | private void drawProgress(Canvas canvas) {
239 | final RectF rectF = new RectF(
240 | mWidth / 2 - (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
241 | mHeight / 2 - (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
242 | mWidth / 2 + (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
243 | mHeight / 2 + (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2));
244 | canvas.drawArc(rectF, -90, mCurrentProgress, false, mProgressPaint);
245 | }
246 |
247 | @Override
248 | public boolean performClick() {
249 | return false;
250 | }
251 |
252 | @Override
253 | public boolean onTouchEvent(MotionEvent event) {
254 | switch (event.getAction()) {
255 | case MotionEvent.ACTION_DOWN:
256 | isRecording = true;
257 | mStartTime = System.currentTimeMillis();
258 | handler.sendEmptyMessageDelayed(MSG_START_LONG_RECORD, LONG_CLICK_MIN_TIME);
259 | break;
260 | case MotionEvent.ACTION_UP:
261 | case MotionEvent.ACTION_CANCEL:
262 | isRecording = false;
263 | mEndTime = System.currentTimeMillis();
264 | if (mEndTime - mStartTime < LONG_CLICK_MIN_TIME) {
265 | //Long press the action time too short.
266 | if (handler.hasMessages(MSG_START_LONG_RECORD)) {
267 | handler.removeMessages(MSG_START_LONG_RECORD);
268 | }
269 | if (onRecordListener != null) {
270 | onRecordListener.onShortClick();
271 | }
272 |
273 | } else {
274 |
275 | if (mProgressAni != null && mProgressAni.getCurrentPlayTime() / 1000 < mMinTime) {
276 | //The recording time is less than the minimum recording time.
277 | if (onRecordListener != null) {
278 | onRecordListener.OnFinish(0);
279 | }
280 | } else {
281 | //The end of the normal
282 | if (onRecordListener != null) {
283 | onRecordListener.OnFinish(1);
284 | }
285 | }
286 | }
287 | mExCircleRadius = mInitExCircleRadius;
288 | mInnerCircleRadius = mInitInnerRadius;
289 | mProgressAni.cancel();
290 | startAnimation(
291 | mInitExCircleRadius * excicleMagnification,
292 | mInitExCircleRadius,
293 | mInitInnerRadius * innerCircleShrinks,
294 | mInitInnerRadius);
295 | break;
296 | case MotionEvent.ACTION_MOVE:
297 | break;
298 | }
299 | return true;
300 | }
301 |
302 | /**
303 | * 设置外圆 内圆缩放动画
304 | *
305 | * @param bigStart
306 | * @param bigEnd
307 | * @param smallStart
308 | * @param smallEnd
309 | */
310 | private void startAnimation(float bigStart, float bigEnd, float smallStart, float smallEnd) {
311 | ValueAnimator bigObjAni = ValueAnimator.ofFloat(bigStart, bigEnd);
312 | bigObjAni.setDuration(150);
313 | bigObjAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
314 | @Override
315 | public void onAnimationUpdate(ValueAnimator animation) {
316 | mExCircleRadius = (float) animation.getAnimatedValue();
317 | invalidate();
318 | }
319 | });
320 |
321 | ValueAnimator smallObjAni = ValueAnimator.ofFloat(smallStart, smallEnd);
322 | smallObjAni.setDuration(150);
323 | smallObjAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
324 | @Override
325 | public void onAnimationUpdate(ValueAnimator animation) {
326 | mInnerCircleRadius = (float) animation.getAnimatedValue();
327 | invalidate();
328 | }
329 | });
330 |
331 | bigObjAni.start();
332 | smallObjAni.start();
333 |
334 | smallObjAni.addListener(new Animator.AnimatorListener() {
335 | @Override
336 | public void onAnimationStart(Animator animation) {
337 |
338 | }
339 |
340 | @Override
341 | public void onAnimationEnd(Animator animation) {
342 | //开始绘制圆形进度
343 | if (isRecording) {
344 | startAniProgress();
345 | }
346 |
347 | }
348 |
349 |
350 | @Override
351 | public void onAnimationCancel(Animator animation) {
352 |
353 | }
354 |
355 | @Override
356 | public void onAnimationRepeat(Animator animation) {
357 |
358 | }
359 | });
360 |
361 | }
362 |
363 | /**
364 | * 开始圆形进度值动画
365 | */
366 | private void startAniProgress() {
367 | if (mProgressAni == null) {
368 | return;
369 | }
370 | mProgressAni.start();
371 | mProgressAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
372 | @Override
373 | public void onAnimationUpdate(ValueAnimator animation) {
374 | mCurrentProgress = (float) animation.getAnimatedValue();
375 | invalidate();
376 | }
377 | });
378 |
379 | mProgressAni.addListener(new AnimatorListenerAdapter() {
380 |
381 | @Override
382 | public void onAnimationEnd(Animator animation) {
383 | isRecording = false;
384 | mCurrentProgress = 0;
385 | invalidate();
386 | }
387 | });
388 | }
389 |
390 | /**
391 | * 设置最大录制时间
392 | *
393 | * @param mMaxTime 最大录制时间 秒
394 | */
395 | public void setMaxTime(int mMaxTime) {
396 | this.mMaxTime = mMaxTime;
397 | }
398 |
399 | /**
400 | * 设置最小录制时间
401 | *
402 | * @param mMinTime 最小录制时间 秒
403 | */
404 | public void setMinTime(int mMinTime) {
405 | this.mMinTime = mMinTime;
406 | }
407 |
408 | /**
409 | * 设置外圆半径
410 | *
411 | * @param mExCircleRadius 外圆半径
412 | */
413 | public void setExCircleRadius(float mExCircleRadius) {
414 | this.mExCircleRadius = mExCircleRadius;
415 | }
416 |
417 | /**
418 | * 设置内圆半径
419 | *
420 | * @param mInnerCircleRadius 内圆半径
421 | */
422 | public void setInnerCircleRadius(float mInnerCircleRadius) {
423 | this.mInnerCircleRadius = mInnerCircleRadius;
424 | }
425 |
426 | /**
427 | * 设置颜色外圆颜色
428 | *
429 | * @param mAnnulusColor
430 | */
431 | public void setAnnulusColor(int mAnnulusColor) {
432 | this.mAnnulusColor = mAnnulusColor;
433 | mExCirclePaint.setColor(mAnnulusColor);
434 | }
435 |
436 | /**
437 | * 设置进度圆环颜色
438 | *
439 | * @param mProgressColor
440 | */
441 | public void setProgressColor(int mProgressColor) {
442 | this.mProgressColor = mProgressColor;
443 | mProgressPaint.setColor(mProgressColor);
444 | }
445 |
446 | /**
447 | * 设置内圆颜色
448 | *
449 | * @param mInnerCircleColor
450 | */
451 | public void setInnerCircleColor(int mInnerCircleColor) {
452 | this.mInnerCircleColor = mInnerCircleColor;
453 | mInnerCirclePaint.setColor(mInnerCircleColor);
454 | }
455 |
456 | private OnRecordListener onRecordListener;
457 |
458 | public void setOnRecordListener(OnRecordListener onRecordListener) {
459 | this.onRecordListener = onRecordListener;
460 | }
461 |
462 | @Override
463 | public void setOnClickListener(@Nullable OnClickListener l) {
464 | super.setOnClickListener(l);
465 | }
466 |
467 | public static abstract class OnRecordListener {
468 |
469 | /**
470 | * 点击拍照
471 | */
472 | public void onShortClick() {
473 | }
474 |
475 | /**
476 | * 开始录制
477 | */
478 | public abstract void OnRecordStartClick();
479 |
480 | /**
481 | * 录制结束
482 | *
483 | * @param resultCode 0 录制时间太短 1 正常结束
484 | */
485 | public abstract void OnFinish(int resultCode);
486 | }
487 |
488 | /**
489 | * 长按录制
490 | */
491 | private static final int MSG_START_LONG_RECORD = 0x1;
492 |
493 |
494 | static class MHandler extends android.os.Handler {
495 |
496 | private WeakReference weakReference = null;
497 |
498 | public MHandler(VideoControlView controlView) {
499 | weakReference = new WeakReference(controlView);
500 | }
501 |
502 | @Override
503 | public void handleMessage(Message msg) {
504 | super.handleMessage(msg);
505 | if (weakReference == null || weakReference.get() == null) return;
506 | final VideoControlView videoControlView = weakReference.get();
507 | switch (msg.what) {
508 | case VideoControlView.MSG_START_LONG_RECORD:
509 | if (videoControlView.onRecordListener != null) {
510 | videoControlView.onRecordListener.OnRecordStartClick();
511 | }
512 | //内外圆动画,内圆缩小,外圆放大
513 | videoControlView.startAnimation(videoControlView.mExCircleRadius,
514 | videoControlView.mExCircleRadius * videoControlView.excicleMagnification,
515 | videoControlView.mInnerCircleRadius,
516 | videoControlView.mInnerCircleRadius * videoControlView.excicleMagnification);
517 | break;
518 | }
519 | }
520 | }
521 | }
522 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android 自定义View 仿微信录制 长按录制 点击拍照
2 | # 仿微信视频录制按钮 长按录制 点击拍照
3 |
4 | 最近项目中用到这样的功能 在这里只单说这个View的定制
5 |
6 | - **长按录制视频 在这里实现长按最短时间的定制**
7 | - **点击拍照**
8 | - **长按过程中有圆弧进度条的绘制**
9 | - **长按事件触发时 放大外圆 缩小内圆 ,视频录制结束时 缩小外圆,放大内圆,在这里用属性动画实现**
10 | - **效果图**
11 |
12 | -----------------
13 | 
14 | -----------------
15 | ### 先看看需要的定制的属性
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | * 初始化的获取一下
39 |
40 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VideoControlView);
41 | mMaxTime = a.getInt(R.styleable.VideoControlView_maxTime, VIDEO_RECORD_DEFAULT_MAX_TIME);
42 | mMinTime = a.getInt(R.styleable.VideoControlView_minTime, VIDEO_RECORD_DEFAULT_MIN_TIME);
43 | excicleMagnification = a.getFloat(R.styleable.VideoControlView_excicleMagnification
44 | , EXCICLE_MAGNIFICATION);
45 | innerCircleShrinks = a.getFloat(R.styleable.VideoControlView_excicleMagnification
46 | , INNER_CIRCLE_SHRINKS);
47 | if (excicleMagnification < 1) {
48 | throw new RuntimeException("外圆放大倍数必须大于1");
49 | }
50 | if (innerCircleShrinks > 1) {
51 | throw new RuntimeException("内圆缩小倍数必须小于1");
52 | }
53 |
54 | mInitExCircleRadius = mExCircleRadius = a.getDimension(R.styleable.VideoControlView_excircleRadius
55 | , VIDEO_RECORD_DEFAULT_EXCIRCLE_RADIUS);
56 | mInitInnerRadius = mInnerCircleRadius = a.getDimension(R.styleable.VideoControlView_innerCircleRadius
57 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_RADIUS);
58 |
59 | mAnnulusColor = a.getColor(R.styleable.VideoControlView_annulusColor
60 | , VIDEO_RECORD_DEFAULT_ANNULUS_COLOR);
61 | mInnerCircleColor = a.getColor(R.styleable.VideoControlView_innerCircleColor
62 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_COLOR);
63 | mProgressColor = a.getColor(R.styleable.VideoControlView_progressColor
64 | , VIDEO_RECORD_DEFAULT_PROGRESS_COLOR);
65 | a.recycle();
66 |
67 | * 初始化画笔
68 |
69 | //初始化外圆画笔
70 | mExCirclePaint = new Paint();
71 | mExCirclePaint.setColor(mAnnulusColor);
72 |
73 | //初始化内圆画笔
74 | mInnerCirclePaint = new Paint();
75 | mInnerCirclePaint.setColor(mInnerCircleColor);
76 |
77 | //初始化进度条画笔
78 | mProgressPaint = new Paint();
79 | mProgressPaint.setColor(mProgressColor);
80 | mProgressPaint.setStrokeWidth(mExCircleRadius - mInnerCircleRadius );
81 | mProgressPaint.setStyle(Paint.Style.STROKE);
82 |
83 | * onMeasrue 方法里面获取下View 的宽高 和始终的参数的合法性
84 |
85 | @Override
86 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
87 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
88 | mWidth = MeasureSpec.getSize(widthMeasureSpec);
89 | mHeight = MeasureSpec.getSize(heightMeasureSpec);
90 |
91 | if (mExCircleRadius * 2 * excicleMagnification > Math.min(mWidth, mHeight)) {
92 | throw new RuntimeException("设置的半径的2 * " + excicleMagnification + "倍要小于宽和高中的最小值的");
93 | }
94 | if (mInnerCircleRadius > mExCircleRadius) {
95 | throw new RuntimeException("设置的内圆半径要小于外圆半径");
96 | } else if (mInnerCircleRadius == mExCircleRadius) {
97 | Log.e(TAG, "mInnerCircleRadius == mExCircleRadius 你将看不到进度条");
98 | }
99 | }
100 | * 在这里说下点击事件和长按事件 先看代码
101 |
102 | public static abstract class OnRecordListener {
103 |
104 | /**
105 | * 点击拍照
106 | */
107 | public void onShortClick() {
108 | }
109 |
110 | /**
111 | * 开始录制
112 | */
113 | public abstract void OnRecordStartClick();
114 |
115 | /**
116 | * 录制结束
117 | *
118 | * @param resultCode 0 录制时间太短 1 正常结束
119 | */
120 | public abstract void OnFinish(int resultCode);
121 | }
122 |
123 | @Override
124 | public boolean onTouchEvent(MotionEvent event) {
125 | switch (event.getAction()) {
126 | case MotionEvent.ACTION_DOWN:
127 | isRecording = true;
128 | mStartTime = System.currentTimeMillis();
129 | handler.sendEmptyMessageDelayed(MSG_START_LONG_RECORD, LONG_CLICK_MIN_TIME);
130 | break;
131 | case MotionEvent.ACTION_UP:
132 | case MotionEvent.ACTION_CANCEL:
133 | isRecording = false;
134 | mEndTime = System.currentTimeMillis();
135 | if (mEndTime - mStartTime < LONG_CLICK_MIN_TIME) {
136 | //Long press the action time too short.
137 | if (handler.hasMessages(MSG_START_LONG_RECORD)) {
138 | handler.removeMessages(MSG_START_LONG_RECORD);
139 | }
140 | if (onRecordListener != null) {
141 | onRecordListener.onShortClick();
142 | }
143 |
144 | } else {
145 |
146 | if (mProgressAni != null && mProgressAni.getCurrentPlayTime() / 1000 < mMinTime) {
147 | //The recording time is less than the minimum recording time.
148 | if (onRecordListener != null) {
149 | onRecordListener.OnFinish(0);
150 | }
151 | } else {
152 | //The end of the normal
153 | if (onRecordListener != null) {
154 | onRecordListener.OnFinish(1);
155 | }
156 | }
157 | }
158 | mExCircleRadius = mInitExCircleRadius;
159 | mInnerCircleRadius = mInitInnerRadius;
160 | mProgressAni.cancel();
161 | startAnimation(
162 | mInitExCircleRadius * excicleMagnification,
163 | mInitExCircleRadius,
164 | mInitInnerRadius * innerCircleShrinks,
165 | mInitInnerRadius);
166 | break;
167 | case MotionEvent.ACTION_MOVE:
168 | break;
169 | }
170 | return true;
171 | }
172 |
173 | * hander 的代码如下
174 |
175 | static class MHandler extends android.os.Handler {
176 |
177 | private WeakReference weakReference = null;
178 |
179 | public MHandler(VideoControlView controlView) {
180 | weakReference = new WeakReference(controlView);
181 | }
182 |
183 | @Override
184 | public void handleMessage(Message msg) {
185 | super.handleMessage(msg);
186 | if (weakReference == null || weakReference.get() == null) return;
187 | final VideoControlView videoControlView = weakReference.get();
188 | switch (msg.what) {
189 | case VideoControlView.MSG_START_LONG_RECORD:
190 | if (videoControlView.onRecordListener != null) {
191 | videoControlView.onRecordListener.OnRecordStartClick();
192 | }
193 | //内外圆动画,内圆缩小,外圆放大
194 | videoControlView.startAnimation(videoControlView.mExCircleRadius,
195 | videoControlView.mExCircleRadius * videoControlView.excicleMagnification,
196 | videoControlView.mInnerCircleRadius,
197 | videoControlView.mInnerCircleRadius * videoControlView.excicleMagnification);
198 | break;
199 | }
200 | }
201 | }
202 |
203 | * 主要的实现实在ACTION_DOWN 下记录一下当前时间 然后根据长按的最短时间发送一个延时消息 再在ACTION_UP和ACTION_CANCEL里面在获取当前时间 如果时间差小于长按时间 那么就是点击拍照 要移除延时消息, 反之 看表示圆弧进度的动画的执行时间和最小录制时间作比较 如果小 回调一下 resultCode 为0 录制时间太短 ,大了就是正常结束 之后再来一次动画 达到初始状态
204 |
205 | - **看一下全部的代码**
206 |
207 | package com.zhang.myapplication;
208 |
209 | import android.animation.Animator;
210 | import android.animation.AnimatorListenerAdapter;
211 | import android.animation.ValueAnimator;
212 | import android.content.Context;
213 | import android.content.res.TypedArray;
214 | import android.graphics.Canvas;
215 | import android.graphics.Color;
216 | import android.graphics.Paint;
217 | import android.graphics.RectF;
218 | import android.os.Message;
219 | import android.support.annotation.Nullable;
220 | import android.util.AttributeSet;
221 | import android.util.Log;
222 | import android.view.MotionEvent;
223 | import android.view.View;
224 |
225 | import java.lang.ref.WeakReference;
226 |
227 | /**
228 | * Created by 张俨 on 2018/1/24.
229 | */
230 |
231 | public class VideoControlView extends View {
232 |
233 | private static final String TAG = VideoControlView.class.getName();
234 | /**
235 | * 视频录制最长时间 秒
236 | */
237 | private static final int VIDEO_RECORD_DEFAULT_MAX_TIME = 10;
238 | /**
239 | * 视频录制最小时间 秒
240 | */
241 | private final int VIDEO_RECORD_DEFAULT_MIN_TIME = 1;
242 | /**
243 | * 视频录制内圆半径
244 | */
245 | private final float VIDEO_RECORD_DEFAULT_INNER_CIRCLE_RADIUS = 5f;
246 | /**
247 | * 视频录制外圆半径
248 | */
249 | private final float VIDEO_RECORD_DEFAULT_EXCIRCLE_RADIUS = 12f;
250 | /**
251 | * 视频录制圆环默认颜色
252 | */
253 | private final int VIDEO_RECORD_DEFAULT_ANNULUS_COLOR = Color.parseColor("#FFFFFF");
254 | /**
255 | * 视频录制内圆默认颜色
256 | */
257 | private final int VIDEO_RECORD_DEFAULT_INNER_CIRCLE_COLOR = Color.parseColor("#F5F5F5");
258 | /**
259 | * 视频录制进度默认颜色
260 | */
261 | private final int VIDEO_RECORD_DEFAULT_PROGRESS_COLOR = Color.parseColor("#00A653");
262 |
263 | /**
264 | * 外圆放大倍数
265 | */
266 | private final float EXCICLE_MAGNIFICATION = 1.25f;
267 | private float excicleMagnification;
268 |
269 | /**
270 | * 内圆缩小倍数
271 | */
272 | private final float INNER_CIRCLE_SHRINKS = 0.75f;
273 | private float innerCircleShrinks;
274 | /**
275 | * 视频实际录制最大时间
276 | */
277 | private int mMaxTime;
278 | /**
279 | * 视频实际录制最小时间
280 | */
281 | private int mMinTime;
282 | /**
283 | * 外圆半径
284 | */
285 | private float mExCircleRadius, mInitExCircleRadius;
286 | /**
287 | * 内圆半径
288 | */
289 | private float mInnerCircleRadius, mInitInnerRadius;
290 | /**
291 | * 外圆颜色
292 | */
293 | private int mAnnulusColor;
294 | /**
295 | * 内圆颜色
296 | */
297 | private int mInnerCircleColor;
298 | /**
299 | * 进度条颜色
300 | */
301 | private int mProgressColor;
302 | /**
303 | * 外圆画笔
304 | */
305 | private Paint mExCirclePaint;
306 | /**
307 | * 内圆画笔
308 | */
309 | private Paint mInnerCirclePaint;
310 | /**
311 | * 进度条画笔
312 | */
313 | private Paint mProgressPaint;
314 |
315 | /**
316 | * 是否正在录制
317 | */
318 | private boolean isRecording = false;
319 | /**
320 | * 进度条值动画
321 | */
322 | private ValueAnimator mProgressAni;
323 |
324 | /**
325 | * 开始录制时间
326 | */
327 | private long mStartTime = 0;
328 | /**
329 | * 录制 结束时间
330 | */
331 | private long mEndTime = 0;
332 | /**
333 | * 长按最短时间 单位毫秒
334 | */
335 | public long LONG_CLICK_MIN_TIME = 800;
336 | private Context context;
337 | private int mWidth;
338 | private int mHeight;
339 | private float mCurrentProgress;
340 | private MHandler handler = new MHandler(this);
341 |
342 | public VideoControlView(Context context) {
343 | this(context, null);
344 | }
345 |
346 |
347 | public VideoControlView(Context context, @Nullable AttributeSet attrs) {
348 | this(context, attrs, 0);
349 | }
350 |
351 | public VideoControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
352 | super(context, attrs, defStyleAttr);
353 | initData(context, attrs);
354 | }
355 |
356 | /**
357 | * 获取布局属性
358 | *
359 | * @param context
360 | * @param attrs
361 | */
362 | private void initData(Context context, AttributeSet attrs) {
363 | this.context = context;
364 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VideoControlView);
365 | mMaxTime = a.getInt(R.styleable.VideoControlView_maxTime, VIDEO_RECORD_DEFAULT_MAX_TIME);
366 | mMinTime = a.getInt(R.styleable.VideoControlView_minTime, VIDEO_RECORD_DEFAULT_MIN_TIME);
367 |
368 | excicleMagnification = a.getFloat(R.styleable.VideoControlView_excicleMagnification
369 | , EXCICLE_MAGNIFICATION);
370 | innerCircleShrinks = a.getFloat(R.styleable.VideoControlView_excicleMagnification
371 | , INNER_CIRCLE_SHRINKS);
372 | if (excicleMagnification < 1) {
373 | throw new RuntimeException("外圆放大倍数必须大于1");
374 | }
375 | if (innerCircleShrinks > 1) {
376 | throw new RuntimeException("内圆缩小倍数必须小于1");
377 | }
378 |
379 | mInitExCircleRadius = mExCircleRadius = a.getDimension(R.styleable.VideoControlView_excircleRadius
380 | , VIDEO_RECORD_DEFAULT_EXCIRCLE_RADIUS);
381 | mInitInnerRadius = mInnerCircleRadius = a.getDimension(R.styleable.VideoControlView_innerCircleRadius
382 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_RADIUS);
383 |
384 | mAnnulusColor = a.getColor(R.styleable.VideoControlView_annulusColor
385 | , VIDEO_RECORD_DEFAULT_ANNULUS_COLOR);
386 | mInnerCircleColor = a.getColor(R.styleable.VideoControlView_innerCircleColor
387 | , VIDEO_RECORD_DEFAULT_INNER_CIRCLE_COLOR);
388 | mProgressColor = a.getColor(R.styleable.VideoControlView_progressColor
389 | , VIDEO_RECORD_DEFAULT_PROGRESS_COLOR);
390 | a.recycle();
391 | //初始化外圆画笔
392 | mExCirclePaint = new Paint();
393 | mExCirclePaint.setColor(mAnnulusColor);
394 |
395 | //初始化内圆画笔
396 | mInnerCirclePaint = new Paint();
397 | mInnerCirclePaint.setColor(mInnerCircleColor);
398 |
399 | //初始化进度条画笔
400 | mProgressPaint = new Paint();
401 | mProgressPaint.setColor(mProgressColor);
402 | mProgressPaint.setStrokeWidth(mExCircleRadius - mInnerCircleRadius);
403 | mProgressPaint.setStyle(Paint.Style.STROKE);
404 | //进度条的属性动画
405 | mProgressAni = ValueAnimator.ofFloat(0, 360f);
406 | mProgressAni.setDuration(mMaxTime * 1000);
407 |
408 | }
409 |
410 | @Override
411 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
412 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
413 | mWidth = MeasureSpec.getSize(widthMeasureSpec);
414 | mHeight = MeasureSpec.getSize(heightMeasureSpec);
415 |
416 | if (mExCircleRadius * 2 * excicleMagnification > Math.min(mWidth, mHeight)) {
417 | throw new RuntimeException("设置的半径的2 * " + excicleMagnification + "倍要小于宽和高中的最小值的");
418 | }
419 | if (mInnerCircleRadius > mExCircleRadius) {
420 | throw new RuntimeException("设置的内圆半径要小于外圆半径");
421 | } else if (mInnerCircleRadius == mExCircleRadius) {
422 | Log.e(TAG, "mInnerCircleRadius == mExCircleRadius 你将看不到进度条");
423 | }
424 | }
425 |
426 | @Override
427 | protected void onDraw(Canvas canvas) {
428 | super.onDraw(canvas);
429 | //画外圆
430 | canvas.drawCircle(mWidth / 2, mHeight / 2, mExCircleRadius, mExCirclePaint);
431 | //画内圆
432 | canvas.drawCircle(mWidth / 2, mHeight / 2, mInnerCircleRadius, mInnerCirclePaint);
433 | if (isRecording) {
434 | drawProgress(canvas);
435 | }
436 | }
437 |
438 | /**
439 | * 绘制圆形进度条
440 | * Draw a circular progress bar.
441 | *
442 | * @param canvas
443 | */
444 | private void drawProgress(Canvas canvas) {
445 | final RectF rectF = new RectF(
446 | mWidth / 2 - (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
447 | mHeight / 2 - (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
448 | mWidth / 2 + (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2),
449 | mHeight / 2 + (mInnerCircleRadius + (mExCircleRadius - mInnerCircleRadius) / 2));
450 | canvas.drawArc(rectF, -90, mCurrentProgress, false, mProgressPaint);
451 | }
452 |
453 | @Override
454 | public boolean performClick() {
455 | return false;
456 | }
457 |
458 | @Override
459 | public boolean onTouchEvent(MotionEvent event) {
460 | switch (event.getAction()) {
461 | case MotionEvent.ACTION_DOWN:
462 | isRecording = true;
463 | mStartTime = System.currentTimeMillis();
464 | handler.sendEmptyMessageDelayed(MSG_START_LONG_RECORD, LONG_CLICK_MIN_TIME);
465 | break;
466 | case MotionEvent.ACTION_UP:
467 | case MotionEvent.ACTION_CANCEL:
468 | isRecording = false;
469 | mEndTime = System.currentTimeMillis();
470 | if (mEndTime - mStartTime < LONG_CLICK_MIN_TIME) {
471 | //Long press the action time too short.
472 | if (handler.hasMessages(MSG_START_LONG_RECORD)) {
473 | handler.removeMessages(MSG_START_LONG_RECORD);
474 | }
475 | if (onRecordListener != null) {
476 | onRecordListener.onShortClick();
477 | }
478 |
479 | } else {
480 |
481 | if (mProgressAni != null && mProgressAni.getCurrentPlayTime() / 1000 < mMinTime) {
482 | //The recording time is less than the minimum recording time.
483 | if (onRecordListener != null) {
484 | onRecordListener.OnFinish(0);
485 | }
486 | } else {
487 | //The end of the normal
488 | if (onRecordListener != null) {
489 | onRecordListener.OnFinish(1);
490 | }
491 | }
492 | }
493 | mExCircleRadius = mInitExCircleRadius;
494 | mInnerCircleRadius = mInitInnerRadius;
495 | mProgressAni.cancel();
496 | startAnimation(
497 | mInitExCircleRadius * excicleMagnification,
498 | mInitExCircleRadius,
499 | mInitInnerRadius * innerCircleShrinks,
500 | mInitInnerRadius);
501 | break;
502 | case MotionEvent.ACTION_MOVE:
503 | break;
504 | }
505 | return true;
506 | }
507 |
508 | /**
509 | * 设置外圆 内圆缩放动画
510 | *
511 | * @param bigStart
512 | * @param bigEnd
513 | * @param smallStart
514 | * @param smallEnd
515 | */
516 | private void startAnimation(float bigStart, float bigEnd, float smallStart, float smallEnd) {
517 | ValueAnimator bigObjAni = ValueAnimator.ofFloat(bigStart, bigEnd);
518 | bigObjAni.setDuration(150);
519 | bigObjAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
520 | @Override
521 | public void onAnimationUpdate(ValueAnimator animation) {
522 | mExCircleRadius = (float) animation.getAnimatedValue();
523 | invalidate();
524 | }
525 | });
526 |
527 | ValueAnimator smallObjAni = ValueAnimator.ofFloat(smallStart, smallEnd);
528 | smallObjAni.setDuration(150);
529 | smallObjAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
530 | @Override
531 | public void onAnimationUpdate(ValueAnimator animation) {
532 | mInnerCircleRadius = (float) animation.getAnimatedValue();
533 | invalidate();
534 | }
535 | });
536 |
537 | bigObjAni.start();
538 | smallObjAni.start();
539 |
540 | smallObjAni.addListener(new Animator.AnimatorListener() {
541 | @Override
542 | public void onAnimationStart(Animator animation) {
543 |
544 | }
545 |
546 | @Override
547 | public void onAnimationEnd(Animator animation) {
548 | //开始绘制圆形进度
549 | if (isRecording) {
550 | startAniProgress();
551 | }
552 |
553 | }
554 |
555 |
556 | @Override
557 | public void onAnimationCancel(Animator animation) {
558 |
559 | }
560 |
561 | @Override
562 | public void onAnimationRepeat(Animator animation) {
563 |
564 | }
565 | });
566 |
567 | }
568 |
569 | /**
570 | * 开始圆形进度值动画
571 | */
572 | private void startAniProgress() {
573 | if (mProgressAni == null) {
574 | return;
575 | }
576 | mProgressAni.start();
577 | mProgressAni.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
578 | @Override
579 | public void onAnimationUpdate(ValueAnimator animation) {
580 | mCurrentProgress = (float) animation.getAnimatedValue();
581 | invalidate();
582 | }
583 | });
584 |
585 | mProgressAni.addListener(new AnimatorListenerAdapter() {
586 |
587 | @Override
588 | public void onAnimationEnd(Animator animation) {
589 | isRecording = false;
590 | mCurrentProgress = 0;
591 | invalidate();
592 | }
593 | });
594 | }
595 |
596 | /**
597 | * 设置最大录制时间
598 | *
599 | * @param mMaxTime 最大录制时间 秒
600 | */
601 | public void setMaxTime(int mMaxTime) {
602 | this.mMaxTime = mMaxTime;
603 | }
604 |
605 | /**
606 | * 设置最小录制时间
607 | *
608 | * @param mMinTime 最小录制时间 秒
609 | */
610 | public void setMinTime(int mMinTime) {
611 | this.mMinTime = mMinTime;
612 | }
613 |
614 | /**
615 | * 设置外圆半径
616 | *
617 | * @param mExCircleRadius 外圆半径
618 | */
619 | public void setExCircleRadius(float mExCircleRadius) {
620 | this.mExCircleRadius = mExCircleRadius;
621 | }
622 |
623 | /**
624 | * 设置内圆半径
625 | *
626 | * @param mInnerCircleRadius 内圆半径
627 | */
628 | public void setInnerCircleRadius(float mInnerCircleRadius) {
629 | this.mInnerCircleRadius = mInnerCircleRadius;
630 | }
631 |
632 | /**
633 | * 设置颜色外圆颜色
634 | *
635 | * @param mAnnulusColor
636 | */
637 | public void setAnnulusColor(int mAnnulusColor) {
638 | this.mAnnulusColor = mAnnulusColor;
639 | mExCirclePaint.setColor(mAnnulusColor);
640 | }
641 |
642 | /**
643 | * 设置进度圆环颜色
644 | *
645 | * @param mProgressColor
646 | */
647 | public void setProgressColor(int mProgressColor) {
648 | this.mProgressColor = mProgressColor;
649 | mProgressPaint.setColor(mProgressColor);
650 | }
651 |
652 | /**
653 | * 设置内圆颜色
654 | *
655 | * @param mInnerCircleColor
656 | */
657 | public void setInnerCircleColor(int mInnerCircleColor) {
658 | this.mInnerCircleColor = mInnerCircleColor;
659 | mInnerCirclePaint.setColor(mInnerCircleColor);
660 | }
661 |
662 | private OnRecordListener onRecordListener;
663 |
664 | public void setOnRecordListener(OnRecordListener onRecordListener) {
665 | this.onRecordListener = onRecordListener;
666 | }
667 |
668 | @Override
669 | public void setOnClickListener(@Nullable OnClickListener l) {
670 | super.setOnClickListener(l);
671 | }
672 |
673 | public static abstract class OnRecordListener {
674 |
675 | /**
676 | * 点击拍照
677 | */
678 | public void onShortClick() {
679 | }
680 |
681 | /**
682 | * 开始录制
683 | */
684 | public abstract void OnRecordStartClick();
685 |
686 | /**
687 | * 录制结束
688 | *
689 | * @param resultCode 0 录制时间太短 1 正常结束
690 | */
691 | public abstract void OnFinish(int resultCode);
692 | }
693 |
694 | /**
695 | * 长按录制
696 | */
697 | private static final int MSG_START_LONG_RECORD = 0x1;
698 |
699 |
700 | static class MHandler extends android.os.Handler {
701 |
702 | private WeakReference weakReference = null;
703 |
704 | public MHandler(VideoControlView controlView) {
705 | weakReference = new WeakReference(controlView);
706 | }
707 |
708 | @Override
709 | public void handleMessage(Message msg) {
710 | super.handleMessage(msg);
711 | if (weakReference == null || weakReference.get() == null) return;
712 | final VideoControlView videoControlView = weakReference.get();
713 | switch (msg.what) {
714 | case VideoControlView.MSG_START_LONG_RECORD:
715 | if (videoControlView.onRecordListener != null) {
716 | videoControlView.onRecordListener.OnRecordStartClick();
717 | }
718 | //内外圆动画,内圆缩小,外圆放大
719 | videoControlView.startAnimation(videoControlView.mExCircleRadius,
720 | videoControlView.mExCircleRadius * videoControlView.excicleMagnification,
721 | videoControlView.mInnerCircleRadius,
722 | videoControlView.mInnerCircleRadius * videoControlView.excicleMagnification);
723 | break;
724 | }
725 | }
726 | }
727 | }
728 |
729 | * 使用 属性 看一自由配置
730 |
731 |
739 | * MainActivity
740 |
741 | VideoControlView controlView = (VideoControlView) findViewById(R.id.control_view);
742 | controlView.setOnRecordListener(new VideoControlView.OnRecordListener() {
743 | @Override
744 | public void onShortClick() {
745 | Toast.makeText(MainActivity.this, "点击事件", Toast.LENGTH_SHORT).show();
746 | Log.i(TAG,"点击事件");
747 |
748 | }
749 |
750 | @Override
751 | public void OnRecordStartClick() {
752 | Toast.makeText(MainActivity.this, "开始录制", Toast.LENGTH_SHORT).show();
753 | Log.i(TAG,"开始录制");
754 | }
755 |
756 | @Override
757 | public void OnFinish(int resultCode) {
758 | switch (resultCode) {
759 | case 0:
760 | Toast.makeText(MainActivity.this, "录制时间过短", Toast.LENGTH_SHORT).show();
761 | Log.i(TAG,"录制时间过短");
762 | break;
763 | case 1:
764 | Toast.makeText(MainActivity.this, "录制结束", Toast.LENGTH_SHORT).show();
765 | Log.i(TAG,"录制结束");
766 | break;
767 | }
768 |
769 | }
770 | });
771 |
772 |
--------------------------------------------------------------------------------