fixed code

This commit is contained in:
Tim Bentley 2016-05-15 17:48:52 +01:00
parent 4f6ab320fa
commit b75b563e9d
20 changed files with 396 additions and 353 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="OpenLP2" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="fixssl" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@ -12,10 +12,7 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
@ -28,7 +25,7 @@
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
@ -36,13 +33,13 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
@ -50,6 +47,15 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
@ -57,6 +63,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@ -64,35 +71,47 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
<orderEntry type="library" exported="" name="classes" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />

View File

@ -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')
}

BIN
app/libs/classes.jar Normal file

Binary file not shown.

View File

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

View File

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

View File

@ -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<String, String> 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<String, String> createBasicAuthHeader(String username, String password) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", RequestQueueService.getInstance(context).getBasicAuth());
return headers;
}
Response.Listener<String> listener = new Response.Listener<String>() {
@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());
}
};
}

View File

@ -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<String, String> 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<String, String> createBasicAuthHeader(String username, String password) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", RequestQueueService.getInstance(context).getBasicAuth());
return headers;
}
Response.Listener<String> listener = new Response.Listener<String>() {
@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);

View File

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

View File

@ -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 + '}';
}
}

View File

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

View File

@ -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<String, Bitmap> cache = new LruCache<String, Bitmap>(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 <T> void addToRequestQueue(Request<T> req) {
getRequestQueue().add(req);
}
public ImageLoader getImageLoader() {
return mImageLoader;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -16,10 +16,6 @@
android:icon="@drawable/ic_refresh_white"
android:title="@string/action_refresh"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_search"
android:icon="@drawable/ic_search_white"
android:title="@string/action_search"
app:showAsAction="never|withText" />
<item android:id="@+id/action_preferences"
android:icon="@android:drawable/ic_menu_preferences"
android:title="@string/action_preferences"

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Sat May 14 10:36:56 BST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip