summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Menu3DTest.java
blob: c0adc6a4094b219d0382861f8573dd31bc2281e4 (plain)
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
package com.android.camera;

import android.app.Activity;
import android.os.Bundle;
import android.view.OrientationEventListener;
import android.widget.FrameLayout;

import com.android.camera.ui.GLRootView;
import com.android.camera.ui.HeadUpDisplay;

public class Menu3DTest extends Activity {

    private static String TAG = "Menu3DTest";

    private GLRootView mRootView;
    private OrientationEventListener mOrientationListener;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        mRootView = new GLRootView(this);

        // set background as 18% gray :D
        mRootView.setBackgroundColor(0xffb7b7b7);
        final HeadUpDisplay hud = new HeadUpDisplay(this);
        mRootView.setContentPane(hud);

        PreferenceInflater inflater = new PreferenceInflater(this);
        PreferenceGroup preferenceGroup =
                (PreferenceGroup) inflater.inflate(R.xml.camera_preferences);
        hud.initialize(this, preferenceGroup);
        hud.overrideSettings(CameraSettings.KEY_FOCUS_MODE, "macro");

        setContentView(mRootView);

        mOrientationListener = new OrientationEventListener(this) {
            private int mLastOrientation = -1;
            @Override
            public void onOrientationChanged(int orientation) {
                // We keep the last known orientation. So if the user
                // first orient the camera then point the camera to
                if (orientation != ORIENTATION_UNKNOWN) {
                    orientation += 90;
                }
                final int finalOrientation =
                        ImageManager.roundOrientation(orientation);
                if (mLastOrientation != finalOrientation) {
                    mLastOrientation = finalOrientation;
                    mRootView.queueEvent(new Runnable() {
                        public void run() {
                            hud.setOrientation(finalOrientation);
                        }
                    });
                }
            }
        };
    }

    @Override
    public void onResume() {
        super.onResume();
        mRootView.onResume();
        mOrientationListener.enable();
    }

    @Override
    public void onPause() {
        super.onPause();
        mRootView.onPause();
        mOrientationListener.disable();
    }

    @Override
    protected void onDestroy() {
        mRootView = null;
        setContentView(new FrameLayout(this));
        super.onDestroy();
    }
}