← Back to team overview

openlp-android team mailing list archive

[Merge] lp:~johanmynhardt/openlp/android into lp:openlp/android

 

Johan Mynhardt has proposed merging lp:~johanmynhardt/openlp/android into lp:openlp/android.

Requested reviews:
  Tim Bentley (trb143)

For more details, see:
https://code.launchpad.net/~johanmynhardt/openlp/android/+merge/107291

Connection profile management - the ability to add and remove server configurations.
Improved workflow and value updates.

Known 'bugs': 
* stage view not working when using SSL.
* indication of current profile
 - When activating a profile, it just sets the values for the keys being used for the connection,
     not an object. The address and port values can be changed on the 'home' preference screen
     without the profile being touched. Keeping track of what changed and is difficult (at this stage)
     and therefore no indication of selected profile.
-- 
https://code.launchpad.net/~johanmynhardt/openlp/android/+merge/107291
Your team OpenLP Android Developers is subscribed to branch lp:openlp/android.
=== modified file 'AndroidManifest.xml'
--- AndroidManifest.xml	2012-05-12 19:40:12 +0000
+++ AndroidManifest.xml	2012-05-24 21:34:23 +0000
@@ -31,7 +31,8 @@
                     android:resource="@xml/searchable"/>
         </activity>
 
-		<activity android:name=".activity.Preferences" android:label="@string/preferences"/>
+		<activity android:name=".activity.preference.Preferences" android:label="@string/preferences"/>
+		<activity android:name=".activity.preference.ConnectionPreferenceActivity"/>
 		<activity android:name=".activity.PagerActivity"/>
 
         <service android:name=".service.PingIntent"/>

=== modified file 'OpenLP.apk'
Binary files OpenLP.apk	2012-05-18 17:55:42 +0000 and OpenLP.apk	2012-05-24 21:34:23 +0000 differ
=== added file 'res/menu/connections_menu.xml'
--- res/menu/connections_menu.xml	1970-01-01 00:00:00 +0000
+++ res/menu/connections_menu.xml	2012-05-24 21:34:23 +0000
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android";>
+	<item
+		android:id="@+id/menuAddHost"
+		android:enabled="true"
+		android:title="Add Host"
+		android:titleCondensed="Add"/>
+</menu>

=== modified file 'res/values/defaultValues.xml'
--- res/values/defaultValues.xml	2012-05-06 15:53:56 +0000
+++ res/values/defaultValues.xml	2012-05-24 21:34:23 +0000
@@ -2,11 +2,12 @@
     <!-- STRING -->
     <string name="hostDefaultValue">192.168.1.1</string>
     <string name="portDefaultValue">4316</string>
+	<string name="ssl.port.default">4317</string>
     <string name="displayTypeValue">@string/displayScreen</string>
 
     <!-- INTEGER -->
     <integer name="socketTimeoutDefaultValue">3000</integer>
     <integer name="connectionTimeoutDefaultValue">3000</integer>
     <string name="backgroundRefreshDefaultValue">5000</string>
-    <integer name="textSizeDefaultValue">14</integer>    
+    <integer name="textSizeDefaultValue">14</integer>
 </resources>

=== modified file 'res/values/keyStrings.xml'
--- res/values/keyStrings.xml	2012-05-05 17:29:57 +0000
+++ res/values/keyStrings.xml	2012-05-24 21:34:23 +0000
@@ -8,4 +8,5 @@
     <string name="keyHost">keyHost</string>
     <string name="keyPort">keyPort</string>
     <string name="keySharedPreferences">keySharedPreferences</string>
-</resources>
\ No newline at end of file
+	<string name="key.ssl.use">ssl.use</string>
+</resources>

