diff options
author | Sol Boucher <solb@google.com> | 2014-06-09 14:37:08 -0700 |
---|---|---|
committer | Ed Heyl <edheyl@google.com> | 2014-06-18 10:24:45 -0700 |
commit | cef46862d6937bc98bf1a6b087c5daa22b5239f3 (patch) | |
tree | 5c06e89ff81de08f86dfb963cda27648be623dfe /camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java | |
parent | da52dbdc5ffc76c1c875229086e91475eb150090 (diff) | |
download | android_frameworks_ex-cef46862d6937bc98bf1a6b087c5daa22b5239f3.tar.gz android_frameworks_ex-cef46862d6937bc98bf1a6b087c5daa22b5239f3.tar.bz2 android_frameworks_ex-cef46862d6937bc98bf1a6b087c5daa22b5239f3.zip |
Refactor CameraManager hierarchy to support new implementations
This relocates several components of the implementation class
AndroidCameraManagerImpl to higher levels in the inheritence hierarchy, where
they can be reused by other implementations of the CameraManager interface:
- AndroidCameraManager.DispatchThread is moved into its own file
- The core (history-tracking) pieces of CameraManager.CameraHandler are moved
into their own HistoryHandler class, which the former is made to inherit
- The constants defined in AndroidCameraManagerImpl for use in its nested
CameraHandler class are moved into a separate class called CameraActions
- AndroidCameraManagerImpl.CameraStateHolder is moved into its own file
- Those CallbackForward classes that aren't tied to Android's Camera1 API are
moved directly into the CameraManager interface
Change-Id: I5f3e1eb72039a0018ce2277e3ec6289bfa4ccec3
Diffstat (limited to 'camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java')
-rw-r--r-- | camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java b/camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java new file mode 100644 index 0000000..ec2a555 --- /dev/null +++ b/camera2/portability/src/com/android/ex/camera2/portability/HistoryHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 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.ex.camera2.portability; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; + +import java.util.LinkedList; + +class HistoryHandler extends Handler { + private static final int MAX_HISTORY_SIZE = 400; + + final LinkedList<Integer> mMsgHistory; + + HistoryHandler(Looper looper) { + super(looper); + mMsgHistory = new LinkedList<Integer>(); + // We add a -1 at the beginning to mark the very beginning of the + // history. + mMsgHistory.offerLast(-1); + } + + String generateHistoryString(int cameraId) { + String info = new String("HIST"); + info += "_ID" + cameraId; + for (Integer msg : mMsgHistory) { + info = info + '_' + msg.toString(); + } + info += "_HEND"; + return info; + } + + /** + * Subclasses' implementations should call this one before doing their work. + */ + @Override + public void handleMessage(Message msg) { + mMsgHistory.offerLast(msg.what); + while (mMsgHistory.size() > MAX_HISTORY_SIZE) { + mMsgHistory.pollFirst(); + } + } +} |