← 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:
  OpenLP Android Developers (openlp-android)

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

Minor restructuring and improvements.

- Restructured resource files, 
- better error handling in terms of exception message display,
- Web call for button navigation now runs an AsyncTask with visual feedback. 
-- 
https://code.launchpad.net/~johanmynhardt/openlp/android/+merge/60123
Your team OpenLP Android Developers is requested to review the proposed merge of lp:~johanmynhardt/openlp/android into lp:openlp/android.
=== modified file '.bzrignore'
--- .bzrignore	2011-05-03 22:11:35 +0000
+++ .bzrignore	2011-05-05 21:37:23 +0000
@@ -6,3 +6,4 @@
 Openlp-android.iml
 Openlp-android-working.iml
 .classpath
+.settings

=== renamed file 'OpenLP.apk' => 'OpenLP.apk.OTHER'
Binary files OpenLP.apk	2011-05-04 20:23:50 +0000 and OpenLP.apk.OTHER	2011-05-05 21:37:23 +0000 differ
=== added file 'res/values-en/defaultValues.xml'
--- res/values-en/defaultValues.xml	1970-01-01 00:00:00 +0000
+++ res/values-en/defaultValues.xml	2011-05-05 21:37:23 +0000
@@ -0,0 +1,9 @@
+<resources>
+    <!-- STRING -->
+    <string name="urlDefaultValue">192.168.1.1</string>
+    <string name="portDefaultValue">4316</string>
+
+    <!-- INTEGER -->
+    <integer name="socketTimeoutDefaultValue">3000</integer>
+    <integer name="connectionTimeoutDefaultValue">3000</integer>
+</resources>
\ No newline at end of file

=== added file 'res/values-en/httpClientTimeoutValues.xml'
--- res/values-en/httpClientTimeoutValues.xml	1970-01-01 00:00:00 +0000
+++ res/values-en/httpClientTimeoutValues.xml	2011-05-05 21:37:23 +0000
@@ -0,0 +1,16 @@
+<resources>
+    <string-array name="socketValueEntries">
+		<item>3000</item>
+		<item>4000</item>
+		<item>5000</item>
+		<item>8000</item>
+		<item>10000</item>
+	</string-array>
+	<string-array name="socketValues">
+		<item>3000</item>
+		<item>4000</item>
+		<item>5000</item>
+		<item>8000</item>
+		<item>10000</item>
+	</string-array>
+</resources>
\ No newline at end of file

=== added file 'res/values-en/keyStrings.xml'
--- res/values-en/keyStrings.xml	1970-01-01 00:00:00 +0000
+++ res/values-en/keyStrings.xml	2011-05-05 21:37:23 +0000
@@ -0,0 +1,5 @@
+<resources>
+    <string name="keyEnableCustomTimeout">enableCustomTimeout</string>
+    <string name="keyConnectionTimeout">connectionTimeout</string>
+    <string name="keySocketTimeout">socketTimeout</string>
+</resources>
\ No newline at end of file

=== modified file 'res/values-en/strings.xml' (properties changed: +x to -x)
--- res/values-en/strings.xml	2011-05-03 22:35:46 +0000
+++ res/values-en/strings.xml	2011-05-05 21:37:23 +0000
@@ -2,7 +2,7 @@
 <resources>
     <string name="app_name">OpenLP</string>
     <string name="settings">Settings</string>
-	<string name="preferences">Preferences</string>
+    <string name="preferences">Preferences</string>
     <string name="exit">Exit</string>
     <string name="prev">Previous</string>
     <string name="next">Next</string>
@@ -13,19 +13,21 @@
     <string name="Slide">Slide</string>
     <string name="Service">Service</string>
     <string name="misc">Miscellaneous</string>
+    <string name="preferenceCategoryTitleServer">Server</string>
     <string name="url">Server</string>
-    <string name="urlDefaultValue">192.168.1.1</string>
     <string name="port">Port</string>
