From 6ad001e8be3de5428d7613848a95f81d2f92cec1 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 6 Nov 2016 00:01:37 -0700 Subject: [PATCH] Update help viewer for Amazon devices --- .../main/java/com/limelight/HelpActivity.java | 62 ++++++++++++++++++- .../com/limelight/utils/HelpLauncher.java | 26 +++++--- app/src/main/res/values/strings.xml | 4 ++ 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/limelight/HelpActivity.java b/app/src/main/java/com/limelight/HelpActivity.java index dad85053..3be731b2 100644 --- a/app/src/main/java/com/limelight/HelpActivity.java +++ b/app/src/main/java/com/limelight/HelpActivity.java @@ -1,19 +1,79 @@ package com.limelight; import android.app.Activity; +import android.graphics.Bitmap; import android.os.Bundle; import android.webkit.WebView; +import android.webkit.WebViewClient; + +import com.limelight.utils.SpinnerDialog; public class HelpActivity extends Activity { + private SpinnerDialog loadingDialog; + private WebView webView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - WebView webView = new WebView(this); + webView = new WebView(this); setContentView(webView); + // These allow the user to zoom the page + webView.getSettings().setBuiltInZoomControls(true); + webView.getSettings().setDisplayZoomControls(false); + + // This sets the view to display the whole page by default + webView.getSettings().setUseWideViewPort(true); + webView.getSettings().setLoadWithOverviewMode(true); + + // This allows the links to places on the same page to work webView.getSettings().setJavaScriptEnabled(true); + + webView.setWebViewClient(new WebViewClient() { + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + if (loadingDialog == null) { + loadingDialog = SpinnerDialog.displayDialog(HelpActivity.this, + getResources().getString(R.string.help_loading_title), + getResources().getString(R.string.help_loading_msg), false); + } + } + + @Override + public void onPageFinished(WebView view, String url) { + if (loadingDialog != null) { + loadingDialog.dismiss(); + loadingDialog = null; + } + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.toUpperCase().startsWith("https://github.com/moonlight-stream/moonlight-docs/wiki/".toUpperCase()) || + url.toUpperCase().startsWith("http://github.com/moonlight-stream/moonlight-docs/wiki/".toUpperCase())) { + // Allow navigation to Moonlight docs + return false; + } + else { + return true; + } + } + }); + webView.loadUrl(getIntent().getData().toString()); } + + @Override + public void onBackPressed() { + // Back goes back through the WebView history + // until no more history remains + if (webView.canGoBack()) { + webView.goBack(); + } + else { + super.onBackPressed(); + } + } } diff --git a/app/src/main/java/com/limelight/utils/HelpLauncher.java b/app/src/main/java/com/limelight/utils/HelpLauncher.java index f27b0bde..c0f94121 100644 --- a/app/src/main/java/com/limelight/utils/HelpLauncher.java +++ b/app/src/main/java/com/limelight/utils/HelpLauncher.java @@ -4,25 +4,33 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Build; import com.limelight.HelpActivity; public class HelpLauncher { private static void launchUrl(Context context, String url) { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse(url)); - // Try to launch the default browser try { - context.startActivity(i); + // Fire TV devices will lie and say they do have a browser + // even though the OS just shows an error dialog if we + // try to use it. + if (!"Amazon".equalsIgnoreCase(Build.MANUFACTURER)) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + context.startActivity(i); + return; + } } catch (ActivityNotFoundException e) { - // This platform has no browser (possibly a leanback device) - // We'll launch our WebView activity - i = new Intent(context, HelpActivity.class); - i.setData(Uri.parse(url)); - context.startActivity(i); + // Fall through } + + // This platform has no browser (possibly a leanback device) + // We'll launch our WebView activity + Intent i = new Intent(context, HelpActivity.class); + i.setData(Uri.parse(url)); + context.startActivity(i); } public static void launchSetupGuide(Context context) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 59abefda..f3d616fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,6 +4,10 @@ PC deleted PC not paired + + Help Viewer + Loading help page… + View Game List Pair with PC