Skip to content

Commit

Permalink
add http and coor
Browse files Browse the repository at this point in the history
  • Loading branch information
n7910ljw committed Oct 16, 2018
1 parent 3db3992 commit 10a0aa9
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 54 deletions.
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 27

defaultConfig {
applicationId "net.yrom.screenrecorder.demo"
applicationId "com.easetest.recorder"
minSdkVersion 21
targetSdkVersion 27
versionCode 13
Expand All @@ -22,3 +22,7 @@ android {
}
}
}

dependencies {
compile 'org.nanohttpd:nanohttpd:2.3.1'
}
Binary file added app/release/app-release.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/release/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":13},"path":"app-release.apk","properties":{"packageId":"com.easetest.recorder","split":"","minSdkVersion":"21"}}]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.yrom.screenrecorder;
package com.netease.testease;

import android.app.Application;
import android.test.ApplicationTestCase;
Expand Down
20 changes: 14 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.yrom.screenrecorder" >
package="com.netease.testease">

<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=".UApplication"
android:allowBackup="false"
android:roundIcon="@mipmap/ic_launcher_round"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity
android:name="net.yrom.screenrecorder.MainActivity"
android:name=".MainActivity"
android:configChanges="screenLayout|orientation|screenSize"
android:label="@string/app_name" >
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name="net.netease.testease.RecordService"
android:enabled="true"
android:exported="true"></service>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.media.MediaFormat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.media.MediaFormat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.media.MediaCodec;
import android.media.MediaFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.yrom.screenrecorder;
package com.netease.testease;

import android.annotation.TargetApi;
import android.app.Activity;
Expand All @@ -34,21 +34,29 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.Range;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.widget.ToggleButton;

import net.yrom.screenrecorder.view.NamedSpinner;
import com.netease.testease.http.CoordinateServer;
import com.netease.testease.view.NamedSpinner;

import com.netease.testease.handler.CoorHandler;
import com.netease.testease.view.FloatView;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -59,8 +67,6 @@
import static android.Manifest.permission.RECORD_AUDIO;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.os.Build.VERSION_CODES.M;
import static net.yrom.screenrecorder.ScreenRecorder.AUDIO_AAC;
import static net.yrom.screenrecorder.ScreenRecorder.VIDEO_AVC;

