├── Camera ├── CameraV1 │ ├── .gitignore │ ├── README.md │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── lb377463323 │ │ │ │ └── camera1 │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── ids.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle └── CameraV2 │ ├── .gitignore │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── lb377463323 │ │ │ └── camera2 │ │ │ └── MainActivity.java │ │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── gallery_imageview.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── Filter ├── .gitignore ├── .idea │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── liubing │ │ │ └── filtertestbed │ │ │ ├── CameraV1.java │ │ │ ├── CameraV1GLSurfaceView │ │ │ ├── CameraV1GLSurfaceView.java │ │ │ ├── CameraV1GLSurfaceViewActivity.java │ │ │ └── CameraV1Renderer.java │ │ │ ├── CameraV1TextureView │ │ │ ├── CameraV1GLRenderer.java │ │ │ └── CameraV1TextureViewActivity.java │ │ │ ├── CameraV2.java │ │ │ ├── CameraV2GLSurfaceView │ │ │ ├── CameraV2GLSurfaceView.java │ │ │ ├── CameraV2GLSurfaceViewActivity.java │ │ │ └── CameraV2Renderer.java │ │ │ ├── FilterEngine.java │ │ │ └── Utils.java │ │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── raw │ │ ├── base_fragment_shader.glsl │ │ └── base_vertex_shader.glsl │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── JNIDemo ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── lb6905 │ │ │ └── jnidemo │ │ │ ├── MainActivity.java │ │ │ └── TestClass.java │ │ ├── jni │ │ ├── Android.mk │ │ └── hello-jni.c │ │ ├── libs │ │ ├── arm64-v8a │ │ │ └── libhello-jni.so │ │ ├── armeabi-v7a │ │ │ └── libhello-jni.so │ │ ├── armeabi │ │ │ └── libhello-jni.so │ │ ├── mips │ │ │ └── libhello-jni.so │ │ ├── mips64 │ │ │ └── libhello-jni.so │ │ ├── x86 │ │ │ └── libhello-jni.so │ │ └── x86_64 │ │ │ └── libhello-jni.so │ │ ├── obj │ │ └── local │ │ │ ├── arm64-v8a │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ ├── armeabi-v7a │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ ├── armeabi │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ ├── mips │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ ├── mips64 │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ ├── x86 │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ │ └── hello-jni │ │ │ │ ├── hello-jni.o │ │ │ │ └── hello-jni.o.d │ │ │ └── x86_64 │ │ │ ├── libhello-jni.so │ │ │ └── objs │ │ │ └── hello-jni │ │ │ ├── hello-jni.o │ │ │ └── hello-jni.o.d │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── OpenGLES ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── lb377463323 │ │ │ └── opengles │ │ │ ├── GLActivity.java │ │ │ ├── GLRenderer.java │ │ │ └── Triangle.java │ │ └── res │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── README.md /Camera/CameraV1/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /Camera/CameraV1/README.md: -------------------------------------------------------------------------------- 1 | This is a CameraV1 Demo,it has preview、switch camera、take picture function. 2 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.lb377463323.camera1" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:25.1.1' 25 | } 26 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/liubing/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/src/main/java/com/lb377463323/camera1/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lb377463323.camera1; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageManager; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Color; 8 | import android.graphics.Matrix; 9 | import android.graphics.SurfaceTexture; 10 | import android.hardware.Camera; 11 | import android.os.Bundle; 12 | import android.os.Environment; 13 | import android.os.Process; 14 | import android.support.v7.app.AppCompatActivity; 15 | import android.util.Log; 16 | import android.view.Gravity; 17 | import android.view.TextureView; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.widget.AdapterView; 21 | import android.widget.BaseAdapter; 22 | import android.widget.Button; 23 | import android.widget.ListView; 24 | import android.widget.PopupWindow; 25 | import android.widget.TextView; 26 | 27 | import java.io.BufferedOutputStream; 28 | import java.io.File; 29 | import java.io.FileNotFoundException; 30 | import java.io.FileOutputStream; 31 | import java.io.IOException; 32 | import java.text.SimpleDateFormat; 33 | import java.util.ArrayList; 34 | import java.util.Date; 35 | import java.util.List; 36 | 37 | public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener, View.OnClickListener, AdapterView.OnItemClickListener{ 38 | private String TAG = "MainActivity"; 39 | public static final String STORAGE_PATH = Environment.getExternalStorageDirectory().toString(); 40 | 41 | private Camera mCamera; 42 | private TextureView mTextureView; 43 | private int mCameraId; 44 | private int mCameraNum; 45 | private Button mCaptureButton; 46 | private Button mSwitchCamButton; 47 | private Button mPictureSizeButton; 48 | private PopupWindow mPreviewPopupWindow; 49 | private PopupWindow mPicturePopupWindow; 50 | private Camera.Parameters mParameters; 51 | private List mSupportedPreSizeList; 52 | private List mSupportedPicSizeList; 53 | private List mPreviewSizeList; 54 | private List mPictureSizeList; 55 | private ListView mPictureListView; 56 | private MyAdapter mPictureAdapter; 57 | private int mCaptureWidth; 58 | private int mCaptureHeight; 59 | 60 | @Override 61 | protected void onCreate(Bundle savedInstanceState) { 62 | super.onCreate(savedInstanceState); 63 | setContentView(R.layout.activity_main); 64 | mTextureView = (TextureView) findViewById(R.id.camera_preview); 65 | mCaptureButton = (Button) findViewById(R.id.btn_capture); 66 | mSwitchCamButton = (Button) findViewById(R.id.btn_switchCam); 67 | mPictureSizeButton = (Button) findViewById(R.id.btn_pictureSize); 68 | mCaptureButton.setOnClickListener(this); 69 | mSwitchCamButton.setOnClickListener(this); 70 | mPictureSizeButton.setOnClickListener(this); 71 | 72 | if(checkCameraHardware(this)){ 73 | mCameraNum = Camera.getNumberOfCameras(); 74 | Log.i(TAG, "Camera Number: " + mCameraNum); 75 | mTextureView.setSurfaceTextureListener(this); 76 | }else { 77 | Log.i(TAG, "Has not Camera!"); 78 | } 79 | } 80 | 81 | @Override 82 | protected void onResume() { 83 | super.onResume(); 84 | requestCamera(mCameraId); 85 | initSizeList(); 86 | initParameters(); 87 | initPopupWindow(); 88 | } 89 | 90 | //Check whether the device has a camera 91 | private boolean checkCameraHardware(Context context){ 92 | if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){ 93 | return true;//has Camera 94 | }else { 95 | return false;// has not Camera 96 | } 97 | } 98 | 99 | private void setPreviewTexture(SurfaceTexture surfaceTexture) { 100 | if (mCamera != null) { 101 | try { 102 | mCamera.setPreviewTexture(surfaceTexture); 103 | } catch (IOException e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | } 108 | 109 | @Override 110 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 111 | setPreviewTexture(surface); 112 | setDisplayOrientation(90); 113 | startPreview(); 114 | Log.i(TAG, "onSurfaceTextureAvailable: size:" + width +"," + height); 115 | } 116 | 117 | @Override 118 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 119 | 120 | } 121 | 122 | @Override 123 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 124 | return false; 125 | } 126 | 127 | @Override 128 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { 129 | 130 | } 131 | 132 | @Override 133 | public void onClick(View v) { 134 | switch (v.getId()){ 135 | case R.id.btn_capture: 136 | takePicture(); 137 | break; 138 | case R.id.btn_switchCam: 139 | switchCamera(); 140 | break; 141 | case R.id.btn_pictureSize: 142 | showPopupWindow(mPicturePopupWindow, mPictureSizeButton); 143 | break; 144 | default: 145 | break; 146 | } 147 | } 148 | 149 | public void takePicture(){ 150 | if (mCamera != null){ 151 | mCamera.takePicture(null, null, mPictureCallback); 152 | } 153 | } 154 | 155 | public void switchCamera(){ 156 | if (mCameraNum > 1){ 157 | mCameraId = mCameraId == Camera.CameraInfo.CAMERA_FACING_BACK ? 158 | Camera.CameraInfo.CAMERA_FACING_FRONT : Camera.CameraInfo.CAMERA_FACING_BACK; 159 | stopPreview(); 160 | closeCamera(); 161 | 162 | requestCamera(mCameraId); 163 | initSizeList(); 164 | for (int i = 0; i < mPreviewSizeList.size(); i++) { 165 | Log.i(TAG, "preview size " + i + " :" + mPreviewSizeList.get(i)); 166 | } 167 | 168 | for (int j = 0; j < mPictureSizeList.size(); j++) { 169 | Log.i(TAG, "picture size " + j + " :" + mPictureSizeList.get(j)); 170 | } 171 | initParameters(); 172 | mPictureAdapter.notifyDataSetChanged(); 173 | setDisplayOrientation(90); 174 | setPreviewTexture(mTextureView.getSurfaceTexture()); 175 | startPreview(); 176 | Log.i(TAG, "Camera has switched!"); 177 | }else { 178 | Log.i(TAG, "This device does not support switch camera"); 179 | } 180 | } 181 | 182 | private Camera.ErrorCallback mErrorCallback = new Camera.ErrorCallback() { 183 | @Override 184 | public void onError(int error, Camera camera) { 185 | Log.e(TAG, "onError: got camera error callback: " + error); 186 | if (error == Camera.CAMERA_ERROR_SERVER_DIED) { 187 | android.os.Process.killProcess(Process.myPid()); 188 | } 189 | } 190 | }; 191 | 192 | private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { 193 | @Override 194 | public void onPictureTaken(final byte[] data, Camera camera) { 195 | new Thread(new Runnable() { 196 | @Override 197 | public void run() { 198 | String path = STORAGE_PATH + "/DCIM" + "/CameraV1"; 199 | writeFile(path, data); 200 | } 201 | }, "captureThread").start(); 202 | startPreview(); 203 | } 204 | }; 205 | 206 | public void writeFile(String path, byte[] data) { 207 | Bitmap bitmap = null; 208 | if (data != null){ 209 | bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); 210 | } 211 | 212 | if (bitmap != null){ 213 | Matrix matrix = new Matrix(); 214 | if (mCameraId == Camera.CameraInfo.CAMERA_FACING_BACK) { 215 | matrix.postRotate(90); 216 | }else if (mCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){ 217 | matrix.postRotate(90); 218 | matrix.postScale(1, -1); 219 | } 220 | Bitmap rotateBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), 221 | bitmap.getHeight(), matrix,false); 222 | saveBmp2SD(path, rotateBmp); 223 | rotateBmp.recycle(); 224 | } 225 | } 226 | 227 | private void saveBmp2SD(String path, Bitmap bitmap){ 228 | File file = new File(path); 229 | if (!file.exists()){ 230 | file.mkdir(); 231 | } 232 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 233 | String fileName = path + "/" + "IMG_" + timeStamp + ".jpg"; 234 | try { 235 | FileOutputStream fos = new FileOutputStream(fileName); 236 | BufferedOutputStream bos = new BufferedOutputStream(fos); 237 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); 238 | bos.flush(); 239 | bos.close(); 240 | Log.i(TAG, "Take picture success!"); 241 | } catch (FileNotFoundException e) { 242 | e.printStackTrace(); 243 | Log.e(TAG, "The save file for take picture is not exists!"); 244 | } catch (IOException e) { 245 | e.printStackTrace(); 246 | Log.e(TAG, "Take picture fail!"); 247 | } 248 | } 249 | 250 | private void setDisplayOrientation(int degree){ 251 | if (mCamera != null) { 252 | mCamera.setDisplayOrientation(degree); 253 | } 254 | Log.i(TAG, "Set display orientation is : " + degree); 255 | } 256 | 257 | private void requestCamera(int mCameraId) { 258 | openCamera(mCameraId); 259 | } 260 | 261 | private void openCamera(int cameraId){ 262 | try{ 263 | if (mCamera == null) { 264 | mCamera = Camera.open(cameraId); 265 | Log.i(TAG, "Camera has opened, cameraId is " + cameraId); 266 | } 267 | }catch (Exception e){ 268 | Log.e(TAG, "Open Camera has exception!"); 269 | } 270 | } 271 | 272 | private void startPreview(){ 273 | if (mCamera != null) { 274 | mCamera.setErrorCallback(mErrorCallback); 275 | mCamera.startPreview(); 276 | Log.i(TAG, "Camera Preview has started!"); 277 | } 278 | } 279 | 280 | private void stopPreview() { 281 | if (mCamera != null){ 282 | mCamera.stopPreview(); 283 | Log.i(TAG, "Camera Preview has stopped!"); 284 | } 285 | } 286 | 287 | private void closeCamera() { 288 | if (mCamera != null){ 289 | mCamera.setErrorCallback(null); 290 | mCamera.release(); 291 | mCamera = null; 292 | Log.i(TAG, "Camera has closed!"); 293 | } 294 | } 295 | 296 | @Override 297 | protected void onPause() { 298 | super.onPause(); 299 | stopPreview(); 300 | closeCamera(); 301 | } 302 | 303 | private void initSizeList() { 304 | mParameters = getParameters(); 305 | mSupportedPreSizeList = getSupportedPreviewSizes(mParameters); 306 | mSupportedPicSizeList = getSupportedPictureSizes(mParameters); 307 | } 308 | 309 | private void initParameters() { 310 | if (mSupportedPreSizeList != null && mSupportedPicSizeList != null) { 311 | mParameters.setPreviewSize(mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).width, 312 | mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).height); 313 | Log.i(TAG, "initParameters: previewSize: " + mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).width + 314 | "," + mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).height); 315 | mCaptureWidth = mSupportedPicSizeList.get(mSupportedPicSizeList.size() - 1).width; 316 | mCaptureHeight = mSupportedPicSizeList.get(mSupportedPicSizeList.size() - 1).height; 317 | mParameters.setPictureSize(mCaptureWidth, mCaptureHeight); 318 | Log.i(TAG, "initParameters: pictureSize: " + mCaptureWidth + "," + mCaptureHeight); 319 | setParameters(); 320 | } 321 | } 322 | 323 | private void initPopupWindow() { 324 | initPicturePopupWindow(); 325 | } 326 | 327 | private void initPicturePopupWindow() { 328 | mPictureAdapter = new MyAdapter(mPictureSizeList); 329 | mPictureListView = new ListView(this); 330 | mPictureListView.setId(R.id.pictureId); 331 | mPictureListView.setAdapter(mPictureAdapter); 332 | if (mPicturePopupWindow == null) { 333 | mPicturePopupWindow = new PopupWindow(mPictureListView, 320, 320,true); 334 | } 335 | mPictureListView.setOnItemClickListener(this); 336 | } 337 | 338 | private void showPopupWindow(PopupWindow popupWindow, View view) { 339 | if (popupWindow != null && view != null && !popupWindow.isShowing()) { 340 | int[] location = new int[2]; 341 | view.getLocationOnScreen(location); 342 | popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1] - popupWindow.getHeight()); 343 | } else { 344 | if (popupWindow != null) { 345 | popupWindow.dismiss(); 346 | } 347 | } 348 | } 349 | 350 | class MyAdapter extends BaseAdapter { 351 | List sizeList = new ArrayList<>(); 352 | 353 | public MyAdapter(List list) { 354 | this.sizeList = list; 355 | } 356 | 357 | @Override 358 | public int getCount() { 359 | return sizeList.size(); 360 | } 361 | 362 | @Override 363 | public Object getItem(int position) { 364 | return sizeList.get(position); 365 | } 366 | 367 | @Override 368 | public long getItemId(int position) { 369 | return position; 370 | } 371 | 372 | @Override 373 | public View getView(int position, View convertView, ViewGroup parent) { 374 | TextView textView = new TextView(MainActivity.this); 375 | textView.setTextSize(18); 376 | textView.setTextColor(Color.rgb(255, 255, 0)); 377 | textView.setText(sizeList.get(position)); 378 | return textView; 379 | } 380 | } 381 | 382 | private Camera.Parameters getParameters() { 383 | if (mCamera != null) { 384 | return mCamera.getParameters(); 385 | } 386 | return null; 387 | } 388 | 389 | private void setParameters() { 390 | if(mCamera != null && mParameters != null) { 391 | mCamera.setParameters(mParameters); 392 | } 393 | } 394 | 395 | private List getSupportedPreviewSizes(Camera.Parameters parameters) { 396 | if (parameters == null) { 397 | return null; 398 | } 399 | if (mPreviewSizeList == null) { 400 | mPreviewSizeList = new ArrayList<>(); 401 | } else { 402 | mPreviewSizeList.clear(); 403 | } 404 | mSupportedPreSizeList = new ArrayList<>(); 405 | for (Camera.Size size : parameters.getSupportedPreviewSizes()) { 406 | if (equalsRate(size, 1.777f)) { 407 | mSupportedPreSizeList.add(size); 408 | } 409 | } 410 | for (Camera.Size size : mSupportedPreSizeList) { 411 | mPreviewSizeList.add(size.width + "×" + size.height); 412 | } 413 | return mSupportedPreSizeList; 414 | } 415 | 416 | 417 | private List getSupportedPictureSizes(Camera.Parameters parameters) { 418 | if (parameters == null) { 419 | return null; 420 | } 421 | if (mPictureSizeList == null) { 422 | mPictureSizeList = new ArrayList<>(); 423 | } else { 424 | mPictureSizeList.clear(); 425 | } 426 | mSupportedPicSizeList = new ArrayList<>(); 427 | for (Camera.Size size : parameters.getSupportedPictureSizes()) { 428 | if(equalsRate(size, 1.777f)) { 429 | mSupportedPicSizeList.add(size); 430 | } 431 | } 432 | for (Camera.Size size : mSupportedPicSizeList) { 433 | mPictureSizeList.add(size.width + "×" + size.height); 434 | } 435 | return mSupportedPicSizeList; 436 | } 437 | 438 | @Override 439 | public void onItemClick(AdapterView parent, View view, int position, long id) { 440 | switch (parent.getId()) { 441 | case R.id.pictureId: 442 | Log.i(TAG, "onItemClick: PictureSize: " + mPictureSizeList.get(position)); 443 | setCaptureSize(mSupportedPicSizeList.get(position).width, 444 | mSupportedPicSizeList.get(position).height); 445 | mPicturePopupWindow.dismiss(); 446 | break; 447 | default: 448 | break; 449 | } 450 | } 451 | 452 | private void setPreviewSize(float rate) { 453 | if (!equalsRate(mParameters.getPreviewSize(), rate)) { 454 | mParameters.setPreviewSize(mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).width, 455 | mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).height); 456 | Log.i(TAG, "setPreviewSize: changed: " + mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).width + 457 | "×" + mSupportedPreSizeList.get(mSupportedPreSizeList.size() - 1).height); 458 | setParameters(); 459 | stopPreview(); 460 | startPreview(); 461 | } else { 462 | return; 463 | } 464 | } 465 | 466 | private void setCaptureSize(int captureWidth, int captureHeight) { 467 | this.mCaptureWidth = captureWidth; 468 | this.mCaptureHeight = captureHeight; 469 | mParameters.setPictureSize(mCaptureWidth, mCaptureHeight); 470 | if (mCamera != null) { 471 | setParameters(); 472 | } 473 | setPreviewSize((float) captureWidth / (float) captureHeight); 474 | } 475 | 476 | private boolean equalsRate(Camera.Size size, float rate){ 477 | float f = (float)size.width / (float) size.height; 478 | if (Math.abs(f - rate) <= 0.1f) { 479 | return true; 480 | } else { 481 | return false; 482 | } 483 | } 484 | } 485 | -------------------------------------------------------------------------------- /Camera/CameraV1/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 21 |