├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── libraries │ ├── universal_image_loader_1_8_6.xml │ ├── support_annotations_20_0_0.xml │ └── support_v4_20_0_0.xml ├── modules.xml ├── gradle.xml ├── compiler.xml ├── misc.xml └── codeStyleSettings.xml ├── app ├── .gitignore ├── libs │ └── universal-image-loader-1.8.6.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ ├── btn_ae.png │ │ │ │ ├── focus.png │ │ │ │ ├── btn_awb.png │ │ │ │ ├── btn_cam.png │ │ │ │ ├── btn_iso.png │ │ │ │ ├── btn_zoom.png │ │ │ │ ├── bg_loading.png │ │ │ │ ├── btn_album.png │ │ │ │ ├── btn_effect.png │ │ │ │ ├── btn_nav_bac.png │ │ │ │ ├── btn_sense.png │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── focus_failed.png │ │ │ │ ├── focus_succeed.png │ │ │ │ ├── bg_focus_start.png │ │ │ │ ├── btn_cam_pressed.png │ │ │ │ ├── btn_flashlight.png │ │ │ │ ├── btn_flash_on_press.png │ │ │ │ ├── btn_setting_normal.png │ │ │ │ ├── ic_camera_wb_auto.png │ │ │ │ ├── ic_camera_wb_shade.png │ │ │ │ ├── btn_flash_auto_normal.png │ │ │ │ ├── btn_flash_auto_press.png │ │ │ │ ├── btn_flash_off_normal.png │ │ │ │ ├── btn_flash_off_press.png │ │ │ │ ├── btn_flash_on_normal.png │ │ │ │ ├── btn_setting_pressed.png │ │ │ │ ├── ic_camera_wb_daylight.png │ │ │ │ ├── ic_camera_wb_twilight.png │ │ │ │ ├── ic_options_item_more.png │ │ │ │ ├── btn_flash_all_on_normal.png │ │ │ │ ├── btn_flash_all_on_press.png │ │ │ │ ├── btn_change_camera_normal.png │ │ │ │ ├── btn_change_camera_pressed.png │ │ │ │ ├── ic_camera_wb_fluorescent.png │ │ │ │ ├── ic_camera_wb_incandescent.png │ │ │ │ ├── icon_setting_arrow_disable.png │ │ │ │ ├── ic_camera_wb_cloudy_daylight.png │ │ │ │ └── ic_camera_wb_warm_fluorescent.png │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ │ └── styles.xml │ │ │ ├── values │ │ │ │ ├── advance.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── common_attrs.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── anim │ │ │ │ ├── alpha_in.xml │ │ │ │ ├── alpha_out.xml │ │ │ │ └── dialog_loading.xml │ │ │ ├── drawable │ │ │ │ ├── advance_setting_item_text_color.xml │ │ │ │ ├── ic_new_tag.xml │ │ │ │ ├── btn_flash_on.xml │ │ │ │ ├── btn_flash_off.xml │ │ │ │ ├── btn_flash_auto.xml │ │ │ │ ├── btn_flash_all_on.xml │ │ │ │ ├── btn_capture.xml │ │ │ │ ├── btn_setting.xml │ │ │ │ ├── btn_change_camera.xml │ │ │ │ ├── title_text_selector.xml │ │ │ │ ├── advance_setting_item_more_icon.xml │ │ │ │ └── bg_transparent_yellow.xml │ │ │ ├── menu │ │ │ │ └── my.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── activity_my.xml │ │ │ │ ├── surface_activity.xml │ │ │ │ ├── show_photo_frag.xml │ │ │ │ ├── item_grid.xml │ │ │ │ ├── album_frag.xml │ │ │ │ ├── item_lv_menu.xml │ │ │ │ ├── flash_activity.xml │ │ │ │ ├── setting_frag.xml │ │ │ │ ├── loading_dialog.xml │ │ │ │ ├── setting_item_layout.xml │ │ │ │ └── title_view_layout.xml │ │ ├── java │ │ │ └── us │ │ │ │ └── yydcdut │ │ │ │ └── androidltest │ │ │ │ ├── MyApp.java │ │ │ │ ├── SleepThread.java │ │ │ │ ├── adpater │ │ │ │ ├── FlashAdapter.java │ │ │ │ ├── EffectAdapter.java │ │ │ │ └── SenseAdapter.java │ │ │ │ ├── view │ │ │ │ ├── AnimationTextView.java │ │ │ │ ├── SettingItem.java │ │ │ │ ├── MyTextureView.java │ │ │ │ ├── AnimationImageView.java │ │ │ │ ├── TitleView.java │ │ │ │ └── AwbSeekBar.java │ │ │ │ ├── callback │ │ │ │ ├── JpegSessionCallback.java │ │ │ │ ├── PreviewSessionCallback.java │ │ │ │ └── DngSessionCallback.java │ │ │ │ ├── listener │ │ │ │ ├── JpegReaderListener.java │ │ │ │ ├── FlashItemClickListener.java │ │ │ │ ├── EffectItemClickListener.java │ │ │ │ ├── TextureViewTouchEvent.java │ │ │ │ ├── AwbSeekBarChangeListener.java │ │ │ │ └── SenseItemClickListener.java │ │ │ │ ├── ui │ │ │ │ ├── ShowPhotoFrag.java │ │ │ │ ├── AlbumFragment.java │ │ │ │ └── SettingFragment.java │ │ │ │ ├── otheractivity │ │ │ │ └── FlashActivity.java │ │ │ │ └── MyActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── us │ │ └── yydcdut │ │ └── androidltest │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── app.iml ├── camera2 ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ ├── btn_cam.png │ │ │ │ ├── ic_launcher.png │ │ │ │ └── btn_setting_normal.png │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ │ └── styles.xml │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── preview_fragment.xml │ │ │ │ └── camera_activity.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── java │ │ │ └── us │ │ │ │ └── yydcdut │ │ │ │ └── camera2 │ │ │ │ ├── CompareSizesByArea.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── PreferenceHelper.java │ │ │ │ ├── ui │ │ │ │ └── ChangeCameraActivity.java │ │ │ │ ├── view │ │ │ │ └── AutoFitTextureView.java │ │ │ │ ├── ImageSaver.java │ │ │ │ ├── DngImageSaver.java │ │ │ │ └── Progress.java │ │ ├── AndroidManifest.xml │ │ └── rs │ │ │ └── yuv2rgb.rs │ └── androidTest │ │ └── java │ │ └── us │ │ └── yydcdut │ │ └── camera2 │ │ └── ApplicationTest.java ├── build.gradle ├── proguard-rules.pro └── camera2.iml ├── settings.gradle ├── .gitignore ├── screenshots └── pic.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── AndroidLTest.iml ├── gradle.properties ├── Camera2.iml ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | AndroidLTest -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /camera2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':camera2' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | .DS_Store 5 | /build 6 | -------------------------------------------------------------------------------- /screenshots/pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/screenshots/pic.png -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/libs/universal-image-loader-1.8.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/libs/universal-image-loader-1.8.6.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_ae.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_ae.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/focus.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Camera2 2 | Android L Camera2 Demo 3 | ![road map](https://github.com/pinguo-yuyidong/Camera2/blob/master/screenshots/pic.png) 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_awb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_awb.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_cam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_cam.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_iso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_iso.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_zoom.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/bg_loading.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_album.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_album.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_effect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_effect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_nav_bac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_nav_bac.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_sense.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_sense.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-xhdpi/btn_cam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-xhdpi/btn_cam.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/focus_failed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/focus_failed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/focus_succeed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/focus_succeed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_focus_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/bg_focus_start.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_cam_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_cam_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flashlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flashlight.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_on_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_on_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_setting_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_setting_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_auto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_auto.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_shade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_shade.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_auto_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_auto_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_auto_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_auto_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_off_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_off_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_off_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_off_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_on_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_on_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_setting_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_setting_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_daylight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_daylight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_twilight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_twilight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_options_item_more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_options_item_more.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_all_on_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_all_on_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_flash_all_on_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_flash_all_on_press.png -------------------------------------------------------------------------------- /camera2/src/main/res/drawable-xhdpi/btn_setting_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/camera2/src/main/res/drawable-xhdpi/btn_setting_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_change_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_change_camera_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_change_camera_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/btn_change_camera_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_fluorescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_fluorescent.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_incandescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_incandescent.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_setting_arrow_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/icon_setting_arrow_disable.png -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_cloudy_daylight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_cloudy_daylight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_camera_wb_warm_fluorescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinguo-yuyidong/Camera2/HEAD/app/src/main/res/drawable-xhdpi/ic_camera_wb_warm_fluorescent.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /camera2/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/advance.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 49dp 4 | 10sp 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /camera2/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /camera2/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /camera2/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | camera2 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/alpha_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/alpha_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 29 19:24:17 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/advance_setting_item_text_color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #c9cdd1 5 | #f8f8f8 6 | 7 | #565555 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/common_attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_new_tag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/universal_image_loader_1_8_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_flash_on.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Camera2 5 | Hello world! 6 | Settings 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_flash_off.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_flash_auto.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_flash_all_on.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/menu/my.xml: -------------------------------------------------------------------------------- 1 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /camera2/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_capture.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /camera2/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /camera2/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_my.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_change_camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 15sp 7 | 105dip 8 | 22dip 9 | 10 | -------------------------------------------------------------------------------- /camera2/src/androidTest/java/us/yydcdut/camera2/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/us/yydcdut/androidltest/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/title_text_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/surface_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/show_photo_frag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/anim/dialog_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_20_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/CompareSizesByArea.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.util.Size; 4 | 5 | import java.util.Comparator; 6 | 7 | /** 8 | * Created by yuyidong on 15-1-8. 9 | */ 10 | public class CompareSizesByArea implements Comparator { 11 | 12 | @Override 13 | public int compare(Size lhs, Size rhs) { 14 | // We cast here to ensure the multiplications won't overflow 15 | return Long.signum((long) lhs.getWidth() * lhs.getHeight() - 16 | (long) rhs.getWidth() * rhs.getHeight()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /camera2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.1" 6 | 7 | defaultConfig { 8 | applicationId "us.yydcdut.camera2" 9 | minSdkVersion 21 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 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(dir: 'libs', include: ['*.jar']) 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/album_frag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/advance_setting_item_more_icon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/MainActivity.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import us.yydcdut.camera2.ui.PreviewFragment; 7 | 8 | 9 | public class MainActivity extends Activity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main); 15 | getFragmentManager().beginTransaction().replace(R.id.layout_frame_main, PreviewFragment.newInstance()).commit(); 16 | // getFragmentManager().beginTransaction().replace(R.id.layout_frame_main, new YUVCameraFragment()).commit(); 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /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 /opt/android-studio/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 | -------------------------------------------------------------------------------- /camera2/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 /opt/android-studio/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 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion '21.1.1' 6 | 7 | defaultConfig { 8 | applicationId "us.yydcdut.androidltest" 9 | minSdkVersion 21 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | // runProguard false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile files('libs/universal-image-loader-1.8.6.jar') 25 | compile 'com.android.support:support-v4:20.0.0' 26 | } 27 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_20_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_lv_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/flash_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 18 | 19 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /AndroidLTest.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /camera2/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Android API 19 Platform 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/MyApp.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest; 2 | 3 | import android.app.Application; 4 | 5 | import com.nostra13.universalimageloader.core.ImageLoader; 6 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 7 | import com.nostra13.universalimageloader.core.assist.QueueProcessingType; 8 | 9 | /** 10 | * Created by yuyidong on 14-12-22. 11 | */ 12 | public class MyApp extends Application { 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 17 | .threadPriority(Thread.NORM_PRIORITY - 2) 18 | .denyCacheImageMultipleSizesInMemory() 19 | .tasksProcessingOrder(QueueProcessingType.LIFO) 20 | .writeDebugLogs() 21 | .build(); 22 | ImageLoader.getInstance().init(config); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/setting_frag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Camera2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/SleepThread.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest; 2 | 3 | import android.os.Handler; 4 | import android.os.Message; 5 | 6 | /** 7 | * Created by yuyidong on 14-12-19. 8 | */ 9 | public class SleepThread implements Runnable { 10 | private Handler mMainHandler; 11 | private int what; 12 | private long mTime; 13 | private Object mObject; 14 | 15 | public SleepThread(Handler mainHandler, int what, long mTime, Object mObject) { 16 | this.mMainHandler = mainHandler; 17 | this.what = what; 18 | this.mTime = mTime; 19 | this.mObject = mObject; 20 | } 21 | 22 | @Override 23 | public void run() { 24 | try { 25 | Thread.sleep(mTime); 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | Message message = mMainHandler.obtainMessage(); 30 | message.what = what; 31 | message.obj = mObject; 32 | mMainHandler.sendMessage(message); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/loading_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 19 | 25 | -------------------------------------------------------------------------------- /camera2/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_transparent_yellow.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/setting_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 12 | 13 | 18 | 19 | 20 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /camera2/src/main/res/layout/preview_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 12 | 13 | 14 | 22 | 23 | 31 | 32 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/adpater/FlashAdapter.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.adpater; 2 | 3 | import android.content.Context; 4 | import android.widget.SimpleAdapter; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import us.yydcdut.androidltest.R; 10 | 11 | /** 12 | * Created by yuyidong on 14-12-18. 13 | */ 14 | public class FlashAdapter { 15 | 16 | public static SimpleAdapter getAdapter(Context context) { 17 | ArrayList> listItem = getFlashList(); 18 | SimpleAdapter listItemAdapter = new SimpleAdapter(context, listItem, R.layout.item_lv_menu, new String[]{"text"}, new int[]{R.id.txt_item_menu}); 19 | return listItemAdapter; 20 | } 21 | 22 | private static ArrayList> getFlashList() { 23 | ArrayList> listItem = new ArrayList>(); 24 | HashMap map1 = new HashMap(); 25 | map1.put("text", "OFF"); 26 | listItem.add(map1); 27 | HashMap map2 = new HashMap(); 28 | map2.put("text", "SINGLE"); 29 | listItem.add(map2); 30 | HashMap map3 = new HashMap(); 31 | map3.put("text", "TORCH"); 32 | listItem.add(map3); 33 | HashMap map4 = new HashMap(); 34 | map4.put("text", "AOTO"); 35 | listItem.add(map4); 36 | HashMap map5 = new HashMap(); 37 | map5.put("text", "ON"); 38 | listItem.add(map5); 39 | return listItem; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/title_view_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 20 | 21 | 32 | 33 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/PreferenceHelper.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by yuyidong on 15-1-12. 8 | */ 9 | public class PreferenceHelper { 10 | 11 | public static String getCameraId(Context context) { 12 | SharedPreferences preferences; 13 | String cameraid; 14 | if (context != null) { 15 | preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); 16 | cameraid = preferences.getString("camera", "0"); 17 | } else { 18 | cameraid = "0"; 19 | } 20 | return cameraid; 21 | } 22 | 23 | public static void writeCameraId(Context context, String value) { 24 | SharedPreferences preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); 25 | SharedPreferences.Editor editor = preferences.edit(); 26 | editor.putString("camera", value); 27 | editor.commit(); 28 | } 29 | 30 | public static String getCameraFormat(Context context) { 31 | SharedPreferences preferences; 32 | String format; 33 | if (context != null) { 34 | preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); 35 | format = preferences.getString("format", "JPEG"); 36 | } else { 37 | format = "JPEG"; 38 | } 39 | return format; 40 | } 41 | 42 | public static void writeCameraFormat(Context context, String value) { 43 | SharedPreferences preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); 44 | SharedPreferences.Editor editor = preferences.edit(); 45 | editor.putString("format", value); 46 | editor.commit(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/AnimationTextView.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.AttributeSet; 6 | import android.view.animation.Animation; 7 | import android.widget.TextView; 8 | 9 | import us.yydcdut.androidltest.SleepThread; 10 | 11 | /** 12 | * Created by yuyidong on 14-12-23. 13 | */ 14 | public class AnimationTextView extends TextView { 15 | private Handler mMainHandler; 16 | private Animation mAnimation; 17 | /** 18 | * 防止又换了个text,但是上次哪个还没有消失即将小时就把新的text的给消失了 19 | */ 20 | public int mTimes = 0; 21 | 22 | public AnimationTextView(Context context) { 23 | super(context); 24 | } 25 | 26 | public AnimationTextView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public AnimationTextView(Context context, AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | public AnimationTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | public void setmMainHandler(Handler mMainHandler) { 39 | this.mMainHandler = mMainHandler; 40 | } 41 | 42 | public void setmAnimation(Animation mAnimation) { 43 | this.mAnimation = mAnimation; 44 | } 45 | 46 | public void start(String text, int message) { 47 | if (mAnimation == null || mMainHandler == null) { 48 | return; 49 | } 50 | this.setVisibility(VISIBLE); 51 | mTimes++; 52 | this.setText(text); 53 | this.startAnimation(mAnimation); 54 | new Thread(new SleepThread(mMainHandler, message, 1000, Integer.valueOf(mTimes))).start(); 55 | } 56 | 57 | public void stop() { 58 | this.setVisibility(GONE); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /camera2/src/main/res/layout/camera_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 31 | 37 | 38 | 42 | 43 | 47 | 48 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /camera2/src/main/rs/yuv2rgb.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma version(1) 17 | #pragma rs java_package_name(us.yydcdut.camera2) 18 | #pragma rs_fp_relaxed 19 | 20 | rs_allocation gCurrentFrame; 21 | rs_allocation gPrevFrame; 22 | 23 | uchar4 __attribute__((kernel)) yuv2rgbFrames(uchar4 prevPixel, uint32_t x, uint32_t y) { 24 | 25 | // Read in pixel values from latest frame - YUV color space 26 | 27 | uchar4 curPixel; 28 | curPixel.r = rsGetElementAtYuv_uchar_Y(gCurrentFrame, x, y); 29 | curPixel.g = rsGetElementAtYuv_uchar_U(gCurrentFrame, x, y); 30 | curPixel.b = rsGetElementAtYuv_uchar_V(gCurrentFrame, x, y); 31 | curPixel.a = 255; 32 | 33 | // Straight passthrough 34 | uchar4 mergedPixel= curPixel; 35 | 36 | // Convert YUV to RGB, JFIF transform with fixed-point math 37 | // R = Y + 1.402 * (V - 128) 38 | // G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128) 39 | // B = Y + 1.772 * (U - 128) 40 | 41 | int4 rgb; 42 | rgb.r = mergedPixel.r + 43 | mergedPixel.b * 1436 / 1024 - 179; 44 | rgb.g = mergedPixel.r - 45 | mergedPixel.g * 46549 / 131072 + 44 - 46 | mergedPixel.b * 93604 / 131072 + 91; 47 | rgb.b = mergedPixel.r + 48 | mergedPixel.g * 1814 / 1024 - 227; 49 | rgb.a = 255; 50 | 51 | // Store current pixel for next frame 52 | rsSetElementAt_uchar4(gPrevFrame, curPixel, x, y); 53 | 54 | // Write out merged HDR result 55 | uchar4 out = convert_uchar4(clamp(rgb, 0, 255)); 56 | 57 | return out; 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/SettingItem.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.util.AttributeSet; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.ImageView; 10 | import android.widget.RelativeLayout; 11 | import android.widget.TextView; 12 | 13 | import us.yydcdut.androidltest.R; 14 | 15 | public class SettingItem extends RelativeLayout { 16 | private TextView mTitle; 17 | private ImageView mIcon; 18 | private ImageView mImage; 19 | private ImageView mNew; 20 | 21 | public SettingItem(Context context) { 22 | super(context); 23 | } 24 | 25 | public SettingItem(Context context, AttributeSet attrs, int defStyleAttr) { 26 | super(context, attrs, defStyleAttr); 27 | } 28 | 29 | public SettingItem(Context context, AttributeSet attributeSet) { 30 | super(context, attributeSet); 31 | initView(context, attributeSet); 32 | } 33 | 34 | private void initView(Context context, AttributeSet attributeSet) { 35 | TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.SettingItem); 36 | float textSize = a.getDimension(R.styleable.SettingItem_customTextSize, 15f); 37 | int textColor = a.getColor(R.styleable.SettingItem_customTextColor, Color.parseColor("#7b8085")); 38 | 39 | View root = LayoutInflater.from(context).inflate(R.layout.setting_item_layout, this); 40 | mTitle = (TextView) root.findViewById(R.id.title); 41 | mTitle.setTextSize(textSize); 42 | mTitle.setTextColor(textColor); 43 | mIcon = (ImageView) root.findViewById(R.id.option_item_icon); 44 | mImage = (ImageView) root.findViewById(R.id.image); 45 | mNew = (ImageView) root.findViewById(R.id.image_new); 46 | } 47 | 48 | public TextView getTitle() { 49 | return mTitle; 50 | } 51 | 52 | public ImageView getIcon() { 53 | return mIcon; 54 | } 55 | 56 | public ImageView getNextImage() { 57 | return mImage; 58 | } 59 | 60 | public ImageView getNewImage() { 61 | return mNew; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/adpater/EffectAdapter.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.adpater; 2 | 3 | import android.content.Context; 4 | import android.widget.SimpleAdapter; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import us.yydcdut.androidltest.R; 10 | 11 | /** 12 | * Created by yuyidong on 14-12-18. 13 | */ 14 | public class EffectAdapter { 15 | 16 | public static SimpleAdapter getAdapter(Context context) { 17 | ArrayList> listItem = getEffectList(); 18 | SimpleAdapter listItemAdapter = new SimpleAdapter(context, listItem, R.layout.item_lv_menu, new String[]{"text"}, new int[]{R.id.txt_item_menu}); 19 | return listItemAdapter; 20 | } 21 | 22 | private static ArrayList> getEffectList() { 23 | ArrayList> listItem = new ArrayList>(); 24 | HashMap map1 = new HashMap(); 25 | map1.put("text", "aqua"); 26 | listItem.add(map1); 27 | HashMap map2 = new HashMap(); 28 | map2.put("text", "blackboard"); 29 | listItem.add(map2); 30 | HashMap map3 = new HashMap(); 31 | map3.put("text", "monocolor"); 32 | listItem.add(map3); 33 | HashMap map4 = new HashMap(); 34 | map4.put("text", "negative"); 35 | listItem.add(map4); 36 | HashMap map5 = new HashMap(); 37 | map5.put("text", "posterization"); 38 | listItem.add(map5); 39 | HashMap map6 = new HashMap(); 40 | map6.put("text", "sepia"); 41 | listItem.add(map6); 42 | HashMap map7 = new HashMap(); 43 | map7.put("text", "solarisation"); 44 | listItem.add(map7); 45 | HashMap map8 = new HashMap(); 46 | map8.put("text", "whiteboard"); 47 | listItem.add(map8); 48 | HashMap map9 = new HashMap(); 49 | map9.put("text", "off"); 50 | listItem.add(map9); 51 | return listItem; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/ui/ChangeCameraActivity.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2.ui; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.widget.CompoundButton; 7 | import android.widget.Switch; 8 | 9 | import us.yydcdut.camera2.PreferenceHelper; 10 | import us.yydcdut.camera2.R; 11 | 12 | /** 13 | * Created by yuyidong on 15-1-12. 14 | */ 15 | public class ChangeCameraActivity extends Activity { 16 | private Context mContext = ChangeCameraActivity.this; 17 | private Switch mSwitchCameraFormat; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.camera_activity); 23 | 24 | Switch switchCameraId = (Switch) findViewById(R.id.switch_camera); 25 | String cameraId = PreferenceHelper.getCameraId(mContext); 26 | if (cameraId.equals("0")) { 27 | switchCameraId.setChecked(false); 28 | } else { 29 | switchCameraId.setChecked(true); 30 | } 31 | switchCameraId.setOnCheckedChangeListener(mListener); 32 | 33 | mSwitchCameraFormat = (Switch) findViewById(R.id.switch_format); 34 | String cameraFormat = PreferenceHelper.getCameraFormat(mContext); 35 | if (cameraFormat.equals("JPEG")) { 36 | mSwitchCameraFormat.setChecked(false); 37 | } else { 38 | mSwitchCameraFormat.setChecked(true); 39 | } 40 | mSwitchCameraFormat.setOnCheckedChangeListener(mListener); 41 | 42 | } 43 | 44 | private CompoundButton.OnCheckedChangeListener mListener = new CompoundButton.OnCheckedChangeListener() { 45 | 46 | @Override 47 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 48 | switch (buttonView.getId()) { 49 | case R.id.switch_camera: 50 | if (isChecked == false) { 51 | PreferenceHelper.writeCameraId(mContext, "0"); 52 | } else { 53 | PreferenceHelper.writeCameraId(mContext, "1"); 54 | PreferenceHelper.writeCameraFormat(mContext, "JPEG"); 55 | mSwitchCameraFormat.setChecked(false); 56 | } 57 | break; 58 | case R.id.switch_format: 59 | if (isChecked == false) { 60 | PreferenceHelper.writeCameraFormat(mContext, "JPEG"); 61 | } else { 62 | PreferenceHelper.writeCameraFormat(mContext, "DNG"); 63 | } 64 | break; 65 | } 66 | } 67 | }; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/MyTextureView.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.view.TextureView; 7 | 8 | /** 9 | * Created by yuyidong on 14-12-10. 10 | */ 11 | public class MyTextureView extends TextureView { 12 | private int mRatioWidth = 0; 13 | private int mRatioHeight = 0; 14 | private MyTextureViewTouchEvent mMyTextureViewTouchEvent; 15 | private FocusPositionTouchEvent mFocusPositionTouchEvent; 16 | 17 | public MyTextureView(Context context) { 18 | super(context); 19 | } 20 | 21 | public MyTextureView(Context context, AttributeSet attrs) { 22 | super(context, attrs); 23 | } 24 | 25 | public MyTextureView(Context context, AttributeSet attrs, int defStyleAttr) { 26 | super(context, attrs, defStyleAttr); 27 | } 28 | 29 | @Override 30 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 31 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 32 | int width = MeasureSpec.getSize(widthMeasureSpec); 33 | int height = MeasureSpec.getSize(heightMeasureSpec); 34 | if (0 == mRatioWidth || 0 == mRatioHeight) { 35 | setMeasuredDimension(width, height); 36 | } else { 37 | if (width < height * mRatioWidth / mRatioHeight) { 38 | setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); 39 | } else { 40 | setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); 41 | } 42 | } 43 | } 44 | 45 | public void fitWindow(int width, int height) { 46 | if (width < 0 || height < 0) { 47 | throw new IllegalArgumentException("Size cannot be negative."); 48 | } 49 | mRatioWidth = width; 50 | mRatioHeight = height; 51 | requestLayout(); 52 | } 53 | 54 | @Override 55 | public boolean onTouchEvent(MotionEvent event) { 56 | mFocusPositionTouchEvent.getPosition(event); 57 | return mMyTextureViewTouchEvent.onAreaTouchEvent(event); 58 | } 59 | 60 | public void setmMyTextureViewTouchEvent(MyTextureViewTouchEvent myTextureViewTouchEvent) { 61 | this.mMyTextureViewTouchEvent = myTextureViewTouchEvent; 62 | } 63 | 64 | public void setmFocusPositionTouchEvent(FocusPositionTouchEvent mFocusPositionTouchEvent) { 65 | this.mFocusPositionTouchEvent = mFocusPositionTouchEvent; 66 | } 67 | 68 | public interface MyTextureViewTouchEvent { 69 | public boolean onAreaTouchEvent(MotionEvent event); 70 | } 71 | 72 | public interface FocusPositionTouchEvent { 73 | public void getPosition(MotionEvent event); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/callback/JpegSessionCallback.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.callback; 2 | 3 | import android.hardware.camera2.CameraCaptureSession; 4 | import android.hardware.camera2.CameraMetadata; 5 | import android.hardware.camera2.CaptureRequest; 6 | import android.hardware.camera2.CaptureResult; 7 | import android.hardware.camera2.TotalCaptureResult; 8 | import android.media.MediaActionSound; 9 | import android.os.Handler; 10 | import android.util.Log; 11 | 12 | /** 13 | * Created by yuyidong on 14-12-17. 14 | */ 15 | public class JpegSessionCallback extends CameraCaptureSession.CaptureCallback { 16 | private Handler mHandler; 17 | private MediaActionSound mMediaActionSound; 18 | private Handler mMainHanler; 19 | 20 | public JpegSessionCallback(Handler mHandler, MediaActionSound mMediaActionSound, Handler mMainHanler) { 21 | this.mHandler = mHandler; 22 | this.mMediaActionSound = mMediaActionSound; 23 | this.mMainHanler = mMainHanler; 24 | } 25 | 26 | @Override 27 | public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { 28 | Log.i("JpegSessionCallback", "onCaptureCompleted"); 29 | super.onCaptureCompleted(session, request, result); 30 | Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); 31 | Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); 32 | if (afState == null || aeState == null) { 33 | return; 34 | } 35 | //todo:这里处理的不是很完善 36 | Log.i("JpegSessionCallback", "要开始进入了,,afState.intValue()--->" + afState.intValue()); 37 | //聚焦完成才能拍照 38 | if (afState.intValue() == CameraMetadata.CONTROL_AF_STATE_FOCUSED_LOCKED || afState.intValue() == CameraMetadata.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED 39 | || CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED == afState.intValue() || CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED == afState.intValue()) { 40 | Log.i("JpegSessionCallback", "进去了一层,,aeState.intValue()--->" + aeState.intValue()); 41 | if (aeState.intValue() == CameraMetadata.CONTROL_AE_STATE_LOCKED || aeState.intValue() == CameraMetadata.CONTROL_AE_STATE_PRECAPTURE 42 | || aeState.intValue() == CameraMetadata.CONTROL_AE_STATE_FLASH_REQUIRED || aeState.intValue() == CameraMetadata.CONTROL_AE_STATE_CONVERGED) { 43 | Log.i("JpegSessionCallback", "进去了两层"); 44 | mHandler.post(new Runnable() { 45 | @Override 46 | public void run() { 47 | mMediaActionSound.play(MediaActionSound.SHUTTER_CLICK); 48 | } 49 | }); 50 | } else { 51 | // mMainHanler.sendEmptyMessage(DisplayFragment.FOCUS_AGAIN); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/AnimationImageView.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.animation.Animation; 8 | import android.widget.ImageView; 9 | 10 | import us.yydcdut.androidltest.R; 11 | import us.yydcdut.androidltest.SleepThread; 12 | import us.yydcdut.androidltest.ui.DisplayFragment; 13 | 14 | /** 15 | * Created by yuyidong on 14-12-23. 16 | */ 17 | public class AnimationImageView extends ImageView { 18 | private Handler mMainHandler; 19 | private Animation mAnimation; 20 | private Context mContext; 21 | /** 22 | * 防止又换了个text,但是上次哪个还没有消失即将小时就把新的text的给消失了 23 | */ 24 | public int mTimes = 0; 25 | 26 | public AnimationImageView(Context context) { 27 | super(context); 28 | mContext = context; 29 | } 30 | 31 | public AnimationImageView(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | mContext = context; 34 | } 35 | 36 | public AnimationImageView(Context context, AttributeSet attrs, int defStyleAttr) { 37 | super(context, attrs, defStyleAttr); 38 | mContext = context; 39 | } 40 | 41 | public AnimationImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 42 | super(context, attrs, defStyleAttr, defStyleRes); 43 | mContext = context; 44 | } 45 | 46 | public void setmMainHandler(Handler mMainHandler) { 47 | this.mMainHandler = mMainHandler; 48 | } 49 | 50 | public void setmAnimation(Animation mAnimation) { 51 | this.mAnimation = mAnimation; 52 | } 53 | 54 | public void initFocus() { 55 | this.setVisibility(VISIBLE); 56 | new Thread(new SleepThread(mMainHandler, DisplayFragment.FOCUS_DISAPPEAR, 1000, null)).start(); 57 | } 58 | 59 | public void startFocusing() { 60 | mTimes++; 61 | this.setVisibility(View.VISIBLE); 62 | this.startAnimation(mAnimation); 63 | this.setBackground(mContext.getDrawable(R.drawable.focus)); 64 | new Thread(new SleepThread(mMainHandler, DisplayFragment.FOCUS_DISAPPEAR, 1000, Integer.valueOf(mTimes))).start(); 65 | } 66 | 67 | public void focusFailed() { 68 | mTimes++; 69 | this.setBackground(mContext.getDrawable(R.drawable.focus_failed)); 70 | new Thread(new SleepThread(mMainHandler, DisplayFragment.FOCUS_DISAPPEAR, 800, Integer.valueOf(mTimes))).start(); 71 | } 72 | 73 | public void focusSuccess() { 74 | mTimes++; 75 | this.setVisibility(View.VISIBLE); 76 | this.setBackground(mContext.getDrawable(R.drawable.focus_succeed)); 77 | new Thread(new SleepThread(mMainHandler, DisplayFragment.FOCUS_DISAPPEAR, 800, Integer.valueOf(mTimes))).start(); 78 | } 79 | 80 | public void stopFocus() { 81 | this.setVisibility(INVISIBLE); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/view/AutoFitTextureView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package us.yydcdut.camera2.view; 18 | 19 | import android.content.Context; 20 | import android.util.AttributeSet; 21 | import android.view.TextureView; 22 | 23 | /** 24 | * A {@link android.view.TextureView} that can be adjusted to a specified aspect ratio. 25 | */ 26 | public class AutoFitTextureView extends TextureView { 27 | 28 | private int mRatioWidth = 0; 29 | private int mRatioHeight = 0; 30 | 31 | public AutoFitTextureView(Context context) { 32 | this(context, null); 33 | } 34 | 35 | public AutoFitTextureView(Context context, AttributeSet attrs) { 36 | this(context, attrs, 0); 37 | } 38 | 39 | public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) { 40 | super(context, attrs, defStyle); 41 | } 42 | 43 | /** 44 | * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio 45 | * calculated from the parameters. Note that the actual sizes of parameters don't matter, that 46 | * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. 47 | * 48 | * @param width Relative horizontal size 49 | * @param height Relative vertical size 50 | */ 51 | public void setAspectRatio(int width, int height) { 52 | if (width < 0 || height < 0) { 53 | throw new IllegalArgumentException("Size cannot be negative."); 54 | } 55 | mRatioWidth = width; 56 | mRatioHeight = height; 57 | requestLayout(); 58 | } 59 | 60 | @Override 61 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 62 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 63 | int width = MeasureSpec.getSize(widthMeasureSpec); 64 | int height = MeasureSpec.getSize(heightMeasureSpec); 65 | if (0 == mRatioWidth || 0 == mRatioHeight) { 66 | setMeasuredDimension(width, height); 67 | } else { 68 | if (width < height * mRatioWidth / mRatioHeight) { 69 | setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); 70 | } else { 71 | setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); 72 | } 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/ImageSaver.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.media.Image; 4 | import android.media.ImageReader; 5 | import android.os.Environment; 6 | import android.util.Log; 7 | 8 | import java.io.File; 9 | import java.io.FileNotFoundException; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.OutputStream; 13 | import java.nio.ByteBuffer; 14 | import java.util.Random; 15 | 16 | /** 17 | * Created by yuyidong on 15-1-9. 18 | */ 19 | public class ImageSaver implements Runnable { 20 | 21 | private ImageReader mImageReader; 22 | 23 | public ImageSaver(ImageReader mImageReader) { 24 | this.mImageReader = mImageReader; 25 | } 26 | 27 | @Override 28 | public void run() { 29 | Log.i("level", "ImageSaver--->run"); 30 | Image image = mImageReader.acquireLatestImage(); 31 | checkParentDir(); 32 | File file; 33 | checkJpegDir(); 34 | file = createJpeg(); 35 | try { 36 | ByteBuffer buffer = image.getPlanes()[0].getBuffer(); 37 | byte[] bytes = new byte[buffer.remaining()]; 38 | buffer.get(bytes); 39 | try { 40 | save(bytes, file); 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } 44 | image.close(); 45 | } catch (Exception e) { 46 | e.getStackTrace(); 47 | } 48 | } 49 | 50 | /** 51 | * 判断父文件是否存在 52 | */ 53 | private void checkParentDir() { 54 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/"); 55 | if (!dir.exists()) { 56 | dir.mkdir(); 57 | } 58 | } 59 | 60 | /** 61 | * 判断文件夹是否存在 62 | */ 63 | private void checkJpegDir() { 64 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 65 | if (!dir.exists()) { 66 | dir.mkdir(); 67 | } 68 | } 69 | 70 | 71 | /** 72 | * 创建jpeg的文件 73 | * 74 | * @return 75 | */ 76 | private File createJpeg() { 77 | long time = System.currentTimeMillis(); 78 | int random = new Random().nextInt(1000); 79 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 80 | Log.i("JpegSaver", time + "_" + random + ".jpg"); 81 | return new File(dir, time + "_" + random + ".jpg"); 82 | } 83 | 84 | 85 | /** 86 | * 保存 87 | * 88 | * @param bytes 89 | * @param file 90 | * @throws java.io.IOException 91 | */ 92 | private void save(byte[] bytes, File file) throws IOException { 93 | Log.i("JpegSaver", "save"); 94 | OutputStream os = null; 95 | try { 96 | os = new FileOutputStream(file); 97 | os.write(bytes); 98 | } catch (FileNotFoundException e) { 99 | e.printStackTrace(); 100 | } catch (IOException e) { 101 | e.printStackTrace(); 102 | } finally { 103 | if (os != null) { 104 | os.close(); 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/DngImageSaver.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.content.Context; 4 | import android.hardware.camera2.CameraAccessException; 5 | import android.hardware.camera2.CameraCharacteristics; 6 | import android.hardware.camera2.CameraManager; 7 | import android.hardware.camera2.CaptureResult; 8 | import android.hardware.camera2.DngCreator; 9 | import android.media.Image; 10 | import android.media.ImageReader; 11 | import android.os.Environment; 12 | import android.util.Log; 13 | 14 | import java.io.File; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | import java.util.Random; 18 | 19 | /** 20 | * Created by yuyidong on 15-1-12. 21 | */ 22 | public class DngImageSaver implements Runnable { 23 | private Context mContext; 24 | private ImageReader mRawImageReader; 25 | private CaptureResult mResult; 26 | 27 | public DngImageSaver(Context mContext, ImageReader mRawImageReader, CaptureResult mResult) { 28 | this.mContext = mContext; 29 | this.mRawImageReader = mRawImageReader; 30 | this.mResult = mResult; 31 | } 32 | 33 | 34 | @Override 35 | public void run() { 36 | if (mRawImageReader == null) { 37 | Log.i("mRawImageReader", "mRawImageReader===null"); 38 | return; 39 | } 40 | DngCreator dngCreator = null; 41 | Image image = mRawImageReader.acquireNextImage(); 42 | while (image == null) { 43 | image = mRawImageReader.acquireNextImage(); 44 | } 45 | if (image == null) { 46 | Log.i("image", "image===null"); 47 | return; 48 | } 49 | CameraManager manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE); 50 | try { 51 | //前置摄像头没有dng 52 | CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics("0"); 53 | dngCreator = new DngCreator(cameraCharacteristics, mResult); 54 | dngCreator.writeImage(new FileOutputStream(createFile()), image); 55 | Log.i("DngImageSaver", createFile().getAbsolutePath()); 56 | } catch (CameraAccessException e) { 57 | e.printStackTrace(); 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | Log.e("DngRunnable", "Exception eException eException e"); 63 | } finally { 64 | System.gc(); 65 | try { 66 | image.close(); 67 | dngCreator.close(); 68 | } catch (Exception e) { 69 | Log.e("DngRunnable", "dngCreator.close();dngCreator.close();"); 70 | } 71 | } 72 | } 73 | 74 | private File createFile() { 75 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/"); 76 | if (!dir.exists()) { 77 | dir.mkdir(); 78 | } 79 | long time = System.currentTimeMillis(); 80 | int random = new Random().nextInt(1000); 81 | File dir1 = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/dng/"); 82 | if (!dir1.exists()) { 83 | dir1.mkdir(); 84 | } 85 | File meidaFile = new File(dir1, time + "_" + random + ".dng"); 86 | return meidaFile; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/adpater/SenseAdapter.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.adpater; 2 | 3 | import android.content.Context; 4 | import android.widget.SimpleAdapter; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import us.yydcdut.androidltest.R; 10 | 11 | /** 12 | * Created by yuyidong on 14-12-23. 13 | */ 14 | public class SenseAdapter { 15 | 16 | public static SimpleAdapter getAdapter(Context context) { 17 | ArrayList> listItem = getSenseList(); 18 | SimpleAdapter listItemAdapter = new SimpleAdapter(context, listItem, R.layout.item_lv_menu, new String[]{"text"}, new int[]{R.id.txt_item_menu}); 19 | return listItemAdapter; 20 | } 21 | 22 | private static ArrayList> getSenseList() { 23 | ArrayList> listItem = new ArrayList>(); 24 | HashMap map1 = new HashMap(); 25 | map1.put("text", "DISABLED"); 26 | listItem.add(map1); 27 | HashMap map2 = new HashMap(); 28 | map2.put("text", "FACE_PRIORITY"); 29 | listItem.add(map2); 30 | HashMap map3 = new HashMap(); 31 | map3.put("text", "ACTION"); 32 | listItem.add(map3); 33 | HashMap map4 = new HashMap(); 34 | map4.put("text", "PORTRAIT"); 35 | listItem.add(map4); 36 | HashMap map5 = new HashMap(); 37 | map5.put("text", "LANDSCAPE"); 38 | listItem.add(map5); 39 | HashMap map6 = new HashMap(); 40 | map6.put("text", "NIGHT"); 41 | listItem.add(map6); 42 | HashMap map7 = new HashMap(); 43 | map7.put("text", "NIGHT_PORTRAIT"); 44 | listItem.add(map7); 45 | HashMap map8 = new HashMap(); 46 | map8.put("text", "THEATRE"); 47 | listItem.add(map8); 48 | HashMap map9 = new HashMap(); 49 | map9.put("text", "BEACH"); 50 | listItem.add(map9); 51 | HashMap map10 = new HashMap(); 52 | map10.put("text", "SNOW"); 53 | listItem.add(map10); 54 | HashMap map11 = new HashMap(); 55 | map11.put("text", "SUNSET"); 56 | listItem.add(map11); 57 | HashMap map12 = new HashMap(); 58 | map12.put("text", "STEADYPHOTO"); 59 | listItem.add(map12); 60 | HashMap map13 = new HashMap(); 61 | map13.put("text", "FIREWORKS"); 62 | listItem.add(map13); 63 | HashMap map14 = new HashMap(); 64 | map14.put("text", "SPORTS"); 65 | listItem.add(map14); 66 | HashMap map15 = new HashMap(); 67 | map15.put("text", "PARTY"); 68 | listItem.add(map15); 69 | HashMap map16 = new HashMap(); 70 | map16.put("text", "CANDLELIGHT"); 71 | listItem.add(map16); 72 | HashMap map17 = new HashMap(); 73 | map17.put("text", "BARCODE"); 74 | listItem.add(map17); 75 | 76 | 77 | return listItem; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/JpegReaderListener.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.media.Image; 4 | import android.media.ImageReader; 5 | import android.os.Environment; 6 | import android.util.Log; 7 | 8 | import java.io.File; 9 | import java.io.FileNotFoundException; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.OutputStream; 13 | import java.nio.ByteBuffer; 14 | import java.util.Random; 15 | 16 | /** 17 | * Created by yuyidong on 15-1-8. 18 | */ 19 | public class JpegReaderListener implements ImageReader.OnImageAvailableListener { 20 | @Override 21 | public void onImageAvailable(ImageReader reader) { 22 | new Thread(new ImageSaver(reader)).start(); 23 | } 24 | 25 | class ImageSaver implements Runnable { 26 | private ImageReader mImageReader; 27 | 28 | ImageSaver(ImageReader mImageReader) { 29 | this.mImageReader = mImageReader; 30 | } 31 | 32 | @Override 33 | public void run() { 34 | Image image = mImageReader.acquireLatestImage(); 35 | checkParentDir(); 36 | File file; 37 | checkJpegDir(); 38 | file = createJpeg(); 39 | try { 40 | ByteBuffer buffer = image.getPlanes()[0].getBuffer(); 41 | byte[] bytes = new byte[buffer.remaining()]; 42 | buffer.get(bytes); 43 | try { 44 | save(bytes, file); 45 | } catch (IOException e) { 46 | e.printStackTrace(); 47 | } 48 | image.close(); 49 | } catch (Exception e) { 50 | e.getStackTrace(); 51 | } 52 | } 53 | } 54 | 55 | 56 | /** 57 | * 判断父文件是否存在 58 | */ 59 | private void checkParentDir() { 60 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/"); 61 | if (!dir.exists()) { 62 | dir.mkdir(); 63 | } 64 | } 65 | 66 | /** 67 | * 判断文件夹是否存在 68 | */ 69 | private void checkJpegDir() { 70 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 71 | if (!dir.exists()) { 72 | dir.mkdir(); 73 | } 74 | } 75 | 76 | 77 | /** 78 | * 创建jpeg的文件 79 | * 80 | * @return 81 | */ 82 | private File createJpeg() { 83 | long time = System.currentTimeMillis(); 84 | int random = new Random().nextInt(1000); 85 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 86 | Log.i("JpegSaver", time + "_" + random + ".jpg"); 87 | return new File(dir, time + "_" + random + ".jpg"); 88 | } 89 | 90 | 91 | /** 92 | * 保存 93 | * 94 | * @param bytes 95 | * @param file 96 | * @throws java.io.IOException 97 | */ 98 | private void save(byte[] bytes, File file) throws IOException { 99 | Log.i("JpegSaver", "save"); 100 | OutputStream os = null; 101 | try { 102 | os = new FileOutputStream(file); 103 | os.write(bytes); 104 | } catch (FileNotFoundException e) { 105 | e.printStackTrace(); 106 | } catch (IOException e) { 107 | e.printStackTrace(); 108 | } finally { 109 | if (os != null) { 110 | os.close(); 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 13 | 14 | 18 | 19 | 25 | 26 | 33 | 34 | 41 | 42 | 50 | 51 | 56 | 57 | 64 | 65 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/TitleView.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.RelativeLayout; 7 | import android.widget.TextView; 8 | 9 | import us.yydcdut.androidltest.R; 10 | 11 | 12 | /** 13 | * Created by marui on 13-12-3. 14 | */ 15 | public class TitleView extends RelativeLayout { 16 | 17 | //Views 18 | private View mTitleBackBtn; 19 | private TextView mTitleText; 20 | private TextView mTitleRightBtn; 21 | // 22 | private OnTitleViewClickListener mClickListener; 23 | 24 | public TitleView(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @Override 29 | protected void onFinishInflate() { 30 | super.onFinishInflate(); 31 | mTitleText = (TextView) findViewById(R.id.title_text_title); 32 | mTitleBackBtn = findViewById(R.id.title_back_btn); 33 | mTitleRightBtn = (TextView) findViewById(R.id.title_right_btn); 34 | 35 | 36 | if (isInEditMode()) { 37 | return; 38 | } 39 | 40 | mTitleBackBtn.setOnClickListener(new OnClickListener() { 41 | @Override 42 | public void onClick(View view) { 43 | if (mClickListener != null) { 44 | mClickListener.onBackClick(); 45 | } 46 | } 47 | }); 48 | 49 | mTitleRightBtn.setOnClickListener(new OnClickListener() { 50 | @Override 51 | public void onClick(View view) { 52 | if (mClickListener != null) { 53 | mClickListener.onRightBtnClick(); 54 | } 55 | } 56 | }); 57 | } 58 | 59 | 60 | public TitleView(Context context) { 61 | this(context, null); 62 | } 63 | 64 | public void hideRightBtn() { 65 | if (mTitleRightBtn != null) { 66 | mTitleRightBtn.setVisibility(View.GONE); 67 | } 68 | } 69 | 70 | public void showRightBtn() { 71 | if (mTitleRightBtn != null) { 72 | mTitleRightBtn.setVisibility(View.VISIBLE); 73 | } 74 | } 75 | 76 | // public void showRightImageBtn() { 77 | // if (mTitleRightImageBtn != null) { 78 | // mTitleRightImageBtn.setVisibility(View.VISIBLE); 79 | // } 80 | // } 81 | 82 | public void hideBackBtn() { 83 | if (mTitleBackBtn != null) { 84 | mTitleBackBtn.setVisibility(View.GONE); 85 | } 86 | } 87 | 88 | 89 | public void setTiTleText(int resId) { 90 | mTitleText.setText(resId); 91 | } 92 | 93 | public void setTiTleText(CharSequence text) { 94 | mTitleText.setText(text); 95 | } 96 | 97 | public void setRightBtnText(int resId) { 98 | mTitleRightBtn.setText(resId); 99 | } 100 | 101 | public String getRightBtnText() { 102 | return (String) mTitleRightBtn.getText(); 103 | } 104 | 105 | public void setRightBtnEnable(boolean isEnable) { 106 | mTitleRightBtn.setEnabled(isEnable); 107 | } 108 | 109 | public void setRightBtnClickState(boolean state) { 110 | mTitleRightBtn.setClickable(state); 111 | mTitleRightBtn.setEnabled(state); 112 | } 113 | 114 | public void setRightBtnText(CharSequence text) { 115 | mTitleRightBtn.setText(text); 116 | } 117 | 118 | public void setOnTitleViewClickListener(OnTitleViewClickListener listener) { 119 | mClickListener = listener; 120 | } 121 | 122 | public interface OnTitleViewClickListener { 123 | public void onBackClick(); 124 | 125 | public void onRightBtnClick(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/FlashItemClickListener.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.hardware.camera2.CameraAccessException; 4 | import android.hardware.camera2.CameraCaptureSession; 5 | import android.hardware.camera2.CameraMetadata; 6 | import android.hardware.camera2.CaptureRequest; 7 | import android.os.Handler; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.AdapterView; 11 | import android.widget.ImageView; 12 | import android.widget.PopupWindow; 13 | 14 | import us.yydcdut.androidltest.R; 15 | import us.yydcdut.androidltest.callback.PreviewSessionCallback; 16 | import us.yydcdut.androidltest.ui.DisplayFragment; 17 | import us.yydcdut.androidltest.view.AnimationTextView; 18 | 19 | /** 20 | * Created by yuyidong on 14-12-18. 21 | */ 22 | public class FlashItemClickListener implements AdapterView.OnItemClickListener { 23 | private CaptureRequest.Builder mPreviewBuilder; 24 | private CameraCaptureSession mCameraCaptureSession; 25 | private Handler mHandler; 26 | private PopupWindow mWindow; 27 | private ImageView mBtnFlash; 28 | private PreviewSessionCallback mPreviewSessionCallback; 29 | private AnimationTextView mAnimationTextView; 30 | 31 | public FlashItemClickListener(CaptureRequest.Builder mPreviewBuilder, CameraCaptureSession mCameraCaptureSession, Handler mHandler, PopupWindow mWindow, ImageView mBtnFlash, PreviewSessionCallback mPreviewSessionCallback, AnimationTextView mAnimationTextView) { 32 | this.mPreviewBuilder = mPreviewBuilder; 33 | this.mCameraCaptureSession = mCameraCaptureSession; 34 | this.mHandler = mHandler; 35 | this.mWindow = mWindow; 36 | this.mBtnFlash = mBtnFlash; 37 | this.mPreviewSessionCallback = mPreviewSessionCallback; 38 | this.mAnimationTextView = mAnimationTextView; 39 | } 40 | 41 | @Override 42 | public void onItemClick(AdapterView parent, View view, int position, long id) { 43 | mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); 44 | switch (position) { 45 | case 0: 46 | mBtnFlash.setImageResource(R.drawable.btn_flash_off); 47 | mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON); 48 | mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF); 49 | mAnimationTextView.start("OFF", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 50 | break; 51 | case 1: 52 | mBtnFlash.setImageResource(R.drawable.btn_flash_on); 53 | mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON); 54 | mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE); 55 | mAnimationTextView.start("SINGLE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 56 | break; 57 | case 2: 58 | mBtnFlash.setImageResource(R.drawable.btn_flash_all_on); 59 | mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON); 60 | mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); 61 | mAnimationTextView.start("TORCH", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 62 | break; 63 | case 3: 64 | mBtnFlash.setImageResource(R.drawable.btn_flash_auto); 65 | mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH); 66 | mAnimationTextView.start("AUTO_FLASH", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 67 | break; 68 | case 4: 69 | mBtnFlash.setImageResource(R.drawable.btn_flash_auto); 70 | mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS_FLASH); 71 | mAnimationTextView.start("ALWAYS_FLASH", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 72 | break; 73 | } 74 | updatePreview(); 75 | mWindow.dismiss(); 76 | } 77 | 78 | /** 79 | * 更新预览 80 | */ 81 | private void updatePreview() { 82 | try { 83 | mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler); 84 | } catch (CameraAccessException e) { 85 | e.printStackTrace(); 86 | } catch (Exception e) { 87 | e.printStackTrace(); 88 | Log.i("updatePreview", "ExceptionExceptionException"); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/callback/PreviewSessionCallback.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.callback; 2 | 3 | import android.hardware.camera2.CameraCaptureSession; 4 | import android.hardware.camera2.CameraMetadata; 5 | import android.hardware.camera2.CaptureRequest; 6 | import android.hardware.camera2.CaptureResult; 7 | import android.hardware.camera2.TotalCaptureResult; 8 | import android.os.Handler; 9 | import android.util.Log; 10 | import android.view.MotionEvent; 11 | import android.view.ViewGroup; 12 | import android.widget.RelativeLayout; 13 | 14 | import us.yydcdut.androidltest.view.AnimationImageView; 15 | import us.yydcdut.androidltest.view.MyTextureView; 16 | 17 | /** 18 | * Created by yuyidong on 14-12-19. 19 | */ 20 | public class PreviewSessionCallback extends CameraCaptureSession.CaptureCallback implements MyTextureView.FocusPositionTouchEvent { 21 | private int mAfState = CameraMetadata.CONTROL_AF_STATE_INACTIVE; 22 | private AnimationImageView mFocusImage; 23 | private Handler mMainHandler; 24 | private int mRawX; 25 | private int mRawY; 26 | private boolean mFlagShowFocusImage = false; 27 | 28 | public PreviewSessionCallback(AnimationImageView mFocusImage, Handler mMainHandler, MyTextureView mMyTextureView) { 29 | this.mFocusImage = mFocusImage; 30 | this.mMainHandler = mMainHandler; 31 | mMyTextureView.setmFocusPositionTouchEvent(this); 32 | } 33 | 34 | @Override 35 | public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, final TotalCaptureResult result) { 36 | super.onCaptureCompleted(session, request, result); 37 | Log.i("Thread", "onCaptureCompleted---->" + Thread.currentThread().getName()); 38 | Log.i("PreviewSessionCallback", "onCaptureCompleted"); 39 | Integer nowAfState = result.get(CaptureResult.CONTROL_AF_STATE); 40 | //获取失败 41 | if (nowAfState == null) { 42 | return; 43 | } 44 | //这次的值与之前的一样,忽略掉 45 | if (nowAfState.intValue() == mAfState) { 46 | return; 47 | } 48 | mAfState = nowAfState.intValue(); 49 | mMainHandler.post(new Runnable() { 50 | @Override 51 | public void run() { 52 | judgeFocus(); 53 | } 54 | }); 55 | } 56 | 57 | private void judgeFocus() { 58 | switch (mAfState) { 59 | case CameraMetadata.CONTROL_AF_STATE_ACTIVE_SCAN: 60 | case CameraMetadata.CONTROL_AF_STATE_PASSIVE_SCAN: 61 | focusFocusing(); 62 | break; 63 | case CameraMetadata.CONTROL_AF_STATE_FOCUSED_LOCKED: 64 | case CameraMetadata.CONTROL_AF_STATE_PASSIVE_FOCUSED: 65 | focusSucceed(); 66 | break; 67 | case CameraMetadata.CONTROL_AF_STATE_INACTIVE: 68 | focusInactive(); 69 | break; 70 | case CameraMetadata.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: 71 | case CameraMetadata.CONTROL_AF_STATE_PASSIVE_UNFOCUSED: 72 | focusFailed(); 73 | break; 74 | } 75 | } 76 | 77 | private void focusFocusing() { 78 | //得到宽高 79 | int width = mFocusImage.getWidth(); 80 | int height = mFocusImage.getHeight(); 81 | //居中 82 | ViewGroup.MarginLayoutParams margin = new ViewGroup.MarginLayoutParams(mFocusImage.getLayoutParams()); 83 | margin.setMargins(mRawX - width / 2, mRawY - height / 2, margin.rightMargin, margin.bottomMargin); 84 | RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(margin); 85 | mFocusImage.setLayoutParams(layoutParams); 86 | //显示 87 | if (mFlagShowFocusImage == false) { 88 | mFocusImage.startFocusing(); 89 | mFlagShowFocusImage = true; 90 | } 91 | } 92 | 93 | private void focusSucceed() { 94 | if (mFlagShowFocusImage == true) { 95 | mFocusImage.focusSuccess(); 96 | mFlagShowFocusImage = false; 97 | } 98 | } 99 | 100 | private void focusInactive() { 101 | mFocusImage.stopFocus(); 102 | mFlagShowFocusImage = false; 103 | } 104 | 105 | private void focusFailed() { 106 | if (mFlagShowFocusImage == true) { 107 | mFocusImage.focusFailed(); 108 | mFlagShowFocusImage = false; 109 | } 110 | } 111 | 112 | @Override 113 | public void getPosition(MotionEvent event) { 114 | mRawX = (int) event.getRawX(); 115 | mRawY = (int) event.getRawY(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /camera2/src/main/java/us/yydcdut/camera2/Progress.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.camera2; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.ImageFormat; 5 | import android.renderscript.Allocation; 6 | import android.renderscript.Element; 7 | import android.renderscript.RenderScript; 8 | import android.renderscript.Type; 9 | import android.util.Size; 10 | import android.view.Surface; 11 | 12 | 13 | /** 14 | * Created by yuyidong on 15-1-23. 15 | */ 16 | public class Progress implements Allocation.OnBufferAvailableListener { 17 | private Allocation mInputNormalAllocation; 18 | private Allocation mOutputAllocation; 19 | private Allocation mPrevAllocation; 20 | private Size mPreviewSize; 21 | private ScriptC_yuv2rgb mScriptC; 22 | 23 | 24 | private GetFrameBitmap mGetFrameBitmap = null; 25 | private GetFrameByteArray mGetFrameByteArray = null; 26 | 27 | public Progress(RenderScript rs, Size dimensions, GetFrameBitmap mGetFrameBitmap) { 28 | mPreviewSize = dimensions; 29 | this.mGetFrameBitmap = mGetFrameBitmap; 30 | 31 | createAllcation(rs, dimensions); 32 | 33 | mInputNormalAllocation.setOnBufferAvailableListener(this); 34 | 35 | mScriptC = new ScriptC_yuv2rgb(rs); 36 | mScriptC.set_gPrevFrame(mPrevAllocation); 37 | mScriptC.set_gCurrentFrame(mInputNormalAllocation); 38 | } 39 | 40 | public Progress(RenderScript rs, Size dimensions, GetFrameByteArray mGetFrameByteArray) { 41 | mPreviewSize = dimensions; 42 | this.mGetFrameByteArray = mGetFrameByteArray; 43 | 44 | createAllcation(rs, dimensions); 45 | 46 | mScriptC = new ScriptC_yuv2rgb(rs); 47 | mScriptC.set_gPrevFrame(mPrevAllocation); 48 | mScriptC.set_gCurrentFrame(mInputNormalAllocation); 49 | mInputNormalAllocation.setOnBufferAvailableListener(this); 50 | 51 | } 52 | 53 | public Progress(RenderScript rs, Size dimensions) { 54 | mPreviewSize = dimensions; 55 | 56 | createAllcation(rs, dimensions); 57 | 58 | mScriptC = new ScriptC_yuv2rgb(rs); 59 | mScriptC.set_gPrevFrame(mPrevAllocation); 60 | mScriptC.set_gCurrentFrame(mInputNormalAllocation); 61 | mInputNormalAllocation.setOnBufferAvailableListener(this); 62 | } 63 | 64 | private void createAllcation(RenderScript rs, Size dimensions) { 65 | Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs)); 66 | yuvTypeBuilder.setX(dimensions.getWidth()); 67 | yuvTypeBuilder.setY(dimensions.getHeight()); 68 | yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888); 69 | mInputNormalAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(), 70 | Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT); 71 | 72 | Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs)); 73 | rgbTypeBuilder.setX(dimensions.getWidth()); 74 | rgbTypeBuilder.setY(dimensions.getHeight()); 75 | mPrevAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), 76 | Allocation.USAGE_SCRIPT); 77 | mOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), 78 | Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT); 79 | 80 | } 81 | 82 | 83 | public Surface getInputNormalSurface() { 84 | return mInputNormalAllocation.getSurface(); 85 | } 86 | 87 | public void setOutputSurface(Surface output) { 88 | mOutputAllocation.setSurface(output); 89 | } 90 | 91 | @Override 92 | public void onBufferAvailable(Allocation a) { 93 | // Get to newest input 94 | mInputNormalAllocation.ioReceive(); 95 | 96 | // Run processing pass 97 | mScriptC.forEach_yuv2rgbFrames(mPrevAllocation, mOutputAllocation); 98 | mOutputAllocation.ioSend(); 99 | if (mGetFrameBitmap != null) { 100 | Bitmap bitmap = Bitmap.createBitmap(mPreviewSize.getWidth(), mPreviewSize.getHeight(), Bitmap.Config.ARGB_8888); 101 | mOutputAllocation.copyTo(bitmap); 102 | mGetFrameBitmap.getBitmap(bitmap); 103 | } else if (mGetFrameByteArray != null) { 104 | byte[] b = new byte[mPreviewSize.getWidth() * mPreviewSize.getHeight() * 2]; 105 | mOutputAllocation.copyTo(b); 106 | mGetFrameByteArray.getByteArray(b); 107 | } 108 | } 109 | 110 | public interface GetFrameBitmap { 111 | public void getBitmap(Bitmap bitmap); 112 | } 113 | 114 | public interface GetFrameByteArray { 115 | public void getByteArray(byte[] bytes); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/EffectItemClickListener.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.hardware.camera2.CameraAccessException; 4 | import android.hardware.camera2.CameraCaptureSession; 5 | import android.hardware.camera2.CameraMetadata; 6 | import android.hardware.camera2.CaptureRequest; 7 | import android.os.Handler; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.AdapterView; 11 | import android.widget.PopupWindow; 12 | 13 | import us.yydcdut.androidltest.callback.PreviewSessionCallback; 14 | import us.yydcdut.androidltest.ui.DisplayFragment; 15 | import us.yydcdut.androidltest.view.AnimationTextView; 16 | 17 | /** 18 | * Created by yuyidong on 14-12-18. 19 | */ 20 | public class EffectItemClickListener implements AdapterView.OnItemClickListener { 21 | private CaptureRequest.Builder mPreviewBuilder; 22 | private CameraCaptureSession mCameraCaptureSession; 23 | private Handler mHandler; 24 | private PopupWindow mWindow; 25 | private PreviewSessionCallback mPreviewSessionCallback; 26 | private AnimationTextView mAnimationTextView; 27 | 28 | public EffectItemClickListener(CaptureRequest.Builder mPreviewBuilder, CameraCaptureSession mCameraCaptureSession, Handler mHandler, PopupWindow mWindow, PreviewSessionCallback mPreviewSessionCallback, AnimationTextView mAnimationTextView) { 29 | this.mPreviewBuilder = mPreviewBuilder; 30 | this.mCameraCaptureSession = mCameraCaptureSession; 31 | this.mHandler = mHandler; 32 | this.mWindow = mWindow; 33 | this.mPreviewSessionCallback = mPreviewSessionCallback; 34 | this.mAnimationTextView = mAnimationTextView; 35 | } 36 | 37 | @Override 38 | public void onItemClick(AdapterView parent, View view, int position, long id) { 39 | mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); 40 | switch (position) { 41 | case 0: 42 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_AQUA); 43 | mAnimationTextView.start("AQUA", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 44 | break; 45 | case 1: 46 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_BLACKBOARD); 47 | mAnimationTextView.start("BLACKBOARD", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 48 | break; 49 | case 2: 50 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_MONO); 51 | mAnimationTextView.start("MONO", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 52 | break; 53 | case 3: 54 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_NEGATIVE); 55 | mAnimationTextView.start("NEGATIVE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 56 | break; 57 | case 4: 58 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_POSTERIZE); 59 | mAnimationTextView.start("POSTERIZE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 60 | break; 61 | case 5: 62 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_SEPIA); 63 | mAnimationTextView.start("SEPIA", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 64 | break; 65 | case 6: 66 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_SOLARIZE); 67 | mAnimationTextView.start("SOLARIZE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 68 | break; 69 | case 7: 70 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_WHITEBOARD); 71 | mAnimationTextView.start("WHITEBOARD", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 72 | break; 73 | case 8: 74 | mPreviewBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_OFF); 75 | mAnimationTextView.start("OFF", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 76 | break; 77 | } 78 | updatePreview(); 79 | mWindow.dismiss(); 80 | } 81 | 82 | /** 83 | * 更新预览 84 | */ 85 | private void updatePreview() { 86 | try { 87 | mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler); 88 | } catch (CameraAccessException e) { 89 | e.printStackTrace(); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | Log.i("updatePreview", "ExceptionExceptionException"); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/TextureViewTouchEvent.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.graphics.Rect; 4 | import android.hardware.camera2.CameraAccessException; 5 | import android.hardware.camera2.CameraCaptureSession; 6 | import android.hardware.camera2.CameraCharacteristics; 7 | import android.hardware.camera2.CameraMetadata; 8 | import android.hardware.camera2.CaptureRequest; 9 | import android.hardware.camera2.params.MeteringRectangle; 10 | import android.os.Handler; 11 | import android.util.Log; 12 | import android.util.Size; 13 | import android.view.MotionEvent; 14 | import android.view.TextureView; 15 | 16 | import us.yydcdut.androidltest.callback.PreviewSessionCallback; 17 | import us.yydcdut.androidltest.view.MyTextureView; 18 | 19 | /** 20 | * Created by yuyidong on 14-12-18. 21 | */ 22 | public class TextureViewTouchEvent implements MyTextureView.MyTextureViewTouchEvent { 23 | private CameraCharacteristics mCameraCharacteristics; 24 | private TextureView mTextureView; 25 | private CaptureRequest.Builder mPreviewBuilder; 26 | private CameraCaptureSession mCameraCaptureSession; 27 | private Handler mHandler; 28 | private PreviewSessionCallback mPreviewSessionCallback; 29 | 30 | public TextureViewTouchEvent(CameraCharacteristics mCameraCharacteristics, TextureView mTextureView, CaptureRequest.Builder mPreviewBuilder, CameraCaptureSession mCameraCaptureSession, Handler mHandler, PreviewSessionCallback mPreviewSessionCallback) { 31 | this.mCameraCharacteristics = mCameraCharacteristics; 32 | this.mTextureView = mTextureView; 33 | this.mPreviewBuilder = mPreviewBuilder; 34 | this.mCameraCaptureSession = mCameraCaptureSession; 35 | this.mHandler = mHandler; 36 | this.mPreviewSessionCallback = mPreviewSessionCallback; 37 | } 38 | 39 | @Override 40 | public boolean onAreaTouchEvent(MotionEvent event) { 41 | switch (event.getAction()) { 42 | case MotionEvent.ACTION_DOWN: 43 | Rect rect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); 44 | Log.i("onAreaTouchEvent", "SENSOR_INFO_ACTIVE_ARRAY_SIZE,,,,,,,,rect.left--->" + rect.left + ",,,rect.top--->" + rect.top + ",,,,rect.right--->" + rect.right + ",,,,rect.bottom---->" + rect.bottom); 45 | Size size = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE); 46 | Log.i("onAreaTouchEvent", "mCameraCharacteristics,,,,size.getWidth()--->" + size.getWidth() + ",,,size.getHeight()--->" + size.getHeight()); 47 | int areaSize = 200; 48 | int right = rect.right; 49 | int bottom = rect.bottom; 50 | int viewWidth = mTextureView.getWidth(); 51 | int viewHeight = mTextureView.getHeight(); 52 | int ll, rr; 53 | Rect newRect; 54 | int centerX = (int) event.getX(); 55 | int centerY = (int) event.getY(); 56 | ll = ((centerX * right) - areaSize) / viewWidth; 57 | rr = ((centerY * bottom) - areaSize) / viewHeight; 58 | int focusLeft = clamp(ll, 0, right); 59 | int focusBottom = clamp(rr, 0, bottom); 60 | Log.i("focus_position", "focusLeft--->" + focusLeft + ",,,focusTop--->" + focusBottom + ",,,focusRight--->" + (focusLeft + areaSize) + ",,,focusBottom--->" + (focusBottom + areaSize)); 61 | newRect = new Rect(focusLeft, focusBottom, focusLeft + areaSize, focusBottom + areaSize); 62 | MeteringRectangle meteringRectangle = new MeteringRectangle(newRect, 500); 63 | MeteringRectangle[] meteringRectangleArr = {meteringRectangle}; 64 | mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); 65 | mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, meteringRectangleArr); 66 | mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); 67 | updatePreview(); 68 | break; 69 | case MotionEvent.ACTION_UP: 70 | break; 71 | } 72 | return true; 73 | } 74 | 75 | /** 76 | * 触摸对焦的计算 77 | * 78 | * @param x 79 | * @param min 80 | * @param max 81 | * @return 82 | */ 83 | private int clamp(int x, int min, int max) { 84 | if (x < min) { 85 | return min; 86 | } else if (x > max) { 87 | return max; 88 | } else { 89 | return x; 90 | } 91 | } 92 | 93 | /** 94 | * 更新预览 95 | */ 96 | private void updatePreview() { 97 | try { 98 | mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler); 99 | } catch (CameraAccessException e) { 100 | e.printStackTrace(); 101 | } catch (Exception e) { 102 | e.printStackTrace(); 103 | Log.i("updatePreview", "ExceptionExceptionException"); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/ui/ShowPhotoFrag.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.ui; 2 | 3 | import android.app.Fragment; 4 | import android.graphics.Bitmap; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.support.v4.view.PagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | 14 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 15 | import com.nostra13.universalimageloader.core.ImageLoader; 16 | 17 | import java.io.File; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import us.yydcdut.androidltest.R; 22 | 23 | /** 24 | * Created by yuyidong on 14-12-22. 25 | */ 26 | public class ShowPhotoFrag extends Fragment { 27 | private List mList; 28 | private int mIndex; 29 | private DisplayImageOptions mOptions; 30 | 31 | public static ShowPhotoFrag newInstance() { 32 | ShowPhotoFrag showPhotoFrag = new ShowPhotoFrag(); 33 | return showPhotoFrag; 34 | } 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | mList = getPhotosPaths(); 40 | Bundle bundle = getArguments(); 41 | if (bundle != null) { 42 | mIndex = bundle.getInt("current"); 43 | } else { 44 | mIndex = 0; 45 | } 46 | initImageLoader(); 47 | } 48 | 49 | private void initImageLoader() { 50 | mOptions = new DisplayImageOptions.Builder() 51 | .showImageForEmptyUri(R.drawable.ic_launcher) 52 | .showImageOnFail(R.drawable.ic_launcher) 53 | .showStubImage(R.drawable.ic_launcher) 54 | .cacheInMemory(true) 55 | .bitmapConfig(Bitmap.Config.RGB_565) 56 | .build(); 57 | } 58 | 59 | private List getPhotosPaths() { 60 | List list = new ArrayList(); 61 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 62 | File[] files = dir.listFiles(); 63 | for (File file : files) { 64 | list.add("file:///" + Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/" + file.getName()); 65 | } 66 | return list; 67 | } 68 | 69 | @Override 70 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 71 | View v = inflater.inflate(R.layout.show_photo_frag, null); 72 | ViewPager viewPager = (ViewPager) v.findViewById(R.id.vp); 73 | viewPager.setPageTransformer(true, new MyPageTransformer()); 74 | viewPager.setAdapter(new MyPagerAdapter()); 75 | viewPager.setCurrentItem(mIndex); 76 | return v; 77 | } 78 | 79 | class MyPagerAdapter extends PagerAdapter { 80 | 81 | @Override 82 | public int getCount() { 83 | return mList.size(); 84 | } 85 | 86 | @Override 87 | public boolean isViewFromObject(View view, Object o) { 88 | return view == o; 89 | } 90 | 91 | @Override 92 | public Object instantiateItem(ViewGroup container, int position) { 93 | ImageView imageView = new ImageView(getActivity()); 94 | imageView.setMaxWidth(ViewGroup.LayoutParams.WRAP_CONTENT); 95 | imageView.setMaxHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 96 | ImageLoader.getInstance().displayImage(mList.get(position), imageView); 97 | ((ViewPager) container).addView(imageView); 98 | return imageView; 99 | } 100 | 101 | @Override 102 | public void destroyItem(ViewGroup container, int position, Object object) { 103 | container.removeView((View) object); 104 | } 105 | } 106 | 107 | class MyPageTransformer implements ViewPager.PageTransformer { 108 | private float MIN_SCALE = 0.85f; 109 | 110 | private float MIN_ALPHA = 0.5f; 111 | 112 | @Override 113 | public void transformPage(View view, float position) { 114 | int pageWidth = view.getWidth(); 115 | int pageHeight = view.getHeight(); 116 | 117 | if (position < -1) { 118 | view.setAlpha(0); 119 | } else if (position <= 1) { 120 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); 121 | float vertMargin = pageHeight * (1 - scaleFactor) / 2; 122 | float horzMargin = pageWidth * (1 - scaleFactor) / 2; 123 | if (position < 0) { 124 | view.setTranslationX(horzMargin - vertMargin / 2); 125 | } else { 126 | view.setTranslationX(-horzMargin + vertMargin / 2); 127 | } 128 | view.setScaleX(scaleFactor); 129 | view.setScaleY(scaleFactor); 130 | view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); 131 | } else { 132 | view.setAlpha(0); 133 | } 134 | } 135 | } 136 | 137 | 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/callback/DngSessionCallback.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.callback; 2 | 3 | import android.content.Context; 4 | import android.hardware.camera2.CameraAccessException; 5 | import android.hardware.camera2.CameraCaptureSession; 6 | import android.hardware.camera2.CameraCharacteristics; 7 | import android.hardware.camera2.CameraManager; 8 | import android.hardware.camera2.CameraMetadata; 9 | import android.hardware.camera2.CaptureRequest; 10 | import android.hardware.camera2.CaptureResult; 11 | import android.hardware.camera2.DngCreator; 12 | import android.hardware.camera2.TotalCaptureResult; 13 | import android.media.ImageReader; 14 | import android.media.MediaActionSound; 15 | import android.os.Environment; 16 | import android.os.Handler; 17 | import android.util.Log; 18 | 19 | import java.io.File; 20 | import java.io.FileOutputStream; 21 | import java.io.IOException; 22 | import java.util.Random; 23 | 24 | /** 25 | * Created by yuyidong on 14-12-17. 26 | */ 27 | @SuppressWarnings("ALL") 28 | public class DngSessionCallback extends CameraCaptureSession.CaptureCallback { 29 | 30 | private Context mContext; 31 | private ImageReader mImageReader; 32 | private Handler mHandler; 33 | private MediaActionSound mMediaActionSound; 34 | 35 | public DngSessionCallback(Context mContext, ImageReader mImageReader, Handler mHandler, MediaActionSound mMediaActionSound) { 36 | this.mContext = mContext; 37 | this.mImageReader = mImageReader; 38 | this.mHandler = mHandler; 39 | this.mMediaActionSound = mMediaActionSound; 40 | } 41 | 42 | @Override 43 | public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { 44 | super.onCaptureCompleted(session, request, result); 45 | Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); 46 | Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); 47 | if (afState == null || aeState == null) { 48 | return; 49 | } 50 | Log.i("DngSessionCallback", "要开始进入了,,afState.intValue()--->" + afState.intValue()); 51 | //聚焦完成才能拍照 52 | if (afState.intValue() == CameraMetadata.CONTROL_AF_STATE_FOCUSED_LOCKED || afState.intValue() == CameraMetadata.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) { 53 | Log.i("DngSessionCallback", "进去了一层,,aeState.intValue()--->" + aeState.intValue()); 54 | if (aeState.intValue() == CameraMetadata.CONTROL_AE_STATE_LOCKED || aeState == CameraMetadata.CONTROL_AE_STATE_CONVERGED || aeState == CameraMetadata.CONTROL_AE_STATE_PRECAPTURE || aeState == CameraMetadata.CONTROL_AE_STATE_FLASH_REQUIRED) { 55 | Log.i("DngSessionCallback", "进去了两层"); 56 | // mHandler.post(new DngRunnable(result)); 57 | new Thread(new DngRunnable(result)).start(); 58 | mHandler.post(new Runnable() { 59 | @Override 60 | public void run() { 61 | mMediaActionSound.play(MediaActionSound.SHUTTER_CLICK); 62 | } 63 | }); 64 | } 65 | } 66 | 67 | } 68 | 69 | class DngRunnable implements Runnable { 70 | private TotalCaptureResult mResult; 71 | 72 | DngRunnable(TotalCaptureResult mResult) { 73 | this.mResult = mResult; 74 | } 75 | 76 | @Override 77 | public void run() { 78 | DngCreator dngCreator = null; 79 | CameraManager manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE); 80 | try { 81 | //前置摄像头没有dng 82 | CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics("0"); 83 | dngCreator = new DngCreator(cameraCharacteristics, mResult); 84 | dngCreator.writeImage(new FileOutputStream(createFile()), mImageReader.acquireNextImage()); 85 | } catch (CameraAccessException e) { 86 | e.printStackTrace(); 87 | } catch (IOException e) { 88 | e.printStackTrace(); 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | Log.e("DngRunnable", "Exception eException eException e"); 92 | } finally { 93 | try { 94 | dngCreator.close(); 95 | } catch (Exception e) { 96 | Log.e("DngRunnable", "dngCreator.close();dngCreator.close();"); 97 | } 98 | } 99 | } 100 | 101 | private File createFile() { 102 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/"); 103 | if (!dir.exists()) { 104 | dir.mkdir(); 105 | } 106 | long time = System.currentTimeMillis(); 107 | int random = new Random().nextInt(1000); 108 | File dir1 = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/dng/"); 109 | if (!dir1.exists()) { 110 | dir1.mkdir(); 111 | } 112 | File meidaFile = new File(dir1, time + "_" + random + ".dng"); 113 | return meidaFile; 114 | } 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/view/AwbSeekBar.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.SeekBar; 6 | 7 | /** 8 | * Created by yuyidong on 14-12-15. 9 | */ 10 | public class AwbSeekBar extends SeekBar { 11 | 12 | private int mProgress; 13 | private AwbSeekBar mAwbSeekBar = this; 14 | private OnAwbSeekBarChangeListener mOnAwbSeekBarChangeListener; 15 | 16 | public AwbSeekBar(Context context) { 17 | super(context); 18 | init(); 19 | } 20 | 21 | public AwbSeekBar(Context context, AttributeSet attrs) { 22 | super(context, attrs); 23 | init(); 24 | } 25 | 26 | public AwbSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { 27 | super(context, attrs, defStyleAttr); 28 | init(); 29 | } 30 | 31 | public AwbSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 32 | super(context, attrs, defStyleAttr, defStyleRes); 33 | init(); 34 | } 35 | 36 | public void setmOnAwbSeekBarChangeListener(OnAwbSeekBarChangeListener mOnAwbSeekBarChangeListener) { 37 | this.mOnAwbSeekBarChangeListener = mOnAwbSeekBarChangeListener; 38 | } 39 | 40 | private void init() { 41 | this.setMax(70); 42 | this.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 43 | @Override 44 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 45 | mProgress = progress; 46 | if (mOnAwbSeekBarChangeListener != null) { 47 | if (0 <= mProgress && mProgress < 5) { 48 | mOnAwbSeekBarChangeListener.doInProgress1(); 49 | } else if (5 <= mProgress && mProgress < 15) { 50 | mOnAwbSeekBarChangeListener.doInProgress2(); 51 | } else if (15 <= mProgress && mProgress < 25) { 52 | mOnAwbSeekBarChangeListener.doInProgress3(); 53 | } else if (25 <= mProgress && mProgress < 35) { 54 | mOnAwbSeekBarChangeListener.doInProgress4(); 55 | } else if (35 <= mProgress && mProgress < 45) { 56 | mOnAwbSeekBarChangeListener.doInProgress5(); 57 | } else if (45 <= mProgress && mProgress < 55) { 58 | mOnAwbSeekBarChangeListener.doInProgress6(); 59 | } else if (55 <= mProgress && mProgress < 65) { 60 | mOnAwbSeekBarChangeListener.doInProgress7(); 61 | } else if (65 <= mProgress && mProgress < 70) { 62 | mOnAwbSeekBarChangeListener.doInProgress8(); 63 | } 64 | } 65 | } 66 | 67 | @Override 68 | public void onStartTrackingTouch(SeekBar seekBar) { 69 | mOnAwbSeekBarChangeListener.onStartTrackingTouch(seekBar); 70 | } 71 | 72 | @Override 73 | public void onStopTrackingTouch(SeekBar seekBar) { 74 | int num = 0; 75 | if (0 <= mProgress && mProgress < 5) { 76 | mAwbSeekBar.setProgress(0); 77 | num = 0; 78 | } else if (5 <= mProgress && mProgress < 15) { 79 | mAwbSeekBar.setProgress(10); 80 | num = 10; 81 | } else if (15 <= mProgress && mProgress < 25) { 82 | mAwbSeekBar.setProgress(20); 83 | num = 20; 84 | } else if (25 <= mProgress && mProgress < 35) { 85 | mAwbSeekBar.setProgress(30); 86 | num = 30; 87 | } else if (35 <= mProgress && mProgress < 45) { 88 | mAwbSeekBar.setProgress(40); 89 | num = 40; 90 | } else if (45 <= mProgress && mProgress < 55) { 91 | mAwbSeekBar.setProgress(50); 92 | num = 50; 93 | } else if (55 <= mProgress && mProgress < 65) { 94 | mAwbSeekBar.setProgress(60); 95 | num = 60; 96 | } else if (65 <= mProgress && mProgress < 70) { 97 | mAwbSeekBar.setProgress(70); 98 | num = 70; 99 | } 100 | if (mOnAwbSeekBarChangeListener != null) { 101 | mOnAwbSeekBarChangeListener.onStopTrackingTouch(num); 102 | } 103 | } 104 | }); 105 | } 106 | 107 | public interface OnAwbSeekBarChangeListener { 108 | public abstract void doInProgress1(); 109 | 110 | public abstract void doInProgress2(); 111 | 112 | public abstract void doInProgress3(); 113 | 114 | public abstract void doInProgress4(); 115 | 116 | public abstract void doInProgress5(); 117 | 118 | public abstract void doInProgress6(); 119 | 120 | public abstract void doInProgress7(); 121 | 122 | public abstract void doInProgress8(); 123 | 124 | public abstract void onStopTrackingTouch(int num); 125 | 126 | public abstract void onStartTrackingTouch(SeekBar seekBar); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/ui/AlbumFragment.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.ui; 2 | 3 | import android.app.Fragment; 4 | import android.graphics.Bitmap; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.AdapterView; 12 | import android.widget.BaseAdapter; 13 | import android.widget.GridView; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | 17 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 18 | import com.nostra13.universalimageloader.core.ImageLoader; 19 | 20 | import java.io.File; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import us.yydcdut.androidltest.R; 25 | 26 | /** 27 | * Created by yuyidong on 14-12-22. 28 | */ 29 | public class AlbumFragment extends Fragment implements View.OnClickListener { 30 | 31 | public static AlbumFragment newInstance() { 32 | AlbumFragment instance = new AlbumFragment(); 33 | return instance; 34 | } 35 | 36 | private List mList; 37 | private DisplayImageOptions mOptions; 38 | 39 | @Override 40 | public void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | mList = getPhotosPaths(); 43 | initImageLoader(); 44 | } 45 | 46 | @Override 47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 48 | View v = inflater.inflate(R.layout.album_frag, null); 49 | initUIAndListener(v); 50 | return v; 51 | } 52 | 53 | private void initUIAndListener(View v) { 54 | ImageView btnBack = (ImageView) v.findViewById(R.id.title_back_btn); 55 | btnBack.setOnClickListener(this); 56 | TextView txtTitle = (TextView) v.findViewById(R.id.title_text_title); 57 | txtTitle.setText("相册"); 58 | GridView gv = (GridView) v.findViewById(R.id.gv_album); 59 | gv.setAdapter(new MyGridViewAdapter()); 60 | gv.setOnItemClickListener(new MyGridViewItemClick()); 61 | } 62 | 63 | private void initImageLoader() { 64 | mOptions = new DisplayImageOptions.Builder() 65 | .showImageForEmptyUri(R.drawable.ic_launcher) 66 | .showStubImage(R.drawable.ic_launcher) 67 | .cacheInMemory(true) 68 | .bitmapConfig(Bitmap.Config.RGB_565) 69 | .build(); 70 | } 71 | 72 | private List getPhotosPaths() { 73 | List list = new ArrayList(); 74 | checkParentDir(); 75 | checkJpegDir(); 76 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 77 | File[] files = dir.listFiles(); 78 | for (File file : files) { 79 | list.add("file:///" + Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/" + file.getName()); 80 | } 81 | return list; 82 | } 83 | 84 | private void checkParentDir() { 85 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/"); 86 | if (!dir.exists()) { 87 | dir.mkdir(); 88 | } 89 | } 90 | 91 | private void checkJpegDir() { 92 | File dir = new File(Environment.getExternalStorageDirectory() + "/Android_L_Test/jpeg/"); 93 | if (!dir.exists()) { 94 | dir.mkdir(); 95 | } 96 | } 97 | 98 | @Override 99 | public void onClick(View v) { 100 | switch (v.getId()) { 101 | case R.id.title_back_btn: 102 | getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_main, DisplayFragment.newInstance()).commit(); 103 | break; 104 | } 105 | } 106 | 107 | 108 | class MyGridViewAdapter extends BaseAdapter { 109 | 110 | @Override 111 | public int getCount() { 112 | return mList.size(); 113 | } 114 | 115 | @Override 116 | public Object getItem(int position) { 117 | return mList.get(position); 118 | } 119 | 120 | @Override 121 | public long getItemId(int position) { 122 | return position; 123 | } 124 | 125 | @Override 126 | public View getView(int position, View convertView, ViewGroup parent) { 127 | Log.i("getView", "position--->" + position); 128 | ViewHolder vh; 129 | if (convertView == null) { 130 | vh = new ViewHolder(); 131 | convertView = getActivity().getLayoutInflater().inflate(R.layout.item_grid, null); 132 | vh.imageView = (ImageView) convertView.findViewById(R.id.item_gv); 133 | convertView.setTag(vh); 134 | } 135 | vh = (ViewHolder) convertView.getTag(); 136 | Log.i("path", "path--->" + mList.get(position)); 137 | ImageLoader.getInstance().displayImage(mList.get(position), vh.imageView, mOptions); 138 | return convertView; 139 | } 140 | } 141 | 142 | class ViewHolder { 143 | ImageView imageView; 144 | } 145 | 146 | class MyGridViewItemClick implements AdapterView.OnItemClickListener { 147 | 148 | @Override 149 | public void onItemClick(AdapterView parent, View view, int position, long id) { 150 | ShowPhotoFrag showPhotoFrag = ShowPhotoFrag.newInstance(); 151 | Bundle bundle = new Bundle(); 152 | bundle.putInt("current", position); 153 | showPhotoFrag.setArguments(bundle); 154 | getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_main, showPhotoFrag).addToBackStack(null).commit(); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/AwbSeekBarChangeListener.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.content.Context; 4 | import android.hardware.camera2.CameraAccessException; 5 | import android.hardware.camera2.CameraCaptureSession; 6 | import android.hardware.camera2.CameraMetadata; 7 | import android.hardware.camera2.CaptureRequest; 8 | import android.os.Handler; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.view.animation.Animation; 12 | import android.view.animation.AnimationUtils; 13 | import android.widget.SeekBar; 14 | import android.widget.TextView; 15 | 16 | import us.yydcdut.androidltest.R; 17 | import us.yydcdut.androidltest.callback.PreviewSessionCallback; 18 | import us.yydcdut.androidltest.view.AwbSeekBar; 19 | 20 | /** 21 | * Created by yuyidong on 14-12-18. 22 | */ 23 | public class AwbSeekBarChangeListener implements AwbSeekBar.OnAwbSeekBarChangeListener { 24 | private TextView mTextView; 25 | private CaptureRequest.Builder mPreviewBuilder; 26 | private CameraCaptureSession mCameraCaptureSession; 27 | private Handler mHandler; 28 | private PreviewSessionCallback mPreviewSessionCallback; 29 | 30 | private Animation mAlphaInAnimation; 31 | private Animation mAlphaOutAnimation; 32 | 33 | public AwbSeekBarChangeListener(Context mContext, TextView mTextView, CaptureRequest.Builder mPreviewBuilder, CameraCaptureSession mCameraCaptureSession, Handler mHandler, PreviewSessionCallback mPreviewSessionCallback) { 34 | this.mTextView = mTextView; 35 | this.mPreviewBuilder = mPreviewBuilder; 36 | this.mCameraCaptureSession = mCameraCaptureSession; 37 | this.mHandler = mHandler; 38 | this.mPreviewSessionCallback = mPreviewSessionCallback; 39 | mAlphaInAnimation = AnimationUtils.loadAnimation(mContext, R.anim.alpha_in); 40 | mAlphaOutAnimation = AnimationUtils.loadAnimation(mContext, R.anim.alpha_out); 41 | } 42 | 43 | @Override 44 | public void doInProgress1() { 45 | mTextView.setText("自动"); 46 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO); 47 | updatePreview(); 48 | } 49 | 50 | @Override 51 | public void doInProgress2() { 52 | mTextView.setText("多云"); 53 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_CLOUDY_DAYLIGHT); 54 | updatePreview(); 55 | } 56 | 57 | @Override 58 | public void doInProgress3() { 59 | mTextView.setText("白天"); 60 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT); 61 | updatePreview(); 62 | } 63 | 64 | @Override 65 | public void doInProgress4() { 66 | mTextView.setText("日光灯"); 67 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT); 68 | updatePreview(); 69 | } 70 | 71 | @Override 72 | public void doInProgress5() { 73 | mTextView.setText("白炽灯"); 74 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_INCANDESCENT); 75 | updatePreview(); 76 | } 77 | 78 | @Override 79 | public void doInProgress6() { 80 | mTextView.setText("阴影"); 81 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_SHADE); 82 | updatePreview(); 83 | } 84 | 85 | @Override 86 | public void doInProgress7() { 87 | mTextView.setText("黄昏"); 88 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT); 89 | updatePreview(); 90 | } 91 | 92 | @Override 93 | public void doInProgress8() { 94 | mTextView.setText("暖光"); 95 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT); 96 | updatePreview(); 97 | } 98 | 99 | @Override 100 | public void onStopTrackingTouch(int num) { 101 | switch (num) { 102 | case 0: 103 | mTextView.setText("自动"); 104 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO); 105 | break; 106 | case 10: 107 | mTextView.setText("多云"); 108 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_CLOUDY_DAYLIGHT); 109 | break; 110 | case 20: 111 | mTextView.setText("白天"); 112 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT); 113 | break; 114 | case 30: 115 | mTextView.setText("日光灯"); 116 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT); 117 | break; 118 | case 40: 119 | mTextView.setText("白炽灯"); 120 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_INCANDESCENT); 121 | break; 122 | case 50: 123 | mTextView.setText("阴影"); 124 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_SHADE); 125 | break; 126 | case 60: 127 | mTextView.setText("黄昏"); 128 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT); 129 | break; 130 | case 70: 131 | mTextView.setText("暖光"); 132 | mPreviewBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT); 133 | break; 134 | } 135 | updatePreview(); 136 | mTextView.startAnimation(mAlphaOutAnimation); 137 | mTextView.setVisibility(View.INVISIBLE); 138 | } 139 | 140 | @Override 141 | public void onStartTrackingTouch(SeekBar seekBar) { 142 | mTextView.setVisibility(View.VISIBLE); 143 | mTextView.startAnimation(mAlphaInAnimation); 144 | } 145 | 146 | /** 147 | * 更新预览 148 | */ 149 | private void updatePreview() { 150 | try { 151 | mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler); 152 | } catch (CameraAccessException e) { 153 | e.printStackTrace(); 154 | } catch (Exception e) { 155 | e.printStackTrace(); 156 | Log.i("updatePreview", "ExceptionExceptionException"); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 171 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/ui/SettingFragment.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.ui; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Fragment; 5 | import android.content.Context; 6 | import android.content.DialogInterface; 7 | import android.content.SharedPreferences; 8 | import android.os.Bundle; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | import us.yydcdut.androidltest.PreferenceHelper; 19 | import us.yydcdut.androidltest.R; 20 | import us.yydcdut.androidltest.view.SettingItem; 21 | 22 | /** 23 | * Created by yuyidong on 14-12-5. 24 | */ 25 | public class SettingFragment extends Fragment implements View.OnClickListener { 26 | /** 27 | * 配置文件 28 | */ 29 | private String mCurrentCameraName; 30 | /** 31 | * 该cameraid所有的配置的文件 32 | */ 33 | private String mCameraName; 34 | /** 35 | * current的SharedPerference 36 | */ 37 | private SharedPreferences mSp; 38 | private SharedPreferences.Editor mEditor; 39 | 40 | public static SettingFragment newInstance() { 41 | SettingFragment instance = new SettingFragment(); 42 | 43 | return instance; 44 | } 45 | 46 | @Override 47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 48 | //传递进来用的哪个cameraid 49 | Bundle bundle = getArguments(); 50 | String name = null; 51 | if (bundle != null) { 52 | name = bundle.getString("camera"); 53 | } else { 54 | name = "camera0"; 55 | } 56 | mCurrentCameraName = "current" + name; 57 | mCameraName = name; 58 | mSp = getActivity().getSharedPreferences(mCurrentCameraName, Context.MODE_PRIVATE); 59 | mEditor = mSp.edit(); 60 | 61 | View v = inflater.inflate(R.layout.setting_frag, null); 62 | ImageView btnBack = (ImageView) v.findViewById(R.id.title_back_btn); 63 | btnBack.setOnClickListener(this); 64 | TextView txtTitle = (TextView) v.findViewById(R.id.title_text_title); 65 | txtTitle.setText(returnCameraName(name) + " 设置"); 66 | SettingItem itemFormat = (SettingItem) v.findViewById(R.id.setting_item_format); 67 | SettingItem itemSize = (SettingItem) v.findViewById(R.id.setting_item_size); 68 | itemFormat.getTitle().setText("图片格式"); 69 | itemFormat.setOnClickListener(this); 70 | itemSize.getTitle().setText("图片大小"); 71 | itemSize.setOnClickListener(this); 72 | return v; 73 | } 74 | 75 | private String returnCameraName(String camera) { 76 | if (camera.equals("camera0")) { 77 | return "后置摄像头"; 78 | } else if (camera.equals("camera1")) { 79 | return "后置摄像头"; 80 | } else { 81 | return "摄像头"; 82 | } 83 | } 84 | 85 | @Override 86 | public void onClick(View view) { 87 | switch (view.getId()) { 88 | case R.id.setting_item_format: 89 | formatDialog(); 90 | break; 91 | case R.id.title_back_btn: 92 | getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_main, DisplayFragment.newInstance()).commit(); 93 | break; 94 | case R.id.setting_item_size: 95 | sizeDialog(); 96 | break; 97 | } 98 | } 99 | 100 | private void formatDialog() { 101 | //格式的中文名字 102 | String[] formatsName = PreferenceHelper.getFormatsName(getActivity(), mCameraName); 103 | //格式的序号 104 | int[] formatsNumber = PreferenceHelper.getFormatsNumber(getActivity(), mCameraName); 105 | //<数组序号,名字> 106 | final Map map1 = new HashMap(); 107 | //<序号,数组序号> 108 | Map map3 = new HashMap(); 109 | for (int i = 0; i < formatsName.length; i++) { 110 | map1.put(i, formatsNumber[i]); 111 | map3.put(formatsNumber[i], i); 112 | } 113 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 114 | builder.setTitle("选择图片格式"); 115 | //选择的格式的编号 116 | int which = mSp.getInt("format", 0); 117 | //选择的格式再对应数组中的位置 118 | builder.setSingleChoiceItems(formatsName, map3.get(which), new DialogInterface.OnClickListener() { 119 | 120 | @Override 121 | public void onClick(DialogInterface dialogInterface, int i) { 122 | //通过数组号找序号 123 | // Log.i("formatDialog", "format--->" + map1.get(i)); 124 | mEditor.putInt("format", map1.get(i)); 125 | mEditor.commit(); 126 | dialogInterface.dismiss(); 127 | } 128 | }); 129 | builder.create().show(); 130 | } 131 | 132 | private void sizeDialog() { 133 | //获取当前format的所有size 134 | String[] formatSize = PreferenceHelper.getFormatSize(getActivity(), mCameraName); 135 | //获取当前的format的设置的size的数组序号 136 | final int which = mSp.getInt("format", 0); 137 | //当前大小 138 | String size = mSp.getInt("format_" + which + "_pictureSize_width", 0) + "*" + mSp.getInt("format_" + which + "_pictureSize_height", 0); 139 | //Log.i("sizeDialog", "size-->" + size); 140 | //<名字, 数组序号> 141 | Map map1 = new HashMap(); 142 | //<数组序号, 名字> 143 | final Map map3 = new HashMap(); 144 | for (int i = 0; i < formatSize.length; i++) { 145 | map1.put(formatSize[i], i); 146 | map3.put(i, formatSize[i]); 147 | } 148 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 149 | builder.setTitle("选择图片大小"); 150 | //map1.get(size),该大小再数组中的位置 151 | builder.setSingleChoiceItems(formatSize, map1.get(size), new DialogInterface.OnClickListener() { 152 | 153 | @Override 154 | public void onClick(DialogInterface dialogInterface, int i) { 155 | // Log.i("sizeDialog", "formatSize-->" + map3.get(i)); 156 | String size = map3.get(i); 157 | String[] arr = size.split("\\*"); 158 | String width = arr[0]; 159 | String height = arr[1]; 160 | mEditor.putInt("format_" + which + "_pictureSize_width", Integer.parseInt(width)); 161 | mEditor.putInt("format_" + which + "_pictureSize_height", Integer.parseInt(height)); 162 | mEditor.commit(); 163 | dialogInterface.dismiss(); 164 | } 165 | }); 166 | builder.create().show(); 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /camera2/camera2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/listener/SenseItemClickListener.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.listener; 2 | 3 | import android.hardware.camera2.CameraAccessException; 4 | import android.hardware.camera2.CameraCaptureSession; 5 | import android.hardware.camera2.CameraMetadata; 6 | import android.hardware.camera2.CaptureRequest; 7 | import android.os.Handler; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.AdapterView; 11 | import android.widget.PopupWindow; 12 | 13 | import us.yydcdut.androidltest.callback.PreviewSessionCallback; 14 | import us.yydcdut.androidltest.ui.DisplayFragment; 15 | import us.yydcdut.androidltest.view.AnimationTextView; 16 | 17 | /** 18 | * Created by yuyidong on 14-12-23. 19 | */ 20 | public class SenseItemClickListener implements AdapterView.OnItemClickListener { 21 | private CaptureRequest.Builder mPreviewBuilder; 22 | private CameraCaptureSession mCameraCaptureSession; 23 | private Handler mHandler; 24 | private PopupWindow mWindow; 25 | private PreviewSessionCallback mPreviewSessionCallback; 26 | private AnimationTextView mAnimationTextView; 27 | 28 | 29 | public SenseItemClickListener(CaptureRequest.Builder mPreviewBuilder, CameraCaptureSession mCameraCaptureSession, Handler mHandler, PopupWindow mWindow, PreviewSessionCallback mPreviewSessionCallback, AnimationTextView mAnimationTextView) { 30 | this.mPreviewBuilder = mPreviewBuilder; 31 | this.mCameraCaptureSession = mCameraCaptureSession; 32 | this.mHandler = mHandler; 33 | this.mWindow = mWindow; 34 | this.mPreviewSessionCallback = mPreviewSessionCallback; 35 | this.mAnimationTextView = mAnimationTextView; 36 | 37 | } 38 | 39 | @Override 40 | public void onItemClick(AdapterView parent, View view, int position, long id) { 41 | mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_USE_SCENE_MODE); 42 | switch (position) { 43 | case 0: 44 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_DISABLED); 45 | mAnimationTextView.start("DISABLED", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 46 | break; 47 | case 1: 48 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_FACE_PRIORITY); 49 | mAnimationTextView.start("FACE_PRIORITY", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 50 | break; 51 | case 2: 52 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_ACTION); 53 | mAnimationTextView.start("ACTION", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 54 | break; 55 | case 3: 56 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_PORTRAIT); 57 | mAnimationTextView.start("PORTRAIT", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 58 | break; 59 | case 4: 60 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_LANDSCAPE); 61 | mAnimationTextView.start("LANDSCAPE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 62 | break; 63 | case 5: 64 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_NIGHT); 65 | mAnimationTextView.start("NIGHT", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 66 | break; 67 | case 6: 68 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_NIGHT_PORTRAIT); 69 | mAnimationTextView.start("PORTRAIT", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 70 | break; 71 | case 7: 72 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_THEATRE); 73 | mAnimationTextView.start("THEATRE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 74 | break; 75 | case 8: 76 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_BEACH); 77 | mAnimationTextView.start("BEACH", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 78 | break; 79 | case 9: 80 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_SNOW); 81 | mAnimationTextView.start("SNOW", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 82 | break; 83 | case 10: 84 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_SUNSET); 85 | mAnimationTextView.start("SUNSET", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 86 | break; 87 | case 11: 88 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_STEADYPHOTO); 89 | mAnimationTextView.start("STEADYPHOTO", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 90 | break; 91 | case 12: 92 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_FIREWORKS); 93 | mAnimationTextView.start("FIREWORKS", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 94 | break; 95 | case 13: 96 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_SPORTS); 97 | mAnimationTextView.start("SPORTS", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 98 | break; 99 | case 14: 100 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_PARTY); 101 | mAnimationTextView.start("PARTY", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 102 | break; 103 | case 15: 104 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_CANDLELIGHT); 105 | mAnimationTextView.start("CANDLELIGHT", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 106 | break; 107 | case 16: 108 | mPreviewBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_BARCODE); 109 | mAnimationTextView.start("BARCODE", DisplayFragment.WINDOW_TEXT_DISAPPEAR); 110 | break; 111 | } 112 | updatePreview(); 113 | mWindow.dismiss(); 114 | } 115 | 116 | /** 117 | * 更新预览 118 | */ 119 | private void updatePreview() { 120 | try { 121 | mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler); 122 | } catch (CameraAccessException e) { 123 | e.printStackTrace(); 124 | } catch (Exception e) { 125 | e.printStackTrace(); 126 | Log.i("updatePreview", "ExceptionExceptionException"); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/otheractivity/FlashActivity.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest.otheractivity; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.SurfaceTexture; 6 | import android.hardware.camera2.CameraAccessException; 7 | import android.hardware.camera2.CameraCaptureSession; 8 | import android.hardware.camera2.CameraCharacteristics; 9 | import android.hardware.camera2.CameraDevice; 10 | import android.hardware.camera2.CameraManager; 11 | import android.hardware.camera2.CameraMetadata; 12 | import android.hardware.camera2.CaptureRequest; 13 | import android.os.Bundle; 14 | import android.util.Size; 15 | import android.view.Surface; 16 | import android.widget.CompoundButton; 17 | import android.widget.Switch; 18 | import android.widget.Toast; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import us.yydcdut.androidltest.R; 24 | 25 | /** 26 | * Created by yuyidong on 14-12-18. 27 | */ 28 | public class FlashActivity extends Activity { 29 | private CameraCaptureSession mSession; 30 | private CaptureRequest.Builder mBuilder; 31 | private CameraDevice mCameraDevice; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.flash_activity); 37 | try { 38 | init(); 39 | } catch (CameraAccessException e) { 40 | e.printStackTrace(); 41 | } 42 | Switch flashSwitch = (Switch) findViewById(R.id.switch_flash); 43 | //default of flash mode is on 44 | flashSwitch.setChecked(true); 45 | flashSwitch.setOnCheckedChangeListener(new MyCheckedChangeListener()); 46 | } 47 | 48 | private CameraManager mCameraManager; 49 | 50 | @SuppressWarnings("ResourceType") 51 | private void init() throws CameraAccessException { 52 | mCameraManager = (CameraManager) FlashActivity.this.getSystemService(Context.CAMERA_SERVICE); 53 | //here to judge if flash is available 54 | CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics("0"); 55 | boolean flashAvailable = cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); 56 | if (flashAvailable) { 57 | mCameraManager.openCamera("0", new MyCameraDeviceStateCallback(), null); 58 | } else { 59 | Toast.makeText(FlashActivity.this, "Flash not available", Toast.LENGTH_SHORT).show(); 60 | //todo: throw Exception 61 | } 62 | mCameraManager.openCamera("0", new MyCameraDeviceStateCallback(), null); 63 | } 64 | 65 | private SurfaceTexture mSurfaceTexture; 66 | private Surface mSurface; 67 | 68 | /** 69 | * camera device callback 70 | */ 71 | class MyCameraDeviceStateCallback extends CameraDevice.StateCallback { 72 | 73 | @Override 74 | public void onOpened(CameraDevice camera) { 75 | mCameraDevice = camera; 76 | //get builder 77 | try { 78 | mBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL); 79 | //flash on, default is on 80 | mBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO); 81 | mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); 82 | List list = new ArrayList(); 83 | mSurfaceTexture = new SurfaceTexture(1); 84 | Size size = getSmallestSize(mCameraDevice.getId()); 85 | mSurfaceTexture.setDefaultBufferSize(size.getWidth(), size.getHeight()); 86 | mSurface = new Surface(mSurfaceTexture); 87 | list.add(mSurface); 88 | mBuilder.addTarget(mSurface); 89 | camera.createCaptureSession(list, new MyCameraCaptureSessionStateCallback(), null); 90 | } catch (CameraAccessException e) { 91 | e.printStackTrace(); 92 | } 93 | } 94 | 95 | @Override 96 | public void onDisconnected(CameraDevice camera) { 97 | 98 | } 99 | 100 | @Override 101 | public void onError(CameraDevice camera, int error) { 102 | 103 | } 104 | } 105 | 106 | private Size getSmallestSize(String cameraId) throws CameraAccessException { 107 | Size[] outputSizes = mCameraManager.getCameraCharacteristics(cameraId) 108 | .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) 109 | .getOutputSizes(SurfaceTexture.class); 110 | if (outputSizes == null || outputSizes.length == 0) { 111 | throw new IllegalStateException( 112 | "Camera " + cameraId + "doesn't support any outputSize."); 113 | } 114 | Size chosen = outputSizes[0]; 115 | for (Size s : outputSizes) { 116 | if (chosen.getWidth() >= s.getWidth() && chosen.getHeight() >= s.getHeight()) { 117 | chosen = s; 118 | } 119 | } 120 | return chosen; 121 | } 122 | 123 | /** 124 | * session callback 125 | */ 126 | class MyCameraCaptureSessionStateCallback extends CameraCaptureSession.StateCallback { 127 | 128 | @Override 129 | public void onConfigured(CameraCaptureSession session) { 130 | mSession = session; 131 | try { 132 | mSession.setRepeatingRequest(mBuilder.build(), null, null); 133 | } catch (CameraAccessException e) { 134 | e.printStackTrace(); 135 | } 136 | } 137 | 138 | @Override 139 | public void onConfigureFailed(CameraCaptureSession session) { 140 | 141 | } 142 | } 143 | 144 | /** 145 | * switch listener 146 | */ 147 | class MyCheckedChangeListener implements CompoundButton.OnCheckedChangeListener { 148 | 149 | @Override 150 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 151 | try { 152 | if (isChecked) { 153 | mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); 154 | mSession.setRepeatingRequest(mBuilder.build(), null, null); 155 | } else { 156 | mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF); 157 | mSession.setRepeatingRequest(mBuilder.build(), null, null); 158 | } 159 | } catch (CameraAccessException e) { 160 | e.printStackTrace(); 161 | } 162 | } 163 | } 164 | 165 | private void close() { 166 | if (mCameraDevice == null || mSession == null) { 167 | return; 168 | } 169 | mSession.close(); 170 | mCameraDevice.close(); 171 | mCameraDevice = null; 172 | mSession = null; 173 | } 174 | 175 | @Override 176 | protected void onDestroy() { 177 | super.onDestroy(); 178 | close(); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /app/src/main/java/us/yydcdut/androidltest/MyActivity.java: -------------------------------------------------------------------------------- 1 | package us.yydcdut.androidltest; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.content.Context; 6 | import android.graphics.ImageFormat; 7 | import android.graphics.SurfaceTexture; 8 | import android.hardware.camera2.CameraAccessException; 9 | import android.hardware.camera2.CameraCharacteristics; 10 | import android.hardware.camera2.CameraManager; 11 | import android.hardware.camera2.params.StreamConfigurationMap; 12 | import android.os.Bundle; 13 | import android.os.Handler; 14 | import android.os.Message; 15 | import android.util.Log; 16 | import android.util.Size; 17 | import android.view.View; 18 | import android.view.animation.Animation; 19 | import android.view.animation.AnimationUtils; 20 | import android.widget.ImageView; 21 | import android.widget.LinearLayout; 22 | import android.widget.Toast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import us.yydcdut.androidltest.ui.DisplayFragment; 28 | 29 | 30 | public class MyActivity extends Activity { 31 | private static final int INIT_OK = 1; 32 | private static final int INIT_BAD = 2; 33 | private Dialog mDialog; 34 | private Handler mHandler = new Handler() { 35 | @Override 36 | public void handleMessage(Message msg) { 37 | switch (msg.what) { 38 | case INIT_OK: 39 | closeDialogLoading(); 40 | DisplayFragment displayFragment = DisplayFragment.newInstance(); 41 | Bundle bundle = new Bundle(); 42 | bundle.putString("cameraid", PreferenceHelper.getCurrentCameraid(MyActivity.this)); 43 | displayFragment.setArguments(bundle); 44 | getFragmentManager().beginTransaction().replace(R.id.frame_main, displayFragment).commit(); 45 | break; 46 | case INIT_BAD: 47 | closeDialogLoading(); 48 | Toast.makeText(MyActivity.this, "初始化失败!!!", Toast.LENGTH_SHORT).show(); 49 | finish(); 50 | break; 51 | } 52 | super.handleMessage(msg); 53 | } 54 | }; 55 | 56 | @Override 57 | protected void onCreate(Bundle savedInstanceState) { 58 | super.onCreate(savedInstanceState); 59 | setContentView(R.layout.activity_my); 60 | //第一次初始化 61 | if (!PreferenceHelper.checkFirstInit(MyActivity.this)) { 62 | initDialogLoading(); 63 | new Thread(new MyRunnable()).start(); 64 | } else { 65 | DisplayFragment displayFragment = DisplayFragment.newInstance(); 66 | Bundle bundle = new Bundle(); 67 | bundle.putString("cameraid", PreferenceHelper.getCurrentCameraid(MyActivity.this)); 68 | displayFragment.setArguments(bundle); 69 | getFragmentManager().beginTransaction().replace(R.id.frame_main, displayFragment).commit(); 70 | } 71 | } 72 | 73 | /** 74 | * 再子线程中初始化相机参数 75 | */ 76 | class MyRunnable implements Runnable { 77 | 78 | @SuppressWarnings("ResourceType") 79 | @Override 80 | public void run() { 81 | try { 82 | //初始化参数到sharedPreference 83 | CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); 84 | String[] cameraIds = manager.getCameraIdList(); 85 | if (cameraIds != null && cameraIds.length > 0) { 86 | //后置摄像头存在 87 | if (cameraIds[0] != null) { 88 | CameraCharacteristics character = manager.getCameraCharacteristics(cameraIds[0]); 89 | //流配置 90 | StreamConfigurationMap map = character.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); 91 | //适合SurfaceTexture的显示的size 92 | Size[] previewSizes = map.getOutputSizes(SurfaceTexture.class); 93 | //图片格式 94 | int[] formatsAll = map.getOutputFormats(); 95 | //这里只要jpeg和dng 96 | List formatList = new ArrayList(); 97 | for (int format : formatsAll) { 98 | if (format == ImageFormat.JPEG || format == ImageFormat.RAW_SENSOR) { 99 | formatList.add(format); 100 | } 101 | } 102 | Integer[] formats = formatList.toArray(new Integer[formatList.size()]); 103 | //不同的format对应不同的照片size 104 | Size[][] pictureSizes = new Size[formats.length][]; 105 | for (int i = 0; i < formats.length; i++) { 106 | //这里会出现有的格式但是没有保存图片的size 107 | if (null != map.getOutputSizes(formats[i])) { 108 | pictureSizes[i] = map.getOutputSizes(formats[i]); 109 | } else { 110 | Log.i("Runnable", "camera0--->map.getOutputSizes为空"); 111 | } 112 | } 113 | PreferenceHelper.writePreferenceForCameraId(MyActivity.this, "camera0", previewSizes, formats, pictureSizes); 114 | 115 | } 116 | if (cameraIds[1] != null) {//前置摄像头存在 117 | CameraCharacteristics character = manager.getCameraCharacteristics(cameraIds[1]); 118 | //流配置 119 | StreamConfigurationMap map = character.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); 120 | //适合SurfaceTexture的显示的size 121 | Size[] previewSizes = map.getOutputSizes(SurfaceTexture.class); 122 | //图片格式 123 | int[] formatsAll = map.getOutputFormats(); 124 | //这里只要jpeg和dng 125 | List formatList = new ArrayList(); 126 | for (int format : formatsAll) { 127 | if (format == ImageFormat.JPEG || format == ImageFormat.RAW_SENSOR) { 128 | formatList.add(format); 129 | } 130 | } 131 | Integer[] formats = formatList.toArray(new Integer[formatList.size()]); 132 | //不同的format对应不同的照片size 133 | Size[][] pictureSizes = new Size[formats.length][]; 134 | for (int i = 0; i < formats.length; i++) { 135 | //这里会出现有的格式但是没有保存图片的size 136 | if (null != map.getOutputSizes(formats[i])) { 137 | pictureSizes[i] = map.getOutputSizes(formats[i]); 138 | } else { 139 | Log.i("Runnable", "camera1--->map.getOutputSizes为空"); 140 | } 141 | } 142 | PreferenceHelper.writePreferenceForCameraId(MyActivity.this, "camera1", previewSizes, formats, pictureSizes); 143 | } 144 | } 145 | } catch (CameraAccessException e) { 146 | e.printStackTrace(); 147 | mHandler.sendEmptyMessage(INIT_BAD); 148 | return; 149 | } 150 | //初始化一开始打开cameraia为1的摄像头 151 | PreferenceHelper.writeCurrentCameraid(MyActivity.this, "0"); 152 | mHandler.sendEmptyMessage(INIT_OK); 153 | } 154 | } 155 | 156 | /** 157 | * 初始化&&显示dialog 158 | */ 159 | private void initDialogLoading() { 160 | View v = getLayoutInflater().inflate(R.layout.loading_dialog, null); 161 | ImageView imageView = (ImageView) v.findViewById(R.id.img_loading); 162 | LinearLayout linearLayout = (LinearLayout) v.findViewById(R.id.liner_dialog); 163 | Animation animation = AnimationUtils.loadAnimation(MyActivity.this, R.anim.dialog_loading); 164 | imageView.setAnimation(animation); 165 | mDialog = new Dialog(MyActivity.this, R.style.loading_dialog); 166 | mDialog.setCancelable(false); 167 | mDialog.setContentView(linearLayout, new LinearLayout.LayoutParams( 168 | LinearLayout.LayoutParams.FILL_PARENT, 169 | LinearLayout.LayoutParams.FILL_PARENT)); 170 | if (mDialog != null && !mDialog.isShowing()) { 171 | mDialog.show(); 172 | } 173 | } 174 | 175 | /** 176 | * 关闭dialog 177 | */ 178 | private void closeDialogLoading() { 179 | if (mDialog != null && mDialog.isShowing()) { 180 | mDialog.dismiss(); 181 | } 182 | } 183 | 184 | } 185 | --------------------------------------------------------------------------------