Skip to content

Commit

Permalink
upgrade version 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloHuDi committed Jun 4, 2018
1 parent 427a570 commit 80ced40
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 170 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
78 changes: 0 additions & 78 deletions .idea/markdown-navigator.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/markdown-navigator/profiles_settings.xml

This file was deleted.

75 changes: 75 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<h3 align="center">ScreenCapture</h3>
<p align="center">
<a href="" target="_blank"><img src="https://img.shields.io/badge/release-v2.3-blue.svg"></img></a>
<a href="" target="_blank"><img src="https://img.shields.io/badge/release-v2.4-blue.svg"></img></a>
</p>

## Implement screen capture without root on Android 5.0+ by using MediaProjectionManager, VirtualDisplay, AudioRecord, MediaCodec and MediaMuxer APIs
Expand All @@ -17,13 +17,14 @@
```
dependencies {
//...
implementation 'com.hd:screencapture:2.3'
implementation 'com.hd:screencapture:2.4'
}
```

### code

```
//use default video config
ScreenCapture.with(activity).startCapture();
```

Expand Down Expand Up @@ -52,5 +53,19 @@ screenCapture.startCapture();
screenCapture.stopCapture();
```

### License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[1]: https://github.com/yrom/ScreenRecorder
[2]: https://github.com/yrom
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// implementation project(':screencapture')
implementation 'com.hd:screencapture:2.3'
implementation 'com.hd:screencapture:2.4'
implementation 'com.hd.splashscreen:splashscreen:1.4'
implementation 'pub.devrel:easypermissions:1.1.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
Expand Down
6 changes: 3 additions & 3 deletions screencapture/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def siteUrl = 'https://github.com/HelloHuDi/ScreenCapture'
def gitUrl = 'git@github.com:HelloHuDi/ScreenCapture.git'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
version = "2.3"
version = "2.4"
group = "com.hd"

android {
Expand All @@ -15,8 +15,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 23
versionName "2.3"
versionCode 24
versionName "2.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
27 changes: 14 additions & 13 deletions screencapture/src/main/java/com/hd/screencapture/ScreenCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.hd.screencapture.config.ScreenCaptureConfig;
import com.hd.screencapture.help.ScreenCaptureFragment;
import com.hd.screencapture.help.ScreenCaptureHelper;
import com.hd.screencapture.help.Utils;
import com.hd.screencapture.observer.CaptureObserver;
import com.hd.screencapture.observer.ScreenCaptureObserver;
Expand Down Expand Up @@ -40,27 +41,27 @@ public static ScreenCapture with(@NonNull AppCompatActivity activity) {
if (!Utils.isExternalStorageReady()) {
Log.e(TAG, "current no storage space");
}
if(!Utils.isPermissionGranted(activity,false)){
if (!Utils.isPermissionGranted(activity, false)) {
Log.e(TAG, "no permission !!!");
}
return new ScreenCapture(activity);
}

private ScreenCaptureFragment screenCaptureFragment;

private CaptureObserver observer;
private ScreenCaptureHelper screenCaptureHelper;

private AtomicBoolean capture = new AtomicBoolean(false);

private ScreenCapture(@NonNull AppCompatActivity activity) {
capture.set(false);
observer = new ScreenCaptureObserver(this);
CaptureObserver observer = new ScreenCaptureObserver(this);
//add lifecycle observer
activity.getLifecycle().addObserver((ScreenCaptureObserver) observer);
//init the main capture work fragment
screenCaptureFragment = getScreenCaptureFragment(activity);
ScreenCaptureFragment screenCaptureFragment = getScreenCaptureFragment(activity);
//add capture callback observer
screenCaptureFragment.addObserver(observer);
//init capture helper
screenCaptureHelper = new ScreenCaptureHelper(activity.getApplicationContext(), observer, screenCaptureFragment);
//init default config
setConfig(ScreenCaptureConfig.initDefaultConfig(activity));
}
Expand All @@ -86,13 +87,12 @@ public ScreenCapture setConfig(@NonNull ScreenCaptureConfig config) {
throw new RuntimeException("you must set the capture video config if you call this method," +//
"if you do not call this method, we will provide a default video config ");
if (config.getAudioConfig() == null)
Log.w(TAG,"note that if you do not set the audio config, your video will have not voice ");
screenCaptureFragment.addConfig(config);
observer.addConfig(config);
Log.w(TAG, "note that if you do not set the audio config, your video will have not voice ");
screenCaptureHelper.addConfig(config);
return this;
}

public boolean isRunning(){
public boolean isRunning() {
return capture.get();
}

Expand All @@ -103,7 +103,7 @@ public void startCapture() {
public void startCapture(long duration) {
if (!isRunning()) {
capture.set(true);
screenCaptureFragment.startCapture();
screenCaptureHelper.startCapture();
if (duration > 0) {
new Timer().schedule(new TimerTask() {
@Override
Expand All @@ -120,8 +120,9 @@ public void run() {
public void stopCapture() {
if (isRunning()) {
capture.set(false);
screenCaptureFragment.stopCapture();
observer.reset();
screenCaptureHelper.stopCapture();
System.gc();
System.runFinalization();
} else {
Log.e(TAG, "stop capture always");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public final class ScreenCaptureConfig extends CaptureConfig {
*/
private boolean allowLog;

/**
* whether the associated lifecycle is needed,
* automatically stops according to activity lifecycle{@link Activity#onDestroy()}
*/
private boolean relevanceLifecycle = true;

/**
* about video config
*/
Expand Down Expand Up @@ -78,6 +84,14 @@ public void setAllowLog(boolean allowLog) {
this.allowLog = allowLog;
}

public boolean isRelevanceLifecycle() {
return relevanceLifecycle;
}

public void setRelevanceLifecycle(boolean relevanceLifecycle) {
this.relevanceLifecycle = relevanceLifecycle;
}

public VideoConfig getVideoConfig() {
return videoConfig;
}
Expand Down Expand Up @@ -115,8 +129,8 @@ public void setAutoMoveTaskToBack(boolean autoMoveTaskToBack) {
}

public File getFile() {
if(file==null)
file=new File(Environment.getExternalStorageDirectory(), "screen_capture_" //
if (file == null)
file = new File(Environment.getExternalStorageDirectory(), "screen_capture_" //
+ new SimpleDateFormat("yyyyMMdd-HH-mm-ss", Locale.US).format(new Date()) + ".mp4");
return file;
}
Expand All @@ -133,6 +147,11 @@ public Builder() {
this.captureConfig = new ScreenCaptureConfig();
}

public Builder setRelevanceLifecycle(boolean relevanceLifecycle) {
captureConfig.setRelevanceLifecycle(relevanceLifecycle);
return this;
}

public Builder setAllowLog(boolean allowLog) {
captureConfig.setAllowLog(allowLog);
return this;
Expand Down
Loading

0 comments on commit 80ced40

Please sign in to comment.