public class MainActivity extends Activity {
private static final int REQUEST_MEDIA_PROJECTION = 1;
Expand Down Expand Up @@ -99,17 +105,20 @@ protected void onCreate(Bundle savedInstanceState) {
mMediaProjectionManager = (MediaProjectionManager) getApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE);
mNotifications = new Notifications(getApplicationContext());
bindViews();
initWindow();
mHandler = new CoorHandler(mLayout, this);
startServer(mHandler);

Utils.findEncodersByTypeAsync(VIDEO_AVC, infos -> {
logCodecInfos(infos, VIDEO_AVC);
Utils.findEncodersByTypeAsync(ScreenRecorder.VIDEO_AVC, infos -> {
logCodecInfos(infos, ScreenRecorder.VIDEO_AVC);
mAvcCodecInfos = infos;
SpinnerAdapter codecsAdapter = createCodecsAdapter(mAvcCodecInfos);
mVideoCodec.setAdapter(codecsAdapter);
restoreSelections(mVideoCodec, mVieoResolution, mVideoFramerate, mIFrameInterval, mVideoBitrate);

});
Utils.findEncodersByTypeAsync(AUDIO_AAC, infos -> {
logCodecInfos(infos, AUDIO_AAC);
Utils.findEncodersByTypeAsync(ScreenRecorder.AUDIO_AAC, infos -> {
logCodecInfos(infos, ScreenRecorder.AUDIO_AAC);
mAacCodecInfos = infos;
SpinnerAdapter codecsAdapter = createCodecsAdapter(mAacCodecInfos);
mAudioCodec.setAdapter(codecsAdapter);
Expand Down Expand Up @@ -222,7 +231,7 @@ private AudioEncodeConfig createAudioConfig() {
int channelCount = getSelectedAudioChannelCount();
int profile = getSelectedAudioProfile();

return new AudioEncodeConfig(codec, AUDIO_AAC, bitrate, samplerate, channelCount, profile);
return new AudioEncodeConfig(codec, ScreenRecorder.AUDIO_AAC, bitrate, samplerate, channelCount, profile);
}

private VideoEncodeConfig createVideoConfig() {
Expand All @@ -241,7 +250,7 @@ private VideoEncodeConfig createVideoConfig() {
int bitrate = getSelectedVideoBitrate();
MediaCodecInfo.CodecProfileLevel profileLevel = getSelectedProfileLevel();
return new VideoEncodeConfig(width, height, bitrate,
framerate, iframe, codec, VIDEO_AVC, profileLevel);
framerate, iframe, codec, ScreenRecorder.VIDEO_AVC, profileLevel);
}

private static File getSavingDir() {
Expand Down Expand Up @@ -399,7 +408,7 @@ private void onResolutionChanged(int selectedPosition, String resolution) {
String codecName = getSelectedVideoCodec();
MediaCodecInfo codec = getVideoCodecInfo(codecName);
if (codec == null) return;
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(VIDEO_AVC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
String[] xes = resolution.split("x");
if (xes.length != 2) throw new IllegalArgumentException();
Expand Down Expand Up @@ -427,7 +436,7 @@ private void onBitrateChanged(int selectedPosition, String bitrate) {
String codecName = getSelectedVideoCodec();
MediaCodecInfo codec = getVideoCodecInfo(codecName);
if (codec == null) return;
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(VIDEO_AVC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
int selectedBitrate = Integer.parseInt(bitrate) * 1000;

Expand All @@ -444,7 +453,7 @@ private void onOrientationChanged(int selectedPosition, String orientation) {
String codecName = getSelectedVideoCodec();
MediaCodecInfo codec = getVideoCodecInfo(codecName);
if (codec == null) return;
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(VIDEO_AVC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
int[] selectedWithHeight = getSelectedWithHeight();
boolean isLandscape = selectedPosition == 1;
Expand All @@ -470,7 +479,7 @@ private void onFramerateChanged(int selectedPosition, String rate) {
String codecName = getSelectedVideoCodec();
MediaCodecInfo codec = getVideoCodecInfo(codecName);
if (codec == null) return;
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(VIDEO_AVC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
int[] selectedWithHeight = getSelectedWithHeight();
int selectedFramerate = Integer.parseInt(rate);
Expand All @@ -495,7 +504,7 @@ private void onVideoCodecSelected(String codecName) {
mVideoProfileLevel.setAdapter(null);
return;
}
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(VIDEO_AVC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);

resetAvcProfileLevelAdapter(capabilities);
}
Expand Down Expand Up @@ -537,7 +546,7 @@ private void onAudioCodecSelected(String codecName) {
mAudioBitrate.setAdapter(null);
return;
}
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(AUDIO_AAC);
MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.AUDIO_AAC);

resetAudioBitrateAdapter(capabilities);
resetSampleRateAdapter(capabilities);
Expand Down Expand Up @@ -620,7 +629,7 @@ private void resetAudioBitrateAdapter(MediaCodecInfo.CodecCapabilities capabilit
private MediaCodecInfo getVideoCodecInfo(String codecName) {
if (codecName == null) return null;
if (mAvcCodecInfos == null) {
mAvcCodecInfos = Utils.findEncodersByType(VIDEO_AVC);
mAvcCodecInfos = Utils.findEncodersByType(ScreenRecorder.VIDEO_AVC);
}
MediaCodecInfo codec = null;
for (int i = 0; i < mAvcCodecInfos.length; i++) {
Expand All @@ -637,7 +646,7 @@ private MediaCodecInfo getVideoCodecInfo(String codecName) {
private MediaCodecInfo getAudioCodecInfo(String codecName) {
if (codecName == null) return null;
if (mAacCodecInfos == null) {
mAacCodecInfos = Utils.findEncodersByType(AUDIO_AAC);
mAacCodecInfos = Utils.findEncodersByType(ScreenRecorder.AUDIO_AAC);
}
MediaCodecInfo codec = null;
for (int i = 0; i < mAacCodecInfos.length; i++) {
Expand Down Expand Up @@ -758,7 +767,7 @@ private static void logCodecInfos(MediaCodecInfo[] codecInfos, String mimeType)
.append("\n Heights: ").append(videoCaps.getSupportedHeights())
.append("\n Frame Rates: ").append(videoCaps.getSupportedFrameRates())
.append("\n Bitrate: ").append(videoCaps.getBitrateRange());
if (VIDEO_AVC.equals(mimeType)) {
if (ScreenRecorder.VIDEO_AVC.equals(mimeType)) {
MediaCodecInfo.CodecProfileLevel[] levels = caps.profileLevels;

builder.append("\n Profile-levels: ");
Expand Down Expand Up @@ -853,7 +862,7 @@ public void onReceive(Context context, Intent intent) {
private void viewResult(File file) {
Intent view = new Intent(Intent.ACTION_VIEW);
view.addCategory(Intent.CATEGORY_DEFAULT);
view.setDataAndType(Uri.fromFile(file), VIDEO_AVC);
view.setDataAndType(Uri.fromFile(file), ScreenRecorder.VIDEO_AVC);
view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(view);
Expand All @@ -863,4 +872,52 @@ private void viewResult(File file) {
}
};

private FloatView mLayout = null;
private CoorHandler mHandler;
private WindowManager mWindowManager;
private WindowManager.LayoutParams param;
private CoordinateServer mServer;

private void initWindow(){
mWindowManager = (WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE); //获取WindowManager
param = ((UApplication)getApplication()).getMywmParams();
param.type= WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; // 系统提示类型,重要
param.format = 1;
param.flags = WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; // 不能抢占聚焦点
param.alpha = 1.0f;
param.gravity = Gravity.LEFT | Gravity.TOP; //调整悬浮窗口至左上角
param.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}

public void showFloatView() {
if (mLayout == null){
mLayout = new FloatView(getApplicationContext());
mLayout.setFocusable(false);
}
mHandler.updateFloatView(mLayout);
mWindowManager.addView(mLayout, param);
}

private void startServer(Handler mHandler) {
try {
if (mServer == null){
mServer = new CoordinateServer(9000, mHandler);
mServer.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}

public void stratRecord() {
onButtonClick(null);
}

public void stopRecord() {
onButtonClick(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.media.AudioFormat;
import android.media.AudioRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.annotation.TargetApi;
import android.app.Notification;
Expand All @@ -29,7 +29,7 @@
import android.text.format.DateUtils;

import static android.os.Build.VERSION_CODES.O;
import static net.yrom.screenrecorder.MainActivity.ACTION_STOP;
import static com.netease.testease.MainActivity.ACTION_STOP;

/**
* @author yrom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package net.yrom.screenrecorder;
package com.netease.testease;

import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/netease/testease/UApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.netease.testease;

import android.app.Application;
import android.view.WindowManager;

public class UApplication extends Application {

/**
* 创建全局变量
* 全局变量一般都比较倾向于创建一个单独的数据类文件,并使用static静态变量
*
* 这里使用了在Application中添加数据的方法实现全局变量
* 注意在AndroidManifest.xml中的Application节点添加android:name=".MyApplication"属性
*
*/
private WindowManager.LayoutParams wmParams=new WindowManager.LayoutParams();

public WindowManager.LayoutParams getMywmParams(){
return wmParams;
}

}
Loading

0 comments on commit 10a0aa9

Please sign in to comment.