質問編集履歴
4
ソースコードと掲載理由を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,20 @@
|
|
12
12
|
|
13
13
|
オブジェクトが使えない原因がよく分かりません。。。
|
14
14
|
|
15
|
+
SmartEyeGlassControlUtils.java(ソースコード追加しました。)には、setRequiredApiVersionやactivateやregisterARObjectなどMainActivityで使うクラスの中身はあるのですが、
|
16
|
+
|
17
|
+
MainActivityの方で、
|
18
|
+
|
19
|
+
private final SmartEyeglassControlUtils utils;
|
20
|
+
|
21
|
+
utils=new SmartEyeglassControlUtils(hostAppPackageName,listener);
|
22
|
+
|
23
|
+
として、オブジェクトUtilsを作成し、SmartEyeGlassControlUtils.javaの中のクラスを使えるようになるはずですが、いざUtils.とピリオドを打つと、PointInWorldCoordinateしか表示されません。
|
24
|
+
|
25
|
+
PointInWorldCoordinateは、SmartEyeGlassControlUtils.javaの中ではクラスなようです。
|
26
|
+
|
27
|
+
少しずつ追記していきますし、真剣に悩んでいるので、少しでも助言ください!
|
28
|
+
|
15
29
|
### ソースコード(並び順が悪い?)
|
16
30
|
|
17
31
|
```Java
|
@@ -124,6 +138,330 @@
|
|
124
138
|
|
125
139
|
```
|
126
140
|
|
141
|
+
### ソースコード(SmartEyeGlassControlUtils)
|
142
|
+
|
143
|
+
※少し長いです。
|
144
|
+
|
145
|
+
```Java
|
146
|
+
|
147
|
+
import略
|
148
|
+
|
149
|
+
private static final List<Integer> RENDER_MODE = Arrays.asList(
|
150
|
+
|
151
|
+
SmartEyeglassControl.Intents.MODE_NORMAL,
|
152
|
+
|
153
|
+
SmartEyeglassControl.Intents.MODE_AR
|
154
|
+
|
155
|
+
);
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
private Context mContext;
|
160
|
+
|
161
|
+
private final String mHostAppPackageName;
|
162
|
+
|
163
|
+
private final BitmapFactory.Options mBitmapOptions;
|
164
|
+
|
165
|
+
private int mRenderingMode = SmartEyeglassControl.Intents.MODE_NORMAL;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
private final Handler mHandler;
|
170
|
+
|
171
|
+
private final SmartEyeglassEventListener mGeneralEventListener;
|
172
|
+
|
173
|
+
private int mSetApiVersion = 0;
|
174
|
+
|
175
|
+
private boolean mCameraStarted = false;
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
public SmartEyeglassControlUtils(String hostAppPackageName,
|
180
|
+
|
181
|
+
SmartEyeglassEventListener eventListener) {
|
182
|
+
|
183
|
+
mHostAppPackageName = hostAppPackageName;
|
184
|
+
|
185
|
+
mHandler = new Handler();
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
if (eventListener != null) {
|
190
|
+
|
191
|
+
mGeneralEventListener = eventListener;
|
192
|
+
|
193
|
+
} else {
|
194
|
+
|
195
|
+
mGeneralEventListener = new SmartEyeglassEventListener();
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
mBitmapOptions = new BitmapFactory.Options();
|
200
|
+
|
201
|
+
mBitmapOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT;
|
202
|
+
|
203
|
+
mBitmapOptions.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
public final void activate(final Context context) {
|
208
|
+
|
209
|
+
if (mContext != null) {
|
210
|
+
|
211
|
+
deactivate();
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
mContext = context;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
// register BroadcastReceiver
|
220
|
+
|
221
|
+
IntentFilter filter = new IntentFilter();
|
222
|
+
|
223
|
+
filter.addAction(SmartEyeglassControl.Intents.CONTROL_AR_GET_OBJECT_REQUEST_INTENT);
|
224
|
+
|
225
|
+
filter.addAction(SmartEyeglassControl.Intents.CONTROL_AR_REGISTER_OBJECT_RESPONSE_INTENT);
|
226
|
+
|
227
|
+
context.registerReceiver(this, filter);
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
sendConfirmApiVersion(context);
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
public final void deactivate() {
|
240
|
+
|
241
|
+
if (mContext == null) {
|
242
|
+
|
243
|
+
return;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
mContext.unregisterReceiver(this);
|
248
|
+
|
249
|
+
mContext = null;
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
private class IntentRunner implements Runnable {
|
256
|
+
|
257
|
+
protected Intent mIntent;
|
258
|
+
|
259
|
+
IntentRunner(Intent intent) {
|
260
|
+
|
261
|
+
mIntent = intent;
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
@Override
|
268
|
+
|
269
|
+
public void run() {
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
@Override
|
278
|
+
|
279
|
+
public void onReceive(Context context, Intent intent) {
|
280
|
+
|
281
|
+
mHandler.post(new IntentRunner(intent) {
|
282
|
+
|
283
|
+
@Override
|
284
|
+
|
285
|
+
public void run() {
|
286
|
+
|
287
|
+
String action = mIntent.getAction();
|
288
|
+
|
289
|
+
if (action == null) {
|
290
|
+
|
291
|
+
return;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
private void sendConfirmApiVersion(final Context context) {
|
296
|
+
|
297
|
+
int apiVersion = context.getResources().getInteger(R.integer.api_version);
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
if (apiVersion < mSetApiVersion) {
|
302
|
+
|
303
|
+
throw new IllegalArgumentException(
|
304
|
+
|
305
|
+
context.getResources().getString(R.string.api_version_error_throw_message));
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
if (mSetApiVersion == 0) {
|
312
|
+
|
313
|
+
mSetApiVersion = apiVersion;
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
Intent intent = new Intent(SmartEyeglassControl.Intents.CONTROL_API_VERSION_CONFIRM_INTENT);
|
320
|
+
|
321
|
+
intent.putExtra(SmartEyeglassControl.Intents.EXTRA_VERSION_DATA, mSetApiVersion);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
sendToHostApp(intent);
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
public void setRequiredApiVersion(final int version) {
|
332
|
+
|
333
|
+
mSetApiVersion = version;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), resourceId,
|
340
|
+
|
341
|
+
mBitmapOptions);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
sendDisplayDataWithCallback(bitmap, INVALID_DISP_OFFSET, INVALID_DISP_OFFSET,
|
346
|
+
|
347
|
+
transactionNumber, SmartEyeglassControl.Intents.DISPLAY_DATA_TYPE_SHOW_IMAGE);
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
public void showBitmap(final Bitmap bitmap) {
|
354
|
+
|
355
|
+
if (Dbg.DEBUG) {
|
356
|
+
|
357
|
+
Dbg.d("showBitmap");
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
sendDisplayData(bitmap, INVALID_DISP_OFFSET, INVALID_DISP_OFFSET);
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
public void showBitmap(final Bitmap bitmap, final int x, final int y) {
|
370
|
+
|
371
|
+
if (Dbg.DEBUG) {
|
372
|
+
|
373
|
+
Dbg.v("showBitmap x: " + x + " y: " + y);
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
sendDisplayData(bitmap, x, y);
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
public void registerARObject(final RenderObject object) {
|
386
|
+
|
387
|
+
if (mRenderingMode != SmartEyeglassControl.Intents.MODE_AR) {
|
388
|
+
|
389
|
+
// error, not in AR mode so operation not possible
|
390
|
+
|
391
|
+
throw new IllegalStateException("Not in AR mode");
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
if (object == null) {
|
398
|
+
|
399
|
+
throw new IllegalArgumentException("object has illegal value");
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
Intent intent = new Intent(SmartEyeglassControl.Intents.CONTROL_AR_REGISTER_OBJECT_REQUEST_INTENT);
|
406
|
+
|
407
|
+
object.toRegisterExtras(intent);
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
sendToHostApp(intent);
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
public class PointInWorldCoordinate {
|
416
|
+
|
417
|
+
public double latitude;
|
418
|
+
|
419
|
+
public double longitude;
|
420
|
+
|
421
|
+
public double altitude;
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
public static PointF convertCoordinateSystemFromWorldToCylindrical(
|
426
|
+
|
427
|
+
final PointInWorldCoordinate viewingLocation,
|
428
|
+
|
429
|
+
final PointInWorldCoordinate targetLocation) {
|
430
|
+
|
431
|
+
PointF point = new PointF();
|
432
|
+
|
433
|
+
float[] results = {0, 0, 0};
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
Location.distanceBetween(viewingLocation.latitude, viewingLocation.longitude,
|
438
|
+
|
439
|
+
targetLocation.latitude, targetLocation.longitude, results);
|
440
|
+
|
441
|
+
float distance = results[0];
|
442
|
+
|
443
|
+
double angle = getAngle(viewingLocation.altitude, targetLocation.altitude, distance);
|
444
|
+
|
445
|
+
int direction = getPosDirection(viewingLocation.latitude, viewingLocation.longitude,
|
446
|
+
|
447
|
+
targetLocation.latitude, targetLocation.longitude);
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
point.set((float) direction, (float) angle);
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
return point;
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
```
|
462
|
+
|
463
|
+
|
464
|
+
|
127
465
|
### 参考文献
|
128
466
|
|
129
467
|
http://korechi.hatenablog.com/entry/2016/03/25/023434
|
3
オブジェクトの生成に問題あり?
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,6 +7,10 @@
|
|
7
7
|
(もしくは、他の関数に入れる?)
|
8
8
|
|
9
9
|
このソースは、MainActivityにまるごと入れていますが、他のクラスを作って方が良いのでしょうか?
|
10
|
+
|
11
|
+
色々調べましたら、SmartEyeglassControlUtilsのオブジェクトであるUtilsが正常に機能しておらず、UtilsにかかるUtils.●●が赤字になっているようです。
|
12
|
+
|
13
|
+
オブジェクトが使えない原因がよく分かりません。。。
|
10
14
|
|
11
15
|
### ソースコード(並び順が悪い?)
|
12
16
|
|
2
文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
おそらくプログラムの並び順が悪いと思うので、正しい並び順を教えていただけないでしょうか?
|
6
6
|
|
7
7
|
(もしくは、他の関数に入れる?)
|
8
|
+
|
9
|
+
このソースは、MainActivityにまるごと入れていますが、他のクラスを作って方が良いのでしょうか?
|
8
10
|
|
9
11
|
### ソースコード(並び順が悪い?)
|
10
12
|
|
1
インデント整理
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,53 +10,51 @@
|
|
10
10
|
|
11
11
|
```Java
|
12
12
|
|
13
|
-
//ARイベント用ハンドラーであるSmartEyeglassEventListenerの登録
|
13
|
+
//ARイベント用ハンドラーであるSmartEyeglassEventListenerの登録
|
14
14
|
|
15
|
-
private final SmartEyeglassEventListener listener = new SmartEyeglassEventListener() {
|
15
|
+
private final SmartEyeglassEventListener listener = new SmartEyeglassEventListener() {
|
16
16
|
|
17
|
-
@Override
|
17
|
+
@Override
|
18
18
|
|
19
|
-
public void onARRegistrationResult(
|
19
|
+
public void onARRegistrationResult(
|
20
20
|
|
21
|
-
final int result, final int objectId) {
|
21
|
+
final int result, final int objectId) {
|
22
22
|
|
23
|
-
if (result != SmartEyeglassControl.Intents.AR_RESULT_OK) {
|
23
|
+
if (result != SmartEyeglassControl.Intents.AR_RESULT_OK) {
|
24
24
|
|
25
|
-
return;
|
25
|
+
return;
|
26
|
+
|
27
|
+
}
|
26
28
|
|
27
29
|
}
|
28
30
|
|
29
|
-
}
|
30
31
|
|
31
|
-
// Find bitmap to render when requested by AR engine
|
32
32
|
|
33
|
-
|
33
|
+
// Find bitmap to render when requested by AR engine
|
34
34
|
|
35
|
+
@Override
|
36
|
+
|
35
|
-
public void onARObjectRequest(final int objectId) {
|
37
|
+
public void onARObjectRequest(final int objectId) {
|
36
38
|
|
37
39
|
|
38
40
|
|
39
|
-
// send bitmap
|
41
|
+
// send bitmap
|
40
42
|
|
41
|
-
utils.sendARObjectResponse(renderObj, 0);
|
43
|
+
utils.sendARObjectResponse(renderObj, 0);
|
42
44
|
|
43
|
-
}
|
45
|
+
}
|
44
46
|
|
45
|
-
};
|
47
|
+
};
|
46
48
|
|
47
|
-
//そしてSmartEyeglassControlUtilsのオブジェクトを生成し、初期設定
|
49
|
+
//そしてSmartEyeglassControlUtilsのオブジェクトを生成し、初期設定
|
48
50
|
|
49
|
-
private final SmartEyeglassControlUtils utils;
|
51
|
+
private final SmartEyeglassControlUtils utils;
|
50
52
|
|
53
|
+
utils=new SmartEyeglassControlUtils(hostAppPackageName,listener);
|
51
54
|
|
55
|
+
utils.setRequiredApiVersion(SMARTEYEGLASS_API_VERSION);
|
52
56
|
|
53
|
-
utils = new SmartEyeglassControlUtils(hostAppPackageName, listener);
|
54
|
-
|
55
|
-
utils.setRequiredApiVersion(SMARTEYEGLASS_API_VERSION);
|
56
|
-
|
57
|
-
utils.activate(context);
|
57
|
+
utils.activate(context);
|
58
|
-
|
59
|
-
|
60
58
|
|
61
59
|
|
62
60
|
|
@@ -68,7 +66,7 @@
|
|
68
66
|
|
69
67
|
|
70
68
|
|
71
|
-
private SparseArray<Bitmap> imageMap
|
69
|
+
private SparseArray<Bitmap> imageMap=new SparseArray<Bitmap>();
|
72
70
|
|
73
71
|
//このimageMapにbitmapを入れる
|
74
72
|
|
@@ -76,47 +74,47 @@
|
|
76
74
|
|
77
75
|
// 配列の番号(キー)
|
78
76
|
|
79
|
-
int key;
|
77
|
+
int key;
|
80
78
|
|
81
79
|
// skiplace.pngが/res/drawable下にあるものとする
|
82
80
|
|
83
|
-
imageMap.put(key,
|
81
|
+
imageMap.put(key,R.drawable.skiplace));
|
84
82
|
|
85
|
-
Bitmap b
|
83
|
+
Bitmap b=BitmapFactory.decodeResource(context.getResources(),R.drawable.skiplace);
|
86
84
|
|
87
|
-
b.setDensity(DisplayMetrics.DENSITY_DEFAULT);
|
85
|
+
b.setDensity(DisplayMetrics.DENSITY_DEFAULT);
|
88
86
|
|
89
87
|
|
90
88
|
|
91
89
|
|
92
90
|
|
93
|
-
// SmartEyeglassに画像を表示
|
91
|
+
// SmartEyeglassに画像を表示
|
94
92
|
|
95
|
-
RenderObject renderObj
|
93
|
+
RenderObject renderObj=new RenderObject(OBJECT_ID,getBitmapResource(R.drawable.skiplace),0,0){
|
96
94
|
|
97
|
-
|
95
|
+
@Override
|
98
96
|
|
99
|
-
|
97
|
+
public void toMoveExtras(Intent intent){
|
100
98
|
|
101
|
-
}
|
99
|
+
}
|
102
100
|
|
103
|
-
};
|
101
|
+
};
|
104
102
|
|
105
|
-
this.utils.registerARObject(renderObj);
|
103
|
+
this.utils.registerARObject(renderObj);
|
106
104
|
|
107
105
|
//そして、bitmapを表示する
|
108
106
|
|
109
107
|
// 欲しいbitmapのキー
|
110
108
|
|
111
|
-
int num
|
109
|
+
int num=0;
|
112
110
|
|
113
|
-
private static final int OBJECT_ID
|
111
|
+
private static final int OBJECT_ID=1;
|
114
112
|
|
115
113
|
|
116
114
|
|
117
|
-
Bitmap bitmap
|
115
|
+
Bitmap bitmap=imageMap.get(num);
|
118
116
|
|
119
|
-
utils.showBitmap(bitmap);
|
117
|
+
utils.showBitmap(bitmap);
|
120
118
|
|
121
119
|
```
|
122
120
|
|