-    <string name="portDefaultValue">4316</string>
-    <string name="keyEnableCustomTimeout">enableCustomTimeout</string>
+    <string name="enableCustomTimeouts">Enable Custom Timeouts</string>
+    <string name="customTimeoutsSummary">Check to modify timeout settings</string>
     <string name="customTimeout">Custom Timeout</string>
     <string name="socketTimeout">Socket Timeout</string>
-    <string name="keySocketTimeout">socketTimeout</string>
-    <string name="connectionTimeout">Connection Timout</string>
-    <string name="keyConnectionTimeout">connectionTimeout</string>
+    <string name="socketTimeoutSummary">Select a value (milliseconds)</string>
+    <string name="connectionTimeout">Connection Timeout</string>
+    <string name="connectionTimeoutSummary">Select a value (milliseconds)</string>
     <string name="save">Save</string>
     <string name="unable">Unable to load page -</string>
     <string name="fail">Connection failed</string>
     <string name="jsonfail">JSON failed</string>
     <string name="loading">Connecting...</string>
+    <string name="loadingServiceItems">Loading service items...</string>
+
 </resources>

=== added file 'res/values/defaultValues.xml'
--- res/values/defaultValues.xml	1970-01-01 00:00:00 +0000
+++ res/values/defaultValues.xml	2011-05-05 21:37:23 +0000
@@ -0,0 +1,9 @@
+<resources>
+    <!-- STRING -->
+    <string name="urlDefaultValue">192.168.1.1</string>
+    <string name="portDefaultValue">4316</string>
+
+    <!-- INTEGER -->
+    <integer name="socketTimeoutDefaultValue">3000</integer>
+    <integer name="connectionTimeoutDefaultValue">3000</integer>
+</resources>
\ No newline at end of file

=== removed file 'res/values/integers.xml'
--- res/values/integers.xml	2011-04-30 22:36:35 +0000
+++ res/values/integers.xml	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-<resources>
-    <integer name="socketTimeoutDefaultValue">3000</integer>
-    <integer name="connectionTimeoutDefaultValue">3000</integer>
-</resources>
\ No newline at end of file

=== added file 'res/values/keyStrings.xml'
--- res/values/keyStrings.xml	1970-01-01 00:00:00 +0000
+++ res/values/keyStrings.xml	2011-05-05 21:37:23 +0000
@@ -0,0 +1,5 @@
+<resources>
+    <string name="keyEnableCustomTimeout">enableCustomTimeout</string>
+    <string name="keyConnectionTimeout">connectionTimeout</string>
+    <string name="keySocketTimeout">socketTimeout</string>
+</resources>
\ No newline at end of file

=== modified file 'res/values/strings.xml'
--- res/values/strings.xml	2011-05-03 22:35:46 +0000
+++ res/values/strings.xml	2011-05-05 21:37:23 +0000
@@ -13,19 +13,20 @@
     <string name="Slide">Slide</string>
     <string name="Service">Service</string>
     <string name="misc">Miscellaneous</string>
+    <string name="preferenceCategoryTitleServer">Server</string>
     <string name="url">Server</string>
-    <string name="urlDefaultValue">192.168.1.1</string>
     <string name="port">Port</string>
-    <string name="portDefaultValue">4316</string>
-    <string name="keyEnableCustomTimeout">enableCustomTimeout</string>
+    <string name="enableCustomTimeouts">Enable Custom Timeouts</string>
+    <string name="customTimeoutsSummary">Check to modify timeout settings</string>
     <string name="customTimeout">Custom Timeout</string>
     <string name="socketTimeout">Socket Timeout</string>
-    <string name="keySocketTimeout">socketTimeout</string>
-    <string name="connectionTimeout">Connection Timout</string>
-    <string name="keyConnectionTimeout">connectionTimeout</string>
+    <string name="socketTimeoutSummary">Select a value (milliseconds)</string>
+    <string name="connectionTimeout">Connection Timeout</string>
+    <string name="connectionTimeoutSummary">Select a value (milliseconds)</string>
     <string name="save">Save</string>
     <string name="unable">Unable to load page -</string>
     <string name="fail">Connection failed</string>
     <string name="jsonfail">JSON failed</string>
     <string name="loading">Connecting...</string>