=== modified file 'res/values/strings.xml'
--- res/values/strings.xml	2012-05-18 18:06:34 +0000
+++ res/values/strings.xml	2012-05-24 21:34:23 +0000
@@ -72,4 +72,17 @@
 	<string name="requestFailed">Request Failed</string>
 	<string name="couldNotHandleLiveItems">Could not handle live items</string>
 	<string name="couldNotHandleServiceItems">Could not handle service items</string>
+	<string name="connection.profiles">Connection Profiles</string>
+	<string name="connection.profiles.manage">Manage Profiles</string>
+	<string name="connection.profile.active">Active Profile</string>
+	<string name="connection.profile.summary.activate">Set this profile as the active profile</string>
+	<string name="connection.profile.activate">Activate</string>
+	<string name="connection.profile.server">Server</string>
+	<string name="connection.profile.remove">Remove</string>
+	<string name="connection.profile.remove.summary">Remove this configuration</string>
+	<string name="notSet">Not set</string>
+	<string name="title.ssl.use">Use SSL</string>
+	<string name="summary.ssl.use">Specify whether SSL should be used</string>
+	<string name="connection.available.configurations">List of available profiles</string>
+	<string name="connection.add.by.menu">Add a config via the menu</string>
 </resources>

=== added file 'res/xml/empty_preferences.xml'
--- res/xml/empty_preferences.xml	1970-01-01 00:00:00 +0000
+++ res/xml/empty_preferences.xml	2012-05-24 21:34:23 +0000
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android";>
+
+</PreferenceScreen>

=== modified file 'res/xml/preferences.xml'
--- res/xml/preferences.xml	2012-05-18 17:55:42 +0000
+++ res/xml/preferences.xml	2012-05-24 21:34:23 +0000
@@ -22,7 +22,7 @@
                 android:defaultValue="@string/displayTypeValue"/>  
     </PreferenceCategory>
     <PreferenceCategory
-            android:title="@string/preferenceCategoryTitleServer">
+            android:title="@string/preferenceCategoryTitleServer" android:key="category.server">
         <EditTextPreference
                 android:title="@string/url"
                 android:key="@string/keyHost"
@@ -35,6 +35,10 @@
                 android:key="@string/keyPort"
                 android:name="@string/url"
                 android:inputType="number"/>
+		<CheckBoxPreference
+			android:title="@string/title.ssl.use"
+			android:key="@string/key.ssl.use"
+			android:summary="@string/summary.ssl.use"/>
     </PreferenceCategory>
     <PreferenceCategory
             android:title="@string/backgroundService">

=== modified file 'src/org/openlp/android/OpenLP.java'
--- src/org/openlp/android/OpenLP.java	2012-05-05 17:29:57 +0000
+++ src/org/openlp/android/OpenLP.java	2012-05-24 21:34:23 +0000
@@ -27,7 +27,7 @@
 import android.view.View;
 import org.openlp.android.activity.DefaultActivity;
 import org.openlp.android.activity.PagerActivity;
-import org.openlp.android.activity.Preferences;
+import org.openlp.android.activity.preference.Preferences;
 import org.openlp.android.utility.OpenLPController;
 
 import static org.openlp.android.utility.OpenLPController.getPageForButton;

=== modified file 'src/org/openlp/android/activity/DefaultActivity.java'
--- src/org/openlp/android/activity/DefaultActivity.java	2012-05-05 17:34:31 +0000
+++ src/org/openlp/android/activity/DefaultActivity.java	2012-05-24 21:34:23 +0000
@@ -26,6 +26,7 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import org.openlp.android.R;
+import org.openlp.android.activity.preference.Preferences;
 import org.openlp.android.api.Api;
 
 

