summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java51
1 files changed, 30 insertions, 21 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
index 8cd388357b..a7f574bf40 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
+import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
@@ -11,28 +12,15 @@ import android.view.WindowManager;
import com.mapbox.android.telemetry.TelemetryUtils;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Class that holds kinds of states of the current phone.
*/
class PhoneState {
- static final String LANDSCAPE = "Landscape";
- static final String PORTRAIT = "Portrait";
private static final String NO_CARRIER = "EMPTY_CARRIER";
private static final int NO_NETWORK = -1;
-
- private static final Map<Integer, String> ORIENTATIONS = new HashMap<Integer, String>() {
- {
- put(Configuration.ORIENTATION_LANDSCAPE, LANDSCAPE);
- put(Configuration.ORIENTATION_PORTRAIT, PORTRAIT);
- }
- };
-
private String created;
private String cellularNetworkType;
- private String orientation;
+ private Orientation orientation;
private String carrier;
private int batteryLevel;
private boolean pluggedIn;
@@ -44,19 +32,19 @@ class PhoneState {
}
- PhoneState(Context context) {
+ PhoneState(@NonNull Context context) {
this.created = TelemetryUtils.obtainCurrentDate();
this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
this.pluggedIn = TelemetryUtils.isPluggedIn(context);
this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
- this.orientation = ORIENTATIONS.get(context.getResources().getConfiguration().orientation);
+ this.orientation = Orientation.getOrientation(context.getResources().getConfiguration().orientation);
this.accessibilityFontScale = context.getResources().getConfiguration().fontScale;
this.carrier = obtainCellularCarrier(context);
this.resolution = obtainDisplayDensity(context);
this.wifi = isConnectedToWifi(context);
}
- private String obtainCellularCarrier(Context context) {
+ private String obtainCellularCarrier(@NonNull Context context) {
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager == null) {
return NO_CARRIER;
@@ -68,13 +56,13 @@ class PhoneState {
return carrierName;
}
- private float obtainDisplayDensity(Context context) {
+ private float obtainDisplayDensity(@NonNull Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.density;
}
- private boolean isConnectedToWifi(Context context) {
+ private boolean isConnectedToWifi(@NonNull Context context) {
try {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiMgr == null) {
@@ -121,10 +109,10 @@ class PhoneState {
}
String getOrientation() {
- return orientation;
+ return orientation.getOrientation();
}
- void setOrientation(String orientation) {
+ void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
@@ -159,4 +147,25 @@ class PhoneState {
void setResolution(float resolution) {
this.resolution = resolution;
}
+
+ enum Orientation {
+ ORIENTATION_PORTRAIT("Portrait"),
+ ORIENTATION_LANDSCAPE("Landscape");
+ private String orientation;
+
+ Orientation(String orientation) {
+ this.orientation = orientation;
+ }
+
+ public static Orientation getOrientation(int index) {
+ if (Configuration.ORIENTATION_PORTRAIT == index) {
+ return ORIENTATION_PORTRAIT;
+ }
+ return ORIENTATION_LANDSCAPE;
+ }
+
+ public String getOrientation() {
+ return orientation;
+ }
+ }
}