Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
Detect phone / tablet configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Dag Liodden committed Jul 19, 2012
1 parent 60c491f commit 575c807
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions event-tracking/src/main/java/com/tapad/tracking/DeviceInfo.java
@@ -0,0 +1,18 @@
package com.tapad.tracking;

import android.content.Context;

public class DeviceInfo {

/**
* Check if the screen configuration indicates that this is a tablet.
*/
public static boolean isTablet(Context context) {
return context.getResources().getConfiguration().screenLayout == 4; // SCREENLAYOUT_SIZE_XLARGE
}

public static String getUserAgent(Context context) {
if (isTablet(context)) return "Android Tablet/TapadEventAPI/1.0";
else return "Android Mobile/TapadEventAPI/1.0";
}
}
Expand Up @@ -36,10 +36,10 @@ class EventResource {
* @param appId the application id to use * @param appId the application id to use
* @param deviceId the device id to use * @param deviceId the device id to use
*/ */
EventResource(String appId, DeviceIdentifier deviceId) { EventResource(String appId, DeviceIdentifier deviceId, String userAgent) {
this.appId = appId; this.appId = appId;
this.deviceId = deviceId; this.deviceId = deviceId;
this.client = HttpClientUtil.createClient("Android/TapadEventAPI/1.0"); this.client = HttpClientUtil.createClient(userAgent);
} }


protected void post(Event e) throws IOException { protected void post(Event e) throws IOException {
Expand Down
Expand Up @@ -98,7 +98,10 @@ protected static void setupAPI(Context context, String appId) {
deviceId = getHashedDeviceId(context); deviceId = getHashedDeviceId(context);
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PREF_TAPAD_DEVICE_ID, deviceId).commit(); PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PREF_TAPAD_DEVICE_ID, deviceId).commit();
} }
service = new TrackingServiceImpl(new EventDispatcher(new EventResource(appId, deviceIdLocator)));
service = new TrackingServiceImpl(
new EventDispatcher(new EventResource(appId, deviceIdLocator, DeviceInfo.getUserAgent(context)))
);
} }
} }
} }
Expand Down

0 comments on commit 575c807

Please sign in to comment.