=== removed file 'src/org/openlp/android/activity/Preferences.java'
--- src/org/openlp/android/activity/Preferences.java	2012-05-18 17:55:42 +0000
+++ src/org/openlp/android/activity/Preferences.java	1970-01-01 00:00:00 +0000
@@ -1,126 +0,0 @@
-/******************************************************************************
- * OpenLP - Open Source Lyrics Projection                                      *
- * --------------------------------------------------------------------------- *
- * Copyright (c) 2011-2012 Raoul Snyman                                        *
- * Portions copyright (c) 2011-2012 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.activity;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.os.Bundle;
-import android.preference.*;
-import android.util.Log;
-import org.openlp.android.R;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Credits: http://www.kaloer.com/android-preferences
- * http://androidpartaker.wordpress.com/2010/07/11/android-preferences/
- */
-public class Preferences extends PreferenceActivity {
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        Log.d(LOG_TAG, "Launching preferences");
-        getPreferenceManager().setSharedPreferencesName(
-                getString(R.string.keySharedPreferences));
-        addPreferencesFromResource(R.xml.preferences);
-
-        PackageManager manager = this.getPackageManager();
-        String version = "";
-        try {
-            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
-            version = info.versionName;
-        } catch (PackageManager.NameNotFoundException e) {
-            // Nop as version defined
-        }
-        Date date = new Date();
-        SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy");
-
-        /* Preferences time! (we build the preferences) */
-        Preference about = getPreference(getResources().getString(R.string.about_text), version, null);
-        Preference openlpLink = getPreference(getResources().getString(R.string.about_display_3), getResources().getString(R.string.about_display_1), new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/";)));
-
-        StringBuffer html = new StringBuffer();
-        html.append(getResources().getString(R.string.about_display_4));
-        html.append(" © 2004-");
-        html.append(simpleDateformat.format(date));
-        html.append(" Raoul Snyman\n");
-        html.append(getResources().getString(R.string.about_display_5));
-        html.append(" © 2004-");
-        html.append(simpleDateformat.format(date));
-        html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
-        Preference copyright = getPreference(getResources().getString(R.string.about_display_4), html.toString(), null);
-
-        DialogPreference license = new MyDialogPreference(this, getResources().getString(R.string.about_display_6), getResources().getString(R.string.about_display_7) + "\n" + getResources().getString(R.string.about_display_8));
-
-        PreferenceScreen preferenceScreen = getPreferenceScreen();
-        addPreferenceCategory(preferenceScreen, getResources().getString(R.string.about), about, openlpLink, copyright, license);
-        this.setPreferenceScreen(preferenceScreen);
-    }
-
-    private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,
-                                          String titleCategory, Preference... preferences) {
-        boolean addPreference = false;
-        for (Preference preference : preferences) {
-            if (preference != null)
-                addPreference = true;
-        }
-        if (addPreference) {
-            PreferenceCategory preferenceCategory = new PreferenceCategory(this);
-            preferenceCategory.setTitle(titleCategory);
-            preferenceScreen.addPreference(preferenceCategory);
-            for (Preference preference : preferences) {
-                if (preference != null)
-                    preferenceCategory.addPreference(preference);
-            }
-            return true;
-        } else
-            return false;
-    }
-
-    private Preference getPreference(String title, String summary, Intent intent) {
-        Preference pref = new Preference(this);
-        pref.setTitle(title);
-        pref.setSummary(summary);
-        if (intent != null)
-            pref.setIntent(intent);
-        return pref;
-    }
-
-    public class MyDialogPreference extends DialogPreference {
-        public MyDialogPreference(Context context, String title, String text) {
-            super(context, null);
-            this.setTitle(title);
-            this.setDialogMessage(text);
-        }
-    }
-
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        Log.d(LOG_TAG, "Destroying preferences");
-    }
-
-    private final String LOG_TAG = Preferences.class.getName();
-}

