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

Commit ac1499d

Browse files
jbolingerGerrit Code Review
authored and
Gerrit Code Review
committed
Merge changes I23901fe7,I0cde537b
* changes: Added functionality of recording and storing videos to the Camera2Sample application Added functionality of taking and storing pictures to the Camera2Sample application
2 parents 5166642 + b67368b commit ac1499d

13 files changed

+1367
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.glass.camera2sample;
18+
19+
import android.content.Context;
20+
import android.view.animation.AnimationUtils;
21+
import android.widget.ImageView;
22+
23+
/**
24+
* Helper class responsible for performing animations on the camera shutter during taking pictures
25+
* and changing shutter icon to the camera icon and vice versa, depends on the current camera mode.
26+
*/
27+
public class AnimationManager {
28+
29+
/**
30+
* Minimum alpha for animations.
31+
*/
32+
private static final float ALPHA_MIN = 0F;
33+
34+
/**
35+
* Maximum alpha for animations.
36+
*/
37+
private static final float ALPHA_MAX = 0.8F;
38+
39+
/**
40+
* Animates shutter action on the given {@link ImageView}.
41+
*/
42+
public static void animateShutter(Context context, ImageView imageView) {
43+
imageView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.alpha));
44+
}
45+
46+
/**
47+
* Changes given {@link ImageView} image resource by the animation using alpha.
48+
*/
49+
public static void changeImageByAlpha(final ImageView imageView, final int resource) {
50+
imageView.animate().alpha(ALPHA_MIN).withEndAction(new Runnable() {
51+
@Override
52+
public void run() {
53+
imageView.setImageResource(resource);
54+
imageView.animate().alpha(ALPHA_MAX);
55+
}
56+
});
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.glass.camera2sample;
18+
19+
import android.os.Handler;
20+
import android.os.HandlerThread;
21+
import android.util.Log;
22+
23+
/**
24+
* Helper class responsible for handling the background thread.
25+
*/
26+
public class BackgroundThreadHandler {
27+
28+
private static final String TAG = BackgroundThreadHandler.class.getSimpleName();
29+
30+
private final String threadName;
31+
private HandlerThread handlerThread;
32+
private Handler handler;
33+
34+
/**
35+
* Constructor of this class needs a background thread name to be passed by an argument.
36+
*
37+
* @param threadName of the background thread to handle.
38+
*/
39+
public BackgroundThreadHandler(String threadName) {
40+
this.threadName = threadName;
41+
}
42+
43+
/**
44+
* Starts a background thread and its {@link Handler}.
45+
*/
46+
public void startBackgroundThread() {
47+
Log.d(TAG, "Starting thread " + threadName);
48+
handlerThread = new HandlerThread(threadName);
49+
handlerThread.start();
50+
handler = new Handler(handlerThread.getLooper());
51+
}
52+
53+
/**
54+
* Stops the background thread and its {@link Handler}.
55+
*/
56+
public void stopBackgroundThread() {
57+
Log.d(TAG, "Stopping thread " + threadName);
58+
handlerThread.quitSafely();
59+
try {
60+
handlerThread.join();
61+
handlerThread = null;
62+
handler = null;
63+
} catch (InterruptedException e) {
64+
Log.e(TAG, "Stopping thread " + threadName + " failed", e);
65+
}
66+
}
67+
68+
/**
69+
* Returns {@link Handler} using the background thread.
70+
*/
71+
public Handler getHandler() {
72+
return handler;
73+
}
74+
}

0 commit comments

Comments
 (0)