1/*
2 * Copyright (C) 2013 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
17package com.android.accessorydisplay.source.presentation;
18
19import com.android.accessorydisplay.common.Logger;
20import com.android.accessorydisplay.source.R;
21
22import android.app.Presentation;
23import android.content.Context;
24import android.content.res.Resources;
25import android.opengl.GLSurfaceView;
26import android.os.Bundle;
27import android.view.Display;
28import android.view.MotionEvent;
29import android.view.View;
30import android.widget.Button;
31
32/**
33 * The presentation to show on the accessory display.
34 * <p>
35 * Note that this display may have different metrics from the display on which
36 * the main activity is showing so we must be careful to use the presentation's
37 * own {@link Context} whenever we load resources.
38 * </p>
39 */
40public final class DemoPresentation extends Presentation {
41    private final Logger mLogger;
42
43    private GLSurfaceView mSurfaceView;
44    private CubeRenderer mRenderer;
45    private Button mExplodeButton;
46
47    public DemoPresentation(Context context, Display display, Logger logger) {
48        super(context, display);
49        mLogger = logger;
50    }
51
52    @Override
53    protected void onCreate(Bundle savedInstanceState) {
54        // Be sure to call the super class.
55        super.onCreate(savedInstanceState);
56
57        // Get the resources for the context of the presentation.
58        // Notice that we are getting the resources from the context of the presentation.
59        Resources r = getContext().getResources();
60
61        // Inflate the layout.
62        setContentView(R.layout.presentation_content);
63
64        // Set up the surface view for visual interest.
65        mRenderer = new CubeRenderer(false);
66        mSurfaceView = (GLSurfaceView)findViewById(R.id.surface_view);
67        mSurfaceView.setRenderer(mRenderer);
68
69        // Add a button.
70        mExplodeButton = (Button)findViewById(R.id.explode_button);
71        mExplodeButton.setOnClickListener(new View.OnClickListener() {
72            @Override
73            public void onClick(View v) {
74                mRenderer.explode();
75            }
76        });
77    }
78
79    @Override
80    public boolean onTouchEvent(MotionEvent event) {
81        mLogger.log("Received touch event: " + event);
82        return super.onTouchEvent(event);
83    }
84}