=== added directory 'src/org/openlp/android/activity/preference'
=== added file 'src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java'
--- src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java	1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java	2012-05-24 21:34:23 +0000
@@ -0,0 +1,343 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection                                      *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2011-2012 Raoul Snyman                                        *
+ * Portions copyright (c) 2011-2012 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.activity.preference;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+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;
+
+/**
+ * @todo: if no host config is set, use the default settings as Server 1
+ */
+public class ConnectionPreferenceActivity extends PreferenceActivity {
+	public static final String KEY_PREFERENCE_DISPALAY = "preferenceDisplay";
+
+	private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
+	private PreferenceScreen preferenceScreen = null;
+
+	private final String PREFERENCE_LIST_SERVERS = "listServers";
+	private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
+
+	private final String KEY_SERVER_ID = "keyServerId";
+	private boolean resume = true;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		addPreferencesFromResource(R.xml.empty_preferences);
+		getPreferenceManager().setSharedPreferencesName(getString(R.string.keySharedPreferences));
+		preferenceScreen = getPreferenceScreen() == null
+				? getPreferenceManager().createPreferenceScreen(this)
+				: getPreferenceScreen();
+		preferenceScreen.removeAll();
+		String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPALAY);
+		if (preferenceDisplay != null && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
+			constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
+		} else {
+			resume = false;
+			constructOverviewScreen();
+		}
+	}
+
+	private void constructOverviewScreen() {
+		getPreferenceScreen().removeAll();
+		Log.i(LOG_TAG, "constructOverviewScreen");
+		Preference configPref = new Preference(this);
+		configPref.setTitle(getString(R.string.connection_available_configurations));
+		configPref.setSummary(getString(R.string.connection_add_by_menu));
+		configPref.setSelectable(false);
+		preferenceScreen.addPreference(configPref);
+		List<HostConfig> hostConfigs = getHostConfigs();
+		if (!hostConfigs.isEmpty()) {
+			for (final HostConfig config : getHostConfigs()) {
+				preferenceScreen.addPreference(simpleClickablePreferenceFromHostConfig(config));
+			}
+		} else {
+			HostConfig config = hostConfigFromPreferencesForHostId(
+										1, getPreferenceManager().getSharedPreferences().getAll()
+								);
+			Preference defaultPreference = simpleClickablePreferenceFromHostConfig(config);
+			preferenceScreen.addPreference(defaultPreference);
+			defaultPreference.getEditor().commit();
+		}
+	}
+
+	private void constructServerView(int hostId) {
+		HostConfig hostConfig = hostConfigFromPreferencesForHostId(
+				hostId,
+				getHostConfigMap(
+						getPreferenceManager()
+								.getSharedPreferences()
+								.getAll()
+				)
+		);
+		addPreferenceCategory(preferenceScreen, hostConfig);
+	}
+
+	private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
+		final Preference serverConfig = new Preference(this);
+		serverConfig.setTitle(config.title);
+		serverConfig.setSummary(String.format("%s:%s", config.hostAddress.getText(), config.hostPort.getText()));
+		serverConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+			@Override
+			public boolean onPreferenceClick(Preference preference) {
+				Intent serverConfigIntent = new Intent(ConnectionPreferenceActivity.this, ConnectionPreferenceActivity.class);
+				serverConfigIntent.putExtra(KEY_PREFERENCE_DISPALAY, PREFERENCE_DISPLAY_SERVER);
+				serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
+				startActivity(serverConfigIntent);
+				return true;
+			}
+		});
+		return serverConfig;
+	}
+
+	private List<HostConfig> getHostConfigs() {
+		return hostConfigsFromPreferences(
+				getHostConfigMap(
+						getPreferenceManager()
+								.getSharedPreferences()
+								.getAll()
+				)
+		);
+	}
+
+	private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
+		Map<String, Object> configMap = new TreeMap<String, Object>();
+
+		List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
+		Collections.sort(sortedKeys);
+		for (String key : sortedKeys) {
+			if (key.startsWith(HostConfig.KEY_PREFIX)) {
+				configMap.put(key, preferences.get(key));
+			}
+		}
+		return configMap;
+	}
+
+	private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
+		List<Integer> hostIds = getHostIds(preferences);
+		List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
+		for (Integer id : hostIds) {
+			hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
+		}
+		return hostConfigs;
+	}
+
+	private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
+		HostConfig hostConfig = new HostConfig(getString(R.string.connection_profile_server), hostId);
+		Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
+		String hostValue = hostValueObject == null ? 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);
+		return hostConfig;
+	}
+
+	private int getNextPrefId(Map<String, ?> preferences) {
+		int max = 0;
+		for (String key : preferences.keySet()) {
+			int prefValue = Integer.valueOf(key.split("\\.")[2]);
+			max = prefValue > max ? prefValue : max;
+		}
+		return max + 1;
+	}
+
+	private List<Integer> getHostIds(Map<String, ?> preferences) {
+		Set<Integer> hashSet = new HashSet<Integer>();
+		for (String key : preferences.keySet()) {
+			hashSet.add(Integer.valueOf(key.split("\\.")[2]));
+		}
+		List<Integer> hostIds = new ArrayList<Integer>(hashSet);
+		Collections.sort(hostIds);
+		Log.i(LOG_TAG, "Got HostIds: " + hostIds);
+		return hostIds;
+	}
+
+	private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
+		PreferenceCategory preferenceCategory = new PreferenceCategory(this);
+		preferenceCategory.setTitle(hostConfig.title);
+		preferenceScreen.addPreference(preferenceCategory);
+		preferenceCategory.addPreference(hostConfig.hostAddress);
+		preferenceCategory.addPreference(hostConfig.hostPort);
+		preferenceCategory.addPreference(hostConfig.remove);
+		preferenceCategory.addPreference(hostConfig.activate);
+		return true;
+	}
+
+	@Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		MenuInflater inflater = getMenuInflater();
+		inflater.inflate(R.menu.connections_menu, menu);
+		return true;
+	}
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item) {
+		switch (item.getItemId()) {
+			case R.id.preferences:
+				startActivity(new Intent(this, Preferences.class));
+				return true;
+			case R.id.menuAddHost:
+				int nextId = getNextPrefId(
+						getHostConfigMap(
+								getPreferenceManager().getSharedPreferences().getAll()
+						)
+				);
+				preferenceScreen.addPreference(
+						simpleClickablePreferenceFromHostConfig(
+								new HostConfig(
+										getString(R.string.connection_profile_server),
+										nextId
+								)
+						)
+				);
+				return true;
+			default:
+				return super.onOptionsItemSelected(item);
+		}
+	}
+
+	@Override
+	protected void onResume() {
+		super.onResume();
+		if (resume) {
+			Log.i(LOG_TAG, "Resuming...");
+		} else {
+			constructOverviewScreen();
+			Log.i(LOG_TAG, "Not resuming...");
+		}
+	}
+
+	private class HostConfig {
+		static final String KEY_PREFIX = "host.config.";
+		final int id;
+		final String title;
+		final EditTextPreference hostAddress;
+		final EditTextPreference hostPort;
+		final Preference remove;
+		final Preference activate;
+
+		HostConfig(String title, int id) {
+			this.title = title + " " + id;
+			this.id = id;
+			hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
+			hostAddress.setTitle(getString(R.string.urlHint));
+			hostAddress.setKey(KEY_PREFIX + id + ".address");
+			hostAddress.setSummary(getString(R.string.urlHint));
+			hostAddress.setDialogTitle(getString(R.string.urlHint));
+			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");
+			hostPort.setSummary(getString(R.string.port));
+			hostPort.setDialogTitle(getString(R.string.port));
+			hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
+			hostPort.setDefaultValue(getString(R.string.portDefaultValue));
+			hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
+			remove = new Preference(ConnectionPreferenceActivity.this);
+			remove.setTitle(getString(R.string.connection_profile_remove));
+			remove.setSummary(getString(R.string.connection_profile_remove_summary));
+			remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+				@Override
+				public boolean onPreferenceClick(Preference preference) {
+					SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+					SharedPreferences.Editor editor = prefs.edit();
+					editor.remove(hostAddress.getKey());
+					editor.remove(hostPort.getKey());
+					editor.commit();
+					ConnectionPreferenceActivity.this.onBackPressed();
+					return false;
+				}
+			});
+
+			activate = new Preference(ConnectionPreferenceActivity.this);
+			activate.setTitle(getString(R.string.connection_profile_activate));
+			activate.setSummary(getString(R.string.connection_profile_summary_activate));
+			activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+				@Override
+				public boolean onPreferenceClick(Preference preference) {
+					SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
+					SharedPreferences.Editor editor = preferences.edit();
+					String host = preferences.getString(hostAddress.getKey(),
+							getString(R.string.hostDefaultValue));
+					editor.putString(getString(R.string.keyHost), host);
+					String port = preferences.getString(hostPort.getKey(),
+							getString(R.string.portDefaultValue));
+					editor.putString(getString(R.string.keyPort), port);
+					editor.commit();
+					Toast.makeText(ConnectionPreferenceActivity.this,
+							String.format(
+									"%s: %s [%s:%s]",
+									getString(R.string.connection_profile_active),
+									HostConfig.this.title,
+									host,
+									port
+							),
+							Toast.LENGTH_SHORT).show();
+					return false;
+				}
+			});
+		}
+
+		@Override
+		public String toString() {
+			return "HostConfig{" +
+					"id=" + id +
+					", title='" + title + '\'' +
+					", hostAddress=" + hostAddress.getKey() +
+					", hostPort=" + hostPort.getKey() +
+					'}';
+		}
+
+		Preference.OnPreferenceChangeListener onPreferenceChangeListener =
+				new Preference.OnPreferenceChangeListener() {
+					@Override
+					public boolean onPreferenceChange(Preference preference, Object o) {
+						preference.setSummary("" + o);
+						return true;
+					}
+				};
+	}
+}

