MaxstARSDK  3.5.0
All Classes Functions Variables
WearableCalibration.java
1 /*
2  * Copyright 2016 Maxst, Inc. All Rights Reserved.
3  */
4 package com.maxst.ar;
5 
6 import android.content.Context;
7 import android.database.Cursor;
8 import android.net.Uri;
9 import android.os.Handler;
10 import android.util.DisplayMetrics;
11 import android.util.Log;
12 import android.util.TypedValue;
13 import android.view.Gravity;
14 import android.view.ViewGroup;
15 import android.widget.TextView;
16 import android.widget.Toast;
17 
21 public class WearableCalibration {
22 
23  private static final String TAG = WearableCalibration.class.getSimpleName();
24 
25  private static final String COLUMN_FILE_NAME = "Filename";
26  private static final String COLUMN_CALIBRATION_DATA = "Calibration Data";
27 
34  public enum EyeType {
35  EYE_LEFT(0),
36  EYE_RIGHT(1),
37  EYE_NUM(2);
38 
39  private int value;
40 
41  private EyeType(int value) {
42  this.value = value;
43  }
44 
45  public int getValue() {
46  return value;
47  }
48  }
49 
57  public enum DistanceType {
58  DISTANCE_NEAR(0),
59  DISTANCE_MIDDLE(1),
60  DISTANCE_FAR(2),
61  DISTANCE_NUM(3);
62 
63  private int value;
64 
65  private DistanceType(int value) {
66  this.value = value;
67  }
68 
69  public int getValue() {
70  return value;
71  }
72  }
73 
74 // public static final String PROFILE_SAVE_DIR = Environment.getExternalStorageDirectory() + "/MaxstAR/WearableCalibrationProfile";
75 // public static final String CONFIG_DIR = Environment.getExternalStorageDirectory() + "/MaxstAR" + "/Config";
76 // public static final String CALIBRATION_CONFIG_NAME = "cali.config";
77 
78  private static WearableCalibration instance = null;
79 
85  public static WearableCalibration getInstance() {
86  if (instance == null) {
87  instance = new WearableCalibration();
88  }
89 
90  return instance;
91  }
92 
93  private String activeProfileName = "";
94 
95  private WearableCalibration() {
96  }
97 
104  public boolean init(String modelName) {
105  return MaxstARJNI.WearableCalibration_init(modelName);
106  }
107 
113  public boolean isActivated() {
114  return MaxstARJNI.WearableCalibration_isActivated();
115  }
116 
123  public void setSurfaceSize(int surfaceWidth, int surfaceHeight) {
124  final Context context = MaxstAR.getApplicationContext();
125 
126  int licenseType = MaxstARJNI.getLicenseType();
127 
128  if(licenseType == 1 || licenseType == 3 || licenseType == 4) {
129  String licenseTypeString = "";
130  switch (licenseType) {
131  case 1:
132  licenseTypeString = "Free";
133  break;
134  case 2:
135  licenseTypeString = "Invalid";
136  break;
137  case 3:
138  licenseTypeString = "None";
139  break;
140  }
141 
142  final String LicenseMessage = "This License " + licenseTypeString;
143  Handler mainHandler = new Handler(context.getMainLooper());
144 
145  Runnable myRunnable = new Runnable() {
146  @Override
147  public void run() {
148  DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
149  int offsetX = displayMetrics.widthPixels / 2;
150  int offsetY = 0;
151 
152  Toast toast = Toast.makeText(context, LicenseMessage, Toast.LENGTH_LONG);
153  ViewGroup group = (ViewGroup) toast.getView();
154  TextView messageTextView = (TextView) group.getChildAt(0);
155  messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 50);
156 
157  toast.setGravity(Gravity.CENTER, offsetX, offsetY);
158  toast.show();
159  }
160  };
161  mainHandler.post(myRunnable);
162  }
163 
164  MaxstARJNI.WearableCalibration_setSurfaceSize(surfaceWidth, surfaceHeight);
165  }
166 
170  public void deinit() {
171  MaxstARJNI.WearableCalibration_deinit();
172  }
173 
180  public float[] getViewport(EyeType eyeType) {
181  return MaxstARJNI.WearableCalibration_getViewport(eyeType.getValue());
182  }
183 
190  public float[] getProjectionMatrix(int eyeType) {
191  return MaxstARJNI.WearableCalibration_getProjectionMatrix(eyeType);
192  }
193 
200  public boolean writeProfile(String filePath) {
201  return MaxstARJNI.WearableCalibration_writeProfile(filePath);
202  }
203 
210  public boolean readProfile(String filePath) {
211  return MaxstARJNI.WearableCalibration_readProfile(filePath);
212  }
213 
214  public void loadDefaultProfile(String modelName) {
215  MaxstARJNI.WearableCalibration_loadDefaultProfile(modelName);
216  }
217 
224  public boolean setProfile(byte[] data) {
225  return MaxstARJNI.WearableCalibration_setProfile(data);
226  }
227 
228  public boolean readActiveProfile(Context context, String wearableDeviceName) {
229  Uri uri = Uri.parse("content://com.maxst.ar.wearablecali/activeprofile");
230  Cursor c = context.getContentResolver().query(uri, null, null, null, null);
231  if (c == null || c.getCount() == 0) {
232  Log.e(TAG, "No active profile");
233  loadDefaultProfile(wearableDeviceName);
234  Log.e(TAG, "Load default device profile "+ wearableDeviceName);
235  return false;
236  }
237  c.moveToFirst();
238  activeProfileName = c.getString(c.getColumnIndex(COLUMN_FILE_NAME));
239  byte[] data = c.getBlob(c.getColumnIndex(COLUMN_CALIBRATION_DATA));
240 
241  Log.d(TAG, "fileName:" + activeProfileName);
242  activeProfileName = activeProfileName.substring(0, activeProfileName.lastIndexOf("."));
243  Log.d(TAG, "data:" + new String(data, 0, data.length));
244 
245  return setProfile(data);
246  }
247 
252  public String getActiveProfileName() {
253  return activeProfileName;
254  }
255 
262  public void getDistancePos(DistanceType distanceType, float[] pos) {
263  MaxstARJNI.WearableCalibration_getDistancePos(distanceType.getValue(), pos);
264  }
265 
271  public void setCameraToEyePose(EyeType eyeType, DistanceType distanceType, float[] pose) {
272  MaxstARJNI.WearableCalibration_setCameraToEyePose(eyeType.getValue(), distanceType.getValue(), pose);
273  }
274 
275  public float[] getScreenCoordinate() {
276  return MaxstARJNI.WearableCalibration_getScreenCoordinate();
277  }
278 
279  public void getTargetGLScale(DistanceType distanceType, float[] scale) {
280  MaxstARJNI.WearableCalibration_getTargetGLScale(distanceType.getValue(), scale);
281  }
282 
283  public void getTargetGLPosition(DistanceType distanceType, float[] position) {
284  MaxstARJNI.WearableCalibration_getTargetGLPosition(distanceType.getValue(), position);
285  }
286 }
void setCameraToEyePose(EyeType eyeType, DistanceType distanceType, float[] pose)
boolean readProfile(String filePath)
boolean writeProfile(String filePath)
void setSurfaceSize(int surfaceWidth, int surfaceHeight)
static WearableCalibration getInstance()
void getDistancePos(DistanceType distanceType, float[] pos)
float [] getViewport(EyeType eyeType)