xie
2024-11-23 3fdfdea0721fe7a36f6aaa509075f01a194f6748
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * 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.camera.one;
 
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
 
/**
 * A common abstract {@link OneCamera} implementation that contains some utility
 * functions and plumbing we don't want every sub-class of {@link OneCamera} to
 * duplicate. Hence all {@link OneCamera} implementations should sub-class this
 * class instead.
 */
public abstract class AbstractOneCamera implements OneCamera {
    protected FocusStateListener mFocusStateListener;
    protected ReadyStateChangedListener mReadyStateChangedListener;
    protected FocusDistanceListener mFocusDistanceListener;
 
    /**
     * Number of characters from the end of the device serial number used to
     * construct folder names for debugging output.
     */
    static final int DEBUG_FOLDER_SERIAL_LENGTH = 4;
 
    @Override
    public final void setFocusStateListener(FocusStateListener listener) {
        mFocusStateListener = listener;
    }
 
    @Override
    public void setFocusDistanceListener(FocusDistanceListener listener) {
        mFocusDistanceListener = listener;
    }
 
    @Override
    public void setReadyStateChangedListener(ReadyStateChangedListener listener) {
        mReadyStateChangedListener = listener;
    }
 
    /**
     * Create a directory we can use to store debugging information during Gcam
     * captures.
     * <br />
     * The directory created is [root]/[folderName]/SSSS_YYYYMMDD_HHMMSS_XXX,
     * where 'SSSS' are the last 'DEBUG_FOLDER_SERIAL_LENGTH' digits of the
     * devices serial number, and 'XXX' are milliseconds of the timestamp.
     *
     * @param root the root into which we put a session-specific sub-directory.
     * @param folderName the sub-folder within 'root' where the data should be
     *            put.
     * @return The session-specific directory (absolute path) into which to
     *         store debug information.
     */
    protected static String makeDebugDir(File root, String folderName) {
        if (root == null) {
            return null;
        }
        if (!root.exists() || !root.isDirectory()) {
            throw new RuntimeException("Gcam debug directory not valid or doesn't exist: "
                    + root.getAbsolutePath());
        }
 
        String serialSubstring = "";
        String serial = android.os.Build.SERIAL;
        if (serial != null) {
            int length = serial.length();
 
            if (length > DEBUG_FOLDER_SERIAL_LENGTH) {
                serialSubstring = serial.substring(length - DEBUG_FOLDER_SERIAL_LENGTH, length);
            } else {
                serialSubstring = serial;
            }
        }
 
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
        simpleDateFormat.setTimeZone(TimeZone.getDefault());
        String currentDateAndTime = simpleDateFormat.format(new Date());
 
        String burstFolderName = String.format("%s_%s", serialSubstring, currentDateAndTime);
        File destFolder = new File(new File(root, folderName), burstFolderName);
        if (!destFolder.mkdirs()) {
            throw new RuntimeException("Could not create Gcam debug data folder.");
        }
        String destFolderPath = destFolder.getAbsolutePath();
        return destFolderPath;
    }
 
    /**
     * If set, tells the ready state changed listener the new state.
     */
    protected void broadcastReadyState(boolean readyForCapture) {
        if (mReadyStateChangedListener != null) {
            mReadyStateChangedListener.onReadyStateChanged(readyForCapture);
        }
    }
 
    @Override
    public float getMaxZoom() {
        // If not implemented, return 1.0.
        return 1f;
    }
 
    @Override
    public void setZoom(float zoom) {
        // If not implemented, no-op.
    }
}