Integrate help buttons into dialogs and the PcView

This commit is contained in:
Cameron Gutman
2016-11-05 19:51:43 -07:00
parent 1b5330323c
commit d68b2382cf
10 changed files with 242 additions and 81 deletions

View File

@@ -0,0 +1,19 @@
package com.limelight;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HelpActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
setContentView(webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(getIntent().getData().toString());
}
}

View File

@@ -23,6 +23,7 @@ import com.limelight.preferences.StreamSettings;
import com.limelight.ui.AdapterFragment;
import com.limelight.ui.AdapterFragmentCallbacks;
import com.limelight.utils.Dialog;
import com.limelight.utils.HelpLauncher;
import com.limelight.utils.ServerHelper;
import com.limelight.utils.ShortcutHelper;
import com.limelight.utils.UiHelper;
@@ -111,6 +112,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
// Setup the list view
ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton);
ImageButton addComputerButton = (ImageButton) findViewById(R.id.manuallyAddPc);
ImageButton helpButton = (ImageButton) findViewById(R.id.helpButton);
settingsButton.setOnClickListener(new OnClickListener() {
@Override
@@ -125,6 +127,12 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
startActivity(i);
}
});
helpButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
HelpLauncher.launchSetupGuide(PcView.this);
}
});
getFragmentManager().beginTransaction()
.replace(R.id.pcFragmentContainer, new AdapterFragment())

View File

@@ -5,6 +5,9 @@ import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.Button;
import com.limelight.R;
public class Dialog implements Runnable {
private final String title;
@@ -55,7 +58,7 @@ public class Dialog implements Runnable {
alert.setCancelable(false);
alert.setCanceledOnTouchOutside(false);
alert.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
alert.setButton(AlertDialog.BUTTON_POSITIVE, activity.getResources().getText(android.R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
synchronized (rundownDialogs) {
rundownDialogs.remove(Dialog.this);
@@ -67,6 +70,31 @@ public class Dialog implements Runnable {
}
}
});
alert.setButton(AlertDialog.BUTTON_NEUTRAL, activity.getResources().getText(R.string.help), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
synchronized (rundownDialogs) {
rundownDialogs.remove(Dialog.this);
alert.dismiss();
}
if (endAfterDismiss) {
activity.finish();
}
HelpLauncher.launchTroubleshooting(activity);
}
});
alert.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialog) {
// Set focus to the OK button by default
Button button = alert.getButton(AlertDialog.BUTTON_POSITIVE);
button.setFocusable(true);
button.setFocusableInTouchMode(true);
button.requestFocus();
}
});
synchronized (rundownDialogs) {
rundownDialogs.add(this);

View File

@@ -0,0 +1,35 @@
package com.limelight.utils;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
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);
} 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);
}
}
public static void launchSetupGuide(Context context) {
launchUrl(context, "https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide");
}
public static void launchTroubleshooting(Context context) {
launchUrl(context, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
}
}