Merge lp:~trb143/openlp/android_dev into lp:openlp/android

Proposed by Tim Bentley
Status: Merged
Merged at revision: 50
Proposed branch: lp:~trb143/openlp/android_dev
Merge into: lp:openlp/android
Diff against target: 4597 lines (+2154/-2181)
20 files modified
src/org/openlp/android/OpenLP.java (+61/-61)
src/org/openlp/android/activity/DefaultActivity.java (+20/-20)
src/org/openlp/android/activity/OpenLPNavigate.java (+36/-34)
src/org/openlp/android/activity/PagerActivity.java (+35/-35)
src/org/openlp/android/activity/Search.java (+2/-2)
src/org/openlp/android/activity/SearchService.java (+3/-3)
src/org/openlp/android/activity/SearchableActivity.java (+235/-238)
src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java (+331/-331)
src/org/openlp/android/activity/preference/Preferences.java (+95/-94)
src/org/openlp/android/api/Api.java (+36/-28)
src/org/openlp/android/data/Poll.java (+95/-95)
src/org/openlp/android/data/SlideItem.java (+42/-42)
src/org/openlp/android/service/PingIntent.java (+55/-55)
src/org/openlp/android/utility/GroupExpandableListAdapter.java (+87/-88)
src/org/openlp/android/utility/JSONHandler.java (+128/-135)
src/org/openlp/android/utility/OpenLPController.java (+548/-567)
src/org/openlp/android/utility/OpenLPHttpClient.java (+154/-154)
src/org/openlp/android/utility/SlideAdapter.java (+94/-95)
src/org/openlp/android/utility/StringHelper.java (+20/-23)
src/org/openlp/android/utility/WebCallReturningAsyncTask.java (+77/-81)
To merge this branch: bzr merge lp:~trb143/openlp/android_dev
Reviewer Review Type Date Requested Status
Johan Mynhardt Approve
Review via email: mp+167382@code.launchpad.net

Description of the change

Code style cleanup only using Intelij

To post a comment you must log in.
Revision history for this message
Johan Mynhardt (johanmynhardt) wrote :

Looks good to me :)

So we'll settle on using spaces for indentation?

