Update help viewer for Amazon devices

This commit is contained in:
Cameron Gutman 2016-11-06 00:01:37 -07:00
parent b6e4d5528b
commit 6ad001e8be
3 changed files with 82 additions and 10 deletions

View File

@ -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();
}
}
}

View File

@ -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) {

View File

@ -4,6 +4,10 @@
<string name="scut_deleted_pc">PC deleted</string>
<string name="scut_not_paired">PC not paired</string>
<!-- Help strings -->
<string name="help_loading_title">Help Viewer</string>
<string name="help_loading_msg">Loading help page…</string>
<!-- PC view menu entries -->
<string name="pcview_menu_app_list">View Game List</string>
<string name="pcview_menu_pair_pc">Pair with PC</string>