diff options
45 files changed, 1178 insertions, 114 deletions
diff --git a/res/drawable-hdpi/bar_beautify_rectangle_blue.png b/res/drawable-hdpi/bar_beautify_rectangle_blue.png Binary files differnew file mode 100755 index 000000000..37b6cdafb --- /dev/null +++ b/res/drawable-hdpi/bar_beautify_rectangle_blue.png diff --git a/res/drawable-hdpi/bar_beautify_rectangle_white.png b/res/drawable-hdpi/bar_beautify_rectangle_white.png Binary files differnew file mode 100755 index 000000000..06bc65042 --- /dev/null +++ b/res/drawable-hdpi/bar_beautify_rectangle_white.png diff --git a/res/drawable-hdpi/ic_beautify_oval.png b/res/drawable-hdpi/ic_beautify_oval.png Binary files differnew file mode 100755 index 000000000..be86fdc03 --- /dev/null +++ b/res/drawable-hdpi/ic_beautify_oval.png diff --git a/res/drawable-mdpi/bar_beautify_rectangle_blue.png b/res/drawable-mdpi/bar_beautify_rectangle_blue.png Binary files differnew file mode 100755 index 000000000..454787c9c --- /dev/null +++ b/res/drawable-mdpi/bar_beautify_rectangle_blue.png diff --git a/res/drawable-mdpi/bar_beautify_rectangle_white.png b/res/drawable-mdpi/bar_beautify_rectangle_white.png Binary files differnew file mode 100755 index 000000000..70b4c951f --- /dev/null +++ b/res/drawable-mdpi/bar_beautify_rectangle_white.png diff --git a/res/drawable-mdpi/ic_beautify_oval.png b/res/drawable-mdpi/ic_beautify_oval.png Binary files differnew file mode 100755 index 000000000..373a99a28 --- /dev/null +++ b/res/drawable-mdpi/ic_beautify_oval.png diff --git a/res/drawable/auto_blue.png b/res/drawable/auto_blue.png Binary files differnew file mode 100644 index 000000000..acf632e16 --- /dev/null +++ b/res/drawable/auto_blue.png diff --git a/res/drawable/beautify_progressbar_style.xml b/res/drawable/beautify_progressbar_style.xml new file mode 100755 index 000000000..962d8dedb --- /dev/null +++ b/res/drawable/beautify_progressbar_style.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright (c) 2016, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@android:id/background" + android:drawable="@drawable/bar_beautify_rectangle_white" /> + <item android:id="@android:id/progress"> + <clip android:drawable="@drawable/bar_beautify_rectangle_blue" /> + </item> +</layer-list>
\ No newline at end of file diff --git a/res/drawable/cloudy.png b/res/drawable/cloudy.png Binary files differnew file mode 100644 index 000000000..b29ab9e5d --- /dev/null +++ b/res/drawable/cloudy.png diff --git a/res/drawable/cloudy_blue.png b/res/drawable/cloudy_blue.png Binary files differnew file mode 100644 index 000000000..303a2703e --- /dev/null +++ b/res/drawable/cloudy_blue.png diff --git a/res/drawable/fluorescent.png b/res/drawable/fluorescent.png Binary files differnew file mode 100644 index 000000000..d25f7473e --- /dev/null +++ b/res/drawable/fluorescent.png diff --git a/res/drawable/fluorescent_blue.png b/res/drawable/fluorescent_blue.png Binary files differnew file mode 100644 index 000000000..7fb7836dd --- /dev/null +++ b/res/drawable/fluorescent_blue.png diff --git a/res/drawable/icon_exposure.png b/res/drawable/icon_exposure.png Binary files differnew file mode 100644 index 000000000..ff5397251 --- /dev/null +++ b/res/drawable/icon_exposure.png diff --git a/res/drawable/icon_exposure_blue.png b/res/drawable/icon_exposure_blue.png Binary files differnew file mode 100644 index 000000000..544b98ab4 --- /dev/null +++ b/res/drawable/icon_exposure_blue.png diff --git a/res/drawable/icon_iso.png b/res/drawable/icon_iso.png Binary files differnew file mode 100644 index 000000000..85662af5e --- /dev/null +++ b/res/drawable/icon_iso.png diff --git a/res/drawable/icon_iso_blue.png b/res/drawable/icon_iso_blue.png Binary files differnew file mode 100644 index 000000000..001d8c9f5 --- /dev/null +++ b/res/drawable/icon_iso_blue.png diff --git a/res/drawable/icon_manual.png b/res/drawable/icon_manual.png Binary files differnew file mode 100644 index 000000000..53e2ff5ec --- /dev/null +++ b/res/drawable/icon_manual.png diff --git a/res/drawable/icon_manual_blue.png b/res/drawable/icon_manual_blue.png Binary files differnew file mode 100644 index 000000000..52b2daa19 --- /dev/null +++ b/res/drawable/icon_manual_blue.png diff --git a/res/drawable/icon_white_balance.png b/res/drawable/icon_white_balance.png Binary files differnew file mode 100644 index 000000000..1fbd36fd3 --- /dev/null +++ b/res/drawable/icon_white_balance.png diff --git a/res/drawable/icon_white_balance_blue.png b/res/drawable/icon_white_balance_blue.png Binary files differnew file mode 100644 index 000000000..ca84b89d8 --- /dev/null +++ b/res/drawable/icon_white_balance_blue.png diff --git a/res/drawable/icon_x.png b/res/drawable/icon_x.png Binary files differnew file mode 100644 index 000000000..a807409c8 --- /dev/null +++ b/res/drawable/icon_x.png diff --git a/res/drawable/incandecent.png b/res/drawable/incandecent.png Binary files differnew file mode 100644 index 000000000..d601e4b5c --- /dev/null +++ b/res/drawable/incandecent.png diff --git a/res/drawable/incandecent_blue.png b/res/drawable/incandecent_blue.png Binary files differnew file mode 100644 index 000000000..0c3eabf13 --- /dev/null +++ b/res/drawable/incandecent_blue.png diff --git a/res/drawable/promode.png b/res/drawable/promode.png Binary files differnew file mode 100644 index 000000000..53e2ff5ec --- /dev/null +++ b/res/drawable/promode.png diff --git a/res/drawable/radial_menu.png b/res/drawable/radial_menu.png Binary files differnew file mode 100644 index 000000000..a5757f1a0 --- /dev/null +++ b/res/drawable/radial_menu.png diff --git a/res/drawable/selected_dot.png b/res/drawable/selected_dot.png Binary files differnew file mode 100644 index 000000000..9114f6ce6 --- /dev/null +++ b/res/drawable/selected_dot.png diff --git a/res/drawable/sunlight.png b/res/drawable/sunlight.png Binary files differnew file mode 100644 index 000000000..cc33dcc3d --- /dev/null +++ b/res/drawable/sunlight.png diff --git a/res/drawable/sunlight_blue.png b/res/drawable/sunlight_blue.png Binary files differnew file mode 100644 index 000000000..c390ec653 --- /dev/null +++ b/res/drawable/sunlight_blue.png diff --git a/res/drawable/white_dot.png b/res/drawable/white_dot.png Binary files differnew file mode 100644 index 000000000..847fd84fe --- /dev/null +++ b/res/drawable/white_dot.png diff --git a/res/layout/one_ui_layout.xml b/res/layout/one_ui_layout.xml index 2a87b6cd2..d87040cde 100644..100755 --- a/res/layout/one_ui_layout.xml +++ b/res/layout/one_ui_layout.xml @@ -21,6 +21,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + <com.android.camera.ui.ProMode + android:id="@+id/promode_slider" + android:layout_height="wrap_content" + android:layout_width="wrap_content" /> + <com.android.camera.ui.FlashToggleButton android:id="@+id/flash_button" style="@style/OneUIMenuButton" @@ -91,42 +96,53 @@ android:id="@+id/makeup_seekbar_layout" android:visibility="gone"> <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:layout_width="12dp" + android:layout_height="20dp" + android:layout_marginLeft="23dp" + android:layout_marginRight="23dp" android:id="@+id/seekbar_toggle"> </ImageView> <RelativeLayout - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/seekbar_body"> <com.android.camera.ui.RotateLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="24dp" + android:layout_height="24dp" android:layout_alignParentLeft="true" android:id="@+id/makeup_low_text"> <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/makeup_seekbar_low"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:textSize="12sp" + android:gravity="center" + android:text="@string/makeup_seekbar_low" + android:textColor="@android:color/white"> </TextView> </com.android.camera.ui.RotateLayout> <SeekBar - android:layout_width="match_parent" + android:layout_width="220dp" android:layout_height="wrap_content" - android:paddingLeft="100dp" - android:paddingRight="100dp" + android:maxHeight="3dip" + android:minHeight="1dip" + android:layout_marginLeft="10dp" + android:layout_toRightOf="@+id/makeup_low_text" + android:progressDrawable="@drawable/beautify_progressbar_style" + android:thumb="@drawable/ic_beautify_oval" android:id="@+id/makeup_seekbar"/> <com.android.camera.ui.RotateLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_toRightOf="@+id/makeup_seekbar" + android:layout_marginLeft="10dp" android:id="@+id/makeup_high_text"> <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/makeup_seekbar_high"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:textSize="12sp" + android:gravity="center" + android:text="@string/makeup_seekbar_high" + android:textColor="@android:color/white"> </TextView> </com.android.camera.ui.RotateLayout> </RelativeLayout> @@ -156,4 +172,11 @@ android:visibility="gone" /> </LinearLayout> + <include layout="@layout/pro_mode_layout" /> + + <ImageView + android:id="@+id/promode_close_button" + android:layout_height="20dp" + android:layout_width="20dp" + android:src="@drawable/icon_x" /> </com.android.camera.ui.OneUICameraControls> diff --git a/res/layout/pro_mode_layout.xml b/res/layout/pro_mode_layout.xml new file mode 100644 index 000000000..54ccb556c --- /dev/null +++ b/res/layout/pro_mode_layout.xml @@ -0,0 +1,148 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (c) 2016, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/pro_mode_layout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:visibility="invisible"> + + <com.android.camera.ui.RotateLayout + android:id="@+id/exposure_rotate_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> + + <LinearLayout + android:id="@+id/exposure_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical"> + + <ImageView + android:id="@+id/exposure" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_gravity="center" + android:src="@drawable/icon_exposure" /> + + <TextView + android:id="@+id/exposure_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + + <com.android.camera.ui.RotateLayout + android:id="@+id/manual_rotate_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> + + <LinearLayout + android:id="@+id/manual_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical"> + + <ImageView + android:id="@+id/manual" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_gravity="center" + android:src="@drawable/icon_manual" /> + + <TextView + android:id="@+id/manual_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + + <com.android.camera.ui.RotateLayout + android:id="@+id/white_balance_rotate_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> + + <LinearLayout + android:id="@+id/white_balance_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical"> + + <ImageView + android:id="@+id/white_balance" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_gravity="center" + android:src="@drawable/icon_white_balance" /> + + <TextView + android:id="@+id/white_balance_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + + <com.android.camera.ui.RotateLayout + android:id="@+id/iso_rotate_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> + + <LinearLayout + android:id="@+id/iso_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical"> + + <ImageView + android:id="@+id/iso" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_gravity="center" + android:src="@drawable/icon_iso" /> + + <TextView + android:id="@+id/iso_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </LinearLayout> + </com.android.camera.ui.RotateLayout> + +</LinearLayout> diff --git a/res/values/camera2arrays.xml b/res/values/camera2arrays.xml index 80c695d58..31d6b5a62 100644 --- a/res/values/camera2arrays.xml +++ b/res/values/camera2arrays.xml @@ -157,6 +157,7 @@ <item>107</item> <item>108</item> <item>104</item> + <item>109</item> </string-array> <!-- Camera Preferences Scene Mode dialog box entries --> @@ -183,6 +184,7 @@ <item>@string/pref_camera_scenemode_entry_sharpshooter</item> <item>@string/pref_camera_scenemode_entry_trackingfocus</item> <item>@string/pref_camera_scenemode_entry_panorama</item> + <item>@string/pref_camera_scenemode_entry_promode</item> </string-array> <array name="pref_camera2_scenemode_thumbnails" translatable="false"> @@ -208,6 +210,7 @@ <item>@drawable/sharp_photo</item> <item>@drawable/tracking_focus</item> <item>@drawable/scene_panorama</item> + <item>@drawable/promode</item> </array> <string-array name="pref_camera2_whitebalance_entryvalues" translatable="false"> diff --git a/res/values/qcomstrings.xml b/res/values/qcomstrings.xml index 34c9b32cf..d53b2c27a 100644 --- a/res/values/qcomstrings.xml +++ b/res/values/qcomstrings.xml @@ -1029,6 +1029,7 @@ <string name="pref_camera_scenemode_entry_sharpshooter" translatable="true">SharpPhoto</string> <string name="pref_camera_scenemode_entry_trackingfocus" translatable="true">TrackingFocus</string> <string name="pref_camera_scenemode_entry_panorama" translatable="true">Panorama</string> + <string name="pref_camera_scenemode_entry_promode" translatable="true">ProMode</string> <string name="bestpicture_done" translatable="true">DONE</string> <string name="bestpicture_at_least_one_picture" translatable="true">At least, one picture has to be chosen.</string> @@ -1040,10 +1041,10 @@ <string name="pref_camera2_shutter_sound_entry_off" translatable="true">Off</string> <string name="pref_camera2_shutter_sound_title" translatable="true">Shutter Sound</string> - <string name="pref_camera2_timer_entry_off" translatable="false">Off</string> - <string name="pref_camera2_timer_entry_2sec" translatable="false">2 seconds</string> - <string name="pref_camera2_timer_entry_5sec" translatable="false">5 seconds</string> - <string name="pref_camera2_timer_entry_10sec" translatable="false">10 seconds</string> + <string name="pref_camera2_timer_entry_off" translatable="true">Off</string> + <string name="pref_camera2_timer_entry_2sec" translatable="true">2 seconds</string> + <string name="pref_camera2_timer_entry_5sec" translatable="true">5 seconds</string> + <string name="pref_camera2_timer_entry_10sec" translatable="true">10 seconds</string> <string name="pref_camera2_timer_value_off" translatable="false">0</string> <string name="pref_camera2_timer_value_2sec" translatable="false">2</string> @@ -1056,5 +1057,11 @@ <string name="makeup_ui_ok_button" translatable="true">OK</string> <string name="makeup_seekbar_low" translatable="true">low</string> <string name="makeup_seekbar_high" translatable="true">high</string> + + <string name="perf_camera2_version_info" translatable="true">Version Info</string> + <string name="perf_camera2_preferences_category_general" translatable="true">General</string> + <string name="perf_camera2_preferences_category_photo" translatable="true">Still camera</string> + <string name="perf_camera2_preferences_category_video" translatable="true">Video camera</string> + <string name="perf_camera2_preferences_category_system" translatable="true">System</string> </resources> diff --git a/res/xml/setting_menu_preferences.xml b/res/xml/setting_menu_preferences.xml index 92b5db8c8..5cf6c0dd1 100644 --- a/res/xml/setting_menu_preferences.xml +++ b/res/xml/setting_menu_preferences.xml @@ -31,7 +31,7 @@ <PreferenceCategory android:key="general" android:layout="@layout/preferences_category" - android:title="GENERAL"> + android:title="@string/perf_camera2_preferences_category_general"> <SwitchPreference android:defaultValue="false" android:icon="@drawable/gps_location" @@ -60,7 +60,7 @@ <PreferenceCategory android:key="photo" android:layout="@layout/preferences_category" - android:title="STILL CAMERA"> + android:title="@string/perf_camera2_preferences_category_photo"> <ListPreference android:defaultValue="@string/pref_camera2_timer_value_off" android:entries="@array/pref_camera2_timer_entries" @@ -169,7 +169,7 @@ <PreferenceCategory android:key="video" android:layout="@layout/preferences_category" - android:title="VIDEO CAMERA"> + android:title="@string/perf_camera2_preferences_category_video"> <ListPreference android:entries="@array/pref_camera2_video_quality_entries" android:entryValues="@array/pref_camera2_video_quality_entryvalues" diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java index 486629895..438be2e90 100755..100644 --- a/src/com/android/camera/AndroidCameraManagerImpl.java +++ b/src/com/android/camera/AndroidCameraManagerImpl.java @@ -200,6 +200,30 @@ class AndroidCameraManagerImpl implements CameraManager { return true; } + public boolean waitDone(long timeout) { + final Object waitDoneLock = new Object(); + final Runnable unlockRunnable = new Runnable() { + @Override + public void run() { + synchronized (waitDoneLock) { + waitDoneLock.notifyAll(); + } + } + }; + + synchronized (waitDoneLock) { + mCameraHandler.post(unlockRunnable); + try { + waitDoneLock.wait(timeout); + mCameraHandler.removeCallbacks(unlockRunnable); + } catch (InterruptedException ex) { + Log.v(TAG, "waitDone interrupted"); + return false; + } + } + return true; + } + /** * This method does not deal with the API level check. Everyone should * check first for supported operations before sending message to this handler. @@ -499,7 +523,7 @@ class AndroidCameraManagerImpl implements CameraManager { @Override public void stopPreview() { mCameraHandler.sendEmptyMessage(STOP_PREVIEW); - mCameraHandler.waitDone(); + mCameraHandler.waitDone(200); } @Override diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 26e7ca933..d3c39793a 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -234,7 +234,6 @@ public class CameraActivity extends Activity private View mPreviewCover; private FrameLayout mPreviewContentLayout; private boolean mPaused = true; - private boolean mHasCriticalPermissions; private boolean mForceReleaseCamera = false; private Uri[] mNfcPushUris = new Uri[1]; @@ -310,7 +309,6 @@ public class CameraActivity extends Activity public void onCameraDisabled(int cameraId) { UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_OPEN_FAIL, "security"); - CameraUtil.showErrorAndFinish(CameraActivity.this, R.string.camera_disabled); } @@ -319,27 +317,21 @@ public class CameraActivity extends Activity public void onDeviceOpenFailure(int cameraId) { UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_OPEN_FAIL, "open"); - - CameraUtil.showErrorAndFinish(CameraActivity.this, - R.string.cannot_connect_camera); + showOpenCameraErrorDialog(); } @Override public void onReconnectionFailure(CameraManager mgr) { UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_OPEN_FAIL, "reconnect"); - - CameraUtil.showErrorAndFinish(CameraActivity.this, - R.string.cannot_connect_camera); + showOpenCameraErrorDialog(); } @Override public void onStartPreviewFailure(int cameraId) { UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_START_PREVIEW_FAIL, "startpreview"); - - CameraUtil.showErrorAndFinish(CameraActivity.this, - R.string.cannot_connect_camera); + showOpenCameraErrorDialog(); } }; @@ -1448,11 +1440,6 @@ public class CameraActivity extends Activity @Override public void onCreate(Bundle state) { super.onCreate(state); - if (checkPermissions() || !mHasCriticalPermissions) { - Log.v(TAG, "onCreate: Missing critical permissions."); - finish(); - return; - } // Check if this is in the secure camera mode. Intent intent = getIntent(); String action = intent.getAction(); @@ -1464,8 +1451,6 @@ public class CameraActivity extends Activity mSecureCamera = intent.getBooleanExtra(SECURE_CAMERA_EXTRA, false); } - mCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); - if (mSecureCamera) { // Change the window flags so that secure camera can show when locked Window win = getWindow(); @@ -1479,9 +1464,20 @@ public class CameraActivity extends Activity Log.d(TAG, "acquire wake lock"); } win.setAttributes(params); + } + if (mSecureCamera && !hasCriticalPermissions()) { + return; + } + if (isStartRequsetPermission()) { + Log.v(TAG, "onCreate: Missing critical permissions."); + finish(); + return; } + + mCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + null, null, null, null); GcamHelper.init(getContentResolver()); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); @@ -1677,6 +1673,10 @@ public class CameraActivity extends Activity @Override public void onPause() { + if (mSecureCamera && !hasCriticalPermissions()) { + super.onPause(); + return; + } // Delete photos that are pending deletion performDeletion(); mOrientationListener.disable(); @@ -1725,9 +1725,8 @@ public class CameraActivity extends Activity * Critical permissions are: camera, microphone and storage. The app cannot run without them. * Non-critical permission is location. */ - private boolean checkPermissions() { - boolean requestPermission = false; - + private boolean hasCriticalPermissions() { + boolean hasCriticalPermission = false; if (checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.RECORD_AUDIO) == @@ -1736,27 +1735,38 @@ public class CameraActivity extends Activity PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - mHasCriticalPermissions = true; + hasCriticalPermission = true; } else { - mHasCriticalPermissions = false; + hasCriticalPermission = false; } + return hasCriticalPermission; + } + + private boolean isStartRequsetPermission() { + boolean isStartPermissionActivity = false; final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean isRequestShown = prefs.getBoolean(CameraSettings.KEY_REQUEST_PERMISSION, false); - if(!isRequestShown || !mHasCriticalPermissions) { - Log.v(TAG, "Request permission"); + + if(!mSecureCamera && (!isRequestShown || !hasCriticalPermissions())) { + Log.v(TAG, "Start Request Permission"); Intent intent = new Intent(this, PermissionsActivity.class); startActivity(intent); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(CameraSettings.KEY_REQUEST_PERMISSION, true); editor.apply(); - requestPermission = true; - } - return requestPermission; + isStartPermissionActivity = true; + } + return isStartPermissionActivity; } @Override public void onResume() { - if (checkPermissions() || !mHasCriticalPermissions) { + if (mSecureCamera && !hasCriticalPermissions()) { + super.onResume(); + showOpenCameraErrorDialog(); + return; + } + if (isStartRequsetPermission()) { super.onResume(); Log.v(TAG, "onResume: Missing critical permissions."); finish(); @@ -1814,6 +1824,9 @@ public class CameraActivity extends Activity @Override public void onStart() { super.onStart(); + if (mSecureCamera && !hasCriticalPermissions()) { + return; + } bindMediaSaveService(); mPanoramaViewHelper.onStart(); } @@ -1821,6 +1834,9 @@ public class CameraActivity extends Activity @Override protected void onStop() { super.onStop(); + if (mSecureCamera && !hasCriticalPermissions()) { + return; + } mPanoramaViewHelper.onStop(); unbindMediaSaveService(); } @@ -2352,4 +2368,14 @@ public class CameraActivity extends Activity public CameraModule getCurrentModule() { return mCurrentModule; } + + private void showOpenCameraErrorDialog() { + if (!hasCriticalPermissions()) { + CameraUtil.showErrorAndFinish(CameraActivity.this, + R.string.error_permissions); + } else { + CameraUtil.showErrorAndFinish(CameraActivity.this, + R.string.cannot_connect_camera); + } + } } diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 069fb8701..97c4eae0a 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -1027,6 +1027,10 @@ public class CameraSettings { return; } + if (numOfCameras > 2 ) { + numOfCameras = 2; + } + CharSequence[] entryValues = new CharSequence[numOfCameras]; for (int i = 0; i < numOfCameras; ++i) { entryValues[i] = "" + i; diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 249a17534..51bb013c5 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -94,6 +94,7 @@ import com.android.camera.util.CameraUtil; import com.android.camera.util.PersistUtil; import com.android.camera.util.SettingTranslation; import com.android.camera.util.ApiHelper; +import com.android.camera.util.AccessibilityUtils; import com.android.internal.util.MemInfoReader; import org.codeaurora.snapcam.R; @@ -104,7 +105,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Comparator; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -116,7 +116,7 @@ public class CaptureModule implements CameraModule, PhotoController, MediaSaveService.Listener, ClearSightImageProcessor.Callback, SettingsManager.Listener, LocationManager.Listener, CountDownView.OnCountDownFinishedListener, - MediaRecorder.OnInfoListener{ + MediaRecorder.OnErrorListener, MediaRecorder.OnInfoListener { public static final int DUAL_MODE = 0; public static final int BAYER_MODE = 1; public static final int MONO_MODE = 2; @@ -193,6 +193,12 @@ public class CaptureModule implements CameraModule, PhotoController, public static CameraCharacteristics.Key<Byte> MetaDataMonoOnlyKey = new CameraCharacteristics.Key<>("org.codeaurora.qcamera3.sensor_meta_data.is_mono_only", Byte.class); + public static CaptureRequest.Key<Integer> SELECT_PRIORITY = + new CaptureRequest.Key<>("org.codeaurora.qcamera3.iso_exp_priority.select_priority", + Integer.class); + public static CaptureRequest.Key<Long> ISO_EXP = + new CaptureRequest.Key<>("org.codeaurora.qcamera3.iso_exp_priority.use_iso_exp_priority", + Long.class); private boolean[] mTakingPicture = new boolean[MAX_NUM_CAM]; private int mControlAFMode = CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE; private int mLastResultAFState = -1; @@ -206,7 +212,8 @@ public class CaptureModule implements CameraModule, PhotoController, private boolean mIsLinked = false; private long mCaptureStartTime; private boolean mPaused = true; - private boolean mSurfaceReady = false; + private Semaphore mSurfaceReadyLock = new Semaphore(1); + private boolean mSurfaceReady = true; private boolean[] mCameraOpened = new boolean[MAX_NUM_CAM]; private CameraDevice[] mCameraDevice = new CameraDevice[MAX_NUM_CAM]; private String[] mCameraId = new String[MAX_NUM_CAM]; @@ -224,6 +231,7 @@ public class CaptureModule implements CameraModule, PhotoController, private int mDisplayOrientation; private boolean mIsRefocus = false; private int mChosenImageFormat; + private Toast mToast; /** * A {@link CameraCaptureSession } for camera preview. @@ -781,8 +789,15 @@ public class CaptureModule implements CameraModule, PhotoController, } } + private void applyFocusDistance(CaptureRequest.Builder builder, String value) { + if (value == null) return; + float valueF = Float.valueOf(value); + builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF); + builder.set(CaptureRequest.LENS_FOCUS_DISTANCE, valueF); + } + private void createSessions() { - if (mPaused || !mCamerasOpened || !mSurfaceReady) return; + if (mPaused || !mCamerasOpened ) return; if (isBackCamera()) { switch (getCameraMode()) { case DUAL_MODE: @@ -811,12 +826,42 @@ public class CaptureModule implements CameraModule, PhotoController, return builder; } + private void waitForPreviewSurfaceReady() { + try { + if (!mSurfaceReady) { + if (!mSurfaceReadyLock.tryAcquire(2000, TimeUnit.MILLISECONDS)) { + Log.d(TAG, "Time out waiting for surface."); + throw new RuntimeException("Time out waiting for surface."); + } + mSurfaceReadyLock.release(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void updatePreviewSurfaceReadyState(boolean rdy) { + if (rdy != mSurfaceReady) { + if (rdy) { + Log.i(TAG, "Preview Surface is ready!"); + mSurfaceReadyLock.release(); + mSurfaceReady = true; + } else { + try { + Log.i(TAG, "Preview Surface is not ready!"); + mSurfaceReady = false; + mSurfaceReadyLock.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } private void createSession(final int id) { - if (mPaused || !mCameraOpened[id] || !mSurfaceReady) return; + if (mPaused || !mCameraOpened[id]) return; Log.d(TAG, "createSession " + id); List<Surface> list = new LinkedList<Surface>(); try { - Surface surface = getPreviewSurfaceForSession(id); // We set up a CaptureRequest.Builder with the output Surface. mPreviewRequestBuilder[id] = getRequestBuilder(id); mPreviewRequestBuilder[id].setTag(id); @@ -889,6 +934,8 @@ public class CaptureModule implements CameraModule, PhotoController, Log.d(TAG, "cameracapturesession - onClosed"); } }; + waitForPreviewSurfaceReady(); + Surface surface = getPreviewSurfaceForSession(id); if(id == getMainCameraId()) { mFrameProcessor.setOutputSurface(surface); @@ -1012,8 +1059,6 @@ public class CaptureModule implements CameraModule, PhotoController, mCameraOpened[i] = false; mTakingPicture[i] = false; } - mSurfaceReady = false; - for (int i = 0; i < MAX_NUM_CAM; i++) { mState[i] = STATE_PREVIEW; } @@ -1302,6 +1347,13 @@ public class CaptureModule implements CameraModule, PhotoController, unlockFocus(id); } }, mCaptureCallbackHandler); + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + mUI.enableVideo(false); + } + }); + } else { checkAndPlayShutterSound(id); if(isMpoOn()) { @@ -1558,6 +1610,7 @@ public class CaptureModule implements CameraModule, PhotoController, public void run() { mUI.stopSelfieFlash(); mUI.enableShutter(true); + mUI.enableVideo(true); } }); } @@ -1831,6 +1884,7 @@ public class CaptureModule implements CameraModule, PhotoController, @Override public void onPauseBeforeSuper() { mPaused = true; + mToast = null; mUI.onPause(); if (mIsRecordingVideo) { stopRecordingVideo(getMainCameraId()); @@ -1872,6 +1926,7 @@ public class CaptureModule implements CameraModule, PhotoController, } mLongshotActive = false; mZoomValue = 1.0f; + updatePreviewSurfaceReadyState(false); } private ArrayList<Integer> getFrameProcFilterId() { @@ -2028,7 +2083,6 @@ public class CaptureModule implements CameraModule, PhotoController, Log.d(TAG, "onResume " + getCameraMode()); initializeValues(); updatePreviewSize(); - mUI.showSurfaceView(); mCameraIdList = new ArrayList<>(); if (mSound == null) { @@ -2057,6 +2111,7 @@ public class CaptureModule implements CameraModule, PhotoController, msg.arg1 = FRONT_ID; mCameraHandler.sendMessage(msg); } + mUI.showSurfaceView(); if (!mFirstTimeInitialized) { initializeFirstTime(); } else { @@ -2070,8 +2125,15 @@ public class CaptureModule implements CameraModule, PhotoController, } }); mUI.enableShutter(true); - + mUI.enableVideo(true); String scene = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE); + boolean promode = false; + if (scene != null) { + int mode = Integer.parseInt(scene); + if (mode == SettingsManager.SCENE_MODE_PROMODE_INT) promode = true; + } + mUI.initializeProMode(promode); + if(isPanoSetting(scene)) { mActivity.onModuleSelected(ModuleSwitcher.PANOCAPTURE_MODULE_INDEX); } @@ -2287,16 +2349,17 @@ public class CaptureModule implements CameraModule, PhotoController, } private boolean isTouchToFocusAllowed() { - if (isTakingPicture() || mIsRecordingVideo || isSceneModeOn()) return false; + if (isTakingPicture() || mIsRecordingVideo || isTouchAfEnabledSceneMode()) return false; return true; } - private boolean isSceneModeOn() { + private boolean isTouchAfEnabledSceneMode() { String scene = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE); if (scene == null) return false; int mode = Integer.parseInt(scene); - if (mode != SettingsManager.SCENE_MODE_DUAL_INT && mode != CaptureRequest - .CONTROL_SCENE_MODE_DISABLED) return true; + if (mode != CaptureRequest.CONTROL_SCENE_MODE_DISABLED + && mode < SettingsManager.SCENE_MODE_CUSTOM_START) + return true; return false; } @@ -2375,17 +2438,16 @@ public class CaptureModule implements CameraModule, PhotoController, @Override public void onPreviewUIReady() { + updatePreviewSurfaceReadyState(true); + if (mPaused || mIsRecordingVideo) { return; } - Log.d(TAG, "onPreviewUIReady"); - mSurfaceReady = true; - createSessions(); } @Override public void onPreviewUIDestroyed() { - mSurfaceReady = false; + updatePreviewSurfaceReadyState(false); } @Override @@ -2535,7 +2597,7 @@ public class CaptureModule implements CameraModule, PhotoController, } } - private void startRecordingVideo(int cameraId) { + private void startRecordingVideo(final int cameraId) { if (null == mCameraDevice[cameraId]) { return; } @@ -2562,7 +2624,7 @@ public class CaptureModule implements CameraModule, PhotoController, createVideoSnapshotImageReader(); mVideoRequestBuilder = mCameraDevice[cameraId].createCaptureRequest(CameraDevice.TEMPLATE_RECORD); mVideoRequestBuilder.setTag(cameraId); - + mPreviewRequestBuilder[cameraId] = mVideoRequestBuilder; List<Surface> surfaces = new ArrayList<>(); Surface surface = getPreviewSurfaceForSession(cameraId); @@ -2588,6 +2650,7 @@ public class CaptureModule implements CameraModule, PhotoController, @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mCurrentSession = cameraCaptureSession; + mCaptureSession[cameraId] = cameraCaptureSession; CameraConstrainedHighSpeedCaptureSession session = (CameraConstrainedHighSpeedCaptureSession) mCurrentSession; try { @@ -2631,6 +2694,7 @@ public class CaptureModule implements CameraModule, PhotoController, public void onConfigured(CameraCaptureSession cameraCaptureSession) { Log.d(TAG, "StartRecordingVideo session onConfigured"); mCurrentSession = cameraCaptureSession; + mCaptureSession[cameraId] = cameraCaptureSession; try { setUpVideoCaptureRequestBuilder(mVideoRequestBuilder); mCurrentSession.setRepeatingRequest(mVideoRequestBuilder.build(), @@ -2831,14 +2895,30 @@ public class CaptureModule implements CameraModule, PhotoController, private void stopRecordingVideo(int cameraId) { Log.d(TAG, "stopRecordingVideo " + cameraId); + boolean shouldAddToMediaStoreNow = false; // Stop recording mFrameProcessor.setVideoOutputSurface(null); mFrameProcessor.onClose(); closePreviewSession(); - mMediaRecorder.stop(); - mMediaRecorder.reset(); - mMediaRecorder.setOnInfoListener(null); - saveVideo(); + try { + mMediaRecorder.setOnErrorListener(null); + mMediaRecorder.setOnInfoListener(null); + mMediaRecorder.stop(); + shouldAddToMediaStoreNow = true; + AccessibilityUtils.makeAnnouncement(mUI.getVideoButton(), + mActivity.getString(R.string.video_recording_stopped)); + } catch (RuntimeException e) { + Log.e(TAG, "MediaRecoder stop fail", e); + if (mVideoFilename != null) deleteVideoFile(mVideoFilename); + } + if (shouldAddToMediaStoreNow) { + saveVideo(); + } + + // release media recorder + releaseMediaRecorder(); + releaseAudioFocus(); + mUI.showRecordingUI(false, false); mUI.enableShutter(true); @@ -2851,9 +2931,8 @@ public class CaptureModule implements CameraModule, PhotoController, if (changed) { mUI.hideSurfaceView(); mUI.showSurfaceView(); - } else { - createSession(cameraId); } + createSessions(); mUI.showUIafterRecording(); mUI.resetTrackingFocus(); } @@ -2936,6 +3015,9 @@ public class CaptureModule implements CameraModule, PhotoController, if (mCaptureTimeLapse) { size = CameraSettings.getTimeLapseQualityFor(size); } + + if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder(); + updateHFRSetting(); boolean hfr = mHighSpeedCapture && !mHighSpeedRecordingMode; mProfile = CamcorderProfile.get(cameraId, size); @@ -3007,7 +3089,15 @@ public class CaptureModule implements CameraModule, PhotoController, } else { mMediaRecorder.setOrientationHint(rotation); } - mMediaRecorder.prepare(); + try { + mMediaRecorder.prepare(); + } catch (IOException e) { + Log.e(TAG, "prepare failed for " + mVideoFilename, e); + releaseMediaRecorder(); + throw new RuntimeException(e); + } + + mMediaRecorder.setOnErrorListener(this); mMediaRecorder.setOnInfoListener(this); } @@ -3162,6 +3252,10 @@ public class CaptureModule implements CameraModule, PhotoController, return true; } + if ( mIsRecordingVideo ) { + Log.e(TAG, " cancel longshot:not supported when recording"); + return true; + } return false; } @@ -3231,6 +3325,9 @@ public class CaptureModule implements CameraModule, PhotoController, updatePreview = true; applyFaceDetection(mPreviewRequestBuilder[cameraId]); break; + case SettingsManager.KEY_FOCUS_DISTANCE: + updatePreview = true; + applyFocusDistance(mPreviewRequestBuilder[cameraId], value); } return updatePreview; } @@ -3280,8 +3377,9 @@ public class CaptureModule implements CameraModule, PhotoController, request.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); return; } - if (mode != CaptureRequest.CONTROL_SCENE_MODE_DISABLED && mode != - SettingsManager.SCENE_MODE_DUAL_INT) { + if (mode != CaptureRequest.CONTROL_SCENE_MODE_DISABLED + && mode != SettingsManager.SCENE_MODE_DUAL_INT + && mode != SettingsManager.SCENE_MODE_PROMODE_INT) { request.set(CaptureRequest.CONTROL_SCENE_MODE, mode); request.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE); } else { @@ -3299,9 +3397,14 @@ public class CaptureModule implements CameraModule, PhotoController, private void applyIso(CaptureRequest.Builder request) { String value = mSettingsManager.getValue(SettingsManager.KEY_ISO); if (value == null) return; - if (value.equals("auto")) return; - int intValue = Integer.parseInt(value); - request.set(CaptureRequest.SENSOR_SENSITIVITY, intValue); + if (value.equals("auto")) { + request.set(SELECT_PRIORITY, null); + request.set(ISO_EXP, null); + } else { + long intValue = Integer.parseInt(value); + request.set(SELECT_PRIORITY, 0); + request.set(ISO_EXP, intValue); + } } private void applyColorEffect(CaptureRequest.Builder request) { @@ -3545,6 +3648,9 @@ public class CaptureModule implements CameraModule, PhotoController, case SettingsManager.KEY_FLASH_MODE: if (count == 0) restartSession(false); return; + case SettingsManager.KEY_SCENE_MODE: + restartAll(); + return; } if (isBackCamera()) { @@ -3838,6 +3944,18 @@ public class CaptureModule implements CameraModule, PhotoController, enableRecordingLocation(false); } + // from MediaRecorder.OnErrorListener + @Override + public void onError(MediaRecorder mr, int what, int extra) { + Log.e(TAG, "MediaRecorder error. what=" + what + ". extra=" + extra); + stopRecordingVideo(getMainCameraId()); + mUI.showUIafterRecording(); + if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { + // We may have run out of space on the sdcard. + mActivity.updateStorageSpaceAndHint(); + } + } + // from MediaRecorder.OnInfoListener @Override public void onInfo(MediaRecorder mr, int what, int extra) { @@ -3866,4 +3984,49 @@ public class CaptureModule implements CameraModule, PhotoController, Storage.setSaveSDCard(mSettingsManager.getValue(SettingsManager .KEY_CAMERA_SAVEPATH).equals("1")); } + + private void deleteVideoFile(String fileName) { + Log.v(TAG, "Deleting video " + fileName); + File f = new File(fileName); + if (!f.delete()) { + Log.v(TAG, "Could not delete " + fileName); + } + } + + private void releaseMediaRecorder() { + Log.v(TAG, "Releasing media recorder."); + if (mMediaRecorder != null) { + cleanupEmptyFile(); + mMediaRecorder.reset(); + mMediaRecorder.release(); + mMediaRecorder = null; + } + mVideoFilename = null; + } + + private void cleanupEmptyFile() { + if (mVideoFilename != null) { + File f = new File(mVideoFilename); + if (f.length() == 0 && f.delete()) { + Log.v(TAG, "Empty video file deleted: " + mVideoFilename); + mVideoFilename = null; + } + } + } + + private void releaseAudioFocus() { + AudioManager am = (AudioManager)mActivity.getSystemService(Context.AUDIO_SERVICE); + int result = am.abandonAudioFocus(null); + if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) { + Log.v(TAG, "Audio focus release failed"); + } + } + + private void showToast(String tips) { + if (mToast == null) { + mToast = Toast.makeText(mActivity, tips, Toast.LENGTH_LONG); + } + mToast.setText(tips); + mToast.show(); + } } diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java index 88460b865..77100ecfb 100644..100755 --- a/src/com/android/camera/CaptureUI.java +++ b/src/com/android/camera/CaptureUI.java @@ -184,6 +184,7 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private PauseButton mPauseButton; private RotateImageView mMuteButton; private ImageView mSeekbarToggleButton; + private View mProModeCloseButton; int mPreviewWidth; int mPreviewHeight; @@ -279,10 +280,18 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, @Override public void onClick(View v) { toggleMakeup(); + updateMenus(); } }); setMakeupButtonIcon(); mFlashButton = (FlashToggleButton) mRootView.findViewById(R.id.flash_button); + mProModeCloseButton = mRootView.findViewById(R.id.promode_close_button); + mProModeCloseButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mSettingsManager.setValue(SettingsManager.KEY_SCENE_MODE, "" + SettingsManager.SCENE_MODE_AUTO_INT); + } + }); initFilterModeButton(); initSceneModeButton(); initSwitchCamera(); @@ -367,8 +376,8 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, String value = mSettingsManager.getValue(SettingsManager.KEY_MAKEUP); if(value != null && !mIsVideoUI) { if(value.equals("0")) { - mSettingsManager.setValue(SettingsManager.KEY_MAKEUP, "10"); - mMakeupSeekBar.setProgress(10); + mSettingsManager.setValue(SettingsManager.KEY_MAKEUP, "50"); + mMakeupSeekBar.setProgress(50); mMakeupSeekBarLayout.setVisibility(View.VISIBLE); mSeekbarBody.setVisibility(View.VISIBLE); mSeekbarToggleButton.setImageResource(R.drawable.seekbar_hide); @@ -425,6 +434,12 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } } + public void initializeProMode(boolean promode) { + mCameraControls.setProMode(promode); + if (promode) mVideoButton.setVisibility(View.INVISIBLE); + else mVideoButton.setVisibility(View.VISIBLE); + } + // called from onResume but only the first time public void initializeFirstTime() { // Initialize shutter button. @@ -477,6 +492,7 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, mFilterLayout = null; } } + updateMenus(); } public void openSettingsMenu() { @@ -544,6 +560,7 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, public void onClick(View v) { addFilterMode(); adjustOrientation(); + updateMenus(); } }); } @@ -860,9 +877,28 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, public void cleanUpMenus() { showUI(); + updateMenus(); mActivity.setSystemBarsVisibility(false); } + public void updateMenus() { + boolean enableMakeupMenu = true; + boolean enableFilterMenu = true; + boolean enableSceneMenu = true; + String makeupValue = mSettingsManager.getValue(SettingsManager.KEY_MAKEUP); + int colorEffect = mSettingsManager.getValueIndex(SettingsManager.KEY_COLOR_EFFECT); + if (makeupValue != null && !makeupValue.equals("0")) { + enableSceneMenu = false; + enableFilterMenu = false; + } else if (colorEffect != 0 || mFilterMenuStatus == FILTER_MENU_ON){ + enableSceneMenu = false; + enableMakeupMenu = false; + } + mMakeupButton.setEnabled(enableMakeupMenu); + mFilterModeSwitcher.setEnabled(enableFilterMenu); + mSceneModeSwitcher.setEnabled(enableSceneMenu); + } + public boolean arePreviewControlsVisible() { return !mUIhidden; } @@ -879,6 +915,15 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } } + /** + * Enables or disables the video button. + */ + public void enableVideo(boolean enabled) { + if (mVideoButton != null) { + mVideoButton.setEnabled(enabled); + } + } + private boolean handleBackKeyOnMenu() { if (mFilterMenuStatus == FILTER_MENU_ON) { removeFilterMenu(true); @@ -1315,6 +1360,7 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } public void showSurfaceView() { + Log.d(TAG, "showSurfaceView"); mSurfaceView.getHolder().setFixedSize(mPreviewWidth, mPreviewHeight); mSurfaceView.setAspectRatio(mPreviewHeight, mPreviewWidth); mSurfaceView.setVisibility(View.VISIBLE); @@ -1359,4 +1405,8 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } } + + public ImageView getVideoButton() { + return mVideoButton; + } } diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 1851466d1..cfdd8af12 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -2518,7 +2518,7 @@ public class PhotoModule private void updateRemainingPhotos() { if (mJpegFileSizeEstimation != 0) { - mRemainingPhotos = (int) + mRemainingPhotos = (int) ((mActivity.getStorageSpaceBytes() - Storage.LOW_STORAGE_THRESHOLD_BYTES) / mJpegFileSizeEstimation); } else { @@ -2971,7 +2971,7 @@ public class PhotoModule if (!mSnapshotOnIdle && !mInstantCaptureSnapShot) { // If the focus mode is continuous autofocus, call cancelAutoFocus to // resume it because it may have been paused by autoFocus call. - if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode())) { + if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode()) && mCameraState !=INIT) { mCameraDevice.cancelAutoFocus(); } } else { @@ -4965,7 +4965,7 @@ public class PhotoModule public void onErrorListener(int error) { enableRecordingLocation(false); } - + } /* Below is no longer needed, except to get rid of compile error diff --git a/src/com/android/camera/SettingsActivity.java b/src/com/android/camera/SettingsActivity.java index 503927904..e97073f58 100644 --- a/src/com/android/camera/SettingsActivity.java +++ b/src/com/android/camera/SettingsActivity.java @@ -89,6 +89,20 @@ public class SettingsActivity extends PreferenceActivity { } }; + private SettingsManager.Listener mListener = new SettingsManager.Listener(){ + @Override + public void onSettingsChanged(List<SettingsManager.SettingState> settings){ + Map<String, SettingsManager.Values> map = mSettingsManager.getValuesMap(); + for( SettingsManager.SettingState state : settings) { + SettingsManager.Values values = map.get(state.key); + boolean enabled = values.overriddenValue == null; + Preference pref = findPreference(state.key); + if (pref != null) { + pref.setEnabled(enabled); + } + } + } + }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -102,6 +116,7 @@ public class SettingsActivity extends PreferenceActivity { finish(); return; } + mSettingsManager.registerListener(mListener); addPreferencesFromResource(R.xml.setting_menu_preferences); mSharedPreferences = getPreferenceManager().getSharedPreferences(); @@ -207,12 +222,16 @@ public class SettingsActivity extends PreferenceActivity { private void updatePreferenceButton(String key) { Preference pref = findPreference(key); - if (pref != null && pref instanceof ListPreference) { - ListPreference pref2 = (ListPreference) pref; - if (pref2.getEntryValues().length == 1) { - pref2.setEnabled(false); - } else { - pref2.setEnabled(true); + if (pref != null ) { + if( pref instanceof ListPreference) { + ListPreference pref2 = (ListPreference) pref; + if (pref2.getEntryValues().length == 1) { + pref2.setEnabled(false); + } else { + pref2.setEnabled(true); + } + }else { + pref.setEnabled(false); } } } @@ -243,6 +262,12 @@ public class SettingsActivity extends PreferenceActivity { finish(); } + @Override + protected void onDestroy() { + super.onDestroy(); + mSettingsManager.unregisterListener(mListener); + } + private void setShowInLockScreen() { // Change the window flags so that secure camera can show when locked Window win = getWindow(); diff --git a/src/com/android/camera/SettingsManager.java b/src/com/android/camera/SettingsManager.java index f64d64a01..520a247f6 100644 --- a/src/com/android/camera/SettingsManager.java +++ b/src/com/android/camera/SettingsManager.java @@ -86,15 +86,17 @@ public class SettingsManager implements ListMenu.SettingsListener { public static final int SCENE_MODE_NIGHT_INT = 5; // Custom-Scenemodes start from 100 - public static final int SCENE_MODE_DUAL_INT = 100; - public static final int SCENE_MODE_OPTIZOOM_INT = 101; - public static final int SCENE_MODE_UBIFOCUS_INT = 102; - public static final int SCENE_MODE_BESTPICTURE_INT = 103; - public static final int SCENE_MODE_PANORAMA_INT = 104; - public static final int SCENE_MODE_CHROMAFLASH_INT = 105; - public static final int SCENE_MODE_BLURBUSTER_INT = 106; - public static final int SCENE_MODE_SHARPSHOOTER_INT = 107; - public static final int SCENE_MODE_TRACKINGFOCUS_INT = 108; + public static final int SCENE_MODE_CUSTOM_START = 100; + public static final int SCENE_MODE_DUAL_INT = SCENE_MODE_CUSTOM_START; + public static final int SCENE_MODE_OPTIZOOM_INT = SCENE_MODE_CUSTOM_START + 1; + public static final int SCENE_MODE_UBIFOCUS_INT = SCENE_MODE_CUSTOM_START + 2; + public static final int SCENE_MODE_BESTPICTURE_INT = SCENE_MODE_CUSTOM_START + 3; + public static final int SCENE_MODE_PANORAMA_INT = SCENE_MODE_CUSTOM_START + 4; + public static final int SCENE_MODE_CHROMAFLASH_INT = SCENE_MODE_CUSTOM_START + 5; + public static final int SCENE_MODE_BLURBUSTER_INT = SCENE_MODE_CUSTOM_START + 6; + public static final int SCENE_MODE_SHARPSHOOTER_INT = SCENE_MODE_CUSTOM_START + 7; + public static final int SCENE_MODE_TRACKINGFOCUS_INT = SCENE_MODE_CUSTOM_START + 8; + public static final int SCENE_MODE_PROMODE_INT = SCENE_MODE_CUSTOM_START + 9; public static final String SCENE_MODE_DUAL_STRING = "100"; public static final String KEY_CAMERA_SAVEPATH = "pref_camera2_savepath_key"; public static final String KEY_RECORD_LOCATION = "pref_camera2_recordlocation_key"; @@ -134,6 +136,7 @@ public class SettingsManager implements ListMenu.SettingsListener { public static final String KEY_SHUTTER_SOUND = "pref_camera2_shutter_sound_key"; public static final String KEY_DEVELOPER_MENU = "pref_camera2_developer_menu_key"; public static final String KEY_RESTORE_DEFAULT = "pref_camera2_restore_default_key"; + public static final String KEY_FOCUS_DISTANCE = "pref_camera2_focus_distance_key"; private static final String TAG = "SnapCam_SettingsManager"; private static SettingsManager sInstance; @@ -419,12 +422,20 @@ public class SettingsManager implements ListMenu.SettingsListener { mListeners.add(listener); } + public void unregisterListener(Listener listener) { + mListeners.remove(listener); + } + private void notifyListeners(List<SettingState> changes) { for (Listener listener : mListeners) { listener.onSettingsChanged(changes); } } + public int getCurrentCameraId() { + return mCameraId; + } + public String getValue(String key) { Values values = mValuesMap.get(key); if (values == null) return null; @@ -467,6 +478,14 @@ public class SettingsManager implements ListMenu.SettingsListener { } } + public void setFocusDistance(float value) { + List<SettingState> list = new ArrayList<>(); + Values values = new Values("" + value, null); + SettingState ss = new SettingState(KEY_FOCUS_DISTANCE, values); + list.add(ss); + notifyListeners(list); + } + private void updateMapAndNotify(ListPreference pref) { String key = pref.getKey(); List changed = checkDependencyAndUpdate(key); @@ -996,6 +1015,11 @@ public class SettingsManager implements ListMenu.SettingsListener { return modes; } + public float getMinimumFocusDistance(int cameraId) { + return mCharacteristics.get(cameraId) + .get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE); + } + private List<String> getSupportedWhiteBalanceModes(int cameraId) { int[] whiteBalanceModes = mCharacteristics.get(cameraId).get(CameraCharacteristics .CONTROL_AWB_AVAILABLE_MODES); @@ -1020,6 +1044,7 @@ public class SettingsManager implements ListMenu.SettingsListener { if (BlurbusterFilter.isSupportedStatic()) modes.add(SCENE_MODE_BLURBUSTER_INT + ""); if (SharpshooterFilter.isSupportedStatic()) modes.add(SCENE_MODE_SHARPSHOOTER_INT + ""); if (TrackingFocusFrameListener.isSupportedStatic()) modes.add(SCENE_MODE_TRACKINGFOCUS_INT + ""); + modes.add("" + SCENE_MODE_PROMODE_INT); for (int mode : sceneModes) { modes.add("" + mode); } diff --git a/src/com/android/camera/ui/CountDownView.java b/src/com/android/camera/ui/CountDownView.java index 6420fd2c3..7e1f28d52 100644..100755 --- a/src/com/android/camera/ui/CountDownView.java +++ b/src/com/android/camera/ui/CountDownView.java @@ -153,16 +153,21 @@ public class CountDownView extends FrameLayout { public void setOrientation(int orientation) { mRemainingSecondsView.setRotation(-orientation); - mCountDownTitle.setRotation(-orientation); + int width = getResources().getDisplayMetrics().widthPixels; + int height = mCountDownTitle.getMeasuredHeight(); + if (height == 0) { + measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED); + height = mCountDownTitle.getMeasuredHeight(); + } int dx = 0, dy = 0; switch (orientation) { case 90: - dy = (mCountDownTitle.getWidth() - mCountDownTitle.getHeight()) / 2; + dy = (width - height) / 2; dx = -dy; break; case 270: - dx = dy = (mCountDownTitle.getWidth() - mCountDownTitle.getHeight()) / 2; + dx = dy = (width - height) / 2; break; case 180: break; diff --git a/src/com/android/camera/ui/OneUICameraControls.java b/src/com/android/camera/ui/OneUICameraControls.java index 63e1b5b4d..413221211 100644 --- a/src/com/android/camera/ui/OneUICameraControls.java +++ b/src/com/android/camera/ui/OneUICameraControls.java @@ -27,15 +27,16 @@ import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; -import org.codeaurora.snapcam.R; - import com.android.camera.Storage; import com.android.camera.imageprocessor.filter.BeautificationFilter; +import org.codeaurora.snapcam.R; + public class OneUICameraControls extends RotatableLayout { private static final String TAG = "CAM_Controls"; @@ -53,6 +54,8 @@ public class OneUICameraControls extends RotatableLayout { private View mMakeupSeekBarLowText; private View mMakeupSeekBarHighText; private View mMakeupSeekBarLayout; + private ViewGroup mProModeLayout; + private View mProModeCloseButton; private ArrowTextView mRefocusToast; @@ -76,9 +79,27 @@ public class OneUICameraControls extends RotatableLayout { private int mHeight; private boolean mVisible; + private ProMode mProMode; + private ImageView mExposureIcon; + private ImageView mManualIcon; + private ImageView mWhiteBalanceIcon; + private ImageView mIsoIcon; + private TextView mExposureText; + private TextView mManualText; + private TextView mWhiteBalanceText; + private TextView mIsoText; + private boolean mProModeOn = false; + private LinearLayout mExposureLayout; + private LinearLayout mManualLayout; + private LinearLayout mWhiteBalanceLayout; + private LinearLayout mIsoLayout; + private RotateLayout mExposureRotateLayout; + private RotateLayout mManualRotateLayout; + private RotateLayout mWhiteBalanceRotateLayout; + private RotateLayout mIsoRotateLayout; + public OneUICameraControls(Context context, AttributeSet attrs) { super(context, attrs); - mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); setWillNotDraw(false); @@ -117,6 +138,83 @@ public class OneUICameraControls extends RotatableLayout { mFilterModeSwitcher = findViewById(R.id.filter_mode_switcher); mRemainingPhotos = (LinearLayout) findViewById(R.id.remaining_photos); mRemainingPhotosText = (TextView) findViewById(R.id.remaining_photos_text); + mProModeLayout = (ViewGroup) findViewById(R.id.pro_mode_layout); + mProModeCloseButton = findViewById(R.id.promode_close_button); + + mExposureIcon = (ImageView) findViewById(R.id.exposure); + mManualIcon = (ImageView) findViewById(R.id.manual); + mWhiteBalanceIcon = (ImageView) findViewById(R.id.white_balance); + mIsoIcon = (ImageView) findViewById(R.id.iso); + mExposureText = (TextView) findViewById(R.id.exposure_value); + mManualText = (TextView) findViewById(R.id.manual_value); + mWhiteBalanceText = (TextView) findViewById(R.id.white_balance_value); + mIsoText = (TextView) findViewById(R.id.iso_value); + mProMode = (ProMode) findViewById(R.id.promode_slider); + mProMode.initialize(this); + + mExposureLayout = (LinearLayout) findViewById(R.id.exposure_layout); + mManualLayout = (LinearLayout) findViewById(R.id.manual_layout); + mWhiteBalanceLayout = (LinearLayout) findViewById(R.id.white_balance_layout); + mIsoLayout = (LinearLayout) findViewById(R.id.iso_layout); + + mExposureRotateLayout = (RotateLayout) findViewById(R.id.exposure_rotate_layout); + mManualRotateLayout = (RotateLayout) findViewById(R.id.manual_rotate_layout); + mWhiteBalanceRotateLayout = (RotateLayout) findViewById(R.id.white_balance_rotate_layout); + mIsoRotateLayout = (RotateLayout) findViewById(R.id.iso_rotate_layout); + + mExposureLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.EXPOSURE_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mExposureIcon.setImageResource(R.drawable.icon_exposure_blue); + mProMode.setMode(ProMode.EXPOSURE_MODE); + } + } + }); + mManualLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.MANUAL_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mManualIcon.setImageResource(R.drawable.icon_manual_blue); + mProMode.setMode(ProMode.MANUAL_MODE); + } + } + }); + mWhiteBalanceLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.WHITE_BALANCE_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mWhiteBalanceIcon.setImageResource(R.drawable.icon_white_balance_blue); + mProMode.setMode(ProMode.WHITE_BALANCE_MODE); + } + } + }); + mIsoLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetProModeIcons(); + int mode = mProMode.getMode(); + if (mode == ProMode.ISO_MODE) { + mProMode.setMode(ProMode.NO_MODE); + } else { + mIsoIcon.setImageResource(R.drawable.icon_iso_blue); + mProMode.setMode(ProMode.ISO_MODE); + } + } + }); + mViews = new View[]{ mSceneModeSwitcher, mFilterModeSwitcher, mFrontBackSwitcher, mTsMakeupSwitcher, mFlashButton, mShutter, mPreview, mVideoShutter @@ -142,6 +240,14 @@ public class OneUICameraControls extends RotatableLayout { if(mMakeupSeekBar != null) { mMakeupSeekBar.setMinimumWidth(mWidth/2); } + + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mWidth/ 4,mWidth/4); + mExposureLayout.setLayoutParams(lp); + + mManualLayout.setLayoutParams(lp); + mWhiteBalanceLayout.setLayoutParams(lp); + mIsoLayout.setLayoutParams(lp); + initializeProMode(mProModeOn); } public boolean isControlRegion(int x, int y) { @@ -212,6 +318,7 @@ public class OneUICameraControls extends RotatableLayout { setLocation(mShutter, false, 2); setLocation(mVideoShutter, false, 3.15f); setLocationCustomBottom(mMakeupSeekBarLayout, 0, 1); + setLocation(mProModeCloseButton, false, 4); layoutToast(mRefocusToast, w, h, rotation); } @@ -332,6 +439,11 @@ public class OneUICameraControls extends RotatableLayout { ((Rotatable) v).setOrientation(orientation, animation); } } + mExposureRotateLayout.setOrientation(orientation, animation); + mManualRotateLayout.setOrientation(orientation, animation); + mWhiteBalanceRotateLayout.setOrientation(orientation, animation); + mIsoRotateLayout.setOrientation(orientation, animation); + mProMode.setOrientation(orientation); layoutRemaingPhotos(); } @@ -377,4 +489,46 @@ public class OneUICameraControls extends RotatableLayout { mPath.lineTo(x1, y1); } } + + public void setProMode(boolean promode) { + mProModeOn = promode; + initializeProMode(mProModeOn); + resetProModeIcons(); + } + + private void resetProModeIcons() { + mExposureIcon.setImageResource(R.drawable.icon_exposure); + mManualIcon.setImageResource(R.drawable.icon_manual); + mWhiteBalanceIcon.setImageResource(R.drawable.icon_white_balance); + mIsoIcon.setImageResource(R.drawable.icon_iso); + } + + public void initializeProMode(boolean promode) { + if (!promode) { + mProMode.setMode(ProMode.NO_MODE); + mProModeLayout.setVisibility(INVISIBLE); + mProModeCloseButton.setVisibility(INVISIBLE); + return; + } + mProModeLayout.setVisibility(VISIBLE); + mProModeCloseButton.setVisibility(VISIBLE); + mProModeLayout.setY(mHeight - mBottom - mProModeLayout.getHeight()); + } + + public void updateProModeText(int mode, String value) { + switch (mode) { + case ProMode.EXPOSURE_MODE: + mExposureText.setText(value); + break; + case ProMode.MANUAL_MODE: + mManualText.setText(value); + break; + case ProMode.WHITE_BALANCE_MODE: + mWhiteBalanceText.setText(value); + break; + case ProMode.ISO_MODE: + mIsoText.setText(value); + break; + } + } } diff --git a/src/com/android/camera/ui/ProMode.java b/src/com/android/camera/ui/ProMode.java new file mode 100644 index 000000000..9f7d576dc --- /dev/null +++ b/src/com/android/camera/ui/ProMode.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.camera.ui; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PathMeasure; +import android.graphics.Point; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.android.camera.SettingsManager; + +import org.codeaurora.snapcam.R; + +import java.util.ArrayList; + +public class ProMode extends View { + public static final int NO_MODE = -1; + public static final int EXPOSURE_MODE = 0; + public static final int MANUAL_MODE = 1; + public static final int WHITE_BALANCE_MODE = 2; + public static final int ISO_MODE = 3; + private static final int DRAG_Y_THRESHOLD = 100; + private static final int DRAG_X_THRESHOLD = 30; + private static final int BLUE = 0xff4693fb; + private static final int SELECTED_DOT_SIZE = 20; + private static final int DOT_SIZE = 10; + private static final int[] wbIcons = {R.drawable.auto, R.drawable.incandecent, + R.drawable.fluorescent, R.drawable.sunlight, R.drawable.cloudy}; + private static final int[] wbIconsBlue = {R.drawable.auto_blue, R.drawable.incandecent_blue, + R.drawable.fluorescent_blue, R.drawable.sunlight_blue, R.drawable.cloudy_blue}; + private static final int WB_ICON_SIZE = 80; + private PathMeasure mCurveMeasure; + private int mCurveLeft; + private int mCurveRight; + private float mSlider = -1; + private Paint mPaint = new Paint(); + private int mNums; + private int mIndex; + private Point[] mPoints; + private float mClickThreshold; + private int mStride; + private SettingsManager mSettingsManager; + private int mMode = NO_MODE; + private Context mContext; + private ViewGroup mParent; + private float minFocus; + private OneUICameraControls mUI; + private int mWidth; + private int mHeight; + private int mCurveY; + private ArrayList<View> mAddedViews; + private float curveCoordinate[] = new float[2]; + private Path mCurvePath = new Path(); + private int mCurveHeight; + private int mOrientation; + + public ProMode(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + mPaint.setStrokeWidth(7f); + mSettingsManager = SettingsManager.getInstance(); + } + + private void init() { + init(EXPOSURE_MODE); + init(WHITE_BALANCE_MODE); + init(ISO_MODE); + mUI.updateProModeText(MANUAL_MODE, "Manual"); + } + + private void init(int mode) { + String key = getKey(mode); + if (key == null) return; + int index = mSettingsManager.getValueIndex(key); + CharSequence[] cc = mSettingsManager.getEntries(key); + mUI.updateProModeText(mode, cc[index].toString()); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if (mMode != NO_MODE) { + mPaint.setColor(Color.WHITE); + mPaint.setStyle(Paint.Style.STROKE); + canvas.drawPath(mCurvePath, mPaint); + } + mPaint.setStyle(Paint.Style.FILL); + if (mMode == MANUAL_MODE) { + mPaint.setColor(Color.WHITE); + canvas.drawCircle(mCurveLeft, mCurveY, DOT_SIZE, mPaint); + canvas.drawCircle(mCurveRight, mCurveY, DOT_SIZE, mPaint); + mPaint.setColor(BLUE); + if (mSlider >= 0f) { + mCurveMeasure.getPosTan(mCurveMeasure.getLength() * mSlider, curveCoordinate, null); + canvas.drawCircle(curveCoordinate[0], curveCoordinate[1], SELECTED_DOT_SIZE, + mPaint); + } + } else { + for (int i = 0; i < mNums; i++) { + if (i == mIndex) { + mPaint.setColor(BLUE); + canvas.drawCircle(mPoints[i].x, mPoints[i].y, SELECTED_DOT_SIZE, mPaint); + } else { + mPaint.setColor(Color.WHITE); + canvas.drawCircle(mPoints[i].x, mPoints[i].y, DOT_SIZE, mPaint); + } + } + } + } + + public void initialize(OneUICameraControls ui) { + mParent = (ViewGroup) getParent(); + mUI = ui; + init(); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + mWidth = right - left; + mHeight = bottom - top; + mCurveLeft = mWidth / 10; + mCurveRight = mWidth - mCurveLeft; + mCurveHeight = mWidth / 7; + mCurveY = (int) (mHeight * 0.67); + + float cx = (mCurveLeft + mCurveRight) / 2; + mCurvePath.moveTo(mCurveLeft, mCurveY); + mCurvePath.quadTo(cx, mCurveY - mCurveHeight, mCurveRight, mCurveY); + mCurveMeasure = new PathMeasure(mCurvePath, false); + } + + public void setOrientation(int orientation) { + mOrientation = orientation; + if (mAddedViews != null) { + int rotation = mOrientation; + if (rotation == 90 || rotation == 270) rotation += 180; + rotation %= 360; + for (View v : mAddedViews) { + v.setRotation(rotation); + } + } + } + + public int getMode() { + return mMode; + } + + public void setMode(int mode) { + mMode = mode; + removeViews(); + if (mMode == NO_MODE) { + setVisibility(INVISIBLE); + return; + } else { + setVisibility(VISIBLE); + } + mIndex = -1; + String key = currentKey(); + if (mMode == MANUAL_MODE) { + minFocus = mSettingsManager + .getMinimumFocusDistance(mSettingsManager.getCurrentCameraId()); + float value = 0.5f; + setSlider(value); + int stride = mCurveRight - mCurveLeft; + for (int i = 0; i < 2; i++) { + TextView v = new TextView(mContext); + String s = "infinity"; + if (i == 1) s = "macro"; + v.setText(s); + v.setTextColor(Color.WHITE); + v.measure(0, 0); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(v.getMeasuredWidth(), + v.getMeasuredHeight()); + v.setLayoutParams(lp); + v.setX(mCurveLeft + i * stride - v.getMeasuredWidth() / 2); + v.setY(mCurveY - 2 * v.getMeasuredHeight()); + mParent.addView(v); + mAddedViews.add(v); + } + } else { + if (key == null) return; + CharSequence[] cc = mSettingsManager.getEntries(key); + int length = mSettingsManager.getEntryValues(key).length; + int index = mSettingsManager.getValueIndex(key); + updateSlider(length); + + for (int i = 0; i < length; i++) { + View v; + if (mMode == WHITE_BALANCE_MODE) { + v = new ImageView(mContext); + ((ImageView) v).setImageResource(wbIcons[i]); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams( + WB_ICON_SIZE, WB_ICON_SIZE); + v.setLayoutParams(lp); + v.setX(mPoints[i].x - WB_ICON_SIZE / 2); + v.setY(mPoints[i].y - 2 * WB_ICON_SIZE); + } else { + v = new TextView(mContext); + ((TextView) v).setText(cc[i]); + ((TextView) v).setTextColor(Color.WHITE); + v.measure(0, 0); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(v.getMeasuredWidth(), + v.getMeasuredHeight()); + v.setLayoutParams(lp); + v.setX(mPoints[i].x - v.getMeasuredWidth() / 2); + v.setY(mPoints[i].y - 2 * v.getMeasuredHeight()); + } + + + mParent.addView(v); + mAddedViews.add(v); + } + setIndex(index, true); + } + setOrientation(mOrientation); + } + + private String getKey(int mode) { + switch (mode) { + case EXPOSURE_MODE: + return SettingsManager.KEY_EXPOSURE; + case WHITE_BALANCE_MODE: + return SettingsManager.KEY_WHITE_BALANCE; + case ISO_MODE: + return SettingsManager.KEY_ISO; + } + return null; + } + + private String currentKey() { + return getKey(mMode); + } + + private void updateSlider(int n) { + mNums = n; + mStride = (mCurveRight - mCurveLeft) / (mNums - 1); + mClickThreshold = mStride * 0.45f; + mPoints = new Point[mNums]; + + float slide = 1f / (mNums - 1); + for (int i = 0; i < mNums; i++) { + mCurveMeasure.getPosTan(mCurveMeasure.getLength() * (slide * i), curveCoordinate, null); + mPoints[i] = new Point((int) curveCoordinate[0], (int) curveCoordinate[1]); + } + + invalidate(); + } + + public void setSlider(float slider) { + mSlider = slider; + mSettingsManager.setFocusDistance(mSlider * minFocus); + mUI.updateProModeText(mMode, "Manual"); + invalidate(); + } + + private void setIndex(int index, boolean force) { + if (mIndex == index && !force) return; + if (mIndex != -1) { + View v = mAddedViews.get(mIndex); + if (v instanceof TextView) { + ((TextView) v).setTextColor(Color.WHITE); + } else if (v instanceof ImageView) { + if (mMode == WHITE_BALANCE_MODE) { + ((ImageView) v).setImageResource(wbIcons[mIndex]); + } + } + } + + mIndex = index; + String key = currentKey(); + View v = mAddedViews.get(mIndex); + if (v instanceof TextView) { + ((TextView) v).setTextColor(BLUE); + } else if (v instanceof ImageView) { + if (mMode == WHITE_BALANCE_MODE) { + ((ImageView) v).setImageResource(wbIconsBlue[mIndex]); + } + } + if (key != null) mSettingsManager.setValueIndex(key, mIndex); + CharSequence[] cc = mSettingsManager.getEntries(key); + mUI.updateProModeText(mMode, cc[mIndex].toString()); + invalidate(); + } + + private void removeViews() { + ViewGroup vg = (ViewGroup) getParent(); + if (mAddedViews != null) { + for (int i = 0; i < mAddedViews.size(); i++) { + vg.removeView(mAddedViews.get(i)); + } + } + mAddedViews = new ArrayList<View>(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (mMode == MANUAL_MODE) { + float slider = getSlider(event.getX(), event.getY()); + if (slider >= 0) { + setSlider(slider); + } + } else { + int idx = findButton(event.getX(), event.getY()); + if (idx != -1) { + setIndex(idx, false); + } + return true; + } + return true; + } + + private int findButton(float x, float y) { + for (int i = 0; i < mNums; i++) { + float xdiff = Math.abs(mPoints[i].x - x); + float ydiff = Math.abs(mPoints[i].y - y); + float dist = xdiff * xdiff + ydiff * ydiff; + if (dist < mClickThreshold * mClickThreshold) return i; + } + return -1; + } + + private float getSlider(float x, float y) { + if (x > mCurveLeft - DRAG_X_THRESHOLD && x < mCurveRight + DRAG_X_THRESHOLD + && y > mCurveY - mCurveHeight - DRAG_Y_THRESHOLD + && y < mCurveY + DRAG_Y_THRESHOLD) { + if (x < mCurveLeft) x = mCurveLeft; + if (x > mCurveRight) x = mCurveRight; + return (x - mCurveLeft) / (mCurveRight - mCurveLeft); + } else { + return -1; + } + } + +} |