-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a2484f3
Showing
40 changed files
with
1,111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.example.administrator.screencap" | ||
minSdkVersion 21 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0-rc02' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/example/administrator/screencap/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.administrator.screencap; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.administrator.screencap", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.administrator.screencap"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.RECORD_AUDIO"/> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".RecordApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<service android:name="com.example.administrator.screencap.RecordService"></service> | ||
</application> | ||
|
||
<supports-screens | ||
android:smallScreens="true" | ||
android:normalScreens="true" | ||
android:largeScreens="true" | ||
android:resizeable="true" | ||
android:anyDensity="true" /> | ||
|
||
</manifest> |
119 changes: 119 additions & 0 deletions
119
app/src/main/java/com/example/administrator/screencap/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.example.administrator.screencap; | ||
|
||
import android.Manifest; | ||
import android.content.ComponentName; | ||
import android.content.Intent; | ||
import android.content.ServiceConnection; | ||
import android.content.pm.PackageManager; | ||
import android.media.projection.MediaProjection; | ||
import android.media.projection.MediaProjectionManager; | ||
import android.os.IBinder; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.DisplayMetrics; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.Toast; | ||
|
||
|
||
public class MainActivity extends AppCompatActivity { | ||
private static final int RECORD_REQUEST_CODE = 101; | ||
private static final int STORAGE_REQUEST_CODE = 102; | ||
private static final int AUDIO_REQUEST_CODE = 103; | ||
|
||
private MediaProjectionManager projectionManager; | ||
private MediaProjection mediaProjection; | ||
private RecordService recordService; | ||
private Button startBtn; | ||
|
||
RecordApplication recordApplication; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
projectionManager = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE); | ||
setContentView(R.layout.activity_main); | ||
|
||
// recordApplication = RecordApplication.getInstance(); | ||
// recordApplication.onCreate(); | ||
startService(new Intent(this, RecordService.class)); | ||
|
||
startBtn = (Button) findViewById(R.id.screencap); | ||
// startBtn.setEnabled(false); | ||
startBtn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
recordService = new RecordService(); | ||
if (recordService.isRunning()) { | ||
recordService.stopRecord(); | ||
startBtn.setText("开始录屏"); | ||
Toast.makeText(MainActivity.this,"视频录制完成,存放地址为\n"+ RecordService.getScreencapPath(),Toast.LENGTH_LONG).show(); | ||
} else { | ||
Intent captureIntent = projectionManager.createScreenCaptureIntent(); | ||
startActivityForResult(captureIntent, RECORD_REQUEST_CODE); | ||
} | ||
} | ||
}); | ||
|
||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
!= PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions(this, | ||
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_REQUEST_CODE); | ||
} | ||
|
||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO) | ||
!= PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions(this, | ||
new String[] {Manifest.permission.RECORD_AUDIO}, AUDIO_REQUEST_CODE); | ||
} | ||
|
||
Intent intent = new Intent(this, RecordService.class); | ||
bindService(intent, connection, BIND_AUTO_CREATE); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
unbindService(connection); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if (requestCode == RECORD_REQUEST_CODE && resultCode == RESULT_OK) { | ||
mediaProjection = projectionManager.getMediaProjection(resultCode, data); | ||
recordService.setMediaProject(mediaProjection); | ||
if(startBtn.getText().toString().equals("开始录屏")){ | ||
recordService.startRecord(); | ||
startBtn.setText("停止录屏"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (requestCode == STORAGE_REQUEST_CODE || requestCode == AUDIO_REQUEST_CODE) { | ||
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { | ||
finish(); | ||
} | ||
} | ||
} | ||
|
||
private ServiceConnection connection = new ServiceConnection() { | ||
@Override | ||
public void onServiceConnected(ComponentName className, IBinder service) { | ||
DisplayMetrics metrics = new DisplayMetrics(); | ||
getWindowManager().getDefaultDisplay().getMetrics(metrics); | ||
RecordService.RecordBinder binder = (RecordService.RecordBinder) service; | ||
recordService = binder.getRecordService(); | ||
recordService.setConfig(metrics.widthPixels, metrics.heightPixels, metrics.densityDpi); | ||
startBtn.setEnabled(true); | ||
startBtn.setText(recordService.isRunning() ? "停止录屏" : "开始录屏"); | ||
} | ||
|
||
@Override | ||
public void onServiceDisconnected(ComponentName arg0) {} | ||
}; | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/example/administrator/screencap/RecordApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.administrator.screencap; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
|
||
public class RecordApplication extends Application { | ||
|
||
private static RecordApplication application; | ||
|
||
@Override | ||
protected void attachBaseContext(Context base) { | ||
super.attachBaseContext(base); | ||
application = this; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
application = this; | ||
// 启动 Marvel service | ||
startService(new Intent(this, RecordService.class)); | ||
} | ||
|
||
public static RecordApplication getInstance() { | ||
return application; | ||
} | ||
} |
Oops, something went wrong.