diff --git a/app/app.iml b/app/app.iml index 78d7daa..fc630d9 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -12,10 +12,7 @@ - + @@ -36,13 +33,13 @@ - + - + @@ -50,6 +47,15 @@ + + + + + + + + + @@ -57,6 +63,7 @@ + @@ -64,35 +71,47 @@ + + + + + + + + + + + - - - - - - - + + + + + + - - + + + + - + diff --git a/app/build.gradle b/app/build.gradle index 830724a..ba4bda1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,5 @@ apply plugin: 'com.android.application' - project.archivesBaseName = 'OpenLP' - android { compileSdkVersion 22 buildToolsVersion "21.1.2" @@ -26,20 +24,15 @@ android { } testOptions { unitTests.returnDefaultValues = true -} + } -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:22.2.1' - compile 'com.android.support:support-v4:22.2.1' - compile 'com.android.support:design:22.2.1' - compile 'com.loopj.android:android-async-http:1.4.6' - testCompile 'junit:junit:4.12' - testCompile 'org.easytesting:fest:1.0.16' - testCompile 'com.squareup:fest-android:1.0.8' - testCompile('org.robolectric:robolectric:3.0-rc2') { - exclude group: 'commons-logging', module: 'commons-logging' - exclude group: 'org.apache.httpcomponents', module: 'httpclient' + dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.android.support:support-v4:22.2.1' + compile 'com.android.support:design:22.2.1' } } +dependencies { + compile files('libs/classes.jar') } \ No newline at end of file diff --git a/app/libs/classes.jar b/app/libs/classes.jar new file mode 100644 index 0000000..791fe0b Binary files /dev/null and b/app/libs/classes.jar differ diff --git a/app/src/main/java/org/openlp/android2/OpenLP.java b/app/src/main/java/org/openlp/android2/OpenLP.java index 5312d6b..baf65b0 100644 --- a/app/src/main/java/org/openlp/android2/OpenLP.java +++ b/app/src/main/java/org/openlp/android2/OpenLP.java @@ -35,6 +35,7 @@ import android.view.WindowManager; import org.openlp.android2.activities.SettingsActivity; import org.openlp.android2.common.NavigationOptions; +import org.openlp.android2.common.NukeSSLCerts; import org.openlp.android2.dialogs.AlertDisplayDialog; import org.openlp.android2.dialogs.BlankDisplayDialog; import org.openlp.android2.fragments.AboutFragment; @@ -64,6 +65,7 @@ public class OpenLP extends ActionBarActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + new NukeSSLCerts().nuke(); doPreferenceCheck(); diff --git a/app/src/main/java/org/openlp/android2/common/NukeSSLCerts.java b/app/src/main/java/org/openlp/android2/common/NukeSSLCerts.java new file mode 100644 index 0000000..511ddb8 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/common/NukeSSLCerts.java @@ -0,0 +1,77 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2015 OpenLP Android Developers * + * --------------------------------------------------------------------------- * + * 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.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + + +public class NukeSSLCerts { + protected static final String TAG = "NukeSSLCerts"; + + public static void nuke() { + try { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + X509Certificate[] myTrustedAnchors = new X509Certificate[0]; + return myTrustedAnchors; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + SSLContext sc = null; + try { + sc = SSLContext.getInstance("TLS"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + try { + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + // Create all-trusting host name verifier + HostnameVerifier allHostsValid = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + // Install the all-trusting host verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch (Exception e) { + } + } +} diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPDialog.java b/app/src/main/java/org/openlp/android2/common/OpenLPDialog.java index 02f9d64..8f4d592 100644 --- a/app/src/main/java/org/openlp/android2/common/OpenLPDialog.java +++ b/app/src/main/java/org/openlp/android2/common/OpenLPDialog.java @@ -6,12 +6,12 @@ * 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 * @@ -22,54 +22,103 @@ import android.app.DialogFragment; import android.content.Context; import android.util.Log; import android.widget.Toast; -import com.loopj.android.http.AsyncHttpClient; -import com.loopj.android.http.TextHttpResponseHandler; -import org.apache.http.Header; + +import com.android.volley.AuthFailureError; +import com.android.volley.ClientError; +import com.android.volley.DefaultRetryPolicy; +import com.android.volley.NetworkError; +import com.android.volley.NoConnectionError; +import com.android.volley.ParseError; +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.ServerError; +import com.android.volley.TimeoutError; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.StringRequest; + import org.openlp.android2.R; import org.openlp.android2.api.Api; +import java.util.HashMap; +import java.util.Map; + abstract public class OpenLPDialog extends DialogFragment { private final String LOG_TAG = OpenLPDialog.class.getName(); - protected String calledURL; - protected OpenLPHttpClient httpClient; + protected Context context; + private String urlcalled; - 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) - if (statusCode == 401) { - Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show(); - } else { - Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show(); - } - errorDisplay(statusCode, responseString); - } - }); + protected void populateDisplay(String responseString) { } - public void manageResponse(String response) { - if (calledURL.equals(Api.POLL_STATUS)) { - populateDisplay(response); - }else { - processUpdate(response); + protected void processUpdate(String responseString) { + } + + protected void errorDisplay(String responseString) { + } + + protected void triggerTextRequest(final String urlbase) { + String url = RequestQueueService.getInstance(this.context).getUrl(urlbase); + urlcalled = urlbase; + + StringRequest request = new StringRequest( + Request.Method.GET, + url, + listener, + errorListener) { + + @Override + public Map getHeaders() throws AuthFailureError { + return createBasicAuthHeader("user", "passwd"); + } + }; + //Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions. + // Volley does retry for you if you have specified the policy. + request.setRetryPolicy(new DefaultRetryPolicy( + RequestQueueService.getInstance(this.context).getConnectionTimeout(), + DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); + request.setTag("OpenLP"); + RequestQueueService.getInstance(this.context).addToRequestQueue(request); + } + + Map createBasicAuthHeader(String username, String password) { + Map headers = new HashMap(); + headers.put("Authorization", RequestQueueService.getInstance(context).getBasicAuth()); + + return headers; + } + + Response.Listener listener = new Response.Listener() { + @Override + public void onResponse(String response) { + if (urlcalled.equals(Api.POLL_STATUS)) { + populateDisplay(response); + } else { + processUpdate(response); + } } - } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.d(LOG_TAG, String.format("Call response error = %s", error.toString())); + if (error instanceof NetworkError) { + } else if (error instanceof ClientError) { + } else if (error instanceof ServerError) { + } else if (error instanceof AuthFailureError) { + Toast.makeText(context, R.string.httpreturn_unauthorised, + Toast.LENGTH_LONG).show(); + } else if (error instanceof ParseError) { + } else if (error instanceof NoConnectionError) { + } else if (error instanceof TimeoutError) { + } + Toast.makeText(context, R.string.unable, + Toast.LENGTH_LONG).show(); + errorDisplay(error.toString()); + + } + }; } diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java b/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java index 6a6d769..7da5ae3 100644 --- a/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java +++ b/app/src/main/java/org/openlp/android2/common/OpenLPFragment.java @@ -26,18 +26,30 @@ import android.view.View; import android.widget.ListView; import android.widget.Toast; -import com.loopj.android.http.AsyncHttpClient; -import com.loopj.android.http.TextHttpResponseHandler; -import org.apache.http.Header; + +import com.android.volley.AuthFailureError; +import com.android.volley.ClientError; +import com.android.volley.DefaultRetryPolicy; +import com.android.volley.NetworkError; +import com.android.volley.NoConnectionError; +import com.android.volley.ParseError; +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.ServerError; +import com.android.volley.TimeoutError; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.StringRequest; import org.openlp.android2.R; import org.openlp.android2.api.Api; +import java.util.HashMap; +import java.util.Map; + abstract public class OpenLPFragment extends ListFragment{ private String LOG_TAG = OpenLPFragment.class.getName(); public Context context; - protected String calledURL; - protected OpenLPHttpClient httpClient; + protected String urlcalled; protected String updateUrl; abstract public void itemClicked(int position); @@ -48,43 +60,72 @@ abstract public class OpenLPFragment extends ListFragment{ itemClicked(position); } - private static AsyncHttpClient client = new AsyncHttpClient(); - protected void refreshDisplay(){} protected void populateDisplay(String responseString, boolean inError) {} protected void processUpdate(String responseString, boolean inError) {} - 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() { + protected void triggerTextRequest(final String urlbase) { + String url = RequestQueueService.getInstance(this.context).getUrl(urlbase); + updateUrl = urlbase; + + StringRequest request = new StringRequest( + Request.Method.GET, + url, + listener, + errorListener) { + @Override - public void onSuccess(int statusCode, Header[] headers, String responseString) { - // called when response HTTP status is "200 OK" - manageResponse(responseString, true); + public Map getHeaders() throws AuthFailureError { + return createBasicAuthHeader("user", "passwd"); } - @Override - public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { - // called when response HTTP status is "4XX" (eg. 401, 403, 404) - if (statusCode == 401) { - Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show(); - } else { - Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show(); - } - manageResponse(responseString, false); - } - }); + }; + //Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions. + // Volley does retry for you if you have specified the policy. + request.setRetryPolicy(new DefaultRetryPolicy( + RequestQueueService.getInstance(this.context).getConnectionTimeout(), + DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); + request.setTag("OpenLP"); + RequestQueueService.getInstance(this.context).addToRequestQueue(request); } - public void manageResponse(String response, boolean notInError) { - if (calledURL.equals(updateUrl)) { - populateDisplay(response, notInError); - }else { - processUpdate(response, notInError); - } + Map createBasicAuthHeader(String username, String password) { + Map headers = new HashMap(); + headers.put("Authorization", RequestQueueService.getInstance(context).getBasicAuth()); + + return headers; } + Response.Listener listener = new Response.Listener() { + @Override + public void onResponse(String response) { + if (urlcalled.equals(updateUrl)) { + populateDisplay(response, true); + } else { + processUpdate(response, true); + } + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.d(LOG_TAG, String.format("Call response error = %s", error.toString())); + if (error instanceof NetworkError) { + } else if (error instanceof ClientError) { + } else if (error instanceof ServerError) { + } else if (error instanceof AuthFailureError) { + Toast.makeText(context, R.string.httpreturn_unauthorised, + Toast.LENGTH_LONG).show(); + } else if (error instanceof ParseError) { + } else if (error instanceof NoConnectionError) { + } else if (error instanceof TimeoutError) { + } + Toast.makeText(context, R.string.unable, + Toast.LENGTH_LONG).show(); + + } + }; + public void next() { Log.d(LOG_TAG, "Going to next slide"); triggerTextRequest(Api.LIVE_NEXT); diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java b/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java deleted file mode 100644 index e1384a4..0000000 --- a/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java +++ /dev/null @@ -1,97 +0,0 @@ -/****************************************************************************** - * OpenLP - Open Source Lyrics Projection * - * --------------------------------------------------------------------------- * - * Copyright (c) 2011-2015 OpenLP Android Developers * - * --------------------------------------------------------------------------- * - * 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 android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; -import com.loopj.android.http.AsyncHttpClient; -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; - } - - public String getAbsoluteUrl(AsyncHttpClient client) { - - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - - String urlBase = getBaseUrl(); - - Log.d(LOG_TAG, "Base Url set to " + urlBase); - - String userid = sharedPrefs.getString(context.getString(R.string.key_userid), "openlp"); - - String password = sharedPrefs.getString(context.getString(R.string.key_password), "password"); - - Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password); - client.setBasicAuth(userid,password); - - int connectionTimeout = context.getResources().getInteger( - R.integer.connectionTimeoutDefaultValue); - - if (sharedPrefs.getBoolean(context.getString(R.string.key_enable_custom_timeout), false)) { - Log.d(LOG_TAG, "Overriding Connection and Socket timeouts"); - - connectionTimeout = Integer.parseInt(sharedPrefs.getString(context.getString(R.string.key_connection_timeout), - String.valueOf(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 String getBaseUrl(){ - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - - useSSL = sharedPrefs.getBoolean(context.getString(R.string.key_ssl_use), false); - String host = sharedPrefs.getString(context.getString(R.string.key_host), - context.getString(R.string.host_default_value)); - String port = sharedPrefs.getString(context.getString(R.string.key_port), "4316"); - - return String.format("http%s://%s:%s", useSSL ? "s" : "", host, port); - - } - -} diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPHttpReturn.java b/app/src/main/java/org/openlp/android2/common/OpenLPHttpReturn.java deleted file mode 100644 index 0f96c14..0000000 --- a/app/src/main/java/org/openlp/android2/common/OpenLPHttpReturn.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * OpenLP - Open Source Lyrics Projection * - * --------------------------------------------------------------------------- * - * Copyright (c) 2011-2015 OpenLP Android Developers * - * --------------------------------------------------------------------------- * - * 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 + '}'; - } -} diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPSSLSocketFactory.java b/app/src/main/java/org/openlp/android2/common/OpenLPSSLSocketFactory.java deleted file mode 100644 index a4f3ea3..0000000 --- a/app/src/main/java/org/openlp/android2/common/OpenLPSSLSocketFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/****************************************************************************** - * OpenLP - Open Source Lyrics Projection * - * --------------------------------------------------------------------------- * - * Copyright (c) 2011-2015 OpenLP Android Developers * - * --------------------------------------------------------------------------- * - * 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.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(); - } -} diff --git a/app/src/main/java/org/openlp/android2/common/RequestQueueService.java b/app/src/main/java/org/openlp/android2/common/RequestQueueService.java new file mode 100644 index 0000000..0412928 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/common/RequestQueueService.java @@ -0,0 +1,101 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2015 OpenLP Android Developers * + * --------------------------------------------------------------------------- * + * 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 android.graphics.Bitmap; +import android.util.Base64; +import android.util.LruCache; + +import com.android.volley.AuthFailureError; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.HurlStack; +import com.android.volley.toolbox.ImageLoader; +import com.android.volley.toolbox.Volley; + +import java.util.HashMap; +import java.util.Map; + +public class RequestQueueService { + + private static RequestQueueService mInstance; + private RequestQueue mRequestQueue; + private ImageLoader mImageLoader; + private static Context mCtx; + private OpenLPURLBuilder urlbuilder; + + private RequestQueueService(Context context) { + mCtx = context; + mRequestQueue = getRequestQueue(); + urlbuilder = new OpenLPURLBuilder(context); + + mImageLoader = new ImageLoader(mRequestQueue, + new ImageLoader.ImageCache() { + private final LruCache cache = new LruCache(20); + + @Override + public Bitmap getBitmap(String url) { + return cache.get(url); + } + + @Override + public void putBitmap(String url, Bitmap bitmap) { + cache.put(url, bitmap); + } + }); + } + + public static synchronized RequestQueueService getInstance(Context context) { + if (mInstance == null) { + mInstance = new RequestQueueService(context); + } + return mInstance; + } + + public RequestQueue getRequestQueue() { + if (mRequestQueue == null) { + // getApplicationContext() is key, it keeps you from leaking the + // Activity or BroadcastReceiver if someone passes one in. + mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext()); + } + return mRequestQueue; + } + + public String getUrl(String url){ + return String.format("%s%s", urlbuilder.getBaseUrl(), url ); + } + + public String getBasicAuth(){ + return urlbuilder.getBasicAuth(); + } + + public int getConnectionTimeout(){ + return urlbuilder.getConnectionTimeout(); + } + + public void addToRequestQueue(Request req) { + getRequestQueue().add(req); + } + + public ImageLoader getImageLoader() { + return mImageLoader; + } +} + diff --git a/app/src/main/java/org/openlp/android2/dialogs/AlertDisplayDialog.java b/app/src/main/java/org/openlp/android2/dialogs/AlertDisplayDialog.java index 0a68677..0c23eee 100644 --- a/app/src/main/java/org/openlp/android2/dialogs/AlertDisplayDialog.java +++ b/app/src/main/java/org/openlp/android2/dialogs/AlertDisplayDialog.java @@ -32,7 +32,6 @@ 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.OpenLPHttpClient; public class AlertDisplayDialog extends OpenLPDialog { private final String LOG_TAG = AlertDisplayDialog.class.getName(); @@ -49,7 +48,6 @@ public class AlertDisplayDialog extends OpenLPDialog { // 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 diff --git a/app/src/main/java/org/openlp/android2/dialogs/BlankDisplayDialog.java b/app/src/main/java/org/openlp/android2/dialogs/BlankDisplayDialog.java index 833e264..8a6fd7d 100644 --- a/app/src/main/java/org/openlp/android2/dialogs/BlankDisplayDialog.java +++ b/app/src/main/java/org/openlp/android2/dialogs/BlankDisplayDialog.java @@ -35,10 +35,10 @@ 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; RadioButton desktop; RadioButton screen; @@ -56,8 +56,6 @@ public class BlankDisplayDialog extends OpenLPDialog { // 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(); @@ -147,8 +145,8 @@ public class BlankDisplayDialog extends OpenLPDialog { } } - public void errorDisplay(int statusCode, String responseString) { - Log.d(LOG_TAG, String.format("URL Error status code %d text %s", statusCode, responseString)); + public void errorDisplay(String responseString) { + Log.d(LOG_TAG, String.format("URL Error text %s", responseString)); reset_display(); } diff --git a/app/src/main/java/org/openlp/android2/fragments/LiveListFragment.java b/app/src/main/java/org/openlp/android2/fragments/LiveListFragment.java index 3717a68..8793b5c 100644 --- a/app/src/main/java/org/openlp/android2/fragments/LiveListFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/LiveListFragment.java @@ -42,7 +42,6 @@ import org.openlp.android2.R; import org.openlp.android2.api.Api; import org.openlp.android2.common.JsonHelpers; import org.openlp.android2.common.OpenLPFragment; -import org.openlp.android2.common.OpenLPHttpClient; import java.util.ArrayList; import java.util.HashMap; @@ -73,8 +72,7 @@ public class LiveListFragment extends OpenLPFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = getActivity(); - updateUrl = Api.LIVE_TEXT; - httpClient = new OpenLPHttpClient(context); + urlcalled = Api.LIVE_TEXT; return super.onCreateView(inflater, container, savedInstanceState); } diff --git a/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java b/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java index c72ed7a..91152cb 100644 --- a/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/ServiceListFragment.java @@ -40,12 +40,10 @@ import org.openlp.android2.R; import org.openlp.android2.api.Api; import org.openlp.android2.common.JsonHelpers; import org.openlp.android2.common.OpenLPFragment; -import org.openlp.android2.common.OpenLPHttpClient; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; public class ServiceListFragment extends OpenLPFragment { @@ -64,8 +62,7 @@ public class ServiceListFragment extends OpenLPFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = getActivity(); - updateUrl = Api.SERVICE_LIST; - httpClient = new OpenLPHttpClient(context); + urlcalled = Api.SERVICE_LIST; return super.onCreateView(inflater, container, savedInstanceState); } diff --git a/app/src/main/java/org/openlp/android2/fragments/WebFragment.java b/app/src/main/java/org/openlp/android2/fragments/WebFragment.java index fdffb41..b441836 100644 --- a/app/src/main/java/org/openlp/android2/fragments/WebFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/WebFragment.java @@ -28,12 +28,10 @@ import android.webkit.SslErrorHandler; import android.webkit.WebView; import android.webkit.WebViewClient; import org.openlp.android2.R; -import org.openlp.android2.common.OpenLPHttpClient; public class WebFragment extends Fragment { protected String curURL; - private OpenLPHttpClient httpClient; private WebView webview; public WebFragment(){ @@ -47,7 +45,7 @@ public class WebFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { - httpClient = new OpenLPHttpClient(getActivity()); + View view = inflater.inflate(R.layout.fragment_web, container, false); if (curURL != null) { @@ -59,7 +57,7 @@ public class WebFragment extends Fragment { webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webview.setScrollbarFadingEnabled(true); webview.setWebViewClient(new webClient()); - webview.loadUrl(String.format("%s%s", httpClient.getBaseUrl(), curURL)); + //webview.loadUrl(String.format("%s%s", httpClient.getBaseUrl(), curURL)); } return view; } diff --git a/app/src/main/res/drawable-hdpi/openlp_splash_screen.png b/app/src/main/res/drawable-hdpi/openlp_splash_screen.png index 618e47c..d413fdd 100644 Binary files a/app/src/main/res/drawable-hdpi/openlp_splash_screen.png and b/app/src/main/res/drawable-hdpi/openlp_splash_screen.png differ diff --git a/app/src/main/res/menu/open_l.xml b/app/src/main/res/menu/open_l.xml index b9513c2..5314e4a 100644 --- a/app/src/main/res/menu/open_l.xml +++ b/app/src/main/res/menu/open_l.xml @@ -16,10 +16,6 @@ android:icon="@drawable/ic_refresh_white" android:title="@string/action_refresh" app:showAsAction="ifRoom" /> -