MaxstARSDK  3.5.0
All Classes Functions Variables
SystemUtil.java
1 /*
2  * Copyright 2016 Maxst, Inc. All Rights Reserved.
3  */
4 
5 package com.maxst.ar;
6 
7 import android.content.Context;
8 import android.content.res.Configuration;
9 import android.os.Build;
10 import android.util.Log;
11 import android.view.Display;
12 import android.view.Surface;
13 import android.view.WindowManager;
14 
18 class SystemUtil {
19 
20  private static final String TAG = SystemUtil.class.getSimpleName();
21 
22  private enum DeviceType {
23  UNCLASSIFIED(0),
24  SMARTPHONE_LIKE(1),
25  TABLET_LIKE(2);
26 
27  private int value;
28 
29  private DeviceType(int value) {
30  this.value = value;
31  }
32 
33  int getValue() {
34  return value;
35  }
36  }
37 
38  private static SystemUtil instance = null;
39 
40  static SystemUtil getInstance() {
41  if (instance == null) {
42  instance = new SystemUtil();
43  }
44 
45  return instance;
46  }
47 
48  private SystemUtil() {
49 
50  }
51 
52  int getDeviceType() {
53  int deviceType = 0;
54 
55  Context context = MaxstARJNI.getContext();
56  int currentWindowOrientation = context.getResources().getConfiguration().orientation;
57  Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
58  int displayRotation = display.getRotation();
59 
60  switch (currentWindowOrientation) {
61  case 1:
62  case 3:
63  deviceType = (displayRotation == 0) || (displayRotation == 2) ? DeviceType.SMARTPHONE_LIKE.getValue() : DeviceType.TABLET_LIKE.getValue();
64  break;
65 
66  case 2:
67  deviceType = (displayRotation == 0) || (displayRotation == 2) ? DeviceType.TABLET_LIKE.getValue() : DeviceType.SMARTPHONE_LIKE.getValue();
68  break;
69 
70  case 0:
71  }
72 
73  Log.i(TAG, "deviceType : " + deviceType);
74 
75  return deviceType;
76  }
77 
78  int getRealOrientation(int orientation) {
79  int realOrientation = 3; // Landscape left
80  int displayRotation = Surface.ROTATION_0;
81  WindowManager windowManager = (WindowManager)MaxstAR.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
82  displayRotation = windowManager.getDefaultDisplay().getRotation();
83 
84  if (Build.MODEL.equalsIgnoreCase("M300")) {
85  if (Surface.ROTATION_0 == displayRotation) {
86  realOrientation = 4; // Landscape right : Vuzix M300 default display rotation
87  } else if (Surface.ROTATION_180 == displayRotation) {
88  realOrientation = 3; // Landscape left
89  } else {
90  realOrientation = 1;
91  }
92  } else {
93  if (orientation == Configuration.ORIENTATION_PORTRAIT) { // Portrait
94  if (displayRotation == Surface.ROTATION_0) { // Phone portrait up
95  realOrientation = 1;
96  } else if (displayRotation == Surface.ROTATION_180) { // Phone portrait down
97  realOrientation = 2;
98  } else if (displayRotation == Surface.ROTATION_90) { // Tablet portrait down
99  realOrientation = 2;
100  } else if (displayRotation == Surface.ROTATION_270) { // Tablet portrait up
101  realOrientation = 1;
102  }
103  } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // Landscape
104  if (displayRotation == Surface.ROTATION_0) { // Tablet landscape left
105  realOrientation = 3;
106  } else if (displayRotation == Surface.ROTATION_180) { // Tablet landscape right
107  realOrientation = 4;
108  } else if (displayRotation == Surface.ROTATION_270) { // Phone landscape right
109  realOrientation = 4;
110  }
111  }
112  }
113 
114  return realOrientation;
115  }
116 }