|
|
|
@ -9,7 +9,9 @@ import android.graphics.Bitmap; |
|
|
|
|
import android.hardware.Camera; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.os.Environment; |
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
|
import android.view.Surface; |
|
|
|
|
import android.view.SurfaceHolder; |
|
|
|
@ -50,7 +52,7 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
private Spinner beautyTypeSelector; |
|
|
|
|
|
|
|
|
|
private ImageView img_photo; |
|
|
|
|
//拍照
|
|
|
|
|
|
|
|
|
|
private boolean takePhoto; |
|
|
|
|
|
|
|
|
|
private final static int videoWidth = 640; |
|
|
|
@ -58,7 +60,15 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
private final static String[] permissions = new String[]{Manifest.permission.CAMERA}; |
|
|
|
|
private final static int CODE_CAMERA = 1001; |
|
|
|
|
|
|
|
|
|
private final static String[] beautySelector = new String[]{"美颜", "冷酷", "日出","素描","白猫", "浪漫", "原图"}; |
|
|
|
|
private final static String[] beautySelector = new String[]{ |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_beauty), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_cool), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_sunrise), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_sketch), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_white), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_romantic), |
|
|
|
|
LiveApplication.getInstance().getString(R.string.effect_raw) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
@ -76,22 +86,22 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@TargetApi(23) |
|
|
|
|
private void requestPermissions(){ |
|
|
|
|
private void requestPermissions() { |
|
|
|
|
requestPermissions(permissions, CODE_CAMERA); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initView(){ |
|
|
|
|
private void initView() { |
|
|
|
|
//SurfaceView
|
|
|
|
|
mSmartCameraView = findViewById(R.id.gl_surfaceview); |
|
|
|
|
//美颜类型
|
|
|
|
|
//beauty type
|
|
|
|
|
beautyTypeSelector = findViewById(R.id.beauty_type_selctor); |
|
|
|
|
//静音
|
|
|
|
|
//mute
|
|
|
|
|
btnMute = findViewById(R.id.button_mute); |
|
|
|
|
//拍照
|
|
|
|
|
//take photo
|
|
|
|
|
img_photo = findViewById(R.id.img_photo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initListener(){ |
|
|
|
|
private void initListener() { |
|
|
|
|
|
|
|
|
|
ArrayAdapter<String> adapterBeautyType = new ArrayAdapter<>(this, |
|
|
|
|
android.R.layout.simple_spinner_item, beautySelector); |
|
|
|
@ -101,7 +111,7 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
@Override |
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
|
|
switch (position){ |
|
|
|
|
switch (position) { |
|
|
|
|
case 0: |
|
|
|
|
switchCameraFilter(MagicFilterType.BEAUTY); |
|
|
|
|
break; |
|
|
|
@ -125,6 +135,7 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) { |
|
|
|
|
|
|
|
|
@ -136,19 +147,20 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
public void onClick(View view) { |
|
|
|
|
is_mute = !is_mute; |
|
|
|
|
|
|
|
|
|
if ( is_mute ) |
|
|
|
|
btnMute.setText("取消静音"); |
|
|
|
|
else |
|
|
|
|
btnMute.setText("静音"); |
|
|
|
|
if (is_mute) { |
|
|
|
|
btnMute.setText(getString(R.string.voice)); |
|
|
|
|
} else { |
|
|
|
|
btnMute.setText(getString(R.string.mute)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//预览数据回调(RGBA格式)
|
|
|
|
|
//preview data callback(RGBA)
|
|
|
|
|
mSmartCameraView.setPreviewCallback(new SmartCameraView.PreviewCallback() { |
|
|
|
|
@Override |
|
|
|
|
public void onGetRgbaFrame(byte[] data, int width, int height) { |
|
|
|
|
|
|
|
|
|
if(takePhoto){ |
|
|
|
|
if (takePhoto) { |
|
|
|
|
takePhoto = false; |
|
|
|
|
Log.i(TAG, "takePhoto..."); |
|
|
|
|
doTakePhoto(data, width, height); |
|
|
|
@ -171,12 +183,13 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拍照 |
|
|
|
|
* @param data 预览数据 |
|
|
|
|
* @param width 图片宽度 |
|
|
|
|
* @param height 图片高度 |
|
|
|
|
* 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){ |
|
|
|
|
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); |
|
|
|
@ -184,7 +197,7 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
Log.i(TAG, "doTakePhoto..."); |
|
|
|
|
FileOutputStream fileOutputStream = null; |
|
|
|
|
String PATH = Environment.getExternalStorageDirectory().getPath(); |
|
|
|
|
String filePath = PATH + File.separator + "hello_openGL" + ".jpg"; |
|
|
|
|
String filePath = PATH + File.separator + "hello" + ".jpg"; |
|
|
|
|
try { |
|
|
|
|
fileOutputStream = new FileOutputStream(filePath); |
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); |
|
|
|
@ -192,8 +205,8 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
Log.e(TAG, "doTakePhoto error=" + e.toString()); |
|
|
|
|
}finally { |
|
|
|
|
if(fileOutputStream != null){ |
|
|
|
|
} finally { |
|
|
|
|
if (fileOutputStream != null) { |
|
|
|
|
try { |
|
|
|
|
fileOutputStream.close(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
@ -215,7 +228,6 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) { |
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
Log.i(TAG, "Surface Destroyed"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -223,13 +235,10 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -241,10 +250,10 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
mSmartCameraView.setPreviewResolution(width, height); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setCameraDisplayOrientation (Activity activity, int cameraId) { |
|
|
|
|
private void setCameraDisplayOrientation(Activity activity, int cameraId) { |
|
|
|
|
Camera.CameraInfo info = new Camera.CameraInfo(); |
|
|
|
|
Camera.getCameraInfo (cameraId , info); |
|
|
|
|
int rotation = activity.getWindowManager ().getDefaultDisplay ().getRotation (); |
|
|
|
|
Camera.getCameraInfo(cameraId, info); |
|
|
|
|
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); |
|
|
|
|
int degrees = 0; |
|
|
|
|
switch (rotation) { |
|
|
|
|
case Surface.ROTATION_0: |
|
|
|
@ -266,40 +275,30 @@ public class PushActivity extends Activity implements Callback { |
|
|
|
|
result = (360 - result) % 360; |
|
|
|
|
} else { |
|
|
|
|
// back-facing
|
|
|
|
|
result = ( info.orientation - degrees + 360) % 360; |
|
|
|
|
result = (info.orientation - degrees + 360) % 360; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Log.i(TAG, "curDegree: "+ result); |
|
|
|
|
|
|
|
|
|
Log.i(TAG, "curDegree: " + result); |
|
|
|
|
mDegree = result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onDestroy(){ |
|
|
|
|
|
|
|
|
|
if ( isStart ) { |
|
|
|
|
protected void onDestroy() { |
|
|
|
|
if (isStart) { |
|
|
|
|
isStart = false; |
|
|
|
|
if(mSmartCameraView != null) |
|
|
|
|
{ |
|
|
|
|
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]); |
|
|
|
|
|
|
|
|
|
if (permissions.length > 0 && grantResults.length > 0) { |
|
|
|
|
setPreviewResolution(videoWidth, videoHeight); |
|
|
|
|
|
|
|
|
|
if (!mSmartCameraView.startCamera()) { |
|
|
|
|
Log.e(TAG, "startCamera error..."); |
|
|
|
|
} |
|
|
|
|