ArViewer  Android Version
Arvos - Augmented reality viewer open source
 All Classes Namespaces Files Functions Variables
Arvos.java
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013, Peter Graf
3 
4  This file is part of Arvos - AR Viewer Open Source for Android.
5  Arvos is free software.
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20  For more information on the AR Viewer Open Source or Peter Graf,
21  please see: http://www.mission-base.com/.
22  */
23 
24 package com.mission_base.arviewer_android;
25 
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
30 
31 import android.annotation.SuppressLint;
32 import android.app.Activity;
33 import android.content.Intent;
34 import android.hardware.SensorManager;
35 import android.view.OrientationEventListener;
36 
37 import com.mission_base.arviewer_android.viewer.Augment;
38 import com.mission_base.arviewer_android.viewer.WebViewer;
39 import com.mission_base.arviewer_android.viewer.opengl.ArvosObject;
40 
48 @SuppressLint("UseSparseArrays")
49 public class Arvos
50 {
51  public boolean mSimulateWeb = true;
52 
53  public boolean mUseCache = true;
54  public boolean mIsAuthor = false;
55  public String mAuthorKey;
56  public String mDeveloperKey;
57 
58  private static String mLock = "Lock";
59  private static Arvos mInstance = null;
60 
61  private Activity mActivity;
62  private OrientationEventListener mListener;
63  private int mOrientation = 0;
64 
65  public String mSessionId;
66  public float mLongitude = -1000f;
67  public float mLatitude = -1000f;
68  public int mVersion = 1;
69 
70  public Augment mAugment;
71  public String mAugmentsUrl = "http://www.mission-base.com/arvos/augments.json";
72 
73  public float mAzimuth = 0;
74  public float mCorrectedAzimuth = 0;
75  public float mPitch = 0;
76  public float mRoll = 0;
77  public long mFPS = 0;
78 
79  public int mWidth;
80  public int mHeight;
81  public volatile boolean mHandleTouch = false;
82  public volatile boolean mModelViewMatrixesRequested = false;
83 
87  public float[] mProjectionMatrix = null;
88 
92  public final HashMap<Integer, float[]> mModelViewMatrixes = new HashMap<Integer, float[]>();
93 
100  public final List<ArvosObject> mArvosObjects = Collections.synchronizedList(new LinkedList<ArvosObject>());
101 
102  private Arvos()
103  {
104  }
105 
111  public static Arvos getInstance()
112  {
113  if (mInstance == null)
114  {
115  synchronized (mLock)
116  {
117  if (mInstance == null)
118  {
119  mInstance = new Arvos();
120  }
121  }
122  }
123  return mInstance;
124  }
125 
133  public static Arvos getInstance(Activity activity)
134  {
135  getInstance();
136  if (activity != null)
137  {
138  mInstance.setActivity(activity);
139  }
140  return mInstance;
141  }
142 
148  public Activity getActivity()
149  {
150  return mActivity;
151  }
152 
153  private void setActivity(Activity activity)
154  {
155  mActivity = activity;
156  if (mActivity != null && mListener == null)
157  {
158  mListener = new OrientationEventListener(mActivity, SensorManager.SENSOR_DELAY_UI)
159  {
160  public void onOrientationChanged(int orientation)
161  {
162  if (orientation == ORIENTATION_UNKNOWN)
163  {
164  mOrientation = 0;
165  }
166  else
167  {
168  mOrientation = orientation;
169  }
170  }
171  };
172  }
173  }
174 
180  public int getOrientation()
181  {
182  return mOrientation;
183  }
184 
192  public int getRotationDegrees()
193  {
194  int degrees = 0;
195  if (mOrientation < 45)
196  {
197  degrees = 0;
198  }
199  else if (mOrientation < 135)
200  {
201  degrees = 270;
202  }
203  else if (mOrientation < 225)
204  {
205  degrees = 180;
206  }
207  else if (mOrientation < 315)
208  {
209  degrees = 90;
210  }
211  return degrees;
212  }
213 
214  public void onResume()
215  {
216  mListener.enable();
217  }
218 
219  public void onPause()
220  {
221  mListener.disable();
222  }
223 
224  private static float toDegreesFactor = 180 / 3.14159f;
225 
234  public static float toDegrees(float radians)
235  {
236  return radians * toDegreesFactor;
237  }
238 
239  private static String mMessage;
240 
250  public static void log(String tag, String message)
251  {
252  mMessage = tag + "" + message;
253  getInstance().mActivity.runOnUiThread(new Runnable()
254  {
255  public void run()
256  {
257  getInstance().mActivity.getActionBar().setSubtitle(mMessage);
258  }
259  });
260  }
261 
268  public void startWebViewer(String url)
269  {
270  new ArvosRunnable(url).run();
271  }
272 
273  private class ArvosRunnable extends Thread
274  {
275  private String mUrl;
276 
277  public ArvosRunnable(String url)
278  {
279  mUrl = url;
280  }
281 
282  public void run()
283  {
284  Intent intent = new Intent(Arvos.getInstance().mActivity, WebViewer.class);
285  intent.putExtra("url", mUrl);
286 
287  Arvos.getInstance().mActivity.startActivity(intent);
288  }
289  }
290 }