├── .gitattributes ├── .gitignore ├── .idea └── gradle.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── libq │ │ └── videocutpreviewviewdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── libq │ │ │ └── videocutpreviewviewdemo │ │ │ ├── MainActivity.java │ │ │ └── RectView.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_slider_left.png │ │ └── ic_slider_right.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── libq │ └── videocutpreviewviewdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── videocutpreview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── libq │ │ └── videocutpreviewview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── libq │ │ │ └── videocutpreview │ │ │ ├── VideoCutView.java │ │ │ ├── VideoThumbnailView.java │ │ │ └── ViewUtil.java │ └── res │ │ ├── layout │ │ └── cut_view.xml │ │ └── values │ │ ├── attr.xml │ │ ├── dimens.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── libq │ └── videocutpreviewview │ └── ExampleUnitTest.java └── view.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VideoCutView 视频裁剪view 带帧预览 2 | ![image](https://github.com/libq/VideoCutView/blob/master/view.png) 3 | 4 | # 1.配置 5 | step 1: project build.gradle 6 | ``` 7 | allprojects { 8 | repositories { 9 | ... 10 | maven { url 'https://jitpack.io' } 11 | } 12 | } 13 | 14 | 15 | ``` 16 | step 2: module build.gradle 17 | 18 | ``` 19 | dependencies { 20 |        compile 'com.github.libq:VideoCutView:1.0.3' 21 | } 22 | 23 | ``` 24 | 25 | 26 | # 2.使用 27 | 28 | ## java 29 | 30 | ``` 31 | 32 | cut.getSuitImageCount(new VideoCutView.GetImageCountCallback() { 33 | @Override 34 | public void invoke(int count) { 35 | String root =Environment.getExternalStorageDirectory().getAbsolutePath(); 36 | //本地图片 37 | 38 | String imgPath = root+ File.separator +"Pictures/03 演示图片.jpg"; 39 | ArrayList paths = new ArrayList<>(); 40 | for(int i = 0 ; i<=count ;i++){ 41 | paths.add(imgPath); 42 | //"http://p3.wmpic.me/article/2017/11/08/1510105952_KopFLXPj.jpg" 43 | } 44 | cut.setImageUrls(paths, new VideoCutView.ImageLoadStrategyLinstener() { 45 | @Override 46 | public void onLoad(ArrayList urls, ArrayList ivs) { 47 | for(int i=0;i 84 | ``` 85 | 86 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.3' 6 | defaultConfig { 7 | applicationId "com.libq.videocutpreviewviewdemo" 8 | minSdkVersion 16 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile project(':videocutpreview') 29 | compile 'pub.devrel:easypermissions:1.0.1' 30 | compile 'com.github.bumptech.glide:glide:3.7.0' 31 | } 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/libq/videocutpreviewviewdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreviewviewdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.libq.videocutpreviewviewdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/libq/videocutpreviewviewdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreviewviewdemo; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.pm.PackageManager; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.os.Bundle; 9 | import android.os.Environment; 10 | import android.support.annotation.NonNull; 11 | import android.support.v4.app.ActivityCompat; 12 | import android.support.v4.content.ContextCompat; 13 | import android.util.Log; 14 | import android.widget.ImageView; 15 | import android.widget.LinearLayout; 16 | import android.widget.Toast; 17 | 18 | import com.bumptech.glide.Glide; 19 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 20 | import com.libq.videocutpreview.VideoCutView; 21 | import com.libq.videocutpreview.VideoThumbnailView; 22 | 23 | import java.io.File; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import pub.devrel.easypermissions.EasyPermissions; 28 | 29 | 30 | public class MainActivity extends Activity implements EasyPermissions.PermissionCallbacks{ 31 | 32 | private VideoCutView cut; 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_main); 37 | 38 | cut = (VideoCutView) findViewById(R.id.cut); 39 | 40 | String[] perms = {Manifest.permission.INTERNET,Manifest.permission.WRITE_SETTINGS, Manifest.permission.READ_EXTERNAL_STORAGE}; 41 | 42 | 43 | if (EasyPermissions.hasPermissions(this, perms)) { 44 | initImage(); 45 | } else { 46 | // 没有申请过权限,现在去申请 47 | EasyPermissions.requestPermissions(this, "QUAN XIAN SHEN QING", 48 | 10, perms); 49 | } 50 | 51 | //本地文件 52 | } 53 | 54 | @Override 55 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 56 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 57 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 58 | } 59 | 60 | @Override //申请成功时调用 61 | public void onPermissionsGranted(int requestCode, List list) { 62 | //请求成功执行相应的操作 63 | initImage(); 64 | 65 | 66 | } 67 | 68 | @Override //申请失败时调用 69 | public void onPermissionsDenied(int requestCode, List list) { 70 | // 请求失败,执行相应操作 71 | 72 | } 73 | private void initImage(){ 74 | cut.getSuitImageCount(new VideoCutView.GetImageCountCallback() { 75 | @Override 76 | public void invoke(int count) { 77 | String root =Environment.getExternalStorageDirectory().getAbsolutePath(); 78 | //本地图片 79 | 80 | String imgPath = root+ File.separator +"Pictures/03 演示图片.jpg"; 81 | ArrayList paths = new ArrayList<>(); 82 | for(int i = 0 ; i<=count ;i++){ 83 | paths.add(imgPath); 84 | //"http://p3.wmpic.me/article/2017/11/08/1510105952_KopFLXPj.jpg" 85 | } 86 | cut.setImageUrls(paths, new VideoCutView.ImageLoadStrategyLinstener() { 87 | @Override 88 | public void onLoad(ArrayList urls, ArrayList ivs) { 89 | for(int i=0;i 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_slider_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-hdpi/ic_slider_left.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_slider_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-hdpi/ic_slider_right.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VideoCutPreviewViewDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/test/java/com/libq/videocutpreviewviewdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreviewviewdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | maven { url 'https://maven.google.com' } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:2.3.0' 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Apr 09 14:17:40 CST 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':videocutpreview' 2 | -------------------------------------------------------------------------------- /videocutpreview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /videocutpreview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.3" 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 16 11 | targetSdkVersion 25 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | compile 'com.android.support:appcompat-v7:25.3.1' 31 | testCompile 'junit:junit:4.12' 32 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', { 33 | exclude group: 'com.android.support', module: 'support-annotations' 34 | }) 35 | compile 'com.android.support:support-v4:25.3.1' 36 | 37 | } 38 | -------------------------------------------------------------------------------- /videocutpreview/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 | -------------------------------------------------------------------------------- /videocutpreview/src/androidTest/java/com/libq/videocutpreviewview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.libq.videocutpreviewview.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /videocutpreview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /videocutpreview/src/main/java/com/libq/videocutpreview/VideoCutView.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreview; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Color; 8 | import android.os.Environment; 9 | import android.support.annotation.NonNull; 10 | import android.support.annotation.Nullable; 11 | import android.util.AttributeSet; 12 | import android.util.Log; 13 | import android.view.LayoutInflater; 14 | import android.view.View; 15 | import android.widget.FrameLayout; 16 | import android.widget.ImageView; 17 | import android.widget.LinearLayout; 18 | 19 | 20 | import java.io.File; 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * 描述:视频裁剪View 25 | * 设置裁剪区间,并且显示缩略图 26 | * ps:为了更好的显示缩略图,需要输入图片的宽高比 27 | * 通过宽高比来计算铺满时显示的缩略图数量 28 | * author: libq 29 | * date2018/4/10 0010. 30 | */ 31 | 32 | public class VideoCutView extends FrameLayout { 33 | private LinearLayout mImageLayout = null; 34 | private VideoThumbnailView mThumb = null; 35 | private FrameLayout root=null; 36 | 37 | private Context mContext = null; 38 | private int minHeight = 100; 39 | private ArrayList imgUrls = null; 40 | private double whRate = 0.618f;//缩略图宽高比 41 | 42 | private int mTopBottomBorderWidth = 6; 43 | private int mBorderColor = Color.RED; 44 | private int mDragAreaWidth = 40;//可拖动区域宽度 45 | private int mCutMinDuration = mDragAreaWidth/2+2;//最小长度//两个拖动条间的最小距离 46 | private int mSliderWidth = 6;//左右两个滑动块的宽度 47 | private boolean isDrawCursor = false;//是否需要画游标 48 | private int mVideoDuration; 49 | private ArrayList imageViews; 50 | 51 | public VideoCutView(@NonNull Context context) { 52 | super(context); 53 | initView(context,null); 54 | } 55 | 56 | public VideoCutView(@NonNull Context context, @Nullable AttributeSet attrs) { 57 | super(context, attrs); 58 | initView(context,attrs); 59 | } 60 | 61 | public VideoCutView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 62 | super(context, attrs, defStyleAttr); 63 | initView(context,attrs); 64 | } 65 | 66 | private void initView(Context context,AttributeSet attrs){ 67 | imageViews = new ArrayList<>(); 68 | mContext = context; 69 | //--------------------------- 70 | if(attrs!=null){ 71 | TypedArray tr = context.obtainStyledAttributes(attrs, R.styleable.VideoCutView); 72 | 73 | isDrawCursor = tr.getBoolean(R.styleable.VideoCutView_draw_cursor,isDrawCursor); 74 | int defTopBotmWidth =ViewUtil.px2dp(mContext,mTopBottomBorderWidth); 75 | mTopBottomBorderWidth = ViewUtil.dp2px(mContext,(int)tr.getDimension(R.styleable.VideoCutView_top_bottom_border_width,defTopBotmWidth)); 76 | mBorderColor = tr.getColor(R.styleable.VideoCutView_border_color,mBorderColor); 77 | int defDragWidth = ViewUtil.px2dp(mContext,mDragAreaWidth); 78 | mDragAreaWidth = ViewUtil.dp2px(mContext,(int)tr.getDimension(R.styleable.VideoCutView_drag_area_width,defDragWidth)); 79 | 80 | mCutMinDuration = tr.getInteger(R.styleable.VideoCutView_cut_min_duration,mCutMinDuration); 81 | int defSliderWidth = ViewUtil.px2dp(mContext,mSliderWidth); 82 | mSliderWidth = ViewUtil.dp2px(mContext,(int)tr.getDimension(R.styleable.VideoCutView_slider_width,defSliderWidth)); 83 | mVideoDuration = tr.getInteger(R.styleable.VideoCutView_video_duration,mVideoDuration); 84 | 85 | tr.recycle(); 86 | } 87 | 88 | //--------------------------- 89 | View root = LayoutInflater.from(mContext).inflate(R.layout.cut_view,this); 90 | mThumb = (VideoThumbnailView) root.findViewById(R.id.thumb); 91 | mImageLayout = (LinearLayout) root.findViewById(R.id.img_list); 92 | 93 | mThumb.setBorderColor(mBorderColor); 94 | mThumb.setDragAreaWidth(mDragAreaWidth); 95 | mThumb.setDrawCursor(isDrawCursor); 96 | mThumb.setSliderWidth(mSliderWidth); 97 | mThumb.setTopBottomBorderWidth(mTopBottomBorderWidth); 98 | 99 | 100 | } 101 | 102 | /** 103 | * 设置图片集 104 | * @param urls 105 | */ 106 | public void setImageUrls(ArrayList urls,ImageLoadStrategyLinstener listener){ 107 | imgUrls = urls; 108 | for(int i=0;i urls,ArrayList ivs); 259 | } 260 | 261 | /** 262 | * 视频播放区间改变监听 263 | */ 264 | public interface OnVideoPlayIntervalChangeListener{ 265 | void onChange(int startTime,int endTime); 266 | } 267 | 268 | 269 | } 270 | -------------------------------------------------------------------------------- /videocutpreview/src/main/java/com/libq/videocutpreview/VideoThumbnailView.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreview; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | import android.graphics.RectF; 9 | import android.support.annotation.Nullable; 10 | import android.util.AttributeSet; 11 | import android.view.MotionEvent; 12 | import android.view.View; 13 | 14 | 15 | 16 | /** 17 | * describ:绘制两头都可以移动的view 18 | * author:libq 19 | * date:2018.4.9 20 | */ 21 | public class VideoThumbnailView extends View { 22 | 23 | private int mWidth; 24 | private int mHeight; 25 | private Paint mPaint; 26 | private Paint mCursorPaint; 27 | private Paint mSliderPaint; 28 | private boolean canDrawCursor = true; 29 | private int mCursorX; 30 | 31 | private Rect sliderLeftRectf;//左边滑块区域 32 | private Rect sliderRightRectf;//右边滑块 33 | private OnCutBorderScrollListener onCutBorderScrollListener; 34 | private OnTouchCutAreaListener onTouchCutAreaListener; 35 | private Context mContext; 36 | 37 | private int mTopBottomBorderWidth = 6; 38 | private int mBorderColor = Color.RED; 39 | private int mDragAreaWidth = 40;//可拖动区域宽度 40 | private int minLength = mDragAreaWidth/2+2;//最小长度//两个拖动条间的最小距离 41 | private int mSliderWidth = 6;//左右两个滑动块的宽度 42 | private boolean isDrawCursor = false;//是否需要画游标 43 | 44 | public void setWidth(int width) { 45 | this.mWidth = width; 46 | } 47 | 48 | public void setTopBottomBorderWidth(int topBottomBorderWidth) { 49 | this.mTopBottomBorderWidth = topBottomBorderWidth; 50 | } 51 | 52 | 53 | public void setDragAreaWidth(int dragAreaWidth) { 54 | this.mDragAreaWidth = dragAreaWidth; 55 | } 56 | 57 | public void setSliderWidth(int sliderWidth) { 58 | this.mSliderWidth = sliderWidth; 59 | } 60 | 61 | public void setDrawCursor(boolean drawCursor) { 62 | isDrawCursor = drawCursor; 63 | } 64 | 65 | public VideoThumbnailView(Context context) { 66 | super(context); 67 | init(context); 68 | } 69 | 70 | public VideoThumbnailView(Context context, @Nullable AttributeSet attrs) { 71 | super(context, attrs); 72 | init(context); 73 | } 74 | 75 | public VideoThumbnailView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 76 | super(context, attrs, defStyleAttr); 77 | init(context); 78 | } 79 | 80 | private int cursorWidth = 3; 81 | private void init(Context context) { 82 | mContext = context; 83 | mCursorPaint = new Paint(); 84 | mCursorPaint.setAntiAlias(true); 85 | mCursorPaint.setStrokeWidth(cursorWidth); 86 | mCursorPaint.setColor(Color.RED); 87 | 88 | mPaint = new Paint(); 89 | mPaint.setAntiAlias(true); 90 | mPaint.setStrokeWidth(mTopBottomBorderWidth); 91 | 92 | mSliderPaint = new Paint(); 93 | mSliderPaint.setAntiAlias(true); 94 | mSliderPaint.setStrokeCap(Paint.Cap.SQUARE); 95 | mSliderPaint.setStyle(Paint.Style.FILL); 96 | mSliderPaint.setColor(mBorderColor); 97 | 98 | } 99 | 100 | 101 | /** 102 | * 设置边框颜色 103 | * @param borderColor 104 | */ 105 | public void setBorderColor(int borderColor){ 106 | mBorderColor = borderColor; 107 | } 108 | /** 109 | * 设置最小间隔 110 | * @param minPx 111 | */ 112 | public void setMinLength(int minPx){ 113 | if(mWidth>0 && minPx > mWidth){ 114 | minPx = mWidth; 115 | } 116 | this.minLength = minPx; 117 | } 118 | 119 | public interface OnCutBorderScrollListener { 120 | void onScrollBorder(int start, int end); 121 | } 122 | 123 | public void setOnCutBorderScrollListener(OnCutBorderScrollListener listener){ 124 | this.onCutBorderScrollListener = listener; 125 | } 126 | 127 | public void setOnTouchCutAreaListener(OnTouchCutAreaListener listener){ 128 | onTouchCutAreaListener = listener; 129 | } 130 | 131 | /** 132 | * 点击裁剪区域监听 133 | */ 134 | public interface OnTouchCutAreaListener { 135 | void onTouchUp(); 136 | void onTouchDown(); 137 | } 138 | 139 | public float getLeftInterval(){ 140 | return sliderLeftRectf.left; 141 | } 142 | 143 | public float getRightInterval(){ 144 | return sliderRightRectf.right; 145 | } 146 | 147 | @Override 148 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 149 | super.onLayout(changed, left, top, right, bottom); 150 | 151 | if (mWidth == 0) { 152 | mWidth = getWidth(); 153 | mHeight = getHeight(); 154 | 155 | sliderLeftRectf = new Rect(); 156 | sliderLeftRectf.left = 0; 157 | sliderLeftRectf.top = 0; 158 | sliderLeftRectf.right = mSliderWidth; 159 | sliderLeftRectf.bottom = mHeight; 160 | 161 | sliderRightRectf = new Rect(); 162 | sliderRightRectf.left = mWidth - mSliderWidth; 163 | sliderRightRectf.top = 0; 164 | sliderRightRectf.right = mWidth; 165 | sliderRightRectf.bottom = mHeight; 166 | } 167 | } 168 | 169 | private float downX; 170 | private boolean scrollLeft; 171 | private boolean scrollRight; 172 | private int mScrollStartPosition,mScrollEndPosition; 173 | 174 | @Override 175 | public boolean onTouchEvent(MotionEvent event) { 176 | 177 | move(event); 178 | return scrollLeft || scrollRight; 179 | } 180 | 181 | boolean scrollChange; 182 | private boolean move(MotionEvent event) { 183 | 184 | switch (event.getAction()) { 185 | case MotionEvent.ACTION_DOWN: 186 | canDrawCursor = false; 187 | downX = event.getX(); 188 | if (downX > sliderLeftRectf.left- mDragAreaWidth/2 && downX < sliderLeftRectf.right+ mDragAreaWidth/2) { 189 | scrollRight = false; 190 | scrollLeft = true; 191 | } 192 | if (downX > sliderRightRectf.left- mDragAreaWidth/2 && downX < sliderRightRectf.right+ mDragAreaWidth /2) { 193 | scrollLeft = false; 194 | scrollRight = true; 195 | } 196 | if ((downX > sliderLeftRectf.left- mDragAreaWidth/2 && downX < sliderLeftRectf.right+ mDragAreaWidth /2)|| 197 | (downX > sliderRightRectf.left- mDragAreaWidth /2 && downX < sliderRightRectf.right+ mDragAreaWidth /2)) { 198 | if(onTouchCutAreaListener !=null){ 199 | onTouchCutAreaListener.onTouchDown(); 200 | } 201 | } 202 | 203 | break; 204 | case MotionEvent.ACTION_MOVE: 205 | canDrawCursor = false; 206 | float moveX = event.getX(); 207 | 208 | float scrollX = moveX - downX; 209 | 210 | if (scrollLeft) { 211 | sliderLeftRectf.left = sliderLeftRectf.left + (int)scrollX; 212 | sliderLeftRectf.right = sliderLeftRectf.right + (int)scrollX; 213 | 214 | if(sliderLeftRectf.left < 0){ 215 | sliderLeftRectf.left = 0; 216 | sliderLeftRectf.right = mSliderWidth; 217 | } 218 | /* if(sliderLeftRectf.left > sliderRightRectf.right- minLength){ 219 | sliderLeftRectf.left = sliderRightRectf.right- minLength; 220 | sliderLeftRectf.right = sliderLeftRectf.left+ mSliderWidth; 221 | }*/ 222 | if(sliderLeftRectf.right > sliderRightRectf.left- minLength){ 223 | sliderLeftRectf.right = sliderRightRectf.left- minLength; 224 | sliderLeftRectf.left = sliderLeftRectf.right - mSliderWidth; 225 | } 226 | scrollChange = true; 227 | invalidate(); 228 | } else if (scrollRight) { 229 | sliderRightRectf.left = sliderRightRectf.left + (int)scrollX; 230 | sliderRightRectf.right = sliderRightRectf.right + (int)scrollX; 231 | 232 | if(sliderRightRectf.right > mWidth){ 233 | sliderRightRectf.right = mWidth; 234 | sliderRightRectf.left = sliderRightRectf.right- mSliderWidth; 235 | } 236 | if(sliderRightRectf.left < sliderLeftRectf.left+ minLength){ 237 | sliderRightRectf.left = sliderLeftRectf.left+ minLength; 238 | sliderRightRectf.right = sliderRightRectf.left + mSliderWidth; 239 | } 240 | scrollChange = true; 241 | invalidate(); 242 | } 243 | 244 | /*if(onCutBorderScrollListener != null){ 245 | onCutBorderScrollListener.onScrollBorder(sliderLeftRectf.left, sliderRightRectf.right); 246 | }*/ 247 | mScrollStartPosition = sliderLeftRectf.left; 248 | mScrollEndPosition = sliderRightRectf.right; 249 | 250 | downX = moveX; 251 | break; 252 | case MotionEvent.ACTION_CANCEL: 253 | case MotionEvent.ACTION_UP: 254 | downX = 0; 255 | scrollLeft = false; 256 | scrollRight = false; 257 | if(scrollChange && onCutBorderScrollListener != null){ 258 | onCutBorderScrollListener.onScrollBorder(mScrollStartPosition,mScrollEndPosition); 259 | } 260 | if(onTouchCutAreaListener !=null){ 261 | onTouchCutAreaListener.onTouchUp(); 262 | } 263 | scrollChange = false; 264 | canDrawCursor = true; 265 | break; 266 | } 267 | return true; 268 | } 269 | 270 | @Override 271 | protected void onDraw(Canvas canvas) { 272 | 273 | if (isDrawCursor) { 274 | if(canDrawCursor){ 275 | canvas.drawLine(mCursorX, sliderLeftRectf.top-mTopBottomBorderWidth,mCursorX, sliderLeftRectf.bottom+mTopBottomBorderWidth,mCursorPaint); 276 | } 277 | } 278 | mPaint.setColor(mBorderColor); 279 | 280 | drawSlider(canvas, sliderLeftRectf); 281 | 282 | drawSlider(canvas,sliderRightRectf); 283 | 284 | canvas.drawLine(sliderLeftRectf.left, 0, sliderRightRectf.right, 0, mPaint); 285 | canvas.drawLine(sliderLeftRectf.left, mHeight, sliderRightRectf.right, mHeight, mPaint); 286 | 287 | mPaint.setColor(Color.parseColor("#99313133")); 288 | 289 | RectF rectF3 = new RectF(); 290 | rectF3.left = 0; 291 | rectF3.top = 0; 292 | rectF3.right = sliderLeftRectf.left; 293 | rectF3.bottom = mHeight; 294 | canvas.drawRect(rectF3, mPaint); 295 | 296 | RectF rectF4 = new RectF(); 297 | rectF4.left = sliderRightRectf.right; 298 | rectF4.top = 0; 299 | rectF4.right = mWidth; 300 | rectF4.bottom = mHeight; 301 | canvas.drawRect(rectF4, mPaint); 302 | 303 | 304 | 305 | } 306 | 307 | /** 308 | * 移动游标 309 | * @param x 310 | */ 311 | public void moveCursor(int x){ 312 | if (isDrawCursor) { 313 | mCursorX = x; 314 | invalidate(); 315 | } 316 | } 317 | 318 | private void drawSlider(Canvas canvas,Rect rect){ 319 | canvas.drawRect(rect,mSliderPaint); 320 | } 321 | } -------------------------------------------------------------------------------- /videocutpreview/src/main/java/com/libq/videocutpreview/ViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreview; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | 6 | /** 7 | * describ: balabala 8 | * author: libq 9 | * date: 2018/4/17 0017.11:52 10 | * email:614527679@qq.com 11 | */ 12 | 13 | public class ViewUtil { 14 | public static int dp2px(Context c,int dp ){ 15 | return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dp,c.getResources().getDisplayMetrics())); 16 | } 17 | 18 | public static int px2dp(Context c,float pxValue){ 19 | float scale=c.getResources().getDisplayMetrics().density; 20 | return Math.round(pxValue/scale+0.5f); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /videocutpreview/src/main/res/layout/cut_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 18 | -------------------------------------------------------------------------------- /videocutpreview/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /videocutpreview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1dp 4 | 1dp 5 | 1dp 6 | 5dp 7 | 8 | 9 | 5dp 10 | 3dp 11 | 1dp 12 | 10dp 13 | 20dp 14 | 25dp 15 | 30dp 16 | 50dp 17 | 80dp 18 | 100dp 19 | 6dp 20 | 21 | -------------------------------------------------------------------------------- /videocutpreview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VideoCutPreviewView 3 | 4 | -------------------------------------------------------------------------------- /videocutpreview/src/test/java/com/libq/videocutpreviewview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.libq.videocutpreview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libq/VideoCutView/e6906cb8caed04995ed6dd38df13cc2d75c7d13d/view.png --------------------------------------------------------------------------------