diff --git a/Live/src/main/AndroidManifest.xml b/Live/src/main/AndroidManifest.xml
index d93668d..5ed1b10 100644
--- a/Live/src/main/AndroidManifest.xml
+++ b/Live/src/main/AndroidManifest.xml
@@ -8,6 +8,7 @@
adapterBeautyType = new ArrayAdapter<>(this,
- android.R.layout.simple_spinner_item, beautySelector);
- adapterBeautyType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- beautyTypeSelector.setAdapter(adapterBeautyType);
- beautyTypeSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
-
- switch (position){
- case 0:
- switchCameraFilter(MagicFilterType.BEAUTY);
- break;
- case 1:
- switchCameraFilter(MagicFilterType.COOL);
- break;
- case 2:
- switchCameraFilter(MagicFilterType.SUNRISE);
- break;
- case 3:
- switchCameraFilter(MagicFilterType.SKETCH);
- break;
- case 4:
- switchCameraFilter(MagicFilterType.WHITECAT);
- break;
- case 5:
- switchCameraFilter(MagicFilterType.ROMANCE);
- break;
- default:
- switchCameraFilter(MagicFilterType.NONE);
- break;
- }
- }
- @Override
- public void onNothingSelected(AdapterView> parent) {
-
- }
- });
-
- btnMute.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- is_mute = !is_mute;
-
- if ( is_mute )
- btnMute.setText("取消静音");
- else
- btnMute.setText("静音");
- }
- });
-
- //预览数据回调(RGBA格式)
- mSmartCameraView.setPreviewCallback(new SmartCameraView.PreviewCallback() {
- @Override
- public void onGetRgbaFrame(byte[] data, int width, int height) {
-
- if(takePhoto){
- takePhoto = false;
- Log.i(TAG, "takePhoto...");
- doTakePhoto(data, width, height);
- }
-
- }
- });
-
- img_photo.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- takePhoto = true;
- }
- });
-
- }
-
- private void switchCameraFilter(MagicFilterType type) {
- mSmartCameraView.setFilter(type);
- }
-
- /**
- * 拍照
- * @param data 预览数据
- * @param width 图片宽度
- * @param height 图片高度
- */
- private void doTakePhoto(byte[] data, int width, int height){
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- ByteBuffer buffer = ByteBuffer.wrap(data);
- bitmap.copyPixelsFromBuffer(buffer);
-
- Log.i(TAG, "doTakePhoto...");
- FileOutputStream fileOutputStream = null;
- String PATH = Environment.getExternalStorageDirectory().getPath();
- String filePath = PATH + File.separator + "hello_openGL" + ".jpg";
- try {
- fileOutputStream = new FileOutputStream(filePath);
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
- fileOutputStream.flush();
- } catch (IOException e) {
- e.printStackTrace();
- Log.e(TAG, "doTakePhoto error=" + e.toString());
- }finally {
- if(fileOutputStream != null){
- try {
- fileOutputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- Log.i(TAG, "surfaceCreated..");
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- Log.i(TAG, "surfaceChanged..");
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- // TODO Auto-generated method stub
- Log.i(TAG, "Surface Destroyed");
- }
-
- public void onConfigurationChanged(Configuration newConfig) {
+ private void initListener() {
+
+ ArrayAdapter adapterBeautyType = new ArrayAdapter<>(this,
+ android.R.layout.simple_spinner_item, beautySelector);
+ adapterBeautyType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ beautyTypeSelector.setAdapter(adapterBeautyType);
+ beautyTypeSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+
+ switch (position) {
+ case 0:
+ switchCameraFilter(MagicFilterType.BEAUTY);
+ break;
+ case 1:
+ switchCameraFilter(MagicFilterType.COOL);
+ break;
+ case 2:
+ switchCameraFilter(MagicFilterType.SUNRISE);
+ break;
+ case 3:
+ switchCameraFilter(MagicFilterType.SKETCH);
+ break;
+ case 4:
+ switchCameraFilter(MagicFilterType.WHITECAT);
+ break;
+ case 5:
+ switchCameraFilter(MagicFilterType.ROMANCE);
+ break;
+ default:
+ switchCameraFilter(MagicFilterType.NONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
+
+ }
+ });
+
+ btnMute.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ is_mute = !is_mute;
+
+ if (is_mute) {
+ btnMute.setText(getString(R.string.voice));
+ } else {
+ btnMute.setText(getString(R.string.mute));
+ }
+ }
+ });
+
+ //preview data callback(RGBA)
+ mSmartCameraView.setPreviewCallback(new SmartCameraView.PreviewCallback() {
+ @Override
+ public void onGetRgbaFrame(byte[] data, int width, int height) {
+
+ if (takePhoto) {
+ takePhoto = false;
+ Log.i(TAG, "takePhoto...");
+ doTakePhoto(data, width, height);
+ }
+
+ }
+ });
+
+ img_photo.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ takePhoto = true;
+ }
+ });
+
+ }
+
+ private void switchCameraFilter(MagicFilterType type) {
+ mSmartCameraView.setFilter(type);
+ }
+
+ /**
+ * take photo
+ *
+ * @param data preview data
+ * @param width the width of photo
+ * @param height the height of photo
+ */
+ private void doTakePhoto(byte[] data, int width, int height) {
+ Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ ByteBuffer buffer = ByteBuffer.wrap(data);
+ bitmap.copyPixelsFromBuffer(buffer);
+
+ Log.i(TAG, "doTakePhoto...");
+ FileOutputStream fileOutputStream = null;
+ String PATH = Environment.getExternalStorageDirectory().getPath();
+ String filePath = PATH + File.separator + "hello" + ".jpg";
try {
- super.onConfigurationChanged(newConfig);
- Log.i(TAG, "onConfigurationChanged, start:" + isStart);
+ fileOutputStream = new FileOutputStream(filePath);
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
+ fileOutputStream.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ Log.e(TAG, "doTakePhoto error=" + e.toString());
+ } finally {
+ if (fileOutputStream != null) {
+ try {
+ fileOutputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
- setCameraDisplayOrientation(this, getCameraId());
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ Log.i(TAG, "surfaceCreated..");
+ }
- mSmartCameraView.setPreviewOrientation(newConfig.orientation, mDegree);
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ Log.i(TAG, "surfaceChanged..");
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ Log.i(TAG, "Surface Destroyed");
+ }
+ public void onConfigurationChanged(Configuration newConfig) {
+ try {
+ super.onConfigurationChanged(newConfig);
+ Log.i(TAG, "onConfigurationChanged, start:" + isStart);
+ setCameraDisplayOrientation(this, getCameraId());
+ mSmartCameraView.setPreviewOrientation(newConfig.orientation, mDegree);
} catch (Exception ex) {
- Log.e(TAG, "error="+ex.toString());
+ Log.e(TAG, "error=" + ex.toString());
+ }
+ }
+
+ private int getCameraId() {
+ return mSmartCameraView.getCameraId();
+ }
+
+ public void setPreviewResolution(int width, int height) {
+ mSmartCameraView.setPreviewResolution(width, height);
+ }
+
+ private void setCameraDisplayOrientation(Activity activity, int cameraId) {
+ Camera.CameraInfo info = new Camera.CameraInfo();
+ Camera.getCameraInfo(cameraId, info);
+ int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+ int degrees = 0;
+ switch (rotation) {
+ case Surface.ROTATION_0:
+ degrees = 0;
+ break;
+ case Surface.ROTATION_90:
+ degrees = 90;
+ break;
+ case Surface.ROTATION_180:
+ degrees = 180;
+ break;
+ case Surface.ROTATION_270:
+ degrees = 270;
+ break;
}
+ int result;
+ if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
+ result = (info.orientation + degrees) % 360;
+ result = (360 - result) % 360;
+ } else {
+ // back-facing
+ result = (info.orientation - degrees + 360) % 360;
+ }
+ Log.i(TAG, "curDegree: " + result);
+ mDegree = result;
}
- private int getCameraId() {
- return mSmartCameraView.getCameraId();
- }
-
- public void setPreviewResolution(int width, int height) {
- mSmartCameraView.setPreviewResolution(width, height);
- }
-
- private void setCameraDisplayOrientation (Activity activity, int cameraId) {
- Camera.CameraInfo info = new Camera.CameraInfo();
- Camera.getCameraInfo (cameraId , info);
- int rotation = activity.getWindowManager ().getDefaultDisplay ().getRotation ();
- int degrees = 0;
- switch (rotation) {
- case Surface.ROTATION_0:
- degrees = 0;
- break;
- case Surface.ROTATION_90:
- degrees = 90;
- break;
- case Surface.ROTATION_180:
- degrees = 180;
- break;
- case Surface.ROTATION_270:
- degrees = 270;
- break;
- }
- int result;
- if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
- result = (info.orientation + degrees) % 360;
- result = (360 - result) % 360;
- } else {
- // back-facing
- result = ( info.orientation - degrees + 360) % 360;
- }
-
- Log.i(TAG, "curDegree: "+ result);
-
- mDegree = result;
- }
-
- @Override
- protected void onDestroy(){
-
- if ( isStart ) {
- isStart = false;
- if(mSmartCameraView != null)
- {
- mSmartCameraView.stopCamera();
- }
-
- Log.i(TAG, "onDestroy StopPublish");
- }
-
- super.onDestroy();
- finish();
- System.exit(0);
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- if(permissions.length > 0 && grantResults.length > 0){
- Log.i(TAG, "permission=" + permissions[0] + "----grantResult=" + grantResults[0]);
-
- setPreviewResolution(videoWidth, videoHeight);
-
- if (!mSmartCameraView.startCamera()) {
- Log.e(TAG, "startCamera error...");
- }
- }
- }
+ @Override
+ protected void onDestroy() {
+ if (isStart) {
+ isStart = false;
+ if (mSmartCameraView != null) {
+ mSmartCameraView.stopCamera();
+ }
+ Log.i(TAG, "onDestroy StopPublish");
+ }
+ super.onDestroy();
+ finish();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (permissions.length > 0 && grantResults.length > 0) {
+ setPreviewResolution(videoWidth, videoHeight);
+ if (!mSmartCameraView.startCamera()) {
+ Log.e(TAG, "startCamera error...");
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Live/src/main/res/values/strings.xml b/Live/src/main/res/values/strings.xml
index 82d655b..d71bcc0 100644
--- a/Live/src/main/res/values/strings.xml
+++ b/Live/src/main/res/values/strings.xml
@@ -3,4 +3,14 @@
切换
开始
停止
+ 静音
+ 取消静音
+
+ 美颜
+ 冷酷
+ 日出
+ 素描
+ 纯白
+ 浪漫
+ 原图