The thought crossed my mind: What is the possibility of 'mavenizing' the build? I was thinking in terms of the code-style/error-detection plugins available for maven which could help us keep everything clean.
Maybe not the best place to discuss it though :P

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/org/openlp/android/OpenLP.java'
2--- src/org/openlp/android/OpenLP.java 2013-04-06 13:44:51 +0000
3+++ src/org/openlp/android/OpenLP.java 2013-06-04 19:32:29 +0000
4@@ -37,65 +37,65 @@
5 */
6 public class OpenLP extends DefaultActivity {
7
8- /**
9- * Called when the activity is first created.
10- */
11- @Override
12- public void onCreate(Bundle savedInstanceState) {
13- super.onCreate(savedInstanceState);
14- setContentView(R.layout.main);
15-
16- doPreferenceCheck();
17- setOnClickListenerPagerForButtons();
18- }
19-
20- private View.OnClickListener onClickListenerPager =
21- new View.OnClickListener() {
22- @Override
23- public void onClick(View view) {
24- Intent pager = new Intent(OpenLP.this, PagerActivity.class);
25- pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));
26- startActivity(pager);
27- }
28- };
29-
30- private void doPreferenceCheck() {
31- if (getSharedPreferences(getString(R.string.keySharedPreferences),
32- Context.MODE_PRIVATE).getString(getString(R.string.keyHost),
33- "NONE").equals("NONE")
34- || getSharedPreferences(
35- getString(R.string.keySharedPreferences),
36- Context.MODE_PRIVATE).getString(
37- getString(R.string.keyHost), null).equals(null)) {
38- Log.d(LOG_TAG,
39- "URL preference not set. Starting preference activity...");
40- Intent preferenceIntent = new Intent(this, Preferences.class);
41- startActivity(preferenceIntent);
42- }
43- }
44-
45- private void setOnClickListenerPagerForButtons() {
46- findViewById(R.id.buttonService)
47- .setOnClickListener(onClickListenerPager);
48- findViewById(R.id.buttonLive)
49- .setOnClickListener(onClickListenerPager);
50- findViewById(R.id.buttonDisplay)
51- .setOnClickListener(onClickListenerPager);
52- findViewById(R.id.buttonAlert)
53- .setOnClickListener(onClickListenerPager);
54- findViewById(R.id.buttonStage)
55- .setOnClickListener(onClickListenerPager);
56- findViewById(R.id.buttonSearch)
57- .setOnClickListener(onClickListenerSearch);
58- }
59-
60- private View.OnClickListener onClickListenerSearch =
61- new View.OnClickListener() {
62- @Override
63- public void onClick(View view) {
64- onSearchRequested();
65- }
66- };
67-
68- private final String LOG_TAG = OpenLP.class.getName();
69+ /**
70+ * Called when the activity is first created.
71+ */
72+ @Override
73+ public void onCreate(Bundle savedInstanceState) {
74+ super.onCreate(savedInstanceState);
75+ setContentView(R.layout.main);
76+
77+ doPreferenceCheck();
78+ setOnClickListenerPagerForButtons();
79+ }
80+
81+ private View.OnClickListener onClickListenerPager =
82+ new View.OnClickListener() {
83+ @Override
84+ public void onClick(View view) {
85+ Intent pager = new Intent(OpenLP.this, PagerActivity.class);
86+ pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));
87+ startActivity(pager);
88+ }
89+ };
90+
91+ private void doPreferenceCheck() {
92+ if (getSharedPreferences(getString(R.string.keySharedPreferences),
93+ Context.MODE_PRIVATE).getString(getString(R.string.keyHost),
94+ "NONE").equals("NONE")
95+ || getSharedPreferences(
96+ getString(R.string.keySharedPreferences),
97+ Context.MODE_PRIVATE).getString(
98+ getString(R.string.keyHost), null).equals(null)) {
99+ Log.d(LOG_TAG,
100+ "URL preference not set. Starting preference activity...");
101+ Intent preferenceIntent = new Intent(this, Preferences.class);
102+ startActivity(preferenceIntent);
103+ }
104+ }
105+
106+ private void setOnClickListenerPagerForButtons() {
107+ findViewById(R.id.buttonService)
108+ .setOnClickListener(onClickListenerPager);
109+ findViewById(R.id.buttonLive)
110+ .setOnClickListener(onClickListenerPager);
111+ findViewById(R.id.buttonDisplay)
112+ .setOnClickListener(onClickListenerPager);
113+ findViewById(R.id.buttonAlert)
114+ .setOnClickListener(onClickListenerPager);
115+ findViewById(R.id.buttonStage)
116+ .setOnClickListener(onClickListenerPager);
117+ findViewById(R.id.buttonSearch)
118+ .setOnClickListener(onClickListenerSearch);
119+ }
120+
121+ private View.OnClickListener onClickListenerSearch =
122+ new View.OnClickListener() {
123+ @Override
124+ public void onClick(View view) {
125+ onSearchRequested();
126+ }
127+ };
128+
129+ private final String LOG_TAG = OpenLP.class.getName();
130 }
131
132=== modified file 'src/org/openlp/android/activity/DefaultActivity.java'
133--- src/org/openlp/android/activity/DefaultActivity.java 2013-04-06 13:44:51 +0000
134+++ src/org/openlp/android/activity/DefaultActivity.java 2013-06-04 19:32:29 +0000
135@@ -31,25 +31,25 @@
136
137
138 public abstract class DefaultActivity extends Activity implements Api {
139- @Override
140- public boolean onCreateOptionsMenu(Menu menu) {
141- MenuInflater inflater = getMenuInflater();
142- inflater.inflate(R.menu.menu, menu);
143- return true;
144- }
145+ @Override
146+ public boolean onCreateOptionsMenu(Menu menu) {
147+ MenuInflater inflater = getMenuInflater();
148+ inflater.inflate(R.menu.menu, menu);
149+ return true;
150+ }
151
152- @Override
153- public boolean onOptionsItemSelected(MenuItem item) {
154- // Handle item selection
155- switch (item.getItemId()) {
156- case R.id.preferences:
157- startActivity(new Intent(this, Preferences.class));
158- return true;
159- case R.id.menuSearch:
160- onSearchRequested();
161- return true;
162- default:
163- return super.onOptionsItemSelected(item);
164- }
165- }
166+ @Override
167+ public boolean onOptionsItemSelected(MenuItem item) {
168+ // Handle item selection
169+ switch (item.getItemId()) {
170+ case R.id.preferences:
171+ startActivity(new Intent(this, Preferences.class));
172+ return true;
173+ case R.id.menuSearch:
174+ onSearchRequested();
175+ return true;
176+ default:
177+ return super.onOptionsItemSelected(item);
178+ }
179+ }
180 }
181
182=== modified file 'src/org/openlp/android/activity/OpenLPNavigate.java'
183--- src/org/openlp/android/activity/OpenLPNavigate.java 2013-04-06 13:44:51 +0000
184+++ src/org/openlp/android/activity/OpenLPNavigate.java 2013-06-04 19:32:29 +0000
185@@ -27,38 +27,40 @@
186 */
187 public interface OpenLPNavigate extends Api {
188
189- public final String NAVIGATE_PREVIOUS = "previous";
190- public final String NAVIGATE_NEXT = "next";
191- public final String HIDE_SCREEN = "blank";
192- public final String HIDE_THEME = "theme";
193- public final String HIDE_DESKTOP = "desktop";
194- public final String DISPLAY_SHOW = "show";
195-
196- /**
197- * Call to the service changing service/slides.
198- *
199- * @param direction A direction constant from {@link org.openlp.android.api.Api}.
200- * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}
201- * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.
202- */
203- void navigate(String direction);
204-
205- /**
206- * Call to the service changing data for Service or Live
207- *
208- * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.
209- * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}
210- * or {@link org.openlp.android.api.Api#SERVICE_SET}
211- * @param id Id of the item selected.
212- */
213- void setData(String apiPart, int id);
214-
215- void setDisplay(String displayRequest);
216- void poll();
217-
218- /**
219- * Replaces what we previously had as FetchItemsTask which basically ran in the UI
220- * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}
221- */
222- void fetchItems(String apiPart);
223+ public final String NAVIGATE_PREVIOUS = "previous";
224+ public final String NAVIGATE_NEXT = "next";
225+ public final String HIDE_SCREEN = "blank";
226+ public final String HIDE_THEME = "theme";
227+ public final String HIDE_DESKTOP = "desktop";
228+ public final String DISPLAY_SHOW = "show";
229+
230+ /**
231+ * Call to the service changing service/slides.
232+ *
233+ * @param direction A direction constant from {@link org.openlp.android.api.Api}.
234+ * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}
235+ * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.
236+ */
237+ void navigate(String direction);
238+
239+ /**
240+ * Call to the service changing data for Service or Live
241+ *
242+ * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.
243+ * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}
244+ * or {@link org.openlp.android.api.Api#SERVICE_SET}
245+ * @param id Id of the item selected.
246+ */
247+ void setData(String apiPart, int id);
248+
249+ void setDisplay(String displayRequest);
250+
251+ void poll();
252+
253+ /**
254+ * Replaces what we previously had as FetchItemsTask which basically ran in the UI
255+ *
256+ * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}
257+ */
258+ void fetchItems(String apiPart);
259 }
260
261=== modified file 'src/org/openlp/android/activity/PagerActivity.java'
262--- src/org/openlp/android/activity/PagerActivity.java 2013-04-06 13:44:51 +0000
263+++ src/org/openlp/android/activity/PagerActivity.java 2013-06-04 19:32:29 +0000
264@@ -28,39 +28,39 @@
265 import org.openlp.android.utility.OpenLPController;
266
267 public class PagerActivity extends DefaultActivity {
268- private ViewPager pager;
269- private OpenLPController controller;
270-
271- @Override
272- protected void onCreate(Bundle savedInstanceState) {
273- super.onCreate(savedInstanceState);
274- Log.i(LOG_TAG, "onCreate");
275-
276- setContentView(R.layout.view_pager_layout);
277-
278- controller = new OpenLPController(this);
279- pager = (ViewPager) findViewById(R.id.myViewPager);
280- pager.setAdapter(controller);
281-
282- Intent intent = getIntent();
283- int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);
284- Log.v(LOG_TAG, "Setting Page number: " + selectedPage);
285- pager.setOnPageChangeListener(controller.onPageChangeListener);
286- pager.setCurrentItem(selectedPage, true);
287- controller.onPageChangeListener.onPageSelected(selectedPage);
288- }
289-
290- public void setCurrentPage(int page) {
291- pager.setCurrentItem(page, true);
292- }
293-
294- @Override
295- protected void onDestroy() {
296- super.onDestroy();
297- Log.v(LOG_TAG, "Destroying pagerActivity...");
298- unregisterReceiver(controller.apiCallReceiver);
299- stopService(controller.pingIntent);
300- }
301-
302- private final String LOG_TAG = PagerActivity.class.getName();
303+ private ViewPager pager;
304+ private OpenLPController controller;
305+
306+ @Override
307+ protected void onCreate(Bundle savedInstanceState) {
308+ super.onCreate(savedInstanceState);
309+ Log.i(LOG_TAG, "onCreate");
310+
311+ setContentView(R.layout.view_pager_layout);
312+
313+ controller = new OpenLPController(this);
314+ pager = (ViewPager) findViewById(R.id.myViewPager);
315+ pager.setAdapter(controller);
316+
317+ Intent intent = getIntent();
318+ int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);
319+ Log.v(LOG_TAG, "Setting Page number: " + selectedPage);
320+ pager.setOnPageChangeListener(controller.onPageChangeListener);
321+ pager.setCurrentItem(selectedPage, true);
322+ controller.onPageChangeListener.onPageSelected(selectedPage);
323+ }
324+
325+ public void setCurrentPage(int page) {
326+ pager.setCurrentItem(page, true);
327+ }
328+
329+ @Override
330+ protected void onDestroy() {
331+ super.onDestroy();
332+ Log.v(LOG_TAG, "Destroying pagerActivity...");
333+ unregisterReceiver(controller.apiCallReceiver);
334+ stopService(controller.pingIntent);
335+ }
336+
337+ private final String LOG_TAG = PagerActivity.class.getName();
338 }
339
340=== modified file 'src/org/openlp/android/activity/Search.java'
341--- src/org/openlp/android/activity/Search.java 2013-04-06 13:44:51 +0000
342+++ src/org/openlp/android/activity/Search.java 2013-06-04 19:32:29 +0000
343@@ -21,7 +21,7 @@
344 package org.openlp.android.activity;
345
346 public interface Search {
347- public final String ACTION = Search.class.getName().concat(".Action");
348+ public final String ACTION = Search.class.getName().concat(".Action");
349
350- public void searchPluginCall(String apiBase, String apiData);
351+ public void searchPluginCall(String apiBase, String apiData);
352 }
353
354=== modified file 'src/org/openlp/android/activity/SearchService.java'
355--- src/org/openlp/android/activity/SearchService.java 2013-04-06 13:44:51 +0000
356+++ src/org/openlp/android/activity/SearchService.java 2013-06-04 19:32:29 +0000
357@@ -27,7 +27,7 @@
358 import java.net.URISyntaxException;
359
360 public interface SearchService {
361- public Intent getSearchPluginIntent(String apiBase, String apiData)
362- throws JSONHandler.JSONHandlerException, IOException,
363- URISyntaxException;
364+ public Intent getSearchPluginIntent(String apiBase, String apiData)
365+ throws JSONHandler.JSONHandlerException, IOException,
366+ URISyntaxException;
367 }
368
369=== modified file 'src/org/openlp/android/activity/SearchableActivity.java'
370--- src/org/openlp/android/activity/SearchableActivity.java 2013-04-06 13:44:51 +0000
371+++ src/org/openlp/android/activity/SearchableActivity.java 2013-06-04 19:32:29 +0000
372@@ -52,242 +52,239 @@
373 import java.util.Map;
374
375 public class SearchableActivity extends Activity implements Api {
376- private ExpandableListView listView;
377- private final int DIALOG_ITEM_OPTIONS = 0;
378- private Object dialogKey;
379- private JSONArray dialogValue;
380-
381- private Search controller = new Search() {
382- @Override
383- public void searchPluginCall(String apiBase, String apiData) {
384- Intent apiCallIntent =
385- new Intent(SearchableActivity.this, ApiCallIntent.class);
386- apiCallIntent.putExtra(apiBase, apiData);
387- startService(apiCallIntent);
388- }
389- };
390-
391- BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
392- @Override
393- public void onReceive(Context context, Intent intent) {
394- Log.d(LOG_TAG, String.format(
395- "Search broadcast received: context(%s), intent(%s, %s)",
396- context, intent, intent.getExtras()));
397- }
398- };
399-
400- @Override
401- protected void onCreate(Bundle savedInstanceState) {
402- super.onCreate(savedInstanceState);
403- setContentView(R.layout.search);
404- listView = (ExpandableListView) findViewById(R.id.list);
405- listView.setOnChildClickListener(onChildClickListener);
406-
407- IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);
408- apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
409-
410- registerReceiver(apiCallReceiver, apiCallFilter);
411-
412- Intent intent = getIntent();
413- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
414- String query = intent.getStringExtra(SearchManager.QUERY);
415- doSearch(query);
416- }
417- }
418-
419- private ExpandableListView.OnChildClickListener onChildClickListener =
420- new ExpandableListView.OnChildClickListener() {
421- @Override
422- public boolean onChildClick(ExpandableListView expandableListView,
423- View view, int parent, int childPosition, long l) {
424- @SuppressWarnings("unchecked") Map<String, JSONArray> child =
425- (Map<String, JSONArray>) listView.getExpandableListAdapter()
426- .getChild(parent, childPosition);
427- dialogKey = null;
428- dialogValue = null;
429- dialogKey =
430- listView.getExpandableListAdapter().getGroup(parent);
431- dialogValue = child.get(dialogKey.toString());
432- showDialog(DIALOG_ITEM_OPTIONS);
433- return false;
434- }
435- };
436-
437- @Override
438- protected Dialog onCreateDialog(int id) {
439- switch (id) {
440- case DIALOG_ITEM_OPTIONS:
441- AlertDialog.Builder dialogBuilder =
442- new AlertDialog.Builder(SearchableActivity.this);
443- dialogBuilder
444- .setTitle(getString(R.string.dialogTitleItemOptions));
445- dialogBuilder.setNegativeButton(
446- getString(R.string.dialogNegativeSendLive),
447- onClickListenerDialogSendLive);
448- dialogBuilder.setPositiveButton(
449- getString(R.string.dialogPositiveAddToService),
450- onClickListenerDialogAddToService);
451- return dialogBuilder.create();
452- default:
453- return null;
454- }
455- }
456-
457- DialogInterface.OnClickListener onClickListenerDialogSendLive =
458- new DialogInterface.OnClickListener() {
459- @Override
460- public void onClick(DialogInterface dialogInterface, int i) {
461- controller.searchPluginCall(
462- String.format(SEARCH_PLUGIN_LIVE, dialogKey),
463- getDialogValue());
464- }
465- };
466-
467- DialogInterface.OnClickListener onClickListenerDialogAddToService =
468- new DialogInterface.OnClickListener() {
469- @Override
470- public void onClick(DialogInterface dialogInterface, int i) {
471- controller.searchPluginCall(
472- String.format(SEARCH_PLUGIN_ADD, dialogKey),
473- getDialogValue());
474- dialogInterface.cancel();
475- }
476- };
477-
478- private String getDialogValue() {
479- try {
480- return String.valueOf(dialogValue.get(0));
481- }
482- catch (JSONException e) {
483- Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());
484- Toast.makeText(SearchableActivity.this, e.getMessage(),
485- Toast.LENGTH_LONG).show();
486- return null;
487- }
488- }
489-
490- @Override
491- protected void onPrepareDialog(int id, Dialog dialog) {
492- try {
493- dialog.setTitle(dialogValue.get(1).toString());
494- }
495- catch (JSONException e) {
496- e.printStackTrace();
497- }
498- }
499-
500- public void doSearch(String search) {
501- new SearchAsync().execute(search);
502- }
503-
504- @Override
505- protected void onDestroy() {
506- super.onDestroy();
507- unregisterReceiver(apiCallReceiver);
508- }
509-
510- class SearchAsync extends AsyncTask<String, Void, SearchResults> {
511- ProgressDialog progressDialog;
512- String query;
513-
514- @Override
515- protected SearchResults doInBackground(String... strings) {
516- query = strings[0];
517- List<String> groups = new ArrayList<String>();
518- List<List<Map<String, JSONArray>>> children =
519- new ArrayList<List<Map<String, JSONArray>>>();
520- AsyncTask<String, Void, String> call =
521- new WebCallReturningAsyncTask(SearchableActivity.this)
522- .execute(SEARCHABLE_PLUGINS);
523-
524- try {
525- JSONArray array =
526- new JSONObject(call.get()).getJSONObject("results")
527- .getJSONArray("items");
528-
529- for (int i = 0; i < array.length(); i++) {
530- String pluginString =
531- ((JSONArray) array.get(i)).get(0).toString();
532- groups.add(pluginString);
533-
534- JSONArray resultArray = null;
535-
536- AsyncTask<String, Void, String> pluginResults =
537- new WebCallReturningAsyncTask(SearchableActivity.this,
538- String
539- .format(SEARCH_PLUGIN_FORMATTED, pluginString))
540- .execute(
541- JSONHandler.createRequestJSON("text", query));
542-
543- List<Map<String, JSONArray>> list =
544- new ArrayList<Map<String, JSONArray>>();
545- if (pluginResults.get() != null &&
546- pluginResults.get().trim().length() > 0) {
547- resultArray = new JSONObject(pluginResults.get())
548- .getJSONObject("results").getJSONArray("items");
549- for (int j = 0; j < resultArray.length(); j++) {
550- Map<String, JSONArray> item =
551- new HashMap<String, JSONArray>();
552- item.put(pluginString,
553- (JSONArray) resultArray.get(j));
554- list.add(item);
555- }
556- }
557- children.add(list);
558- }
559- }
560- catch (Exception e) {
561- Log.e(LOG_TAG, e.toString());
562- Toast.makeText(SearchableActivity.this, e.getMessage(),
563- Toast.LENGTH_LONG).show();
564- }
565-
566- SearchResults results = new SearchResults();
567- results.setGroups(groups);
568- results.setChildren(children);
569- return results;
570- }
571-
572- @Override
573- protected void onPreExecute() {
574- super.onPreExecute();
575- progressDialog = ProgressDialog.show(SearchableActivity.this, null,
576- getString(R.string.searching));
577- }
578-
579- @Override
580- protected void onPostExecute(SearchResults results) {
581- super.onPostExecute(results);
582- listView.setAdapter(
583- new GroupExpandableListAdapter(SearchableActivity.this,
584- results.getGroups(), results.getChildren()));
585- progressDialog.dismiss();
586- Toast.makeText(SearchableActivity.this,
587- String.format(getString(R.string.showingResults), query),
588- Toast.LENGTH_SHORT).show();
589- }
590- }
591-
592- class SearchResults {
593- List<String> groups;
594- List<List<Map<String, JSONArray>>> children;
595-
596- public List<String> getGroups() {
597- return groups;
598- }
599-
600- public void setGroups(List<String> groups) {
601- this.groups = groups;
602- }
603-
604- public List<List<Map<String, JSONArray>>> getChildren() {
605- return children;
606- }
607-
608- public void setChildren(List<List<Map<String, JSONArray>>> children) {
609- this.children = children;
610- }
611- }
612-
613- private final String LOG_TAG = this.getClass().getName();
614+ private ExpandableListView listView;
615+ private final int DIALOG_ITEM_OPTIONS = 0;
616+ private Object dialogKey;
617+ private JSONArray dialogValue;
618+
619+ private Search controller = new Search() {
620+ @Override
621+ public void searchPluginCall(String apiBase, String apiData) {
622+ Intent apiCallIntent =
623+ new Intent(SearchableActivity.this, ApiCallIntent.class);
624+ apiCallIntent.putExtra(apiBase, apiData);
625+ startService(apiCallIntent);
626+ }
627+ };
628+
629+ BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
630+ @Override
631+ public void onReceive(Context context, Intent intent) {
632+ Log.d(LOG_TAG, String.format(
633+ "Search broadcast received: context(%s), intent(%s, %s)",
634+ context, intent, intent.getExtras()));
635+ }
636+ };
637+
638+ @Override
639+ protected void onCreate(Bundle savedInstanceState) {
640+ super.onCreate(savedInstanceState);
641+ setContentView(R.layout.search);
642+ listView = (ExpandableListView) findViewById(R.id.list);
643+ listView.setOnChildClickListener(onChildClickListener);
644+
645+ IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);
646+ apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
647+
648+ registerReceiver(apiCallReceiver, apiCallFilter);
649+
650+ Intent intent = getIntent();
651+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
652+ String query = intent.getStringExtra(SearchManager.QUERY);
653+ doSearch(query);
654+ }
655+ }
656+
657+ private ExpandableListView.OnChildClickListener onChildClickListener =
658+ new ExpandableListView.OnChildClickListener() {
659+ @Override
660+ public boolean onChildClick(ExpandableListView expandableListView,
661+ View view, int parent, int childPosition, long l) {
662+ @SuppressWarnings("unchecked") Map<String, JSONArray> child =
663+ (Map<String, JSONArray>) listView.getExpandableListAdapter()
664+ .getChild(parent, childPosition);
665+ dialogKey = null;
666+ dialogValue = null;
667+ dialogKey =
668+ listView.getExpandableListAdapter().getGroup(parent);
669+ dialogValue = child.get(dialogKey.toString());
670+ showDialog(DIALOG_ITEM_OPTIONS);
671+ return false;
672+ }
673+ };
674+
675+ @Override
676+ protected Dialog onCreateDialog(int id) {
677+ switch (id) {
678+ case DIALOG_ITEM_OPTIONS:
679+ AlertDialog.Builder dialogBuilder =
680+ new AlertDialog.Builder(SearchableActivity.this);
681+ dialogBuilder
682+ .setTitle(getString(R.string.dialogTitleItemOptions));
683+ dialogBuilder.setNegativeButton(
684+ getString(R.string.dialogNegativeSendLive),
685+ onClickListenerDialogSendLive);
686+ dialogBuilder.setPositiveButton(
687+ getString(R.string.dialogPositiveAddToService),
688+ onClickListenerDialogAddToService);
689+ return dialogBuilder.create();
690+ default:
691+ return null;
692+ }
693+ }
694+
695+ DialogInterface.OnClickListener onClickListenerDialogSendLive =
696+ new DialogInterface.OnClickListener() {
697+ @Override
698+ public void onClick(DialogInterface dialogInterface, int i) {
699+ controller.searchPluginCall(
700+ String.format(SEARCH_PLUGIN_LIVE, dialogKey),
701+ getDialogValue());
702+ }
703+ };
704+
705+ DialogInterface.OnClickListener onClickListenerDialogAddToService =
706+ new DialogInterface.OnClickListener() {
707+ @Override
708+ public void onClick(DialogInterface dialogInterface, int i) {
709+ controller.searchPluginCall(
710+ String.format(SEARCH_PLUGIN_ADD, dialogKey),
711+ getDialogValue());
712+ dialogInterface.cancel();
713+ }
714+ };
715+
716+ private String getDialogValue() {
717+ try {
718+ return String.valueOf(dialogValue.get(0));
719+ } catch (JSONException e) {
720+ Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());
721+ Toast.makeText(SearchableActivity.this, e.getMessage(),
722+ Toast.LENGTH_LONG).show();
723+ return null;
724+ }
725+ }
726+
727+ @Override
728+ protected void onPrepareDialog(int id, Dialog dialog) {
729+ try {
730+ dialog.setTitle(dialogValue.get(1).toString());
731+ } catch (JSONException e) {
732+ e.printStackTrace();
733+ }
734+ }
735+
736+ public void doSearch(String search) {
737+ new SearchAsync().execute(search);
738+ }
739+
740+ @Override
741+ protected void onDestroy() {
742+ super.onDestroy();
743+ unregisterReceiver(apiCallReceiver);
744+ }
745+
746+ class SearchAsync extends AsyncTask<String, Void, SearchResults> {
747+ ProgressDialog progressDialog;
748+ String query;
749+
750+ @Override
751+ protected SearchResults doInBackground(String... strings) {
752+ query = strings[0];
753+ List<String> groups = new ArrayList<String>();
754+ List<List<Map<String, JSONArray>>> children =
755+ new ArrayList<List<Map<String, JSONArray>>>();
756+ AsyncTask<String, Void, String> call =
757+ new WebCallReturningAsyncTask(SearchableActivity.this)
758+ .execute(SEARCHABLE_PLUGINS);
759+
760+ try {
761+ JSONArray array =
762+ new JSONObject(call.get()).getJSONObject("results")
763+ .getJSONArray("items");
764+
765+ for (int i = 0; i < array.length(); i++) {
766+ String pluginString =
767+ ((JSONArray) array.get(i)).get(0).toString();
768+ groups.add(pluginString);
769+
770+ JSONArray resultArray = null;
771+
772+ AsyncTask<String, Void, String> pluginResults =
773+ new WebCallReturningAsyncTask(SearchableActivity.this,
774+ String
775+ .format(SEARCH_PLUGIN_FORMATTED, pluginString))
776+ .execute(
777+ JSONHandler.createRequestJSON("text", query));
778+
779+ List<Map<String, JSONArray>> list =
780+ new ArrayList<Map<String, JSONArray>>();
781+ if (pluginResults.get() != null &&
782+ pluginResults.get().trim().length() > 0) {
783+ resultArray = new JSONObject(pluginResults.get())
784+ .getJSONObject("results").getJSONArray("items");
785+ for (int j = 0; j < resultArray.length(); j++) {
786+ Map<String, JSONArray> item =
787+ new HashMap<String, JSONArray>();
788+ item.put(pluginString,
789+ (JSONArray) resultArray.get(j));
790+ list.add(item);
791+ }
792+ }
793+ children.add(list);
794+ }
795+ } catch (Exception e) {
796+ Log.e(LOG_TAG, e.toString());
797+ Toast.makeText(SearchableActivity.this, e.getMessage(),
798+ Toast.LENGTH_LONG).show();
799+ }
800+
801+ SearchResults results = new SearchResults();
802+ results.setGroups(groups);
803+ results.setChildren(children);
804+ return results;
805+ }
806+
807+ @Override
808+ protected void onPreExecute() {
809+ super.onPreExecute();
810+ progressDialog = ProgressDialog.show(SearchableActivity.this, null,
811+ getString(R.string.searching));
812+ }
813+
814+ @Override
815+ protected void onPostExecute(SearchResults results) {
816+ super.onPostExecute(results);
817+ listView.setAdapter(
818+ new GroupExpandableListAdapter(SearchableActivity.this,
819+ results.getGroups(), results.getChildren()));
820+ progressDialog.dismiss();
821+ Toast.makeText(SearchableActivity.this,
822+ String.format(getString(R.string.showingResults), query),
823+ Toast.LENGTH_SHORT).show();
824+ }
825+ }
826+
827+ class SearchResults {
828+ List<String> groups;
829+ List<List<Map<String, JSONArray>>> children;
830+
831+ public List<String> getGroups() {
832+ return groups;
833+ }
834+
835+ public void setGroups(List<String> groups) {
836+ this.groups = groups;
837+ }
838+
839+ public List<List<Map<String, JSONArray>>> getChildren() {
840+ return children;
841+ }
842+
843+ public void setChildren(List<List<Map<String, JSONArray>>> children) {
844+ this.children = children;
845+ }
846+ }
847+
848+ private final String LOG_TAG = this.getClass().getName();
849 }
850
851=== modified file 'src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java'
852--- src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2013-04-07 12:24:38 +0000
853+++ src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2013-06-04 19:32:29 +0000
854@@ -43,162 +43,162 @@
855 import org.openlp.android.R;
856
857 public class ConnectionPreferenceActivity extends PreferenceActivity {
858- private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";
859- private final String KEY_SERVER_ID = "keyServerId";
860- private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
861- private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
862-
863- private PreferenceScreen preferenceScreen = null;
864- private boolean resume = true;
865-
866- @Override
867- protected void onCreate(Bundle savedInstanceState) {
868- super.onCreate(savedInstanceState);
869- addPreferencesFromResource(R.xml.empty_preferences);
870- getPreferenceManager()
871- .setSharedPreferencesName(getString(R.string.keySharedPreferences));
872- preferenceScreen = getPreferenceScreen() == null
873- ? getPreferenceManager().createPreferenceScreen(this)
874- : getPreferenceScreen();
875- preferenceScreen.removeAll();
876- String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);
877- if (preferenceDisplay != null
878- && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
879- constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
880- } else {
881- resume = false;
882- constructOverviewScreen();
883- }
884- }
885-
886- private void constructOverviewScreen() {
887- getPreferenceScreen().removeAll();
888- Log.i(LOG_TAG, "constructOverviewScreen");
889- Preference configPref = new Preference(this);
890- configPref.setTitle(getString(R.string.connection_available_configurations));
891- configPref.setSummary(getString(R.string.connection_add_by_menu));
892- configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
893- @Override
894- public boolean onPreferenceClick(Preference preference) {
895- int nextId = getNextPrefId(
896- getHostConfigMap(
897- getPreferenceManager()
898- .getSharedPreferences().getAll()
899- )
900- );
901- Preference newPreference = simpleClickablePreferenceFromHostConfig(
902- new HostConfig(
903- getString(R.string.connection_profile_server),
904- nextId));
905- newPreference.setTitle(getString(R.string.connection_profile_new_server));
906- newPreference.setSummary(getString(R.string.connection_profile_not_saved));
907- preferenceScreen.addPreference(newPreference);
908- return true;
909- }
910- });
911- preferenceScreen.addPreference(configPref);
912- List<HostConfig> hostConfigs = getHostConfigs();
913- if (!hostConfigs.isEmpty()) {
914- for (final HostConfig config : getHostConfigs()) {
915- preferenceScreen.addPreference(
916- simpleClickablePreferenceFromHostConfig(config));
917- }
918- }
919- }
920-
921- private void constructServerView(int hostId) {
922- HostConfig hostConfig = hostConfigFromPreferencesForHostId(
923- hostId,
924- getHostConfigMap(
925- getPreferenceManager()
926- .getSharedPreferences()
927- .getAll()
928- )
929- );
930- addPreferenceCategory(preferenceScreen, hostConfig);
931- }
932-
933- private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
934- final Preference serverConfig = new Preference(this);
935- serverConfig.setTitle(config.title.getSummary());
936-
937- Boolean useSsl = getPreferenceManager()
938- .getSharedPreferences()
939- .getBoolean(config.useSsl.getKey(), false);
940-
941- serverConfig.setSummary(String.format(
942- "%s:%s %s",
943- config.hostAddress.getText(),
944- config.hostPort.getText(),
945- useSsl ? "(SSL)" : "")
946- );
947- serverConfig.setOnPreferenceClickListener(
948- new Preference.OnPreferenceClickListener() {
949- @Override
950- public boolean onPreferenceClick(Preference preference) {
951- Intent serverConfigIntent = new Intent(
952- ConnectionPreferenceActivity.this,
953- ConnectionPreferenceActivity.class
954- );
955- serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,
956- PREFERENCE_DISPLAY_SERVER);
957- serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
958- startActivity(serverConfigIntent);
959- return true;
960- }
961- });
962- return serverConfig;
963- }
964-
965- private List<HostConfig> getHostConfigs() {
966- return hostConfigsFromPreferences(
967- getHostConfigMap(
968- getPreferenceManager()
969- .getSharedPreferences()
970- .getAll()
971- )
972- );
973- }
974-
975- private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
976- Map<String, Object> configMap = new TreeMap<String, Object>();
977-
978- List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
979- Collections.sort(sortedKeys);
980- for (String key : sortedKeys) {
981- if (key.startsWith(HostConfig.KEY_PREFIX)) {
982- configMap.put(key, preferences.get(key));
983- }
984- }
985- return configMap;
986- }
987-
988- private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
989- List<Integer> hostIds = getHostIds(preferences);
990- List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
991- for (Integer id : hostIds) {
992- hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
993- }
994- return hostConfigs;
995- }
996-
997- private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
998- Object titleValue = preferences.get(getHostConfigTitleKey(hostId));
999- String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();
1000- HostConfig hostConfig = new HostConfig(
1001- hostTitle, hostId
1002- );
1003- Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
1004- String hostValue = hostValueObject == null
1005- ? getString(R.string.hostDefaultValue) : hostValueObject.toString();
1006- hostConfig.hostAddress.setText(hostValue);
1007- hostConfig.hostAddress.setSummary(hostValue);
1008-
1009- Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
1010- String portValue = portValueObject == null
1011- ? getString(R.string.portDefaultValue) : portValueObject.toString();
1012- hostConfig.hostPort.setText(portValue);
1013- hostConfig.hostPort.setSummary(portValue);
1014+ private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";
1015+ private final String KEY_SERVER_ID = "keyServerId";
1016+ private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
1017+ private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
1018+
1019+ private PreferenceScreen preferenceScreen = null;
1020+ private boolean resume = true;
1021+
1022+ @Override
1023+ protected void onCreate(Bundle savedInstanceState) {
1024+ super.onCreate(savedInstanceState);
1025+ addPreferencesFromResource(R.xml.empty_preferences);
1026+ getPreferenceManager()
1027+ .setSharedPreferencesName(getString(R.string.keySharedPreferences));
1028+ preferenceScreen = getPreferenceScreen() == null
1029+ ? getPreferenceManager().createPreferenceScreen(this)
1030+ : getPreferenceScreen();
1031+ preferenceScreen.removeAll();
1032+ String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);
1033+ if (preferenceDisplay != null
1034+ && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
1035+ constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
1036+ } else {
1037+ resume = false;
1038+ constructOverviewScreen();
1039+ }
1040+ }
1041+
1042+ private void constructOverviewScreen() {
1043+ getPreferenceScreen().removeAll();
1044+ Log.i(LOG_TAG, "constructOverviewScreen");
1045+ Preference configPref = new Preference(this);
1046+ configPref.setTitle(getString(R.string.connection_available_configurations));
1047+ configPref.setSummary(getString(R.string.connection_add_by_menu));
1048+ configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1049+ @Override
1050+ public boolean onPreferenceClick(Preference preference) {
1051+ int nextId = getNextPrefId(
1052+ getHostConfigMap(
1053+ getPreferenceManager()
1054+ .getSharedPreferences().getAll()
1055+ )
1056+ );
1057+ Preference newPreference = simpleClickablePreferenceFromHostConfig(
1058+ new HostConfig(
1059+ getString(R.string.connection_profile_server),
1060+ nextId));
1061+ newPreference.setTitle(getString(R.string.connection_profile_new_server));
1062+ newPreference.setSummary(getString(R.string.connection_profile_not_saved));
1063+ preferenceScreen.addPreference(newPreference);
1064+ return true;
1065+ }
1066+ });
1067+ preferenceScreen.addPreference(configPref);
1068+ List<HostConfig> hostConfigs = getHostConfigs();
1069+ if (!hostConfigs.isEmpty()) {
1070+ for (final HostConfig config : getHostConfigs()) {
1071+ preferenceScreen.addPreference(
1072+ simpleClickablePreferenceFromHostConfig(config));
1073+ }
1074+ }
1075+ }
1076+
1077+ private void constructServerView(int hostId) {
1078+ HostConfig hostConfig = hostConfigFromPreferencesForHostId(
1079+ hostId,
1080+ getHostConfigMap(
1081+ getPreferenceManager()
1082+ .getSharedPreferences()
1083+ .getAll()
1084+ )
1085+ );
1086+ addPreferenceCategory(preferenceScreen, hostConfig);
1087+ }
1088+
1089+ private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
1090+ final Preference serverConfig = new Preference(this);
1091+ serverConfig.setTitle(config.title.getSummary());
1092+
1093+ Boolean useSsl = getPreferenceManager()
1094+ .getSharedPreferences()
1095+ .getBoolean(config.useSsl.getKey(), false);
1096+
1097+ serverConfig.setSummary(String.format(
1098+ "%s:%s %s",
1099+ config.hostAddress.getText(),
1100+ config.hostPort.getText(),
1101+ useSsl ? "(SSL)" : "")
1102+ );
1103+ serverConfig.setOnPreferenceClickListener(
1104+ new Preference.OnPreferenceClickListener() {
1105+ @Override
1106+ public boolean onPreferenceClick(Preference preference) {
1107+ Intent serverConfigIntent = new Intent(
1108+ ConnectionPreferenceActivity.this,
1109+ ConnectionPreferenceActivity.class
1110+ );
1111+ serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,
1112+ PREFERENCE_DISPLAY_SERVER);
1113+ serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
1114+ startActivity(serverConfigIntent);
1115+ return true;
1116+ }
1117+ });
1118+ return serverConfig;
1119+ }
1120+
1121+ private List<HostConfig> getHostConfigs() {
1122+ return hostConfigsFromPreferences(
1123+ getHostConfigMap(
1124+ getPreferenceManager()
1125+ .getSharedPreferences()
1126+ .getAll()
1127+ )
1128+ );
1129+ }
1130+
1131+ private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
1132+ Map<String, Object> configMap = new TreeMap<String, Object>();
1133+
1134+ List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
1135+ Collections.sort(sortedKeys);
1136+ for (String key : sortedKeys) {
1137+ if (key.startsWith(HostConfig.KEY_PREFIX)) {
1138+ configMap.put(key, preferences.get(key));
1139+ }
1140+ }
1141+ return configMap;
1142+ }
1143+
1144+ private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
1145+ List<Integer> hostIds = getHostIds(preferences);
1146+ List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
1147+ for (Integer id : hostIds) {
1148+ hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
1149+ }
1150+ return hostConfigs;
1151+ }
1152+
1153+ private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
1154+ Object titleValue = preferences.get(getHostConfigTitleKey(hostId));
1155+ String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();
1156+ HostConfig hostConfig = new HostConfig(
1157+ hostTitle, hostId
1158+ );
1159+ Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
1160+ String hostValue = hostValueObject == null
1161+ ? getString(R.string.hostDefaultValue) : hostValueObject.toString();
1162+ hostConfig.hostAddress.setText(hostValue);
1163+ hostConfig.hostAddress.setSummary(hostValue);
1164+
1165+ Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
1166+ String portValue = portValueObject == null
1167+ ? getString(R.string.portDefaultValue) : portValueObject.toString();
1168+ hostConfig.hostPort.setText(portValue);
1169+ hostConfig.hostPort.setSummary(portValue);
1170
1171 Object useridValueObject = preferences.get(hostConfig.userid.getKey());
1172 String useridValue = useridValueObject == null
1173@@ -211,106 +211,106 @@
1174 ? getString(R.string.passwordDefaultValue) : passwordValueObject.toString();
1175 hostConfig.password.setText(passwordValue);
1176 hostConfig.password.setSummary(passwordValue);
1177- return hostConfig;
1178- }
1179-
1180- private int getNextPrefId(Map<String, ?> preferences) {
1181- int max = 0;
1182- for (String key : preferences.keySet()) {
1183- int prefValue = Integer.valueOf(key.split("\\.")[2]);
1184- max = prefValue > max ? prefValue : max;
1185- }
1186- return max + 1;
1187- }
1188-
1189- private List<Integer> getHostIds(Map<String, ?> preferences) {
1190- Set<Integer> hashSet = new HashSet<Integer>();
1191- for (String key : preferences.keySet()) {
1192- hashSet.add(Integer.valueOf(key.split("\\.")[2]));
1193- }
1194- List<Integer> hostIds = new ArrayList<Integer>(hashSet);
1195- Collections.sort(hostIds);
1196- Log.i(LOG_TAG, "Got HostIds: " + hostIds);
1197- return hostIds;
1198- }
1199-
1200- private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
1201- PreferenceCategory preferenceCategory = new PreferenceCategory(this);
1202- preferenceCategory.setTitle(hostConfig.title.getSummary());
1203- preferenceCategory.setKey("key.preference.category");
1204- preferenceScreen.addPreference(preferenceCategory);
1205- preferenceCategory.addPreference(hostConfig.title);
1206- preferenceCategory.addPreference(hostConfig.hostAddress);
1207- preferenceCategory.addPreference(hostConfig.hostPort);
1208- preferenceCategory.addPreference(hostConfig.useSsl);
1209+ return hostConfig;
1210+ }
1211+
1212+ private int getNextPrefId(Map<String, ?> preferences) {
1213+ int max = 0;
1214+ for (String key : preferences.keySet()) {
1215+ int prefValue = Integer.valueOf(key.split("\\.")[2]);
1216+ max = prefValue > max ? prefValue : max;
1217+ }
1218+ return max + 1;
1219+ }
1220+
1221+ private List<Integer> getHostIds(Map<String, ?> preferences) {
1222+ Set<Integer> hashSet = new HashSet<Integer>();
1223+ for (String key : preferences.keySet()) {
1224+ hashSet.add(Integer.valueOf(key.split("\\.")[2]));
1225+ }
1226+ List<Integer> hostIds = new ArrayList<Integer>(hashSet);
1227+ Collections.sort(hostIds);
1228+ Log.i(LOG_TAG, "Got HostIds: " + hostIds);
1229+ return hostIds;
1230+ }
1231+
1232+ private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
1233+ PreferenceCategory preferenceCategory = new PreferenceCategory(this);
1234+ preferenceCategory.setTitle(hostConfig.title.getSummary());
1235+ preferenceCategory.setKey("key.preference.category");
1236+ preferenceScreen.addPreference(preferenceCategory);
1237+ preferenceCategory.addPreference(hostConfig.title);
1238+ preferenceCategory.addPreference(hostConfig.hostAddress);
1239+ preferenceCategory.addPreference(hostConfig.hostPort);
1240+ preferenceCategory.addPreference(hostConfig.useSsl);
1241 preferenceCategory.addPreference(hostConfig.userid);
1242 preferenceCategory.addPreference(hostConfig.password);
1243- preferenceCategory.addPreference(hostConfig.remove);
1244- preferenceCategory.addPreference(hostConfig.activate);
1245- return true;
1246- }
1247-
1248- @Override
1249- protected void onResume() {
1250- super.onResume();
1251- if (resume) {
1252- Log.i(LOG_TAG, "Resuming...");
1253- } else {
1254- constructOverviewScreen();
1255- Log.i(LOG_TAG, "Not resuming...");
1256- }
1257- }
1258-
1259- private static String getHostConfigTitleKey(int id) {
1260- return HostConfig.KEY_PREFIX + id + ".title";
1261- }
1262-
1263- private class HostConfig {
1264- static final String KEY_PREFIX = "host.config.";
1265- final int id;
1266- final EditTextPreference title;
1267- final EditTextPreference hostAddress;
1268- final EditTextPreference hostPort;
1269- final CheckBoxPreference useSsl;
1270+ preferenceCategory.addPreference(hostConfig.remove);
1271+ preferenceCategory.addPreference(hostConfig.activate);
1272+ return true;
1273+ }
1274+
1275+ @Override
1276+ protected void onResume() {
1277+ super.onResume();
1278+ if (resume) {
1279+ Log.i(LOG_TAG, "Resuming...");
1280+ } else {
1281+ constructOverviewScreen();
1282+ Log.i(LOG_TAG, "Not resuming...");
1283+ }
1284+ }
1285+
1286+ private static String getHostConfigTitleKey(int id) {
1287+ return HostConfig.KEY_PREFIX + id + ".title";
1288+ }
1289+
1290+ private class HostConfig {
1291+ static final String KEY_PREFIX = "host.config.";
1292+ final int id;
1293+ final EditTextPreference title;
1294+ final EditTextPreference hostAddress;
1295+ final EditTextPreference hostPort;
1296+ final CheckBoxPreference useSsl;
1297 final EditTextPreference userid;
1298 final EditTextPreference password;
1299- final Preference remove;
1300- final Preference activate;
1301-
1302- HostConfig(String sTitle, int id) {
1303- this.id = id;
1304- title = new EditTextPreference(ConnectionPreferenceActivity.this);
1305- title.setSummary(getString(R.string.url));
1306- title.getEditText().setHint(getString(R.string.url));
1307- title.setTitle(getString(R.string.connection_profile_title));
1308- title.setKey(KEY_PREFIX + id + ".title");
1309- title.setDefaultValue(getString(R.string.url));
1310- title.setSummary(sTitle);
1311- title.setDialogTitle(getString(R.string.connection_profile_title));
1312- title.setOnPreferenceChangeListener(onPreferenceChangeListener);
1313-
1314- hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
1315- hostAddress.setTitle(getString(R.string.urlHint));
1316- hostAddress.setKey(KEY_PREFIX + id + ".address");
1317- hostAddress.getEditText().setHint(R.string.urlHint);
1318- hostAddress.setSummary(getString(R.string.urlHint));
1319- hostAddress.setDialogTitle(getString(R.string.urlHint));
1320- hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
1321- hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
1322-
1323- hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
1324- hostPort.setTitle(getString(R.string.port));
1325- hostPort.setKey(KEY_PREFIX + id + ".port");
1326- hostPort.setSummary(getString(R.string.port));
1327- hostPort.setDialogTitle(getString(R.string.port));
1328- hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
1329- hostPort.setDefaultValue(getString(R.string.portDefaultValue));
1330- hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
1331-
1332- useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);
1333- useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
1334- useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
1335- useSsl.setKey(KEY_PREFIX + id + ".usessl");
1336+ final Preference remove;
1337+ final Preference activate;
1338+
1339+ HostConfig(String sTitle, int id) {
1340+ this.id = id;
1341+ title = new EditTextPreference(ConnectionPreferenceActivity.this);
1342+ title.setSummary(getString(R.string.url));
1343+ title.getEditText().setHint(getString(R.string.url));
1344+ title.setTitle(getString(R.string.connection_profile_title));
1345+ title.setKey(KEY_PREFIX + id + ".title");
1346+ title.setDefaultValue(getString(R.string.url));
1347+ title.setSummary(sTitle);
1348+ title.setDialogTitle(getString(R.string.connection_profile_title));
1349+ title.setOnPreferenceChangeListener(onPreferenceChangeListener);
1350+
1351+ hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
1352+ hostAddress.setTitle(getString(R.string.urlHint));
1353+ hostAddress.setKey(KEY_PREFIX + id + ".address");
1354+ hostAddress.getEditText().setHint(R.string.urlHint);
1355+ hostAddress.setSummary(getString(R.string.urlHint));
1356+ hostAddress.setDialogTitle(getString(R.string.urlHint));
1357+ hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
1358+ hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
1359+
1360+ hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
1361+ hostPort.setTitle(getString(R.string.port));
1362+ hostPort.setKey(KEY_PREFIX + id + ".port");
1363+ hostPort.setSummary(getString(R.string.port));
1364+ hostPort.setDialogTitle(getString(R.string.port));
1365+ hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
1366+ hostPort.setDefaultValue(getString(R.string.portDefaultValue));
1367+ hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
1368+
1369+ useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);
1370+ useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
1371+ useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
1372+ useSsl.setKey(KEY_PREFIX + id + ".usessl");
1373
1374 userid = new EditTextPreference(ConnectionPreferenceActivity.this);
1375 userid.setSummary(getString(R.string.connection_userid));
1376@@ -332,92 +332,92 @@
1377 password.setDialogTitle(getString(R.string.connection_password));
1378 password.setOnPreferenceChangeListener(onPreferenceChangeListener);
1379
1380- remove = new Preference(ConnectionPreferenceActivity.this);
1381- remove.setTitle(getString(R.string.connection_profile_remove));
1382- remove.setSummary(getString(R.string.connection_profile_remove_summary));
1383- remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1384- @Override
1385- public boolean onPreferenceClick(Preference preference) {
1386- SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
1387- SharedPreferences.Editor editor = prefs.edit();
1388- editor.remove(hostAddress.getKey());
1389- editor.remove(hostPort.getKey());
1390- editor.remove(title.getKey());
1391- editor.remove(useSsl.getKey());
1392+ remove = new Preference(ConnectionPreferenceActivity.this);
1393+ remove.setTitle(getString(R.string.connection_profile_remove));
1394+ remove.setSummary(getString(R.string.connection_profile_remove_summary));
1395+ remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1396+ @Override
1397+ public boolean onPreferenceClick(Preference preference) {
1398+ SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
1399+ SharedPreferences.Editor editor = prefs.edit();
1400+ editor.remove(hostAddress.getKey());
1401+ editor.remove(hostPort.getKey());
1402+ editor.remove(title.getKey());
1403+ editor.remove(useSsl.getKey());
1404 editor.remove(userid.getKey());
1405 editor.remove(password.getKey());
1406- editor.commit();
1407- ConnectionPreferenceActivity.this.onBackPressed();
1408- return false;
1409- }
1410- });
1411+ editor.commit();
1412+ ConnectionPreferenceActivity.this.onBackPressed();
1413+ return false;
1414+ }
1415+ });
1416
1417- activate = new Preference(ConnectionPreferenceActivity.this);
1418- activate.setTitle(getString(R.string.connection_profile_activate));
1419- activate.setSummary(getString(R.string.connection_profile_summary_activate));
1420- activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1421- @Override
1422- public boolean onPreferenceClick(Preference preference) {
1423- SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
1424- SharedPreferences.Editor editor = preferences.edit();
1425- String host = preferences.getString(hostAddress.getKey(),
1426- getString(R.string.hostDefaultValue));
1427- editor.putString(getString(R.string.keyHost), host);
1428- String port = preferences.getString(hostPort.getKey(),
1429- getString(R.string.portDefaultValue));
1430- editor.putString(getString(R.string.keyPort), port);
1431- Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
1432- editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
1433+ activate = new Preference(ConnectionPreferenceActivity.this);
1434+ activate.setTitle(getString(R.string.connection_profile_activate));
1435+ activate.setSummary(getString(R.string.connection_profile_summary_activate));
1436+ activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1437+ @Override
1438+ public boolean onPreferenceClick(Preference preference) {
1439+ SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
1440+ SharedPreferences.Editor editor = preferences.edit();
1441+ String host = preferences.getString(hostAddress.getKey(),
1442+ getString(R.string.hostDefaultValue));
1443+ editor.putString(getString(R.string.keyHost), host);
1444+ String port = preferences.getString(hostPort.getKey(),
1445+ getString(R.string.portDefaultValue));
1446+ editor.putString(getString(R.string.keyPort), port);
1447+ Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
1448+ editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
1449 String suserid = preferences.getString(userid.getKey(), getString(R.string.useridDefaultValue));
1450 editor.putString(getString(R.string.key_userid), suserid);
1451 String spassword = preferences.getString(password.getKey(),
1452 getString(R.string.passwordDefaultValue));
1453 editor.putString(getString(R.string.key_password), spassword);
1454
1455- editor.putString(
1456- getString(R.string.key_profile_selected_title),
1457- preferences.getString(
1458- title.getKey(),
1459- getString(R.string.url)));
1460-
1461- editor.commit();
1462- Toast.makeText(ConnectionPreferenceActivity.this,
1463- String.format(
1464- "%s: %s\n[%s:%s] %s",
1465- getString(R.string.connection_profile_active_toast),
1466- HostConfig.this.title.getText(),
1467- host,
1468- port,
1469- useSsl.isChecked() ? "(SSL)" : ""
1470- ),
1471- Toast.LENGTH_LONG).show();
1472- return false;
1473- }
1474- });
1475- }
1476-
1477- @Override
1478- public String toString() {
1479- return "HostConfig{" +
1480- "id=" + id +
1481- ", title='" + title + '\'' +
1482- ", hostAddress=" + hostAddress.getKey() +
1483- ", hostPort=" + hostPort.getKey() +
1484- '}';
1485- }
1486-
1487- Preference.OnPreferenceChangeListener onPreferenceChangeListener =
1488- new Preference.OnPreferenceChangeListener() {
1489- @Override
1490- public boolean onPreferenceChange(Preference preference, Object o) {
1491- preference.setSummary("" + o);
1492- if (preference.getKey().endsWith(".title")) {
1493- preferenceScreen
1494- .findPreference("key.preference.category")
1495- .setTitle("" + o);
1496- }
1497- return true;
1498- }
1499- };
1500- }
1501+ editor.putString(
1502+ getString(R.string.key_profile_selected_title),
1503+ preferences.getString(
1504+ title.getKey(),
1505+ getString(R.string.url)));
1506+
1507+ editor.commit();
1508+ Toast.makeText(ConnectionPreferenceActivity.this,
1509+ String.format(
1510+ "%s: %s\n[%s:%s] %s",
1511+ getString(R.string.connection_profile_active_toast),
1512+ HostConfig.this.title.getText(),
1513+ host,
1514+ port,
1515+ useSsl.isChecked() ? "(SSL)" : ""
1516+ ),
1517+ Toast.LENGTH_LONG).show();
1518+ return false;
1519+ }
1520+ });
1521+ }
1522+
1523+ @Override
1524+ public String toString() {
1525+ return "HostConfig{" +
1526+ "id=" + id +
1527+ ", title='" + title + '\'' +
1528+ ", hostAddress=" + hostAddress.getKey() +
1529+ ", hostPort=" + hostPort.getKey() +
1530+ '}';
1531+ }
1532+
1533+ Preference.OnPreferenceChangeListener onPreferenceChangeListener =
1534+ new Preference.OnPreferenceChangeListener() {
1535+ @Override
1536+ public boolean onPreferenceChange(Preference preference, Object o) {
1537+ preference.setSummary("" + o);
1538+ if (preference.getKey().endsWith(".title")) {
1539+ preferenceScreen
1540+ .findPreference("key.preference.category")
1541+ .setTitle("" + o);
1542+ }
1543+ return true;
1544+ }
1545+ };
1546+ }
1547 }
1548
1549=== modified file 'src/org/openlp/android/activity/preference/Preferences.java'
1550--- src/org/openlp/android/activity/preference/Preferences.java 2013-04-06 13:44:51 +0000
1551+++ src/org/openlp/android/activity/preference/Preferences.java 2013-06-04 19:32:29 +0000
1552@@ -50,99 +50,100 @@
1553 buildPreferences();
1554 }
1555
1556- private void buildPreferences() {
1557- if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
1558-
1559- getPreferenceManager()
1560- .setSharedPreferencesName(getString(R.string.keySharedPreferences));
1561-
1562- addPreferencesFromResource(R.xml.preferences);
1563- final SharedPreferences sharedPreferences = getPreferenceManager()
1564- .getSharedPreferences();
1565-
1566- StringBuilder stringBuilder = new StringBuilder();
1567- stringBuilder.append(sharedPreferences.getString(
1568- getString(R.string.keyHost),
1569- getString(R.string.notSet)));
1570- stringBuilder.append(":");
1571-
1572- Boolean useSsl = sharedPreferences.getBoolean(
1573- getString(R.string.key_ssl_use), false);
1574- stringBuilder.append(
1575- String.format("%s %s",
1576- sharedPreferences.getString(
1577- getString(R.string.keyPort),
1578- getString(R.string.notSet)), useSsl ? "(SSL)" : ""));
1579-
1580- final Preference hostPreference = findPreference(getString(R.string.keyHost));
1581- hostPreference.setTitle(
1582- getPreferenceManager().getSharedPreferences()
1583- .getString(
1584- getString(R.string.key_profile_selected_title),
1585- getString(R.string.url)
1586- )
1587- );
1588- hostPreference.setSummary(stringBuilder.toString());
1589-
1590- PackageManager manager = this.getPackageManager();
1591- String version = "";
1592- try {
1593- PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
1594- version = info.versionName;
1595- } catch (PackageManager.NameNotFoundException ignored) {}
1596-
1597- String date = new SimpleDateFormat("yyyy").format(new Date());
1598-
1599- //Preferences time! (we build the preferences)
1600- Preference about = getPreference(getString(R.string.about_text), version, null);
1601- about.setSelectable(false);
1602- Preference openlpLink = getPreference(
1603- getString(R.string.about_display_3),
1604- getString(R.string.about_display_1),
1605- new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));
1606-
1607- StringBuilder html = new StringBuilder();
1608- html.append(getString(R.string.about_display_4));
1609- html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
1610- html.append(getString(R.string.about_display_5));
1611- html.append(" © 2004-").append(date);
1612- html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
1613-
1614- Preference copyright = getPreference(
1615- getString(R.string.about_display_4),
1616- html.toString(), null);
1617- copyright.setSelectable(false);
1618-
1619- DialogPreference license = new MyDialogPreference(
1620- this,
1621- getString(R.string.about_display_6),
1622- String.format(
1623- "%s\n%s",
1624- getString(R.string.about_display_7),
1625- getString(R.string.about_display_8)
1626- )
1627- );
1628-
1629-
1630- PreferenceScreen preferenceScreen = getPreferenceScreen();
1631- addPreferenceCategory(preferenceScreen,getString(R.string.about),
1632- about, openlpLink, copyright, license);
1633-
1634- Preference preference = findPreference(getString(R.string.keyHost));
1635- preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
1636- }
1637+ private void buildPreferences() {
1638+ if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
1639+
1640+ getPreferenceManager()
1641+ .setSharedPreferencesName(getString(R.string.keySharedPreferences));
1642+
1643+ addPreferencesFromResource(R.xml.preferences);
1644+ final SharedPreferences sharedPreferences = getPreferenceManager()
1645+ .getSharedPreferences();
1646+
1647+ StringBuilder stringBuilder = new StringBuilder();
1648+ stringBuilder.append(sharedPreferences.getString(
1649+ getString(R.string.keyHost),
1650+ getString(R.string.notSet)));
1651+ stringBuilder.append(":");
1652+
1653+ Boolean useSsl = sharedPreferences.getBoolean(
1654+ getString(R.string.key_ssl_use), false);
1655+ stringBuilder.append(
1656+ String.format("%s %s",
1657+ sharedPreferences.getString(
1658+ getString(R.string.keyPort),
1659+ getString(R.string.notSet)), useSsl ? "(SSL)" : ""));
1660+
1661+ final Preference hostPreference = findPreference(getString(R.string.keyHost));
1662+ hostPreference.setTitle(
1663+ getPreferenceManager().getSharedPreferences()
1664+ .getString(
1665+ getString(R.string.key_profile_selected_title),
1666+ getString(R.string.url)
1667+ )
1668+ );
1669+ hostPreference.setSummary(stringBuilder.toString());
1670+
1671+ PackageManager manager = this.getPackageManager();
1672+ String version = "";
1673+ try {
1674+ PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
1675+ version = info.versionName;
1676+ } catch (PackageManager.NameNotFoundException ignored) {
1677+ }
1678+
1679+ String date = new SimpleDateFormat("yyyy").format(new Date());
1680+
1681+ //Preferences time! (we build the preferences)
1682+ Preference about = getPreference(getString(R.string.about_text), version, null);
1683+ about.setSelectable(false);
1684+ Preference openlpLink = getPreference(
1685+ getString(R.string.about_display_3),
1686+ getString(R.string.about_display_1),
1687+ new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));
1688+
1689+ StringBuilder html = new StringBuilder();
1690+ html.append(getString(R.string.about_display_4));
1691+ html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
1692+ html.append(getString(R.string.about_display_5));
1693+ html.append(" © 2004-").append(date);
1694+ html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
1695+
1696+ Preference copyright = getPreference(
1697+ getString(R.string.about_display_4),
1698+ html.toString(), null);
1699+ copyright.setSelectable(false);
1700+
1701+ DialogPreference license = new MyDialogPreference(
1702+ this,
1703+ getString(R.string.about_display_6),
1704+ String.format(
1705+ "%s\n%s",
1706+ getString(R.string.about_display_7),
1707+ getString(R.string.about_display_8)
1708+ )
1709+ );
1710+
1711+
1712+ PreferenceScreen preferenceScreen = getPreferenceScreen();
1713+ addPreferenceCategory(preferenceScreen, getString(R.string.about),
1714+ about, openlpLink, copyright, license);
1715+
1716+ Preference preference = findPreference(getString(R.string.keyHost));
1717+ preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
1718+ }
1719
1720 private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,
1721- String titleCategory, Preference... preferences) {
1722-
1723- boolean addPreference = false;
1724-
1725- for (Preference preference : preferences) {
1726+ String titleCategory, Preference... preferences) {
1727+
1728+ boolean addPreference = false;
1729+
1730+ for (Preference preference : preferences) {
1731 if (preference != null)
1732 addPreference = true;
1733 }
1734
1735- if (addPreference) {
1736+ if (addPreference) {
1737 PreferenceCategory preferenceCategory = new PreferenceCategory(this);
1738 preferenceCategory.setTitle(titleCategory);
1739 preferenceScreen.addPreference(preferenceCategory);
1740@@ -178,12 +179,12 @@
1741 Log.d(LOG_TAG, "Destroying preferences");
1742 }
1743
1744- @Override
1745- protected void onResume() {
1746- super.onResume();
1747- Log.i(LOG_TAG, "Resuming Preferences...");
1748- buildPreferences();
1749- }
1750+ @Override
1751+ protected void onResume() {
1752+ super.onResume();
1753+ Log.i(LOG_TAG, "Resuming Preferences...");
1754+ buildPreferences();
1755+ }
1756
1757- private final String LOG_TAG = Preferences.class.getName();
1758+ private final String LOG_TAG = Preferences.class.getName();
1759 }
1760
1761=== modified file 'src/org/openlp/android/api/Api.java'
1762--- src/org/openlp/android/api/Api.java 2013-04-06 13:44:51 +0000
1763+++ src/org/openlp/android/api/Api.java 2013-06-04 19:32:29 +0000
1764@@ -91,32 +91,40 @@
1765
1766 public interface Api {
1767
1768- public final String LIVE_BASE = "/api/controller/live/";
1769- public final String LIVE_NEXT = "/api/controller/live/next";
1770- public final String LIVE_PREVIOUS = "/api/controller/live/previous";
1771- public final String LIVE_TEXT = "/api/controller/live/text";
1772- public final String LIVE_SET = "/api/controller/live/set?data=";
1773-
1774- /** Use with {@link #SERVICE_BASE} + (previous|next) */
1775- public final String SERVICE_BASE = "/api/service/";
1776- // todo: cleanup, use {@link #SERVICE_BASE}
1777- public final String SERVICE_LIST = "/api/service/list";
1778- public final String SERVICE_SET = "/api/service/set?data=";
1779-
1780- /** Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show) */
1781- public final String DISPLAY_BASE = "/api/display/";
1782- public final String POLL_STATUS = "/api/poll";
1783-
1784- public final String ALERT = "/api/alert?data=";
1785-
1786- public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
1787- /**
1788- * This is a special string that uses the String.format() method. See
1789- * {@link String#format(String, Object...)}
1790- */
1791- public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
1792- /** Match intent extra key with regex since multiple plugins can be inserted */
1793- public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
1794- /** Match intent extra key with regex since multiple plugins can be inserted */
1795- public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
1796+ public final String LIVE_BASE = "/api/controller/live/";
1797+ public final String LIVE_NEXT = "/api/controller/live/next";
1798+ public final String LIVE_PREVIOUS = "/api/controller/live/previous";
1799+ public final String LIVE_TEXT = "/api/controller/live/text";
1800+ public final String LIVE_SET = "/api/controller/live/set?data=";
1801+
1802+ /**
1803+ * Use with {@link #SERVICE_BASE} + (previous|next)
1804+ */
1805+ public final String SERVICE_BASE = "/api/service/";
1806+ // todo: cleanup, use {@link #SERVICE_BASE}
1807+ public final String SERVICE_LIST = "/api/service/list";
1808+ public final String SERVICE_SET = "/api/service/set?data=";
1809+
1810+ /**
1811+ * Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show)
1812+ */
1813+ public final String DISPLAY_BASE = "/api/display/";
1814+ public final String POLL_STATUS = "/api/poll";
1815+
1816+ public final String ALERT = "/api/alert?data=";
1817+
1818+ public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
1819+ /**
1820+ * This is a special string that uses the String.format() method. See
1821+ * {@link String#format(String, Object...)}
1822+ */
1823+ public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
1824+ /**
1825+ * Match intent extra key with regex since multiple plugins can be inserted
1826+ */
1827+ public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
1828+ /**
1829+ * Match intent extra key with regex since multiple plugins can be inserted
1830+ */
1831+ public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
1832 }
1833
1834=== modified file 'src/org/openlp/android/data/Poll.java'
1835--- src/org/openlp/android/data/Poll.java 2013-04-06 13:44:51 +0000
1836+++ src/org/openlp/android/data/Poll.java 2013-06-04 19:32:29 +0000
1837@@ -23,99 +23,99 @@
1838
1839 public class Poll {
1840
1841- private int slide;
1842- private String item;
1843- private int service = -1;
1844- private boolean twelveHourDisplay = false;
1845- private boolean blankedDisplayed = false;
1846- private boolean themeDisplayed = false;
1847- private boolean desktopDisplayed = false;
1848- private boolean displayHidden = false;
1849-
1850- public int getSlide() {
1851- return slide;
1852- }
1853-
1854- public void setSlide(int slide) {
1855- this.slide = slide;
1856- }
1857-
1858- public String getItem() {
1859- return item;
1860- }
1861-
1862- public void setItem(String item) {
1863- this.item = item;
1864- }
1865-
1866- public boolean isTwelveHourDisplay() {
1867- return twelveHourDisplay;
1868- }
1869-
1870- public void setTwelveHourDisplay(boolean twelveHourDisplay) {
1871- this.twelveHourDisplay = twelveHourDisplay;
1872- }
1873-
1874- public boolean isBlankedDisplayed() {
1875- return blankedDisplayed;
1876- }
1877-
1878- public void setBlankedDisplayed(boolean blankedDisplayed) {
1879- this.blankedDisplayed = blankedDisplayed;
1880- if (blankedDisplayed) {
1881- this.displayHidden = true;
1882- }
1883- }
1884-
1885- public boolean isThemeDisplayed() {
1886- return themeDisplayed;
1887- }
1888-
1889- public void setThemeDisplayed(boolean themeDisplayed) {
1890- this.themeDisplayed = themeDisplayed;
1891- if (themeDisplayed) {
1892- this.displayHidden = true;
1893- }
1894- }
1895-
1896- public boolean isDesktopDisplayed() {
1897- return desktopDisplayed;
1898- }
1899-
1900- public void setDesktopDisplayed(boolean desktopDisplayed) {
1901- this.desktopDisplayed = desktopDisplayed;
1902- if (desktopDisplayed) {
1903- this.displayHidden = true;
1904- }
1905- }
1906-
1907- public boolean isDisplayHidden() {
1908- return displayHidden;
1909- }
1910-
1911- public void setDisplayHidden(boolean displayHidden) {
1912- this.displayHidden = displayHidden;
1913- }
1914-
1915- public int getService() {
1916- return service;
1917- }
1918-
1919- public void setService(int service) {
1920- this.service = service;
1921- }
1922-
1923- @Override
1924- public String toString() {
1925- return "Poll{" +
1926- "slide=" + slide +
1927- ", item='" + item + '\'' +
1928- ", service=" + service +
1929- ", twelveHourDisplay=" + twelveHourDisplay +
1930- ", blankedDisplayed=" + blankedDisplayed +
1931- ", themeDisplayed=" + themeDisplayed +
1932- ", desktopDisplayed=" + desktopDisplayed +
1933- ", displayHidden=" + displayHidden +
1934- '}';
1935- }
1936+ private int slide;
1937+ private String item;
1938+ private int service = -1;
1939+ private boolean twelveHourDisplay = false;
1940+ private boolean blankedDisplayed = false;
1941+ private boolean themeDisplayed = false;
1942+ private boolean desktopDisplayed = false;
1943+ private boolean displayHidden = false;
1944+
1945+ public int getSlide() {
1946+ return slide;
1947+ }
1948+
1949+ public void setSlide(int slide) {
1950+ this.slide = slide;
1951+ }
1952+
1953+ public String getItem() {
1954+ return item;
1955+ }
1956+
1957+ public void setItem(String item) {
1958+ this.item = item;
1959+ }
1960+
1961+ public boolean isTwelveHourDisplay() {
1962+ return twelveHourDisplay;
1963+ }
1964+
1965+ public void setTwelveHourDisplay(boolean twelveHourDisplay) {
1966+ this.twelveHourDisplay = twelveHourDisplay;
1967+ }
1968+
1969+ public boolean isBlankedDisplayed() {
1970+ return blankedDisplayed;
1971+ }
1972+
1973+ public void setBlankedDisplayed(boolean blankedDisplayed) {
1974+ this.blankedDisplayed = blankedDisplayed;
1975+ if (blankedDisplayed) {
1976+ this.displayHidden = true;
1977+ }
1978+ }
1979+
1980+ public boolean isThemeDisplayed() {
1981+ return themeDisplayed;
1982+ }
1983+
1984+ public void setThemeDisplayed(boolean themeDisplayed) {
1985+ this.themeDisplayed = themeDisplayed;
1986+ if (themeDisplayed) {
1987+ this.displayHidden = true;
1988+ }
1989+ }
1990+
1991+ public boolean isDesktopDisplayed() {
1992+ return desktopDisplayed;
1993+ }
1994+
1995+ public void setDesktopDisplayed(boolean desktopDisplayed) {
1996+ this.desktopDisplayed = desktopDisplayed;
1997+ if (desktopDisplayed) {
1998+ this.displayHidden = true;
1999+ }
2000+ }
2001+
2002+ public boolean isDisplayHidden() {
2003+ return displayHidden;
2004+ }
2005+
2006+ public void setDisplayHidden(boolean displayHidden) {
2007+ this.displayHidden = displayHidden;
2008+ }
2009+
2010+ public int getService() {
2011+ return service;
2012+ }
2013+
2014+ public void setService(int service) {
2015+ this.service = service;
2016+ }
2017+
2018+ @Override
2019+ public String toString() {
2020+ return "Poll{" +
2021+ "slide=" + slide +
2022+ ", item='" + item + '\'' +
2023+ ", service=" + service +
2024+ ", twelveHourDisplay=" + twelveHourDisplay +
2025+ ", blankedDisplayed=" + blankedDisplayed +
2026+ ", themeDisplayed=" + themeDisplayed +
2027+ ", desktopDisplayed=" + desktopDisplayed +
2028+ ", displayHidden=" + displayHidden +
2029+ '}';
2030+ }
2031 }
2032
2033=== modified file 'src/org/openlp/android/data/SlideItem.java'
2034--- src/org/openlp/android/data/SlideItem.java 2013-04-06 13:44:51 +0000
2035+++ src/org/openlp/android/data/SlideItem.java 2013-06-04 19:32:29 +0000
2036@@ -21,46 +21,46 @@
2037 package org.openlp.android.data;
2038
2039 public class SlideItem {
2040- private String text;
2041- private boolean selected;
2042- private String tag;
2043- private String html;
2044-
2045- public String getText() {
2046- return text;
2047- }
2048-
2049- public void setText(String text) {
2050- this.text = text;
2051- }
2052-
2053- public boolean isSelected() {
2054- return selected;
2055- }
2056-
2057- public void setSelected(boolean selected) {
2058- this.selected = selected;
2059- }
2060-
2061- public String getTag() {
2062- return tag;
2063- }
2064-
2065- public void setTag(String tag) {
2066- this.tag = tag;
2067- }
2068-
2069- public String getHtml() {
2070- return html;
2071- }
2072-
2073- public void setHtml(String html) {
2074- this.html = html;
2075- }
2076-
2077- @Override
2078- public String toString() {
2079- return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected
2080- + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';
2081- }
2082+ private String text;
2083+ private boolean selected;
2084+ private String tag;
2085+ private String html;
2086+
2087+ public String getText() {
2088+ return text;
2089+ }
2090+
2091+ public void setText(String text) {
2092+ this.text = text;
2093+ }
2094+
2095+ public boolean isSelected() {
2096+ return selected;
2097+ }
2098+
2099+ public void setSelected(boolean selected) {
2100+ this.selected = selected;
2101+ }
2102+
2103+ public String getTag() {
2104+ return tag;
2105+ }
2106+
2107+ public void setTag(String tag) {
2108+ this.tag = tag;
2109+ }
2110+
2111+ public String getHtml() {
2112+ return html;
2113+ }
2114+
2115+ public void setHtml(String html) {
2116+ this.html = html;
2117+ }
2118+
2119+ @Override
2120+ public String toString() {
2121+ return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected
2122+ + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';
2123+ }
2124 }
2125
2126=== modified file 'src/org/openlp/android/service/PingIntent.java'
2127--- src/org/openlp/android/service/PingIntent.java 2013-04-06 13:44:51 +0000
2128+++ src/org/openlp/android/service/PingIntent.java 2013-06-04 19:32:29 +0000
2129@@ -32,60 +32,60 @@
2130
2131 public class PingIntent extends Service {
2132
2133- private Handler handler = new Handler();
2134- private Integer delay;
2135-
2136- public PingIntent() {
2137- super();
2138- Log.v(LOG_TAG, "Instantiating PingIntent...");
2139-
2140- }
2141-
2142- @Override
2143- public IBinder onBind(Intent intent) {
2144- return null;
2145- }
2146-
2147- @Override
2148- public void onStart(Intent intent, int startId) {
2149- String PREFERENCES_KEY =
2150- getApplicationContext().getString(R.string.keySharedPreferences);
2151- SharedPreferences preferences = getApplicationContext()
2152- .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);
2153- Resources resources = getApplicationContext().getResources();
2154- delay = Integer.valueOf(
2155- resources.getString(R.string.backgroundRefreshDefaultValue));
2156- Log.v(LOG_TAG, "Starting PingIntent...");
2157- super.onStart(intent, startId);
2158- delay = Integer.parseInt(preferences
2159- .getString(resources.getString(R.string.keyBackgroundService),
2160- delay.toString()));
2161-
2162- Log.d(LOG_TAG, "PingIntent delay: " + delay);
2163- handler.removeCallbacks(r);
2164- handler.postDelayed(r, delay);
2165- }
2166-
2167- Runnable r = new Runnable() {
2168-
2169- @Override
2170- public void run() {
2171- Intent apiCallPingIntent =
2172- new Intent(getApplicationContext(), ApiCallIntent.class);
2173- apiCallPingIntent.putExtra(Api.POLL_STATUS, "");
2174- startService(apiCallPingIntent);
2175- if (delay > 0) {
2176- handler.postDelayed(r, delay);
2177+ private Handler handler = new Handler();
2178+ private Integer delay;
2179+
2180+ public PingIntent() {
2181+ super();
2182+ Log.v(LOG_TAG, "Instantiating PingIntent...");
2183+
2184+ }
2185+
2186+ @Override
2187+ public IBinder onBind(Intent intent) {
2188+ return null;
2189+ }
2190+
2191+ @Override
2192+ public void onStart(Intent intent, int startId) {
2193+ String PREFERENCES_KEY =
2194+ getApplicationContext().getString(R.string.keySharedPreferences);
2195+ SharedPreferences preferences = getApplicationContext()
2196+ .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);
2197+ Resources resources = getApplicationContext().getResources();
2198+ delay = Integer.valueOf(
2199+ resources.getString(R.string.backgroundRefreshDefaultValue));
2200+ Log.v(LOG_TAG, "Starting PingIntent...");
2201+ super.onStart(intent, startId);
2202+ delay = Integer.parseInt(preferences
2203+ .getString(resources.getString(R.string.keyBackgroundService),
2204+ delay.toString()));
2205+
2206+ Log.d(LOG_TAG, "PingIntent delay: " + delay);
2207+ handler.removeCallbacks(r);
2208+ handler.postDelayed(r, delay);
2209+ }
2210+
2211+ Runnable r = new Runnable() {
2212+
2213+ @Override
2214+ public void run() {
2215+ Intent apiCallPingIntent =
2216+ new Intent(getApplicationContext(), ApiCallIntent.class);
2217+ apiCallPingIntent.putExtra(Api.POLL_STATUS, "");
2218+ startService(apiCallPingIntent);
2219+ if (delay > 0) {
2220+ handler.postDelayed(r, delay);
2221+ }
2222 }
2223- }
2224- };
2225-
2226- @Override
2227- public void onDestroy() {
2228- Log.v(LOG_TAG, "Stopping PingIntent...");
2229- handler.removeCallbacks(r);
2230- super.onDestroy();
2231- }
2232-
2233- private static final String LOG_TAG = PingIntent.class.getName();
2234+ };
2235+
2236+ @Override
2237+ public void onDestroy() {
2238+ Log.v(LOG_TAG, "Stopping PingIntent...");
2239+ handler.removeCallbacks(r);
2240+ super.onDestroy();
2241+ }
2242+
2243+ private static final String LOG_TAG = PingIntent.class.getName();
2244 }
2245
2246=== modified file 'src/org/openlp/android/utility/GroupExpandableListAdapter.java'
2247--- src/org/openlp/android/utility/GroupExpandableListAdapter.java 2013-04-06 13:44:51 +0000
2248+++ src/org/openlp/android/utility/GroupExpandableListAdapter.java 2013-06-04 19:32:29 +0000
2249@@ -34,92 +34,91 @@
2250 import java.util.Map;
2251
2252 public class GroupExpandableListAdapter extends BaseExpandableListAdapter {
2253- List<String> groups;
2254- List<List<Map<String, JSONArray>>> children;
2255- LayoutInflater inflater;
2256- Activity context;
2257-
2258- public GroupExpandableListAdapter(Activity context, List<String> groups,
2259- List<List<Map<String, JSONArray>>> children) {
2260- this.context = context;
2261- this.groups = groups;
2262- this.children = children;
2263- inflater = context.getLayoutInflater();
2264- }
2265-
2266- @Override
2267- public int getGroupCount() {
2268- return groups.size();
2269- }
2270-
2271- @Override
2272- public int getChildrenCount(int position) {
2273- return children.get(position).size();
2274- }
2275-
2276- @Override
2277- public Object getGroup(int position) {
2278- return groups.get(position);
2279- }
2280-
2281- @Override
2282- public Object getChild(int rootPosition, int childPosition) {
2283- return children.get(rootPosition).get(childPosition);
2284- }
2285-
2286- @Override
2287- public long getGroupId(int position) {
2288- return groups.indexOf(groups.get(position));
2289- }
2290-
2291- @Override
2292- public long getChildId(int i, int i1) {
2293- List<Map<String, JSONArray>> child = children.get(i);
2294- return child.indexOf(child.get(i1));
2295- }
2296-
2297- @Override
2298- public boolean hasStableIds() {
2299- return false;
2300- }
2301-
2302- @Override
2303- public View getGroupView(int position, boolean b, View view,
2304- ViewGroup viewGroup) {
2305- if (view == null) {
2306- view = inflater.inflate(R.layout.group_parent, null);
2307- view.setClickable(false);
2308- }
2309- TextView textView = (TextView) view.findViewById(R.id.groupParentText);
2310- TextView numberView = (TextView) view
2311- .findViewById(R.id.parentChildCount);
2312- numberView.setText(String.format("%s", children.get(position).size()));
2313- textView.setText(groups.get(position));
2314- return view;
2315- }
2316-
2317- @Override
2318- public View getChildView(int groupPosition, int childPosition, boolean b,
2319- View view, ViewGroup viewGroup) {
2320- if (view == null) {
2321- view = inflater.inflate(R.layout.group_child, null);
2322- view.setClickable(false);
2323- }
2324- TextView childView = (TextView) view.findViewById(R.id.groupChildText);
2325- List<Map<String, JSONArray>> childItem = children.get(groupPosition);
2326- Map<String, JSONArray> mapItem = childItem.get(childPosition);
2327- JSONArray jsonItem = mapItem.get(groups.get(groupPosition));
2328- try {
2329- childView.setText(String.format("%s", jsonItem.get(1)));
2330- }
2331- catch (JSONException e) {
2332- e.printStackTrace();
2333- }
2334- return view;
2335- }
2336-
2337- @Override
2338- public boolean isChildSelectable(int i, int i1) {
2339- return true;
2340- }
2341+ List<String> groups;
2342+ List<List<Map<String, JSONArray>>> children;
2343+ LayoutInflater inflater;
2344+ Activity context;
2345+
2346+ public GroupExpandableListAdapter(Activity context, List<String> groups,
2347+ List<List<Map<String, JSONArray>>> children) {
2348+ this.context = context;
2349+ this.groups = groups;
2350+ this.children = children;
2351+ inflater = context.getLayoutInflater();
2352+ }
2353+
2354+ @Override
2355+ public int getGroupCount() {
2356+ return groups.size();
2357+ }
2358+
2359+ @Override
2360+ public int getChildrenCount(int position) {
2361+ return children.get(position).size();
2362+ }
2363+
2364+ @Override
2365+ public Object getGroup(int position) {
2366+ return groups.get(position);
2367+ }
2368+
2369+ @Override
2370+ public Object getChild(int rootPosition, int childPosition) {
2371+ return children.get(rootPosition).get(childPosition);
2372+ }
2373+
2374+ @Override
2375+ public long getGroupId(int position) {
2376+ return groups.indexOf(groups.get(position));
2377+ }
2378+
2379+ @Override
2380+ public long getChildId(int i, int i1) {
2381+ List<Map<String, JSONArray>> child = children.get(i);
2382+ return child.indexOf(child.get(i1));
2383+ }
2384+
2385+ @Override
2386+ public boolean hasStableIds() {
2387+ return false;
2388+ }
2389+
2390+ @Override
2391+ public View getGroupView(int position, boolean b, View view,
2392+ ViewGroup viewGroup) {
2393+ if (view == null) {
2394+ view = inflater.inflate(R.layout.group_parent, null);
2395+ view.setClickable(false);
2396+ }
2397+ TextView textView = (TextView) view.findViewById(R.id.groupParentText);
2398+ TextView numberView = (TextView) view
2399+ .findViewById(R.id.parentChildCount);
2400+ numberView.setText(String.format("%s", children.get(position).size()));
2401+ textView.setText(groups.get(position));
2402+ return view;
2403+ }
2404+
2405+ @Override
2406+ public View getChildView(int groupPosition, int childPosition, boolean b,
2407+ View view, ViewGroup viewGroup) {
2408+ if (view == null) {
2409+ view = inflater.inflate(R.layout.group_child, null);
2410+ view.setClickable(false);
2411+ }
2412+ TextView childView = (TextView) view.findViewById(R.id.groupChildText);
2413+ List<Map<String, JSONArray>> childItem = children.get(groupPosition);
2414+ Map<String, JSONArray> mapItem = childItem.get(childPosition);
2415+ JSONArray jsonItem = mapItem.get(groups.get(groupPosition));
2416+ try {
2417+ childView.setText(String.format("%s", jsonItem.get(1)));
2418+ } catch (JSONException e) {
2419+ e.printStackTrace();
2420+ }
2421+ return view;
2422+ }
2423+
2424+ @Override
2425+ public boolean isChildSelectable(int i, int i1) {
2426+ return true;
2427+ }
2428 }
2429
2430=== modified file 'src/org/openlp/android/utility/JSONHandler.java'
2431--- src/org/openlp/android/utility/JSONHandler.java 2013-04-06 13:44:51 +0000
2432+++ src/org/openlp/android/utility/JSONHandler.java 2013-06-04 19:32:29 +0000
2433@@ -38,139 +38,132 @@
2434
2435 public class JSONHandler {
2436
2437- public static String createRequestJSON(String key, String value)
2438- throws JSONHandlerException {
2439- try {
2440- String responseJSON;
2441- JSONObject jo = new JSONObject();
2442- jo.put(key, value);
2443- responseJSON = new JSONStringer().object().key("request").value(jo)
2444- .endObject().toString();
2445- responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
2446- return responseJSON;
2447- }
2448- catch (JSONException e) {
2449- throw new JSONHandlerException(e);
2450- }
2451- catch (UnsupportedEncodingException e) {
2452- throw new JSONHandlerException(e);
2453- }
2454- }
2455-
2456- public static List<SlideItem> parseServiceItemResponseJSON(
2457- HttpEntity entity)
2458- throws JSONHandlerException {
2459- try {
2460- List<SlideItem> serviceItemList;
2461- InputStream inputStream = entity.getContent();
2462- String result = StringHelper.convertStreamToString(inputStream);
2463- Log.v(LOG_TAG, result);
2464- serviceItemList = getServiceItemsFromString(result);
2465- inputStream.close();
2466- return serviceItemList;
2467- }
2468- catch (IOException e) {
2469- throw new JSONHandlerException(e);
2470- }
2471- }
2472-
2473- public static List<SlideItem> getServiceItemsFromString(String itemsJson)
2474- throws JSONHandlerException {
2475- try {
2476- List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
2477- JSONObject jObject = new JSONObject(itemsJson);
2478- JSONObject results = jObject.getJSONObject("results");
2479- JSONArray items = results.getJSONArray("items");
2480-
2481- for (int i = 0; i < items.length(); i++) {
2482- JSONObject item = items.getJSONObject(i);
2483- SlideItem slide = new SlideItem();
2484- slide.setTag("");
2485- slide.setText(item.getString("title"));
2486- slide.setSelected(item.getBoolean("selected"));
2487- slide.setHtml("");
2488- serviceItemList.add(slide);
2489- }
2490- return serviceItemList;
2491- }
2492- catch (JSONException e) {
2493- throw new JSONHandlerException(e);
2494- }
2495- }
2496-
2497- public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)
2498- throws JSONHandlerException {
2499- try {
2500- List<SlideItem> serviceItemList;
2501- InputStream inputStream = entity.getContent();
2502- String result = StringHelper.convertStreamToString(inputStream);
2503- Log.v(LOG_TAG, result);
2504- serviceItemList = getSlideItemsFromString(result);
2505- inputStream.close();
2506- return serviceItemList;
2507- }
2508- catch (IOException e) {
2509- throw new JSONHandlerException(e);
2510- }
2511- }
2512-
2513- public static List<SlideItem> getSlideItemsFromString(String itemJson)
2514- throws JSONHandlerException {
2515- try {
2516- JSONObject jObject = new JSONObject(itemJson);
2517- JSONObject results = jObject.getJSONObject("results");
2518- JSONArray items = results.getJSONArray("slides");
2519-
2520- List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
2521- for (int i = 0; i < items.length(); i++) {
2522- JSONObject item = items.getJSONObject(i);
2523- SlideItem slide = new SlideItem();
2524- slide.setText(item.getString("text"));
2525- slide.setTag(item.getString("tag"));
2526- slide.setSelected(item.getBoolean("selected"));
2527- slide.setHtml(item.getString("html"));
2528- serviceItemList.add(slide);
2529- }
2530- return serviceItemList;
2531- }
2532- catch (JSONException e) {
2533- throw new JSONHandlerException(e);
2534- }
2535- }
2536-
2537- public static Poll getPollFromString(String pollJson)
2538- throws JSONHandlerException {
2539- Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));
2540- try {
2541- JSONObject jObject = new JSONObject(pollJson);
2542- JSONObject results = jObject.getJSONObject("results");
2543- Poll poll = new Poll();
2544- poll.setSlide(results.getInt("slide"));
2545- poll.setItem(results.getString("item"));
2546- poll.setTwelveHourDisplay(results.getBoolean("twelve"));
2547- poll.setBlankedDisplayed(results.getBoolean("blank"));
2548- poll.setThemeDisplayed(results.getBoolean("theme"));
2549- poll.setDesktopDisplayed(results.getBoolean("display"));
2550- if (!results.has("service")) {
2551- Log.w(LOG_TAG,
2552- "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");
2553- }
2554- poll.setService(
2555- results.has("service") ? results.getInt("service") : -1);
2556- return poll;
2557- }
2558- catch (JSONException e) {
2559- throw new JSONHandlerException(e);
2560- }
2561- }
2562-
2563- public static class JSONHandlerException extends Exception {
2564- private static final long serialVersionUID = -6772307308404816615L;
2565-
2566- public JSONHandlerException(Throwable throwable) {
2567- super(throwable);
2568- }
2569- }
2570-
2571- private static String LOG_TAG = JSONHandler.class.getName();
2572+ public static String createRequestJSON(String key, String value)
2573+ throws JSONHandlerException {
2574+ try {
2575+ String responseJSON;
2576+ JSONObject jo = new JSONObject();
2577+ jo.put(key, value);
2578+ responseJSON = new JSONStringer().object().key("request").value(jo)
2579+ .endObject().toString();
2580+ responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
2581+ return responseJSON;
2582+ } catch (JSONException e) {
2583+ throw new JSONHandlerException(e);
2584+ } catch (UnsupportedEncodingException e) {
2585+ throw new JSONHandlerException(e);
2586+ }
2587+ }
2588+
2589+ public static List<SlideItem> parseServiceItemResponseJSON(
2590+ HttpEntity entity)
2591+ throws JSONHandlerException {
2592+ try {
2593+ List<SlideItem> serviceItemList;
2594+ InputStream inputStream = entity.getContent();
2595+ String result = StringHelper.convertStreamToString(inputStream);
2596+ Log.v(LOG_TAG, result);
2597+ serviceItemList = getServiceItemsFromString(result);
2598+ inputStream.close();
2599+ return serviceItemList;
2600+ } catch (IOException e) {
2601+ throw new JSONHandlerException(e);
2602+ }
2603+ }
2604+
2605+ public static List<SlideItem> getServiceItemsFromString(String itemsJson)
2606+ throws JSONHandlerException {
2607+ try {
2608+ List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
2609+ JSONObject jObject = new JSONObject(itemsJson);
2610+ JSONObject results = jObject.getJSONObject("results");
2611+ JSONArray items = results.getJSONArray("items");
2612+
2613+ for (int i = 0; i < items.length(); i++) {
2614+ JSONObject item = items.getJSONObject(i);
2615+ SlideItem slide = new SlideItem();
2616+ slide.setTag("");
2617+ slide.setText(item.getString("title"));
2618+ slide.setSelected(item.getBoolean("selected"));
2619+ slide.setHtml("");
2620+ serviceItemList.add(slide);
2621+ }
2622+ return serviceItemList;
2623+ } catch (JSONException e) {
2624+ throw new JSONHandlerException(e);
2625+ }
2626+ }
2627+
2628+ public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)
2629+ throws JSONHandlerException {
2630+ try {
2631+ List<SlideItem> serviceItemList;
2632+ InputStream inputStream = entity.getContent();
2633+ String result = StringHelper.convertStreamToString(inputStream);
2634+ Log.v(LOG_TAG, result);
2635+ serviceItemList = getSlideItemsFromString(result);
2636+ inputStream.close();
2637+ return serviceItemList;
2638+ } catch (IOException e) {
2639+ throw new JSONHandlerException(e);
2640+ }
2641+ }
2642+
2643+ public static List<SlideItem> getSlideItemsFromString(String itemJson)
2644+ throws JSONHandlerException {
2645+ try {
2646+ JSONObject jObject = new JSONObject(itemJson);
2647+ JSONObject results = jObject.getJSONObject("results");
2648+ JSONArray items = results.getJSONArray("slides");
2649+
2650+ List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
2651+ for (int i = 0; i < items.length(); i++) {
2652+ JSONObject item = items.getJSONObject(i);
2653+ SlideItem slide = new SlideItem();
2654+ slide.setText(item.getString("text"));
2655+ slide.setTag(item.getString("tag"));
2656+ slide.setSelected(item.getBoolean("selected"));
2657+ slide.setHtml(item.getString("html"));
2658+ serviceItemList.add(slide);
2659+ }
2660+ return serviceItemList;
2661+ } catch (JSONException e) {
2662+ throw new JSONHandlerException(e);
2663+ }
2664+ }
2665+
2666+ public static Poll getPollFromString(String pollJson)
2667+ throws JSONHandlerException {
2668+ Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));
2669+ try {
2670+ JSONObject jObject = new JSONObject(pollJson);
2671+ JSONObject results = jObject.getJSONObject("results");
2672+ Poll poll = new Poll();
2673+ poll.setSlide(results.getInt("slide"));
2674+ poll.setItem(results.getString("item"));
2675+ poll.setTwelveHourDisplay(results.getBoolean("twelve"));
2676+ poll.setBlankedDisplayed(results.getBoolean("blank"));
2677+ poll.setThemeDisplayed(results.getBoolean("theme"));
2678+ poll.setDesktopDisplayed(results.getBoolean("display"));
2679+ if (!results.has("service")) {
2680+ Log.w(LOG_TAG,
2681+ "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");
2682+ }
2683+ poll.setService(
2684+ results.has("service") ? results.getInt("service") : -1);
2685+ return poll;
2686+ } catch (JSONException e) {
2687+ throw new JSONHandlerException(e);
2688+ }
2689+ }
2690+
2691+ public static class JSONHandlerException extends Exception {
2692+ private static final long serialVersionUID = -6772307308404816615L;
2693+
2694+ public JSONHandlerException(Throwable throwable) {
2695+ super(throwable);
2696+ }
2697+ }
2698+
2699+ private static String LOG_TAG = JSONHandler.class.getName();
2700 }
2701
2702=== modified file 'src/org/openlp/android/utility/OpenLPController.java'
2703--- src/org/openlp/android/utility/OpenLPController.java 2013-04-06 13:44:51 +0000
2704+++ src/org/openlp/android/utility/OpenLPController.java 2013-06-04 19:32:29 +0000
2705@@ -56,579 +56,560 @@
2706
2707 public class OpenLPController extends PagerAdapter {
2708
2709- private static Activity context;
2710- private ListView listViewService;
2711- private ListView listViewLive;
2712- private int currentService = -1;
2713- private int currentLive = -1;
2714- private String itemId = "";
2715-
2716- private static int currentPage = 0;
2717-
2718- public static final String PAGE_KEY = "openlp.pageKey";
2719- public static final int PAGE_SERVICE = 0;
2720- public static final int PAGE_LIVE = 1;
2721- public static final int PAGE_DISPLAY = 2;
2722- public static final int PAGE_STAGE = 3;
2723- public static final int PAGE_ALERT = 4;
2724- public static final int PAGE_SEARCH = 5;
2725-
2726- private String displayType;
2727- private WebView webView;
2728- private SharedPreferences preferences;
2729-
2730- public Intent pingIntent;
2731- public Intent apiCallIntent;
2732-
2733- public OpenLPController(Activity context) {
2734- OpenLPController.context = context;
2735- preferences = context.getApplicationContext().getSharedPreferences(
2736- context.getString(R.string.keySharedPreferences),
2737- Context.MODE_PRIVATE);
2738- pingIntent = new Intent(context, PingIntent.class);
2739- apiCallIntent = new Intent(context, ApiCallIntent.class);
2740-
2741- IntentFilter apiCallFilter =
2742- new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);
2743- apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
2744- context.registerReceiver(apiCallReceiver, apiCallFilter);
2745- }
2746-
2747- public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
2748- @Override
2749- public void onReceive(Context broadcastedContext, Intent intent) {
2750- Log.v(LOG_TAG, String
2751- .format("%s broadcast received: intent(%s), context(%s)",
2752- ApiCallIntent.API_CALL_RECEIVE, intent,
2753- broadcastedContext));
2754- if (intent.hasExtra("error")) {
2755- context.stopService(pingIntent);
2756- Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +
2757- intent.getStringExtra("error"));
2758- Toast.makeText(broadcastedContext, String
2759- .format("%s: %s", context.getString(R.string.requestFailed),
2760- intent.getStringExtra("error")), Toast.LENGTH_LONG)
2761- .show();
2762- }
2763- else {
2764- if (intent.hasExtra("apiBase")) {
2765- String apiBase = intent.getStringExtra("apiBase");
2766- if (apiBase.equals(Api.ALERT)) {
2767- Toast.makeText(broadcastedContext, "Alert sent!",
2768- Toast.LENGTH_SHORT).show();
2769- }
2770- if (apiBase.equals(Api.DISPLAY_BASE)) {
2771- controller.poll();
2772- }
2773- if (apiBase.equals(Api.POLL_STATUS)) {
2774- handlePollResponse(intent.getStringExtra("pollJson"));
2775- }
2776- if (apiBase.equals(Api.LIVE_TEXT)) {
2777- handleLiveItemsResponse(
2778- intent.getStringExtra("itemsJson"));
2779- }
2780- if (apiBase.equals(Api.SERVICE_LIST)) {
2781- handleServiceItemsResponse(
2782- intent.getStringExtra("itemsJson"));
2783- }
2784- }
2785- }
2786- }
2787- };
2788-
2789- private void handlePollResponse(final String pollResponse) {
2790- try {
2791-
2792- Poll poll = JSONHandler.getPollFromString(pollResponse);
2793- if (poll != null) {
2794- if (currentPage == PAGE_DISPLAY) {
2795- setDisplayFromPoll(poll);
2796- }
2797- else {
2798- setServiceOrLiveFromPoll(poll);
2799- }
2800- }
2801- else {
2802- Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");
2803- }
2804- }
2805- catch (JSONHandler.JSONHandlerException e) {
2806- Log.e(LOG_TAG, e.toString());
2807- Toast.makeText(context, String.format("%s: %s",
2808- context.getString(R.string.couldNotHandlePollResponse),
2809- e.getMessage()), Toast.LENGTH_LONG).show();
2810- }
2811- }
2812-
2813- private void setDisplayFromPoll(Poll poll) {
2814- final ToggleButton toggleButton = (ToggleButton)
2815- context.findViewById(R.id.toggleDisplayButton);
2816- if (poll == null) {
2817- toggleButton.setEnabled(false);
2818- }
2819- else {
2820- String onText;
2821- String offText;
2822-
2823- displayType = getDisplayType();
2824- Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType
2825- + " " + poll.isDisplayHidden());
2826- if (displayType.equals(context.getString(R.string.displayScreen))) {
2827- Log.v(LOG_TAG, "Blank called");
2828- onText = context.getString(R.string.displayScreen);
2829- offText = context.getString(R.string.displayScreen);
2830- }
2831- else if (displayType
2832- .equals(context.getString(R.string.displayTheme))) {
2833- Log.v(LOG_TAG, "Theme called");
2834- onText = context.getString(R.string.displayTheme);
2835- offText = context.getString(R.string.displayTheme);
2836- }
2837- else {
2838- Log.v(LOG_TAG, "Desktop called");
2839- onText = context.getString(R.string.displayDesktop);
2840- offText = context.getString(R.string.displayDesktop);
2841- }
2842- /*
2843+ private static Activity context;
2844+ private ListView listViewService;
2845+ private ListView listViewLive;
2846+ private int currentService = -1;
2847+ private int currentLive = -1;
2848+ private String itemId = "";
2849+
2850+ private static int currentPage = 0;
2851+
2852+ public static final String PAGE_KEY = "openlp.pageKey";
2853+ public static final int PAGE_SERVICE = 0;
2854+ public static final int PAGE_LIVE = 1;
2855+ public static final int PAGE_DISPLAY = 2;
2856+ public static final int PAGE_STAGE = 3;
2857+ public static final int PAGE_ALERT = 4;
2858+ public static final int PAGE_SEARCH = 5;
2859+
2860+ private String displayType;
2861+ private WebView webView;
2862+ private SharedPreferences preferences;
2863+
2864+ public Intent pingIntent;
2865+ public Intent apiCallIntent;
2866+
2867+ public OpenLPController(Activity context) {
2868+ OpenLPController.context = context;
2869+ preferences = context.getApplicationContext().getSharedPreferences(
2870+ context.getString(R.string.keySharedPreferences),
2871+ Context.MODE_PRIVATE);
2872+ pingIntent = new Intent(context, PingIntent.class);
2873+ apiCallIntent = new Intent(context, ApiCallIntent.class);
2874+
2875+ IntentFilter apiCallFilter =
2876+ new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);
2877+ apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
2878+ context.registerReceiver(apiCallReceiver, apiCallFilter);
2879+ }
2880+
2881+ public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
2882+ @Override
2883+ public void onReceive(Context broadcastedContext, Intent intent) {
2884+ Log.v(LOG_TAG, String
2885+ .format("%s broadcast received: intent(%s), context(%s)",
2886+ ApiCallIntent.API_CALL_RECEIVE, intent,
2887+ broadcastedContext));
2888+ if (intent.hasExtra("error")) {
2889+ context.stopService(pingIntent);
2890+ Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +
2891+ intent.getStringExtra("error"));
2892+ Toast.makeText(broadcastedContext, String
2893+ .format("%s: %s", context.getString(R.string.requestFailed),
2894+ intent.getStringExtra("error")), Toast.LENGTH_LONG)
2895+ .show();
2896+ } else {
2897+ if (intent.hasExtra("apiBase")) {
2898+ String apiBase = intent.getStringExtra("apiBase");
2899+ if (apiBase.equals(Api.ALERT)) {
2900+ Toast.makeText(broadcastedContext, "Alert sent!",
2901+ Toast.LENGTH_SHORT).show();
2902+ }
2903+ if (apiBase.equals(Api.DISPLAY_BASE)) {
2904+ controller.poll();
2905+ }
2906+ if (apiBase.equals(Api.POLL_STATUS)) {
2907+ handlePollResponse(intent.getStringExtra("pollJson"));
2908+ }
2909+ if (apiBase.equals(Api.LIVE_TEXT)) {
2910+ handleLiveItemsResponse(
2911+ intent.getStringExtra("itemsJson"));
2912+ }
2913+ if (apiBase.equals(Api.SERVICE_LIST)) {
2914+ handleServiceItemsResponse(
2915+ intent.getStringExtra("itemsJson"));
2916+ }
2917+ }
2918+ }
2919+ }
2920+ };
2921+
2922+ private void handlePollResponse(final String pollResponse) {
2923+ try {
2924+
2925+ Poll poll = JSONHandler.getPollFromString(pollResponse);
2926+ if (poll != null) {
2927+ if (currentPage == PAGE_DISPLAY) {
2928+ setDisplayFromPoll(poll);
2929+ } else {
2930+ setServiceOrLiveFromPoll(poll);
2931+ }
2932+ } else {
2933+ Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");
2934+ }
2935+ } catch (JSONHandler.JSONHandlerException e) {
2936+ Log.e(LOG_TAG, e.toString());
2937+ Toast.makeText(context, String.format("%s: %s",
2938+ context.getString(R.string.couldNotHandlePollResponse),
2939+ e.getMessage()), Toast.LENGTH_LONG).show();
2940+ }
2941+ }
2942+
2943+ private void setDisplayFromPoll(Poll poll) {
2944+ final ToggleButton toggleButton = (ToggleButton)
2945+ context.findViewById(R.id.toggleDisplayButton);
2946+ if (poll == null) {
2947+ toggleButton.setEnabled(false);
2948+ } else {
2949+ String onText;
2950+ String offText;
2951+
2952+ displayType = getDisplayType();
2953+ Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType
2954+ + " " + poll.isDisplayHidden());
2955+ if (displayType.equals(context.getString(R.string.displayScreen))) {
2956+ Log.v(LOG_TAG, "Blank called");
2957+ onText = context.getString(R.string.displayScreen);
2958+ offText = context.getString(R.string.displayScreen);
2959+ } else if (displayType
2960+ .equals(context.getString(R.string.displayTheme))) {
2961+ Log.v(LOG_TAG, "Theme called");
2962+ onText = context.getString(R.string.displayTheme);
2963+ offText = context.getString(R.string.displayTheme);
2964+ } else {
2965+ Log.v(LOG_TAG, "Desktop called");
2966+ onText = context.getString(R.string.displayDesktop);
2967+ offText = context.getString(R.string.displayDesktop);
2968+ }
2969+ /*
2970 Set display blanked to the off value to that of the screen
2971 */
2972- if (poll.isDisplayHidden()) {
2973- if (poll.isBlankedDisplayed()) {
2974- Log.v(LOG_TAG, "Hidden Blank called");
2975- onText = context.getString(R.string.displayScreen);
2976- }
2977- else if (poll.isThemeDisplayed()) {
2978- Log.v(LOG_TAG, "Hidden Theme called");
2979- onText = context.getString(R.string.displayTheme);
2980- }
2981- else {
2982- Log.v(LOG_TAG, "Hidden Desktop called");
2983- onText = context.getString(R.string.displayDesktop);
2984- }
2985- }
2986- toggleButton.setTextOn(
2987- context.getString(R.string.displayBlankOn) + " " + onText);
2988- toggleButton.setTextOff(
2989- context.getString(R.string.displayBlankOff) + " " + offText);
2990- toggleButton.setEnabled(true);
2991- toggleButton.setChecked(false);
2992- if (poll.isDisplayHidden()) {
2993- toggleButton.setChecked(true);
2994- }
2995- }
2996- }
2997-
2998- private void setServiceOrLiveFromPoll(Poll poll) {
2999- if (currentPage == PAGE_LIVE) {
3000- if (!itemId.equals(poll.getItem()) ||
3001- currentLive != poll.getSlide()) {
3002- Log.v(LOG_TAG, "Slide Changed. Polling update...");
3003- currentLive = poll.getSlide();
3004- itemId = poll.getItem();
3005- controller.fetchItems(Api.LIVE_TEXT);
3006- }
3007- }
3008- else if (currentPage == PAGE_SERVICE) {
3009- if (currentService < poll.getService()) {
3010- Log.v(LOG_TAG, "Service Changed. Polling update...");
3011- currentService = poll.getService();
3012- controller.fetchItems(Api.SERVICE_LIST);
3013- }
3014- }
3015- }
3016-
3017- private void handleLiveItemsResponse(final String itemsJson) {
3018- try {
3019- List<SlideItem> liveItems =
3020- JSONHandler.getSlideItemsFromString(itemsJson);
3021- listViewLive
3022- .setAdapter(new SlideAdapter(context, liveItems, currentLive));
3023+ if (poll.isDisplayHidden()) {
3024+ if (poll.isBlankedDisplayed()) {
3025+ Log.v(LOG_TAG, "Hidden Blank called");
3026+ onText = context.getString(R.string.displayScreen);
3027+ } else if (poll.isThemeDisplayed()) {
3028+ Log.v(LOG_TAG, "Hidden Theme called");
3029+ onText = context.getString(R.string.displayTheme);
3030+ } else {
3031+ Log.v(LOG_TAG, "Hidden Desktop called");
3032+ onText = context.getString(R.string.displayDesktop);
3033+ }
3034+ }
3035+ toggleButton.setTextOn(
3036+ context.getString(R.string.displayBlankOn) + " " + onText);
3037+ toggleButton.setTextOff(
3038+ context.getString(R.string.displayBlankOff) + " " + offText);
3039+ toggleButton.setEnabled(true);
3040+ toggleButton.setChecked(false);
3041+ if (poll.isDisplayHidden()) {
3042+ toggleButton.setChecked(true);
3043+ }
3044+ }
3045+ }
3046+
3047+ private void setServiceOrLiveFromPoll(Poll poll) {
3048+ if (currentPage == PAGE_LIVE) {
3049+ if (!itemId.equals(poll.getItem()) ||
3050+ currentLive != poll.getSlide()) {
3051+ Log.v(LOG_TAG, "Slide Changed. Polling update...");
3052+ currentLive = poll.getSlide();
3053+ itemId = poll.getItem();
3054+ controller.fetchItems(Api.LIVE_TEXT);
3055+ }
3056+ } else if (currentPage == PAGE_SERVICE) {
3057+ if (currentService < poll.getService()) {
3058+ Log.v(LOG_TAG, "Service Changed. Polling update...");
3059+ currentService = poll.getService();
3060+ controller.fetchItems(Api.SERVICE_LIST);
3061+ }
3062+ }
3063+ }
3064+
3065+ private void handleLiveItemsResponse(final String itemsJson) {
3066+ try {
3067+ List<SlideItem> liveItems =
3068+ JSONHandler.getSlideItemsFromString(itemsJson);
3069+ listViewLive
3070+ .setAdapter(new SlideAdapter(context, liveItems, currentLive));
3071 listViewLive.setSelection(currentLive);
3072- }
3073- catch (JSONHandler.JSONHandlerException e) {
3074- Log.e(LOG_TAG, e.toString());
3075- Toast.makeText(context, String.format("%s: %s",
3076- context.getString(R.string.couldNotHandleLiveItems),
3077- e.getMessage()), Toast.LENGTH_LONG).show();
3078- }
3079- }
3080-
3081- private void handleServiceItemsResponse(final String itemsJson) {
3082- try {
3083- List<SlideItem> serviceItems =
3084- JSONHandler.getServiceItemsFromString(itemsJson);
3085- listViewService.setAdapter(
3086- new SlideAdapter(context, serviceItems, currentService));
3087- }
3088- catch (JSONHandler.JSONHandlerException e) {
3089- Log.e(LOG_TAG, e.toString());
3090- Toast.makeText(context, String.format("%s: %s",
3091- context.getString(R.string.couldNotHandleServiceItems),
3092- e.getMessage()), Toast.LENGTH_LONG).show();
3093- }
3094- }
3095-
3096- private OpenLPNavigate controller = new OpenLPNavigate() {
3097- @Override
3098- public void navigate(final String navigationRequest) {
3099- Intent navigationIntent = new Intent(context, ApiCallIntent.class);
3100- if (currentPage == PAGE_SERVICE) {
3101- navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);
3102- }
3103- if (currentPage == PAGE_LIVE) {
3104- navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);
3105- }
3106- context.startService(navigationIntent);
3107- }
3108-
3109- @Override
3110- public void setData(String apiPart, int id) {
3111- Intent setDataIntent = new Intent(context, ApiCallIntent.class);
3112- setDataIntent.putExtra(apiPart, id);
3113- context.startService(setDataIntent);
3114- }
3115-
3116- @Override
3117- public void setDisplay(String displayRequest) {
3118- Log.d(LOG_TAG, String
3119- .format("Setting Display: displayRequest(%s)", displayRequest));
3120- Intent displayIntent = new Intent(context, ApiCallIntent.class);
3121- displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);
3122- context.startService(displayIntent);
3123- }
3124-
3125- @Override
3126- public void poll() {
3127- Intent pollIntent = new Intent(context, ApiCallIntent.class);
3128- pollIntent.putExtra(Api.POLL_STATUS, "");
3129- context.startService(pollIntent);
3130- }
3131-
3132- @Override
3133- public void fetchItems(String apiPart) {
3134- Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);
3135- fetchItemsIntent.putExtra(apiPart, "");
3136- context.startService(fetchItemsIntent);
3137- }
3138- };
3139-
3140- @Override
3141- public Object instantiateItem(final ViewGroup container, int position) {
3142- LayoutInflater inflater = (LayoutInflater) container.getContext()
3143- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
3144- int res = 0;
3145- try {
3146- res = getLayoutForPosition(position);
3147- }
3148- catch (NoLayoutForPositionException e) {
3149- Log.e(LOG_TAG, e.getMessage());
3150- }
3151-
3152- View view = inflater.inflate(res, null);
3153-
3154- if (position == PAGE_SERVICE || position == PAGE_LIVE) {
3155- if (position == PAGE_SERVICE) {
3156- listViewService = (ListView) view.findViewById(R.id.list);
3157- listViewService
3158- .setOnItemClickListener(onItemClickListenerService);
3159- listViewService.setOnItemLongClickListener(
3160- adapterViewOnItemLongClickListener);
3161- }
3162-
3163- if (position == PAGE_LIVE) {
3164- listViewLive = (ListView) view.findViewById(R.id.list);
3165- listViewLive.setOnItemClickListener(onItemClickListenerSetLive);
3166- }
3167-
3168- view.findViewById(R.id.prev)
3169- .setOnClickListener(onClickListenerNavigate);
3170- view.findViewById(R.id.next)
3171- .setOnClickListener(onClickListenerNavigate);
3172- }
3173-
3174- if (position == PAGE_STAGE) {
3175- webView = getWebViewFromView(view);
3176- }
3177- if (position == PAGE_ALERT) {
3178- view.findViewById(R.id.send).setOnClickListener(mSend);
3179- }
3180- if (position == PAGE_DISPLAY) {
3181- view.findViewById(R.id.toggleDisplayButton)
3182- .setOnClickListener(onClickListenerToggleDisplay);
3183- }
3184-
3185- container.addView(view, 0);
3186- return view;
3187- }
3188-
3189- private WebView getWebViewFromView(View view) {
3190- WebView myWebView = (WebView) view.findViewById(R.id.stageview);
3191+ } catch (JSONHandler.JSONHandlerException e) {
3192+ Log.e(LOG_TAG, e.toString());
3193+ Toast.makeText(context, String.format("%s: %s",
3194+ context.getString(R.string.couldNotHandleLiveItems),
3195+ e.getMessage()), Toast.LENGTH_LONG).show();
3196+ }
3197+ }
3198+
3199+ private void handleServiceItemsResponse(final String itemsJson) {
3200+ try {
3201+ List<SlideItem> serviceItems =
3202+ JSONHandler.getServiceItemsFromString(itemsJson);
3203+ listViewService.setAdapter(
3204+ new SlideAdapter(context, serviceItems, currentService));
3205+ } catch (JSONHandler.JSONHandlerException e) {
3206+ Log.e(LOG_TAG, e.toString());
3207+ Toast.makeText(context, String.format("%s: %s",
3208+ context.getString(R.string.couldNotHandleServiceItems),
3209+ e.getMessage()), Toast.LENGTH_LONG).show();
3210+ }
3211+ }
3212+
3213+ private OpenLPNavigate controller = new OpenLPNavigate() {
3214+ @Override
3215+ public void navigate(final String navigationRequest) {
3216+ Intent navigationIntent = new Intent(context, ApiCallIntent.class);
3217+ if (currentPage == PAGE_SERVICE) {
3218+ navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);
3219+ }
3220+ if (currentPage == PAGE_LIVE) {
3221+ navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);
3222+ }
3223+ context.startService(navigationIntent);
3224+ }
3225+
3226+ @Override
3227+ public void setData(String apiPart, int id) {
3228+ Intent setDataIntent = new Intent(context, ApiCallIntent.class);
3229+ setDataIntent.putExtra(apiPart, id);
3230+ context.startService(setDataIntent);
3231+ }
3232+
3233+ @Override
3234+ public void setDisplay(String displayRequest) {
3235+ Log.d(LOG_TAG, String
3236+ .format("Setting Display: displayRequest(%s)", displayRequest));
3237+ Intent displayIntent = new Intent(context, ApiCallIntent.class);
3238+ displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);
3239+ context.startService(displayIntent);
3240+ }
3241+
3242+ @Override
3243+ public void poll() {
3244+ Intent pollIntent = new Intent(context, ApiCallIntent.class);
3245+ pollIntent.putExtra(Api.POLL_STATUS, "");
3246+ context.startService(pollIntent);
3247+ }
3248+
3249+ @Override
3250+ public void fetchItems(String apiPart) {
3251+ Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);
3252+ fetchItemsIntent.putExtra(apiPart, "");
3253+ context.startService(fetchItemsIntent);
3254+ }
3255+ };
3256+
3257+ @Override
3258+ public Object instantiateItem(final ViewGroup container, int position) {
3259+ LayoutInflater inflater = (LayoutInflater) container.getContext()
3260+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
3261+ int res = 0;
3262+ try {
3263+ res = getLayoutForPosition(position);
3264+ } catch (NoLayoutForPositionException e) {
3265+ Log.e(LOG_TAG, e.getMessage());
3266+ }
3267+
3268+ View view = inflater.inflate(res, null);
3269+
3270+ if (position == PAGE_SERVICE || position == PAGE_LIVE) {
3271+ if (position == PAGE_SERVICE) {
3272+ listViewService = (ListView) view.findViewById(R.id.list);
3273+ listViewService
3274+ .setOnItemClickListener(onItemClickListenerService);
3275+ listViewService.setOnItemLongClickListener(
3276+ adapterViewOnItemLongClickListener);
3277+ }
3278+
3279+ if (position == PAGE_LIVE) {
3280+ listViewLive = (ListView) view.findViewById(R.id.list);
3281+ listViewLive.setOnItemClickListener(onItemClickListenerSetLive);
3282+ }
3283+
3284+ view.findViewById(R.id.prev)
3285+ .setOnClickListener(onClickListenerNavigate);
3286+ view.findViewById(R.id.next)
3287+ .setOnClickListener(onClickListenerNavigate);
3288+ }
3289+
3290+ if (position == PAGE_STAGE) {
3291+ webView = getWebViewFromView(view);
3292+ }
3293+ if (position == PAGE_ALERT) {
3294+ view.findViewById(R.id.send).setOnClickListener(mSend);
3295+ }
3296+ if (position == PAGE_DISPLAY) {
3297+ view.findViewById(R.id.toggleDisplayButton)
3298+ .setOnClickListener(onClickListenerToggleDisplay);
3299+ }
3300+
3301+ container.addView(view, 0);
3302+ return view;
3303+ }
3304+
3305+ private WebView getWebViewFromView(View view) {
3306+ WebView myWebView = (WebView) view.findViewById(R.id.stageview);
3307 /*
3308 * Handle SSL self signed certificates and refresh the screen if the certificate
3309 * page appears.
3310 */
3311 myWebView.setWebViewClient(new WebViewClient() {
3312- public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
3313- handler.proceed() ;
3314- }
3315- } );
3316- WebSettings webSettings = myWebView.getSettings();
3317- webSettings.setJavaScriptEnabled(true);
3318- webSettings.setBuiltInZoomControls(true);
3319- webSettings.setLoadWithOverviewMode(true);
3320- webSettings.setUseWideViewPort(true);
3321- myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
3322- myWebView.setScrollbarFadingEnabled(true);
3323-
3324- myWebView.loadUrl(getUrlBase());
3325- return myWebView;
3326- }
3327-
3328- public static int getPageForButton(View view) {
3329- final int buttonId = view.getId();
3330- if (buttonId == R.id.buttonAlert) {
3331- return PAGE_ALERT;
3332- }
3333- if (buttonId == R.id.buttonDisplay) {
3334- return PAGE_DISPLAY;
3335- }
3336- if (buttonId == R.id.buttonLive) {
3337- return PAGE_LIVE;
3338- }
3339- if (buttonId == R.id.buttonSearch) {
3340- return PAGE_SEARCH;
3341- }
3342- if (buttonId == R.id.buttonService) {
3343- return PAGE_SERVICE;
3344- }
3345- if (buttonId == R.id.buttonStage) {
3346- return PAGE_STAGE;
3347- }
3348-
3349- Log.e(OpenLPController.class.getName(),
3350- "No Button connected to the requested view, with id: " + buttonId);
3351- return 0;
3352- }
3353-
3354- public ViewPager.OnPageChangeListener onPageChangeListener =
3355- new ViewPager.OnPageChangeListener() {
3356- @Override
3357- public void onPageScrolled(int i, float v, int i1) {
3358- }
3359-
3360- @Override
3361- public void onPageSelected(int selectedPage) {
3362- Log.d(LOG_TAG, String
3363- .format("Selected Page: position(%s) title(%s)",
3364- selectedPage, getPageTitle(selectedPage)));
3365- currentPage = selectedPage;
3366-
3367- if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {
3368- context.startService(pingIntent);
3369- if (currentPage == PAGE_SERVICE) {
3370- controller.fetchItems(Api.SERVICE_LIST);
3371- }
3372- if (currentPage == PAGE_LIVE) {
3373- controller.fetchItems(Api.LIVE_TEXT);
3374- }
3375- }
3376- else {
3377- context.stopService(pingIntent);
3378- }
3379-
3380- if (currentPage == PAGE_STAGE) {
3381- if (webView == null) {
3382- webView = getWebViewFromView(context.getLayoutInflater()
3383- .inflate(R.layout.stageview, null));
3384- }
3385- }
3386-
3387- if (currentPage == PAGE_DISPLAY) {
3388- controller.poll();
3389- }
3390- }
3391-
3392- @Override
3393- public void onPageScrollStateChanged(int i) {
3394- }
3395- };
3396-
3397-
3398- @Override
3399- public CharSequence getPageTitle(int position) {
3400- String page = "none";
3401- switch (position) {
3402- case PAGE_SERVICE:
3403- page = context.getString(R.string.tabService);
3404- break;
3405- case PAGE_LIVE:
3406- page = context.getString(R.string.tabLive);
3407- break;
3408- case PAGE_DISPLAY:
3409- page = context.getString(R.string.tabDisplay);
3410- break;
3411- case PAGE_STAGE:
3412- page = context.getString(R.string.tabStage);
3413- break;
3414- case PAGE_ALERT:
3415- page = context.getString(R.string.tabAlert);
3416- break;
3417- case PAGE_SEARCH:
3418- page = context.getString(R.string.buttonSearchText);
3419- break;
3420- }
3421- return page;
3422- }
3423-
3424- private int getLayoutForPosition(int position)
3425- throws NoLayoutForPositionException {
3426- switch (position) {
3427- case PAGE_SERVICE:
3428- return R.layout.slide_service;
3429- case PAGE_LIVE:
3430- return R.layout.slide_service;
3431- case PAGE_DISPLAY:
3432- return R.layout.misc;
3433- case PAGE_STAGE:
3434- return R.layout.stageview;
3435- case PAGE_ALERT:
3436- return R.layout.alert;
3437- case PAGE_SEARCH:
3438- return R.layout.search;
3439- default:
3440- throw new NoLayoutForPositionException(
3441- "No Layout for position (" + position + ")");
3442- }
3443- }
3444-
3445- private AdapterView.OnItemClickListener onItemClickListenerSetLive =
3446- new AdapterView.OnItemClickListener() {
3447- @Override
3448- public void onItemClick(AdapterView<?> adapterView, View view,
3449- int i, long l) {
3450- controller.setData(Api.LIVE_SET, i);
3451- }
3452- };
3453-
3454- private AdapterView.OnItemLongClickListener
3455- adapterViewOnItemLongClickListener =
3456- new AdapterView.OnItemLongClickListener() {
3457- @Override
3458- public boolean onItemLongClick(AdapterView<?> adapterView,
3459- View view, int i, long l) {
3460- controller.setData(Api.SERVICE_SET, i);
3461- ((PagerActivity) context).setCurrentPage(PAGE_LIVE);
3462- return true;
3463- }
3464- };
3465-
3466- private ListView.OnItemClickListener onItemClickListenerService =
3467- new AdapterView.OnItemClickListener() {
3468- @Override
3469- public void onItemClick(AdapterView<?> adapterView, View view,
3470- int i, long l) {
3471- controller.setData(Api.SERVICE_SET, i);
3472- }
3473- };
3474-
3475- private Button.OnClickListener onClickListenerNavigate =
3476- new Button.OnClickListener() {
3477- @Override
3478- public void onClick(View v) {
3479- if (v.getId() == R.id.prev) {
3480- controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);
3481- }
3482- else if (v.getId() == R.id.next) {
3483- controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);
3484- }
3485- }
3486- };
3487-
3488- /**
3489- * Alert Button Listener
3490- */
3491- private Button.OnClickListener mSend = new Button.OnClickListener() {
3492- @Override
3493- public void onClick(View v) {
3494- EditText edittext = (EditText) context.findViewById(R.id.alert);
3495-
3496- if (edittext.getText().toString().trim().length() > 0) {
3497- apiCallIntent
3498- .putExtra(Api.ALERT, edittext.getText().toString());
3499- context.startService(apiCallIntent);
3500- }
3501- else {
3502- Toast.makeText(context,
3503- context.getString(R.string.alertTextNull),
3504- Toast.LENGTH_SHORT).show();
3505- }
3506- }
3507- };
3508-
3509- public View.OnClickListener onClickListenerToggleDisplay =
3510- new View.OnClickListener() {
3511- @Override
3512- public void onClick(View view) {
3513- ToggleButton toggleButton = (ToggleButton) view;
3514-
3515- String displayType = getDisplayType();
3516- if (!toggleButton.isChecked()) {
3517- controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);
3518- }
3519- else {
3520- if (displayType
3521- .equals(context.getString(R.string.displayScreen))) {
3522- controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);
3523- }
3524- else if (displayType
3525- .equals(context.getString(R.string.displayTheme))) {
3526- controller.setDisplay(OpenLPNavigate.HIDE_THEME);
3527- }
3528- else {
3529- controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);
3530- }
3531- }
3532- }
3533- };
3534-
3535- @Override
3536- public int getCount() {
3537- return 5;
3538- }
3539-
3540- @Override
3541- public boolean isViewFromObject(View view, Object o) {
3542- return view == o;
3543- }
3544-
3545- @Override
3546- public void destroyItem(ViewGroup container, int position, Object object) {
3547- container.removeView((View) object);
3548- }
3549-
3550- private static final String LOG_TAG = OpenLPController.class.getName();
3551-
3552- private String getDisplayType() {
3553- displayType = preferences
3554- .getString(context.getString(R.string.keyDisplayBlankType),
3555- context.getString(R.string.displayTypeValue));
3556- return displayType;
3557- }
3558-
3559- private String getUrlBase() {
3560- Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
3561-
3562- return String.format("%s://%s:%s/stage",
3563- useSsl ? "https" : "http",
3564- preferences.getString(context.getString(R.string.keyHost),
3565- context.getString(R.string.hostDefaultValue)),
3566- preferences.getString(context.getString(R.string.keyPort),
3567- context.getString(R.string.portDefaultValue)));
3568- }
3569-
3570- class NoLayoutForPositionException extends Exception {
3571- NoLayoutForPositionException(String detailMessage) {
3572- super(detailMessage);
3573- }
3574- }
3575+ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
3576+ handler.proceed();
3577+ }
3578+ });
3579+ WebSettings webSettings = myWebView.getSettings();
3580+ webSettings.setJavaScriptEnabled(true);
3581+ webSettings.setBuiltInZoomControls(true);
3582+ webSettings.setLoadWithOverviewMode(true);
3583+ webSettings.setUseWideViewPort(true);
3584+ myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
3585+ myWebView.setScrollbarFadingEnabled(true);
3586+
3587+ myWebView.loadUrl(getUrlBase());
3588+ return myWebView;
3589+ }
3590+
3591+ public static int getPageForButton(View view) {
3592+ final int buttonId = view.getId();
3593+ if (buttonId == R.id.buttonAlert) {
3594+ return PAGE_ALERT;
3595+ }
3596+ if (buttonId == R.id.buttonDisplay) {
3597+ return PAGE_DISPLAY;
3598+ }
3599+ if (buttonId == R.id.buttonLive) {
3600+ return PAGE_LIVE;
3601+ }
3602+ if (buttonId == R.id.buttonSearch) {
3603+ return PAGE_SEARCH;
3604+ }
3605+ if (buttonId == R.id.buttonService) {
3606+ return PAGE_SERVICE;
3607+ }
3608+ if (buttonId == R.id.buttonStage) {
3609+ return PAGE_STAGE;
3610+ }
3611+
3612+ Log.e(OpenLPController.class.getName(),
3613+ "No Button connected to the requested view, with id: " + buttonId);
3614+ return 0;
3615+ }
3616+
3617+ public ViewPager.OnPageChangeListener onPageChangeListener =
3618+ new ViewPager.OnPageChangeListener() {
3619+ @Override
3620+ public void onPageScrolled(int i, float v, int i1) {
3621+ }
3622+
3623+ @Override
3624+ public void onPageSelected(int selectedPage) {
3625+ Log.d(LOG_TAG, String
3626+ .format("Selected Page: position(%s) title(%s)",
3627+ selectedPage, getPageTitle(selectedPage)));
3628+ currentPage = selectedPage;
3629+
3630+ if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {
3631+ context.startService(pingIntent);
3632+ if (currentPage == PAGE_SERVICE) {
3633+ controller.fetchItems(Api.SERVICE_LIST);
3634+ }
3635+ if (currentPage == PAGE_LIVE) {
3636+ controller.fetchItems(Api.LIVE_TEXT);
3637+ }
3638+ } else {
3639+ context.stopService(pingIntent);
3640+ }
3641+
3642+ if (currentPage == PAGE_STAGE) {
3643+ if (webView == null) {
3644+ webView = getWebViewFromView(context.getLayoutInflater()
3645+ .inflate(R.layout.stageview, null));
3646+ }
3647+ }
3648+
3649+ if (currentPage == PAGE_DISPLAY) {
3650+ controller.poll();
3651+ }
3652+ }
3653+
3654+ @Override
3655+ public void onPageScrollStateChanged(int i) {
3656+ }
3657+ };
3658+
3659+
3660+ @Override
3661+ public CharSequence getPageTitle(int position) {
3662+ String page = "none";
3663+ switch (position) {
3664+ case PAGE_SERVICE:
3665+ page = context.getString(R.string.tabService);
3666+ break;
3667+ case PAGE_LIVE:
3668+ page = context.getString(R.string.tabLive);
3669+ break;
3670+ case PAGE_DISPLAY:
3671+ page = context.getString(R.string.tabDisplay);
3672+ break;
3673+ case PAGE_STAGE:
3674+ page = context.getString(R.string.tabStage);
3675+ break;
3676+ case PAGE_ALERT:
3677+ page = context.getString(R.string.tabAlert);
3678+ break;
3679+ case PAGE_SEARCH:
3680+ page = context.getString(R.string.buttonSearchText);
3681+ break;
3682+ }
3683+ return page;
3684+ }
3685+
3686+ private int getLayoutForPosition(int position)
3687+ throws NoLayoutForPositionException {
3688+ switch (position) {
3689+ case PAGE_SERVICE:
3690+ return R.layout.slide_service;
3691+ case PAGE_LIVE:
3692+ return R.layout.slide_service;
3693+ case PAGE_DISPLAY:
3694+ return R.layout.misc;
3695+ case PAGE_STAGE:
3696+ return R.layout.stageview;
3697+ case PAGE_ALERT:
3698+ return R.layout.alert;
3699+ case PAGE_SEARCH:
3700+ return R.layout.search;
3701+ default:
3702+ throw new NoLayoutForPositionException(
3703+ "No Layout for position (" + position + ")");
3704+ }
3705+ }
3706+
3707+ private AdapterView.OnItemClickListener onItemClickListenerSetLive =
3708+ new AdapterView.OnItemClickListener() {
3709+ @Override
3710+ public void onItemClick(AdapterView<?> adapterView, View view,
3711+ int i, long l) {
3712+ controller.setData(Api.LIVE_SET, i);
3713+ }
3714+ };
3715+
3716+ private AdapterView.OnItemLongClickListener
3717+ adapterViewOnItemLongClickListener =
3718+ new AdapterView.OnItemLongClickListener() {
3719+ @Override
3720+ public boolean onItemLongClick(AdapterView<?> adapterView,
3721+ View view, int i, long l) {
3722+ controller.setData(Api.SERVICE_SET, i);
3723+ ((PagerActivity) context).setCurrentPage(PAGE_LIVE);
3724+ return true;
3725+ }
3726+ };
3727+
3728+ private ListView.OnItemClickListener onItemClickListenerService =
3729+ new AdapterView.OnItemClickListener() {
3730+ @Override
3731+ public void onItemClick(AdapterView<?> adapterView, View view,
3732+ int i, long l) {
3733+ controller.setData(Api.SERVICE_SET, i);
3734+ }
3735+ };
3736+
3737+ private Button.OnClickListener onClickListenerNavigate =
3738+ new Button.OnClickListener() {
3739+ @Override
3740+ public void onClick(View v) {
3741+ if (v.getId() == R.id.prev) {
3742+ controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);
3743+ } else if (v.getId() == R.id.next) {
3744+ controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);
3745+ }
3746+ }
3747+ };
3748+
3749+ /**
3750+ * Alert Button Listener
3751+ */
3752+ private Button.OnClickListener mSend = new Button.OnClickListener() {
3753+ @Override
3754+ public void onClick(View v) {
3755+ EditText edittext = (EditText) context.findViewById(R.id.alert);
3756+
3757+ if (edittext.getText().toString().trim().length() > 0) {
3758+ apiCallIntent
3759+ .putExtra(Api.ALERT, edittext.getText().toString());
3760+ context.startService(apiCallIntent);
3761+ } else {
3762+ Toast.makeText(context,
3763+ context.getString(R.string.alertTextNull),
3764+ Toast.LENGTH_SHORT).show();
3765+ }
3766+ }
3767+ };
3768+
3769+ public View.OnClickListener onClickListenerToggleDisplay =
3770+ new View.OnClickListener() {
3771+ @Override
3772+ public void onClick(View view) {
3773+ ToggleButton toggleButton = (ToggleButton) view;
3774+
3775+ String displayType = getDisplayType();
3776+ if (!toggleButton.isChecked()) {
3777+ controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);
3778+ } else {
3779+ if (displayType
3780+ .equals(context.getString(R.string.displayScreen))) {
3781+ controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);
3782+ } else if (displayType
3783+ .equals(context.getString(R.string.displayTheme))) {
3784+ controller.setDisplay(OpenLPNavigate.HIDE_THEME);
3785+ } else {
3786+ controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);
3787+ }
3788+ }
3789+ }
3790+ };
3791+
3792+ @Override
3793+ public int getCount() {
3794+ return 5;
3795+ }
3796+
3797+ @Override
3798+ public boolean isViewFromObject(View view, Object o) {
3799+ return view == o;
3800+ }
3801+
3802+ @Override
3803+ public void destroyItem(ViewGroup container, int position, Object object) {
3804+ container.removeView((View) object);
3805+ }
3806+
3807+ private static final String LOG_TAG = OpenLPController.class.getName();
3808+
3809+ private String getDisplayType() {
3810+ displayType = preferences
3811+ .getString(context.getString(R.string.keyDisplayBlankType),
3812+ context.getString(R.string.displayTypeValue));
3813+ return displayType;
3814+ }
3815+
3816+ private String getUrlBase() {
3817+ Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
3818+
3819+ return String.format("%s://%s:%s/stage",
3820+ useSsl ? "https" : "http",
3821+ preferences.getString(context.getString(R.string.keyHost),
3822+ context.getString(R.string.hostDefaultValue)),
3823+ preferences.getString(context.getString(R.string.keyPort),
3824+ context.getString(R.string.portDefaultValue)));
3825+ }
3826+
3827+ class NoLayoutForPositionException extends Exception {
3828+ NoLayoutForPositionException(String detailMessage) {
3829+ super(detailMessage);
3830+ }
3831+ }
3832 }
3833
3834=== modified file 'src/org/openlp/android/utility/OpenLPHttpClient.java'
3835--- src/org/openlp/android/utility/OpenLPHttpClient.java 2013-04-07 12:24:38 +0000
3836+++ src/org/openlp/android/utility/OpenLPHttpClient.java 2013-06-04 19:32:29 +0000
3837@@ -68,49 +68,49 @@
3838 */
3839 public class OpenLPHttpClient extends DefaultHttpClient {
3840
3841- private HttpGet httpGet;
3842- private URL url;
3843- private final String urlBase;
3844- private SSLSocketFactory sslSocketFactory;
3845+ private HttpGet httpGet;
3846+ private URL url;
3847+ private final String urlBase;
3848+ private SSLSocketFactory sslSocketFactory;
3849 private Context context;
3850
3851- public OpenLPHttpClient(Context context) {
3852- SharedPreferences preferences = context.getSharedPreferences(
3853- context.getString(R.string.keySharedPreferences),
3854- Context.MODE_PRIVATE);
3855- HttpParams httpParams = new BasicHttpParams();
3856+ public OpenLPHttpClient(Context context) {
3857+ SharedPreferences preferences = context.getSharedPreferences(
3858+ context.getString(R.string.keySharedPreferences),
3859+ Context.MODE_PRIVATE);
3860+ HttpParams httpParams = new BasicHttpParams();
3861
3862 this.context = context;
3863
3864- Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
3865-
3866- String port = preferences.getString(
3867- context.getString(R.string.keyPort),
3868- context.getString(R.string.portDefaultValue)
3869- );
3870-
3871- SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
3872- if (!useSsl) {
3873- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
3874- } else {
3875- try {
3876- initSsl();
3877- schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
3878- } catch (NoSuchAlgorithmException e) {
3879- Log.e(LOG_TAG, e.toString());
3880- } catch (KeyManagementException e) {
3881- Log.e(LOG_TAG, e.toString());
3882- } catch (KeyStoreException e) {
3883- Log.e(LOG_TAG, e.toString());
3884- } catch (UnrecoverableKeyException e) {
3885- Log.e(LOG_TAG, e.toString());
3886- } catch (CertificateException e) {
3887- e.printStackTrace();
3888- } catch (IOException e) {
3889- e.printStackTrace();
3890- }
3891-
3892- }
3893+ Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
3894+
3895+ String port = preferences.getString(
3896+ context.getString(R.string.keyPort),
3897+ context.getString(R.string.portDefaultValue)
3898+ );
3899+
3900+ SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
3901+ if (!useSsl) {
3902+ schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
3903+ } else {
3904+ try {
3905+ initSsl();
3906+ schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
3907+ } catch (NoSuchAlgorithmException e) {
3908+ Log.e(LOG_TAG, e.toString());
3909+ } catch (KeyManagementException e) {
3910+ Log.e(LOG_TAG, e.toString());
3911+ } catch (KeyStoreException e) {
3912+ Log.e(LOG_TAG, e.toString());
3913+ } catch (UnrecoverableKeyException e) {
3914+ Log.e(LOG_TAG, e.toString());
3915+ } catch (CertificateException e) {
3916+ e.printStackTrace();
3917+ } catch (IOException e) {
3918+ e.printStackTrace();
3919+ }
3920+
3921+ }
3922
3923 String userid = preferences.getString(
3924 context.getString(R.string.key_userid),
3925@@ -123,131 +123,131 @@
3926 context.getString(R.string.passwordDefaultValue)
3927 );
3928
3929- Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
3930+ Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
3931
3932 Credentials creds = new UsernamePasswordCredentials(userid, password);
3933 getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);
3934
3935 urlBase = String.format("http%s://%s:%s",
3936- useSsl ? "s" : "",
3937- preferences.getString(
3938- context.getString(R.string.keyHost),
3939- context.getString(R.string.hostDefaultValue)), port);
3940-
3941- int connectionTimeout = context.getResources().getInteger(
3942- R.integer.connectionTimeoutDefaultValue);
3943- int socketTimeout = context.getResources().getInteger(
3944- R.integer.socketTimeoutDefaultValue);
3945-
3946- if (preferences.getBoolean(
3947- context.getString(R.string.keyEnableCustomTimeout), false)) {
3948- Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",
3949- context.getString(R.string.keyConnectionTimeout),
3950- context.getString(R.string.keySocketTimeout)));
3951- connectionTimeout = Integer.parseInt(preferences.getString(
3952- context.getString(R.string.keyConnectionTimeout),
3953- String.valueOf(context.getResources().getInteger(
3954- R.integer.connectionTimeoutDefaultValue))));
3955- socketTimeout = Integer.parseInt(preferences.getString(
3956- context.getString(R.string.keySocketTimeout),
3957- String.valueOf(context.getResources().getInteger(
3958- R.integer.socketTimeoutDefaultValue))));
3959- }
3960- HttpConnectionParams
3961- .setConnectionTimeout(httpParams, connectionTimeout);
3962- HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
3963- setParams(httpParams);
3964- httpGet = new HttpGet();
3965- }
3966-
3967- public URL getUrl() {
3968- return url;
3969- }
3970-
3971- public void setUrl(String apiPart) throws URISyntaxException,
3972- MalformedURLException {
3973- url = new URL(urlBase.concat(apiPart));
3974- try {
3975- Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));
3976- } catch (UnsupportedEncodingException e) {
3977- Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());
3978- }
3979- httpGet.setURI(getUrl().toURI());
3980- }
3981-
3982- public HttpResponse execute() throws IOException {
3983- return super.execute(httpGet);
3984- }
3985-
3986- public HttpReturn handleExecute() throws IOException {
3987- HttpResponse response = this.execute();
3988+ useSsl ? "s" : "",
3989+ preferences.getString(
3990+ context.getString(R.string.keyHost),
3991+ context.getString(R.string.hostDefaultValue)), port);
3992+
3993+ int connectionTimeout = context.getResources().getInteger(
3994+ R.integer.connectionTimeoutDefaultValue);
3995+ int socketTimeout = context.getResources().getInteger(
3996+ R.integer.socketTimeoutDefaultValue);
3997+
3998+ if (preferences.getBoolean(
3999+ context.getString(R.string.keyEnableCustomTimeout), false)) {
4000+ Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",
4001+ context.getString(R.string.keyConnectionTimeout),
4002+ context.getString(R.string.keySocketTimeout)));
4003+ connectionTimeout = Integer.parseInt(preferences.getString(
4004+ context.getString(R.string.keyConnectionTimeout),
4005+ String.valueOf(context.getResources().getInteger(
4006+ R.integer.connectionTimeoutDefaultValue))));
4007+ socketTimeout = Integer.parseInt(preferences.getString(
4008+ context.getString(R.string.keySocketTimeout),
4009+ String.valueOf(context.getResources().getInteger(
4010+ R.integer.socketTimeoutDefaultValue))));
4011+ }
4012+ HttpConnectionParams
4013+ .setConnectionTimeout(httpParams, connectionTimeout);
4014+ HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
4015+ setParams(httpParams);
4016+ httpGet = new HttpGet();
4017+ }
4018+
4019+ public URL getUrl() {
4020+ return url;
4021+ }
4022+
4023+ public void setUrl(String apiPart) throws URISyntaxException,
4024+ MalformedURLException {
4025+ url = new URL(urlBase.concat(apiPart));
4026+ try {
4027+ Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));
4028+ } catch (UnsupportedEncodingException e) {
4029+ Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());
4030+ }
4031+ httpGet.setURI(getUrl().toURI());
4032+ }
4033+
4034+ public HttpResponse execute() throws IOException {
4035+ return super.execute(httpGet);
4036+ }
4037+
4038+ public HttpReturn handleExecute() throws IOException {
4039+ HttpResponse response = this.execute();
4040
4041 Log.d(LOG_TAG, "Http response code " + String.valueOf(response.getStatusLine().getStatusCode()));
4042
4043- if (response.getStatusLine().getStatusCode() == 200) {
4044- BufferedReader bufferedReader;
4045- HttpEntity entity = response.getEntity();
4046-
4047- if (entity != null) {
4048- bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
4049- StringBuilder stringBuilder = new StringBuilder();
4050-
4051- String line = bufferedReader.readLine();
4052- while (line != null) {
4053- stringBuilder.append(line);
4054- line = bufferedReader.readLine();
4055- }
4056- bufferedReader.close();
4057- return new HttpReturn(0, stringBuilder.toString(), this.context);
4058- }
4059- }
4060- return new HttpReturn(response.getStatusLine().getStatusCode() , null, this.context);
4061- }
4062-
4063- public HttpEntity handleAndReturnEntity() throws IOException {
4064- HttpResponse response = this.execute();
4065-
4066- if (response.getStatusLine().getStatusCode() == 200) {
4067- return response.getEntity();
4068- }
4069- return null;
4070- }
4071-
4072- private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
4073+ if (response.getStatusLine().getStatusCode() == 200) {
4074+ BufferedReader bufferedReader;
4075+ HttpEntity entity = response.getEntity();
4076+
4077+ if (entity != null) {
4078+ bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
4079+ StringBuilder stringBuilder = new StringBuilder();
4080+
4081+ String line = bufferedReader.readLine();
4082+ while (line != null) {
4083+ stringBuilder.append(line);
4084+ line = bufferedReader.readLine();
4085+ }
4086+ bufferedReader.close();
4087+ return new HttpReturn(0, stringBuilder.toString(), this.context);
4088+ }
4089+ }
4090+ return new HttpReturn(response.getStatusLine().getStatusCode(), null, this.context);
4091+ }
4092+
4093+ public HttpEntity handleAndReturnEntity() throws IOException {
4094+ HttpResponse response = this.execute();
4095+
4096+ if (response.getStatusLine().getStatusCode() == 200) {
4097+ return response.getEntity();
4098+ }
4099+ return null;
4100+ }
4101+
4102+ private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
4103 UnrecoverableKeyException, IOException, CertificateException {
4104- final SSLContext sslContext = SSLContext.getInstance("TLS");
4105- X509TrustManager trustManager = new X509TrustManager() {
4106- @Override
4107- public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
4108- }
4109-
4110- @Override
4111- public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
4112- }
4113-
4114- @Override
4115- public X509Certificate[] getAcceptedIssuers() {
4116- return null;
4117- }
4118- };
4119- sslContext.init(null, new TrustManager[]{trustManager}, null);
4120-
4121- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
4122- keyStore.load(null, null);
4123- sslSocketFactory = new SSLSocketFactory(keyStore) {
4124- @Override
4125- public Socket createSocket() throws IOException {
4126- return sslContext.getSocketFactory().createSocket();
4127- }
4128-
4129- @Override
4130- public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
4131+ final SSLContext sslContext = SSLContext.getInstance("TLS");
4132+ X509TrustManager trustManager = new X509TrustManager() {
4133+ @Override
4134+ public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
4135+ }
4136+
4137+ @Override
4138+ public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
4139+ }
4140+
4141+ @Override
4142+ public X509Certificate[] getAcceptedIssuers() {
4143+ return null;
4144+ }
4145+ };
4146+ sslContext.init(null, new TrustManager[]{trustManager}, null);
4147+
4148+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
4149+ keyStore.load(null, null);
4150+ sslSocketFactory = new SSLSocketFactory(keyStore) {
4151+ @Override
4152+ public Socket createSocket() throws IOException {
4153+ return sslContext.getSocketFactory().createSocket();
4154+ }
4155+
4156+ @Override
4157+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
4158 UnknownHostException {
4159- return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
4160- }
4161- };
4162- sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
4163- }
4164+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
4165+ }
4166+ };
4167+ sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
4168+ }
4169
4170- private final String LOG_TAG = OpenLPHttpClient.class.getName();
4171+ private final String LOG_TAG = OpenLPHttpClient.class.getName();
4172 }
4173
4174=== modified file 'src/org/openlp/android/utility/SlideAdapter.java'
4175--- src/org/openlp/android/utility/SlideAdapter.java 2013-04-06 13:44:51 +0000
4176+++ src/org/openlp/android/utility/SlideAdapter.java 2013-06-04 19:32:29 +0000
4177@@ -35,99 +35,98 @@
4178 import org.openlp.android.data.SlideItem;
4179
4180 public class SlideAdapter extends BaseAdapter {
4181- List<SlideItem> items;
4182- Activity context;
4183- LayoutInflater inflater;
4184- boolean useTagDisplay = true;
4185- private int[] colors = new int[] { 0x74717000, 0x00000000 };
4186- private int currentSlide = -1;
4187- SharedPreferences prefs;
4188-
4189- public SlideAdapter(Activity context, List<SlideItem> items, int slide) {
4190- this.context = context;
4191- this.items = items;
4192- this.currentSlide = slide;
4193- inflater = context.getLayoutInflater();
4194-
4195- prefs = context.getSharedPreferences(
4196- context.getString(R.string.keySharedPreferences),
4197- Context.MODE_PRIVATE);
4198- }
4199-
4200- public SlideAdapter(Activity context, List<SlideItem> items,
4201- boolean useTagDisplay) {
4202- this.context = context;
4203- this.items = items;
4204- this.useTagDisplay = useTagDisplay;
4205- inflater = context.getLayoutInflater();
4206-
4207- prefs = context.getSharedPreferences(
4208- context.getString(R.string.keySharedPreferences),
4209- Context.MODE_PRIVATE);
4210- }
4211-
4212- @Override
4213- public int getCount() {
4214- return items.size();
4215- }
4216-
4217- @Override
4218- public Object getItem(int i) {
4219- return items.get(i);
4220- }
4221-
4222- @Override
4223- public long getItemId(int i) {
4224- return items.indexOf(items.get(i));
4225- }
4226-
4227- @Override
4228- public View getView(int position, View convertView, ViewGroup parent) {
4229- ViewHolder holder;
4230- View view = convertView;
4231-
4232- SlideItem item = items.get(position);
4233-
4234- if (view == null) {
4235- view = inflater.inflate(R.layout.slide_list_item, null);
4236- holder = new ViewHolder();
4237-
4238- holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
4239- holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
4240-
4241- view.setTag(holder);
4242- }
4243- else {
4244- holder = (ViewHolder) view.getTag();
4245- }
4246-
4247- int size = Integer.parseInt(prefs.getString(
4248- context.getString(R.string.keyTextSize),
4249- String.valueOf(context.getResources().getInteger(
4250- R.integer.textSizeDefaultValue))));
4251-
4252- holder.rowMarker.setText(item.getTag());
4253- holder.rowItem.setText(item.getText());
4254- holder.rowItem.setTextSize(size);
4255-
4256- if (useTagDisplay) {
4257- holder.rowMarker.setMinWidth(40);
4258- }
4259- if (position == this.currentSlide) {
4260- holder.rowItem.setTextColor(Color.WHITE);
4261- view.setBackgroundColor(Color.argb(99, 200, 200, 200));
4262- } else {
4263- holder.rowItem.setTextColor(Color.LTGRAY);
4264- view.setBackgroundColor(colors[position % colors.length]);
4265- }
4266-
4267- return view;
4268- }
4269-
4270- static class ViewHolder {
4271- TextView rowMarker;
4272- TextView rowItem;
4273- }
4274-
4275- private final String LOG_TAG = SlideAdapter.class.getName();
4276+ List<SlideItem> items;
4277+ Activity context;
4278+ LayoutInflater inflater;
4279+ boolean useTagDisplay = true;
4280+ private int[] colors = new int[]{0x74717000, 0x00000000};
4281+ private int currentSlide = -1;
4282+ SharedPreferences prefs;
4283+
4284+ public SlideAdapter(Activity context, List<SlideItem> items, int slide) {
4285+ this.context = context;
4286+ this.items = items;
4287+ this.currentSlide = slide;
4288+ inflater = context.getLayoutInflater();
4289+
4290+ prefs = context.getSharedPreferences(
4291+ context.getString(R.string.keySharedPreferences),
4292+ Context.MODE_PRIVATE);
4293+ }
4294+
4295+ public SlideAdapter(Activity context, List<SlideItem> items,
4296+ boolean useTagDisplay) {
4297+ this.context = context;
4298+ this.items = items;
4299+ this.useTagDisplay = useTagDisplay;
4300+ inflater = context.getLayoutInflater();
4301+
4302+ prefs = context.getSharedPreferences(
4303+ context.getString(R.string.keySharedPreferences),
4304+ Context.MODE_PRIVATE);
4305+ }
4306+
4307+ @Override
4308+ public int getCount() {
4309+ return items.size();
4310+ }
4311+
4312+ @Override
4313+ public Object getItem(int i) {
4314+ return items.get(i);
4315+ }
4316+
4317+ @Override
4318+ public long getItemId(int i) {
4319+ return items.indexOf(items.get(i));
4320+ }
4321+
4322+ @Override
4323+ public View getView(int position, View convertView, ViewGroup parent) {
4324+ ViewHolder holder;
4325+ View view = convertView;
4326+
4327+ SlideItem item = items.get(position);
4328+
4329+ if (view == null) {
4330+ view = inflater.inflate(R.layout.slide_list_item, null);
4331+ holder = new ViewHolder();
4332+
4333+ holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
4334+ holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
4335+
4336+ view.setTag(holder);
4337+ } else {
4338+ holder = (ViewHolder) view.getTag();
4339+ }
4340+
4341+ int size = Integer.parseInt(prefs.getString(
4342+ context.getString(R.string.keyTextSize),
4343+ String.valueOf(context.getResources().getInteger(
4344+ R.integer.textSizeDefaultValue))));
4345+
4346+ holder.rowMarker.setText(item.getTag());
4347+ holder.rowItem.setText(item.getText());
4348+ holder.rowItem.setTextSize(size);
4349+
4350+ if (useTagDisplay) {
4351+ holder.rowMarker.setMinWidth(40);
4352+ }
4353+ if (position == this.currentSlide) {
4354+ holder.rowItem.setTextColor(Color.WHITE);
4355+ view.setBackgroundColor(Color.argb(99, 200, 200, 200));
4356+ } else {
4357+ holder.rowItem.setTextColor(Color.LTGRAY);
4358+ view.setBackgroundColor(colors[position % colors.length]);
4359+ }
4360+
4361+ return view;
4362+ }
4363+
4364+ static class ViewHolder {
4365+ TextView rowMarker;
4366+ TextView rowItem;
4367+ }
4368+
4369+ private final String LOG_TAG = SlideAdapter.class.getName();
4370 }
4371
4372=== modified file 'src/org/openlp/android/utility/StringHelper.java'
4373--- src/org/openlp/android/utility/StringHelper.java 2013-04-06 13:44:51 +0000
4374+++ src/org/openlp/android/utility/StringHelper.java 2013-06-04 19:32:29 +0000
4375@@ -29,35 +29,32 @@
4376 * String helper utility to do common string processing.
4377 */
4378 public class StringHelper {
4379- public synchronized static String convertStreamToString(InputStream is) {
4380- /*
4381+ public synchronized static String convertStreamToString(InputStream is) {
4382+ /*
4383 * To convert the InputStream to String we use the
4384 * BufferedReader.readLine() method. We iterate until the BufferedReader
4385 * return null which means there's no more data to read. Each line will
4386 * appended to a StringBuilder and returned as String.
4387 */
4388
4389- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
4390- StringBuilder sb = new StringBuilder();
4391+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
4392+ StringBuilder sb = new StringBuilder();
4393
4394- String line = null;
4395- try {
4396- while ((line = reader.readLine()) != null) {
4397- sb.append(line + "\n");
4398- }
4399- }
4400- catch (IOException e) {
4401- e.printStackTrace();
4402- }
4403- finally {
4404- try {
4405- is.close();
4406- }
4407- catch (IOException e) {
4408- e.printStackTrace();
4409- }
4410- }
4411- return sb.toString();
4412- }
4413+ String line = null;
4414+ try {
4415+ while ((line = reader.readLine()) != null) {
4416+ sb.append(line + "\n");
4417+ }
4418+ } catch (IOException e) {
4419+ e.printStackTrace();
4420+ } finally {
4421+ try {
4422+ is.close();
4423+ } catch (IOException e) {
4424+ e.printStackTrace();
4425+ }
4426+ }
4427+ return sb.toString();
4428+ }
4429
4430 }
4431
4432=== modified file 'src/org/openlp/android/utility/WebCallReturningAsyncTask.java'
4433--- src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2013-04-06 13:44:51 +0000
4434+++ src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2013-06-04 19:32:29 +0000
4435@@ -34,85 +34,81 @@
4436 import java.io.InputStreamReader;
4437
4438 public class WebCallReturningAsyncTask extends AsyncTask<String, Void, String> {
4439- private Activity context;
4440- private String apiPart;
4441-
4442- public WebCallReturningAsyncTask(Activity context) {
4443- this.context = context;
4444- }
4445-
4446- public WebCallReturningAsyncTask(Activity context, String apiPart) {
4447- this.context = context;
4448- this.apiPart = apiPart;
4449- }
4450-
4451- @Override
4452- protected String doInBackground(String... apiCall) {
4453- OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
4454- HttpResponse response = null;
4455- BufferedReader bufferedReader = null;
4456-
4457- try {
4458- if (apiPart == null) {
4459- httpClient.setUrl(apiCall[0]);
4460- }
4461- else {
4462- httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
4463- }
4464-
4465- if (httpClient.getUrl().getHost().trim().length() <= 0) {
4466- context.startActivity(new Intent(context, Preferences.class));
4467- }
4468- else {
4469- response = httpClient.execute();
4470- }
4471-
4472- if (response != null
4473- && response.getStatusLine().getStatusCode() == 200) {
4474- HttpEntity entity = response.getEntity();
4475-
4476- if (entity != null) {
4477- bufferedReader = new BufferedReader(
4478- new InputStreamReader(entity.getContent()));
4479- StringBuilder stringBuilder = new StringBuilder();
4480-
4481- String line = bufferedReader.readLine();
4482- while (line != null) {
4483- stringBuilder.append(line);
4484- line = bufferedReader.readLine();
4485- }
4486-
4487- Log.i(LOG_TAG, String.format("entity: %s",
4488- stringBuilder.toString()));
4489- bufferedReader.close();
4490- return stringBuilder.toString();
4491- }
4492- }
4493- }
4494- catch (Exception e) {
4495- Log.e(LOG_TAG, e.toString());
4496- Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
4497- if (bufferedReader != null) {
4498- try {
4499- bufferedReader.close();
4500- }
4501- catch (IOException e1) {
4502- // do nothing as we are in an error state anyway
4503- }
4504- }
4505- }
4506- return null;
4507- }
4508-
4509- @Override
4510- protected void onPreExecute() {
4511- super.onPreExecute();
4512- }
4513-
4514- @Override
4515- protected void onPostExecute(String s) {
4516- super.onPostExecute(s);
4517- }
4518-
4519- private final String LOG_TAG = this.getClass().getName();
4520+ private Activity context;
4521+ private String apiPart;
4522+
4523+ public WebCallReturningAsyncTask(Activity context) {
4524+ this.context = context;
4525+ }
4526+
4527+ public WebCallReturningAsyncTask(Activity context, String apiPart) {
4528+ this.context = context;
4529+ this.apiPart = apiPart;
4530+ }
4531+
4532+ @Override
4533+ protected String doInBackground(String... apiCall) {
4534+ OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
4535+ HttpResponse response = null;
4536+ BufferedReader bufferedReader = null;
4537+
4538+ try {
4539+ if (apiPart == null) {
4540+ httpClient.setUrl(apiCall[0]);
4541+ } else {
4542+ httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
4543+ }
4544+
4545+ if (httpClient.getUrl().getHost().trim().length() <= 0) {
4546+ context.startActivity(new Intent(context, Preferences.class));
4547+ } else {
4548+ response = httpClient.execute();
4549+ }
4550+
4551+ if (response != null
4552+ && response.getStatusLine().getStatusCode() == 200) {
4553+ HttpEntity entity = response.getEntity();
4554+
4555+ if (entity != null) {
4556+ bufferedReader = new BufferedReader(
4557+ new InputStreamReader(entity.getContent()));
4558+ StringBuilder stringBuilder = new StringBuilder();
4559+
4560+ String line = bufferedReader.readLine();
4561+ while (line != null) {
4562+ stringBuilder.append(line);
4563+ line = bufferedReader.readLine();
4564+ }
4565+
4566+ Log.i(LOG_TAG, String.format("entity: %s",
4567+ stringBuilder.toString()));
4568+ bufferedReader.close();
4569+ return stringBuilder.toString();
4570+ }
4571+ }
4572+ } catch (Exception e) {
4573+ Log.e(LOG_TAG, e.toString());
4574+ Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
4575+ if (bufferedReader != null) {
4576+ try {
4577+ bufferedReader.close();
4578+ } catch (IOException e1) {
4579+ // do nothing as we are in an error state anyway
4580+ }
4581+ }
4582+ }
4583+ return null;
4584+ }
4585+
4586+ @Override
4587+ protected void onPreExecute() {
4588+ super.onPreExecute();
4589+ }
4590+
4591+ @Override
4592+ protected void onPostExecute(String s) {
4593+ super.onPostExecute(s);
4594+ }
4595+
4596+ private final String LOG_TAG = this.getClass().getName();
4597 }

Subscribers

People subscribed via source and target branches