Missing files

This commit is contained in:
Tim Bentley 2014-11-15 15:59:52 +00:00
parent e856bea4e5
commit 1efed76680
11 changed files with 906 additions and 0 deletions

View File

@ -0,0 +1,127 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.api;
/**
* <h1>Routes:</h1>
* <p/>
* <p/>
* <pre>
* ``/``
* Go to the web interface.
*
* ``/files/{filename}``
*
* ``/api/poll``
* {"results": {"type": "controller"}}
* Or, if there were no results, False::
* {"results": False}
*
* ``/api/display/{hide|show}``
* Blank or unblank the screen.
*
* ``/api/alert``
* {"request": {"text": "<your alert text>"}}
* ``/api/controller/{live|preview}/{action}``
* ``next``
* Load the next slide.
*
* ``previous``
* Load the previous slide.
*
* ``set``
* Set a specific slide. Requires an id return in a JSON-encoded dict like
* this::
*
* {"request": {"id": 1}}
*
* ``first``
* Load the first slide.
*
* ``last``
* Load the last slide.
*
* ``text``
* Fetches the text of the current song. The output is a JSON-encoded
* dict which looks like this::
*
* {"result": {"slides": ["...", "..."]}}
*
* ``/api/service/{action}``
* Perform ``{action}`` on the service manager (e.g. go live). Data is
* passed as a json-encoded ``data`` parameter. Valid actions are:
*
* ``next``
* Load the next item in the service.
*
* ``previous``
*
* ``set``
* Set a specific item in the service. Requires an id returned in a
* JSON-encoded dict like this::
*
* {"request": {"id": 1}}
*
* ``list``
* Request a list of items in the service. Returns a list of items in the
* current service in a JSON-encoded dict like this::
*
* {"results": {"items": [{...}, {...}]}}
* """
* </pre>
*/
public interface Api {
public final String LIVE_BASE = "/api/controller/live/";
public final String LIVE_NEXT = "/api/controller/live/next";
public final String LIVE_PREVIOUS = "/api/controller/live/previous";
public final String LIVE_TEXT = "/api/controller/live/text";
public final String LIVE_SET = "/api/controller/live/set?data=";
public final String STAGE_VIEW = "/stage";
public final String LIVE_VIEW = "/main";
public final String SERVICE_LIST = "/api/service/list";
public final String SERVICE_SET = "/api/service/set?data=";
public final String DISPLAY_SHOW = "/api/display/show";
public final String DISPLAY_BLANK = "/api/display/blank";
public final String DISPLAY_THEME = "/api/display/theme";
public final String DISPLAY_DESKTOP = "/api/display/desktop";
public final String POLL_STATUS = "/api/poll";
public final String ALERT = "/api/alert?data=";
public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
/**
* This is a special string that uses the String.format() method. See
* {@link String#format(String, Object...)}
*/
public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
/**
* Match intent extra key with regex since multiple plugins can be inserted
*/
public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
/**
* Match intent extra key with regex since multiple plugins can be inserted
*/
public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
}

View File

@ -0,0 +1,56 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.common;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class JsonHelpers {
private static String LOG_TAG = JsonHelpers.class.getName();
public static String createRequestJSON(String key, String value) throws JSONHandlerException {
try {
String responseJSON;
JSONObject jo = new JSONObject();
jo.put(key, value);
responseJSON = new JSONStringer().object().key("request").value(jo)
.endObject().toString();
responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
return responseJSON;
} catch (JSONException e) {
throw new JSONHandlerException(e);
} catch (UnsupportedEncodingException e) {
throw new JSONHandlerException(e);
}
}
public static class JSONHandlerException extends Exception {
private static final long serialVersionUID = -6772307308404816615L;
public JSONHandlerException(Throwable throwable) {
super(throwable);
}
}
}

View File

@ -0,0 +1,28 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.common;
public class NavigationOptions{
public final static int Home = 0;
public final static int ServiceList = 1;
public final static int LiveList = 2;
public final static int StageView = 3;
public final static int LiveView = 4;
}

