Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/cardboard/MenuBar.java

Issue 2252123002: [Remoting Android] Remove Cardboard Code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback - Removed unused const and strings Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chromoting.cardboard;
6
7 import android.content.Context;
8 import android.graphics.PointF;
9 import android.graphics.RectF;
10 import android.opengl.Matrix;
11
12 import org.chromium.chromoting.R;
13
14 /**
15 * Cardboard activity menu bar that contains multiple menu items.
16 */
17 public class MenuBar {
18 public enum MenuItemType {
19 BACK(R.drawable.ic_backspace),
20 VOICE_INPUT(R.drawable.ic_voice_input),
21 ZOOM_IN(R.drawable.ic_zoom_in),
22 ZOOM_OUT(R.drawable.ic_zoom_out);
23
24 private final int mResourceId;
25
26 MenuItemType(int resourceId) {
27 mResourceId = resourceId;
28 }
29
30 public int resourceId() {
31 return mResourceId;
32 }
33 }
34
35 public static final float MENU_ITEM_SIZE = 0.1f;
36
37 private final RectF mMenuBarRect;
38
39 private final MenuItem[] mItems;
40
41 private float[] mModelMatrix;
42 private float[] mCombinedMatrix;
43
44 public MenuBar(Context context) {
45 MenuItemType[] menuItemTypes = MenuItemType.values();
46 final int numItem = menuItemTypes.length;
47 mCombinedMatrix = new float[16];
48 mModelMatrix = new float[16];
49
50 final float halfMenuWidth = numItem * MENU_ITEM_SIZE / 2;
51 final float halfMenuHeight = MENU_ITEM_SIZE / 2;
52 mMenuBarRect = new RectF(-halfMenuWidth, -halfMenuHeight, halfMenuWidth, halfMenuHeight);
53
54 RectF currentRect = new RectF(-halfMenuWidth, -halfMenuHeight,
55 -halfMenuWidth + MENU_ITEM_SIZE, halfMenuHeight);
56 mItems = new MenuItem[numItem];
57 for (int i = 0; i < numItem; i++) {
58 mItems[i] = new MenuItem(context, menuItemTypes[i], currentRect);
59 currentRect.offset(MENU_ITEM_SIZE, 0);
60 }
61 }
62
63 /**
64 * Get menu item that user is looking at.
65 * Return the CardboardActivity menu item that contains the passed in coordi nates or
66 * null if none of menu items contains the passed in coordinates.
67 */
68 public MenuItem getLookingItem(PointF lookingPosition) {
69 for (MenuItem item : mItems) {
70 if (item.contains(lookingPosition)) {
71 return item;
72 }
73 }
74
75 return null;
76 }
77
78 public void draw(float[] viewMatrix, float[] projectionMatrix, PointF eyeMen uBarPosition,
79 float centerX, float centerY, float centerZ) {
80 for (MenuItem item : mItems) {
81 Matrix.setIdentityM(mModelMatrix, 0);
82 Matrix.translateM(mModelMatrix, 0, item.getPosition().x + centerX,
83 item.getPosition().y + centerY, centerZ);
84 Matrix.multiplyMM(mCombinedMatrix, 0, viewMatrix, 0, mModelMatrix, 0 );
85 Matrix.multiplyMM(mCombinedMatrix, 0, projectionMatrix, 0, mCombined Matrix, 0);
86 item.draw(mCombinedMatrix, item.contains(eyeMenuBarPosition));
87 }
88 }
89
90 /**
91 * Return true if the passed in point is inside the menu bar.
92 * @param x x coordinate user is looking at.
93 * @param y y coordinate user is looking at.
94 */
95 public boolean contains(PointF lookingPosition) {
96 return mMenuBarRect.contains(lookingPosition.x, lookingPosition.y);
97 }
98
99 /**
100 * Clean up opengl data.
101 */
102 public void cleanup() {
103 for (MenuItem item : mItems) {
104 item.clean();
105 }
106 }
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698