Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -16,6 +17,7 @@
import android.webkit.ConsoleMessage;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebMessage;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand Down Expand Up @@ -48,6 +50,20 @@ public class FullscreenActivity extends AppCompatActivity {
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler();
private View mContentView;
private WebView myWebView;
// Load the revieve-web-plugin from Revieve's production CDN:
final String REVIEVE_CDN_DOMAIN = "https://d38knilzwtuys1.cloudfront.net";
// Origin set to *
final String REVIEVE_ORIGIN = "*";
// Select which Revieve API environment to use. Can be test or prod
final String REVIEVE_ENV = "test";
// Partner ID
final String REVIEVE_PARTNER_ID = "TShEWzW05I";

// Construct the full URL
final String REVIEVE_FULL_URL = REVIEVE_CDN_DOMAIN + "/revieve-plugin-v4/app.html?partnerId=" + REVIEVE_PARTNER_ID + "&env=" + REVIEVE_ENV + "&crossOrigin=1&origin=" + REVIEVE_ORIGIN;


private final Runnable mHidePart2Runnable = new Runnable() {
@SuppressLint("InlinedApi")
@Override
Expand Down Expand Up @@ -147,20 +163,8 @@ protected void onPostCreate(Bundle savedInstanceState) {
// Revieve webview example:
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

// Load the revieve-web-plugin from Revieve's production CDN:
final String REVIEVE_CDN_DOMAIN = "https://d38knilzwtuys1.cloudfront.net";
// Origin set to *
final String REVIEVE_ORIGIN = "*";
// Select which Revieve API environment to use. Can be test or prod
final String REVIEVE_ENV = "test";
// Partner ID
final String REVIEVE_PARTNER_ID = "kToSMAjsNx";

// Construct the full URL
final String REVIEVE_FULL_URL = REVIEVE_CDN_DOMAIN + "/revieve-plugin-v4/app.html?partnerId=" + REVIEVE_PARTNER_ID + "&env=" + REVIEVE_ENV + "&crossOrigin=1&origin=" + REVIEVE_ORIGIN;

// Load it
WebView myWebView = (WebView) findViewById(R.id.revieveWebview);
myWebView = (WebView) findViewById(R.id.revieveWebview);

myWebView.setWebChromeClient(new WebChromeClient() {
private Boolean listenerCalled = false;
Expand Down Expand Up @@ -212,11 +216,34 @@ public void onProgressChanged(WebView view, int progress) {
webSettings.setGeolocationEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
myWebView.setWebContentsDebuggingEnabled(true);
myWebView.addJavascriptInterface(new RevieveJSInterface(this), "Android");

myWebView.loadUrl(REVIEVE_FULL_URL);
}

@Override
protected void onPause () {
super.onPause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
myWebView.postWebMessage(
new WebMessage("{\"type\": \"setCameraPause\", \"payload\": true}"),
Uri.parse(REVIEVE_CDN_DOMAIN)
);
}
}

@Override
protected void onResume () {
super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
myWebView.postWebMessage(
new WebMessage("{\"type\": \"setCameraPause\", \"payload\": false}"),
Uri.parse(REVIEVE_CDN_DOMAIN)
);
}
}

Comment on lines +225 to +246
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to comment in the code why they might want to use this snippet and also mention webview.pause / resume alternatives

private void toggle() {
if (mVisible) {
hide();
Expand Down