openlp-android team mailing list archive
-
openlp-android team
-
Mailing list archive
-
Message #00190
[Merge] lp:~trb143/openlp/android-2 into lp:openlp/android
Tim Bentley has proposed merging lp:~trb143/openlp/android-2 into lp:openlp/android.
Requested reviews:
OpenLP Android Developers (openlp-android)
For more details, see:
https://code.launchpad.net/~trb143/openlp/android-2/+merge/157543
Fix up the SSL code to work with CherryPy
Add Userid and Password to config and HTTPCLient
Fix up error handling to work better
Move display strings to translatables.
--
https://code.launchpad.net/~trb143/openlp/android-2/+merge/157543
Your team OpenLP Android Developers is requested to review the proposed merge of lp:~trb143/openlp/android-2 into lp:openlp/android.
=== modified file 'AndroidManifest.xml'
--- AndroidManifest.xml 2013-03-12 19:45:46 +0000
+++ AndroidManifest.xml 2013-04-07 12:27:25 +0000
@@ -3,8 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
package="org.openlp.android"
- android:versionCode="1"
- android:versionName="1.0"
+ android:versionCode="7"
+ android:versionName="1.1"
>
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
=== modified file 'res/values/defaultValues.xml'
--- res/values/defaultValues.xml 2012-05-23 21:37:47 +0000
+++ res/values/defaultValues.xml 2013-04-07 12:27:25 +0000
@@ -4,6 +4,8 @@
<string name="portDefaultValue">4316</string>
<string name="ssl.port.default">4317</string>
<string name="displayTypeValue">@string/displayScreen</string>
+ <string name="useridDefaultValue">openlp</string>
+ <string name="passwordDefaultValue">password</string>
<!-- INTEGER -->
<integer name="socketTimeoutDefaultValue">3000</integer>
=== modified file 'res/values/keyStrings.xml'
--- res/values/keyStrings.xml 2012-05-27 21:42:19 +0000
+++ res/values/keyStrings.xml 2013-04-07 12:27:25 +0000
@@ -7,6 +7,8 @@
<string name="keySocketTimeout">socketTimeout</string>
<string name="keyHost">keyHost</string>
<string name="keyPort">keyPort</string>
+ <string name="key.userid">key.userid</string>
+ <string name="key.password">key.password</string>
<string name="keySharedPreferences">keySharedPreferences</string>
<string name="key.ssl.use">ssl.use</string>
<string name="key.profile.selected.title">key.profile.selected.title</string>
=== modified file 'res/values/strings.xml'
--- res/values/strings.xml 2012-06-02 14:43:23 +0000
+++ res/values/strings.xml 2013-04-07 12:27:25 +0000
@@ -89,4 +89,13 @@
<string name="connection.profile.ssl.summary">Specify whether SSL should be used</string>
<string name="connection.available.configurations">List of available profiles</string>
<string name="connection.add.by.menu">Tap to add a new profile</string>
+ <string name="connection.userid">Userid</string>
+ <string name="connection.password">Password</string>
+ <string name="httpreturn.unauthorised">Unauthorised Access, please enter valid userid and password</string>
+ <string name="apiCallIntent.search">Unexpected invalid result during Search Call.</string>
+ <string name="apiCallIntent.alert">Unexpected invalid result during Alert call.</string>
+ <string name="apiCallIntent.navigation">Unexpected invalid result during Navigation.</string>
+ <string name="apiCallIntent.list_data">Unexpected invalid result while setting list data.</string>
+ <string name="apiCallIntent.poll">Unexpected invalid result during status Poll.</string>
+ <string name="apiCallIntent.fetch">Unexpected invalid result while fetching items.</string>
</resources>
=== modified file 'src/org/openlp/android/OpenLP.java'
--- src/org/openlp/android/OpenLP.java 2012-05-24 21:06:55 +0000
+++ src/org/openlp/android/OpenLP.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/DefaultActivity.java'
--- src/org/openlp/android/activity/DefaultActivity.java 2012-05-24 21:06:55 +0000
+++ src/org/openlp/android/activity/DefaultActivity.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/OpenLPNavigate.java'
--- src/org/openlp/android/activity/OpenLPNavigate.java 2012-05-01 18:49:58 +0000
+++ src/org/openlp/android/activity/OpenLPNavigate.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/PagerActivity.java'
--- src/org/openlp/android/activity/PagerActivity.java 2012-05-01 20:43:27 +0000
+++ src/org/openlp/android/activity/PagerActivity.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/Search.java'
--- src/org/openlp/android/activity/Search.java 2012-05-05 14:12:12 +0000
+++ src/org/openlp/android/activity/Search.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/SearchService.java'
--- src/org/openlp/android/activity/SearchService.java 2012-05-05 14:12:12 +0000
+++ src/org/openlp/android/activity/SearchService.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/SearchableActivity.java'
--- src/org/openlp/android/activity/SearchableActivity.java 2012-05-05 17:34:31 +0000
+++ src/org/openlp/android/activity/SearchableActivity.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java'
--- src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2012-07-02 05:09:23 +0000
+++ src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
@@ -39,9 +39,6 @@
import android.preference.PreferenceScreen;
import android.text.InputType;
import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.widget.Toast;
import org.openlp.android.R;
@@ -51,7 +48,6 @@
private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
-
private PreferenceScreen preferenceScreen = null;
private boolean resume = true;
@@ -197,11 +193,24 @@
? getString(R.string.hostDefaultValue) : hostValueObject.toString();
hostConfig.hostAddress.setText(hostValue);
hostConfig.hostAddress.setSummary(hostValue);
+
Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
String portValue = portValueObject == null
? getString(R.string.portDefaultValue) : portValueObject.toString();
hostConfig.hostPort.setText(portValue);
hostConfig.hostPort.setSummary(portValue);
+
+ Object useridValueObject = preferences.get(hostConfig.userid.getKey());
+ String useridValue = useridValueObject == null
+ ? getString(R.string.useridDefaultValue) : useridValueObject.toString();
+ hostConfig.userid.setText(useridValue);
+ hostConfig.userid.setSummary(useridValue);
+
+ Object passwordValueObject = preferences.get(hostConfig.password.getKey());
+ String passwordValue = passwordValueObject == null
+ ? getString(R.string.passwordDefaultValue) : passwordValueObject.toString();
+ hostConfig.password.setText(passwordValue);
+ hostConfig.password.setSummary(passwordValue);
return hostConfig;
}
@@ -234,6 +243,8 @@
preferenceCategory.addPreference(hostConfig.hostAddress);
preferenceCategory.addPreference(hostConfig.hostPort);
preferenceCategory.addPreference(hostConfig.useSsl);
+ preferenceCategory.addPreference(hostConfig.userid);
+ preferenceCategory.addPreference(hostConfig.password);
preferenceCategory.addPreference(hostConfig.remove);
preferenceCategory.addPreference(hostConfig.activate);
return true;
@@ -261,6 +272,8 @@
final EditTextPreference hostAddress;
final EditTextPreference hostPort;
final CheckBoxPreference useSsl;
+ final EditTextPreference userid;
+ final EditTextPreference password;
final Preference remove;
final Preference activate;
@@ -282,10 +295,9 @@
hostAddress.getEditText().setHint(R.string.urlHint);
hostAddress.setSummary(getString(R.string.urlHint));
hostAddress.setDialogTitle(getString(R.string.urlHint));
- hostAddress.getEditText().setInputType(
- InputType.TYPE_TEXT_VARIATION_URI);
- hostAddress.setOnPreferenceChangeListener(
- onPreferenceChangeListener);
+ hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
+ hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
hostPort.setTitle(getString(R.string.port));
hostPort.setKey(KEY_PREFIX + id + ".port");
@@ -299,8 +311,26 @@
useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
useSsl.setKey(KEY_PREFIX + id + ".usessl");
- // Only till SSL is added to core
- useSsl.setEnabled(false);
+
+ userid = new EditTextPreference(ConnectionPreferenceActivity.this);
+ userid.setSummary(getString(R.string.connection_userid));
+ userid.getEditText().setHint(getString(R.string.connection_userid));
+ userid.setTitle(getString(R.string.connection_userid));
+ userid.setKey(KEY_PREFIX + id + ".userid");
+ userid.setDefaultValue(getString(R.string.useridDefaultValue));
+ userid.setSummary(getString(R.string.useridDefaultValue));
+ userid.setDialogTitle(getString(R.string.connection_userid));
+ userid.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+ password = new EditTextPreference(ConnectionPreferenceActivity.this);
+ password.setSummary(getString(R.string.connection_password));
+ password.getEditText().setHint(getString(R.string.connection_password));
+ password.setTitle(getString(R.string.connection_password));
+ password.setKey(KEY_PREFIX + id + ".password");
+ password.setDefaultValue(getString(R.string.passwordDefaultValue));
+ password.setSummary(getString(R.string.passwordDefaultValue));
+ password.setDialogTitle(getString(R.string.connection_password));
+ password.setOnPreferenceChangeListener(onPreferenceChangeListener);
remove = new Preference(ConnectionPreferenceActivity.this);
remove.setTitle(getString(R.string.connection_profile_remove));
@@ -314,6 +344,8 @@
editor.remove(hostPort.getKey());
editor.remove(title.getKey());
editor.remove(useSsl.getKey());
+ editor.remove(userid.getKey());
+ editor.remove(password.getKey());
editor.commit();
ConnectionPreferenceActivity.this.onBackPressed();
return false;
@@ -336,6 +368,11 @@
editor.putString(getString(R.string.keyPort), port);
Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
+ String suserid = preferences.getString(userid.getKey(), getString(R.string.useridDefaultValue));
+ editor.putString(getString(R.string.key_userid), suserid);
+ String spassword = preferences.getString(password.getKey(),
+ getString(R.string.passwordDefaultValue));
+ editor.putString(getString(R.string.key_password), spassword);
editor.putString(
getString(R.string.key_profile_selected_title),
=== modified file 'src/org/openlp/android/activity/preference/Preferences.java'
--- src/org/openlp/android/activity/preference/Preferences.java 2012-05-31 20:07:41 +0000
+++ src/org/openlp/android/activity/preference/Preferences.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/api/Api.java'
--- src/org/openlp/android/api/Api.java 2012-05-01 18:49:58 +0000
+++ src/org/openlp/android/api/Api.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== added file 'src/org/openlp/android/data/HttpReturn.java'
--- src/org/openlp/android/data/HttpReturn.java 1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/data/HttpReturn.java 2013-04-07 12:27:25 +0000
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
+ * Sjöbergsson *
+ * --------------------------------------------------------------------------- *
+ * 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.android.data;
+
+import android.content.Context;
+import org.openlp.android.R;
+
+public class HttpReturn {
+ private int return_code = 0;
+ private String data = null;
+ private Context context;
+
+ public HttpReturn(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 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 + '}';
+ }
+}
=== modified file 'src/org/openlp/android/data/Poll.java'
--- src/org/openlp/android/data/Poll.java 2012-05-05 17:29:57 +0000
+++ src/org/openlp/android/data/Poll.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/data/SlideItem.java'
--- src/org/openlp/android/data/SlideItem.java 2012-03-04 17:20:44 +0000
+++ src/org/openlp/android/data/SlideItem.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/service/ApiCallIntent.java'
--- src/org/openlp/android/service/ApiCallIntent.java 2012-05-12 19:40:12 +0000
+++ src/org/openlp/android/service/ApiCallIntent.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
@@ -23,9 +23,11 @@
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
+import org.openlp.android.R;
import org.openlp.android.activity.Search;
import org.openlp.android.activity.SearchService;
import org.openlp.android.api.Api;
+import org.openlp.android.data.HttpReturn;
import org.openlp.android.utility.JSONHandler;
import org.openlp.android.utility.OpenLPHttpClient;
@@ -38,265 +40,247 @@
* from an OpenLP server.
*/
public class ApiCallIntent extends IntentService implements SearchService {
- public static final String API_CALL_RECEIVE =
- ApiCallIntent.class.getName().concat(".Receive");
-
- public ApiCallIntent() {
- super(ApiCallIntent.class.getName());
- }
-
- /**
- * apiPart is one of the strings set in {@link org.openlp.android.api.Api}
- * apiCall is when the requested apiPart takes input
- *
- * @param intent The intent requesting data
- */
- @Override
- protected void onHandleIntent(Intent intent) {
- Log.v(LOG_TAG, "Executing WebCallIntent from: " + intent);
- Intent apiCallReceiverIntent = null;
-
- try {
- if (intent.hasExtra(Api.ALERT)) {
- String alertData = JSONHandler.createRequestJSON("text",
- intent.getStringExtra(Api.ALERT));
- apiCallReceiverIntent = executeAlert(alertData);
- }
- else if (intent.hasExtra(Api.SERVICE_BASE)) {
- apiCallReceiverIntent = executeNavigation(Api.SERVICE_BASE,
- intent.getStringExtra(Api.SERVICE_BASE));
- }
- else if (intent.hasExtra(Api.LIVE_BASE)) {
- apiCallReceiverIntent = executeNavigation(Api.LIVE_BASE,
- intent.getStringExtra(Api.LIVE_BASE));
- }
- else if (intent.hasExtra(Api.DISPLAY_BASE)) {
- apiCallReceiverIntent = executeNavigation(Api.DISPLAY_BASE,
- intent.getStringExtra(Api.DISPLAY_BASE));
- }
- else if (intent.hasExtra(Api.POLL_STATUS)) {
- apiCallReceiverIntent = executePoll();
- }
- else if (intent.hasExtra(Api.LIVE_TEXT)) {
- apiCallReceiverIntent = executeItemFetch(Api.LIVE_TEXT);
- }
- else if (intent.hasExtra(Api.SERVICE_LIST)) {
- apiCallReceiverIntent = executeItemFetch(Api.SERVICE_LIST);
- }
- else if (intent.hasExtra(Api.LIVE_SET)) {
- apiCallReceiverIntent = executeSetData(Api.LIVE_SET,
- intent.getIntExtra(Api.LIVE_SET, 0));
- }
- else if (intent.hasExtra(Api.SERVICE_SET)) {
- apiCallReceiverIntent = executeSetData(Api.SERVICE_SET,
- intent.getIntExtra(Api.SERVICE_SET, 0));
- }
-
- if (apiCallReceiverIntent == null) {
-
- // match wildcard intent keys
- for (String key : intent.getExtras().keySet()) {
- if (key.matches("/api/\\w+\\W?\\w+/live\\?data=") ||
- key.matches("/api/\\w+\\W?\\w+/add\\?data=")) {
- apiCallReceiverIntent = getSearchPluginIntent(key,
- intent.getStringExtra(key));
- break;
- }
- }
-
- if (apiCallReceiverIntent == null) {
- String nyiMessage =
- "Not yet Implemented for calls with these extras: " +
- intent.getExtras();
- Log.w(LOG_TAG, nyiMessage);
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(nyiMessage));
- }
- }
- }
- catch (Exception e) {
- Log.e(LOG_TAG, e.toString());
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(String
- .format("%s: %s", e.getClass().getSimpleName(),
- e.getMessage())));
- Log.w(LOG_TAG,
- "Sending Broadcast with error: " + apiCallReceiverIntent);
- }
- sendBroadcast(apiCallReceiverIntent);
- }
-
- @Override
- public Intent getSearchPluginIntent(String apiBase, String apiData)
- throws JSONHandler.JSONHandlerException, IOException,
- URISyntaxException {
- Intent apiCallSearchReceiverIntent =
- new WebCallReceiverIntent(apiBase, apiData);
- apiCallSearchReceiverIntent
- .setAction(Search.ACTION); //override default receiver action
- String jsonRequest = JSONHandler.createRequestJSON("id", apiData);
-
- OpenLPHttpClient httpClient =
- getApiConfiguredClient(apiBase, jsonRequest);
- String result = httpClient.handleExecute();
-
- if (result == null) {
- apiCallSearchReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result during searchPluginCall."));
- apiCallSearchReceiverIntent.setAction(Search.ACTION);
- }
- else {
- Log.d(LOG_TAG, "searchPluginCall result: " + result);
- }
-
- return apiCallSearchReceiverIntent;
- }
-
- private Intent executeAlert(String alertData)
- throws IOException, URISyntaxException {
- Intent apiCallReceiverIntent =
- new WebCallReceiverIntent(Api.ALERT, alertData);
- OpenLPHttpClient httpClient =
- getApiConfiguredClient(Api.ALERT, alertData);
-
- String result = httpClient.handleExecute();
- if (result == null) {
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result during alert call."));
- }
- else {
- Log.d(LOG_TAG, "Alert result: " + result);
- }
-
- return apiCallReceiverIntent;
- }
-
- private Intent executeNavigation(final String apiBase, final String apiData)
- throws IOException, URISyntaxException {
- Intent apiCallReceiverIntent =
- new WebCallReceiverIntent(apiBase, apiData);
- OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase, apiData);
-
- String result = httpClient.handleExecute();
- if (result == null) {
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result during navigation."));
- }
- else {
- Log.d(LOG_TAG, "Navigation result: " + result);
- }
-
- return apiCallReceiverIntent;
- }
-
- private Intent executeSetData(String apiBase, int position)
- throws JSONHandler.JSONHandlerException, IOException,
- URISyntaxException {
- String request =
- JSONHandler.createRequestJSON("id", Integer.toString(position));
- Intent apiCallreceiverIntent =
- new WebCallReceiverIntent(apiBase, request);
- OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase, request);
-
- String result = httpClient.handleExecute();
- if (result == null) {
- String message = String.format(
- "Unexpected null result while setting list data. apiBase(%s), position(%s)",
- apiBase, position);
- Log.e(LOG_TAG, message);
- apiCallreceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result while setting list data."));
- }
- else {
- Log.d(LOG_TAG, "setData result: " + result);
- }
-
- return apiCallreceiverIntent;
- }
-
- private Intent executePoll() throws IOException, URISyntaxException,
- JSONHandler.JSONHandlerException {
- Intent apiCallReceiverIntent =
- new WebCallReceiverIntent(Api.POLL_STATUS, "");
- OpenLPHttpClient httpClient = getApiConfiguredClient(Api.POLL_STATUS);
-
- String pollJson = httpClient.handleExecute();
- if (pollJson == null) {
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result during status poll."));
- }
- else {
- Log.d(LOG_TAG, "Poll result: " + pollJson);
- apiCallReceiverIntent.putExtra("pollJson", pollJson);
- }
- return apiCallReceiverIntent;
- }
-
- private Intent executeItemFetch(final String apiBase)
- throws IOException, URISyntaxException {
- Intent apiCallReceiverIntent = new WebCallReceiverIntent(apiBase, "");
- OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase);
-
- String itemsJson = httpClient.handleExecute();
- if (itemsJson == null) {
- apiCallReceiverIntent = new WebCallReceiverIntent(
- new WebCallReceiverIntentError(
- "Unexpected null result while fetching itmes."));
- }
- else {
- Log.d(LOG_TAG, "Items JSON: " + itemsJson);
- apiCallReceiverIntent.putExtra("itemsJson", itemsJson);
- }
- return apiCallReceiverIntent;
- }
-
- private OpenLPHttpClient getApiConfiguredClient(String apiBase,
- String partData) throws MalformedURLException, URISyntaxException {
- OpenLPHttpClient httpClient =
- new OpenLPHttpClient(getApplicationContext());
- httpClient.setUrl(String.format("%s%s", apiBase, partData));
- return httpClient;
- }
-
- private OpenLPHttpClient getApiConfiguredClient(String apiBase)
- throws MalformedURLException, URISyntaxException {
- return getApiConfiguredClient(apiBase, "");
- }
-
- private final String LOG_TAG = ApiCallIntent.class.getName();
-
- class WebCallReceiverIntent extends Intent {
- WebCallReceiverIntent() {
- setDefaults();
- }
-
- WebCallReceiverIntent(WebCallReceiverIntentError error) {
- setDefaults();
- WebCallReceiverIntent.this.putExtra("error", error.message);
- }
-
- WebCallReceiverIntent(String apiBase, String apiData) {
- setDefaults();
- WebCallReceiverIntent.this.putExtra("apiBase", apiBase);
- WebCallReceiverIntent.this.putExtra("apiData", apiData);
- }
-
- private void setDefaults() {
- WebCallReceiverIntent.this.setAction(API_CALL_RECEIVE);
- WebCallReceiverIntent.this.addCategory(Intent.CATEGORY_DEFAULT);
- }
- }
-
- class WebCallReceiverIntentError {
- final String message;
-
- WebCallReceiverIntentError(String error) {
- this.message = error;
- }
- }
+ public static final String API_CALL_RECEIVE =
+ ApiCallIntent.class.getName().concat(".Receive");
+
+ public ApiCallIntent() {
+ super(ApiCallIntent.class.getName());
+ }
+
+ /**
+ * apiPart is one of the strings set in {@link org.openlp.android.api.Api}
+ * apiCall is when the requested apiPart takes input
+ *
+ * @param intent The intent requesting data
+ */
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ Log.v(LOG_TAG, "Executing WebCallIntent from: " + intent);
+ Intent apiCallReceiverIntent = null;
+
+ try {
+ if (intent.hasExtra(Api.ALERT)) {
+ String alertData = JSONHandler.createRequestJSON("text",
+ intent.getStringExtra(Api.ALERT));
+ apiCallReceiverIntent = executeAlert(alertData);
+ } else if (intent.hasExtra(Api.SERVICE_BASE)) {
+ apiCallReceiverIntent = executeNavigation(Api.SERVICE_BASE,
+ intent.getStringExtra(Api.SERVICE_BASE));
+ } else if (intent.hasExtra(Api.LIVE_BASE)) {
+ apiCallReceiverIntent = executeNavigation(Api.LIVE_BASE,
+ intent.getStringExtra(Api.LIVE_BASE));
+ } else if (intent.hasExtra(Api.DISPLAY_BASE)) {
+ apiCallReceiverIntent = executeNavigation(Api.DISPLAY_BASE,
+ intent.getStringExtra(Api.DISPLAY_BASE));
+ } else if (intent.hasExtra(Api.POLL_STATUS)) {
+ apiCallReceiverIntent = executePoll();
+ } else if (intent.hasExtra(Api.LIVE_TEXT)) {
+ apiCallReceiverIntent = executeItemFetch(Api.LIVE_TEXT);
+ } else if (intent.hasExtra(Api.SERVICE_LIST)) {
+ apiCallReceiverIntent = executeItemFetch(Api.SERVICE_LIST);
+ } else if (intent.hasExtra(Api.LIVE_SET)) {
+ apiCallReceiverIntent = executeSetData(Api.LIVE_SET,
+ intent.getIntExtra(Api.LIVE_SET, 0));
+ } else if (intent.hasExtra(Api.SERVICE_SET)) {
+ apiCallReceiverIntent = executeSetData(Api.SERVICE_SET,
+ intent.getIntExtra(Api.SERVICE_SET, 0));
+ }
+
+ if (apiCallReceiverIntent == null) {
+
+ // match wildcard intent keys
+ for (String key : intent.getExtras().keySet()) {
+ if (key.matches("/api/\\w+\\W?\\w+/live\\?data=") ||
+ key.matches("/api/\\w+\\W?\\w+/add\\?data=")) {
+ apiCallReceiverIntent = getSearchPluginIntent(key,
+ intent.getStringExtra(key));
+ break;
+ }
+ }
+
+ if (apiCallReceiverIntent == null) {
+ String nyiMessage =
+ "Not yet Implemented for calls with these extras: " +
+ intent.getExtras();
+ Log.w(LOG_TAG, nyiMessage);
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(nyiMessage));
+ }
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, e.toString());
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(String
+ .format("%s: %s", e.getClass().getSimpleName(),
+ e.getMessage())));
+ Log.w(LOG_TAG,
+ "Sending Broadcast with error: " + apiCallReceiverIntent);
+ }
+ sendBroadcast(apiCallReceiverIntent);
+ }
+
+ @Override
+ public Intent getSearchPluginIntent(String apiBase, String apiData)
+ throws JSONHandler.JSONHandlerException, IOException,
+ URISyntaxException {
+ Intent apiCallSearchReceiverIntent =
+ new WebCallReceiverIntent(apiBase, apiData);
+ apiCallSearchReceiverIntent
+ .setAction(Search.ACTION); //override default receiver action
+ String jsonRequest = JSONHandler.createRequestJSON("id", apiData);
+
+ OpenLPHttpClient httpClient =
+ getApiConfiguredClient(apiBase, jsonRequest);
+ HttpReturn result = httpClient.handleExecute();
+
+ if (result.isError()) {
+ apiCallSearchReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(result.getErrorMessage(
+ String.valueOf(R.string.apiCallIntent_search))));
+ apiCallSearchReceiverIntent.setAction(Search.ACTION);
+ } else {
+ Log.d(LOG_TAG, "searchPluginCall result: " + result.getData());
+ }
+
+ return apiCallSearchReceiverIntent;
+ }
+
+ private Intent executeAlert(String alertData)
+ throws IOException, URISyntaxException {
+ Intent apiCallReceiverIntent =
+ new WebCallReceiverIntent(Api.ALERT, alertData);
+ OpenLPHttpClient httpClient =
+ getApiConfiguredClient(Api.ALERT, alertData);
+
+ HttpReturn result = httpClient.handleExecute();
+ if (result.isError()) {
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(result.getErrorMessage(
+ String.valueOf(R.string.apiCallIntent_alert))));
+ } else {
+ Log.d(LOG_TAG, "Alert result: " + result.getData());
+ }
+
+ return apiCallReceiverIntent;
+ }
+
+ private Intent executeNavigation(final String apiBase, final String apiData)
+ throws IOException, URISyntaxException {
+ Intent apiCallReceiverIntent =
+ new WebCallReceiverIntent(apiBase, apiData);
+ OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase, apiData);
+
+ HttpReturn result = httpClient.handleExecute();
+ if (result.isError()) {
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(result.getErrorMessage(
+ String.valueOf(R.string.apiCallIntent_navigation))));
+ } else {
+ Log.d(LOG_TAG, "Navigation result: " + result.getData());
+ }
+
+ return apiCallReceiverIntent;
+ }
+
+ private Intent executeSetData(String apiBase, int position)
+ throws JSONHandler.JSONHandlerException, IOException,
+ URISyntaxException {
+ String request = JSONHandler.createRequestJSON("id", Integer.toString(position));
+ Intent apiCallreceiverIntent = new WebCallReceiverIntent(apiBase, request);
+ OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase, request);
+
+ HttpReturn result = httpClient.handleExecute();
+ if (result.isError()) {
+ String message = String.format(
+ "Unexpected null result while setting list data. apiBase(%s), position(%s)",
+ apiBase, position);
+ Log.e(LOG_TAG, message);
+ apiCallreceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(result.getErrorMessage(
+ String.valueOf(R.string.apiCallIntent_list_data))));
+ } else {
+ Log.d(LOG_TAG, "setData result: " + result.getData());
+ }
+
+ return apiCallreceiverIntent;
+ }
+
+ private Intent executePoll() throws IOException, URISyntaxException,
+ JSONHandler.JSONHandlerException {
+ Intent apiCallReceiverIntent = new WebCallReceiverIntent(Api.POLL_STATUS, "");
+ OpenLPHttpClient httpClient = getApiConfiguredClient(Api.POLL_STATUS);
+
+ HttpReturn pollJson = httpClient.handleExecute();
+ if (pollJson.isError()) {
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(pollJson.getErrorMessage(
+ String.valueOf(R.string.apiCallIntent_poll))));
+ } else {
+ Log.d(LOG_TAG, "Poll result: " + pollJson);
+ apiCallReceiverIntent.putExtra("pollJson", pollJson.getData());
+ }
+ return apiCallReceiverIntent;
+ }
+
+ private Intent executeItemFetch(final String apiBase)
+ throws IOException, URISyntaxException {
+ Intent apiCallReceiverIntent = new WebCallReceiverIntent(apiBase, "");
+ OpenLPHttpClient httpClient = getApiConfiguredClient(apiBase);
+
+ HttpReturn itemsJson = httpClient.handleExecute();
+ if (itemsJson.isError()) {
+ apiCallReceiverIntent = new WebCallReceiverIntent(
+ new WebCallReceiverIntentError(
+ itemsJson.getErrorMessage(String.valueOf(R.string.apiCallIntent_fetch))));
+ } else {
+ Log.d(LOG_TAG, "Items JSON: " + itemsJson);
+ apiCallReceiverIntent.putExtra("itemsJson", itemsJson.getData());
+ }
+ return apiCallReceiverIntent;
+ }
+
+ private OpenLPHttpClient getApiConfiguredClient(String apiBase,
+ String partData) throws MalformedURLException, URISyntaxException {
+ OpenLPHttpClient httpClient =
+ new OpenLPHttpClient(getApplicationContext());
+ httpClient.setUrl(String.format("%s%s", apiBase, partData));
+ return httpClient;
+ }
+
+ private OpenLPHttpClient getApiConfiguredClient(String apiBase)
+ throws MalformedURLException, URISyntaxException {
+ return getApiConfiguredClient(apiBase, "");
+ }
+
+ private final String LOG_TAG = ApiCallIntent.class.getName();
+
+ class WebCallReceiverIntent extends Intent {
+ WebCallReceiverIntent() {
+ setDefaults();
+ }
+
+ WebCallReceiverIntent(WebCallReceiverIntentError error) {
+ setDefaults();
+ WebCallReceiverIntent.this.putExtra("error", error.message);
+ }
+
+ WebCallReceiverIntent(String apiBase, String apiData) {
+ setDefaults();
+ WebCallReceiverIntent.this.putExtra("apiBase", apiBase);
+ WebCallReceiverIntent.this.putExtra("apiData", apiData);
+ }
+
+ private void setDefaults() {
+ WebCallReceiverIntent.this.setAction(API_CALL_RECEIVE);
+ WebCallReceiverIntent.this.addCategory(Intent.CATEGORY_DEFAULT);
+ }
+ }
+
+ class WebCallReceiverIntentError {
+ final String message;
+
+ WebCallReceiverIntentError(String error) {
+ this.message = error;
+ }
+ }
}
=== modified file 'src/org/openlp/android/service/PingIntent.java'
--- src/org/openlp/android/service/PingIntent.java 2012-05-06 15:53:56 +0000
+++ src/org/openlp/android/service/PingIntent.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/utility/GroupExpandableListAdapter.java'
--- src/org/openlp/android/utility/GroupExpandableListAdapter.java 2012-03-04 17:20:44 +0000
+++ src/org/openlp/android/utility/GroupExpandableListAdapter.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/utility/JSONHandler.java'
--- src/org/openlp/android/utility/JSONHandler.java 2012-05-05 17:34:31 +0000
+++ src/org/openlp/android/utility/JSONHandler.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/utility/OpenLPController.java'
--- src/org/openlp/android/utility/OpenLPController.java 2012-07-31 17:13:08 +0000
+++ src/org/openlp/android/utility/OpenLPController.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
@@ -26,14 +26,17 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.net.http.SslError;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
+import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
@@ -360,6 +363,15 @@
private WebView getWebViewFromView(View view) {
WebView myWebView = (WebView) view.findViewById(R.id.stageview);
+ /*
+ * Handle SSL self signed certificates and refresh the screen if the certificate
+ * page appears.
+ */
+ myWebView.setWebViewClient(new WebViewClient() {
+ public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
+ handler.proceed() ;
+ }
+ } );
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
@@ -369,7 +381,6 @@
myWebView.setScrollbarFadingEnabled(true);
myWebView.loadUrl(getUrlBase());
-
return myWebView;
}
=== modified file 'src/org/openlp/android/utility/OpenLPHttpClient.java'
--- src/org/openlp/android/utility/OpenLPHttpClient.java 2012-05-23 21:37:47 +0000
+++ src/org/openlp/android/utility/OpenLPHttpClient.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
@@ -47,6 +47,9 @@
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
@@ -57,11 +60,11 @@
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.openlp.android.R;
+import org.openlp.android.data.HttpReturn;
/**
* Personalised HttpClient to be used throughout OpenLP with customisable
* parameters.
- * todo: accomodate https
*/
public class OpenLPHttpClient extends DefaultHttpClient {
@@ -69,6 +72,7 @@
private URL url;
private final String urlBase;
private SSLSocketFactory sslSocketFactory;
+ private Context context;
public OpenLPHttpClient(Context context) {
SharedPreferences preferences = context.getSharedPreferences(
@@ -76,6 +80,8 @@
Context.MODE_PRIVATE);
HttpParams httpParams = new BasicHttpParams();
+ this.context = context;
+
Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
String port = preferences.getString(
@@ -83,7 +89,6 @@
context.getString(R.string.portDefaultValue)
);
-
SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
if (!useSsl) {
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
@@ -107,7 +112,23 @@
}
- urlBase = String.format("http%s://%s:%s",
+ String userid = preferences.getString(
+ context.getString(R.string.key_userid),
+ context.getString(R.string.useridDefaultValue)
+ );
+
+
+ String password = preferences.getString(
+ context.getString(R.string.key_password),
+ context.getString(R.string.passwordDefaultValue)
+ );
+
+ Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
+
+ Credentials creds = new UsernamePasswordCredentials(userid, password);
+ getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);
+
+ urlBase = String.format("http%s://%s:%s",
useSsl ? "s" : "",
preferences.getString(
context.getString(R.string.keyHost),
@@ -158,9 +179,11 @@
return super.execute(httpGet);
}
- public String handleExecute() throws IOException {
+ public HttpReturn 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();
@@ -175,10 +198,10 @@
line = bufferedReader.readLine();
}
bufferedReader.close();
- return stringBuilder.toString();
+ return new HttpReturn(0, stringBuilder.toString(), this.context);
}
}
- return null;
+ return new HttpReturn(response.getStatusLine().getStatusCode() , null, this.context);
}
public HttpEntity handleAndReturnEntity() throws IOException {
@@ -190,7 +213,8 @@
return null;
}
- private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, IOException, CertificateException {
+ private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
+ UnrecoverableKeyException, IOException, CertificateException {
final SSLContext sslContext = SSLContext.getInstance("TLS");
X509TrustManager trustManager = new X509TrustManager() {
@Override
@@ -217,7 +241,8 @@
}
@Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
+ UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
};
=== modified file 'src/org/openlp/android/utility/SlideAdapter.java'
--- src/org/openlp/android/utility/SlideAdapter.java 2012-05-05 17:34:31 +0000
+++ src/org/openlp/android/utility/SlideAdapter.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/utility/StringHelper.java'
--- src/org/openlp/android/utility/StringHelper.java 2012-03-04 10:56:34 +0000
+++ src/org/openlp/android/utility/StringHelper.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
=== modified file 'src/org/openlp/android/utility/WebCallReturningAsyncTask.java'
--- src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2012-05-24 21:06:55 +0000
+++ src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2013-04-07 12:27:25 +0000
@@ -1,8 +1,8 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman *
- * Portions copyright (c) 2011-2012 Tim Bentley, Johan Mynhardt, Samuel *
+ * Copyright (c) 2011-2013 Raoul Snyman *
+ * Portions copyright (c) 2011-2013 Tim Bentley, Johan Mynhardt, Samuel *
* Sjöbergsson *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
Follow ups