View File

@ -0,0 +1,69 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.common;
import android.app.DialogFragment;
import android.content.Context;
import android.util.Log;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;
import org.apache.http.Header;
import org.openlp.android2.api.Api;
abstract public class OpenLPDialog extends DialogFragment {
private final String LOG_TAG = OpenLPDialog.class.getName();
protected String calledURL;
protected OpenLPHttpClient httpClient;
protected Context context;
private static AsyncHttpClient client = new AsyncHttpClient();
protected void populateDisplay(String responseString) {}
protected void processUpdate(String responseString) {}
protected void errorDisplay(int statusCode, String responseString) {}
protected void triggerTextRequest(String url) {
calledURL = url;
Log.d(LOG_TAG, "Trigger Request for url " + url);
String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url );
client.get(callurl, null, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
// called when response HTTP status is "200 OK"
manageResponse(responseString);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
errorDisplay(statusCode, responseString);
}
});
}
public void manageResponse(String response) {
if (calledURL.equals(Api.POLL_STATUS)) {
populateDisplay(response);
}else {
processUpdate(response);
}
}
}

View File

@ -0,0 +1,157 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.common;
import java.security.KeyStore;
import java.util.*;
import android.content.Context;
import android.util.Log;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.MySSLSocketFactory;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.openlp.android2.R;
/**
* Personalised HttpClient to be used throughout OpenLP with customisable
* parameters.
*/
public class OpenLPHttpClient {
private final String LOG_TAG = OpenLPHttpClient.class.getName();
private Context context;
private Boolean useSSL = Boolean.FALSE;
public OpenLPHttpClient(Context context) {
this.context = context;
}
private String getPreference(Map preferences, String key, String defaultValue) {
if (preferences.containsKey(key)) {
return preferences.get(key).toString();
} else {
return defaultValue;
}
}
private Integer getPreference(Map preferences, String key, Integer defaultValue) {
if (preferences.containsKey(key)) {
return Integer.valueOf(preferences.get(key).toString());
} else {
return defaultValue;
}
}
private Boolean getPreference(Map preferences, String key, Boolean defaultValue) {
if (preferences.containsKey(key)) {
return Boolean.valueOf(preferences.get(key).toString());
} else {
return defaultValue;
}
}
public String getAbsoluteUrl(AsyncHttpClient client) {
if (useSSL){
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
client.setSSLSocketFactory(sf);
}
catch (Exception e) {;
}
}
Map<String, ?> preferences = context.getSharedPreferences(context.getString(R.string.keySharedPreferences), Context.MODE_PRIVATE).getAll();
useSSL = getPreference(preferences, context.getString(R.string.key_ssl_use), false);
String host = getPreference(preferences, context.getString(R.string.keyHost),
context.getString(R.string.hostDefaultValue));
String port = getPreference(preferences, context.getString(R.string.keyPort), "4316");
String userid = getPreference(preferences, context.getString(R.string.key_userid), "openlp");
String password = getPreference(preferences, context.getString(R.string.key_password), "password");
Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
client.setBasicAuth(userid,password);
Credentials creds = new UsernamePasswordCredentials(userid, password);
String urlBase = String.format("http%s://%s:%s", useSSL ? "s" : "", host, port);
int connectionTimeout = context.getResources().getInteger(
R.integer.connectionTimeoutDefaultValue);
if (getPreference(preferences, context.getString(R.string.keyEnableCustomTimeout), false)) {
Log.d(LOG_TAG, "Overriding Connection and Socket timeouts");
connectionTimeout = getPreference(preferences,
context.getString(R.string.keyConnectionTimeout),
context.getResources().getInteger(
R.integer.connectionTimeoutDefaultValue)
);
}
client.setTimeout(connectionTimeout);
if (useSSL){
try {
KeyStore trustStore = KeyStore.getInstance((KeyStore.getDefaultType()));
trustStore.load(null, null);
OpenLPSSLSocketFactory sf = new OpenLPSSLSocketFactory(trustStore);
sf.setHostnameVerifier((OpenLPSSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER));
client.setSSLSocketFactory(sf);
}
catch (Exception e){
}
}
return urlBase;
}
/* public OpenLPHttpReturn handleExecute() throws IOException {
//HttpResponse response = this.execute();
Log.d(LOG_TAG, "Http response code " + String.valueOf(response.getStatusLine().getStatusCode()));
if (response.getStatusLine().getStatusCode() == 200) {
BufferedReader bufferedReader;
HttpEntity entity = response.getEntity();
if (entity != null) {
bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
StringBuilder stringBuilder = new StringBuilder();
String line = bufferedReader.readLine();
while (line != null) {
stringBuilder.append(line);
line = bufferedReader.readLine();
}
bufferedReader.close();
return new OpenLPHttpReturn(0, stringBuilder.toString(), this.context);
}
}
return new OpenLPHttpReturn(response.getStatusLine().getStatusCode(), null, this.context);
}*/
}

View File

@ -0,0 +1,62 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.common;
import android.content.Context;
import org.openlp.android2.R;
public class OpenLPHttpReturn {
private int return_code = 0;
private String data = null;
private Context context;
public OpenLPHttpReturn() {
this.return_code = -1;
this.data = "";
this.context = null;
}
public OpenLPHttpReturn(int return_code, String data, Context context) {
this.return_code = return_code;
this.data = data;
this.context = context;
}
public String getData() {
return this.data;
}
public boolean isError() {
return return_code != 0;
}
public boolean isSecurityError() {
return return_code == 401;
}
public String getErrorMessage(String message) {
return return_code == 401 ? this.context.getString(R.string.httpreturn_unauthorised) : message;
}
@Override
public String toString() {
return "HttpReturn{" + "data='" + data + '\'' + ", return code=" + return_code + '}';
}
}

View File

@ -0,0 +1,48 @@
package org.openlp.android2.common;
import org.apache.http.conn.ssl.SSLSocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* Created by tim on 14/11/14.
*/
public class OpenLPSSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public OpenLPSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}

View File

@ -0,0 +1,124 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.openlp.android2.R;
import org.openlp.android2.api.Api;
import org.openlp.android2.common.JsonHelpers;
import org.openlp.android2.common.OpenLPDialog;
import org.openlp.android2.common.OpenLPHttpReturn;
public class AlertDisplayDialog extends OpenLPDialog {
private final String LOG_TAG = AlertDisplayDialog.class.getName();
public AlertDialog dialog;
/**
* The system calls this only when creating the layout in a dialog.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// The only reason you might override this method when using onCreateView() is
// to modify any dialog characteristics. For example, the dialog includes a
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
context = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View view = inflater.inflate(R.layout.alert_display_dialog, null);
builder.setView(view);
builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AlertDisplayDialog.this.getDialog().cancel();
}
});
builder.setNegativeButton(R.string.process, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int id) {
EditText text = (EditText) dialog.findViewById(R.id.alertText);
requestAlert(text.getText().toString());
}
});
dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogI) {
Button btnNegative = dialog.getButton(Dialog.BUTTON_NEGATIVE);
btnNegative.setTextSize(20);
Button btnPositive = dialog.getButton(Dialog.BUTTON_POSITIVE);
btnPositive.setTextSize(20);
}
});
return dialog;
}
@Override
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "Resuming...");
triggerRequest(Api.POLL_STATUS);
Log.d(LOG_TAG, "Resumed...");
}
private void triggerRequest(String url) {
ExecuteHttpRequestTask task = new ExecuteHttpRequestTask();
task.execute(new String[]{url});
}
public void populateDisplay(OpenLPHttpReturn response) {
Log.d(LOG_TAG, "populateDisplay");
if (response.isSecurityError()) {
Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show();
} else if (response.isError()) {
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
}
}
public void requestAlert(String text) {
try {
String request = JsonHelpers.createRequestJSON("text", text);
triggerRequest(String.format("%s%s", Api.ALERT, request));
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), text(%s)",
Api.ALERT, text));
Toast.makeText(getActivity().getBaseContext(), "Alert Requested", Toast.LENGTH_SHORT).show();
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -0,0 +1,158 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2014 Raoul Snyman *
* Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*******************************************************************************/
package org.openlp.android2.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import org.openlp.android2.R;
import org.openlp.android2.api.Api;
import org.openlp.android2.common.OpenLPDialog;
import org.openlp.android2.common.OpenLPHttpClient;
public class BlankDisplayDialog extends OpenLPDialog {
private final String LOG_TAG = BlankDisplayDialog.class.getName();
public AlertDialog dialog;
Button desktop;
Button screen;
Button theme;
Button reset;
/**
* The system calls this only when creating the layout in a dialog.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// The only reason you might override this method when using onCreateView() is
// to modify any dialog characteristics. For example, the dialog includes a
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
context = getActivity();
httpClient = new OpenLPHttpClient(context);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View view = inflater.inflate(R.layout.blank_display_dialog, null);
builder.setView(view);
reset = (Button) view.findViewById(R.id.buttonReset);
reset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_SHOW);
}
});
screen = (Button) view.findViewById(R.id.buttonScreen);
screen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_BLANK);
}
});
theme = (Button) view.findViewById(R.id.buttonTheme);
theme.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_THEME);
}
});
desktop = (Button) view.findViewById(R.id.buttonDesktop);
desktop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
triggerTextRequest(Api.DISPLAY_DESKTOP);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
BlankDisplayDialog.this.getDialog().cancel();
}
});
dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogI) {
Button btnNegative = dialog.getButton(Dialog.BUTTON_NEGATIVE);
btnNegative.setTextSize(20);
}
});
return dialog;
}
@Override
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "Resuming...");
triggerTextRequest(Api.POLL_STATUS);
Log.d(LOG_TAG, "Resumed...");
}
public void processUpdate(String response) {
triggerTextRequest(Api.POLL_STATUS);
}
public void populateDisplay(String json) {
Log.d(LOG_TAG, "populateDisplay");
try {
JSONObject item = new JSONObject(json).getJSONObject("results");
if (item.getString("theme").equals("false") &
item.getString("display").equals("false") &
item.getString("blank").equals("false")) {
screen.setEnabled(true);
theme.setEnabled(true);
desktop.setEnabled(true);
reset.setEnabled(false);
} else {
screen.setEnabled(false);
theme.setEnabled(false);
desktop.setEnabled(false);
reset.setEnabled(true);
}
} catch (JSONException e) {
Log.e(LOG_TAG, "Exception with Json = " + json);
e.printStackTrace();
}
}
public void errorDisplay(int statusCode, String responseString) {
Log.d(LOG_TAG, String.format("URL Error status code %d text %s", statusCode, responseString));
screen.setEnabled(false);
theme.setEnabled(false);
desktop.setEnabled(false);
reset.setEnabled(false);
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="294dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/enterAlertText"
android:id="@+id/textView"
android:autoText="true"
android:textStyle="bold|italic"
android:textSize="40px"
android:height="45dp"/>
<EditText
android:id="@+id/alertText"
android:layout_width="290dp"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="294dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/displayBlankSummary"
android:id="@+id/textView"
android:autoText="true"
android:textStyle="bold|italic"
android:textSize="40px"
android:height="45dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/display.Reset"
android:id="@+id/buttonReset"
android:textSize="20sp"
android:height="40dp"
android:clickable="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/display.Screen"
android:id="@+id/buttonScreen"
android:textSize="20sp"
android:height="40dp"
android:clickable="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/display.Theme"
android:id="@+id/buttonTheme"
android:textSize="20sp"
android:height="40dp"
android:clickable="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/display.Desktop"
android:id="@+id/buttonDesktop"
android:textSize="20sp"
android:height="40dp"
android:clickable="true"/>
</LinearLayout>