+
 </resources>

=== modified file 'res/xml/preferences.xml'
--- res/xml/preferences.xml	2011-05-03 20:52:22 +0000
+++ res/xml/preferences.xml	2011-05-05 21:37:23 +0000
@@ -2,11 +2,11 @@
 <PreferenceScreen
         xmlns:android="http://schemas.android.com/apk/res/android";>
     <PreferenceCategory
-            android:title="Server">
+            android:title="@string/preferenceCategoryTitleServer">
         <EditTextPreference
                 android:title="@string/url"
                 android:key="url"
-                android:defaultValue="192.168.1.1"
+                android:defaultValue="@string/urlDefaultValue"
                 android:inputType="phone"
                 android:name="@string/url"/>
         <EditTextPreference
@@ -19,13 +19,13 @@
     <PreferenceCategory
             android:title="@string/customTimeout">
         <CheckBoxPreference
-                android:title="Enable Custom Timeouts"
+                android:title="@string/enableCustomTimeouts"
                 android:key="@string/keyEnableCustomTimeout"
-                android:summary="Check to modify timeout settings"/>
+                android:summary="@string/customTimeoutsSummary"/>
         <ListPreference
                 android:title="@string/connectionTimeout"
                 android:key="@string/keyConnectionTimeout"
-                android:summary="Select a value (milliseconds)"
+                android:summary="@string/connectionTimeoutSummary"
                 android:dependency="@string/keyEnableCustomTimeout"
                 android:entries="@array/socketValueEntries"
                 android:entryValues="@array/socketValues"
@@ -33,7 +33,7 @@
         <ListPreference
                 android:title="@string/socketTimeout"
                 android:key="@string/keySocketTimeout"
-                android:summary="Select a value (milliseconds)"
+                android:summary="@string/socketTimeoutSummary"
                 android:dependency="@string/keyEnableCustomTimeout"
                 android:entries="@array/socketValueEntries"
                 android:entryValues="@array/socketValues"

=== modified file 'src/org/openlp/android/Misc.java'
--- src/org/openlp/android/Misc.java	2011-05-03 20:52:22 +0000
+++ src/org/openlp/android/Misc.java	2011-05-05 21:37:23 +0000
@@ -22,6 +22,7 @@
  *******************************************************************************/
 package org.openlp.android;
 
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
@@ -35,16 +36,18 @@
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONStringer;
+import org.openlp.android.utility.WebCallAsyncTask;
 
 import java.io.UnsupportedEncodingException;
 
 public class Misc extends OpenLPActivity implements OpenLP.ApiActions {
+    private Context context = this;
     public Button.OnClickListener mBlank = new Button.OnClickListener() {
         @Override
         public void onClick(View v) {
             String urlAll = String.format("%s:%s%s", getURL(), getPort(), DISPLAY_HIDE);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
                 Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
@@ -57,7 +60,7 @@
         public void onClick(View v) {
             String urlAll = String.format("%s:%s%s", getURL(), getPort(), DISPLAY_SHOW);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
                 Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
@@ -84,7 +87,7 @@
             }
             String urlAll = String.format("%s:%s%s%s", getURL(), getPort(), ALERT, alert);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
                 Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();

=== modified file 'src/org/openlp/android/OpenLPActivity.java'
--- src/org/openlp/android/OpenLPActivity.java	2011-05-04 10:29:58 +0000
+++ src/org/openlp/android/OpenLPActivity.java	2011-05-05 21:37:23 +0000
@@ -26,6 +26,7 @@
 import android.content.SharedPreferences;
 import android.util.Log;
 import org.openlp.android.utility.OpenLPHttpClient;
+import org.openlp.android.utility.WebCallAsyncTask;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -42,14 +43,5 @@
         return prefs.getString("port", getString(R.string.portDefaultValue));
     }
 
-    public void webCall(String url) throws IOException, URISyntaxException {
-        OpenLPHttpClient httpclient = new OpenLPHttpClient(getApplicationContext());
-        httpclient.setUrl(new URL(url));
-
-        Log.d(LOG_TAG, "Executing request: " + httpclient.getUrl().toString());
-        httpclient.execute();
-
-    }
-
     private String LOG_TAG = OpenLPActivity.class.getName();
 }

=== modified file 'src/org/openlp/android/Service.java'
--- src/org/openlp/android/Service.java	2011-05-04 10:29:58 +0000
+++ src/org/openlp/android/Service.java	2011-05-05 21:37:23 +0000
@@ -23,6 +23,7 @@
 package org.openlp.android;
 
 import android.app.ProgressDialog;
+import android.content.Context;
 import android.content.Intent;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -43,6 +44,7 @@
 import org.json.JSONObject;
 import org.openlp.android.utility.OpenLPHttpClient;
 import org.openlp.android.utility.StringHelper;
+import org.openlp.android.utility.WebCallAsyncTask;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -57,6 +59,7 @@
  */
 public class Service extends OpenLPActivity implements OpenLP.ApiActions {
     private final String LOG_TAG = Service.class.getName();
+    private final Context context = this;
 
     private TextView txt;
 
@@ -85,10 +88,12 @@
         public void onClick(View v) {
             String urlAll = String.format("%s:%s%s", getURL(), getPort(), SERVICE_PREVIOUS);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
-                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
+                Toast.makeText(getApplicationContext(),
+                        String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()),
+                        Toast.LENGTH_SHORT).show();
             }
         }
     };