=== added file 'src/org/openlp/android/activity/preference/Preferences.java'
--- src/org/openlp/android/activity/preference/Preferences.java	1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/activity/preference/Preferences.java	2012-05-24 21:34:23 +0000
@@ -0,0 +1,167 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection                                      *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2011-2012 Raoul Snyman                                        *
+ * Portions copyright (c) 2011-2012 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.activity.preference;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.DialogPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import org.openlp.android.R;
+
+/**
+ * Credits: http://www.kaloer.com/android-preferences
+ * http://androidpartaker.wordpress.com/2010/07/11/android-preferences/
+ */
+public class Preferences extends PreferenceActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Log.d(LOG_TAG, "Launching preferences");
+        buildPreferences();
+    }
+
+	private void buildPreferences() {
+		if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
+		getPreferenceManager().setSharedPreferencesName(
+				getString(R.string.keySharedPreferences));
+		addPreferencesFromResource(R.xml.preferences);
+		final SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
+
+		final Preference hostPreference = findPreference(getString(R.string.keyHost));
+		hostPreference.setSummary(
+				sharedPreferences.getString(getString(R.string.keyHost), getString(R.string.notSet))
+		);
+		Preference.OnPreferenceChangeListener onPreferenceChangeListener = new Preference.OnPreferenceChangeListener() {
+			@Override
+			public boolean onPreferenceChange(Preference preference, Object o) {
+				preference.setSummary("" + o);
+				return true;
+			}
+		};
+		hostPreference.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+		final Preference portPreference = findPreference(getString(R.string.keyPort));
+		portPreference.setSummary(
+				sharedPreferences.getString(getString(R.string.keyPort), getString(R.string.notSet))
+		);
+		portPreference.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+		PackageManager manager = this.getPackageManager();
+		String version = "";
+		try {
+			PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
+			version = info.versionName;
+		} catch (PackageManager.NameNotFoundException e) {
+			// Nop as version defined
+		}
+
+		String date = new SimpleDateFormat("yyyy").format(new Date());
+
+		/* Preferences time! (we build the preferences) */
+		Preference about = getPreference(getString(R.string.about_text), version, null);
+		Preference openlpLink = getPreference(getString(R.string.about_display_3), getString(R.string.about_display_1), new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/";)));
+
+		StringBuilder html = new StringBuilder();
+		html.append(getString(R.string.about_display_4));
+		html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
+		html.append(getString(R.string.about_display_5));
+		html.append(" © 2004-").append(date);
+		html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
+		Preference copyright = getPreference(getString(R.string.about_display_4), html.toString(), null);
+
+		DialogPreference license = new MyDialogPreference(this, getString(R.string.about_display_6), getString(R.string.about_display_7) + "\n" + getString(R.string.about_display_8));
+
+
+		PreferenceScreen preferenceScreen = getPreferenceScreen();
+		addPreferenceCategory(preferenceScreen, getString(R.string.about), about, openlpLink, copyright, license);
+
+		Preference preference = new Preference(this);
+		preference.setTitle(getString(R.string.connection_profiles_manage));
+		preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
+		preference.setKey("preference.manage.profiles");
+		PreferenceCategory preferenceCategory = ((PreferenceCategory) findPreference("category.server"));
+		if (findPreference("preference.manage.profiles") == null) preferenceCategory.addPreference(preference);
+	}
+
+    private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,
+                                          String titleCategory, Preference... preferences) {
+        boolean addPreference = false;
+        for (Preference preference : preferences) {
+            if (preference != null)
+                addPreference = true;
+        }
+        if (addPreference) {
+            PreferenceCategory preferenceCategory = new PreferenceCategory(this);
+            preferenceCategory.setTitle(titleCategory);
+            preferenceScreen.addPreference(preferenceCategory);
+            for (Preference preference : preferences) {
+                if (preference != null)
+                    preferenceCategory.addPreference(preference);
+            }
+            return true;
+        } else
+            return false;
+    }
+
+    private Preference getPreference(String title, String summary, Intent intent) {
+        Preference pref = new Preference(this);
+        pref.setTitle(title);
+        pref.setSummary(summary);
+        if (intent != null)
+            pref.setIntent(intent);
+        return pref;
+    }
+
+    public class MyDialogPreference extends DialogPreference {
+        public MyDialogPreference(Context context, String title, String text) {
+            super(context, null);
+            this.setTitle(title);
+            this.setDialogMessage(text);
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        Log.d(LOG_TAG, "Destroying preferences");
+    }
+
+	@Override
+	protected void onResume() {
+		super.onResume();
+		Log.i(LOG_TAG, "Resuming Preferences...");
+		buildPreferences();
+	}
+
+	private final String LOG_TAG = Preferences.class.getName();
+}

