Skip to content

Commit

Permalink
Add client profile and client profile version to cedexis.start call
Browse files Browse the repository at this point in the history
Also includes:

 - Change URL to ../0/0/radar.html
 - Bump library version to 0.2.7
  • Loading branch information
Jacob Wan committed Mar 30, 2018
1 parent f21108a commit 70e9e9d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion android-radar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/cedexis/AndroidRadar'
gitUrl = 'https://github.com/cedexis/AndroidRadar.git'

libraryVersion = '0.2.6'
libraryVersion = '0.2.7'

developerId = 'cedexis'
developerName = 'Cedexis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

class CedexisRadarWebClient extends WebViewClient {

// 2 is the client profile code for AndroidRadar
final int CLIENT_PROFILE = 2;
// Client profile version conveys the version of the WebView wrapper code.
final int CLIENT_PROFILE_VERSION = 1;
final String TAG = CedexisRadarWebClient.class.getSimpleName();
private final int zoneId;
private final int customerId;
Expand All @@ -43,15 +47,21 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String startCommand = String.format(Locale.getDefault(), "cedexis.start(%d,%d);", zoneId, customerId);
String startCommand = String.format(
Locale.getDefault(),
"cedexis.start(%d,%d,%d,%d);",
zoneId,
customerId,
CLIENT_PROFILE,
CLIENT_PROFILE_VERSION);
Log.d(TAG, String.format("Detected version: %d", Build.VERSION.SDK_INT));
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Log.d(TAG, "Using evaluateJavascript");
Log.d(TAG, String.format("Using evaluateJavascript; start command=%s", startCommand));
view.evaluateJavascript("console.log('sending cedexis commands');", null);
view.evaluateJavascript(startCommand, null);
} else {
Log.d(TAG, "Using loadUrl");
Log.d(TAG, String.format("Using loadUrl: start command: %s", startCommand));
view.loadUrl("javascript:console.log('sending cedexis commands');");
view.loadUrl("javascript:" + startCommand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.cedexis.androidradar;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;

import java.util.Locale;
Expand Down Expand Up @@ -73,10 +73,15 @@ public void start(final int zoneId, final int customerId, final RadarScheme sche
} else if (webView == null) {
throw new IllegalAccessError("Call Radar#init method before sending Radar events");
} else {
configureWebView(webView);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowFileAccess(true);
settings.setAllowContentAccess(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
webView.setWebViewClient(createOrGetWebClient(zoneId, customerId));
String url = String.format(Locale.getDefault(),
"%s://%s/%d/%d/radar.html", scheme.toString(), RADAR_HOST, zoneId, customerId);
"%s://%s/0/0/radar.html", scheme.toString(), RADAR_HOST);
Log.d(TAG, String.format("Radar URL: %s", url));
webView.loadUrl(url);
}
Expand All @@ -88,27 +93,4 @@ private CedexisRadarWebClient createOrGetWebClient(int zoneId, int customerId) {
}
return webViewClient;
}

/**
* Give all access to the webview to use JavaScript and allow universal access,
* only send {@link CedexisRadarWebClient} to only allow redirects on the same
* Radar host.
*
* @param webView
*/
@SuppressLint("SetJavaScriptEnabled")
private void configureWebView(WebView webView) {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
webView.getSettings().setAllowContentAccess(true);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe

Button radarButton;
private int requestorZoneId = 1;
private int requestorCustomerId = 22746;
private int requestorCustomerId = 10660;
private Cedexis cedexis;

@Override
Expand Down

0 comments on commit 70e9e9d

Please sign in to comment.