openlp-android team mailing list archive
-
openlp-android team
-
Mailing list archive
-
Message #00044
[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/61820
Click-able items in the Service and Slide ListViews, which send the service/slide live.
Improved Layout:
- previous and next buttons are now next to each other and at the bottom, which handles better on the hand.
- List item layout is better structured and slide item numbers or verse tags are now in bold white text.
JSON handler for parsing slide and service items and creating requests.
Added SlidePOJO to handle slide/service items parsed from the JSON response.
Better (less verbose) error handling inside the code.
--
https://code.launchpad.net/~johanmynhardt/openlp/android/+merge/61820
Your team OpenLP Android Developers is requested to review the proposed merge of lp:~johanmynhardt/openlp/android into lp:openlp/android.
=== modified file 'OpenLP.apk'
Binary files OpenLP.apk 2011-05-08 21:05:10 +0000 and OpenLP.apk 2011-05-20 19:56:46 +0000 differ
=== removed file 'res/layout/listitem.xml'
--- res/layout/listitem.xml 2011-03-12 18:34:47 +0000
+++ res/layout/listitem.xml 1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="0dip" android:layout_weight="1"
- android:layout_height="fill_parent">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/listitem" />
- </LinearLayout>
-</LinearLayout>
\ No newline at end of file
=== modified file 'res/layout/main.xml'
--- res/layout/main.xml 2011-03-08 21:02:48 +0000
+++ res/layout/main.xml 2011-05-20 19:56:46 +0000
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/tabhost"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
+ android:id="@android:id/tabhost"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
<LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="5dp">
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="5dp">
<TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
+ android:id="@android:id/tabs"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"/>
<FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="5dp" />
+ android:id="@android:id/tabcontent"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="0dp"/>
</LinearLayout>
</TabHost>
=== modified file 'res/layout/service.xml'
--- res/layout/service.xml 2011-05-07 20:01:46 +0000
+++ res/layout/service.xml 2011-05-20 19:56:46 +0000
@@ -1,26 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:baselineAligned="false"
android:orientation="vertical"
- android:layout_width="fill_parent"
android:layout_height="fill_parent">
- <Button
- android:text="@string/prev"
- android:id="@+id/prev"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <Button
- android:text="@string/next"
- android:id="@+id/next"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
-<!-- <TextView
- android:id="@+id/services"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>-->
- <ListView
- android:id="@+id/list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
+ <TableLayout
+ android:id="@+id/tableLayout1"
+ android:layout_width="fill_parent"
+ android:layout_gravity="fill"
+ android:layout_height="fill_parent">
+ <ListView
+ android:layout_gravity="top"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:id="@+id/list"
+ android:layout_width="fill_parent"/>
+ <LinearLayout
+ android:baselineAligned="false"
+ android:id="@+id/linearLayout1"
+ android:layout_width="fill_parent"
+ android:layout_gravity="fill"
+ android:layout_height="wrap_content"
+ android:layout_weight="0">
+ <Button
+ android:text="@string/prev"
+ android:layout_weight="1"
+ android:id="@+id/prev"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"/>
+ <Button
+ android:text="@string/next"
+ android:layout_weight="1"
+ android:id="@+id/next"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"/>
+ </LinearLayout>
+ </TableLayout>
</LinearLayout>
=== modified file 'res/layout/slide.xml'
--- res/layout/slide.xml 2011-05-07 20:01:46 +0000
+++ res/layout/slide.xml 2011-05-20 19:56:46 +0000
@@ -1,21 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="@string/prev"
- android:id="@+id/prev" android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
- <Button
- android:text="@string/next"
- android:id="@+id/next"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+ <TableLayout
+ android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
- <ListView
- android:id="@+id/list"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
+ android:layout_height="fill_parent">
+ <ListView
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:id="@+id/list"
+ android:layout_width="wrap_content"/>
+ <LinearLayout
+ android:layout_height="wrap_content"
+ android:id="@+id/linearLayout1"
+ android:layout_width="fill_parent">
+ <Button
+ android:text="@string/prev"
+ android:layout_weight="1"
+ android:id="@+id/prev"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_gravity="center_vertical"/>
+ <Button
+ android:text="@string/next"
+ android:layout_weight="1"
+ android:id="@+id/next"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_gravity="center"/>
+ </LinearLayout>
+ </TableLayout>
</LinearLayout>
=== added file 'res/layout/slide_list_item.xml'
--- res/layout/slide_list_item.xml 1970-01-01 00:00:00 +0000
+++ res/layout/slide_list_item.xml 2011-05-20 19:56:46 +0000
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <TextView
+ android:id="@+id/rowItemMarker"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:gravity="center"
+ android:textStyle="bold"
+ android:minWidth="40dip"
+ android:textColor="@color/white"
+ />
+ <TextView
+ android:id="@+id/rowItemText"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:gravity="center_vertical"
+ android:minLines="2"
+ android:textSize="8pt"/>
+</LinearLayout>
\ No newline at end of file
=== added file 'res/values/colors.xml'
--- res/values/colors.xml 1970-01-01 00:00:00 +0000
+++ res/values/colors.xml 2011-05-20 19:56:46 +0000
@@ -0,0 +1,4 @@
+<resources>
+ <color name="lightGreen">#ff66ff33</color>
+ <color name="white">#ffffffff</color>
+</resources>
\ No newline at end of file
=== modified file 'res/values/strings.xml'
--- res/values/strings.xml 2011-05-08 11:48:35 +0000
+++ res/values/strings.xml 2011-05-20 19:56:46 +0000
@@ -14,6 +14,7 @@
<string name="unblank">Unblank</string>
<string name="alert">Alert:</string>
<string name="alertHint">Enter alert message</string>
+ <string name="alertTextNull">Please enter a message to send.</string>
<string name="send">Send</string>
<string name="Slide">Slide</string>
<string name="slides">Slides</string>
=== modified file 'src/org/openlp/android/Misc.java'
--- src/org/openlp/android/Misc.java 2011-05-07 20:01:46 +0000
+++ src/org/openlp/android/Misc.java 2011-05-20 19:56:46 +0000
@@ -35,14 +35,10 @@
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONStringer;
import org.openlp.android.api.Api;
+import org.openlp.android.utility.JSONHandler;
import org.openlp.android.utility.WebCallAsyncTask;
-import java.io.UnsupportedEncodingException;
-
public class Misc extends Activity implements Api {
private final Context context = this;
@@ -52,22 +48,15 @@
EditText edittext = (EditText) findViewById(R.id.alert);
String alert;
try {
- JSONObject jo = new JSONObject();
- jo.put("text", edittext.getText());
- alert = new JSONStringer().object().key("request").value(jo).endObject().toString();
- alert = java.net.URLEncoder.encode(alert, "UTF-8");
- }
- catch (JSONException e) {
- alert = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
- catch (UnsupportedEncodingException e) {
- alert = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
-
- try {
- new WebCallAsyncTask(context).execute(String.format("%s%s", ALERT, alert));
- }
- catch (Exception e) {
+ if (edittext.getText().toString().trim().length() > 0) {
+ alert = JSONHandler.createRequestJSON("text", edittext.getText().toString());
+ new WebCallAsyncTask(context, ALERT).execute(alert);
+ }
+ else {
+ Toast.makeText(getBaseContext(), getString(R.string.alertTextNull), Toast.LENGTH_SHORT).show();
+ }
+ }
+ catch (JSONHandler.JSONHandlerException e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
=== modified file 'src/org/openlp/android/Service.java'
--- src/org/openlp/android/Service.java 2011-05-08 11:41:49 +0000
+++ src/org/openlp/android/Service.java 2011-05-20 19:56:46 +0000
@@ -24,7 +24,6 @@
import android.app.Activity;
import android.app.ProgressDialog;
-import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -33,24 +32,19 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.ArrayAdapter;
+import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.openlp.android.api.Api;
+import org.openlp.android.pojo.SlidePOJO;
+import org.openlp.android.utility.JSONHandler;
import org.openlp.android.utility.OpenLPHttpClient;
-import org.openlp.android.utility.StringHelper;
+import org.openlp.android.utility.SlideAdapter;
import org.openlp.android.utility.WebCallAsyncTask;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -59,7 +53,7 @@
*/
public class Service extends Activity implements Api {
private final String LOG_TAG = Service.class.getName();
- private final Context context = this;
+ private final Activity context = this;
private ListView listView;
@@ -72,6 +66,25 @@
listView = (ListView) findViewById(R.id.list);
findViewById(R.id.prev).setOnClickListener(mPrev);
findViewById(R.id.next).setOnClickListener(mNext);
+
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+ String alert;
+ try {
+ alert = JSONHandler.createRequestJSON("id", Integer.toString(i));
+ new WebCallAsyncTask(context, SERVICE_SET).execute(alert);
+ alert = null;
+ }
+ catch (JSONHandler.JSONHandlerException e) {
+ alert = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+ }
+
+ if (alert != null) {
+ Toast.makeText(getApplicationContext(), alert, Toast.LENGTH_LONG).show();
+ }
+ }
+ });
}
@Override
@@ -131,7 +144,7 @@
/**
* Asynchronous task to fetch the service items.
*/
- class FetchServiceItemsTask extends AsyncTask<String, String[], Void> {
+ class FetchServiceItemsTask extends AsyncTask<String, SlidePOJO[], Void> {
Service serviceActivity;
ProgressDialog progressDialog;
String error;
@@ -165,43 +178,24 @@
if (response != null && response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
- // If the response does not enclose an entity, there is no need
- // to worry about connection release
if (entity != null) {
- InputStream instream = entity.getContent();
- String result = StringHelper.convertStreamToString(instream);
- Log.i(LOG_TAG, result);
-
- // Build the return string.
- JSONObject jObject = new JSONObject(result);
- JSONObject results = jObject.getJSONObject("results");
- JSONArray items = results.getJSONArray("items");
- List<String> serviceItemList = new ArrayList<String>();
- returnString = "";
-
- for (int i = 0; i < items.length(); i++) {
- serviceItemList.add(items.getJSONObject(i).getString("title"));
- }
-
- instream.close();
-
+ List<SlidePOJO> serviceItemList = JSONHandler.parseServiceItemResponseJSON(entity);
Log.i(LOG_TAG, String.format("Service Items: %s", serviceItemList));
- publishProgress(serviceItemList.toArray(new String[]{}));
+ publishProgress(serviceItemList.toArray(new SlidePOJO[]{}));
}
}
else {
returnString = String.format("%s %s", getString(R.string.unable), response);
}
}
- catch (JSONException ex) {
- returnString = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
- }
- catch (IOException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
- catch (URISyntaxException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+ catch (Exception e) {
+ try {
+ throw new FetchItemsException(e);
+ }
+ catch (FetchItemsException e1) {
+ returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+ }
}
if (returnString.trim().length() > 0) {
@@ -212,9 +206,9 @@
}
@Override
- protected void onProgressUpdate(String[]... values) {
+ protected void onProgressUpdate(SlidePOJO[]... values) {
super.onProgressUpdate(values);
- listView.setAdapter(new ArrayAdapter<String>(serviceActivity, android.R.layout.simple_list_item_1, values[0]));
+ listView.setAdapter(new SlideAdapter(context, Arrays.asList(values[0])));
}
@Override
@@ -225,5 +219,11 @@
Toast.makeText(context, error, Toast.LENGTH_LONG).show();
}
}
+
+ class FetchItemsException extends Exception {
+ FetchItemsException(Throwable throwable) {
+ super(throwable);
+ }
+ }
}
}
\ No newline at end of file
=== modified file 'src/org/openlp/android/Slide.java'
--- src/org/openlp/android/Slide.java 2011-05-08 11:41:49 +0000
+++ src/org/openlp/android/Slide.java 2011-05-20 19:56:46 +0000
@@ -24,7 +24,6 @@
import android.app.Activity;
import android.app.ProgressDialog;
-import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -33,30 +32,24 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.ArrayAdapter;
+import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.openlp.android.api.Api;
+import org.openlp.android.pojo.SlidePOJO;
+import org.openlp.android.utility.JSONHandler;
import org.openlp.android.utility.OpenLPHttpClient;
-import org.openlp.android.utility.StringHelper;
+import org.openlp.android.utility.SlideAdapter;
import org.openlp.android.utility.WebCallAsyncTask;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Slide extends Activity implements Api {
- private final Context context = this;
+ private final Activity context = this;
private final String LOG_TAG = Slide.class.getName();
private ListView slideList;
@@ -69,6 +62,30 @@
findViewById(R.id.prev).setOnClickListener(mPrev);
findViewById(R.id.next).setOnClickListener(mNext);
+ slideList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+ String alert;
+ try {
+ alert = JSONHandler.createRequestJSON("id", Integer.toString(i));
+ new WebCallAsyncTask(context, LIVE_SET).execute(alert);
+ alert = null;
+ }
+ catch (Exception e) {
+ try {
+ throw new JSONHandler.JSONHandlerException(e);
+ }
+ catch (JSONHandler.JSONHandlerException e1) {
+ alert = String.format("%s: %s", e1.getClass().getSimpleName(), e1.getMessage());
+ }
+ }
+
+ if (alert != null) {
+ Toast.makeText(getApplicationContext(), alert, Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+
}
@Override
@@ -126,7 +143,7 @@
}
}
- class FetchSlideItemsTask extends AsyncTask<String, String[], Void> {
+ class FetchSlideItemsTask extends AsyncTask<String, SlidePOJO[], Void> {
Slide slideActivity;
ProgressDialog progressDialog;
String error;
@@ -159,52 +176,24 @@
if (response != null && response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
- // If the response does not enclose an entity, there is no need
- // to worry about connection release
if (entity != null) {
- InputStream instream = entity.getContent();
-
- String result = StringHelper.convertStreamToString(instream);
- Log.i(LOG_TAG, result);
-
- // Load the requested page converted to a string into a
- // JSONObject.
-
- // Build the return string.
- JSONObject jObject = new JSONObject(result);
- JSONObject results = jObject.getJSONObject("results");
- JSONArray slides = results.getJSONArray("slides");
- List<String> result1 = new ArrayList<String>();
- returnString = "";
-
- for (int i = 0; i < slides.length(); i++) {
- result1.add(slides.getJSONObject(i).getString("text"));
- }
-
- instream.close();
- Log.d(LOG_TAG, String.format("slides: %s", result1));
- publishProgress(result1.toArray(new String[]{}));
+ List<SlidePOJO> slideItemList = JSONHandler.parseSlideItemResponseJSON(entity);
+ Log.d(LOG_TAG, String.format("slides: %s", slideItemList));
+ publishProgress(slideItemList.toArray(new SlidePOJO[]{}));
}
}
else {
returnString = String.format("%s %s", getString(R.string.unable), response);
}
}
- catch (JSONException ex) {
- returnString = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
- }
- catch (MalformedURLException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
- catch (IOException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
- catch (URISyntaxException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
- }
- catch (IllegalArgumentException e) {
- returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+ catch (Exception ex) {
+ try {
+ throw new FetchItemsException(ex);
+ }
+ catch (FetchItemsException e) {
+ returnString = String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
+ }
}
if (returnString.trim().length() > 0) {
@@ -225,9 +214,15 @@
}
@Override
- protected void onProgressUpdate(String[]... values) {
+ protected void onProgressUpdate(SlidePOJO[]... values) {
super.onProgressUpdate(values);
- slideList.setAdapter(new ArrayAdapter<String>(slideActivity, android.R.layout.simple_list_item_1, values[0]));
+ slideList.setAdapter(new SlideAdapter(context, Arrays.asList(values[0])));
+ }
+
+ class FetchItemsException extends Exception {
+ FetchItemsException(Throwable throwable) {
+ super(throwable);
+ }
}
}
}
=== modified file 'src/org/openlp/android/api/Api.java'
--- src/org/openlp/android/api/Api.java 2011-05-07 20:01:46 +0000
+++ src/org/openlp/android/api/Api.java 2011-05-20 19:56:46 +0000
@@ -95,10 +95,12 @@
public final String LIVE_NEXT = "/api/controller/live/next";
public final String LIVE_PREVIOUS = "/api/controller/live/previous";
public final String LIVE_TEXT = "/api/controller/live/text";
+ public final String LIVE_SET = "/api/controller/live/set?data=";
public final String SERVICE_NEXT = "/api/service/next";
public final String SERVICE_PREVIOUS = "/api/service/previous";
public final String SERVICE_LIST = "/api/service/list";
+ public final String SERVICE_SET = "/api/service/set?data=";
public final String DISPLAY_HIDE = "/api/display/hide";
public final String DISPLAY_SHOW = "/api/display/show";
=== added directory 'src/org/openlp/android/pojo'
=== added file 'src/org/openlp/android/pojo/SlidePOJO.java'
--- src/org/openlp/android/pojo/SlidePOJO.java 1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/pojo/SlidePOJO.java 2011-05-20 19:56:46 +0000
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2008-2011 Raoul Snyman *
+ * Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael *
+ * Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, *
+ * Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, *
+ * Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund *
+ * --------------------------------------------------------------------------- *
+ * 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.pojo;
+
+public class SlidePOJO {
+ private String text;
+ private boolean selected;
+ private String tag;
+ private String html;
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public boolean isSelected() {
+ return selected;
+ }
+
+ public void setSelected(boolean selected) {
+ this.selected = selected;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public String getHtml() {
+ return html;
+ }
+
+ public void setHtml(String html) {
+ this.html = html;
+ }
+
+ @Override
+ public String toString() {
+ return "SlidePOJO{" +
+ "text='" + text + '\'' +
+ ", selected=" + selected +
+ ", tag='" + tag + '\'' +
+ ", html='" + html + '\'' +
+ '}';
+ }
+}
=== added file 'src/org/openlp/android/utility/JSONHandler.java'
--- src/org/openlp/android/utility/JSONHandler.java 1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/utility/JSONHandler.java 2011-05-20 19:56:46 +0000
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2008-2011 Raoul Snyman *
+ * Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael *
+ * Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, *
+ * Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, *
+ * Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund *
+ * --------------------------------------------------------------------------- *
+ * 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.utility;
+
+import android.util.Log;
+import org.apache.http.HttpEntity;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONStringer;
+import org.openlp.android.pojo.SlidePOJO;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JSONHandler {
+ private static String LOG_TAG = JSONHandler.class.getName();
+
+ public static String createRequestJSON(String key, String value) throws JSONHandlerException {
+ try {
+ String responseJSON;
+ JSONObject jo = new JSONObject();
+ jo.put(key, value);
+ responseJSON = new JSONStringer().object().key("request").value(jo).endObject().toString();
+ responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
+ return responseJSON;
+ }
+ catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static List<SlidePOJO> parseServiceItemResponseJSON(HttpEntity entity) throws JSONHandlerException {
+ try {
+ List<SlidePOJO> serviceItemList = new ArrayList<SlidePOJO>();
+ InputStream inputStream = entity.getContent();
+ String result = StringHelper.convertStreamToString(inputStream);
+ Log.i(LOG_TAG, result);
+
+ JSONObject jObject = new JSONObject(result);
+ JSONObject results = jObject.getJSONObject("results");
+ JSONArray items = results.getJSONArray("items");
+
+ for (int i = 0; i < items.length(); i++) {
+ JSONObject item = items.getJSONObject(i);
+ SlidePOJO slide = new SlidePOJO();
+ slide.setTag("");
+ slide.setText(item.getString("title"));
+ slide.setSelected(item.getBoolean("selected"));
+ slide.setHtml("");
+ serviceItemList.add(slide);
+ }
+
+ inputStream.close();
+ return serviceItemList;
+ }
+ catch (IOException e) {
+ throw new JSONHandlerException(e);
+ }
+ catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+
+ }
+
+ public static List<SlidePOJO> parseSlideItemResponseJSON(HttpEntity entity) throws JSONHandlerException {
+ try {
+ List<SlidePOJO> serviceItemList = new ArrayList<SlidePOJO>();
+ InputStream inputStream = entity.getContent();
+ String result = StringHelper.convertStreamToString(inputStream);
+ Log.i(LOG_TAG, result);
+
+ JSONObject jObject = new JSONObject(result);
+ JSONObject results = jObject.getJSONObject("results");
+ JSONArray items = results.getJSONArray("slides");
+
+ for (int i = 0; i < items.length(); i++) {
+ JSONObject item = items.getJSONObject(i);
+ SlidePOJO slide = new SlidePOJO();
+ slide.setText(item.getString("text"));
+ slide.setTag(item.getString("tag"));
+ slide.setSelected(item.getBoolean("selected"));
+ slide.setHtml(item.getString("html"));
+ serviceItemList.add(slide);
+ }
+
+ inputStream.close();
+ return serviceItemList;
+ }
+ catch (IOException e) {
+ throw new JSONHandlerException(e);
+ }
+ catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+
+ }
+
+ public static class JSONHandlerException extends Exception {
+ public JSONHandlerException(Throwable throwable) {
+ super(throwable);
+ }
+ }
+}
=== added file 'src/org/openlp/android/utility/SlideAdapter.java'
--- src/org/openlp/android/utility/SlideAdapter.java 1970-01-01 00:00:00 +0000
+++ src/org/openlp/android/utility/SlideAdapter.java 2011-05-20 19:56:46 +0000
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * OpenLP - Open Source Lyrics Projection *
+ * --------------------------------------------------------------------------- *
+ * Copyright (c) 2008-2011 Raoul Snyman *
+ * Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael *
+ * Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, *
+ * Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, *
+ * Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund *
+ * --------------------------------------------------------------------------- *
+ * 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.utility;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+import org.openlp.android.R;
+import org.openlp.android.pojo.SlidePOJO;
+
+import java.util.List;
+
+public class SlideAdapter extends BaseAdapter {
+ List<SlidePOJO> items;
+ Context context;
+ LayoutInflater inflater;
+
+ public SlideAdapter(Activity context, List<SlidePOJO> items) {
+ this.context = context;
+ this.items = items;
+ inflater = context.getLayoutInflater();
+ }
+
+ @Override
+ public int getCount() {
+ return items.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ return items.get(i);
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return items.indexOf(items.get(i));
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ View view = convertView;
+
+ SlidePOJO item = items.get(position);
+
+ if (view == null) {
+ view = inflater.inflate(R.layout.slide_list_item, null);
+ holder = new ViewHolder();
+
+ holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
+ holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
+
+ view.setTag(holder);
+ }
+ else {
+ holder = (ViewHolder) view.getTag();
+ }
+
+ holder.rowMarker.setText(item.getTag());
+ holder.rowItem.setText(item.getText());
+ return view;
+ }
+
+ static class ViewHolder {
+ TextView rowMarker;
+ TextView rowItem;
+ }
+}
=== modified file 'src/org/openlp/android/utility/WebCallAsyncTask.java'
--- src/org/openlp/android/utility/WebCallAsyncTask.java 2011-05-08 11:41:49 +0000
+++ src/org/openlp/android/utility/WebCallAsyncTask.java 2011-05-20 19:56:46 +0000
@@ -40,11 +40,17 @@
private Context context;
private ProgressDialog progressDialog;
private String error;
+ private String apiPart;
public WebCallAsyncTask(Context context) {
this.context = context;
}
+ public WebCallAsyncTask(Context context, String apiPart) {
+ this.context = context;
+ this.apiPart = apiPart;
+ }
+
@Override
protected void onPreExecute() {
super.onPreExecute();
@@ -55,7 +61,12 @@
protected Void doInBackground(String... apiCall) {
OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
try {
- httpClient.setUrl(apiCall[0]);
+ if (apiPart == null) {
+ httpClient.setUrl(apiCall[0]);
+ }
+ else {
+ httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
+ }
Log.d(LOG_TAG, "Executing request: " + httpClient.getUrl().toString());
if (httpClient.getUrl().getHost() != null) {
Follow ups