Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
Changed Camera2Sample UI to indicate camera/video mode change (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
idzkowski-google authored Feb 21, 2020
1 parent 8948932 commit 0da8724
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.glass.camera2sample;

import android.content.Context;
import android.graphics.drawable.TransitionDrawable;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

Expand All @@ -36,6 +37,11 @@ public class AnimationManager {
*/
private static final float ALPHA_MAX = 0.8F;

/**
* Transition duration in milliseconds,
*/
private static final int TRANSITION_DURATION_MS = 200;

/**
* Animates shutter action on the given {@link ImageView}.
*/
Expand All @@ -55,4 +61,19 @@ public void run() {
}
});
}

/**
* Performs transition on the image background to change highlight of a given {@link ImageView}.
*
* @param reverse true means reverse transition.
*/
public static void changeBackgroundDrawable(final ImageView imageView, final boolean reverse) {
final TransitionDrawable transitionDrawable = (TransitionDrawable) imageView.getBackground();

if (reverse) {
transitionDrawable.reverseTransition(TRANSITION_DURATION_MS);
} else {
transitionDrawable.startTransition(TRANSITION_DURATION_MS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.example.glass.camera2sample.CameraActionHandler.CameraActionHandlerCallback;
import com.example.glass.camera2sample.CameraActionHandler.CameraMode;
import com.example.glass.ui.GlassGestureDetector;

import java.util.Objects;

/**
* Fragment responsible for displaying the camera preview and handling camera actions.
*/
public class CameraFragment extends Fragment
implements OnRequestPermissionsResultCallback, GlassGestureDetector.OnGestureListener, CameraActionHandlerCallback {
implements OnRequestPermissionsResultCallback, GlassGestureDetector.OnGestureListener,
CameraActionHandlerCallback {

private static final String TAG = CameraFragment.class.getSimpleName();

Expand Down Expand Up @@ -77,6 +74,11 @@ public class CameraFragment extends Fragment
*/
private ImageView shutterImageView;

/**
* An {@link ImageView} for video cam image.
*/
private ImageView videoImageView;

/**
* {@link CameraActionHandler} for the camera.
*/
Expand Down Expand Up @@ -120,21 +122,15 @@ public void onSurfaceTextureUpdated(SurfaceTexture texture) {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final FrameLayout frameLayout = new FrameLayout(
Objects.requireNonNull(getContext(), "Context must not be null"));
textureView = new TextureView(getContext());
frameLayout.addView(textureView);

shutterImageView = new ImageView(getContext());
shutterImageView.setImageResource(R.drawable.ic_camera_white_96dp);

final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
layoutParams.setMarginEnd(DEFAULT_MARGIN_PX);
shutterImageView.setLayoutParams(layoutParams);
frameLayout.addView(shutterImageView);
return frameLayout;
return inflater.inflate(R.layout.camera_layout, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
textureView = view.findViewById(R.id.cameraTextureView);
shutterImageView = view.findViewById(R.id.cameraImageView);
videoImageView = view.findViewById(R.id.videoImageView);
}

@Override
Expand Down Expand Up @@ -252,24 +248,26 @@ public void onTakingPictureStarted() {
@Override
public void onVideoRecordingStarted() {
Log.d(TAG, "Video recording started");
AnimationManager.changeImageByAlpha(shutterImageView, R.drawable.ic_videocam_red_96dp);
AnimationManager.changeImageByAlpha(videoImageView, R.drawable.ic_videocam_red);
}

@Override
public void onVideoRecordingStopped() {
Log.d(TAG, "Video recording stopped");
AnimationManager.changeImageByAlpha(shutterImageView, R.drawable.ic_videocam_white_96dp);
AnimationManager.changeImageByAlpha(videoImageView, R.drawable.ic_videocam_white);
}

@Override
public void onCameraModeChanged(CameraMode newCameraMode) {
Log.d(TAG, "Camera mode changed to " + newCameraMode.name());
switch (newCameraMode) {
case VIDEO:
AnimationManager.changeImageByAlpha(shutterImageView, R.drawable.ic_videocam_white_96dp);
AnimationManager.changeBackgroundDrawable(shutterImageView, false);
AnimationManager.changeBackgroundDrawable(videoImageView, false);
break;
case PICTURE:
AnimationManager.changeImageByAlpha(shutterImageView, R.drawable.ic_camera_white_96dp);
AnimationManager.changeBackgroundDrawable(videoImageView, true);
AnimationManager.changeBackgroundDrawable(shutterImageView, true);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="96dp"
android:height="96dp"
android:alpha="0.8"
android:width="@dimen/icon_size"
android:height="@dimen/icon_size"
android:tint="#FFFFFF"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="96dp"
android:height="96dp"
android:alpha="0.8"
android:width="@dimen/icon_size"
android:height="@dimen/icon_size"
android:tint="#DD4B39"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="96dp"
android:height="96dp"
android:alpha="0.8"
android:width="@dimen/icon_size"
android:height="@dimen/icon_size"
android:tint="#FFFFFF"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
Expand Down
23 changes: 23 additions & 0 deletions Camera2Sample/app/src/main/res/drawable/icon_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@android:color/black" />
</shape>
</item>
</layer-list>
20 changes: 20 additions & 0 deletions Camera2Sample/app/src/main/res/drawable/recording_transition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_videocam_white" />
<item android:drawable="@drawable/ic_videocam_red" />
</transition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/ic_launcher_background" />
</shape>
</item>
</layer-list>
20 changes: 20 additions & 0 deletions Camera2Sample/app/src/main/res/drawable/shutter_transition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/selected_icon_background" />
<item android:drawable="@drawable/icon_background" />
</transition>
20 changes: 20 additions & 0 deletions Camera2Sample/app/src/main/res/drawable/video_transition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_background" />
<item android:drawable="@drawable/selected_icon_background" />
</transition>
45 changes: 45 additions & 0 deletions Camera2Sample/app/src/main/res/layout/camera_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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.
-->
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextureView
android:id="@+id/cameraTextureView"
style="@style/CameraPreviewStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/cameraImageView"
style="@style/ShutterIconStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/videoImageView"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />

<ImageView
android:id="@+id/videoImageView"
style="@style/VideoIconStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/cameraImageView" />

</android.support.constraint.ConstraintLayout>
21 changes: 21 additions & 0 deletions Camera2Sample/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Google LLC
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="icon_size">48dp</dimen>
<dimen name="icon_margin">16dp</dimen>
<dimen name="icon_padding">8dp</dimen>
</resources>
Loading

0 comments on commit 0da8724

Please sign in to comment.