@@ -98,10 +103,12 @@
         public void onClick(View v) {
             String urlAll = String.format("%s:%s%s", getURL(), getPort(), SERVICE_NEXT);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
-                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
+                Toast.makeText(getApplicationContext(),
+                        String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()),
+                        Toast.LENGTH_SHORT).show();
             }
         }
     };
@@ -115,7 +122,6 @@
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
-        // Handle item selection
         switch (item.getItemId()) {
             case R.id.preferences:
                 startActivity(new Intent(this, Preferences.class));
@@ -139,7 +145,8 @@
         @Override
         protected void onPreExecute() {
             super.onPreExecute();
-            progressDialog = ProgressDialog.show(Service.this, getString(R.string.loading), "Loading service items...");
+            progressDialog = ProgressDialog.show(Service.this, getString(R.string.loading),
+                    getString(R.string.loadingServiceItems));
         }
 
         @Override
@@ -180,17 +187,21 @@
                     }
                 }
                 else {
-                    returnString = String.format("Unable to load page - %s", response.getStatusLine());
+                    returnString = String.format("%s %s", getString(R.string.unable), response.getStatusLine());
                 }
             }
             catch (JSONException ex) {
-                returnString = "JSON failed; " + ex.getMessage();
+                returnString = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
             }
             catch (IOException e) {
-                returnString = "IOException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
             }
             catch (URISyntaxException e) {
-                returnString = "URISyntaxException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+            }
+
+            if (returnString.trim().length() > 0) {
+                Log.e(LOG_TAG, returnString);
             }
             return returnString;
         }

=== modified file 'src/org/openlp/android/Slide.java'
--- src/org/openlp/android/Slide.java	2011-05-04 05:21:09 +0000
+++ src/org/openlp/android/Slide.java	2011-05-05 21:37:23 +0000
@@ -23,6 +23,7 @@
 package org.openlp.android;
 
 import android.app.ProgressDialog;
+import android.content.Context;
 import android.content.Intent;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -43,6 +44,7 @@
 import org.json.JSONObject;
 import org.openlp.android.utility.OpenLPHttpClient;
 import org.openlp.android.utility.StringHelper;
+import org.openlp.android.utility.WebCallAsyncTask;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -54,6 +56,7 @@
 import java.util.List;
 
 public class Slide extends OpenLPActivity implements OpenLP.ApiActions {
+    private final Context context = this;
     private final String LOG_TAG = Slide.class.getName();
     private TextView txt;
 
@@ -74,10 +77,12 @@
         public void onClick(View v) {
             String urlAll = String.format("%s:%s%s", getURL(), getPort(), LIVE_PREVIOUS);
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
-                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
+                Toast.makeText(getApplicationContext(),
+                        String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()),
+                        Toast.LENGTH_SHORT).show();
                 Log.e(LOG_TAG, e.toString(), e);
             }
         }
