diff options
Diffstat (limited to 'java/com/android/dialer/callcomposer/cameraui')
12 files changed, 313 insertions, 0 deletions
diff --git a/java/com/android/dialer/callcomposer/cameraui/AndroidManifest.xml b/java/com/android/dialer/callcomposer/cameraui/AndroidManifest.xml new file mode 100644 index 000000000..12694ee5f --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/AndroidManifest.xml @@ -0,0 +1,16 @@ +<!-- + ~ Copyright (C) 2016 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<manifest package="com.android.dialer.callcomposer.cameraui"/>
\ No newline at end of file diff --git a/java/com/android/dialer/callcomposer/cameraui/CameraMediaChooserView.java b/java/com/android/dialer/callcomposer/cameraui/CameraMediaChooserView.java new file mode 100644 index 000000000..85c64e477 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/CameraMediaChooserView.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.callcomposer.cameraui; + +import android.content.Context; +import android.graphics.Canvas; +import android.hardware.Camera; +import android.os.Bundle; +import android.os.Parcelable; +import android.util.AttributeSet; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import com.android.dialer.callcomposer.camera.CameraManager; +import com.android.dialer.callcomposer.camera.HardwareCameraPreview; +import com.android.dialer.callcomposer.camera.SoftwareCameraPreview; +import com.android.dialer.common.LogUtil; + +/** Used to display the view of the camera. */ +public class CameraMediaChooserView extends FrameLayout { + private static final String STATE_CAMERA_INDEX = "camera_index"; + private static final String STATE_SUPER = "super"; + + // True if we have at least queued an update to the view tree to support software rendering + // fallback + private boolean mIsSoftwareFallbackActive; + + public CameraMediaChooserView(final Context context, final AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected Parcelable onSaveInstanceState() { + final Bundle bundle = new Bundle(); + bundle.putParcelable(STATE_SUPER, super.onSaveInstanceState()); + final int cameraIndex = CameraManager.get().getCameraIndex(); + LogUtil.i("CameraMediaChooserView.onSaveInstanceState", "saving camera index:" + cameraIndex); + bundle.putInt(STATE_CAMERA_INDEX, cameraIndex); + return bundle; + } + + @Override + protected void onRestoreInstanceState(final Parcelable state) { + if (!(state instanceof Bundle)) { + return; + } + + final Bundle bundle = (Bundle) state; + final int cameraIndex = bundle.getInt(STATE_CAMERA_INDEX); + super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER)); + + LogUtil.i( + "CameraMediaChooserView.onRestoreInstanceState", "restoring camera index:" + cameraIndex); + if (cameraIndex != -1) { + CameraManager.get().selectCameraByIndex(cameraIndex); + } else { + resetState(); + } + } + + public void resetState() { + CameraManager.get().selectCamera(Camera.CameraInfo.CAMERA_FACING_BACK); + } + + @Override + protected void onDraw(final Canvas canvas) { + super.onDraw(canvas); + // If the canvas isn't hardware accelerated, we have to replace the HardwareCameraPreview + // with a SoftwareCameraPreview which supports software rendering + if (!canvas.isHardwareAccelerated() && !mIsSoftwareFallbackActive) { + mIsSoftwareFallbackActive = true; + // Post modifying the tree since we can't modify the view tree during a draw pass + post( + new Runnable() { + @Override + public void run() { + final HardwareCameraPreview cameraPreview = + (HardwareCameraPreview) findViewById(R.id.camera_preview); + if (cameraPreview == null) { + return; + } + final ViewGroup parent = ((ViewGroup) cameraPreview.getParent()); + final int index = parent.indexOfChild(cameraPreview); + final SoftwareCameraPreview softwareCameraPreview = + new SoftwareCameraPreview(getContext()); + // Be sure to remove the hardware view before adding the software view to + // prevent having 2 camera previews active at the same time + parent.removeView(cameraPreview); + parent.addView(softwareCameraPreview, index); + } + }); + } + } +} diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable-hdpi/ic_capture.png b/java/com/android/dialer/callcomposer/cameraui/res/drawable-hdpi/ic_capture.png Binary files differnew file mode 100644 index 000000000..b974c9f70 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable-hdpi/ic_capture.png diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable-mdpi/ic_capture.png b/java/com/android/dialer/callcomposer/cameraui/res/drawable-mdpi/ic_capture.png Binary files differnew file mode 100644 index 000000000..98427587b --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable-mdpi/ic_capture.png diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable-xhdpi/ic_capture.png b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xhdpi/ic_capture.png Binary files differnew file mode 100644 index 000000000..4ec9f75e8 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xhdpi/ic_capture.png diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxhdpi/ic_capture.png b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxhdpi/ic_capture.png Binary files differnew file mode 100644 index 000000000..e2345dc86 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxhdpi/ic_capture.png diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxxhdpi/ic_capture.png b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxxhdpi/ic_capture.png Binary files differnew file mode 100644 index 000000000..3bab00984 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable-xxxhdpi/ic_capture.png diff --git a/java/com/android/dialer/callcomposer/cameraui/res/drawable/transparent_button_background.xml b/java/com/android/dialer/callcomposer/cameraui/res/drawable/transparent_button_background.xml new file mode 100644 index 000000000..fda52c99c --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/drawable/transparent_button_background.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2016 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:drawable="@color/background_item_grey_pressed" + android:state_pressed="true"/> + <item + android:drawable="@color/background_item_grey_pressed" + android:state_activated="true"/> + <item + android:drawable="@android:color/transparent"/> +</selector>
\ No newline at end of file diff --git a/java/com/android/dialer/callcomposer/cameraui/res/layout/camera_view.xml b/java/com/android/dialer/callcomposer/cameraui/res/layout/camera_view.xml new file mode 100644 index 000000000..75401b14b --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/layout/camera_view.xml @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2016 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<com.android.dialer.callcomposer.cameraui.CameraMediaChooserView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/camera_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/black"> + + <FrameLayout + android:id="@+id/mediapicker_enabled" + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <!-- Default to using the hardware rendered camera preview, we will fall back to + SoftwareCameraPreview in CameraMediaChooserView if needed --> + <com.android.dialer.callcomposer.camera.HardwareCameraPreview + android:id="@+id/camera_preview" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" /> + + <com.android.dialer.callcomposer.camera.camerafocus.RenderOverlay + android:id="@+id/focus_visual" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <View + android:id="@+id/camera_shutter_visual" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/white" + android:visibility="gone" /> + + <!-- Need a background on this view in order for the ripple effect to have a place to draw --> + <FrameLayout + android:id="@+id/camera_button_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/transparent" + android:padding="16dp" + android:layout_gravity="bottom"> + + <ImageButton + android:id="@+id/camera_fullscreen" + android:layout_width="@dimen/camera_view_button_size" + android:layout_height="@dimen/camera_view_button_size" + android:layout_gravity="bottom|end" + android:layout_marginEnd="@dimen/camera_view_button_margin" + android:layout_marginBottom="@dimen/camera_view_button_margin" + android:src="@drawable/quantum_ic_fullscreen_white_48" + android:background="?android:selectableItemBackgroundBorderless"/> + + <ImageButton + android:id="@+id/camera_exit_fullscreen" + android:layout_width="@dimen/camera_view_button_size" + android:layout_height="@dimen/camera_view_button_size" + android:layout_gravity="bottom|end" + android:layout_marginEnd="@dimen/camera_view_button_margin" + android:layout_marginBottom="@dimen/camera_view_button_margin" + android:src="@drawable/quantum_ic_fullscreen_exit_white_48" + android:visibility="gone" + android:background="?android:selectableItemBackgroundBorderless"/> + + <ImageButton + android:id="@+id/camera_capture_button" + android:layout_width="@dimen/capture_button_size" + android:layout_height="@dimen/capture_button_size" + android:layout_gravity="bottom|center_horizontal" + android:layout_marginBottom="@dimen/capture_button_bottom_margin" + android:background="?android:selectableItemBackgroundBorderless" + android:src="@drawable/ic_capture" + android:scaleType="fitXY" + android:contentDescription="@string/camera_take_picture"/> + + <ImageButton + android:id="@+id/swap_camera_button" + android:layout_width="@dimen/camera_view_button_size" + android:layout_height="@dimen/camera_view_button_size" + android:layout_gravity="start|bottom" + android:layout_marginStart="@dimen/camera_view_button_margin" + android:layout_marginBottom="@dimen/camera_view_button_margin" + android:src="@drawable/front_back_switch_button_animation" + android:background="@drawable/transparent_button_background" + android:contentDescription="@string/camera_switch_camera_rear"/> + + <ImageButton + android:id="@+id/camera_cancel_button" + android:layout_width="@dimen/camera_view_button_size" + android:layout_height="@dimen/camera_view_button_size" + android:layout_gravity="start|bottom" + android:layout_marginStart="@dimen/camera_view_button_margin" + android:layout_marginBottom="@dimen/camera_view_button_margin" + android:visibility="gone" + android:background="@drawable/transparent_button_background" + android:src="@drawable/quantum_ic_undo_white_48" + android:contentDescription="@string/camera_cancel_recording" /> + </FrameLayout> + </FrameLayout> + + <ProgressBar + android:id="@+id/loading" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:visibility="gone"/> +</com.android.dialer.callcomposer.cameraui.CameraMediaChooserView>
\ No newline at end of file diff --git a/java/com/android/dialer/callcomposer/cameraui/res/values/colors.xml b/java/com/android/dialer/callcomposer/cameraui/res/values/colors.xml new file mode 100644 index 000000000..d5a839aca --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/values/colors.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="background_item_grey_pressed">#E0E0E0</color> +</resources>
\ No newline at end of file diff --git a/java/com/android/dialer/callcomposer/cameraui/res/values/dimens.xml b/java/com/android/dialer/callcomposer/cameraui/res/values/dimens.xml new file mode 100644 index 000000000..09d4a58fd --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/values/dimens.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2016 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<resources> + <dimen name="camera_view_button_margin">22dp</dimen> + <dimen name="camera_view_button_size">46dp</dimen> + <dimen name="capture_button_size">84dp</dimen> + <dimen name="capture_button_bottom_margin">4dp</dimen> +</resources>
\ No newline at end of file diff --git a/java/com/android/dialer/callcomposer/cameraui/res/values/strings.xml b/java/com/android/dialer/callcomposer/cameraui/res/values/strings.xml new file mode 100644 index 000000000..999fe8f96 --- /dev/null +++ b/java/com/android/dialer/callcomposer/cameraui/res/values/strings.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <!-- Content description of button to switch to full screen camera --> + <string name="camera_switch_full_screen">Switch to full screen camera</string> + <!-- Content description of button when after swapped to front --> + <string name="camera_switch_camera_facing">Button is now front camera</string> + <!-- Content description of button when after swapped to back --> + <string name="camera_switch_camera_rear">Button is now back camera</string> + <!-- Content description of button to cancel recording video --> + <string name="camera_cancel_recording">Stop recording video</string> + <!-- Accessibility announcement for when we are using the front facing camera --> + <string name="using_front_camera">Using front camera</string> + <!-- Accessibility announcement for when we are using the back camera --> + <string name="using_back_camera">Using back camera</string> + <!-- Content description of button to take a photo --> + <string name="camera_take_picture">Take photo</string> +</resources>
\ No newline at end of file |