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
=== modified file 'src/org/openlp/android/OpenLP.java'
--- src/org/openlp/android/OpenLP.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/OpenLP.java 2013-06-04 19:32:29 +0000
@@ -37,65 +37,65 @@
37 */37 */
38public class OpenLP extends DefaultActivity {38public class OpenLP extends DefaultActivity {
3939
40 /**40 /**
41 * Called when the activity is first created.41 * Called when the activity is first created.
42 */42 */
43 @Override43 @Override
44 public void onCreate(Bundle savedInstanceState) {44 public void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);45 super.onCreate(savedInstanceState);
46 setContentView(R.layout.main);46 setContentView(R.layout.main);
4747
48 doPreferenceCheck();48 doPreferenceCheck();
49 setOnClickListenerPagerForButtons();49 setOnClickListenerPagerForButtons();
50 }50 }
5151
52 private View.OnClickListener onClickListenerPager =52 private View.OnClickListener onClickListenerPager =
53 new View.OnClickListener() {53 new View.OnClickListener() {
54 @Override54 @Override
55 public void onClick(View view) {55 public void onClick(View view) {
56 Intent pager = new Intent(OpenLP.this, PagerActivity.class);56 Intent pager = new Intent(OpenLP.this, PagerActivity.class);
57 pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));57 pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));
58 startActivity(pager);58 startActivity(pager);
59 }59 }
60 };60 };
6161
62 private void doPreferenceCheck() {62 private void doPreferenceCheck() {
63 if (getSharedPreferences(getString(R.string.keySharedPreferences),63 if (getSharedPreferences(getString(R.string.keySharedPreferences),
64 Context.MODE_PRIVATE).getString(getString(R.string.keyHost),64 Context.MODE_PRIVATE).getString(getString(R.string.keyHost),
65 "NONE").equals("NONE")65 "NONE").equals("NONE")
66 || getSharedPreferences(66 || getSharedPreferences(
67 getString(R.string.keySharedPreferences),67 getString(R.string.keySharedPreferences),
68 Context.MODE_PRIVATE).getString(68 Context.MODE_PRIVATE).getString(
69 getString(R.string.keyHost), null).equals(null)) {69 getString(R.string.keyHost), null).equals(null)) {
70 Log.d(LOG_TAG,70 Log.d(LOG_TAG,
71 "URL preference not set. Starting preference activity...");71 "URL preference not set. Starting preference activity...");
72 Intent preferenceIntent = new Intent(this, Preferences.class);72 Intent preferenceIntent = new Intent(this, Preferences.class);
73 startActivity(preferenceIntent);73 startActivity(preferenceIntent);
74 }74 }
75 }75 }
7676
77 private void setOnClickListenerPagerForButtons() {77 private void setOnClickListenerPagerForButtons() {
78 findViewById(R.id.buttonService)78 findViewById(R.id.buttonService)
79 .setOnClickListener(onClickListenerPager);79 .setOnClickListener(onClickListenerPager);
80 findViewById(R.id.buttonLive)80 findViewById(R.id.buttonLive)
81 .setOnClickListener(onClickListenerPager);81 .setOnClickListener(onClickListenerPager);
82 findViewById(R.id.buttonDisplay)82 findViewById(R.id.buttonDisplay)
83 .setOnClickListener(onClickListenerPager);83 .setOnClickListener(onClickListenerPager);
84 findViewById(R.id.buttonAlert)84 findViewById(R.id.buttonAlert)
85 .setOnClickListener(onClickListenerPager);85 .setOnClickListener(onClickListenerPager);
86 findViewById(R.id.buttonStage)86 findViewById(R.id.buttonStage)
87 .setOnClickListener(onClickListenerPager);87 .setOnClickListener(onClickListenerPager);
88 findViewById(R.id.buttonSearch)88 findViewById(R.id.buttonSearch)
89 .setOnClickListener(onClickListenerSearch);89 .setOnClickListener(onClickListenerSearch);
90 }90 }
9191
92 private View.OnClickListener onClickListenerSearch =92 private View.OnClickListener onClickListenerSearch =
93 new View.OnClickListener() {93 new View.OnClickListener() {
94 @Override94 @Override
95 public void onClick(View view) {95 public void onClick(View view) {
96 onSearchRequested();96 onSearchRequested();
97 }97 }
98 };98 };
9999
100 private final String LOG_TAG = OpenLP.class.getName();100 private final String LOG_TAG = OpenLP.class.getName();
101}101}
102102
=== modified file 'src/org/openlp/android/activity/DefaultActivity.java'
--- src/org/openlp/android/activity/DefaultActivity.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/DefaultActivity.java 2013-06-04 19:32:29 +0000
@@ -31,25 +31,25 @@
3131
3232
33public abstract class DefaultActivity extends Activity implements Api {33public abstract class DefaultActivity extends Activity implements Api {
34 @Override34 @Override
35 public boolean onCreateOptionsMenu(Menu menu) {35 public boolean onCreateOptionsMenu(Menu menu) {
36 MenuInflater inflater = getMenuInflater();36 MenuInflater inflater = getMenuInflater();
37 inflater.inflate(R.menu.menu, menu);37 inflater.inflate(R.menu.menu, menu);
38 return true;38 return true;
39 }39 }
4040
41 @Override41 @Override
42 public boolean onOptionsItemSelected(MenuItem item) {42 public boolean onOptionsItemSelected(MenuItem item) {
43 // Handle item selection43 // Handle item selection
44 switch (item.getItemId()) {44 switch (item.getItemId()) {
45 case R.id.preferences:45 case R.id.preferences:
46 startActivity(new Intent(this, Preferences.class));46 startActivity(new Intent(this, Preferences.class));
47 return true;47 return true;
48 case R.id.menuSearch:48 case R.id.menuSearch:
49 onSearchRequested();49 onSearchRequested();
50 return true;50 return true;
51 default:51 default:
52 return super.onOptionsItemSelected(item);52 return super.onOptionsItemSelected(item);
53 }53 }
54 }54 }
55}55}
5656
=== modified file 'src/org/openlp/android/activity/OpenLPNavigate.java'
--- src/org/openlp/android/activity/OpenLPNavigate.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/OpenLPNavigate.java 2013-06-04 19:32:29 +0000
@@ -27,38 +27,40 @@
27 */27 */
28public interface OpenLPNavigate extends Api {28public interface OpenLPNavigate extends Api {
2929
30 public final String NAVIGATE_PREVIOUS = "previous";30 public final String NAVIGATE_PREVIOUS = "previous";
31 public final String NAVIGATE_NEXT = "next";31 public final String NAVIGATE_NEXT = "next";
32 public final String HIDE_SCREEN = "blank";32 public final String HIDE_SCREEN = "blank";
33 public final String HIDE_THEME = "theme";33 public final String HIDE_THEME = "theme";
34 public final String HIDE_DESKTOP = "desktop";34 public final String HIDE_DESKTOP = "desktop";
35 public final String DISPLAY_SHOW = "show";35 public final String DISPLAY_SHOW = "show";
3636
37 /**37 /**
38 * Call to the service changing service/slides.38 * Call to the service changing service/slides.
39 *39 *
40 * @param direction A direction constant from {@link org.openlp.android.api.Api}.40 * @param direction A direction constant from {@link org.openlp.android.api.Api}.
41 * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}41 * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}
42 * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.42 * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.
43 */43 */
44 void navigate(String direction);44 void navigate(String direction);
4545
46 /**46 /**
47 * Call to the service changing data for Service or Live47 * Call to the service changing data for Service or Live
48 *48 *
49 * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.49 * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.
50 * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}50 * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}
51 * or {@link org.openlp.android.api.Api#SERVICE_SET}51 * or {@link org.openlp.android.api.Api#SERVICE_SET}
52 * @param id Id of the item selected.52 * @param id Id of the item selected.
53 */53 */
54 void setData(String apiPart, int id);54 void setData(String apiPart, int id);
5555
56 void setDisplay(String displayRequest);56 void setDisplay(String displayRequest);
57 void poll();57
5858 void poll();
59 /**59
60 * Replaces what we previously had as FetchItemsTask which basically ran in the UI60 /**
61 * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}61 * Replaces what we previously had as FetchItemsTask which basically ran in the UI
62 */62 *
63 void fetchItems(String apiPart);63 * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}
64 */
65 void fetchItems(String apiPart);
64}66}
6567
=== modified file 'src/org/openlp/android/activity/PagerActivity.java'
--- src/org/openlp/android/activity/PagerActivity.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/PagerActivity.java 2013-06-04 19:32:29 +0000
@@ -28,39 +28,39 @@
28import org.openlp.android.utility.OpenLPController;28import org.openlp.android.utility.OpenLPController;
2929
30public class PagerActivity extends DefaultActivity {30public class PagerActivity extends DefaultActivity {
31 private ViewPager pager;31 private ViewPager pager;
32 private OpenLPController controller;32 private OpenLPController controller;
3333
34 @Override34 @Override
35 protected void onCreate(Bundle savedInstanceState) {35 protected void onCreate(Bundle savedInstanceState) {
36 super.onCreate(savedInstanceState);36 super.onCreate(savedInstanceState);
37 Log.i(LOG_TAG, "onCreate");37 Log.i(LOG_TAG, "onCreate");
3838
39 setContentView(R.layout.view_pager_layout);39 setContentView(R.layout.view_pager_layout);
4040
41 controller = new OpenLPController(this);41 controller = new OpenLPController(this);
42 pager = (ViewPager) findViewById(R.id.myViewPager);42 pager = (ViewPager) findViewById(R.id.myViewPager);
43 pager.setAdapter(controller);43 pager.setAdapter(controller);
4444
45 Intent intent = getIntent();45 Intent intent = getIntent();
46 int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);46 int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);
47 Log.v(LOG_TAG, "Setting Page number: " + selectedPage);47 Log.v(LOG_TAG, "Setting Page number: " + selectedPage);
48 pager.setOnPageChangeListener(controller.onPageChangeListener);48 pager.setOnPageChangeListener(controller.onPageChangeListener);
49 pager.setCurrentItem(selectedPage, true);49 pager.setCurrentItem(selectedPage, true);
50 controller.onPageChangeListener.onPageSelected(selectedPage);50 controller.onPageChangeListener.onPageSelected(selectedPage);
51 }51 }
5252
53 public void setCurrentPage(int page) {53 public void setCurrentPage(int page) {
54 pager.setCurrentItem(page, true);54 pager.setCurrentItem(page, true);
55 }55 }
5656
57 @Override57 @Override
58 protected void onDestroy() {58 protected void onDestroy() {
59 super.onDestroy();59 super.onDestroy();
60 Log.v(LOG_TAG, "Destroying pagerActivity...");60 Log.v(LOG_TAG, "Destroying pagerActivity...");
61 unregisterReceiver(controller.apiCallReceiver);61 unregisterReceiver(controller.apiCallReceiver);
62 stopService(controller.pingIntent);62 stopService(controller.pingIntent);
63 }63 }
6464
65 private final String LOG_TAG = PagerActivity.class.getName();65 private final String LOG_TAG = PagerActivity.class.getName();
66}66}
6767
=== modified file 'src/org/openlp/android/activity/Search.java'
--- src/org/openlp/android/activity/Search.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/Search.java 2013-06-04 19:32:29 +0000
@@ -21,7 +21,7 @@
21package org.openlp.android.activity;21package org.openlp.android.activity;
2222
23public interface Search {23public interface Search {
24 public final String ACTION = Search.class.getName().concat(".Action");24 public final String ACTION = Search.class.getName().concat(".Action");
2525
26 public void searchPluginCall(String apiBase, String apiData);26 public void searchPluginCall(String apiBase, String apiData);
27}27}
2828
=== modified file 'src/org/openlp/android/activity/SearchService.java'
--- src/org/openlp/android/activity/SearchService.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/SearchService.java 2013-06-04 19:32:29 +0000
@@ -27,7 +27,7 @@
27import java.net.URISyntaxException;27import java.net.URISyntaxException;
2828
29public interface SearchService {29public interface SearchService {
30 public Intent getSearchPluginIntent(String apiBase, String apiData)30 public Intent getSearchPluginIntent(String apiBase, String apiData)
31 throws JSONHandler.JSONHandlerException, IOException,31 throws JSONHandler.JSONHandlerException, IOException,
32 URISyntaxException;32 URISyntaxException;
33}33}
3434
=== modified file 'src/org/openlp/android/activity/SearchableActivity.java'
--- src/org/openlp/android/activity/SearchableActivity.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/SearchableActivity.java 2013-06-04 19:32:29 +0000
@@ -52,242 +52,239 @@
52import java.util.Map;52import java.util.Map;
5353
54public class SearchableActivity extends Activity implements Api {54public class SearchableActivity extends Activity implements Api {
55 private ExpandableListView listView;55 private ExpandableListView listView;
56 private final int DIALOG_ITEM_OPTIONS = 0;56 private final int DIALOG_ITEM_OPTIONS = 0;
57 private Object dialogKey;57 private Object dialogKey;
58 private JSONArray dialogValue;58 private JSONArray dialogValue;
5959
60 private Search controller = new Search() {60 private Search controller = new Search() {
61 @Override61 @Override
62 public void searchPluginCall(String apiBase, String apiData) {62 public void searchPluginCall(String apiBase, String apiData) {
63 Intent apiCallIntent =63 Intent apiCallIntent =
64 new Intent(SearchableActivity.this, ApiCallIntent.class);64 new Intent(SearchableActivity.this, ApiCallIntent.class);
65 apiCallIntent.putExtra(apiBase, apiData);65 apiCallIntent.putExtra(apiBase, apiData);
66 startService(apiCallIntent);66 startService(apiCallIntent);
67 }67 }
68 };68 };
6969
70 BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {70 BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
71 @Override71 @Override
72 public void onReceive(Context context, Intent intent) {72 public void onReceive(Context context, Intent intent) {
73 Log.d(LOG_TAG, String.format(73 Log.d(LOG_TAG, String.format(
74 "Search broadcast received: context(%s), intent(%s, %s)",74 "Search broadcast received: context(%s), intent(%s, %s)",
75 context, intent, intent.getExtras()));75 context, intent, intent.getExtras()));
76 }76 }
77 };77 };
7878
79 @Override79 @Override
80 protected void onCreate(Bundle savedInstanceState) {80 protected void onCreate(Bundle savedInstanceState) {
81 super.onCreate(savedInstanceState);81 super.onCreate(savedInstanceState);
82 setContentView(R.layout.search);82 setContentView(R.layout.search);
83 listView = (ExpandableListView) findViewById(R.id.list);83 listView = (ExpandableListView) findViewById(R.id.list);
84 listView.setOnChildClickListener(onChildClickListener);84 listView.setOnChildClickListener(onChildClickListener);
8585
86 IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);86 IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);
87 apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);87 apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
8888
89 registerReceiver(apiCallReceiver, apiCallFilter);89 registerReceiver(apiCallReceiver, apiCallFilter);
9090
91 Intent intent = getIntent();91 Intent intent = getIntent();
92 if (Intent.ACTION_SEARCH.equals(intent.getAction())) {92 if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
93 String query = intent.getStringExtra(SearchManager.QUERY);93 String query = intent.getStringExtra(SearchManager.QUERY);
94 doSearch(query);94 doSearch(query);
95 }95 }
96 }96 }
9797
98 private ExpandableListView.OnChildClickListener onChildClickListener =98 private ExpandableListView.OnChildClickListener onChildClickListener =
99 new ExpandableListView.OnChildClickListener() {99 new ExpandableListView.OnChildClickListener() {
100 @Override100 @Override
101 public boolean onChildClick(ExpandableListView expandableListView,101 public boolean onChildClick(ExpandableListView expandableListView,
102 View view, int parent, int childPosition, long l) {102 View view, int parent, int childPosition, long l) {
103 @SuppressWarnings("unchecked") Map<String, JSONArray> child =103 @SuppressWarnings("unchecked") Map<String, JSONArray> child =
104 (Map<String, JSONArray>) listView.getExpandableListAdapter()104 (Map<String, JSONArray>) listView.getExpandableListAdapter()
105 .getChild(parent, childPosition);105 .getChild(parent, childPosition);
106 dialogKey = null;106 dialogKey = null;
107 dialogValue = null;107 dialogValue = null;
108 dialogKey =108 dialogKey =
109 listView.getExpandableListAdapter().getGroup(parent);109 listView.getExpandableListAdapter().getGroup(parent);
110 dialogValue = child.get(dialogKey.toString());110 dialogValue = child.get(dialogKey.toString());
111 showDialog(DIALOG_ITEM_OPTIONS);111 showDialog(DIALOG_ITEM_OPTIONS);
112 return false;112 return false;
113 }113 }
114 };114 };
115115
116 @Override116 @Override
117 protected Dialog onCreateDialog(int id) {117 protected Dialog onCreateDialog(int id) {
118 switch (id) {118 switch (id) {
119 case DIALOG_ITEM_OPTIONS:119 case DIALOG_ITEM_OPTIONS:
120 AlertDialog.Builder dialogBuilder =120 AlertDialog.Builder dialogBuilder =
121 new AlertDialog.Builder(SearchableActivity.this);121 new AlertDialog.Builder(SearchableActivity.this);
122 dialogBuilder122 dialogBuilder
123 .setTitle(getString(R.string.dialogTitleItemOptions));123 .setTitle(getString(R.string.dialogTitleItemOptions));
124 dialogBuilder.setNegativeButton(124 dialogBuilder.setNegativeButton(
125 getString(R.string.dialogNegativeSendLive),125 getString(R.string.dialogNegativeSendLive),
126 onClickListenerDialogSendLive);126 onClickListenerDialogSendLive);
127 dialogBuilder.setPositiveButton(127 dialogBuilder.setPositiveButton(
128 getString(R.string.dialogPositiveAddToService),128 getString(R.string.dialogPositiveAddToService),
129 onClickListenerDialogAddToService);129 onClickListenerDialogAddToService);
130 return dialogBuilder.create();130 return dialogBuilder.create();
131 default:131 default:
132 return null;132 return null;
133 }133 }
134 }134 }
135135
136 DialogInterface.OnClickListener onClickListenerDialogSendLive =136 DialogInterface.OnClickListener onClickListenerDialogSendLive =
137 new DialogInterface.OnClickListener() {137 new DialogInterface.OnClickListener() {
138 @Override138 @Override
139 public void onClick(DialogInterface dialogInterface, int i) {139 public void onClick(DialogInterface dialogInterface, int i) {
140 controller.searchPluginCall(140 controller.searchPluginCall(
141 String.format(SEARCH_PLUGIN_LIVE, dialogKey),141 String.format(SEARCH_PLUGIN_LIVE, dialogKey),
142 getDialogValue());142 getDialogValue());
143 }143 }
144 };144 };
145145
146 DialogInterface.OnClickListener onClickListenerDialogAddToService =146 DialogInterface.OnClickListener onClickListenerDialogAddToService =
147 new DialogInterface.OnClickListener() {147 new DialogInterface.OnClickListener() {
148 @Override148 @Override
149 public void onClick(DialogInterface dialogInterface, int i) {149 public void onClick(DialogInterface dialogInterface, int i) {
150 controller.searchPluginCall(150 controller.searchPluginCall(
151 String.format(SEARCH_PLUGIN_ADD, dialogKey),151 String.format(SEARCH_PLUGIN_ADD, dialogKey),
152 getDialogValue());152 getDialogValue());
153 dialogInterface.cancel();153 dialogInterface.cancel();
154 }154 }
155 };155 };
156156
157 private String getDialogValue() {157 private String getDialogValue() {
158 try {158 try {
159 return String.valueOf(dialogValue.get(0));159 return String.valueOf(dialogValue.get(0));
160 }160 } catch (JSONException e) {
161 catch (JSONException e) {161 Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());
162 Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());162 Toast.makeText(SearchableActivity.this, e.getMessage(),
163 Toast.makeText(SearchableActivity.this, e.getMessage(),163 Toast.LENGTH_LONG).show();
164 Toast.LENGTH_LONG).show();164 return null;
165 return null;165 }
166 }166 }
167 }167
168168 @Override
169 @Override169 protected void onPrepareDialog(int id, Dialog dialog) {
170 protected void onPrepareDialog(int id, Dialog dialog) {170 try {
171 try {171 dialog.setTitle(dialogValue.get(1).toString());
172 dialog.setTitle(dialogValue.get(1).toString());172 } catch (JSONException e) {
173 }173 e.printStackTrace();
174 catch (JSONException e) {174 }
175 e.printStackTrace();175 }
176 }176
177 }177 public void doSearch(String search) {
178178 new SearchAsync().execute(search);
179 public void doSearch(String search) {179 }
180 new SearchAsync().execute(search);180
181 }181 @Override
182182 protected void onDestroy() {
183 @Override183 super.onDestroy();
184 protected void onDestroy() {184 unregisterReceiver(apiCallReceiver);
185 super.onDestroy();185 }
186 unregisterReceiver(apiCallReceiver);186
187 }187 class SearchAsync extends AsyncTask<String, Void, SearchResults> {
188188 ProgressDialog progressDialog;
189 class SearchAsync extends AsyncTask<String, Void, SearchResults> {189 String query;
190 ProgressDialog progressDialog;190
191 String query;191 @Override
192192 protected SearchResults doInBackground(String... strings) {
193 @Override193 query = strings[0];
194 protected SearchResults doInBackground(String... strings) {194 List<String> groups = new ArrayList<String>();
195 query = strings[0];195 List<List<Map<String, JSONArray>>> children =
196 List<String> groups = new ArrayList<String>();196 new ArrayList<List<Map<String, JSONArray>>>();
197 List<List<Map<String, JSONArray>>> children =197 AsyncTask<String, Void, String> call =
198 new ArrayList<List<Map<String, JSONArray>>>();198 new WebCallReturningAsyncTask(SearchableActivity.this)
199 AsyncTask<String, Void, String> call =199 .execute(SEARCHABLE_PLUGINS);
200 new WebCallReturningAsyncTask(SearchableActivity.this)200
201 .execute(SEARCHABLE_PLUGINS);201 try {
202202 JSONArray array =
203 try {203 new JSONObject(call.get()).getJSONObject("results")
204 JSONArray array =204 .getJSONArray("items");
205 new JSONObject(call.get()).getJSONObject("results")205
206 .getJSONArray("items");206 for (int i = 0; i < array.length(); i++) {
207207 String pluginString =
208 for (int i = 0; i < array.length(); i++) {208 ((JSONArray) array.get(i)).get(0).toString();
209 String pluginString =209 groups.add(pluginString);
210 ((JSONArray) array.get(i)).get(0).toString();210
211 groups.add(pluginString);211 JSONArray resultArray = null;
212212
213 JSONArray resultArray = null;213 AsyncTask<String, Void, String> pluginResults =
214214 new WebCallReturningAsyncTask(SearchableActivity.this,
215 AsyncTask<String, Void, String> pluginResults =215 String
216 new WebCallReturningAsyncTask(SearchableActivity.this,216 .format(SEARCH_PLUGIN_FORMATTED, pluginString))
217 String217 .execute(
218 .format(SEARCH_PLUGIN_FORMATTED, pluginString))218 JSONHandler.createRequestJSON("text", query));
219 .execute(219
220 JSONHandler.createRequestJSON("text", query));220 List<Map<String, JSONArray>> list =
221221 new ArrayList<Map<String, JSONArray>>();
222 List<Map<String, JSONArray>> list =222 if (pluginResults.get() != null &&
223 new ArrayList<Map<String, JSONArray>>();223 pluginResults.get().trim().length() > 0) {
224 if (pluginResults.get() != null &&224 resultArray = new JSONObject(pluginResults.get())
225 pluginResults.get().trim().length() > 0) {225 .getJSONObject("results").getJSONArray("items");
226 resultArray = new JSONObject(pluginResults.get())226 for (int j = 0; j < resultArray.length(); j++) {
227 .getJSONObject("results").getJSONArray("items");227 Map<String, JSONArray> item =
228 for (int j = 0; j < resultArray.length(); j++) {228 new HashMap<String, JSONArray>();
229 Map<String, JSONArray> item =229 item.put(pluginString,
230 new HashMap<String, JSONArray>();230 (JSONArray) resultArray.get(j));
231 item.put(pluginString,231 list.add(item);
232 (JSONArray) resultArray.get(j));232 }
233 list.add(item);233 }
234 }234 children.add(list);
235 }235 }
236 children.add(list);236 } catch (Exception e) {
237 }237 Log.e(LOG_TAG, e.toString());
238 }238 Toast.makeText(SearchableActivity.this, e.getMessage(),
239 catch (Exception e) {239 Toast.LENGTH_LONG).show();
240 Log.e(LOG_TAG, e.toString());240 }
241 Toast.makeText(SearchableActivity.this, e.getMessage(),241
242 Toast.LENGTH_LONG).show();242 SearchResults results = new SearchResults();
243 }243 results.setGroups(groups);
244244 results.setChildren(children);
245 SearchResults results = new SearchResults();245 return results;
246 results.setGroups(groups);246 }
247 results.setChildren(children);247
248 return results;248 @Override
249 }249 protected void onPreExecute() {
250250 super.onPreExecute();
251 @Override251 progressDialog = ProgressDialog.show(SearchableActivity.this, null,
252 protected void onPreExecute() {252 getString(R.string.searching));
253 super.onPreExecute();253 }
254 progressDialog = ProgressDialog.show(SearchableActivity.this, null,254
255 getString(R.string.searching));255 @Override
256 }256 protected void onPostExecute(SearchResults results) {
257257 super.onPostExecute(results);
258 @Override258 listView.setAdapter(
259 protected void onPostExecute(SearchResults results) {259 new GroupExpandableListAdapter(SearchableActivity.this,
260 super.onPostExecute(results);260 results.getGroups(), results.getChildren()));
261 listView.setAdapter(261 progressDialog.dismiss();
262 new GroupExpandableListAdapter(SearchableActivity.this,262 Toast.makeText(SearchableActivity.this,
263 results.getGroups(), results.getChildren()));263 String.format(getString(R.string.showingResults), query),
264 progressDialog.dismiss();264 Toast.LENGTH_SHORT).show();
265 Toast.makeText(SearchableActivity.this,265 }
266 String.format(getString(R.string.showingResults), query),266 }
267 Toast.LENGTH_SHORT).show();267
268 }268 class SearchResults {
269 }269 List<String> groups;
270270 List<List<Map<String, JSONArray>>> children;
271 class SearchResults {271
272 List<String> groups;272 public List<String> getGroups() {
273 List<List<Map<String, JSONArray>>> children;273 return groups;
274274 }
275 public List<String> getGroups() {275
276 return groups;276 public void setGroups(List<String> groups) {
277 }277 this.groups = groups;
278278 }
279 public void setGroups(List<String> groups) {279
280 this.groups = groups;280 public List<List<Map<String, JSONArray>>> getChildren() {
281 }281 return children;
282282 }
283 public List<List<Map<String, JSONArray>>> getChildren() {283
284 return children;284 public void setChildren(List<List<Map<String, JSONArray>>> children) {
285 }285 this.children = children;
286286 }
287 public void setChildren(List<List<Map<String, JSONArray>>> children) {287 }
288 this.children = children;288
289 }289 private final String LOG_TAG = this.getClass().getName();
290 }
291
292 private final String LOG_TAG = this.getClass().getName();
293}290}
294291
=== modified file 'src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java'
--- src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2013-04-07 12:24:38 +0000
+++ src/org/openlp/android/activity/preference/ConnectionPreferenceActivity.java 2013-06-04 19:32:29 +0000
@@ -43,162 +43,162 @@
43import org.openlp.android.R;43import org.openlp.android.R;
4444
45public class ConnectionPreferenceActivity extends PreferenceActivity {45public class ConnectionPreferenceActivity extends PreferenceActivity {
46 private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";46 private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";
47 private final String KEY_SERVER_ID = "keyServerId";47 private final String KEY_SERVER_ID = "keyServerId";
48 private final String PREFERENCE_DISPLAY_SERVER = "displayServer";48 private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
49 private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();49 private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
5050
51 private PreferenceScreen preferenceScreen = null;51 private PreferenceScreen preferenceScreen = null;
52 private boolean resume = true;52 private boolean resume = true;
5353
54 @Override54 @Override
55 protected void onCreate(Bundle savedInstanceState) {55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);56 super.onCreate(savedInstanceState);
57 addPreferencesFromResource(R.xml.empty_preferences);57 addPreferencesFromResource(R.xml.empty_preferences);
58 getPreferenceManager()58 getPreferenceManager()
59 .setSharedPreferencesName(getString(R.string.keySharedPreferences));59 .setSharedPreferencesName(getString(R.string.keySharedPreferences));
60 preferenceScreen = getPreferenceScreen() == null60 preferenceScreen = getPreferenceScreen() == null
61 ? getPreferenceManager().createPreferenceScreen(this)61 ? getPreferenceManager().createPreferenceScreen(this)
62 : getPreferenceScreen();62 : getPreferenceScreen();
63 preferenceScreen.removeAll();63 preferenceScreen.removeAll();
64 String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);64 String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);
65 if (preferenceDisplay != null65 if (preferenceDisplay != null
66 && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {66 && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
67 constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));67 constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
68 } else {68 } else {
69 resume = false;69 resume = false;
70 constructOverviewScreen();70 constructOverviewScreen();
71 }71 }
72 }72 }
7373
74 private void constructOverviewScreen() {74 private void constructOverviewScreen() {
75 getPreferenceScreen().removeAll();75 getPreferenceScreen().removeAll();
76 Log.i(LOG_TAG, "constructOverviewScreen");76 Log.i(LOG_TAG, "constructOverviewScreen");
77 Preference configPref = new Preference(this);77 Preference configPref = new Preference(this);
78 configPref.setTitle(getString(R.string.connection_available_configurations));78 configPref.setTitle(getString(R.string.connection_available_configurations));
79 configPref.setSummary(getString(R.string.connection_add_by_menu));79 configPref.setSummary(getString(R.string.connection_add_by_menu));
80 configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {80 configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
81 @Override81 @Override
82 public boolean onPreferenceClick(Preference preference) {82 public boolean onPreferenceClick(Preference preference) {
83 int nextId = getNextPrefId(83 int nextId = getNextPrefId(
84 getHostConfigMap(84 getHostConfigMap(
85 getPreferenceManager()85 getPreferenceManager()
86 .getSharedPreferences().getAll()86 .getSharedPreferences().getAll()
87 )87 )
88 );88 );
89 Preference newPreference = simpleClickablePreferenceFromHostConfig(89 Preference newPreference = simpleClickablePreferenceFromHostConfig(
90 new HostConfig(90 new HostConfig(
91 getString(R.string.connection_profile_server),91 getString(R.string.connection_profile_server),
92 nextId));92 nextId));
93 newPreference.setTitle(getString(R.string.connection_profile_new_server));93 newPreference.setTitle(getString(R.string.connection_profile_new_server));
94 newPreference.setSummary(getString(R.string.connection_profile_not_saved));94 newPreference.setSummary(getString(R.string.connection_profile_not_saved));
95 preferenceScreen.addPreference(newPreference);95 preferenceScreen.addPreference(newPreference);
96 return true;96 return true;
97 }97 }
98 });98 });
99 preferenceScreen.addPreference(configPref);99 preferenceScreen.addPreference(configPref);
100 List<HostConfig> hostConfigs = getHostConfigs();100 List<HostConfig> hostConfigs = getHostConfigs();
101 if (!hostConfigs.isEmpty()) {101 if (!hostConfigs.isEmpty()) {
102 for (final HostConfig config : getHostConfigs()) {102 for (final HostConfig config : getHostConfigs()) {
103 preferenceScreen.addPreference(103 preferenceScreen.addPreference(
104 simpleClickablePreferenceFromHostConfig(config));104 simpleClickablePreferenceFromHostConfig(config));
105 }105 }
106 }106 }
107 }107 }
108108
109 private void constructServerView(int hostId) {109 private void constructServerView(int hostId) {
110 HostConfig hostConfig = hostConfigFromPreferencesForHostId(110 HostConfig hostConfig = hostConfigFromPreferencesForHostId(
111 hostId,111 hostId,
112 getHostConfigMap(112 getHostConfigMap(
113 getPreferenceManager()113 getPreferenceManager()
114 .getSharedPreferences()114 .getSharedPreferences()
115 .getAll()115 .getAll()
116 )116 )
117 );117 );
118 addPreferenceCategory(preferenceScreen, hostConfig);118 addPreferenceCategory(preferenceScreen, hostConfig);
119 }119 }
120120
121 private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {121 private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
122 final Preference serverConfig = new Preference(this);122 final Preference serverConfig = new Preference(this);
123 serverConfig.setTitle(config.title.getSummary());123 serverConfig.setTitle(config.title.getSummary());
124124
125 Boolean useSsl = getPreferenceManager()125 Boolean useSsl = getPreferenceManager()
126 .getSharedPreferences()126 .getSharedPreferences()
127 .getBoolean(config.useSsl.getKey(), false);127 .getBoolean(config.useSsl.getKey(), false);
128128
129 serverConfig.setSummary(String.format(129 serverConfig.setSummary(String.format(
130 "%s:%s %s",130 "%s:%s %s",
131 config.hostAddress.getText(),131 config.hostAddress.getText(),
132 config.hostPort.getText(),132 config.hostPort.getText(),
133 useSsl ? "(SSL)" : "")133 useSsl ? "(SSL)" : "")
134 );134 );
135 serverConfig.setOnPreferenceClickListener(135 serverConfig.setOnPreferenceClickListener(
136 new Preference.OnPreferenceClickListener() {136 new Preference.OnPreferenceClickListener() {
137 @Override137 @Override
138 public boolean onPreferenceClick(Preference preference) {138 public boolean onPreferenceClick(Preference preference) {
139 Intent serverConfigIntent = new Intent(139 Intent serverConfigIntent = new Intent(
140 ConnectionPreferenceActivity.this,140 ConnectionPreferenceActivity.this,
141 ConnectionPreferenceActivity.class141 ConnectionPreferenceActivity.class
142 );142 );
143 serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,143 serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,
144 PREFERENCE_DISPLAY_SERVER);144 PREFERENCE_DISPLAY_SERVER);
145 serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);145 serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
146 startActivity(serverConfigIntent);146 startActivity(serverConfigIntent);
147 return true;147 return true;
148 }148 }
149 });149 });
150 return serverConfig;150 return serverConfig;
151 }151 }
152152
153 private List<HostConfig> getHostConfigs() {153 private List<HostConfig> getHostConfigs() {
154 return hostConfigsFromPreferences(154 return hostConfigsFromPreferences(
155 getHostConfigMap(155 getHostConfigMap(
156 getPreferenceManager()156 getPreferenceManager()
157 .getSharedPreferences()157 .getSharedPreferences()
158 .getAll()158 .getAll()
159 )159 )
160 );160 );
161 }161 }
162162
163 private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {163 private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
164 Map<String, Object> configMap = new TreeMap<String, Object>();164 Map<String, Object> configMap = new TreeMap<String, Object>();
165165
166 List<String> sortedKeys = new ArrayList<String>(preferences.keySet());166 List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
167 Collections.sort(sortedKeys);167 Collections.sort(sortedKeys);
168 for (String key : sortedKeys) {168 for (String key : sortedKeys) {
169 if (key.startsWith(HostConfig.KEY_PREFIX)) {169 if (key.startsWith(HostConfig.KEY_PREFIX)) {
170 configMap.put(key, preferences.get(key));170 configMap.put(key, preferences.get(key));
171 }171 }
172 }172 }
173 return configMap;173 return configMap;
174 }174 }
175175
176 private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {176 private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
177 List<Integer> hostIds = getHostIds(preferences);177 List<Integer> hostIds = getHostIds(preferences);
178 List<HostConfig> hostConfigs = new ArrayList<HostConfig>();178 List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
179 for (Integer id : hostIds) {179 for (Integer id : hostIds) {
180 hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));180 hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
181 }181 }
182 return hostConfigs;182 return hostConfigs;
183 }183 }
184184
185 private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {185 private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
186 Object titleValue = preferences.get(getHostConfigTitleKey(hostId));186 Object titleValue = preferences.get(getHostConfigTitleKey(hostId));
187 String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();187 String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();
188 HostConfig hostConfig = new HostConfig(188 HostConfig hostConfig = new HostConfig(
189 hostTitle, hostId189 hostTitle, hostId
190 );190 );
191 Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());191 Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
192 String hostValue = hostValueObject == null192 String hostValue = hostValueObject == null
193 ? getString(R.string.hostDefaultValue) : hostValueObject.toString();193 ? getString(R.string.hostDefaultValue) : hostValueObject.toString();
194 hostConfig.hostAddress.setText(hostValue);194 hostConfig.hostAddress.setText(hostValue);
195 hostConfig.hostAddress.setSummary(hostValue);195 hostConfig.hostAddress.setSummary(hostValue);
196196
197 Object portValueObject = preferences.get(hostConfig.hostPort.getKey());197 Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
198 String portValue = portValueObject == null198 String portValue = portValueObject == null
199 ? getString(R.string.portDefaultValue) : portValueObject.toString();199 ? getString(R.string.portDefaultValue) : portValueObject.toString();
200 hostConfig.hostPort.setText(portValue);200 hostConfig.hostPort.setText(portValue);
201 hostConfig.hostPort.setSummary(portValue);201 hostConfig.hostPort.setSummary(portValue);
202202
203 Object useridValueObject = preferences.get(hostConfig.userid.getKey());203 Object useridValueObject = preferences.get(hostConfig.userid.getKey());
204 String useridValue = useridValueObject == null204 String useridValue = useridValueObject == null
@@ -211,106 +211,106 @@
211 ? getString(R.string.passwordDefaultValue) : passwordValueObject.toString();211 ? getString(R.string.passwordDefaultValue) : passwordValueObject.toString();
212 hostConfig.password.setText(passwordValue);212 hostConfig.password.setText(passwordValue);
213 hostConfig.password.setSummary(passwordValue);213 hostConfig.password.setSummary(passwordValue);
214 return hostConfig;214 return hostConfig;
215 }215 }
216216
217 private int getNextPrefId(Map<String, ?> preferences) {217 private int getNextPrefId(Map<String, ?> preferences) {
218 int max = 0;218 int max = 0;
219 for (String key : preferences.keySet()) {219 for (String key : preferences.keySet()) {
220 int prefValue = Integer.valueOf(key.split("\\.")[2]);220 int prefValue = Integer.valueOf(key.split("\\.")[2]);
221 max = prefValue > max ? prefValue : max;221 max = prefValue > max ? prefValue : max;
222 }222 }
223 return max + 1;223 return max + 1;
224 }224 }
225225
226 private List<Integer> getHostIds(Map<String, ?> preferences) {226 private List<Integer> getHostIds(Map<String, ?> preferences) {
227 Set<Integer> hashSet = new HashSet<Integer>();227 Set<Integer> hashSet = new HashSet<Integer>();
228 for (String key : preferences.keySet()) {228 for (String key : preferences.keySet()) {
229 hashSet.add(Integer.valueOf(key.split("\\.")[2]));229 hashSet.add(Integer.valueOf(key.split("\\.")[2]));
230 }230 }
231 List<Integer> hostIds = new ArrayList<Integer>(hashSet);231 List<Integer> hostIds = new ArrayList<Integer>(hashSet);
232 Collections.sort(hostIds);232 Collections.sort(hostIds);
233 Log.i(LOG_TAG, "Got HostIds: " + hostIds);233 Log.i(LOG_TAG, "Got HostIds: " + hostIds);
234 return hostIds;234 return hostIds;
235 }235 }
236236
237 private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {237 private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
238 PreferenceCategory preferenceCategory = new PreferenceCategory(this);238 PreferenceCategory preferenceCategory = new PreferenceCategory(this);
239 preferenceCategory.setTitle(hostConfig.title.getSummary());239 preferenceCategory.setTitle(hostConfig.title.getSummary());
240 preferenceCategory.setKey("key.preference.category");240 preferenceCategory.setKey("key.preference.category");
241 preferenceScreen.addPreference(preferenceCategory);241 preferenceScreen.addPreference(preferenceCategory);
242 preferenceCategory.addPreference(hostConfig.title);242 preferenceCategory.addPreference(hostConfig.title);
243 preferenceCategory.addPreference(hostConfig.hostAddress);243 preferenceCategory.addPreference(hostConfig.hostAddress);
244 preferenceCategory.addPreference(hostConfig.hostPort);244 preferenceCategory.addPreference(hostConfig.hostPort);
245 preferenceCategory.addPreference(hostConfig.useSsl);245 preferenceCategory.addPreference(hostConfig.useSsl);
246 preferenceCategory.addPreference(hostConfig.userid);246 preferenceCategory.addPreference(hostConfig.userid);
247 preferenceCategory.addPreference(hostConfig.password);247 preferenceCategory.addPreference(hostConfig.password);
248 preferenceCategory.addPreference(hostConfig.remove);248 preferenceCategory.addPreference(hostConfig.remove);
249 preferenceCategory.addPreference(hostConfig.activate);249 preferenceCategory.addPreference(hostConfig.activate);
250 return true;250 return true;
251 }251 }
252252
253 @Override253 @Override
254 protected void onResume() {254 protected void onResume() {
255 super.onResume();255 super.onResume();
256 if (resume) {256 if (resume) {
257 Log.i(LOG_TAG, "Resuming...");257 Log.i(LOG_TAG, "Resuming...");
258 } else {258 } else {
259 constructOverviewScreen();259 constructOverviewScreen();
260 Log.i(LOG_TAG, "Not resuming...");260 Log.i(LOG_TAG, "Not resuming...");
261 }261 }
262 }262 }
263263
264 private static String getHostConfigTitleKey(int id) {264 private static String getHostConfigTitleKey(int id) {
265 return HostConfig.KEY_PREFIX + id + ".title";265 return HostConfig.KEY_PREFIX + id + ".title";
266 }266 }
267267
268 private class HostConfig {268 private class HostConfig {
269 static final String KEY_PREFIX = "host.config.";269 static final String KEY_PREFIX = "host.config.";
270 final int id;270 final int id;
271 final EditTextPreference title;271 final EditTextPreference title;
272 final EditTextPreference hostAddress;272 final EditTextPreference hostAddress;
273 final EditTextPreference hostPort;273 final EditTextPreference hostPort;
274 final CheckBoxPreference useSsl;274 final CheckBoxPreference useSsl;
275 final EditTextPreference userid;275 final EditTextPreference userid;
276 final EditTextPreference password;276 final EditTextPreference password;
277 final Preference remove;277 final Preference remove;
278 final Preference activate;278 final Preference activate;
279279
280 HostConfig(String sTitle, int id) {280 HostConfig(String sTitle, int id) {
281 this.id = id;281 this.id = id;
282 title = new EditTextPreference(ConnectionPreferenceActivity.this);282 title = new EditTextPreference(ConnectionPreferenceActivity.this);
283 title.setSummary(getString(R.string.url));283 title.setSummary(getString(R.string.url));
284 title.getEditText().setHint(getString(R.string.url));284 title.getEditText().setHint(getString(R.string.url));
285 title.setTitle(getString(R.string.connection_profile_title));285 title.setTitle(getString(R.string.connection_profile_title));
286 title.setKey(KEY_PREFIX + id + ".title");286 title.setKey(KEY_PREFIX + id + ".title");
287 title.setDefaultValue(getString(R.string.url));287 title.setDefaultValue(getString(R.string.url));
288 title.setSummary(sTitle);288 title.setSummary(sTitle);
289 title.setDialogTitle(getString(R.string.connection_profile_title));289 title.setDialogTitle(getString(R.string.connection_profile_title));
290 title.setOnPreferenceChangeListener(onPreferenceChangeListener);290 title.setOnPreferenceChangeListener(onPreferenceChangeListener);
291291
292 hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);292 hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
293 hostAddress.setTitle(getString(R.string.urlHint));293 hostAddress.setTitle(getString(R.string.urlHint));
294 hostAddress.setKey(KEY_PREFIX + id + ".address");294 hostAddress.setKey(KEY_PREFIX + id + ".address");
295 hostAddress.getEditText().setHint(R.string.urlHint);295 hostAddress.getEditText().setHint(R.string.urlHint);
296 hostAddress.setSummary(getString(R.string.urlHint));296 hostAddress.setSummary(getString(R.string.urlHint));
297 hostAddress.setDialogTitle(getString(R.string.urlHint));297 hostAddress.setDialogTitle(getString(R.string.urlHint));
298 hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);298 hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
299 hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);299 hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
300300
301 hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);301 hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
302 hostPort.setTitle(getString(R.string.port));302 hostPort.setTitle(getString(R.string.port));
303 hostPort.setKey(KEY_PREFIX + id + ".port");303 hostPort.setKey(KEY_PREFIX + id + ".port");
304 hostPort.setSummary(getString(R.string.port));304 hostPort.setSummary(getString(R.string.port));
305 hostPort.setDialogTitle(getString(R.string.port));305 hostPort.setDialogTitle(getString(R.string.port));
306 hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);306 hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
307 hostPort.setDefaultValue(getString(R.string.portDefaultValue));307 hostPort.setDefaultValue(getString(R.string.portDefaultValue));
308 hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);308 hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
309309
310 useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);310 useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);
311 useSsl.setTitle(getString(R.string.connection_profile_ssl_use));311 useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
312 useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));312 useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
313 useSsl.setKey(KEY_PREFIX + id + ".usessl");313 useSsl.setKey(KEY_PREFIX + id + ".usessl");
314314
315 userid = new EditTextPreference(ConnectionPreferenceActivity.this);315 userid = new EditTextPreference(ConnectionPreferenceActivity.this);
316 userid.setSummary(getString(R.string.connection_userid));316 userid.setSummary(getString(R.string.connection_userid));
@@ -332,92 +332,92 @@
332 password.setDialogTitle(getString(R.string.connection_password));332 password.setDialogTitle(getString(R.string.connection_password));
333 password.setOnPreferenceChangeListener(onPreferenceChangeListener);333 password.setOnPreferenceChangeListener(onPreferenceChangeListener);
334334
335 remove = new Preference(ConnectionPreferenceActivity.this);335 remove = new Preference(ConnectionPreferenceActivity.this);
336 remove.setTitle(getString(R.string.connection_profile_remove));336 remove.setTitle(getString(R.string.connection_profile_remove));
337 remove.setSummary(getString(R.string.connection_profile_remove_summary));337 remove.setSummary(getString(R.string.connection_profile_remove_summary));
338 remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {338 remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
339 @Override339 @Override
340 public boolean onPreferenceClick(Preference preference) {340 public boolean onPreferenceClick(Preference preference) {
341 SharedPreferences prefs = getPreferenceManager().getSharedPreferences();341 SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
342 SharedPreferences.Editor editor = prefs.edit();342 SharedPreferences.Editor editor = prefs.edit();
343 editor.remove(hostAddress.getKey());343 editor.remove(hostAddress.getKey());
344 editor.remove(hostPort.getKey());344 editor.remove(hostPort.getKey());
345 editor.remove(title.getKey());345 editor.remove(title.getKey());
346 editor.remove(useSsl.getKey());346 editor.remove(useSsl.getKey());
347 editor.remove(userid.getKey());347 editor.remove(userid.getKey());
348 editor.remove(password.getKey());348 editor.remove(password.getKey());
349 editor.commit();349 editor.commit();
350 ConnectionPreferenceActivity.this.onBackPressed();350 ConnectionPreferenceActivity.this.onBackPressed();
351 return false;351 return false;
352 }352 }
353 });353 });
354354
355 activate = new Preference(ConnectionPreferenceActivity.this);355 activate = new Preference(ConnectionPreferenceActivity.this);
356 activate.setTitle(getString(R.string.connection_profile_activate));356 activate.setTitle(getString(R.string.connection_profile_activate));
357 activate.setSummary(getString(R.string.connection_profile_summary_activate));357 activate.setSummary(getString(R.string.connection_profile_summary_activate));
358 activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {358 activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
359 @Override359 @Override
360 public boolean onPreferenceClick(Preference preference) {360 public boolean onPreferenceClick(Preference preference) {
361 SharedPreferences preferences = getPreferenceManager().getSharedPreferences();361 SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
362 SharedPreferences.Editor editor = preferences.edit();362 SharedPreferences.Editor editor = preferences.edit();
363 String host = preferences.getString(hostAddress.getKey(),363 String host = preferences.getString(hostAddress.getKey(),
364 getString(R.string.hostDefaultValue));364 getString(R.string.hostDefaultValue));
365 editor.putString(getString(R.string.keyHost), host);365 editor.putString(getString(R.string.keyHost), host);
366 String port = preferences.getString(hostPort.getKey(),366 String port = preferences.getString(hostPort.getKey(),
367 getString(R.string.portDefaultValue));367 getString(R.string.portDefaultValue));
368 editor.putString(getString(R.string.keyPort), port);368 editor.putString(getString(R.string.keyPort), port);
369 Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);369 Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
370 editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);370 editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
371 String suserid = preferences.getString(userid.getKey(), getString(R.string.useridDefaultValue));371 String suserid = preferences.getString(userid.getKey(), getString(R.string.useridDefaultValue));
372 editor.putString(getString(R.string.key_userid), suserid);372 editor.putString(getString(R.string.key_userid), suserid);
373 String spassword = preferences.getString(password.getKey(),373 String spassword = preferences.getString(password.getKey(),
374 getString(R.string.passwordDefaultValue));374 getString(R.string.passwordDefaultValue));
375 editor.putString(getString(R.string.key_password), spassword);375 editor.putString(getString(R.string.key_password), spassword);
376376
377 editor.putString(377 editor.putString(
378 getString(R.string.key_profile_selected_title),378 getString(R.string.key_profile_selected_title),
379 preferences.getString(379 preferences.getString(
380 title.getKey(),380 title.getKey(),
381 getString(R.string.url)));381 getString(R.string.url)));
382382
383 editor.commit();383 editor.commit();
384 Toast.makeText(ConnectionPreferenceActivity.this,384 Toast.makeText(ConnectionPreferenceActivity.this,
385 String.format(385 String.format(
386 "%s: %s\n[%s:%s] %s",386 "%s: %s\n[%s:%s] %s",
387 getString(R.string.connection_profile_active_toast),387 getString(R.string.connection_profile_active_toast),
388 HostConfig.this.title.getText(),388 HostConfig.this.title.getText(),
389 host,389 host,
390 port,390 port,
391 useSsl.isChecked() ? "(SSL)" : ""391 useSsl.isChecked() ? "(SSL)" : ""
392 ),392 ),
393 Toast.LENGTH_LONG).show();393 Toast.LENGTH_LONG).show();
394 return false;394 return false;
395 }395 }
396 });396 });
397 }397 }
398398
399 @Override399 @Override
400 public String toString() {400 public String toString() {
401 return "HostConfig{" +401 return "HostConfig{" +
402 "id=" + id +402 "id=" + id +
403 ", title='" + title + '\'' +403 ", title='" + title + '\'' +
404 ", hostAddress=" + hostAddress.getKey() +404 ", hostAddress=" + hostAddress.getKey() +
405 ", hostPort=" + hostPort.getKey() +405 ", hostPort=" + hostPort.getKey() +
406 '}';406 '}';
407 }407 }
408408
409 Preference.OnPreferenceChangeListener onPreferenceChangeListener =409 Preference.OnPreferenceChangeListener onPreferenceChangeListener =
410 new Preference.OnPreferenceChangeListener() {410 new Preference.OnPreferenceChangeListener() {
411 @Override411 @Override
412 public boolean onPreferenceChange(Preference preference, Object o) {412 public boolean onPreferenceChange(Preference preference, Object o) {
413 preference.setSummary("" + o);413 preference.setSummary("" + o);
414 if (preference.getKey().endsWith(".title")) {414 if (preference.getKey().endsWith(".title")) {
415 preferenceScreen415 preferenceScreen
416 .findPreference("key.preference.category")416 .findPreference("key.preference.category")
417 .setTitle("" + o);417 .setTitle("" + o);
418 }418 }
419 return true;419 return true;
420 }420 }
421 };421 };
422 }422 }
423}423}
424424
=== modified file 'src/org/openlp/android/activity/preference/Preferences.java'
--- src/org/openlp/android/activity/preference/Preferences.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/activity/preference/Preferences.java 2013-06-04 19:32:29 +0000
@@ -50,99 +50,100 @@
50 buildPreferences();50 buildPreferences();
51 }51 }
5252
53 private void buildPreferences() {53 private void buildPreferences() {
54 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();54 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
5555
56 getPreferenceManager()56 getPreferenceManager()
57 .setSharedPreferencesName(getString(R.string.keySharedPreferences));57 .setSharedPreferencesName(getString(R.string.keySharedPreferences));
5858
59 addPreferencesFromResource(R.xml.preferences);59 addPreferencesFromResource(R.xml.preferences);
60 final SharedPreferences sharedPreferences = getPreferenceManager()60 final SharedPreferences sharedPreferences = getPreferenceManager()
61 .getSharedPreferences();61 .getSharedPreferences();
6262
63 StringBuilder stringBuilder = new StringBuilder();63 StringBuilder stringBuilder = new StringBuilder();
64 stringBuilder.append(sharedPreferences.getString(64 stringBuilder.append(sharedPreferences.getString(
65 getString(R.string.keyHost),65 getString(R.string.keyHost),
66 getString(R.string.notSet)));66 getString(R.string.notSet)));
67 stringBuilder.append(":");67 stringBuilder.append(":");
6868
69 Boolean useSsl = sharedPreferences.getBoolean(69 Boolean useSsl = sharedPreferences.getBoolean(
70 getString(R.string.key_ssl_use), false);70 getString(R.string.key_ssl_use), false);
71 stringBuilder.append(71 stringBuilder.append(
72 String.format("%s %s",72 String.format("%s %s",
73 sharedPreferences.getString(73 sharedPreferences.getString(
74 getString(R.string.keyPort),74 getString(R.string.keyPort),
75 getString(R.string.notSet)), useSsl ? "(SSL)" : ""));75 getString(R.string.notSet)), useSsl ? "(SSL)" : ""));
7676
77 final Preference hostPreference = findPreference(getString(R.string.keyHost));77 final Preference hostPreference = findPreference(getString(R.string.keyHost));
78 hostPreference.setTitle(78 hostPreference.setTitle(
79 getPreferenceManager().getSharedPreferences()79 getPreferenceManager().getSharedPreferences()
80 .getString(80 .getString(
81 getString(R.string.key_profile_selected_title),81 getString(R.string.key_profile_selected_title),
82 getString(R.string.url)82 getString(R.string.url)
83 )83 )
84 );84 );
85 hostPreference.setSummary(stringBuilder.toString());85 hostPreference.setSummary(stringBuilder.toString());
8686
87 PackageManager manager = this.getPackageManager();87 PackageManager manager = this.getPackageManager();
88 String version = "";88 String version = "";
89 try {89 try {
90 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);90 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
91 version = info.versionName;91 version = info.versionName;
92 } catch (PackageManager.NameNotFoundException ignored) {}92 } catch (PackageManager.NameNotFoundException ignored) {
9393 }
94 String date = new SimpleDateFormat("yyyy").format(new Date());94
9595 String date = new SimpleDateFormat("yyyy").format(new Date());
96 //Preferences time! (we build the preferences)96
97 Preference about = getPreference(getString(R.string.about_text), version, null);97 //Preferences time! (we build the preferences)
98 about.setSelectable(false);98 Preference about = getPreference(getString(R.string.about_text), version, null);
99 Preference openlpLink = getPreference(99 about.setSelectable(false);
100 getString(R.string.about_display_3),100 Preference openlpLink = getPreference(
101 getString(R.string.about_display_1),101 getString(R.string.about_display_3),
102 new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));102 getString(R.string.about_display_1),
103103 new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));
104 StringBuilder html = new StringBuilder();104
105 html.append(getString(R.string.about_display_4));105 StringBuilder html = new StringBuilder();
106 html.append(" © 2004-").append(date).append(" Raoul Snyman\n");106 html.append(getString(R.string.about_display_4));
107 html.append(getString(R.string.about_display_5));107 html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
108 html.append(" © 2004-").append(date);108 html.append(getString(R.string.about_display_5));
109 html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");109 html.append(" © 2004-").append(date);
110110 html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
111 Preference copyright = getPreference(111
112 getString(R.string.about_display_4),112 Preference copyright = getPreference(
113 html.toString(), null);113 getString(R.string.about_display_4),
114 copyright.setSelectable(false);114 html.toString(), null);
115115 copyright.setSelectable(false);
116 DialogPreference license = new MyDialogPreference(116
117 this,117 DialogPreference license = new MyDialogPreference(
118 getString(R.string.about_display_6),118 this,
119 String.format(119 getString(R.string.about_display_6),
120 "%s\n%s",120 String.format(
121 getString(R.string.about_display_7),121 "%s\n%s",
122 getString(R.string.about_display_8)122 getString(R.string.about_display_7),
123 )123 getString(R.string.about_display_8)
124 );124 )
125125 );
126126
127 PreferenceScreen preferenceScreen = getPreferenceScreen();127
128 addPreferenceCategory(preferenceScreen,getString(R.string.about),128 PreferenceScreen preferenceScreen = getPreferenceScreen();
129 about, openlpLink, copyright, license);129 addPreferenceCategory(preferenceScreen, getString(R.string.about),
130130 about, openlpLink, copyright, license);
131 Preference preference = findPreference(getString(R.string.keyHost));131
132 preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));132 Preference preference = findPreference(getString(R.string.keyHost));
133 }133 preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
134 }
134135
135 private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,136 private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,
136 String titleCategory, Preference... preferences) {137 String titleCategory, Preference... preferences) {
137138
138 boolean addPreference = false;139 boolean addPreference = false;
139140
140 for (Preference preference : preferences) {141 for (Preference preference : preferences) {
141 if (preference != null)142 if (preference != null)
142 addPreference = true;143 addPreference = true;
143 }144 }
144145
145 if (addPreference) {146 if (addPreference) {
146 PreferenceCategory preferenceCategory = new PreferenceCategory(this);147 PreferenceCategory preferenceCategory = new PreferenceCategory(this);
147 preferenceCategory.setTitle(titleCategory);148 preferenceCategory.setTitle(titleCategory);
148 preferenceScreen.addPreference(preferenceCategory);149 preferenceScreen.addPreference(preferenceCategory);
@@ -178,12 +179,12 @@
178 Log.d(LOG_TAG, "Destroying preferences");179 Log.d(LOG_TAG, "Destroying preferences");
179 }180 }
180181
181 @Override182 @Override
182 protected void onResume() {183 protected void onResume() {
183 super.onResume();184 super.onResume();
184 Log.i(LOG_TAG, "Resuming Preferences...");185 Log.i(LOG_TAG, "Resuming Preferences...");
185 buildPreferences();186 buildPreferences();
186 }187 }
187188
188 private final String LOG_TAG = Preferences.class.getName();189 private final String LOG_TAG = Preferences.class.getName();
189}190}
190191
=== modified file 'src/org/openlp/android/api/Api.java'
--- src/org/openlp/android/api/Api.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/api/Api.java 2013-06-04 19:32:29 +0000
@@ -91,32 +91,40 @@
9191
92public interface Api {92public interface Api {
9393
94 public final String LIVE_BASE = "/api/controller/live/";94 public final String LIVE_BASE = "/api/controller/live/";
95 public final String LIVE_NEXT = "/api/controller/live/next";95 public final String LIVE_NEXT = "/api/controller/live/next";
96 public final String LIVE_PREVIOUS = "/api/controller/live/previous";96 public final String LIVE_PREVIOUS = "/api/controller/live/previous";
97 public final String LIVE_TEXT = "/api/controller/live/text";97 public final String LIVE_TEXT = "/api/controller/live/text";
98 public final String LIVE_SET = "/api/controller/live/set?data=";98 public final String LIVE_SET = "/api/controller/live/set?data=";
9999
100 /** Use with {@link #SERVICE_BASE} + (previous|next) */100 /**
101 public final String SERVICE_BASE = "/api/service/";101 * Use with {@link #SERVICE_BASE} + (previous|next)
102 // todo: cleanup, use {@link #SERVICE_BASE}102 */
103 public final String SERVICE_LIST = "/api/service/list";103 public final String SERVICE_BASE = "/api/service/";
104 public final String SERVICE_SET = "/api/service/set?data=";104 // todo: cleanup, use {@link #SERVICE_BASE}
105105 public final String SERVICE_LIST = "/api/service/list";
106 /** Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show) */106 public final String SERVICE_SET = "/api/service/set?data=";
107 public final String DISPLAY_BASE = "/api/display/";107
108 public final String POLL_STATUS = "/api/poll";108 /**
109109 * Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show)
110 public final String ALERT = "/api/alert?data=";110 */
111111 public final String DISPLAY_BASE = "/api/display/";
112 public final String SEARCHABLE_PLUGINS = "/api/plugin/search";112 public final String POLL_STATUS = "/api/poll";
113 /**113
114 * This is a special string that uses the String.format() method. See114 public final String ALERT = "/api/alert?data=";
115 * {@link String#format(String, Object...)}115
116 */116 public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
117 public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";117 /**
118 /** Match intent extra key with regex since multiple plugins can be inserted */118 * This is a special string that uses the String.format() method. See
119 public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";119 * {@link String#format(String, Object...)}
120 /** Match intent extra key with regex since multiple plugins can be inserted */120 */
121 public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";121 public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
122 /**
123 * Match intent extra key with regex since multiple plugins can be inserted
124 */
125 public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
126 /**
127 * Match intent extra key with regex since multiple plugins can be inserted
128 */
129 public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
122}130}
123131
=== modified file 'src/org/openlp/android/data/Poll.java'
--- src/org/openlp/android/data/Poll.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/data/Poll.java 2013-06-04 19:32:29 +0000
@@ -23,99 +23,99 @@
2323
24public class Poll {24public class Poll {
2525
26 private int slide;26 private int slide;
27 private String item;27 private String item;
28 private int service = -1;28 private int service = -1;
29 private boolean twelveHourDisplay = false;29 private boolean twelveHourDisplay = false;
30 private boolean blankedDisplayed = false;30 private boolean blankedDisplayed = false;
31 private boolean themeDisplayed = false;31 private boolean themeDisplayed = false;
32 private boolean desktopDisplayed = false;32 private boolean desktopDisplayed = false;
33 private boolean displayHidden = false;33 private boolean displayHidden = false;
3434
35 public int getSlide() {35 public int getSlide() {
36 return slide;36 return slide;
37 }37 }
3838
39 public void setSlide(int slide) {39 public void setSlide(int slide) {
40 this.slide = slide;40 this.slide = slide;
41 }41 }
4242
43 public String getItem() {43 public String getItem() {
44 return item;44 return item;
45 }45 }
4646
47 public void setItem(String item) {47 public void setItem(String item) {
48 this.item = item;48 this.item = item;
49 }49 }
5050
51 public boolean isTwelveHourDisplay() {51 public boolean isTwelveHourDisplay() {
52 return twelveHourDisplay;52 return twelveHourDisplay;
53 }53 }
5454
55 public void setTwelveHourDisplay(boolean twelveHourDisplay) {55 public void setTwelveHourDisplay(boolean twelveHourDisplay) {
56 this.twelveHourDisplay = twelveHourDisplay;56 this.twelveHourDisplay = twelveHourDisplay;
57 }57 }
5858
59 public boolean isBlankedDisplayed() {59 public boolean isBlankedDisplayed() {
60 return blankedDisplayed;60 return blankedDisplayed;
61 }61 }
6262
63 public void setBlankedDisplayed(boolean blankedDisplayed) {63 public void setBlankedDisplayed(boolean blankedDisplayed) {
64 this.blankedDisplayed = blankedDisplayed;64 this.blankedDisplayed = blankedDisplayed;
65 if (blankedDisplayed) {65 if (blankedDisplayed) {
66 this.displayHidden = true;66 this.displayHidden = true;
67 }67 }
68 }68 }
6969
70 public boolean isThemeDisplayed() {70 public boolean isThemeDisplayed() {
71 return themeDisplayed;71 return themeDisplayed;
72 }72 }
7373
74 public void setThemeDisplayed(boolean themeDisplayed) {74 public void setThemeDisplayed(boolean themeDisplayed) {
75 this.themeDisplayed = themeDisplayed;75 this.themeDisplayed = themeDisplayed;
76 if (themeDisplayed) {76 if (themeDisplayed) {
77 this.displayHidden = true;77 this.displayHidden = true;
78 }78 }
79 }79 }
8080
81 public boolean isDesktopDisplayed() {81 public boolean isDesktopDisplayed() {
82 return desktopDisplayed;82 return desktopDisplayed;
83 }83 }
8484
85 public void setDesktopDisplayed(boolean desktopDisplayed) {85 public void setDesktopDisplayed(boolean desktopDisplayed) {
86 this.desktopDisplayed = desktopDisplayed;86 this.desktopDisplayed = desktopDisplayed;
87 if (desktopDisplayed) {87 if (desktopDisplayed) {
88 this.displayHidden = true;88 this.displayHidden = true;
89 }89 }
90 }90 }
9191
92 public boolean isDisplayHidden() {92 public boolean isDisplayHidden() {
93 return displayHidden;93 return displayHidden;
94 }94 }
9595
96 public void setDisplayHidden(boolean displayHidden) {96 public void setDisplayHidden(boolean displayHidden) {
97 this.displayHidden = displayHidden;97 this.displayHidden = displayHidden;
98 }98 }
9999
100 public int getService() {100 public int getService() {
101 return service;101 return service;
102 }102 }
103103
104 public void setService(int service) {104 public void setService(int service) {
105 this.service = service;105 this.service = service;
106 }106 }
107107
108 @Override108 @Override
109 public String toString() {109 public String toString() {
110 return "Poll{" +110 return "Poll{" +
111 "slide=" + slide +111 "slide=" + slide +
112 ", item='" + item + '\'' +112 ", item='" + item + '\'' +
113 ", service=" + service +113 ", service=" + service +
114 ", twelveHourDisplay=" + twelveHourDisplay +114 ", twelveHourDisplay=" + twelveHourDisplay +
115 ", blankedDisplayed=" + blankedDisplayed +115 ", blankedDisplayed=" + blankedDisplayed +
116 ", themeDisplayed=" + themeDisplayed +116 ", themeDisplayed=" + themeDisplayed +
117 ", desktopDisplayed=" + desktopDisplayed +117 ", desktopDisplayed=" + desktopDisplayed +
118 ", displayHidden=" + displayHidden +118 ", displayHidden=" + displayHidden +
119 '}';119 '}';
120 }120 }
121}121}
122122
=== modified file 'src/org/openlp/android/data/SlideItem.java'
--- src/org/openlp/android/data/SlideItem.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/data/SlideItem.java 2013-06-04 19:32:29 +0000
@@ -21,46 +21,46 @@
21package org.openlp.android.data;21package org.openlp.android.data;
2222
23public class SlideItem {23public class SlideItem {
24 private String text;24 private String text;
25 private boolean selected;25 private boolean selected;
26 private String tag;26 private String tag;
27 private String html;27 private String html;
2828
29 public String getText() {29 public String getText() {
30 return text;30 return text;
31 }31 }
3232
33 public void setText(String text) {33 public void setText(String text) {
34 this.text = text;34 this.text = text;
35 }35 }
3636
37 public boolean isSelected() {37 public boolean isSelected() {
38 return selected;38 return selected;
39 }39 }
4040
41 public void setSelected(boolean selected) {41 public void setSelected(boolean selected) {
42 this.selected = selected;42 this.selected = selected;
43 }43 }
4444
45 public String getTag() {45 public String getTag() {
46 return tag;46 return tag;
47 }47 }
4848
49 public void setTag(String tag) {49 public void setTag(String tag) {
50 this.tag = tag;50 this.tag = tag;
51 }51 }
5252
53 public String getHtml() {53 public String getHtml() {
54 return html;54 return html;
55 }55 }
5656
57 public void setHtml(String html) {57 public void setHtml(String html) {
58 this.html = html;58 this.html = html;
59 }59 }
6060
61 @Override61 @Override
62 public String toString() {62 public String toString() {
63 return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected63 return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected
64 + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';64 + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';
65 }65 }
66}66}
6767
=== modified file 'src/org/openlp/android/service/PingIntent.java'
--- src/org/openlp/android/service/PingIntent.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/service/PingIntent.java 2013-06-04 19:32:29 +0000
@@ -32,60 +32,60 @@
3232
33public class PingIntent extends Service {33public class PingIntent extends Service {
3434
35 private Handler handler = new Handler();35 private Handler handler = new Handler();
36 private Integer delay;36 private Integer delay;
3737
38 public PingIntent() {38 public PingIntent() {
39 super();39 super();
40 Log.v(LOG_TAG, "Instantiating PingIntent...");40 Log.v(LOG_TAG, "Instantiating PingIntent...");
4141
42 }42 }
4343
44 @Override44 @Override
45 public IBinder onBind(Intent intent) {45 public IBinder onBind(Intent intent) {
46 return null;46 return null;
47 }47 }
4848
49 @Override49 @Override
50 public void onStart(Intent intent, int startId) {50 public void onStart(Intent intent, int startId) {
51 String PREFERENCES_KEY =51 String PREFERENCES_KEY =
52 getApplicationContext().getString(R.string.keySharedPreferences);52 getApplicationContext().getString(R.string.keySharedPreferences);
53 SharedPreferences preferences = getApplicationContext()53 SharedPreferences preferences = getApplicationContext()
54 .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);54 .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);
55 Resources resources = getApplicationContext().getResources();55 Resources resources = getApplicationContext().getResources();
56 delay = Integer.valueOf(56 delay = Integer.valueOf(
57 resources.getString(R.string.backgroundRefreshDefaultValue));57 resources.getString(R.string.backgroundRefreshDefaultValue));
58 Log.v(LOG_TAG, "Starting PingIntent...");58 Log.v(LOG_TAG, "Starting PingIntent...");
59 super.onStart(intent, startId);59 super.onStart(intent, startId);
60 delay = Integer.parseInt(preferences60 delay = Integer.parseInt(preferences
61 .getString(resources.getString(R.string.keyBackgroundService),61 .getString(resources.getString(R.string.keyBackgroundService),
62 delay.toString()));62 delay.toString()));
6363
64 Log.d(LOG_TAG, "PingIntent delay: " + delay);64 Log.d(LOG_TAG, "PingIntent delay: " + delay);
65 handler.removeCallbacks(r);65 handler.removeCallbacks(r);
66 handler.postDelayed(r, delay);66 handler.postDelayed(r, delay);
67 }67 }
6868
69 Runnable r = new Runnable() {69 Runnable r = new Runnable() {
7070
71 @Override71 @Override
72 public void run() {72 public void run() {
73 Intent apiCallPingIntent =73 Intent apiCallPingIntent =
74 new Intent(getApplicationContext(), ApiCallIntent.class);74 new Intent(getApplicationContext(), ApiCallIntent.class);
75 apiCallPingIntent.putExtra(Api.POLL_STATUS, "");75 apiCallPingIntent.putExtra(Api.POLL_STATUS, "");
76 startService(apiCallPingIntent);76 startService(apiCallPingIntent);
77 if (delay > 0) {77 if (delay > 0) {
78 handler.postDelayed(r, delay);78 handler.postDelayed(r, delay);
79 }
79 }80 }
80 }81 };
81 };82
8283 @Override
83 @Override84 public void onDestroy() {
84 public void onDestroy() {85 Log.v(LOG_TAG, "Stopping PingIntent...");
85 Log.v(LOG_TAG, "Stopping PingIntent...");86 handler.removeCallbacks(r);
86 handler.removeCallbacks(r);87 super.onDestroy();
87 super.onDestroy();88 }
88 }89
8990 private static final String LOG_TAG = PingIntent.class.getName();
90 private static final String LOG_TAG = PingIntent.class.getName();
91}91}
9292
=== modified file 'src/org/openlp/android/utility/GroupExpandableListAdapter.java'
--- src/org/openlp/android/utility/GroupExpandableListAdapter.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/GroupExpandableListAdapter.java 2013-06-04 19:32:29 +0000
@@ -34,92 +34,91 @@
34import java.util.Map;34import java.util.Map;
3535
36public class GroupExpandableListAdapter extends BaseExpandableListAdapter {36public class GroupExpandableListAdapter extends BaseExpandableListAdapter {
37 List<String> groups;37 List<String> groups;
38 List<List<Map<String, JSONArray>>> children;38 List<List<Map<String, JSONArray>>> children;
39 LayoutInflater inflater;39 LayoutInflater inflater;
40 Activity context;40 Activity context;
4141
42 public GroupExpandableListAdapter(Activity context, List<String> groups,42 public GroupExpandableListAdapter(Activity context, List<String> groups,
43 List<List<Map<String, JSONArray>>> children) {43 List<List<Map<String, JSONArray>>> children) {
44 this.context = context;44 this.context = context;
45 this.groups = groups;45 this.groups = groups;
46 this.children = children;46 this.children = children;
47 inflater = context.getLayoutInflater();47 inflater = context.getLayoutInflater();
48 }48 }
4949
50 @Override50 @Override
51 public int getGroupCount() {51 public int getGroupCount() {
52 return groups.size();52 return groups.size();
53 }53 }
5454
55 @Override55 @Override
56 public int getChildrenCount(int position) {56 public int getChildrenCount(int position) {
57 return children.get(position).size();57 return children.get(position).size();
58 }58 }
5959
60 @Override60 @Override
61 public Object getGroup(int position) {61 public Object getGroup(int position) {
62 return groups.get(position);62 return groups.get(position);
63 }63 }
6464
65 @Override65 @Override
66 public Object getChild(int rootPosition, int childPosition) {66 public Object getChild(int rootPosition, int childPosition) {
67 return children.get(rootPosition).get(childPosition);67 return children.get(rootPosition).get(childPosition);
68 }68 }
6969
70 @Override70 @Override
71 public long getGroupId(int position) {71 public long getGroupId(int position) {
72 return groups.indexOf(groups.get(position));72 return groups.indexOf(groups.get(position));
73 }73 }
7474
75 @Override75 @Override
76 public long getChildId(int i, int i1) {76 public long getChildId(int i, int i1) {
77 List<Map<String, JSONArray>> child = children.get(i);77 List<Map<String, JSONArray>> child = children.get(i);
78 return child.indexOf(child.get(i1));78 return child.indexOf(child.get(i1));
79 }79 }
8080
81 @Override81 @Override
82 public boolean hasStableIds() {82 public boolean hasStableIds() {
83 return false;83 return false;
84 }84 }
8585
86 @Override86 @Override
87 public View getGroupView(int position, boolean b, View view,87 public View getGroupView(int position, boolean b, View view,
88 ViewGroup viewGroup) {88 ViewGroup viewGroup) {
89 if (view == null) {89 if (view == null) {
90 view = inflater.inflate(R.layout.group_parent, null);90 view = inflater.inflate(R.layout.group_parent, null);
91 view.setClickable(false);91 view.setClickable(false);
92 }92 }
93 TextView textView = (TextView) view.findViewById(R.id.groupParentText);93 TextView textView = (TextView) view.findViewById(R.id.groupParentText);
94 TextView numberView = (TextView) view94 TextView numberView = (TextView) view
95 .findViewById(R.id.parentChildCount);95 .findViewById(R.id.parentChildCount);
96 numberView.setText(String.format("%s", children.get(position).size()));96 numberView.setText(String.format("%s", children.get(position).size()));
97 textView.setText(groups.get(position));97 textView.setText(groups.get(position));
98 return view;98 return view;
99 }99 }
100100
101 @Override101 @Override
102 public View getChildView(int groupPosition, int childPosition, boolean b,102 public View getChildView(int groupPosition, int childPosition, boolean b,
103 View view, ViewGroup viewGroup) {103 View view, ViewGroup viewGroup) {
104 if (view == null) {104 if (view == null) {
105 view = inflater.inflate(R.layout.group_child, null);105 view = inflater.inflate(R.layout.group_child, null);
106 view.setClickable(false);106 view.setClickable(false);
107 }107 }
108 TextView childView = (TextView) view.findViewById(R.id.groupChildText);108 TextView childView = (TextView) view.findViewById(R.id.groupChildText);
109 List<Map<String, JSONArray>> childItem = children.get(groupPosition);109 List<Map<String, JSONArray>> childItem = children.get(groupPosition);
110 Map<String, JSONArray> mapItem = childItem.get(childPosition);110 Map<String, JSONArray> mapItem = childItem.get(childPosition);
111 JSONArray jsonItem = mapItem.get(groups.get(groupPosition));111 JSONArray jsonItem = mapItem.get(groups.get(groupPosition));
112 try {112 try {
113 childView.setText(String.format("%s", jsonItem.get(1)));113 childView.setText(String.format("%s", jsonItem.get(1)));
114 }114 } catch (JSONException e) {
115 catch (JSONException e) {115 e.printStackTrace();
116 e.printStackTrace();116 }
117 }117 return view;
118 return view;118 }
119 }119
120120 @Override
121 @Override121 public boolean isChildSelectable(int i, int i1) {
122 public boolean isChildSelectable(int i, int i1) {122 return true;
123 return true;123 }
124 }
125}124}
126125
=== modified file 'src/org/openlp/android/utility/JSONHandler.java'
--- src/org/openlp/android/utility/JSONHandler.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/JSONHandler.java 2013-06-04 19:32:29 +0000
@@ -38,139 +38,132 @@
3838
39public class JSONHandler {39public class JSONHandler {
4040
41 public static String createRequestJSON(String key, String value)41 public static String createRequestJSON(String key, String value)
42 throws JSONHandlerException {42 throws JSONHandlerException {
43 try {43 try {
44 String responseJSON;44 String responseJSON;
45 JSONObject jo = new JSONObject();45 JSONObject jo = new JSONObject();
46 jo.put(key, value);46 jo.put(key, value);
47 responseJSON = new JSONStringer().object().key("request").value(jo)47 responseJSON = new JSONStringer().object().key("request").value(jo)
48 .endObject().toString();48 .endObject().toString();
49 responseJSON = URLEncoder.encode(responseJSON, "UTF-8");49 responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
50 return responseJSON;50 return responseJSON;
51 }51 } catch (JSONException e) {
52 catch (JSONException e) {52 throw new JSONHandlerException(e);
53 throw new JSONHandlerException(e);53 } catch (UnsupportedEncodingException e) {
54 }54 throw new JSONHandlerException(e);
55 catch (UnsupportedEncodingException e) {55 }
56 throw new JSONHandlerException(e);56 }
57 }57
58 }58 public static List<SlideItem> parseServiceItemResponseJSON(
5959 HttpEntity entity)
60 public static List<SlideItem> parseServiceItemResponseJSON(60 throws JSONHandlerException {
61 HttpEntity entity)61 try {
62 throws JSONHandlerException {62 List<SlideItem> serviceItemList;
63 try {63 InputStream inputStream = entity.getContent();
64 List<SlideItem> serviceItemList;64 String result = StringHelper.convertStreamToString(inputStream);
65 InputStream inputStream = entity.getContent();65 Log.v(LOG_TAG, result);
66 String result = StringHelper.convertStreamToString(inputStream);66 serviceItemList = getServiceItemsFromString(result);
67 Log.v(LOG_TAG, result);67 inputStream.close();
68 serviceItemList = getServiceItemsFromString(result);68 return serviceItemList;
69 inputStream.close();69 } catch (IOException e) {
70 return serviceItemList;70 throw new JSONHandlerException(e);
71 }71 }
72 catch (IOException e) {72 }
73 throw new JSONHandlerException(e);73
74 }74 public static List<SlideItem> getServiceItemsFromString(String itemsJson)
75 }75 throws JSONHandlerException {
7676 try {
77 public static List<SlideItem> getServiceItemsFromString(String itemsJson)77 List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
78 throws JSONHandlerException {78 JSONObject jObject = new JSONObject(itemsJson);
79 try {79 JSONObject results = jObject.getJSONObject("results");
80 List<SlideItem> serviceItemList = new ArrayList<SlideItem>();80 JSONArray items = results.getJSONArray("items");
81 JSONObject jObject = new JSONObject(itemsJson);81
82 JSONObject results = jObject.getJSONObject("results");82 for (int i = 0; i < items.length(); i++) {
83 JSONArray items = results.getJSONArray("items");83 JSONObject item = items.getJSONObject(i);
8484 SlideItem slide = new SlideItem();
85 for (int i = 0; i < items.length(); i++) {85 slide.setTag("");
86 JSONObject item = items.getJSONObject(i);86 slide.setText(item.getString("title"));
87 SlideItem slide = new SlideItem();87 slide.setSelected(item.getBoolean("selected"));
88 slide.setTag("");88 slide.setHtml("");
89 slide.setText(item.getString("title"));89 serviceItemList.add(slide);
90 slide.setSelected(item.getBoolean("selected"));90 }
91 slide.setHtml("");91 return serviceItemList;
92 serviceItemList.add(slide);92 } catch (JSONException e) {
93 }93 throw new JSONHandlerException(e);
94 return serviceItemList;94 }
95 }95 }
96 catch (JSONException e) {96
97 throw new JSONHandlerException(e);97 public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)
98 }98 throws JSONHandlerException {
99 }99 try {
100100 List<SlideItem> serviceItemList;
101 public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)101 InputStream inputStream = entity.getContent();
102 throws JSONHandlerException {102 String result = StringHelper.convertStreamToString(inputStream);
103 try {103 Log.v(LOG_TAG, result);
104 List<SlideItem> serviceItemList;104 serviceItemList = getSlideItemsFromString(result);
105 InputStream inputStream = entity.getContent();105 inputStream.close();
106 String result = StringHelper.convertStreamToString(inputStream);106 return serviceItemList;
107 Log.v(LOG_TAG, result);107 } catch (IOException e) {
108 serviceItemList = getSlideItemsFromString(result);108 throw new JSONHandlerException(e);
109 inputStream.close();109 }
110 return serviceItemList;110 }
111 }111
112 catch (IOException e) {112 public static List<SlideItem> getSlideItemsFromString(String itemJson)
113 throw new JSONHandlerException(e);113 throws JSONHandlerException {
114 }114 try {
115 }115 JSONObject jObject = new JSONObject(itemJson);
116116 JSONObject results = jObject.getJSONObject("results");
117 public static List<SlideItem> getSlideItemsFromString(String itemJson)117 JSONArray items = results.getJSONArray("slides");
118 throws JSONHandlerException {118
119 try {119 List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
120 JSONObject jObject = new JSONObject(itemJson);120 for (int i = 0; i < items.length(); i++) {
121 JSONObject results = jObject.getJSONObject("results");121 JSONObject item = items.getJSONObject(i);
122 JSONArray items = results.getJSONArray("slides");122 SlideItem slide = new SlideItem();
123123 slide.setText(item.getString("text"));
124 List<SlideItem> serviceItemList = new ArrayList<SlideItem>();124 slide.setTag(item.getString("tag"));
125 for (int i = 0; i < items.length(); i++) {125 slide.setSelected(item.getBoolean("selected"));
126 JSONObject item = items.getJSONObject(i);126 slide.setHtml(item.getString("html"));
127 SlideItem slide = new SlideItem();127 serviceItemList.add(slide);
128 slide.setText(item.getString("text"));128 }
129 slide.setTag(item.getString("tag"));129 return serviceItemList;
130 slide.setSelected(item.getBoolean("selected"));130 } catch (JSONException e) {
131 slide.setHtml(item.getString("html"));131 throw new JSONHandlerException(e);
132 serviceItemList.add(slide);132 }
133 }133 }
134 return serviceItemList;134
135 }135 public static Poll getPollFromString(String pollJson)
136 catch (JSONException e) {136 throws JSONHandlerException {
137 throw new JSONHandlerException(e);137 Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));
138 }138 try {
139 }139 JSONObject jObject = new JSONObject(pollJson);
140140 JSONObject results = jObject.getJSONObject("results");
141 public static Poll getPollFromString(String pollJson)141 Poll poll = new Poll();
142 throws JSONHandlerException {142 poll.setSlide(results.getInt("slide"));
143 Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));143 poll.setItem(results.getString("item"));
144 try {144 poll.setTwelveHourDisplay(results.getBoolean("twelve"));
145 JSONObject jObject = new JSONObject(pollJson);145 poll.setBlankedDisplayed(results.getBoolean("blank"));
146 JSONObject results = jObject.getJSONObject("results");146 poll.setThemeDisplayed(results.getBoolean("theme"));
147 Poll poll = new Poll();147 poll.setDesktopDisplayed(results.getBoolean("display"));
148 poll.setSlide(results.getInt("slide"));148 if (!results.has("service")) {
149 poll.setItem(results.getString("item"));149 Log.w(LOG_TAG,
150 poll.setTwelveHourDisplay(results.getBoolean("twelve"));150 "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");
151 poll.setBlankedDisplayed(results.getBoolean("blank"));151 }
152 poll.setThemeDisplayed(results.getBoolean("theme"));152 poll.setService(
153 poll.setDesktopDisplayed(results.getBoolean("display"));153 results.has("service") ? results.getInt("service") : -1);
154 if (!results.has("service")) {154 return poll;
155 Log.w(LOG_TAG,155 } catch (JSONException e) {
156 "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");156 throw new JSONHandlerException(e);
157 }157 }
158 poll.setService(158 }
159 results.has("service") ? results.getInt("service") : -1);159
160 return poll;160 public static class JSONHandlerException extends Exception {
161 }161 private static final long serialVersionUID = -6772307308404816615L;
162 catch (JSONException e) {162
163 throw new JSONHandlerException(e);163 public JSONHandlerException(Throwable throwable) {
164 }164 super(throwable);
165 }165 }
166166 }
167 public static class JSONHandlerException extends Exception {167
168 private static final long serialVersionUID = -6772307308404816615L;168 private static String LOG_TAG = JSONHandler.class.getName();
169
170 public JSONHandlerException(Throwable throwable) {
171 super(throwable);
172 }
173 }
174
175 private static String LOG_TAG = JSONHandler.class.getName();
176}169}
177170
=== modified file 'src/org/openlp/android/utility/OpenLPController.java'
--- src/org/openlp/android/utility/OpenLPController.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/OpenLPController.java 2013-06-04 19:32:29 +0000
@@ -56,579 +56,560 @@
5656
57public class OpenLPController extends PagerAdapter {57public class OpenLPController extends PagerAdapter {
5858
59 private static Activity context;59 private static Activity context;
60 private ListView listViewService;60 private ListView listViewService;
61 private ListView listViewLive;61 private ListView listViewLive;
62 private int currentService = -1;62 private int currentService = -1;
63 private int currentLive = -1;63 private int currentLive = -1;
64 private String itemId = "";64 private String itemId = "";
6565
66 private static int currentPage = 0;66 private static int currentPage = 0;
6767
68 public static final String PAGE_KEY = "openlp.pageKey";68 public static final String PAGE_KEY = "openlp.pageKey";
69 public static final int PAGE_SERVICE = 0;69 public static final int PAGE_SERVICE = 0;
70 public static final int PAGE_LIVE = 1;70 public static final int PAGE_LIVE = 1;
71 public static final int PAGE_DISPLAY = 2;71 public static final int PAGE_DISPLAY = 2;
72 public static final int PAGE_STAGE = 3;72 public static final int PAGE_STAGE = 3;
73 public static final int PAGE_ALERT = 4;73 public static final int PAGE_ALERT = 4;
74 public static final int PAGE_SEARCH = 5;74 public static final int PAGE_SEARCH = 5;
7575
76 private String displayType;76 private String displayType;
77 private WebView webView;77 private WebView webView;
78 private SharedPreferences preferences;78 private SharedPreferences preferences;
7979
80 public Intent pingIntent;80 public Intent pingIntent;
81 public Intent apiCallIntent;81 public Intent apiCallIntent;
8282
83 public OpenLPController(Activity context) {83 public OpenLPController(Activity context) {
84 OpenLPController.context = context;84 OpenLPController.context = context;
85 preferences = context.getApplicationContext().getSharedPreferences(85 preferences = context.getApplicationContext().getSharedPreferences(
86 context.getString(R.string.keySharedPreferences),86 context.getString(R.string.keySharedPreferences),
87 Context.MODE_PRIVATE);87 Context.MODE_PRIVATE);
88 pingIntent = new Intent(context, PingIntent.class);88 pingIntent = new Intent(context, PingIntent.class);
89 apiCallIntent = new Intent(context, ApiCallIntent.class);89 apiCallIntent = new Intent(context, ApiCallIntent.class);
9090
91 IntentFilter apiCallFilter =91 IntentFilter apiCallFilter =
92 new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);92 new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);
93 apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);93 apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
94 context.registerReceiver(apiCallReceiver, apiCallFilter);94 context.registerReceiver(apiCallReceiver, apiCallFilter);
95 }95 }
9696
97 public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {97 public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
98 @Override98 @Override
99 public void onReceive(Context broadcastedContext, Intent intent) {99 public void onReceive(Context broadcastedContext, Intent intent) {
100 Log.v(LOG_TAG, String100 Log.v(LOG_TAG, String
101 .format("%s broadcast received: intent(%s), context(%s)",101 .format("%s broadcast received: intent(%s), context(%s)",
102 ApiCallIntent.API_CALL_RECEIVE, intent,102 ApiCallIntent.API_CALL_RECEIVE, intent,
103 broadcastedContext));103 broadcastedContext));
104 if (intent.hasExtra("error")) {104 if (intent.hasExtra("error")) {
105 context.stopService(pingIntent);105 context.stopService(pingIntent);
106 Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +106 Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +
107 intent.getStringExtra("error"));107 intent.getStringExtra("error"));
108 Toast.makeText(broadcastedContext, String108 Toast.makeText(broadcastedContext, String
109 .format("%s: %s", context.getString(R.string.requestFailed),109 .format("%s: %s", context.getString(R.string.requestFailed),
110 intent.getStringExtra("error")), Toast.LENGTH_LONG)110 intent.getStringExtra("error")), Toast.LENGTH_LONG)
111 .show();111 .show();
112 }112 } else {
113 else {113 if (intent.hasExtra("apiBase")) {
114 if (intent.hasExtra("apiBase")) {114 String apiBase = intent.getStringExtra("apiBase");
115 String apiBase = intent.getStringExtra("apiBase");115 if (apiBase.equals(Api.ALERT)) {
116 if (apiBase.equals(Api.ALERT)) {116 Toast.makeText(broadcastedContext, "Alert sent!",
117 Toast.makeText(broadcastedContext, "Alert sent!",117 Toast.LENGTH_SHORT).show();
118 Toast.LENGTH_SHORT).show();118 }
119 }119 if (apiBase.equals(Api.DISPLAY_BASE)) {
120 if (apiBase.equals(Api.DISPLAY_BASE)) {120 controller.poll();
121 controller.poll();121 }
122 }122 if (apiBase.equals(Api.POLL_STATUS)) {
123 if (apiBase.equals(Api.POLL_STATUS)) {123 handlePollResponse(intent.getStringExtra("pollJson"));
124 handlePollResponse(intent.getStringExtra("pollJson"));124 }
125 }125 if (apiBase.equals(Api.LIVE_TEXT)) {
126 if (apiBase.equals(Api.LIVE_TEXT)) {126 handleLiveItemsResponse(
127 handleLiveItemsResponse(127 intent.getStringExtra("itemsJson"));
128 intent.getStringExtra("itemsJson"));128 }
129 }129 if (apiBase.equals(Api.SERVICE_LIST)) {
130 if (apiBase.equals(Api.SERVICE_LIST)) {130 handleServiceItemsResponse(
131 handleServiceItemsResponse(131 intent.getStringExtra("itemsJson"));
132 intent.getStringExtra("itemsJson"));132 }
133 }133 }
134 }134 }
135 }135 }
136 }136 };
137 };137
138138 private void handlePollResponse(final String pollResponse) {
139 private void handlePollResponse(final String pollResponse) {139 try {
140 try {140
141141 Poll poll = JSONHandler.getPollFromString(pollResponse);
142 Poll poll = JSONHandler.getPollFromString(pollResponse);142 if (poll != null) {
143 if (poll != null) {143 if (currentPage == PAGE_DISPLAY) {
144 if (currentPage == PAGE_DISPLAY) {144 setDisplayFromPoll(poll);
145 setDisplayFromPoll(poll);145 } else {
146 }146 setServiceOrLiveFromPoll(poll);
147 else {147 }
148 setServiceOrLiveFromPoll(poll);148 } else {
149 }149 Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");
150 }150 }
151 else {151 } catch (JSONHandler.JSONHandlerException e) {
152 Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");152 Log.e(LOG_TAG, e.toString());
153 }153 Toast.makeText(context, String.format("%s: %s",
154 }154 context.getString(R.string.couldNotHandlePollResponse),
155 catch (JSONHandler.JSONHandlerException e) {155 e.getMessage()), Toast.LENGTH_LONG).show();
156 Log.e(LOG_TAG, e.toString());156 }
157 Toast.makeText(context, String.format("%s: %s",157 }
158 context.getString(R.string.couldNotHandlePollResponse),158
159 e.getMessage()), Toast.LENGTH_LONG).show();159 private void setDisplayFromPoll(Poll poll) {
160 }160 final ToggleButton toggleButton = (ToggleButton)
161 }161 context.findViewById(R.id.toggleDisplayButton);
162162 if (poll == null) {
163 private void setDisplayFromPoll(Poll poll) {163 toggleButton.setEnabled(false);
164 final ToggleButton toggleButton = (ToggleButton)164 } else {
165 context.findViewById(R.id.toggleDisplayButton);165 String onText;
166 if (poll == null) {166 String offText;
167 toggleButton.setEnabled(false);167
168 }168 displayType = getDisplayType();
169 else {169 Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType
170 String onText;170 + " " + poll.isDisplayHidden());
171 String offText;171 if (displayType.equals(context.getString(R.string.displayScreen))) {
172172 Log.v(LOG_TAG, "Blank called");
173 displayType = getDisplayType();173 onText = context.getString(R.string.displayScreen);
174 Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType174 offText = context.getString(R.string.displayScreen);
175 + " " + poll.isDisplayHidden());175 } else if (displayType
176 if (displayType.equals(context.getString(R.string.displayScreen))) {176 .equals(context.getString(R.string.displayTheme))) {
177 Log.v(LOG_TAG, "Blank called");177 Log.v(LOG_TAG, "Theme called");
178 onText = context.getString(R.string.displayScreen);178 onText = context.getString(R.string.displayTheme);
179 offText = context.getString(R.string.displayScreen);179 offText = context.getString(R.string.displayTheme);
180 }180 } else {
181 else if (displayType181 Log.v(LOG_TAG, "Desktop called");
182 .equals(context.getString(R.string.displayTheme))) {182 onText = context.getString(R.string.displayDesktop);
183 Log.v(LOG_TAG, "Theme called");183 offText = context.getString(R.string.displayDesktop);
184 onText = context.getString(R.string.displayTheme);184 }
185 offText = context.getString(R.string.displayTheme);185 /*
186 }
187 else {
188 Log.v(LOG_TAG, "Desktop called");
189 onText = context.getString(R.string.displayDesktop);
190 offText = context.getString(R.string.displayDesktop);
191 }
192 /*
193 Set display blanked to the off value to that of the screen186 Set display blanked to the off value to that of the screen
194 */187 */
195 if (poll.isDisplayHidden()) {188 if (poll.isDisplayHidden()) {
196 if (poll.isBlankedDisplayed()) {189 if (poll.isBlankedDisplayed()) {
197 Log.v(LOG_TAG, "Hidden Blank called");190 Log.v(LOG_TAG, "Hidden Blank called");
198 onText = context.getString(R.string.displayScreen);191 onText = context.getString(R.string.displayScreen);
199 }192 } else if (poll.isThemeDisplayed()) {
200 else if (poll.isThemeDisplayed()) {193 Log.v(LOG_TAG, "Hidden Theme called");
201 Log.v(LOG_TAG, "Hidden Theme called");194 onText = context.getString(R.string.displayTheme);
202 onText = context.getString(R.string.displayTheme);195 } else {
203 }196 Log.v(LOG_TAG, "Hidden Desktop called");
204 else {197 onText = context.getString(R.string.displayDesktop);
205 Log.v(LOG_TAG, "Hidden Desktop called");198 }
206 onText = context.getString(R.string.displayDesktop);199 }
207 }200 toggleButton.setTextOn(
208 }201 context.getString(R.string.displayBlankOn) + " " + onText);
209 toggleButton.setTextOn(202 toggleButton.setTextOff(
210 context.getString(R.string.displayBlankOn) + " " + onText);203 context.getString(R.string.displayBlankOff) + " " + offText);
211 toggleButton.setTextOff(204 toggleButton.setEnabled(true);
212 context.getString(R.string.displayBlankOff) + " " + offText);205 toggleButton.setChecked(false);
213 toggleButton.setEnabled(true);206 if (poll.isDisplayHidden()) {
214 toggleButton.setChecked(false);207 toggleButton.setChecked(true);
215 if (poll.isDisplayHidden()) {208 }
216 toggleButton.setChecked(true);209 }
217 }210 }
218 }211
219 }212 private void setServiceOrLiveFromPoll(Poll poll) {
220213 if (currentPage == PAGE_LIVE) {
221 private void setServiceOrLiveFromPoll(Poll poll) {214 if (!itemId.equals(poll.getItem()) ||
222 if (currentPage == PAGE_LIVE) {215 currentLive != poll.getSlide()) {
223 if (!itemId.equals(poll.getItem()) ||216 Log.v(LOG_TAG, "Slide Changed. Polling update...");
224 currentLive != poll.getSlide()) {217 currentLive = poll.getSlide();
225 Log.v(LOG_TAG, "Slide Changed. Polling update...");218 itemId = poll.getItem();
226 currentLive = poll.getSlide();219 controller.fetchItems(Api.LIVE_TEXT);
227 itemId = poll.getItem();220 }
228 controller.fetchItems(Api.LIVE_TEXT);221 } else if (currentPage == PAGE_SERVICE) {
229 }222 if (currentService < poll.getService()) {
230 }223 Log.v(LOG_TAG, "Service Changed. Polling update...");
231 else if (currentPage == PAGE_SERVICE) {224 currentService = poll.getService();
232 if (currentService < poll.getService()) {225 controller.fetchItems(Api.SERVICE_LIST);
233 Log.v(LOG_TAG, "Service Changed. Polling update...");226 }
234 currentService = poll.getService();227 }
235 controller.fetchItems(Api.SERVICE_LIST);228 }
236 }229
237 }230 private void handleLiveItemsResponse(final String itemsJson) {
238 }231 try {
239232 List<SlideItem> liveItems =
240 private void handleLiveItemsResponse(final String itemsJson) {233 JSONHandler.getSlideItemsFromString(itemsJson);
241 try {234 listViewLive
242 List<SlideItem> liveItems =235 .setAdapter(new SlideAdapter(context, liveItems, currentLive));
243 JSONHandler.getSlideItemsFromString(itemsJson);
244 listViewLive
245 .setAdapter(new SlideAdapter(context, liveItems, currentLive));
246 listViewLive.setSelection(currentLive);236 listViewLive.setSelection(currentLive);
247 }237 } catch (JSONHandler.JSONHandlerException e) {
248 catch (JSONHandler.JSONHandlerException e) {238 Log.e(LOG_TAG, e.toString());
249 Log.e(LOG_TAG, e.toString());239 Toast.makeText(context, String.format("%s: %s",
250 Toast.makeText(context, String.format("%s: %s",240 context.getString(R.string.couldNotHandleLiveItems),
251 context.getString(R.string.couldNotHandleLiveItems),241 e.getMessage()), Toast.LENGTH_LONG).show();
252 e.getMessage()), Toast.LENGTH_LONG).show();242 }
253 }243 }
254 }244
255245 private void handleServiceItemsResponse(final String itemsJson) {
256 private void handleServiceItemsResponse(final String itemsJson) {246 try {
257 try {247 List<SlideItem> serviceItems =
258 List<SlideItem> serviceItems =248 JSONHandler.getServiceItemsFromString(itemsJson);
259 JSONHandler.getServiceItemsFromString(itemsJson);249 listViewService.setAdapter(
260 listViewService.setAdapter(250 new SlideAdapter(context, serviceItems, currentService));
261 new SlideAdapter(context, serviceItems, currentService));251 } catch (JSONHandler.JSONHandlerException e) {
262 }252 Log.e(LOG_TAG, e.toString());
263 catch (JSONHandler.JSONHandlerException e) {253 Toast.makeText(context, String.format("%s: %s",
264 Log.e(LOG_TAG, e.toString());254 context.getString(R.string.couldNotHandleServiceItems),
265 Toast.makeText(context, String.format("%s: %s",255 e.getMessage()), Toast.LENGTH_LONG).show();
266 context.getString(R.string.couldNotHandleServiceItems),256 }
267 e.getMessage()), Toast.LENGTH_LONG).show();257 }
268 }258
269 }259 private OpenLPNavigate controller = new OpenLPNavigate() {
270260 @Override
271 private OpenLPNavigate controller = new OpenLPNavigate() {261 public void navigate(final String navigationRequest) {
272 @Override262 Intent navigationIntent = new Intent(context, ApiCallIntent.class);
273 public void navigate(final String navigationRequest) {263 if (currentPage == PAGE_SERVICE) {
274 Intent navigationIntent = new Intent(context, ApiCallIntent.class);264 navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);
275 if (currentPage == PAGE_SERVICE) {265 }
276 navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);266 if (currentPage == PAGE_LIVE) {
277 }267 navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);
278 if (currentPage == PAGE_LIVE) {268 }
279 navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);269 context.startService(navigationIntent);
280 }270 }
281 context.startService(navigationIntent);271
282 }272 @Override
283273 public void setData(String apiPart, int id) {
284 @Override274 Intent setDataIntent = new Intent(context, ApiCallIntent.class);
285 public void setData(String apiPart, int id) {275 setDataIntent.putExtra(apiPart, id);
286 Intent setDataIntent = new Intent(context, ApiCallIntent.class);276 context.startService(setDataIntent);
287 setDataIntent.putExtra(apiPart, id);277 }
288 context.startService(setDataIntent);278
289 }279 @Override
290280 public void setDisplay(String displayRequest) {
291 @Override281 Log.d(LOG_TAG, String
292 public void setDisplay(String displayRequest) {282 .format("Setting Display: displayRequest(%s)", displayRequest));
293 Log.d(LOG_TAG, String283 Intent displayIntent = new Intent(context, ApiCallIntent.class);
294 .format("Setting Display: displayRequest(%s)", displayRequest));284 displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);
295 Intent displayIntent = new Intent(context, ApiCallIntent.class);285 context.startService(displayIntent);
296 displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);286 }
297 context.startService(displayIntent);287
298 }288 @Override
299289 public void poll() {
300 @Override290 Intent pollIntent = new Intent(context, ApiCallIntent.class);
301 public void poll() {291 pollIntent.putExtra(Api.POLL_STATUS, "");
302 Intent pollIntent = new Intent(context, ApiCallIntent.class);292 context.startService(pollIntent);
303 pollIntent.putExtra(Api.POLL_STATUS, "");293 }
304 context.startService(pollIntent);294
305 }295 @Override
306296 public void fetchItems(String apiPart) {
307 @Override297 Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);
308 public void fetchItems(String apiPart) {298 fetchItemsIntent.putExtra(apiPart, "");
309 Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);299 context.startService(fetchItemsIntent);
310 fetchItemsIntent.putExtra(apiPart, "");300 }
311 context.startService(fetchItemsIntent);301 };
312 }302
313 };303 @Override
314304 public Object instantiateItem(final ViewGroup container, int position) {
315 @Override305 LayoutInflater inflater = (LayoutInflater) container.getContext()
316 public Object instantiateItem(final ViewGroup container, int position) {306 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
317 LayoutInflater inflater = (LayoutInflater) container.getContext()307 int res = 0;
318 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);308 try {
319 int res = 0;309 res = getLayoutForPosition(position);
320 try {310 } catch (NoLayoutForPositionException e) {
321 res = getLayoutForPosition(position);311 Log.e(LOG_TAG, e.getMessage());
322 }312 }
323 catch (NoLayoutForPositionException e) {313
324 Log.e(LOG_TAG, e.getMessage());314 View view = inflater.inflate(res, null);
325 }315
326316 if (position == PAGE_SERVICE || position == PAGE_LIVE) {
327 View view = inflater.inflate(res, null);317 if (position == PAGE_SERVICE) {
328318 listViewService = (ListView) view.findViewById(R.id.list);
329 if (position == PAGE_SERVICE || position == PAGE_LIVE) {319 listViewService
330 if (position == PAGE_SERVICE) {320 .setOnItemClickListener(onItemClickListenerService);
331 listViewService = (ListView) view.findViewById(R.id.list);321 listViewService.setOnItemLongClickListener(
332 listViewService322 adapterViewOnItemLongClickListener);
333 .setOnItemClickListener(onItemClickListenerService);323 }
334 listViewService.setOnItemLongClickListener(324
335 adapterViewOnItemLongClickListener);325 if (position == PAGE_LIVE) {
336 }326 listViewLive = (ListView) view.findViewById(R.id.list);
337327 listViewLive.setOnItemClickListener(onItemClickListenerSetLive);
338 if (position == PAGE_LIVE) {328 }
339 listViewLive = (ListView) view.findViewById(R.id.list);329
340 listViewLive.setOnItemClickListener(onItemClickListenerSetLive);330 view.findViewById(R.id.prev)
341 }331 .setOnClickListener(onClickListenerNavigate);
342332 view.findViewById(R.id.next)
343 view.findViewById(R.id.prev)333 .setOnClickListener(onClickListenerNavigate);
344 .setOnClickListener(onClickListenerNavigate);334 }
345 view.findViewById(R.id.next)335
346 .setOnClickListener(onClickListenerNavigate);336 if (position == PAGE_STAGE) {
347 }337 webView = getWebViewFromView(view);
348338 }
349 if (position == PAGE_STAGE) {339 if (position == PAGE_ALERT) {
350 webView = getWebViewFromView(view);340 view.findViewById(R.id.send).setOnClickListener(mSend);
351 }341 }
352 if (position == PAGE_ALERT) {342 if (position == PAGE_DISPLAY) {
353 view.findViewById(R.id.send).setOnClickListener(mSend);343 view.findViewById(R.id.toggleDisplayButton)
354 }344 .setOnClickListener(onClickListenerToggleDisplay);
355 if (position == PAGE_DISPLAY) {345 }
356 view.findViewById(R.id.toggleDisplayButton)346
357 .setOnClickListener(onClickListenerToggleDisplay);347 container.addView(view, 0);
358 }348 return view;
359349 }
360 container.addView(view, 0);350
361 return view;351 private WebView getWebViewFromView(View view) {
362 }352 WebView myWebView = (WebView) view.findViewById(R.id.stageview);
363
364 private WebView getWebViewFromView(View view) {
365 WebView myWebView = (WebView) view.findViewById(R.id.stageview);
366 /*353 /*
367 * Handle SSL self signed certificates and refresh the screen if the certificate354 * Handle SSL self signed certificates and refresh the screen if the certificate
368 * page appears.355 * page appears.
369 */356 */
370 myWebView.setWebViewClient(new WebViewClient() {357 myWebView.setWebViewClient(new WebViewClient() {
371 public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {358 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
372 handler.proceed() ;359 handler.proceed();
373 }360 }
374 } );361 });
375 WebSettings webSettings = myWebView.getSettings();362 WebSettings webSettings = myWebView.getSettings();
376 webSettings.setJavaScriptEnabled(true);363 webSettings.setJavaScriptEnabled(true);
377 webSettings.setBuiltInZoomControls(true);364 webSettings.setBuiltInZoomControls(true);
378 webSettings.setLoadWithOverviewMode(true);365 webSettings.setLoadWithOverviewMode(true);
379 webSettings.setUseWideViewPort(true);366 webSettings.setUseWideViewPort(true);
380 myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);367 myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
381 myWebView.setScrollbarFadingEnabled(true);368 myWebView.setScrollbarFadingEnabled(true);
382369
383 myWebView.loadUrl(getUrlBase());370 myWebView.loadUrl(getUrlBase());
384 return myWebView;371 return myWebView;
385 }372 }
386373
387 public static int getPageForButton(View view) {374 public static int getPageForButton(View view) {
388 final int buttonId = view.getId();375 final int buttonId = view.getId();
389 if (buttonId == R.id.buttonAlert) {376 if (buttonId == R.id.buttonAlert) {
390 return PAGE_ALERT;377 return PAGE_ALERT;
391 }378 }
392 if (buttonId == R.id.buttonDisplay) {379 if (buttonId == R.id.buttonDisplay) {
393 return PAGE_DISPLAY;380 return PAGE_DISPLAY;
394 }381 }
395 if (buttonId == R.id.buttonLive) {382 if (buttonId == R.id.buttonLive) {
396 return PAGE_LIVE;383 return PAGE_LIVE;
397 }384 }
398 if (buttonId == R.id.buttonSearch) {385 if (buttonId == R.id.buttonSearch) {
399 return PAGE_SEARCH;386 return PAGE_SEARCH;
400 }387 }
401 if (buttonId == R.id.buttonService) {388 if (buttonId == R.id.buttonService) {
402 return PAGE_SERVICE;389 return PAGE_SERVICE;
403 }390 }
404 if (buttonId == R.id.buttonStage) {391 if (buttonId == R.id.buttonStage) {
405 return PAGE_STAGE;392 return PAGE_STAGE;
406 }393 }
407394
408 Log.e(OpenLPController.class.getName(),395 Log.e(OpenLPController.class.getName(),
409 "No Button connected to the requested view, with id: " + buttonId);396 "No Button connected to the requested view, with id: " + buttonId);
410 return 0;397 return 0;
411 }398 }
412399
413 public ViewPager.OnPageChangeListener onPageChangeListener =400 public ViewPager.OnPageChangeListener onPageChangeListener =
414 new ViewPager.OnPageChangeListener() {401 new ViewPager.OnPageChangeListener() {
415 @Override402 @Override
416 public void onPageScrolled(int i, float v, int i1) {403 public void onPageScrolled(int i, float v, int i1) {
417 }404 }
418405
419 @Override406 @Override
420 public void onPageSelected(int selectedPage) {407 public void onPageSelected(int selectedPage) {
421 Log.d(LOG_TAG, String408 Log.d(LOG_TAG, String
422 .format("Selected Page: position(%s) title(%s)",409 .format("Selected Page: position(%s) title(%s)",
423 selectedPage, getPageTitle(selectedPage)));410 selectedPage, getPageTitle(selectedPage)));
424 currentPage = selectedPage;411 currentPage = selectedPage;
425412
426 if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {413 if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {
427 context.startService(pingIntent);414 context.startService(pingIntent);
428 if (currentPage == PAGE_SERVICE) {415 if (currentPage == PAGE_SERVICE) {
429 controller.fetchItems(Api.SERVICE_LIST);416 controller.fetchItems(Api.SERVICE_LIST);
430 }417 }
431 if (currentPage == PAGE_LIVE) {418 if (currentPage == PAGE_LIVE) {
432 controller.fetchItems(Api.LIVE_TEXT);419 controller.fetchItems(Api.LIVE_TEXT);
433 }420 }
434 }421 } else {
435 else {422 context.stopService(pingIntent);
436 context.stopService(pingIntent);423 }
437 }424
438425 if (currentPage == PAGE_STAGE) {
439 if (currentPage == PAGE_STAGE) {426 if (webView == null) {
440 if (webView == null) {427 webView = getWebViewFromView(context.getLayoutInflater()
441 webView = getWebViewFromView(context.getLayoutInflater()428 .inflate(R.layout.stageview, null));
442 .inflate(R.layout.stageview, null));429 }
443 }430 }
444 }431
445432 if (currentPage == PAGE_DISPLAY) {
446 if (currentPage == PAGE_DISPLAY) {433 controller.poll();
447 controller.poll();434 }
448 }435 }
449 }436
450437 @Override
451 @Override438 public void onPageScrollStateChanged(int i) {
452 public void onPageScrollStateChanged(int i) {439 }
453 }440 };
454 };441
455442
456443 @Override
457 @Override444 public CharSequence getPageTitle(int position) {
458 public CharSequence getPageTitle(int position) {445 String page = "none";
459 String page = "none";446 switch (position) {
460 switch (position) {447 case PAGE_SERVICE:
461 case PAGE_SERVICE:448 page = context.getString(R.string.tabService);
462 page = context.getString(R.string.tabService);449 break;
463 break;450 case PAGE_LIVE:
464 case PAGE_LIVE:451 page = context.getString(R.string.tabLive);
465 page = context.getString(R.string.tabLive);452 break;
466 break;453 case PAGE_DISPLAY:
467 case PAGE_DISPLAY:454 page = context.getString(R.string.tabDisplay);
468 page = context.getString(R.string.tabDisplay);455 break;
469 break;456 case PAGE_STAGE:
470 case PAGE_STAGE:457 page = context.getString(R.string.tabStage);
471 page = context.getString(R.string.tabStage);458 break;
472 break;459 case PAGE_ALERT:
473 case PAGE_ALERT:460 page = context.getString(R.string.tabAlert);
474 page = context.getString(R.string.tabAlert);461 break;
475 break;462 case PAGE_SEARCH:
476 case PAGE_SEARCH:463 page = context.getString(R.string.buttonSearchText);
477 page = context.getString(R.string.buttonSearchText);464 break;
478 break;465 }
479 }466 return page;
480 return page;467 }
481 }468
482469 private int getLayoutForPosition(int position)
483 private int getLayoutForPosition(int position)470 throws NoLayoutForPositionException {
484 throws NoLayoutForPositionException {471 switch (position) {
485 switch (position) {472 case PAGE_SERVICE:
486 case PAGE_SERVICE:473 return R.layout.slide_service;
487 return R.layout.slide_service;474 case PAGE_LIVE:
488 case PAGE_LIVE:475 return R.layout.slide_service;
489 return R.layout.slide_service;476 case PAGE_DISPLAY:
490 case PAGE_DISPLAY:477 return R.layout.misc;
491 return R.layout.misc;478 case PAGE_STAGE:
492 case PAGE_STAGE:479 return R.layout.stageview;
493 return R.layout.stageview;480 case PAGE_ALERT:
494 case PAGE_ALERT:481 return R.layout.alert;
495 return R.layout.alert;482 case PAGE_SEARCH:
496 case PAGE_SEARCH:483 return R.layout.search;
497 return R.layout.search;484 default:
498 default:485 throw new NoLayoutForPositionException(
499 throw new NoLayoutForPositionException(486 "No Layout for position (" + position + ")");
500 "No Layout for position (" + position + ")");487 }
501 }488 }
502 }489
503490 private AdapterView.OnItemClickListener onItemClickListenerSetLive =
504 private AdapterView.OnItemClickListener onItemClickListenerSetLive =491 new AdapterView.OnItemClickListener() {
505 new AdapterView.OnItemClickListener() {492 @Override
506 @Override493 public void onItemClick(AdapterView<?> adapterView, View view,
507 public void onItemClick(AdapterView<?> adapterView, View view,494 int i, long l) {
508 int i, long l) {495 controller.setData(Api.LIVE_SET, i);
509 controller.setData(Api.LIVE_SET, i);496 }
510 }497 };
511 };498
512499 private AdapterView.OnItemLongClickListener
513 private AdapterView.OnItemLongClickListener500 adapterViewOnItemLongClickListener =
514 adapterViewOnItemLongClickListener =501 new AdapterView.OnItemLongClickListener() {
515 new AdapterView.OnItemLongClickListener() {502 @Override
516 @Override503 public boolean onItemLongClick(AdapterView<?> adapterView,
517 public boolean onItemLongClick(AdapterView<?> adapterView,504 View view, int i, long l) {
518 View view, int i, long l) {505 controller.setData(Api.SERVICE_SET, i);
519 controller.setData(Api.SERVICE_SET, i);506 ((PagerActivity) context).setCurrentPage(PAGE_LIVE);
520 ((PagerActivity) context).setCurrentPage(PAGE_LIVE);507 return true;
521 return true;508 }
522 }509 };
523 };510
524511 private ListView.OnItemClickListener onItemClickListenerService =
525 private ListView.OnItemClickListener onItemClickListenerService =512 new AdapterView.OnItemClickListener() {
526 new AdapterView.OnItemClickListener() {513 @Override
527 @Override514 public void onItemClick(AdapterView<?> adapterView, View view,
528 public void onItemClick(AdapterView<?> adapterView, View view,515 int i, long l) {
529 int i, long l) {516 controller.setData(Api.SERVICE_SET, i);
530 controller.setData(Api.SERVICE_SET, i);517 }
531 }518 };
532 };519
533520 private Button.OnClickListener onClickListenerNavigate =
534 private Button.OnClickListener onClickListenerNavigate =521 new Button.OnClickListener() {
535 new Button.OnClickListener() {522 @Override
536 @Override523 public void onClick(View v) {
537 public void onClick(View v) {524 if (v.getId() == R.id.prev) {
538 if (v.getId() == R.id.prev) {525 controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);
539 controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);526 } else if (v.getId() == R.id.next) {
540 }527 controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);
541 else if (v.getId() == R.id.next) {528 }
542 controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);529 }
543 }530 };
544 }531
545 };532 /**
546533 * Alert Button Listener
547 /**534 */
548 * Alert Button Listener535 private Button.OnClickListener mSend = new Button.OnClickListener() {
549 */536 @Override
550 private Button.OnClickListener mSend = new Button.OnClickListener() {537 public void onClick(View v) {
551 @Override538 EditText edittext = (EditText) context.findViewById(R.id.alert);
552 public void onClick(View v) {539
553 EditText edittext = (EditText) context.findViewById(R.id.alert);540 if (edittext.getText().toString().trim().length() > 0) {
554541 apiCallIntent
555 if (edittext.getText().toString().trim().length() > 0) {542 .putExtra(Api.ALERT, edittext.getText().toString());
556 apiCallIntent543 context.startService(apiCallIntent);
557 .putExtra(Api.ALERT, edittext.getText().toString());544 } else {
558 context.startService(apiCallIntent);545 Toast.makeText(context,
559 }546 context.getString(R.string.alertTextNull),
560 else {547 Toast.LENGTH_SHORT).show();
561 Toast.makeText(context,548 }
562 context.getString(R.string.alertTextNull),549 }
563 Toast.LENGTH_SHORT).show();550 };
564 }551
565 }552 public View.OnClickListener onClickListenerToggleDisplay =
566 };553 new View.OnClickListener() {
567554 @Override
568 public View.OnClickListener onClickListenerToggleDisplay =555 public void onClick(View view) {
569 new View.OnClickListener() {556 ToggleButton toggleButton = (ToggleButton) view;
570 @Override557
571 public void onClick(View view) {558 String displayType = getDisplayType();
572 ToggleButton toggleButton = (ToggleButton) view;559 if (!toggleButton.isChecked()) {
573560 controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);
574 String displayType = getDisplayType();561 } else {
575 if (!toggleButton.isChecked()) {562 if (displayType
576 controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);563 .equals(context.getString(R.string.displayScreen))) {
577 }564 controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);
578 else {565 } else if (displayType
579 if (displayType566 .equals(context.getString(R.string.displayTheme))) {
580 .equals(context.getString(R.string.displayScreen))) {567 controller.setDisplay(OpenLPNavigate.HIDE_THEME);
581 controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);568 } else {
582 }569 controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);
583 else if (displayType570 }
584 .equals(context.getString(R.string.displayTheme))) {571 }
585 controller.setDisplay(OpenLPNavigate.HIDE_THEME);572 }
586 }573 };
587 else {574
588 controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);575 @Override
589 }576 public int getCount() {
590 }577 return 5;
591 }578 }
592 };579
593580 @Override
594 @Override581 public boolean isViewFromObject(View view, Object o) {
595 public int getCount() {582 return view == o;
596 return 5;583 }
597 }584
598585 @Override
599 @Override586 public void destroyItem(ViewGroup container, int position, Object object) {
600 public boolean isViewFromObject(View view, Object o) {587 container.removeView((View) object);
601 return view == o;588 }
602 }589
603590 private static final String LOG_TAG = OpenLPController.class.getName();
604 @Override591
605 public void destroyItem(ViewGroup container, int position, Object object) {592 private String getDisplayType() {
606 container.removeView((View) object);593 displayType = preferences
607 }594 .getString(context.getString(R.string.keyDisplayBlankType),
608595 context.getString(R.string.displayTypeValue));
609 private static final String LOG_TAG = OpenLPController.class.getName();596 return displayType;
610597 }
611 private String getDisplayType() {598
612 displayType = preferences599 private String getUrlBase() {
613 .getString(context.getString(R.string.keyDisplayBlankType),600 Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
614 context.getString(R.string.displayTypeValue));601
615 return displayType;602 return String.format("%s://%s:%s/stage",
616 }603 useSsl ? "https" : "http",
617604 preferences.getString(context.getString(R.string.keyHost),
618 private String getUrlBase() {605 context.getString(R.string.hostDefaultValue)),
619 Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);606 preferences.getString(context.getString(R.string.keyPort),
620607 context.getString(R.string.portDefaultValue)));
621 return String.format("%s://%s:%s/stage",608 }
622 useSsl ? "https" : "http",609
623 preferences.getString(context.getString(R.string.keyHost),610 class NoLayoutForPositionException extends Exception {
624 context.getString(R.string.hostDefaultValue)),611 NoLayoutForPositionException(String detailMessage) {
625 preferences.getString(context.getString(R.string.keyPort),612 super(detailMessage);
626 context.getString(R.string.portDefaultValue)));613 }
627 }614 }
628
629 class NoLayoutForPositionException extends Exception {
630 NoLayoutForPositionException(String detailMessage) {
631 super(detailMessage);
632 }
633 }
634}615}
635616
=== modified file 'src/org/openlp/android/utility/OpenLPHttpClient.java'
--- src/org/openlp/android/utility/OpenLPHttpClient.java 2013-04-07 12:24:38 +0000
+++ src/org/openlp/android/utility/OpenLPHttpClient.java 2013-06-04 19:32:29 +0000
@@ -68,49 +68,49 @@
68 */68 */
69public class OpenLPHttpClient extends DefaultHttpClient {69public class OpenLPHttpClient extends DefaultHttpClient {
7070
71 private HttpGet httpGet;71 private HttpGet httpGet;
72 private URL url;72 private URL url;
73 private final String urlBase;73 private final String urlBase;
74 private SSLSocketFactory sslSocketFactory;74 private SSLSocketFactory sslSocketFactory;
75 private Context context;75 private Context context;
7676
77 public OpenLPHttpClient(Context context) {77 public OpenLPHttpClient(Context context) {
78 SharedPreferences preferences = context.getSharedPreferences(78 SharedPreferences preferences = context.getSharedPreferences(
79 context.getString(R.string.keySharedPreferences),79 context.getString(R.string.keySharedPreferences),
80 Context.MODE_PRIVATE);80 Context.MODE_PRIVATE);
81 HttpParams httpParams = new BasicHttpParams();81 HttpParams httpParams = new BasicHttpParams();
8282
83 this.context = context;83 this.context = context;
8484
85 Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);85 Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
8686
87 String port = preferences.getString(87 String port = preferences.getString(
88 context.getString(R.string.keyPort),88 context.getString(R.string.keyPort),
89 context.getString(R.string.portDefaultValue)89 context.getString(R.string.portDefaultValue)
90 );90 );
9191
92 SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();92 SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
93 if (!useSsl) {93 if (!useSsl) {
94 schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));94 schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
95 } else {95 } else {
96 try {96 try {
97 initSsl();97 initSsl();
98 schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));98 schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
99 } catch (NoSuchAlgorithmException e) {99 } catch (NoSuchAlgorithmException e) {
100 Log.e(LOG_TAG, e.toString());100 Log.e(LOG_TAG, e.toString());
101 } catch (KeyManagementException e) {101 } catch (KeyManagementException e) {
102 Log.e(LOG_TAG, e.toString());102 Log.e(LOG_TAG, e.toString());
103 } catch (KeyStoreException e) {103 } catch (KeyStoreException e) {
104 Log.e(LOG_TAG, e.toString());104 Log.e(LOG_TAG, e.toString());
105 } catch (UnrecoverableKeyException e) {105 } catch (UnrecoverableKeyException e) {
106 Log.e(LOG_TAG, e.toString());106 Log.e(LOG_TAG, e.toString());
107 } catch (CertificateException e) {107 } catch (CertificateException e) {
108 e.printStackTrace();108 e.printStackTrace();
109 } catch (IOException e) {109 } catch (IOException e) {
110 e.printStackTrace();110 e.printStackTrace();
111 }111 }
112112
113 }113 }
114114
115 String userid = preferences.getString(115 String userid = preferences.getString(
116 context.getString(R.string.key_userid),116 context.getString(R.string.key_userid),
@@ -123,131 +123,131 @@
123 context.getString(R.string.passwordDefaultValue)123 context.getString(R.string.passwordDefaultValue)
124 );124 );
125125
126 Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);126 Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
127127
128 Credentials creds = new UsernamePasswordCredentials(userid, password);128 Credentials creds = new UsernamePasswordCredentials(userid, password);
129 getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);129 getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);
130130
131 urlBase = String.format("http%s://%s:%s",131 urlBase = String.format("http%s://%s:%s",
132 useSsl ? "s" : "",132 useSsl ? "s" : "",
133 preferences.getString(133 preferences.getString(
134 context.getString(R.string.keyHost),134 context.getString(R.string.keyHost),
135 context.getString(R.string.hostDefaultValue)), port);135 context.getString(R.string.hostDefaultValue)), port);
136136
137 int connectionTimeout = context.getResources().getInteger(137 int connectionTimeout = context.getResources().getInteger(
138 R.integer.connectionTimeoutDefaultValue);138 R.integer.connectionTimeoutDefaultValue);
139 int socketTimeout = context.getResources().getInteger(139 int socketTimeout = context.getResources().getInteger(
140 R.integer.socketTimeoutDefaultValue);140 R.integer.socketTimeoutDefaultValue);
141141
142 if (preferences.getBoolean(142 if (preferences.getBoolean(
143 context.getString(R.string.keyEnableCustomTimeout), false)) {143 context.getString(R.string.keyEnableCustomTimeout), false)) {
144 Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",144 Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",
145 context.getString(R.string.keyConnectionTimeout),145 context.getString(R.string.keyConnectionTimeout),
146 context.getString(R.string.keySocketTimeout)));146 context.getString(R.string.keySocketTimeout)));
147 connectionTimeout = Integer.parseInt(preferences.getString(147 connectionTimeout = Integer.parseInt(preferences.getString(
148 context.getString(R.string.keyConnectionTimeout),148 context.getString(R.string.keyConnectionTimeout),
149 String.valueOf(context.getResources().getInteger(149 String.valueOf(context.getResources().getInteger(
150 R.integer.connectionTimeoutDefaultValue))));150 R.integer.connectionTimeoutDefaultValue))));
151 socketTimeout = Integer.parseInt(preferences.getString(151 socketTimeout = Integer.parseInt(preferences.getString(
152 context.getString(R.string.keySocketTimeout),152 context.getString(R.string.keySocketTimeout),
153 String.valueOf(context.getResources().getInteger(153 String.valueOf(context.getResources().getInteger(
154 R.integer.socketTimeoutDefaultValue))));154 R.integer.socketTimeoutDefaultValue))));
155 }155 }
156 HttpConnectionParams156 HttpConnectionParams
157 .setConnectionTimeout(httpParams, connectionTimeout);157 .setConnectionTimeout(httpParams, connectionTimeout);
158 HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);158 HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
159 setParams(httpParams);159 setParams(httpParams);
160 httpGet = new HttpGet();160 httpGet = new HttpGet();
161 }161 }
162162
163 public URL getUrl() {163 public URL getUrl() {
164 return url;164 return url;
165 }165 }
166166
167 public void setUrl(String apiPart) throws URISyntaxException,167 public void setUrl(String apiPart) throws URISyntaxException,
168 MalformedURLException {168 MalformedURLException {
169 url = new URL(urlBase.concat(apiPart));169 url = new URL(urlBase.concat(apiPart));
170 try {170 try {
171 Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));171 Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));
172 } catch (UnsupportedEncodingException e) {172 } catch (UnsupportedEncodingException e) {
173 Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());173 Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());
174 }174 }
175 httpGet.setURI(getUrl().toURI());175 httpGet.setURI(getUrl().toURI());
176 }176 }
177177
178 public HttpResponse execute() throws IOException {178 public HttpResponse execute() throws IOException {
179 return super.execute(httpGet);179 return super.execute(httpGet);
180 }180 }
181181
182 public HttpReturn handleExecute() throws IOException {182 public HttpReturn handleExecute() throws IOException {
183 HttpResponse response = this.execute();183 HttpResponse response = this.execute();
184184
185 Log.d(LOG_TAG, "Http response code " + String.valueOf(response.getStatusLine().getStatusCode()));185 Log.d(LOG_TAG, "Http response code " + String.valueOf(response.getStatusLine().getStatusCode()));
186186
187 if (response.getStatusLine().getStatusCode() == 200) {187 if (response.getStatusLine().getStatusCode() == 200) {
188 BufferedReader bufferedReader;188 BufferedReader bufferedReader;
189 HttpEntity entity = response.getEntity();189 HttpEntity entity = response.getEntity();
190190
191 if (entity != null) {191 if (entity != null) {
192 bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));192 bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
193 StringBuilder stringBuilder = new StringBuilder();193 StringBuilder stringBuilder = new StringBuilder();
194194
195 String line = bufferedReader.readLine();195 String line = bufferedReader.readLine();
196 while (line != null) {196 while (line != null) {
197 stringBuilder.append(line);197 stringBuilder.append(line);
198 line = bufferedReader.readLine();198 line = bufferedReader.readLine();
199 }199 }
200 bufferedReader.close();200 bufferedReader.close();
201 return new HttpReturn(0, stringBuilder.toString(), this.context);201 return new HttpReturn(0, stringBuilder.toString(), this.context);
202 }202 }
203 }203 }
204 return new HttpReturn(response.getStatusLine().getStatusCode() , null, this.context);204 return new HttpReturn(response.getStatusLine().getStatusCode(), null, this.context);
205 }205 }
206206
207 public HttpEntity handleAndReturnEntity() throws IOException {207 public HttpEntity handleAndReturnEntity() throws IOException {
208 HttpResponse response = this.execute();208 HttpResponse response = this.execute();
209209
210 if (response.getStatusLine().getStatusCode() == 200) {210 if (response.getStatusLine().getStatusCode() == 200) {
211 return response.getEntity();211 return response.getEntity();
212 }212 }
213 return null;213 return null;
214 }214 }
215215
216 private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,216 private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
217 UnrecoverableKeyException, IOException, CertificateException {217 UnrecoverableKeyException, IOException, CertificateException {
218 final SSLContext sslContext = SSLContext.getInstance("TLS");218 final SSLContext sslContext = SSLContext.getInstance("TLS");
219 X509TrustManager trustManager = new X509TrustManager() {219 X509TrustManager trustManager = new X509TrustManager() {
220 @Override220 @Override
221 public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {221 public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
222 }222 }
223223
224 @Override224 @Override
225 public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {225 public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
226 }226 }
227227
228 @Override228 @Override
229 public X509Certificate[] getAcceptedIssuers() {229 public X509Certificate[] getAcceptedIssuers() {
230 return null;230 return null;
231 }231 }
232 };232 };
233 sslContext.init(null, new TrustManager[]{trustManager}, null);233 sslContext.init(null, new TrustManager[]{trustManager}, null);
234234
235 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());235 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
236 keyStore.load(null, null);236 keyStore.load(null, null);
237 sslSocketFactory = new SSLSocketFactory(keyStore) {237 sslSocketFactory = new SSLSocketFactory(keyStore) {
238 @Override238 @Override
239 public Socket createSocket() throws IOException {239 public Socket createSocket() throws IOException {
240 return sslContext.getSocketFactory().createSocket();240 return sslContext.getSocketFactory().createSocket();
241 }241 }
242242
243 @Override243 @Override
244 public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,244 public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
245 UnknownHostException {245 UnknownHostException {
246 return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);246 return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
247 }247 }
248 };248 };
249 sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);249 sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
250 }250 }
251251
252 private final String LOG_TAG = OpenLPHttpClient.class.getName();252 private final String LOG_TAG = OpenLPHttpClient.class.getName();
253}253}
254254
=== modified file 'src/org/openlp/android/utility/SlideAdapter.java'
--- src/org/openlp/android/utility/SlideAdapter.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/SlideAdapter.java 2013-06-04 19:32:29 +0000
@@ -35,99 +35,98 @@
35import org.openlp.android.data.SlideItem;35import org.openlp.android.data.SlideItem;
3636
37public class SlideAdapter extends BaseAdapter {37public class SlideAdapter extends BaseAdapter {
38 List<SlideItem> items;38 List<SlideItem> items;
39 Activity context;39 Activity context;
40 LayoutInflater inflater;40 LayoutInflater inflater;
41 boolean useTagDisplay = true;41 boolean useTagDisplay = true;
42 private int[] colors = new int[] { 0x74717000, 0x00000000 };42 private int[] colors = new int[]{0x74717000, 0x00000000};
43 private int currentSlide = -1;43 private int currentSlide = -1;
44 SharedPreferences prefs;44 SharedPreferences prefs;
4545
46 public SlideAdapter(Activity context, List<SlideItem> items, int slide) {46 public SlideAdapter(Activity context, List<SlideItem> items, int slide) {
47 this.context = context;47 this.context = context;
48 this.items = items;48 this.items = items;
49 this.currentSlide = slide;49 this.currentSlide = slide;
50 inflater = context.getLayoutInflater();50 inflater = context.getLayoutInflater();
5151
52 prefs = context.getSharedPreferences(52 prefs = context.getSharedPreferences(
53 context.getString(R.string.keySharedPreferences),53 context.getString(R.string.keySharedPreferences),
54 Context.MODE_PRIVATE);54 Context.MODE_PRIVATE);
55 }55 }
5656
57 public SlideAdapter(Activity context, List<SlideItem> items,57 public SlideAdapter(Activity context, List<SlideItem> items,
58 boolean useTagDisplay) {58 boolean useTagDisplay) {
59 this.context = context;59 this.context = context;
60 this.items = items;60 this.items = items;
61 this.useTagDisplay = useTagDisplay;61 this.useTagDisplay = useTagDisplay;
62 inflater = context.getLayoutInflater();62 inflater = context.getLayoutInflater();
6363
64 prefs = context.getSharedPreferences(64 prefs = context.getSharedPreferences(
65 context.getString(R.string.keySharedPreferences),65 context.getString(R.string.keySharedPreferences),
66 Context.MODE_PRIVATE);66 Context.MODE_PRIVATE);
67 }67 }
6868
69 @Override69 @Override
70 public int getCount() {70 public int getCount() {
71 return items.size();71 return items.size();
72 }72 }
7373
74 @Override74 @Override
75 public Object getItem(int i) {75 public Object getItem(int i) {
76 return items.get(i);76 return items.get(i);
77 }77 }
7878
79 @Override79 @Override
80 public long getItemId(int i) {80 public long getItemId(int i) {
81 return items.indexOf(items.get(i));81 return items.indexOf(items.get(i));
82 }82 }
8383
84 @Override84 @Override
85 public View getView(int position, View convertView, ViewGroup parent) {85 public View getView(int position, View convertView, ViewGroup parent) {
86 ViewHolder holder;86 ViewHolder holder;
87 View view = convertView;87 View view = convertView;
8888
89 SlideItem item = items.get(position);89 SlideItem item = items.get(position);
9090
91 if (view == null) {91 if (view == null) {
92 view = inflater.inflate(R.layout.slide_list_item, null);92 view = inflater.inflate(R.layout.slide_list_item, null);
93 holder = new ViewHolder();93 holder = new ViewHolder();
9494
95 holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);95 holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
96 holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);96 holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
9797
98 view.setTag(holder);98 view.setTag(holder);
99 }99 } else {
100 else {100 holder = (ViewHolder) view.getTag();
101 holder = (ViewHolder) view.getTag();101 }
102 }102
103103 int size = Integer.parseInt(prefs.getString(
104 int size = Integer.parseInt(prefs.getString(104 context.getString(R.string.keyTextSize),
105 context.getString(R.string.keyTextSize),105 String.valueOf(context.getResources().getInteger(
106 String.valueOf(context.getResources().getInteger(106 R.integer.textSizeDefaultValue))));
107 R.integer.textSizeDefaultValue))));107
108108 holder.rowMarker.setText(item.getTag());
109 holder.rowMarker.setText(item.getTag());109 holder.rowItem.setText(item.getText());
110 holder.rowItem.setText(item.getText());110 holder.rowItem.setTextSize(size);
111 holder.rowItem.setTextSize(size);111
112112 if (useTagDisplay) {
113 if (useTagDisplay) {113 holder.rowMarker.setMinWidth(40);
114 holder.rowMarker.setMinWidth(40);114 }
115 }115 if (position == this.currentSlide) {
116 if (position == this.currentSlide) {116 holder.rowItem.setTextColor(Color.WHITE);
117 holder.rowItem.setTextColor(Color.WHITE);117 view.setBackgroundColor(Color.argb(99, 200, 200, 200));
118 view.setBackgroundColor(Color.argb(99, 200, 200, 200));118 } else {
119 } else {119 holder.rowItem.setTextColor(Color.LTGRAY);
120 holder.rowItem.setTextColor(Color.LTGRAY);120 view.setBackgroundColor(colors[position % colors.length]);
121 view.setBackgroundColor(colors[position % colors.length]);121 }
122 }122
123123 return view;
124 return view;124 }
125 }125
126126 static class ViewHolder {
127 static class ViewHolder {127 TextView rowMarker;
128 TextView rowMarker;128 TextView rowItem;
129 TextView rowItem;129 }
130 }130
131131 private final String LOG_TAG = SlideAdapter.class.getName();
132 private final String LOG_TAG = SlideAdapter.class.getName();
133}132}
134133
=== modified file 'src/org/openlp/android/utility/StringHelper.java'
--- src/org/openlp/android/utility/StringHelper.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/StringHelper.java 2013-06-04 19:32:29 +0000
@@ -29,35 +29,32 @@
29 * String helper utility to do common string processing.29 * String helper utility to do common string processing.
30 */30 */
31public class StringHelper {31public class StringHelper {
32 public synchronized static String convertStreamToString(InputStream is) {32 public synchronized static String convertStreamToString(InputStream is) {
33 /*33 /*
34 * To convert the InputStream to String we use the34 * To convert the InputStream to String we use the
35 * BufferedReader.readLine() method. We iterate until the BufferedReader35 * BufferedReader.readLine() method. We iterate until the BufferedReader
36 * return null which means there's no more data to read. Each line will36 * return null which means there's no more data to read. Each line will
37 * appended to a StringBuilder and returned as String.37 * appended to a StringBuilder and returned as String.
38 */38 */
3939
40 BufferedReader reader = new BufferedReader(new InputStreamReader(is));40 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
41 StringBuilder sb = new StringBuilder();41 StringBuilder sb = new StringBuilder();
4242
43 String line = null;43 String line = null;
44 try {44 try {
45 while ((line = reader.readLine()) != null) {45 while ((line = reader.readLine()) != null) {
46 sb.append(line + "\n");46 sb.append(line + "\n");
47 }47 }
48 }48 } catch (IOException e) {
49 catch (IOException e) {49 e.printStackTrace();
50 e.printStackTrace();50 } finally {
51 }51 try {
52 finally {52 is.close();
53 try {53 } catch (IOException e) {
54 is.close();54 e.printStackTrace();
55 }55 }
56 catch (IOException e) {56 }
57 e.printStackTrace();57 return sb.toString();
58 }58 }
59 }
60 return sb.toString();
61 }
6259
63}60}
6461
=== modified file 'src/org/openlp/android/utility/WebCallReturningAsyncTask.java'
--- src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2013-04-06 13:44:51 +0000
+++ src/org/openlp/android/utility/WebCallReturningAsyncTask.java 2013-06-04 19:32:29 +0000
@@ -34,85 +34,81 @@
34import java.io.InputStreamReader;34import java.io.InputStreamReader;
3535
36public class WebCallReturningAsyncTask extends AsyncTask<String, Void, String> {36public class WebCallReturningAsyncTask extends AsyncTask<String, Void, String> {
37 private Activity context;37 private Activity context;
38 private String apiPart;38 private String apiPart;
3939
40 public WebCallReturningAsyncTask(Activity context) {40 public WebCallReturningAsyncTask(Activity context) {
41 this.context = context;41 this.context = context;
42 }42 }
4343
44 public WebCallReturningAsyncTask(Activity context, String apiPart) {44 public WebCallReturningAsyncTask(Activity context, String apiPart) {
45 this.context = context;45 this.context = context;
46 this.apiPart = apiPart;46 this.apiPart = apiPart;
47 }47 }
4848
49 @Override49 @Override
50 protected String doInBackground(String... apiCall) {50 protected String doInBackground(String... apiCall) {
51 OpenLPHttpClient httpClient = new OpenLPHttpClient(context);51 OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
52 HttpResponse response = null;52 HttpResponse response = null;
53 BufferedReader bufferedReader = null;53 BufferedReader bufferedReader = null;
5454
55 try {55 try {
56 if (apiPart == null) {56 if (apiPart == null) {
57 httpClient.setUrl(apiCall[0]);57 httpClient.setUrl(apiCall[0]);
58 }58 } else {
59 else {59 httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
60 httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));60 }
61 }61
6262 if (httpClient.getUrl().getHost().trim().length() <= 0) {
63 if (httpClient.getUrl().getHost().trim().length() <= 0) {63 context.startActivity(new Intent(context, Preferences.class));
64 context.startActivity(new Intent(context, Preferences.class));64 } else {
65 }65 response = httpClient.execute();
66 else {66 }
67 response = httpClient.execute();67
68 }68 if (response != null
6969 && response.getStatusLine().getStatusCode() == 200) {
70 if (response != null70 HttpEntity entity = response.getEntity();
71 && response.getStatusLine().getStatusCode() == 200) {71
72 HttpEntity entity = response.getEntity();72 if (entity != null) {
7373 bufferedReader = new BufferedReader(
74 if (entity != null) {74 new InputStreamReader(entity.getContent()));
75 bufferedReader = new BufferedReader(75 StringBuilder stringBuilder = new StringBuilder();
76 new InputStreamReader(entity.getContent()));76
77 StringBuilder stringBuilder = new StringBuilder();77 String line = bufferedReader.readLine();
7878 while (line != null) {
79 String line = bufferedReader.readLine();79 stringBuilder.append(line);
80 while (line != null) {80 line = bufferedReader.readLine();
81 stringBuilder.append(line);81 }
82 line = bufferedReader.readLine();82
83 }83 Log.i(LOG_TAG, String.format("entity: %s",
8484 stringBuilder.toString()));
85 Log.i(LOG_TAG, String.format("entity: %s",85 bufferedReader.close();
86 stringBuilder.toString()));86 return stringBuilder.toString();
87 bufferedReader.close();87 }
88 return stringBuilder.toString();88 }
89 }89 } catch (Exception e) {
90 }90 Log.e(LOG_TAG, e.toString());
91 }91 Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
92 catch (Exception e) {92 if (bufferedReader != null) {
93 Log.e(LOG_TAG, e.toString());93 try {
94 Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();94 bufferedReader.close();
95 if (bufferedReader != null) {95 } catch (IOException e1) {
96 try {96 // do nothing as we are in an error state anyway
97 bufferedReader.close();97 }
98 }98 }
99 catch (IOException e1) {99 }
100 // do nothing as we are in an error state anyway100 return null;
101 }101 }
102 }102
103 }103 @Override
104 return null;104 protected void onPreExecute() {
105 }105 super.onPreExecute();
106106 }
107 @Override107
108 protected void onPreExecute() {108 @Override
109 super.onPreExecute();109 protected void onPostExecute(String s) {
110 }110 super.onPostExecute(s);
111111 }
112 @Override112
113 protected void onPostExecute(String s) {113 private final String LOG_TAG = this.getClass().getName();
114 super.onPostExecute(s);
115 }
116
117 private final String LOG_TAG = this.getClass().getName();
118}114}

Subscribers

People subscribed via source and target branches