=== modified file 'src/org/openlp/android/utility/OpenLPController.java'
--- src/org/openlp/android/utility/OpenLPController.java	2012-05-05 14:12:12 +0000
+++ src/org/openlp/android/utility/OpenLPController.java	2012-05-24 21:34:23 +0000
@@ -604,7 +604,10 @@
 	}
 
 	private String getUrlBase() {
-		return String.format("http://%s:%s/stage";,
+		Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
+
+		return String.format("%s://%s:%s/stage",
+				useSsl ? "https" : "http",
 			preferences.getString(context.getString(R.string.keyHost),
 				context.getString(R.string.hostDefaultValue)),
 			preferences.getString(context.getString(R.string.keyPort),

=== modified file 'src/org/openlp/android/utility/OpenLPHttpClient.java'
--- src/org/openlp/android/utility/OpenLPHttpClient.java	2012-05-05 14:12:12 +0000
+++ src/org/openlp/android/utility/OpenLPHttpClient.java	2012-05-24 21:34:23 +0000
@@ -25,11 +25,22 @@
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
+import java.net.Socket;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
 
-import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
 
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -37,6 +48,10 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpConnectionParams;
@@ -53,20 +68,50 @@
 	private HttpGet httpGet;
 	private URL url;
 	private final String urlBase;
+	private SSLSocketFactory sslSocketFactory;
 
 	public OpenLPHttpClient(Context context) {
 		SharedPreferences preferences = context.getSharedPreferences(
 				context.getString(R.string.keySharedPreferences),
 				Context.MODE_PRIVATE);
-
-		Log.v(LOG_TAG, String.format("Preferences: %s", preferences.getAll().toString()));
 		HttpParams httpParams = new BasicHttpParams();
 
-		urlBase = String.format("http://%s:%s";, preferences.getString(
+		Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
+
+		String port = preferences.getString(
+				context.getString(R.string.keyPort),
+				context.getString(R.string.portDefaultValue)
+		);
+
+
+		SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
+		if (!useSsl) {
+			schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
+		} else {
+			try {
+				initSsl();
+				schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
+			} catch (NoSuchAlgorithmException e) {
+				Log.e(LOG_TAG, e.toString());
+			} catch (KeyManagementException e) {
+				Log.e(LOG_TAG, e.toString());
+			} catch (KeyStoreException e) {
+				Log.e(LOG_TAG, e.toString());
+			} catch (UnrecoverableKeyException e) {
+				Log.e(LOG_TAG, e.toString());
+			} catch (CertificateException e) {
+				e.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+
+		}
+
+		urlBase = String.format("http%s://%s:%s",
+				useSsl ? "s" : "",
+				preferences.getString(
 				context.getString(R.string.keyHost),
-				context.getString(R.string.hostDefaultValue)), preferences
-				.getString(context.getString(R.string.keyPort),
-						context.getString(R.string.portDefaultValue)));
+				context.getString(R.string.hostDefaultValue)), port);
 
 		int connectionTimeout = context.getResources().getInteger(
 				R.integer.connectionTimeoutDefaultValue);
@@ -129,8 +174,6 @@
 					stringBuilder.append(line);
 					line = bufferedReader.readLine();
 				}
-
-				Log.v(LOG_TAG, String.format("entity: %s",stringBuilder.toString()));
 				bufferedReader.close();
 				return stringBuilder.toString();
 			}
@@ -147,5 +190,39 @@
 		return null;
 	}
 
+	private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, IOException, CertificateException {
+		final SSLContext sslContext = SSLContext.getInstance("TLS");
+		X509TrustManager trustManager = new X509TrustManager() {
+			@Override
+			public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+			}
+
+			@Override
+			public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+			}
+
+			@Override
+			public X509Certificate[] getAcceptedIssuers() {
+				return null;
+			}
+		};
+		sslContext.init(null, new TrustManager[]{trustManager}, null);
+
+		KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyStore.load(null, null);
+		sslSocketFactory = new SSLSocketFactory(keyStore) {
+			@Override
+			public Socket createSocket() throws IOException {
+				return sslContext.getSocketFactory().createSocket();
+			}
+
+			@Override
+			public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
+				return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+			}
+		};
+		sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+	}
+
 	private final String LOG_TAG = OpenLPHttpClient.class.getName();
 }

=== modified file 'src/org/openlp/android/utility/WebCallReturningAsyncTask.java'
--- src/org/openlp/android/utility/WebCallReturningAsyncTask.java	2012-05-05 17:51:24 +0000
+++ src/org/openlp/android/utility/WebCallReturningAsyncTask.java	2012-05-24 21:34:23 +0000
@@ -27,8 +27,7 @@
 import android.widget.Toast;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
-import org.openlp.android.activity.Preferences;
-import org.openlp.android.utility.OpenLPHttpClient;
+import org.openlp.android.activity.preference.Preferences;
 
 import java.io.BufferedReader;
 import java.io.IOException;


Follow ups