@@ -87,10 +92,12 @@
         public void onClick(View v) {
             String urlAll = getURL() + ":" + getPort() + LIVE_NEXT;
             try {
-                webCall(urlAll);
+                new WebCallAsyncTask(context).execute(urlAll);
             }
             catch (Exception e) {
-                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
+                Toast.makeText(getApplicationContext(),
+                        String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()),
+                        Toast.LENGTH_SHORT).show();
                 Log.e(LOG_TAG, e.toString(), e);
             }
         }
@@ -179,19 +186,23 @@
                 }
             }
             catch (JSONException ex) {
-                returnString = "JSON failed: " + ex.getMessage();
+                returnString = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
             }
             catch (MalformedURLException e) {
-                returnString = "MalformedURLException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
             }
             catch (IOException e) {
-                returnString = "IOException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
             }
             catch (URISyntaxException e) {
-                returnString = "URISyntaxException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
             }
             catch (IllegalArgumentException e) {
-                returnString = "IllegalArgumentException: " + e.getMessage();
+                returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+            }
+
+            if (returnString.trim().length() > 0) {
+                Log.e(LOG_TAG, returnString);
             }
             return returnString;
         }

=== modified file 'src/org/openlp/android/utility/StringHelper.java'
--- src/org/openlp/android/utility/StringHelper.java	2011-05-04 10:29:58 +0000
+++ src/org/openlp/android/utility/StringHelper.java	2011-05-05 21:37:23 +0000
@@ -33,11 +33,12 @@
 public class StringHelper {
     public synchronized static String convertStreamToString(InputStream is) {
         /*
-                     * To convert the InputStream to String we use the
-                     * BufferedReader.readLine() method. We iterate until the BufferedReader
-                     * return null which means there's no more data to read. Each line will
-                     * appended to a StringBuilder and returned as String.
-                     */
+            To convert the InputStream to String we use the
+            BufferedReader.readLine() method. We iterate until the BufferedReader
+            return null which means there's no more data to read. Each line will
+            appended to a StringBuilder and returned as String.
+        */
+
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         StringBuilder sb = new StringBuilder();
 

=== added file 'src/org/openlp/android/utility/WebCallAsyncTask.java'
--- src/org/openlp/android/utility/WebCallAsyncTask.java	1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/utility/WebCallAsyncTask.java	2011-05-05 21:37:23 +0000
@@ -0,0 +1,56 @@
+package org.openlp.android.utility;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.AsyncTask;
+import android.util.Log;
+import org.openlp.android.R;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * @author johan.mynhardt@xxxxxxxxxxxxxxx
+ * @version 2011.0505
+ *          Time: 10:51 PM
+ */
+public class WebCallAsyncTask extends AsyncTask<String, Void, Void> {
+    private final String LOG_TAG = WebCallAsyncTask.class.getName();
+    private Context context;
+    private ProgressDialog progressDialog;
+
+    public WebCallAsyncTask(Context context) {
+        this.context = context;
+    }
+
+    @Override
+    protected void onPreExecute() {
+        super.onPreExecute();
+        progressDialog = ProgressDialog.show(context, "", context.getString(R.string.loading));
+    }
+
+    @Override
+    protected Void doInBackground(String... url) {
+        OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
+        try {
+            httpClient.setUrl(new URL(url[0]));
+
+            Log.d(LOG_TAG, "Executing request: " + httpClient.getUrl().toString());
+            httpClient.execute();
+        }
+        catch (URISyntaxException e) {
+            Log.e(LOG_TAG, e.toString());
+        }
+        catch (IOException e) {
+            Log.e(LOG_TAG, e.toString());
+        }
+        return null;
+    }
+
+    @Override
+    protected void onPostExecute(Void aVoid) {
+        super.onPostExecute(aVoid);
+        progressDialog.dismiss();
+    }
+}


Follow ups