openlp-android team mailing list archive
-
openlp-android team
-
Mailing list archive
-
Message #00198
[Merge] lp:~trb143/openlp/android_dev into lp:openlp/android
Tim Bentley has proposed merging lp:~trb143/openlp/android_dev into lp:openlp/android.
Requested reviews:
OpenLP Android Developers (openlp-android)
For more details, see:
https://code.launchpad.net/~trb143/openlp/android_dev/+merge/167382
Code style cleanup only using Intelij
--
https://code.launchpad.net/~trb143/openlp/android_dev/+merge/167382
Your team OpenLP Android Developers is requested to review the proposed merge of lp:~trb143/openlp/android_dev into lp:openlp/android.
=== 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 @@
*/
public class OpenLP extends DefaultActivity {
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- doPreferenceCheck();
- setOnClickListenerPagerForButtons();
- }
-
- private View.OnClickListener onClickListenerPager =
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent pager = new Intent(OpenLP.this, PagerActivity.class);
- pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));
- startActivity(pager);
- }
- };
-
- private void doPreferenceCheck() {
- if (getSharedPreferences(getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE).getString(getString(R.string.keyHost),
- "NONE").equals("NONE")
- || getSharedPreferences(
- getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE).getString(
- getString(R.string.keyHost), null).equals(null)) {
- Log.d(LOG_TAG,
- "URL preference not set. Starting preference activity...");
- Intent preferenceIntent = new Intent(this, Preferences.class);
- startActivity(preferenceIntent);
- }
- }
-
- private void setOnClickListenerPagerForButtons() {
- findViewById(R.id.buttonService)
- .setOnClickListener(onClickListenerPager);
- findViewById(R.id.buttonLive)
- .setOnClickListener(onClickListenerPager);
- findViewById(R.id.buttonDisplay)
- .setOnClickListener(onClickListenerPager);
- findViewById(R.id.buttonAlert)
- .setOnClickListener(onClickListenerPager);
- findViewById(R.id.buttonStage)
- .setOnClickListener(onClickListenerPager);
- findViewById(R.id.buttonSearch)
- .setOnClickListener(onClickListenerSearch);
- }
-
- private View.OnClickListener onClickListenerSearch =
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- onSearchRequested();
- }
- };
-
- private final String LOG_TAG = OpenLP.class.getName();
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ doPreferenceCheck();
+ setOnClickListenerPagerForButtons();
+ }
+
+ private View.OnClickListener onClickListenerPager =
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent pager = new Intent(OpenLP.this, PagerActivity.class);
+ pager.putExtra(OpenLPController.PAGE_KEY, getPageForButton(view));
+ startActivity(pager);
+ }
+ };
+
+ private void doPreferenceCheck() {
+ if (getSharedPreferences(getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE).getString(getString(R.string.keyHost),
+ "NONE").equals("NONE")
+ || getSharedPreferences(
+ getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE).getString(
+ getString(R.string.keyHost), null).equals(null)) {
+ Log.d(LOG_TAG,
+ "URL preference not set. Starting preference activity...");
+ Intent preferenceIntent = new Intent(this, Preferences.class);
+ startActivity(preferenceIntent);
+ }
+ }
+
+ private void setOnClickListenerPagerForButtons() {
+ findViewById(R.id.buttonService)
+ .setOnClickListener(onClickListenerPager);
+ findViewById(R.id.buttonLive)
+ .setOnClickListener(onClickListenerPager);
+ findViewById(R.id.buttonDisplay)
+ .setOnClickListener(onClickListenerPager);
+ findViewById(R.id.buttonAlert)
+ .setOnClickListener(onClickListenerPager);
+ findViewById(R.id.buttonStage)
+ .setOnClickListener(onClickListenerPager);
+ findViewById(R.id.buttonSearch)
+ .setOnClickListener(onClickListenerSearch);
+ }
+
+ private View.OnClickListener onClickListenerSearch =
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ onSearchRequested();
+ }
+ };
+
+ private final String LOG_TAG = OpenLP.class.getName();
}
=== 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 @@
public abstract class DefaultActivity extends Activity implements Api {
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.menu, menu);
- return true;
- }
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.menu, menu);
+ return true;
+ }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.preferences:
- startActivity(new Intent(this, Preferences.class));
- return true;
- case R.id.menuSearch:
- onSearchRequested();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.preferences:
+ startActivity(new Intent(this, Preferences.class));
+ return true;
+ case R.id.menuSearch:
+ onSearchRequested();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
}
=== 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 @@
*/
public interface OpenLPNavigate extends Api {
- public final String NAVIGATE_PREVIOUS = "previous";
- public final String NAVIGATE_NEXT = "next";
- public final String HIDE_SCREEN = "blank";
- public final String HIDE_THEME = "theme";
- public final String HIDE_DESKTOP = "desktop";
- public final String DISPLAY_SHOW = "show";
-
- /**
- * Call to the service changing service/slides.
- *
- * @param direction A direction constant from {@link org.openlp.android.api.Api}.
- * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}
- * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.
- */
- void navigate(String direction);
-
- /**
- * Call to the service changing data for Service or Live
- *
- * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.
- * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}
- * or {@link org.openlp.android.api.Api#SERVICE_SET}
- * @param id Id of the item selected.
- */
- void setData(String apiPart, int id);
-
- void setDisplay(String displayRequest);
- void poll();
-
- /**
- * Replaces what we previously had as FetchItemsTask which basically ran in the UI
- * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}
- */
- void fetchItems(String apiPart);
+ public final String NAVIGATE_PREVIOUS = "previous";
+ public final String NAVIGATE_NEXT = "next";
+ public final String HIDE_SCREEN = "blank";
+ public final String HIDE_THEME = "theme";
+ public final String HIDE_DESKTOP = "desktop";
+ public final String DISPLAY_SHOW = "show";
+
+ /**
+ * Call to the service changing service/slides.
+ *
+ * @param direction A direction constant from {@link org.openlp.android.api.Api}.
+ * Eg.: {@link org.openlp.android.api.Api#LIVE_NEXT}
+ * or {@link org.openlp.android.api.Api#SERVICE_BASE} + previous/next.
+ */
+ void navigate(String direction);
+
+ /**
+ * Call to the service changing data for Service or Live
+ *
+ * @param apiPart An {@link org.openlp.android.api.Api} part for which to set data.
+ * Eg.: {@link org.openlp.android.api.Api#LIVE_SET}
+ * or {@link org.openlp.android.api.Api#SERVICE_SET}
+ * @param id Id of the item selected.
+ */
+ void setData(String apiPart, int id);
+
+ void setDisplay(String displayRequest);
+
+ void poll();
+
+ /**
+ * Replaces what we previously had as FetchItemsTask which basically ran in the UI
+ *
+ * @param apiPart Items to fetch, eg.: {@link Api#LIVE_TEXT} or {@link Api#SERVICE_LIST}
+ */
+ void fetchItems(String apiPart);
}
=== 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 @@
import org.openlp.android.utility.OpenLPController;
public class PagerActivity extends DefaultActivity {
- private ViewPager pager;
- private OpenLPController controller;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Log.i(LOG_TAG, "onCreate");
-
- setContentView(R.layout.view_pager_layout);
-
- controller = new OpenLPController(this);
- pager = (ViewPager) findViewById(R.id.myViewPager);
- pager.setAdapter(controller);
-
- Intent intent = getIntent();
- int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);
- Log.v(LOG_TAG, "Setting Page number: " + selectedPage);
- pager.setOnPageChangeListener(controller.onPageChangeListener);
- pager.setCurrentItem(selectedPage, true);
- controller.onPageChangeListener.onPageSelected(selectedPage);
- }
-
- public void setCurrentPage(int page) {
- pager.setCurrentItem(page, true);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- Log.v(LOG_TAG, "Destroying pagerActivity...");
- unregisterReceiver(controller.apiCallReceiver);
- stopService(controller.pingIntent);
- }
-
- private final String LOG_TAG = PagerActivity.class.getName();
+ private ViewPager pager;
+ private OpenLPController controller;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.i(LOG_TAG, "onCreate");
+
+ setContentView(R.layout.view_pager_layout);
+
+ controller = new OpenLPController(this);
+ pager = (ViewPager) findViewById(R.id.myViewPager);
+ pager.setAdapter(controller);
+
+ Intent intent = getIntent();
+ int selectedPage = intent.getIntExtra(OpenLPController.PAGE_KEY, 0);
+ Log.v(LOG_TAG, "Setting Page number: " + selectedPage);
+ pager.setOnPageChangeListener(controller.onPageChangeListener);
+ pager.setCurrentItem(selectedPage, true);
+ controller.onPageChangeListener.onPageSelected(selectedPage);
+ }
+
+ public void setCurrentPage(int page) {
+ pager.setCurrentItem(page, true);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ Log.v(LOG_TAG, "Destroying pagerActivity...");
+ unregisterReceiver(controller.apiCallReceiver);
+ stopService(controller.pingIntent);
+ }
+
+ private final String LOG_TAG = PagerActivity.class.getName();
}
=== 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 @@
package org.openlp.android.activity;
public interface Search {
- public final String ACTION = Search.class.getName().concat(".Action");
+ public final String ACTION = Search.class.getName().concat(".Action");
- public void searchPluginCall(String apiBase, String apiData);
+ public void searchPluginCall(String apiBase, String apiData);
}
=== 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 @@
import java.net.URISyntaxException;
public interface SearchService {
- public Intent getSearchPluginIntent(String apiBase, String apiData)
- throws JSONHandler.JSONHandlerException, IOException,
- URISyntaxException;
+ public Intent getSearchPluginIntent(String apiBase, String apiData)
+ throws JSONHandler.JSONHandlerException, IOException,
+ URISyntaxException;
}
=== 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 @@
import java.util.Map;
public class SearchableActivity extends Activity implements Api {
- private ExpandableListView listView;
- private final int DIALOG_ITEM_OPTIONS = 0;
- private Object dialogKey;
- private JSONArray dialogValue;
-
- private Search controller = new Search() {
- @Override
- public void searchPluginCall(String apiBase, String apiData) {
- Intent apiCallIntent =
- new Intent(SearchableActivity.this, ApiCallIntent.class);
- apiCallIntent.putExtra(apiBase, apiData);
- startService(apiCallIntent);
- }
- };
-
- BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d(LOG_TAG, String.format(
- "Search broadcast received: context(%s), intent(%s, %s)",
- context, intent, intent.getExtras()));
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.search);
- listView = (ExpandableListView) findViewById(R.id.list);
- listView.setOnChildClickListener(onChildClickListener);
-
- IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);
- apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
-
- registerReceiver(apiCallReceiver, apiCallFilter);
-
- Intent intent = getIntent();
- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
- String query = intent.getStringExtra(SearchManager.QUERY);
- doSearch(query);
- }
- }
-
- private ExpandableListView.OnChildClickListener onChildClickListener =
- new ExpandableListView.OnChildClickListener() {
- @Override
- public boolean onChildClick(ExpandableListView expandableListView,
- View view, int parent, int childPosition, long l) {
- @SuppressWarnings("unchecked") Map<String, JSONArray> child =
- (Map<String, JSONArray>) listView.getExpandableListAdapter()
- .getChild(parent, childPosition);
- dialogKey = null;
- dialogValue = null;
- dialogKey =
- listView.getExpandableListAdapter().getGroup(parent);
- dialogValue = child.get(dialogKey.toString());
- showDialog(DIALOG_ITEM_OPTIONS);
- return false;
- }
- };
-
- @Override
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DIALOG_ITEM_OPTIONS:
- AlertDialog.Builder dialogBuilder =
- new AlertDialog.Builder(SearchableActivity.this);
- dialogBuilder
- .setTitle(getString(R.string.dialogTitleItemOptions));
- dialogBuilder.setNegativeButton(
- getString(R.string.dialogNegativeSendLive),
- onClickListenerDialogSendLive);
- dialogBuilder.setPositiveButton(
- getString(R.string.dialogPositiveAddToService),
- onClickListenerDialogAddToService);
- return dialogBuilder.create();
- default:
- return null;
- }
- }
-
- DialogInterface.OnClickListener onClickListenerDialogSendLive =
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- controller.searchPluginCall(
- String.format(SEARCH_PLUGIN_LIVE, dialogKey),
- getDialogValue());
- }
- };
-
- DialogInterface.OnClickListener onClickListenerDialogAddToService =
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- controller.searchPluginCall(
- String.format(SEARCH_PLUGIN_ADD, dialogKey),
- getDialogValue());
- dialogInterface.cancel();
- }
- };
-
- private String getDialogValue() {
- try {
- return String.valueOf(dialogValue.get(0));
- }
- catch (JSONException e) {
- Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());
- Toast.makeText(SearchableActivity.this, e.getMessage(),
- Toast.LENGTH_LONG).show();
- return null;
- }
- }
-
- @Override
- protected void onPrepareDialog(int id, Dialog dialog) {
- try {
- dialog.setTitle(dialogValue.get(1).toString());
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
- }
-
- public void doSearch(String search) {
- new SearchAsync().execute(search);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unregisterReceiver(apiCallReceiver);
- }
-
- class SearchAsync extends AsyncTask<String, Void, SearchResults> {
- ProgressDialog progressDialog;
- String query;
-
- @Override
- protected SearchResults doInBackground(String... strings) {
- query = strings[0];
- List<String> groups = new ArrayList<String>();
- List<List<Map<String, JSONArray>>> children =
- new ArrayList<List<Map<String, JSONArray>>>();
- AsyncTask<String, Void, String> call =
- new WebCallReturningAsyncTask(SearchableActivity.this)
- .execute(SEARCHABLE_PLUGINS);
-
- try {
- JSONArray array =
- new JSONObject(call.get()).getJSONObject("results")
- .getJSONArray("items");
-
- for (int i = 0; i < array.length(); i++) {
- String pluginString =
- ((JSONArray) array.get(i)).get(0).toString();
- groups.add(pluginString);
-
- JSONArray resultArray = null;
-
- AsyncTask<String, Void, String> pluginResults =
- new WebCallReturningAsyncTask(SearchableActivity.this,
- String
- .format(SEARCH_PLUGIN_FORMATTED, pluginString))
- .execute(
- JSONHandler.createRequestJSON("text", query));
-
- List<Map<String, JSONArray>> list =
- new ArrayList<Map<String, JSONArray>>();
- if (pluginResults.get() != null &&
- pluginResults.get().trim().length() > 0) {
- resultArray = new JSONObject(pluginResults.get())
- .getJSONObject("results").getJSONArray("items");
- for (int j = 0; j < resultArray.length(); j++) {
- Map<String, JSONArray> item =
- new HashMap<String, JSONArray>();
- item.put(pluginString,
- (JSONArray) resultArray.get(j));
- list.add(item);
- }
- }
- children.add(list);
- }
- }
- catch (Exception e) {
- Log.e(LOG_TAG, e.toString());
- Toast.makeText(SearchableActivity.this, e.getMessage(),
- Toast.LENGTH_LONG).show();
- }
-
- SearchResults results = new SearchResults();
- results.setGroups(groups);
- results.setChildren(children);
- return results;
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- progressDialog = ProgressDialog.show(SearchableActivity.this, null,
- getString(R.string.searching));
- }
-
- @Override
- protected void onPostExecute(SearchResults results) {
- super.onPostExecute(results);
- listView.setAdapter(
- new GroupExpandableListAdapter(SearchableActivity.this,
- results.getGroups(), results.getChildren()));
- progressDialog.dismiss();
- Toast.makeText(SearchableActivity.this,
- String.format(getString(R.string.showingResults), query),
- Toast.LENGTH_SHORT).show();
- }
- }
-
- class SearchResults {
- List<String> groups;
- List<List<Map<String, JSONArray>>> children;
-
- public List<String> getGroups() {
- return groups;
- }
-
- public void setGroups(List<String> groups) {
- this.groups = groups;
- }
-
- public List<List<Map<String, JSONArray>>> getChildren() {
- return children;
- }
-
- public void setChildren(List<List<Map<String, JSONArray>>> children) {
- this.children = children;
- }
- }
-
- private final String LOG_TAG = this.getClass().getName();
+ private ExpandableListView listView;
+ private final int DIALOG_ITEM_OPTIONS = 0;
+ private Object dialogKey;
+ private JSONArray dialogValue;
+
+ private Search controller = new Search() {
+ @Override
+ public void searchPluginCall(String apiBase, String apiData) {
+ Intent apiCallIntent =
+ new Intent(SearchableActivity.this, ApiCallIntent.class);
+ apiCallIntent.putExtra(apiBase, apiData);
+ startService(apiCallIntent);
+ }
+ };
+
+ BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d(LOG_TAG, String.format(
+ "Search broadcast received: context(%s), intent(%s, %s)",
+ context, intent, intent.getExtras()));
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.search);
+ listView = (ExpandableListView) findViewById(R.id.list);
+ listView.setOnChildClickListener(onChildClickListener);
+
+ IntentFilter apiCallFilter = new IntentFilter(Search.ACTION);
+ apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
+
+ registerReceiver(apiCallReceiver, apiCallFilter);
+
+ Intent intent = getIntent();
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ doSearch(query);
+ }
+ }
+
+ private ExpandableListView.OnChildClickListener onChildClickListener =
+ new ExpandableListView.OnChildClickListener() {
+ @Override
+ public boolean onChildClick(ExpandableListView expandableListView,
+ View view, int parent, int childPosition, long l) {
+ @SuppressWarnings("unchecked") Map<String, JSONArray> child =
+ (Map<String, JSONArray>) listView.getExpandableListAdapter()
+ .getChild(parent, childPosition);
+ dialogKey = null;
+ dialogValue = null;
+ dialogKey =
+ listView.getExpandableListAdapter().getGroup(parent);
+ dialogValue = child.get(dialogKey.toString());
+ showDialog(DIALOG_ITEM_OPTIONS);
+ return false;
+ }
+ };
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_ITEM_OPTIONS:
+ AlertDialog.Builder dialogBuilder =
+ new AlertDialog.Builder(SearchableActivity.this);
+ dialogBuilder
+ .setTitle(getString(R.string.dialogTitleItemOptions));
+ dialogBuilder.setNegativeButton(
+ getString(R.string.dialogNegativeSendLive),
+ onClickListenerDialogSendLive);
+ dialogBuilder.setPositiveButton(
+ getString(R.string.dialogPositiveAddToService),
+ onClickListenerDialogAddToService);
+ return dialogBuilder.create();
+ default:
+ return null;
+ }
+ }
+
+ DialogInterface.OnClickListener onClickListenerDialogSendLive =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ controller.searchPluginCall(
+ String.format(SEARCH_PLUGIN_LIVE, dialogKey),
+ getDialogValue());
+ }
+ };
+
+ DialogInterface.OnClickListener onClickListenerDialogAddToService =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ controller.searchPluginCall(
+ String.format(SEARCH_PLUGIN_ADD, dialogKey),
+ getDialogValue());
+ dialogInterface.cancel();
+ }
+ };
+
+ private String getDialogValue() {
+ try {
+ return String.valueOf(dialogValue.get(0));
+ } catch (JSONException e) {
+ Log.e(LOG_TAG, "Could not get dialogValue: " + e.getMessage());
+ Toast.makeText(SearchableActivity.this, e.getMessage(),
+ Toast.LENGTH_LONG).show();
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPrepareDialog(int id, Dialog dialog) {
+ try {
+ dialog.setTitle(dialogValue.get(1).toString());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void doSearch(String search) {
+ new SearchAsync().execute(search);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(apiCallReceiver);
+ }
+
+ class SearchAsync extends AsyncTask<String, Void, SearchResults> {
+ ProgressDialog progressDialog;
+ String query;
+
+ @Override
+ protected SearchResults doInBackground(String... strings) {
+ query = strings[0];
+ List<String> groups = new ArrayList<String>();
+ List<List<Map<String, JSONArray>>> children =
+ new ArrayList<List<Map<String, JSONArray>>>();
+ AsyncTask<String, Void, String> call =
+ new WebCallReturningAsyncTask(SearchableActivity.this)
+ .execute(SEARCHABLE_PLUGINS);
+
+ try {
+ JSONArray array =
+ new JSONObject(call.get()).getJSONObject("results")
+ .getJSONArray("items");
+
+ for (int i = 0; i < array.length(); i++) {
+ String pluginString =
+ ((JSONArray) array.get(i)).get(0).toString();
+ groups.add(pluginString);
+
+ JSONArray resultArray = null;
+
+ AsyncTask<String, Void, String> pluginResults =
+ new WebCallReturningAsyncTask(SearchableActivity.this,
+ String
+ .format(SEARCH_PLUGIN_FORMATTED, pluginString))
+ .execute(
+ JSONHandler.createRequestJSON("text", query));
+
+ List<Map<String, JSONArray>> list =
+ new ArrayList<Map<String, JSONArray>>();
+ if (pluginResults.get() != null &&
+ pluginResults.get().trim().length() > 0) {
+ resultArray = new JSONObject(pluginResults.get())
+ .getJSONObject("results").getJSONArray("items");
+ for (int j = 0; j < resultArray.length(); j++) {
+ Map<String, JSONArray> item =
+ new HashMap<String, JSONArray>();
+ item.put(pluginString,
+ (JSONArray) resultArray.get(j));
+ list.add(item);
+ }
+ }
+ children.add(list);
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, e.toString());
+ Toast.makeText(SearchableActivity.this, e.getMessage(),
+ Toast.LENGTH_LONG).show();
+ }
+
+ SearchResults results = new SearchResults();
+ results.setGroups(groups);
+ results.setChildren(children);
+ return results;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ progressDialog = ProgressDialog.show(SearchableActivity.this, null,
+ getString(R.string.searching));
+ }
+
+ @Override
+ protected void onPostExecute(SearchResults results) {
+ super.onPostExecute(results);
+ listView.setAdapter(
+ new GroupExpandableListAdapter(SearchableActivity.this,
+ results.getGroups(), results.getChildren()));
+ progressDialog.dismiss();
+ Toast.makeText(SearchableActivity.this,
+ String.format(getString(R.string.showingResults), query),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ class SearchResults {
+ List<String> groups;
+ List<List<Map<String, JSONArray>>> children;
+
+ public List<String> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(List<String> groups) {
+ this.groups = groups;
+ }
+
+ public List<List<Map<String, JSONArray>>> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<List<Map<String, JSONArray>>> children) {
+ this.children = children;
+ }
+ }
+
+ private final String LOG_TAG = this.getClass().getName();
}
=== 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 @@
import org.openlp.android.R;
public class ConnectionPreferenceActivity extends PreferenceActivity {
- private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";
- private final String KEY_SERVER_ID = "keyServerId";
- private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
- private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
-
- private PreferenceScreen preferenceScreen = null;
- private boolean resume = true;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.empty_preferences);
- getPreferenceManager()
- .setSharedPreferencesName(getString(R.string.keySharedPreferences));
- preferenceScreen = getPreferenceScreen() == null
- ? getPreferenceManager().createPreferenceScreen(this)
- : getPreferenceScreen();
- preferenceScreen.removeAll();
- String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);
- if (preferenceDisplay != null
- && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
- constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
- } else {
- resume = false;
- constructOverviewScreen();
- }
- }
-
- private void constructOverviewScreen() {
- getPreferenceScreen().removeAll();
- Log.i(LOG_TAG, "constructOverviewScreen");
- Preference configPref = new Preference(this);
- configPref.setTitle(getString(R.string.connection_available_configurations));
- configPref.setSummary(getString(R.string.connection_add_by_menu));
- configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- int nextId = getNextPrefId(
- getHostConfigMap(
- getPreferenceManager()
- .getSharedPreferences().getAll()
- )
- );
- Preference newPreference = simpleClickablePreferenceFromHostConfig(
- new HostConfig(
- getString(R.string.connection_profile_server),
- nextId));
- newPreference.setTitle(getString(R.string.connection_profile_new_server));
- newPreference.setSummary(getString(R.string.connection_profile_not_saved));
- preferenceScreen.addPreference(newPreference);
- return true;
- }
- });
- preferenceScreen.addPreference(configPref);
- List<HostConfig> hostConfigs = getHostConfigs();
- if (!hostConfigs.isEmpty()) {
- for (final HostConfig config : getHostConfigs()) {
- preferenceScreen.addPreference(
- simpleClickablePreferenceFromHostConfig(config));
- }
- }
- }
-
- private void constructServerView(int hostId) {
- HostConfig hostConfig = hostConfigFromPreferencesForHostId(
- hostId,
- getHostConfigMap(
- getPreferenceManager()
- .getSharedPreferences()
- .getAll()
- )
- );
- addPreferenceCategory(preferenceScreen, hostConfig);
- }
-
- private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
- final Preference serverConfig = new Preference(this);
- serverConfig.setTitle(config.title.getSummary());
-
- Boolean useSsl = getPreferenceManager()
- .getSharedPreferences()
- .getBoolean(config.useSsl.getKey(), false);
-
- serverConfig.setSummary(String.format(
- "%s:%s %s",
- config.hostAddress.getText(),
- config.hostPort.getText(),
- useSsl ? "(SSL)" : "")
- );
- serverConfig.setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- Intent serverConfigIntent = new Intent(
- ConnectionPreferenceActivity.this,
- ConnectionPreferenceActivity.class
- );
- serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,
- PREFERENCE_DISPLAY_SERVER);
- serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
- startActivity(serverConfigIntent);
- return true;
- }
- });
- return serverConfig;
- }
-
- private List<HostConfig> getHostConfigs() {
- return hostConfigsFromPreferences(
- getHostConfigMap(
- getPreferenceManager()
- .getSharedPreferences()
- .getAll()
- )
- );
- }
-
- private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
- Map<String, Object> configMap = new TreeMap<String, Object>();
-
- List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
- Collections.sort(sortedKeys);
- for (String key : sortedKeys) {
- if (key.startsWith(HostConfig.KEY_PREFIX)) {
- configMap.put(key, preferences.get(key));
- }
- }
- return configMap;
- }
-
- private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
- List<Integer> hostIds = getHostIds(preferences);
- List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
- for (Integer id : hostIds) {
- hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
- }
- return hostConfigs;
- }
-
- private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
- Object titleValue = preferences.get(getHostConfigTitleKey(hostId));
- String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();
- HostConfig hostConfig = new HostConfig(
- hostTitle, hostId
- );
- Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
- String hostValue = hostValueObject == null
- ? getString(R.string.hostDefaultValue) : hostValueObject.toString();
- hostConfig.hostAddress.setText(hostValue);
- hostConfig.hostAddress.setSummary(hostValue);
-
- Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
- String portValue = portValueObject == null
- ? getString(R.string.portDefaultValue) : portValueObject.toString();
- hostConfig.hostPort.setText(portValue);
- hostConfig.hostPort.setSummary(portValue);
+ private final String KEY_PREFERENCE_DISPLAY = "preferenceDisplay";
+ private final String KEY_SERVER_ID = "keyServerId";
+ private final String PREFERENCE_DISPLAY_SERVER = "displayServer";
+ private final String LOG_TAG = ConnectionPreferenceActivity.class.getName();
+
+ private PreferenceScreen preferenceScreen = null;
+ private boolean resume = true;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.empty_preferences);
+ getPreferenceManager()
+ .setSharedPreferencesName(getString(R.string.keySharedPreferences));
+ preferenceScreen = getPreferenceScreen() == null
+ ? getPreferenceManager().createPreferenceScreen(this)
+ : getPreferenceScreen();
+ preferenceScreen.removeAll();
+ String preferenceDisplay = getIntent().getStringExtra(KEY_PREFERENCE_DISPLAY);
+ if (preferenceDisplay != null
+ && preferenceDisplay.equalsIgnoreCase(PREFERENCE_DISPLAY_SERVER)) {
+ constructServerView(getIntent().getIntExtra(KEY_SERVER_ID, 1));
+ } else {
+ resume = false;
+ constructOverviewScreen();
+ }
+ }
+
+ private void constructOverviewScreen() {
+ getPreferenceScreen().removeAll();
+ Log.i(LOG_TAG, "constructOverviewScreen");
+ Preference configPref = new Preference(this);
+ configPref.setTitle(getString(R.string.connection_available_configurations));
+ configPref.setSummary(getString(R.string.connection_add_by_menu));
+ configPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ int nextId = getNextPrefId(
+ getHostConfigMap(
+ getPreferenceManager()
+ .getSharedPreferences().getAll()
+ )
+ );
+ Preference newPreference = simpleClickablePreferenceFromHostConfig(
+ new HostConfig(
+ getString(R.string.connection_profile_server),
+ nextId));
+ newPreference.setTitle(getString(R.string.connection_profile_new_server));
+ newPreference.setSummary(getString(R.string.connection_profile_not_saved));
+ preferenceScreen.addPreference(newPreference);
+ return true;
+ }
+ });
+ preferenceScreen.addPreference(configPref);
+ List<HostConfig> hostConfigs = getHostConfigs();
+ if (!hostConfigs.isEmpty()) {
+ for (final HostConfig config : getHostConfigs()) {
+ preferenceScreen.addPreference(
+ simpleClickablePreferenceFromHostConfig(config));
+ }
+ }
+ }
+
+ private void constructServerView(int hostId) {
+ HostConfig hostConfig = hostConfigFromPreferencesForHostId(
+ hostId,
+ getHostConfigMap(
+ getPreferenceManager()
+ .getSharedPreferences()
+ .getAll()
+ )
+ );
+ addPreferenceCategory(preferenceScreen, hostConfig);
+ }
+
+ private Preference simpleClickablePreferenceFromHostConfig(final HostConfig config) {
+ final Preference serverConfig = new Preference(this);
+ serverConfig.setTitle(config.title.getSummary());
+
+ Boolean useSsl = getPreferenceManager()
+ .getSharedPreferences()
+ .getBoolean(config.useSsl.getKey(), false);
+
+ serverConfig.setSummary(String.format(
+ "%s:%s %s",
+ config.hostAddress.getText(),
+ config.hostPort.getText(),
+ useSsl ? "(SSL)" : "")
+ );
+ serverConfig.setOnPreferenceClickListener(
+ new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent serverConfigIntent = new Intent(
+ ConnectionPreferenceActivity.this,
+ ConnectionPreferenceActivity.class
+ );
+ serverConfigIntent.putExtra(KEY_PREFERENCE_DISPLAY,
+ PREFERENCE_DISPLAY_SERVER);
+ serverConfigIntent.putExtra(KEY_SERVER_ID, config.id);
+ startActivity(serverConfigIntent);
+ return true;
+ }
+ });
+ return serverConfig;
+ }
+
+ private List<HostConfig> getHostConfigs() {
+ return hostConfigsFromPreferences(
+ getHostConfigMap(
+ getPreferenceManager()
+ .getSharedPreferences()
+ .getAll()
+ )
+ );
+ }
+
+ private Map<String, ?> getHostConfigMap(Map<String, ?> preferences) {
+ Map<String, Object> configMap = new TreeMap<String, Object>();
+
+ List<String> sortedKeys = new ArrayList<String>(preferences.keySet());
+ Collections.sort(sortedKeys);
+ for (String key : sortedKeys) {
+ if (key.startsWith(HostConfig.KEY_PREFIX)) {
+ configMap.put(key, preferences.get(key));
+ }
+ }
+ return configMap;
+ }
+
+ private List<HostConfig> hostConfigsFromPreferences(Map<String, ?> preferences) {
+ List<Integer> hostIds = getHostIds(preferences);
+ List<HostConfig> hostConfigs = new ArrayList<HostConfig>();
+ for (Integer id : hostIds) {
+ hostConfigs.add(hostConfigFromPreferencesForHostId(id, preferences));
+ }
+ return hostConfigs;
+ }
+
+ private HostConfig hostConfigFromPreferencesForHostId(int hostId, Map<String, ?> preferences) {
+ Object titleValue = preferences.get(getHostConfigTitleKey(hostId));
+ String hostTitle = titleValue == null ? getString(R.string.connection_profile_server) : titleValue.toString();
+ HostConfig hostConfig = new HostConfig(
+ hostTitle, hostId
+ );
+ Object hostValueObject = preferences.get(hostConfig.hostAddress.getKey());
+ String hostValue = hostValueObject == null
+ ? getString(R.string.hostDefaultValue) : hostValueObject.toString();
+ hostConfig.hostAddress.setText(hostValue);
+ hostConfig.hostAddress.setSummary(hostValue);
+
+ Object portValueObject = preferences.get(hostConfig.hostPort.getKey());
+ String portValue = portValueObject == null
+ ? getString(R.string.portDefaultValue) : portValueObject.toString();
+ hostConfig.hostPort.setText(portValue);
+ hostConfig.hostPort.setSummary(portValue);
Object useridValueObject = preferences.get(hostConfig.userid.getKey());
String useridValue = useridValueObject == null
@@ -211,106 +211,106 @@
? getString(R.string.passwordDefaultValue) : passwordValueObject.toString();
hostConfig.password.setText(passwordValue);
hostConfig.password.setSummary(passwordValue);
- return hostConfig;
- }
-
- private int getNextPrefId(Map<String, ?> preferences) {
- int max = 0;
- for (String key : preferences.keySet()) {
- int prefValue = Integer.valueOf(key.split("\\.")[2]);
- max = prefValue > max ? prefValue : max;
- }
- return max + 1;
- }
-
- private List<Integer> getHostIds(Map<String, ?> preferences) {
- Set<Integer> hashSet = new HashSet<Integer>();
- for (String key : preferences.keySet()) {
- hashSet.add(Integer.valueOf(key.split("\\.")[2]));
- }
- List<Integer> hostIds = new ArrayList<Integer>(hashSet);
- Collections.sort(hostIds);
- Log.i(LOG_TAG, "Got HostIds: " + hostIds);
- return hostIds;
- }
-
- private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
- PreferenceCategory preferenceCategory = new PreferenceCategory(this);
- preferenceCategory.setTitle(hostConfig.title.getSummary());
- preferenceCategory.setKey("key.preference.category");
- preferenceScreen.addPreference(preferenceCategory);
- preferenceCategory.addPreference(hostConfig.title);
- preferenceCategory.addPreference(hostConfig.hostAddress);
- preferenceCategory.addPreference(hostConfig.hostPort);
- preferenceCategory.addPreference(hostConfig.useSsl);
+ return hostConfig;
+ }
+
+ private int getNextPrefId(Map<String, ?> preferences) {
+ int max = 0;
+ for (String key : preferences.keySet()) {
+ int prefValue = Integer.valueOf(key.split("\\.")[2]);
+ max = prefValue > max ? prefValue : max;
+ }
+ return max + 1;
+ }
+
+ private List<Integer> getHostIds(Map<String, ?> preferences) {
+ Set<Integer> hashSet = new HashSet<Integer>();
+ for (String key : preferences.keySet()) {
+ hashSet.add(Integer.valueOf(key.split("\\.")[2]));
+ }
+ List<Integer> hostIds = new ArrayList<Integer>(hashSet);
+ Collections.sort(hostIds);
+ Log.i(LOG_TAG, "Got HostIds: " + hostIds);
+ return hostIds;
+ }
+
+ private boolean addPreferenceCategory(PreferenceScreen preferenceScreen, HostConfig hostConfig) {
+ PreferenceCategory preferenceCategory = new PreferenceCategory(this);
+ preferenceCategory.setTitle(hostConfig.title.getSummary());
+ preferenceCategory.setKey("key.preference.category");
+ preferenceScreen.addPreference(preferenceCategory);
+ preferenceCategory.addPreference(hostConfig.title);
+ preferenceCategory.addPreference(hostConfig.hostAddress);
+ preferenceCategory.addPreference(hostConfig.hostPort);
+ preferenceCategory.addPreference(hostConfig.useSsl);
preferenceCategory.addPreference(hostConfig.userid);
preferenceCategory.addPreference(hostConfig.password);
- preferenceCategory.addPreference(hostConfig.remove);
- preferenceCategory.addPreference(hostConfig.activate);
- return true;
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (resume) {
- Log.i(LOG_TAG, "Resuming...");
- } else {
- constructOverviewScreen();
- Log.i(LOG_TAG, "Not resuming...");
- }
- }
-
- private static String getHostConfigTitleKey(int id) {
- return HostConfig.KEY_PREFIX + id + ".title";
- }
-
- private class HostConfig {
- static final String KEY_PREFIX = "host.config.";
- final int id;
- final EditTextPreference title;
- final EditTextPreference hostAddress;
- final EditTextPreference hostPort;
- final CheckBoxPreference useSsl;
+ preferenceCategory.addPreference(hostConfig.remove);
+ preferenceCategory.addPreference(hostConfig.activate);
+ return true;
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (resume) {
+ Log.i(LOG_TAG, "Resuming...");
+ } else {
+ constructOverviewScreen();
+ Log.i(LOG_TAG, "Not resuming...");
+ }
+ }
+
+ private static String getHostConfigTitleKey(int id) {
+ return HostConfig.KEY_PREFIX + id + ".title";
+ }
+
+ private class HostConfig {
+ static final String KEY_PREFIX = "host.config.";
+ final int id;
+ final EditTextPreference title;
+ final EditTextPreference hostAddress;
+ final EditTextPreference hostPort;
+ final CheckBoxPreference useSsl;
final EditTextPreference userid;
final EditTextPreference password;
- final Preference remove;
- final Preference activate;
-
- HostConfig(String sTitle, int id) {
- this.id = id;
- title = new EditTextPreference(ConnectionPreferenceActivity.this);
- title.setSummary(getString(R.string.url));
- title.getEditText().setHint(getString(R.string.url));
- title.setTitle(getString(R.string.connection_profile_title));
- title.setKey(KEY_PREFIX + id + ".title");
- title.setDefaultValue(getString(R.string.url));
- title.setSummary(sTitle);
- title.setDialogTitle(getString(R.string.connection_profile_title));
- title.setOnPreferenceChangeListener(onPreferenceChangeListener);
-
- hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
- hostAddress.setTitle(getString(R.string.urlHint));
- hostAddress.setKey(KEY_PREFIX + id + ".address");
- hostAddress.getEditText().setHint(R.string.urlHint);
- hostAddress.setSummary(getString(R.string.urlHint));
- hostAddress.setDialogTitle(getString(R.string.urlHint));
- hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
- hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
-
- hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
- hostPort.setTitle(getString(R.string.port));
- hostPort.setKey(KEY_PREFIX + id + ".port");
- hostPort.setSummary(getString(R.string.port));
- hostPort.setDialogTitle(getString(R.string.port));
- hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
- hostPort.setDefaultValue(getString(R.string.portDefaultValue));
- hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
-
- useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);
- useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
- useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
- useSsl.setKey(KEY_PREFIX + id + ".usessl");
+ final Preference remove;
+ final Preference activate;
+
+ HostConfig(String sTitle, int id) {
+ this.id = id;
+ title = new EditTextPreference(ConnectionPreferenceActivity.this);
+ title.setSummary(getString(R.string.url));
+ title.getEditText().setHint(getString(R.string.url));
+ title.setTitle(getString(R.string.connection_profile_title));
+ title.setKey(KEY_PREFIX + id + ".title");
+ title.setDefaultValue(getString(R.string.url));
+ title.setSummary(sTitle);
+ title.setDialogTitle(getString(R.string.connection_profile_title));
+ title.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+ hostAddress = new EditTextPreference(ConnectionPreferenceActivity.this);
+ hostAddress.setTitle(getString(R.string.urlHint));
+ hostAddress.setKey(KEY_PREFIX + id + ".address");
+ hostAddress.getEditText().setHint(R.string.urlHint);
+ hostAddress.setSummary(getString(R.string.urlHint));
+ hostAddress.setDialogTitle(getString(R.string.urlHint));
+ hostAddress.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
+ hostAddress.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+ hostPort = new EditTextPreference(ConnectionPreferenceActivity.this);
+ hostPort.setTitle(getString(R.string.port));
+ hostPort.setKey(KEY_PREFIX + id + ".port");
+ hostPort.setSummary(getString(R.string.port));
+ hostPort.setDialogTitle(getString(R.string.port));
+ hostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
+ hostPort.setDefaultValue(getString(R.string.portDefaultValue));
+ hostPort.setOnPreferenceChangeListener(onPreferenceChangeListener);
+
+ useSsl = new CheckBoxPreference(ConnectionPreferenceActivity.this);
+ useSsl.setTitle(getString(R.string.connection_profile_ssl_use));
+ useSsl.setSummary(getString(R.string.connection_profile_ssl_summary));
+ useSsl.setKey(KEY_PREFIX + id + ".usessl");
userid = new EditTextPreference(ConnectionPreferenceActivity.this);
userid.setSummary(getString(R.string.connection_userid));
@@ -332,92 +332,92 @@
password.setDialogTitle(getString(R.string.connection_password));
password.setOnPreferenceChangeListener(onPreferenceChangeListener);
- remove = new Preference(ConnectionPreferenceActivity.this);
- remove.setTitle(getString(R.string.connection_profile_remove));
- remove.setSummary(getString(R.string.connection_profile_remove_summary));
- remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- SharedPreferences.Editor editor = prefs.edit();
- editor.remove(hostAddress.getKey());
- editor.remove(hostPort.getKey());
- editor.remove(title.getKey());
- editor.remove(useSsl.getKey());
+ remove = new Preference(ConnectionPreferenceActivity.this);
+ remove.setTitle(getString(R.string.connection_profile_remove));
+ remove.setSummary(getString(R.string.connection_profile_remove_summary));
+ remove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.remove(hostAddress.getKey());
+ editor.remove(hostPort.getKey());
+ editor.remove(title.getKey());
+ editor.remove(useSsl.getKey());
editor.remove(userid.getKey());
editor.remove(password.getKey());
- editor.commit();
- ConnectionPreferenceActivity.this.onBackPressed();
- return false;
- }
- });
+ editor.commit();
+ ConnectionPreferenceActivity.this.onBackPressed();
+ return false;
+ }
+ });
- activate = new Preference(ConnectionPreferenceActivity.this);
- activate.setTitle(getString(R.string.connection_profile_activate));
- activate.setSummary(getString(R.string.connection_profile_summary_activate));
- activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
- SharedPreferences.Editor editor = preferences.edit();
- String host = preferences.getString(hostAddress.getKey(),
- getString(R.string.hostDefaultValue));
- editor.putString(getString(R.string.keyHost), host);
- String port = preferences.getString(hostPort.getKey(),
- getString(R.string.portDefaultValue));
- editor.putString(getString(R.string.keyPort), port);
- Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
- editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
+ activate = new Preference(ConnectionPreferenceActivity.this);
+ activate.setTitle(getString(R.string.connection_profile_activate));
+ activate.setSummary(getString(R.string.connection_profile_summary_activate));
+ activate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
+ SharedPreferences.Editor editor = preferences.edit();
+ String host = preferences.getString(hostAddress.getKey(),
+ getString(R.string.hostDefaultValue));
+ editor.putString(getString(R.string.keyHost), host);
+ String port = preferences.getString(hostPort.getKey(),
+ getString(R.string.portDefaultValue));
+ editor.putString(getString(R.string.keyPort), port);
+ Boolean bUseSsl = preferences.getBoolean(useSsl.getKey(), false);
+ editor.putBoolean(getString(R.string.key_ssl_use), bUseSsl);
String suserid = preferences.getString(userid.getKey(), getString(R.string.useridDefaultValue));
editor.putString(getString(R.string.key_userid), suserid);
String spassword = preferences.getString(password.getKey(),
getString(R.string.passwordDefaultValue));
editor.putString(getString(R.string.key_password), spassword);
- editor.putString(
- getString(R.string.key_profile_selected_title),
- preferences.getString(
- title.getKey(),
- getString(R.string.url)));
-
- editor.commit();
- Toast.makeText(ConnectionPreferenceActivity.this,
- String.format(
- "%s: %s\n[%s:%s] %s",
- getString(R.string.connection_profile_active_toast),
- HostConfig.this.title.getText(),
- host,
- port,
- useSsl.isChecked() ? "(SSL)" : ""
- ),
- Toast.LENGTH_LONG).show();
- return false;
- }
- });
- }
-
- @Override
- public String toString() {
- return "HostConfig{" +
- "id=" + id +
- ", title='" + title + '\'' +
- ", hostAddress=" + hostAddress.getKey() +
- ", hostPort=" + hostPort.getKey() +
- '}';
- }
-
- Preference.OnPreferenceChangeListener onPreferenceChangeListener =
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object o) {
- preference.setSummary("" + o);
- if (preference.getKey().endsWith(".title")) {
- preferenceScreen
- .findPreference("key.preference.category")
- .setTitle("" + o);
- }
- return true;
- }
- };
- }
+ editor.putString(
+ getString(R.string.key_profile_selected_title),
+ preferences.getString(
+ title.getKey(),
+ getString(R.string.url)));
+
+ editor.commit();
+ Toast.makeText(ConnectionPreferenceActivity.this,
+ String.format(
+ "%s: %s\n[%s:%s] %s",
+ getString(R.string.connection_profile_active_toast),
+ HostConfig.this.title.getText(),
+ host,
+ port,
+ useSsl.isChecked() ? "(SSL)" : ""
+ ),
+ Toast.LENGTH_LONG).show();
+ return false;
+ }
+ });
+ }
+
+ @Override
+ public String toString() {
+ return "HostConfig{" +
+ "id=" + id +
+ ", title='" + title + '\'' +
+ ", hostAddress=" + hostAddress.getKey() +
+ ", hostPort=" + hostPort.getKey() +
+ '}';
+ }
+
+ Preference.OnPreferenceChangeListener onPreferenceChangeListener =
+ new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object o) {
+ preference.setSummary("" + o);
+ if (preference.getKey().endsWith(".title")) {
+ preferenceScreen
+ .findPreference("key.preference.category")
+ .setTitle("" + o);
+ }
+ return true;
+ }
+ };
+ }
}
=== 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 @@
buildPreferences();
}
- private void buildPreferences() {
- if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
-
- getPreferenceManager()
- .setSharedPreferencesName(getString(R.string.keySharedPreferences));
-
- addPreferencesFromResource(R.xml.preferences);
- final SharedPreferences sharedPreferences = getPreferenceManager()
- .getSharedPreferences();
-
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(sharedPreferences.getString(
- getString(R.string.keyHost),
- getString(R.string.notSet)));
- stringBuilder.append(":");
-
- Boolean useSsl = sharedPreferences.getBoolean(
- getString(R.string.key_ssl_use), false);
- stringBuilder.append(
- String.format("%s %s",
- sharedPreferences.getString(
- getString(R.string.keyPort),
- getString(R.string.notSet)), useSsl ? "(SSL)" : ""));
-
- final Preference hostPreference = findPreference(getString(R.string.keyHost));
- hostPreference.setTitle(
- getPreferenceManager().getSharedPreferences()
- .getString(
- getString(R.string.key_profile_selected_title),
- getString(R.string.url)
- )
- );
- hostPreference.setSummary(stringBuilder.toString());
-
- PackageManager manager = this.getPackageManager();
- String version = "";
- try {
- PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
- version = info.versionName;
- } catch (PackageManager.NameNotFoundException ignored) {}
-
- String date = new SimpleDateFormat("yyyy").format(new Date());
-
- //Preferences time! (we build the preferences)
- Preference about = getPreference(getString(R.string.about_text), version, null);
- about.setSelectable(false);
- Preference openlpLink = getPreference(
- getString(R.string.about_display_3),
- getString(R.string.about_display_1),
- new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));
-
- StringBuilder html = new StringBuilder();
- html.append(getString(R.string.about_display_4));
- html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
- html.append(getString(R.string.about_display_5));
- html.append(" © 2004-").append(date);
- html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
-
- Preference copyright = getPreference(
- getString(R.string.about_display_4),
- html.toString(), null);
- copyright.setSelectable(false);
-
- DialogPreference license = new MyDialogPreference(
- this,
- getString(R.string.about_display_6),
- String.format(
- "%s\n%s",
- getString(R.string.about_display_7),
- getString(R.string.about_display_8)
- )
- );
-
-
- PreferenceScreen preferenceScreen = getPreferenceScreen();
- addPreferenceCategory(preferenceScreen,getString(R.string.about),
- about, openlpLink, copyright, license);
-
- Preference preference = findPreference(getString(R.string.keyHost));
- preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
- }
+ private void buildPreferences() {
+ if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
+
+ getPreferenceManager()
+ .setSharedPreferencesName(getString(R.string.keySharedPreferences));
+
+ addPreferencesFromResource(R.xml.preferences);
+ final SharedPreferences sharedPreferences = getPreferenceManager()
+ .getSharedPreferences();
+
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(sharedPreferences.getString(
+ getString(R.string.keyHost),
+ getString(R.string.notSet)));
+ stringBuilder.append(":");
+
+ Boolean useSsl = sharedPreferences.getBoolean(
+ getString(R.string.key_ssl_use), false);
+ stringBuilder.append(
+ String.format("%s %s",
+ sharedPreferences.getString(
+ getString(R.string.keyPort),
+ getString(R.string.notSet)), useSsl ? "(SSL)" : ""));
+
+ final Preference hostPreference = findPreference(getString(R.string.keyHost));
+ hostPreference.setTitle(
+ getPreferenceManager().getSharedPreferences()
+ .getString(
+ getString(R.string.key_profile_selected_title),
+ getString(R.string.url)
+ )
+ );
+ hostPreference.setSummary(stringBuilder.toString());
+
+ PackageManager manager = this.getPackageManager();
+ String version = "";
+ try {
+ PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
+ version = info.versionName;
+ } catch (PackageManager.NameNotFoundException ignored) {
+ }
+
+ String date = new SimpleDateFormat("yyyy").format(new Date());
+
+ //Preferences time! (we build the preferences)
+ Preference about = getPreference(getString(R.string.about_text), version, null);
+ about.setSelectable(false);
+ Preference openlpLink = getPreference(
+ getString(R.string.about_display_3),
+ getString(R.string.about_display_1),
+ new Intent(Intent.ACTION_VIEW, Uri.parse("http://openlp.org/")));
+
+ StringBuilder html = new StringBuilder();
+ html.append(getString(R.string.about_display_4));
+ html.append(" © 2004-").append(date).append(" Raoul Snyman\n");
+ html.append(getString(R.string.about_display_5));
+ html.append(" © 2004-").append(date);
+ html.append("\nTim Bentley, Johan Mynhardt, Samuel Sjöbergsson");
+
+ Preference copyright = getPreference(
+ getString(R.string.about_display_4),
+ html.toString(), null);
+ copyright.setSelectable(false);
+
+ DialogPreference license = new MyDialogPreference(
+ this,
+ getString(R.string.about_display_6),
+ String.format(
+ "%s\n%s",
+ getString(R.string.about_display_7),
+ getString(R.string.about_display_8)
+ )
+ );
+
+
+ PreferenceScreen preferenceScreen = getPreferenceScreen();
+ addPreferenceCategory(preferenceScreen, getString(R.string.about),
+ about, openlpLink, copyright, license);
+
+ Preference preference = findPreference(getString(R.string.keyHost));
+ preference.setIntent(new Intent(this, ConnectionPreferenceActivity.class));
+ }
private boolean addPreferenceCategory(PreferenceScreen preferenceScreen,
- String titleCategory, Preference... preferences) {
-
- boolean addPreference = false;
-
- for (Preference preference : preferences) {
+ String titleCategory, Preference... preferences) {
+
+ boolean addPreference = false;
+
+ for (Preference preference : preferences) {
if (preference != null)
addPreference = true;
}
- if (addPreference) {
+ if (addPreference) {
PreferenceCategory preferenceCategory = new PreferenceCategory(this);
preferenceCategory.setTitle(titleCategory);
preferenceScreen.addPreference(preferenceCategory);
@@ -178,12 +179,12 @@
Log.d(LOG_TAG, "Destroying preferences");
}
- @Override
- protected void onResume() {
- super.onResume();
- Log.i(LOG_TAG, "Resuming Preferences...");
- buildPreferences();
- }
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Log.i(LOG_TAG, "Resuming Preferences...");
+ buildPreferences();
+ }
- private final String LOG_TAG = Preferences.class.getName();
+ private final String LOG_TAG = Preferences.class.getName();
}
=== 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 @@
public interface Api {
- public final String LIVE_BASE = "/api/controller/live/";
- public final String LIVE_NEXT = "/api/controller/live/next";
- public final String LIVE_PREVIOUS = "/api/controller/live/previous";
- public final String LIVE_TEXT = "/api/controller/live/text";
- public final String LIVE_SET = "/api/controller/live/set?data=";
-
- /** Use with {@link #SERVICE_BASE} + (previous|next) */
- public final String SERVICE_BASE = "/api/service/";
- // todo: cleanup, use {@link #SERVICE_BASE}
- public final String SERVICE_LIST = "/api/service/list";
- public final String SERVICE_SET = "/api/service/set?data=";
-
- /** Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show) */
- public final String DISPLAY_BASE = "/api/display/";
- public final String POLL_STATUS = "/api/poll";
-
- public final String ALERT = "/api/alert?data=";
-
- public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
- /**
- * This is a special string that uses the String.format() method. See
- * {@link String#format(String, Object...)}
- */
- public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
- /** Match intent extra key with regex since multiple plugins can be inserted */
- public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
- /** Match intent extra key with regex since multiple plugins can be inserted */
- public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
+ public final String LIVE_BASE = "/api/controller/live/";
+ public final String LIVE_NEXT = "/api/controller/live/next";
+ public final String LIVE_PREVIOUS = "/api/controller/live/previous";
+ public final String LIVE_TEXT = "/api/controller/live/text";
+ public final String LIVE_SET = "/api/controller/live/set?data=";
+
+ /**
+ * Use with {@link #SERVICE_BASE} + (previous|next)
+ */
+ public final String SERVICE_BASE = "/api/service/";
+ // todo: cleanup, use {@link #SERVICE_BASE}
+ public final String SERVICE_LIST = "/api/service/list";
+ public final String SERVICE_SET = "/api/service/set?data=";
+
+ /**
+ * Use with {@link #DISPLAY_BASE} + (blank|theme|desktop|show)
+ */
+ public final String DISPLAY_BASE = "/api/display/";
+ public final String POLL_STATUS = "/api/poll";
+
+ public final String ALERT = "/api/alert?data=";
+
+ public final String SEARCHABLE_PLUGINS = "/api/plugin/search";
+ /**
+ * This is a special string that uses the String.format() method. See
+ * {@link String#format(String, Object...)}
+ */
+ public final String SEARCH_PLUGIN_FORMATTED = "/api/%s/search?data=";
+ /**
+ * Match intent extra key with regex since multiple plugins can be inserted
+ */
+ public final String SEARCH_PLUGIN_ADD = "/api/%s/add?data=";
+ /**
+ * Match intent extra key with regex since multiple plugins can be inserted
+ */
+ public final String SEARCH_PLUGIN_LIVE = "/api/%s/live?data=";
}
=== 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 @@
public class Poll {
- private int slide;
- private String item;
- private int service = -1;
- private boolean twelveHourDisplay = false;
- private boolean blankedDisplayed = false;
- private boolean themeDisplayed = false;
- private boolean desktopDisplayed = false;
- private boolean displayHidden = false;
-
- public int getSlide() {
- return slide;
- }
-
- public void setSlide(int slide) {
- this.slide = slide;
- }
-
- public String getItem() {
- return item;
- }
-
- public void setItem(String item) {
- this.item = item;
- }
-
- public boolean isTwelveHourDisplay() {
- return twelveHourDisplay;
- }
-
- public void setTwelveHourDisplay(boolean twelveHourDisplay) {
- this.twelveHourDisplay = twelveHourDisplay;
- }
-
- public boolean isBlankedDisplayed() {
- return blankedDisplayed;
- }
-
- public void setBlankedDisplayed(boolean blankedDisplayed) {
- this.blankedDisplayed = blankedDisplayed;
- if (blankedDisplayed) {
- this.displayHidden = true;
- }
- }
-
- public boolean isThemeDisplayed() {
- return themeDisplayed;
- }
-
- public void setThemeDisplayed(boolean themeDisplayed) {
- this.themeDisplayed = themeDisplayed;
- if (themeDisplayed) {
- this.displayHidden = true;
- }
- }
-
- public boolean isDesktopDisplayed() {
- return desktopDisplayed;
- }
-
- public void setDesktopDisplayed(boolean desktopDisplayed) {
- this.desktopDisplayed = desktopDisplayed;
- if (desktopDisplayed) {
- this.displayHidden = true;
- }
- }
-
- public boolean isDisplayHidden() {
- return displayHidden;
- }
-
- public void setDisplayHidden(boolean displayHidden) {
- this.displayHidden = displayHidden;
- }
-
- public int getService() {
- return service;
- }
-
- public void setService(int service) {
- this.service = service;
- }
-
- @Override
- public String toString() {
- return "Poll{" +
- "slide=" + slide +
- ", item='" + item + '\'' +
- ", service=" + service +
- ", twelveHourDisplay=" + twelveHourDisplay +
- ", blankedDisplayed=" + blankedDisplayed +
- ", themeDisplayed=" + themeDisplayed +
- ", desktopDisplayed=" + desktopDisplayed +
- ", displayHidden=" + displayHidden +
- '}';
- }
+ private int slide;
+ private String item;
+ private int service = -1;
+ private boolean twelveHourDisplay = false;
+ private boolean blankedDisplayed = false;
+ private boolean themeDisplayed = false;
+ private boolean desktopDisplayed = false;
+ private boolean displayHidden = false;
+
+ public int getSlide() {
+ return slide;
+ }
+
+ public void setSlide(int slide) {
+ this.slide = slide;
+ }
+
+ public String getItem() {
+ return item;
+ }
+
+ public void setItem(String item) {
+ this.item = item;
+ }
+
+ public boolean isTwelveHourDisplay() {
+ return twelveHourDisplay;
+ }
+
+ public void setTwelveHourDisplay(boolean twelveHourDisplay) {
+ this.twelveHourDisplay = twelveHourDisplay;
+ }
+
+ public boolean isBlankedDisplayed() {
+ return blankedDisplayed;
+ }
+
+ public void setBlankedDisplayed(boolean blankedDisplayed) {
+ this.blankedDisplayed = blankedDisplayed;
+ if (blankedDisplayed) {
+ this.displayHidden = true;
+ }
+ }
+
+ public boolean isThemeDisplayed() {
+ return themeDisplayed;
+ }
+
+ public void setThemeDisplayed(boolean themeDisplayed) {
+ this.themeDisplayed = themeDisplayed;
+ if (themeDisplayed) {
+ this.displayHidden = true;
+ }
+ }
+
+ public boolean isDesktopDisplayed() {
+ return desktopDisplayed;
+ }
+
+ public void setDesktopDisplayed(boolean desktopDisplayed) {
+ this.desktopDisplayed = desktopDisplayed;
+ if (desktopDisplayed) {
+ this.displayHidden = true;
+ }
+ }
+
+ public boolean isDisplayHidden() {
+ return displayHidden;
+ }
+
+ public void setDisplayHidden(boolean displayHidden) {
+ this.displayHidden = displayHidden;
+ }
+
+ public int getService() {
+ return service;
+ }
+
+ public void setService(int service) {
+ this.service = service;
+ }
+
+ @Override
+ public String toString() {
+ return "Poll{" +
+ "slide=" + slide +
+ ", item='" + item + '\'' +
+ ", service=" + service +
+ ", twelveHourDisplay=" + twelveHourDisplay +
+ ", blankedDisplayed=" + blankedDisplayed +
+ ", themeDisplayed=" + themeDisplayed +
+ ", desktopDisplayed=" + desktopDisplayed +
+ ", displayHidden=" + displayHidden +
+ '}';
+ }
}
=== 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 @@
package org.openlp.android.data;
public class SlideItem {
- private String text;
- private boolean selected;
- private String tag;
- private String html;
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public boolean isSelected() {
- return selected;
- }
-
- public void setSelected(boolean selected) {
- this.selected = selected;
- }
-
- public String getTag() {
- return tag;
- }
-
- public void setTag(String tag) {
- this.tag = tag;
- }
-
- public String getHtml() {
- return html;
- }
-
- public void setHtml(String html) {
- this.html = html;
- }
-
- @Override
- public String toString() {
- return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected
- + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';
- }
+ private String text;
+ private boolean selected;
+ private String tag;
+ private String html;
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public boolean isSelected() {
+ return selected;
+ }
+
+ public void setSelected(boolean selected) {
+ this.selected = selected;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public String getHtml() {
+ return html;
+ }
+
+ public void setHtml(String html) {
+ this.html = html;
+ }
+
+ @Override
+ public String toString() {
+ return "SlidePOJO{" + "text='" + text + '\'' + ", selected=" + selected
+ + ", tag='" + tag + '\'' + ", html='" + html + '\'' + '}';
+ }
}
=== 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 @@
public class PingIntent extends Service {
- private Handler handler = new Handler();
- private Integer delay;
-
- public PingIntent() {
- super();
- Log.v(LOG_TAG, "Instantiating PingIntent...");
-
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- @Override
- public void onStart(Intent intent, int startId) {
- String PREFERENCES_KEY =
- getApplicationContext().getString(R.string.keySharedPreferences);
- SharedPreferences preferences = getApplicationContext()
- .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);
- Resources resources = getApplicationContext().getResources();
- delay = Integer.valueOf(
- resources.getString(R.string.backgroundRefreshDefaultValue));
- Log.v(LOG_TAG, "Starting PingIntent...");
- super.onStart(intent, startId);
- delay = Integer.parseInt(preferences
- .getString(resources.getString(R.string.keyBackgroundService),
- delay.toString()));
-
- Log.d(LOG_TAG, "PingIntent delay: " + delay);
- handler.removeCallbacks(r);
- handler.postDelayed(r, delay);
- }
-
- Runnable r = new Runnable() {
-
- @Override
- public void run() {
- Intent apiCallPingIntent =
- new Intent(getApplicationContext(), ApiCallIntent.class);
- apiCallPingIntent.putExtra(Api.POLL_STATUS, "");
- startService(apiCallPingIntent);
- if (delay > 0) {
- handler.postDelayed(r, delay);
+ private Handler handler = new Handler();
+ private Integer delay;
+
+ public PingIntent() {
+ super();
+ Log.v(LOG_TAG, "Instantiating PingIntent...");
+
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+ String PREFERENCES_KEY =
+ getApplicationContext().getString(R.string.keySharedPreferences);
+ SharedPreferences preferences = getApplicationContext()
+ .getSharedPreferences(PREFERENCES_KEY, MODE_PRIVATE);
+ Resources resources = getApplicationContext().getResources();
+ delay = Integer.valueOf(
+ resources.getString(R.string.backgroundRefreshDefaultValue));
+ Log.v(LOG_TAG, "Starting PingIntent...");
+ super.onStart(intent, startId);
+ delay = Integer.parseInt(preferences
+ .getString(resources.getString(R.string.keyBackgroundService),
+ delay.toString()));
+
+ Log.d(LOG_TAG, "PingIntent delay: " + delay);
+ handler.removeCallbacks(r);
+ handler.postDelayed(r, delay);
+ }
+
+ Runnable r = new Runnable() {
+
+ @Override
+ public void run() {
+ Intent apiCallPingIntent =
+ new Intent(getApplicationContext(), ApiCallIntent.class);
+ apiCallPingIntent.putExtra(Api.POLL_STATUS, "");
+ startService(apiCallPingIntent);
+ if (delay > 0) {
+ handler.postDelayed(r, delay);
+ }
}
- }
- };
-
- @Override
- public void onDestroy() {
- Log.v(LOG_TAG, "Stopping PingIntent...");
- handler.removeCallbacks(r);
- super.onDestroy();
- }
-
- private static final String LOG_TAG = PingIntent.class.getName();
+ };
+
+ @Override
+ public void onDestroy() {
+ Log.v(LOG_TAG, "Stopping PingIntent...");
+ handler.removeCallbacks(r);
+ super.onDestroy();
+ }
+
+ private static final String LOG_TAG = PingIntent.class.getName();
}
=== 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 @@
import java.util.Map;
public class GroupExpandableListAdapter extends BaseExpandableListAdapter {
- List<String> groups;
- List<List<Map<String, JSONArray>>> children;
- LayoutInflater inflater;
- Activity context;
-
- public GroupExpandableListAdapter(Activity context, List<String> groups,
- List<List<Map<String, JSONArray>>> children) {
- this.context = context;
- this.groups = groups;
- this.children = children;
- inflater = context.getLayoutInflater();
- }
-
- @Override
- public int getGroupCount() {
- return groups.size();
- }
-
- @Override
- public int getChildrenCount(int position) {
- return children.get(position).size();
- }
-
- @Override
- public Object getGroup(int position) {
- return groups.get(position);
- }
-
- @Override
- public Object getChild(int rootPosition, int childPosition) {
- return children.get(rootPosition).get(childPosition);
- }
-
- @Override
- public long getGroupId(int position) {
- return groups.indexOf(groups.get(position));
- }
-
- @Override
- public long getChildId(int i, int i1) {
- List<Map<String, JSONArray>> child = children.get(i);
- return child.indexOf(child.get(i1));
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
- }
-
- @Override
- public View getGroupView(int position, boolean b, View view,
- ViewGroup viewGroup) {
- if (view == null) {
- view = inflater.inflate(R.layout.group_parent, null);
- view.setClickable(false);
- }
- TextView textView = (TextView) view.findViewById(R.id.groupParentText);
- TextView numberView = (TextView) view
- .findViewById(R.id.parentChildCount);
- numberView.setText(String.format("%s", children.get(position).size()));
- textView.setText(groups.get(position));
- return view;
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition, boolean b,
- View view, ViewGroup viewGroup) {
- if (view == null) {
- view = inflater.inflate(R.layout.group_child, null);
- view.setClickable(false);
- }
- TextView childView = (TextView) view.findViewById(R.id.groupChildText);
- List<Map<String, JSONArray>> childItem = children.get(groupPosition);
- Map<String, JSONArray> mapItem = childItem.get(childPosition);
- JSONArray jsonItem = mapItem.get(groups.get(groupPosition));
- try {
- childView.setText(String.format("%s", jsonItem.get(1)));
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
- return view;
- }
-
- @Override
- public boolean isChildSelectable(int i, int i1) {
- return true;
- }
+ List<String> groups;
+ List<List<Map<String, JSONArray>>> children;
+ LayoutInflater inflater;
+ Activity context;
+
+ public GroupExpandableListAdapter(Activity context, List<String> groups,
+ List<List<Map<String, JSONArray>>> children) {
+ this.context = context;
+ this.groups = groups;
+ this.children = children;
+ inflater = context.getLayoutInflater();
+ }
+
+ @Override
+ public int getGroupCount() {
+ return groups.size();
+ }
+
+ @Override
+ public int getChildrenCount(int position) {
+ return children.get(position).size();
+ }
+
+ @Override
+ public Object getGroup(int position) {
+ return groups.get(position);
+ }
+
+ @Override
+ public Object getChild(int rootPosition, int childPosition) {
+ return children.get(rootPosition).get(childPosition);
+ }
+
+ @Override
+ public long getGroupId(int position) {
+ return groups.indexOf(groups.get(position));
+ }
+
+ @Override
+ public long getChildId(int i, int i1) {
+ List<Map<String, JSONArray>> child = children.get(i);
+ return child.indexOf(child.get(i1));
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public View getGroupView(int position, boolean b, View view,
+ ViewGroup viewGroup) {
+ if (view == null) {
+ view = inflater.inflate(R.layout.group_parent, null);
+ view.setClickable(false);
+ }
+ TextView textView = (TextView) view.findViewById(R.id.groupParentText);
+ TextView numberView = (TextView) view
+ .findViewById(R.id.parentChildCount);
+ numberView.setText(String.format("%s", children.get(position).size()));
+ textView.setText(groups.get(position));
+ return view;
+ }
+
+ @Override
+ public View getChildView(int groupPosition, int childPosition, boolean b,
+ View view, ViewGroup viewGroup) {
+ if (view == null) {
+ view = inflater.inflate(R.layout.group_child, null);
+ view.setClickable(false);
+ }
+ TextView childView = (TextView) view.findViewById(R.id.groupChildText);
+ List<Map<String, JSONArray>> childItem = children.get(groupPosition);
+ Map<String, JSONArray> mapItem = childItem.get(childPosition);
+ JSONArray jsonItem = mapItem.get(groups.get(groupPosition));
+ try {
+ childView.setText(String.format("%s", jsonItem.get(1)));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return view;
+ }
+
+ @Override
+ public boolean isChildSelectable(int i, int i1) {
+ return true;
+ }
}
=== 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 @@
public class JSONHandler {
- public static String createRequestJSON(String key, String value)
- throws JSONHandlerException {
- try {
- String responseJSON;
- JSONObject jo = new JSONObject();
- jo.put(key, value);
- responseJSON = new JSONStringer().object().key("request").value(jo)
- .endObject().toString();
- responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
- return responseJSON;
- }
- catch (JSONException e) {
- throw new JSONHandlerException(e);
- }
- catch (UnsupportedEncodingException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static List<SlideItem> parseServiceItemResponseJSON(
- HttpEntity entity)
- throws JSONHandlerException {
- try {
- List<SlideItem> serviceItemList;
- InputStream inputStream = entity.getContent();
- String result = StringHelper.convertStreamToString(inputStream);
- Log.v(LOG_TAG, result);
- serviceItemList = getServiceItemsFromString(result);
- inputStream.close();
- return serviceItemList;
- }
- catch (IOException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static List<SlideItem> getServiceItemsFromString(String itemsJson)
- throws JSONHandlerException {
- try {
- List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
- JSONObject jObject = new JSONObject(itemsJson);
- JSONObject results = jObject.getJSONObject("results");
- JSONArray items = results.getJSONArray("items");
-
- for (int i = 0; i < items.length(); i++) {
- JSONObject item = items.getJSONObject(i);
- SlideItem slide = new SlideItem();
- slide.setTag("");
- slide.setText(item.getString("title"));
- slide.setSelected(item.getBoolean("selected"));
- slide.setHtml("");
- serviceItemList.add(slide);
- }
- return serviceItemList;
- }
- catch (JSONException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)
- throws JSONHandlerException {
- try {
- List<SlideItem> serviceItemList;
- InputStream inputStream = entity.getContent();
- String result = StringHelper.convertStreamToString(inputStream);
- Log.v(LOG_TAG, result);
- serviceItemList = getSlideItemsFromString(result);
- inputStream.close();
- return serviceItemList;
- }
- catch (IOException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static List<SlideItem> getSlideItemsFromString(String itemJson)
- throws JSONHandlerException {
- try {
- JSONObject jObject = new JSONObject(itemJson);
- JSONObject results = jObject.getJSONObject("results");
- JSONArray items = results.getJSONArray("slides");
-
- List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
- for (int i = 0; i < items.length(); i++) {
- JSONObject item = items.getJSONObject(i);
- SlideItem slide = new SlideItem();
- slide.setText(item.getString("text"));
- slide.setTag(item.getString("tag"));
- slide.setSelected(item.getBoolean("selected"));
- slide.setHtml(item.getString("html"));
- serviceItemList.add(slide);
- }
- return serviceItemList;
- }
- catch (JSONException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static Poll getPollFromString(String pollJson)
- throws JSONHandlerException {
- Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));
- try {
- JSONObject jObject = new JSONObject(pollJson);
- JSONObject results = jObject.getJSONObject("results");
- Poll poll = new Poll();
- poll.setSlide(results.getInt("slide"));
- poll.setItem(results.getString("item"));
- poll.setTwelveHourDisplay(results.getBoolean("twelve"));
- poll.setBlankedDisplayed(results.getBoolean("blank"));
- poll.setThemeDisplayed(results.getBoolean("theme"));
- poll.setDesktopDisplayed(results.getBoolean("display"));
- if (!results.has("service")) {
- Log.w(LOG_TAG,
- "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");
- }
- poll.setService(
- results.has("service") ? results.getInt("service") : -1);
- return poll;
- }
- catch (JSONException e) {
- throw new JSONHandlerException(e);
- }
- }
-
- public static class JSONHandlerException extends Exception {
- private static final long serialVersionUID = -6772307308404816615L;
-
- public JSONHandlerException(Throwable throwable) {
- super(throwable);
- }
- }
-
- private static String LOG_TAG = JSONHandler.class.getName();
+ public static String createRequestJSON(String key, String value)
+ throws JSONHandlerException {
+ try {
+ String responseJSON;
+ JSONObject jo = new JSONObject();
+ jo.put(key, value);
+ responseJSON = new JSONStringer().object().key("request").value(jo)
+ .endObject().toString();
+ responseJSON = URLEncoder.encode(responseJSON, "UTF-8");
+ return responseJSON;
+ } catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ } catch (UnsupportedEncodingException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static List<SlideItem> parseServiceItemResponseJSON(
+ HttpEntity entity)
+ throws JSONHandlerException {
+ try {
+ List<SlideItem> serviceItemList;
+ InputStream inputStream = entity.getContent();
+ String result = StringHelper.convertStreamToString(inputStream);
+ Log.v(LOG_TAG, result);
+ serviceItemList = getServiceItemsFromString(result);
+ inputStream.close();
+ return serviceItemList;
+ } catch (IOException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static List<SlideItem> getServiceItemsFromString(String itemsJson)
+ throws JSONHandlerException {
+ try {
+ List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
+ JSONObject jObject = new JSONObject(itemsJson);
+ JSONObject results = jObject.getJSONObject("results");
+ JSONArray items = results.getJSONArray("items");
+
+ for (int i = 0; i < items.length(); i++) {
+ JSONObject item = items.getJSONObject(i);
+ SlideItem slide = new SlideItem();
+ slide.setTag("");
+ slide.setText(item.getString("title"));
+ slide.setSelected(item.getBoolean("selected"));
+ slide.setHtml("");
+ serviceItemList.add(slide);
+ }
+ return serviceItemList;
+ } catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static List<SlideItem> parseSlideItemResponseJSON(HttpEntity entity)
+ throws JSONHandlerException {
+ try {
+ List<SlideItem> serviceItemList;
+ InputStream inputStream = entity.getContent();
+ String result = StringHelper.convertStreamToString(inputStream);
+ Log.v(LOG_TAG, result);
+ serviceItemList = getSlideItemsFromString(result);
+ inputStream.close();
+ return serviceItemList;
+ } catch (IOException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static List<SlideItem> getSlideItemsFromString(String itemJson)
+ throws JSONHandlerException {
+ try {
+ JSONObject jObject = new JSONObject(itemJson);
+ JSONObject results = jObject.getJSONObject("results");
+ JSONArray items = results.getJSONArray("slides");
+
+ List<SlideItem> serviceItemList = new ArrayList<SlideItem>();
+ for (int i = 0; i < items.length(); i++) {
+ JSONObject item = items.getJSONObject(i);
+ SlideItem slide = new SlideItem();
+ slide.setText(item.getString("text"));
+ slide.setTag(item.getString("tag"));
+ slide.setSelected(item.getBoolean("selected"));
+ slide.setHtml(item.getString("html"));
+ serviceItemList.add(slide);
+ }
+ return serviceItemList;
+ } catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static Poll getPollFromString(String pollJson)
+ throws JSONHandlerException {
+ Log.v(LOG_TAG, String.format("parsePollResponseJSON: " + pollJson));
+ try {
+ JSONObject jObject = new JSONObject(pollJson);
+ JSONObject results = jObject.getJSONObject("results");
+ Poll poll = new Poll();
+ poll.setSlide(results.getInt("slide"));
+ poll.setItem(results.getString("item"));
+ poll.setTwelveHourDisplay(results.getBoolean("twelve"));
+ poll.setBlankedDisplayed(results.getBoolean("blank"));
+ poll.setThemeDisplayed(results.getBoolean("theme"));
+ poll.setDesktopDisplayed(results.getBoolean("display"));
+ if (!results.has("service")) {
+ Log.w(LOG_TAG,
+ "Current OpenLP too old. Missing \"service\" (OpenLP < 1941)");
+ }
+ poll.setService(
+ results.has("service") ? results.getInt("service") : -1);
+ return poll;
+ } catch (JSONException e) {
+ throw new JSONHandlerException(e);
+ }
+ }
+
+ public static class JSONHandlerException extends Exception {
+ private static final long serialVersionUID = -6772307308404816615L;
+
+ public JSONHandlerException(Throwable throwable) {
+ super(throwable);
+ }
+ }
+
+ private static String LOG_TAG = JSONHandler.class.getName();
}
=== 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 @@
public class OpenLPController extends PagerAdapter {
- private static Activity context;
- private ListView listViewService;
- private ListView listViewLive;
- private int currentService = -1;
- private int currentLive = -1;
- private String itemId = "";
-
- private static int currentPage = 0;
-
- public static final String PAGE_KEY = "openlp.pageKey";
- public static final int PAGE_SERVICE = 0;
- public static final int PAGE_LIVE = 1;
- public static final int PAGE_DISPLAY = 2;
- public static final int PAGE_STAGE = 3;
- public static final int PAGE_ALERT = 4;
- public static final int PAGE_SEARCH = 5;
-
- private String displayType;
- private WebView webView;
- private SharedPreferences preferences;
-
- public Intent pingIntent;
- public Intent apiCallIntent;
-
- public OpenLPController(Activity context) {
- OpenLPController.context = context;
- preferences = context.getApplicationContext().getSharedPreferences(
- context.getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE);
- pingIntent = new Intent(context, PingIntent.class);
- apiCallIntent = new Intent(context, ApiCallIntent.class);
-
- IntentFilter apiCallFilter =
- new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);
- apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
- context.registerReceiver(apiCallReceiver, apiCallFilter);
- }
-
- public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context broadcastedContext, Intent intent) {
- Log.v(LOG_TAG, String
- .format("%s broadcast received: intent(%s), context(%s)",
- ApiCallIntent.API_CALL_RECEIVE, intent,
- broadcastedContext));
- if (intent.hasExtra("error")) {
- context.stopService(pingIntent);
- Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +
- intent.getStringExtra("error"));
- Toast.makeText(broadcastedContext, String
- .format("%s: %s", context.getString(R.string.requestFailed),
- intent.getStringExtra("error")), Toast.LENGTH_LONG)
- .show();
- }
- else {
- if (intent.hasExtra("apiBase")) {
- String apiBase = intent.getStringExtra("apiBase");
- if (apiBase.equals(Api.ALERT)) {
- Toast.makeText(broadcastedContext, "Alert sent!",
- Toast.LENGTH_SHORT).show();
- }
- if (apiBase.equals(Api.DISPLAY_BASE)) {
- controller.poll();
- }
- if (apiBase.equals(Api.POLL_STATUS)) {
- handlePollResponse(intent.getStringExtra("pollJson"));
- }
- if (apiBase.equals(Api.LIVE_TEXT)) {
- handleLiveItemsResponse(
- intent.getStringExtra("itemsJson"));
- }
- if (apiBase.equals(Api.SERVICE_LIST)) {
- handleServiceItemsResponse(
- intent.getStringExtra("itemsJson"));
- }
- }
- }
- }
- };
-
- private void handlePollResponse(final String pollResponse) {
- try {
-
- Poll poll = JSONHandler.getPollFromString(pollResponse);
- if (poll != null) {
- if (currentPage == PAGE_DISPLAY) {
- setDisplayFromPoll(poll);
- }
- else {
- setServiceOrLiveFromPoll(poll);
- }
- }
- else {
- Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");
- }
- }
- catch (JSONHandler.JSONHandlerException e) {
- Log.e(LOG_TAG, e.toString());
- Toast.makeText(context, String.format("%s: %s",
- context.getString(R.string.couldNotHandlePollResponse),
- e.getMessage()), Toast.LENGTH_LONG).show();
- }
- }
-
- private void setDisplayFromPoll(Poll poll) {
- final ToggleButton toggleButton = (ToggleButton)
- context.findViewById(R.id.toggleDisplayButton);
- if (poll == null) {
- toggleButton.setEnabled(false);
- }
- else {
- String onText;
- String offText;
-
- displayType = getDisplayType();
- Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType
- + " " + poll.isDisplayHidden());
- if (displayType.equals(context.getString(R.string.displayScreen))) {
- Log.v(LOG_TAG, "Blank called");
- onText = context.getString(R.string.displayScreen);
- offText = context.getString(R.string.displayScreen);
- }
- else if (displayType
- .equals(context.getString(R.string.displayTheme))) {
- Log.v(LOG_TAG, "Theme called");
- onText = context.getString(R.string.displayTheme);
- offText = context.getString(R.string.displayTheme);
- }
- else {
- Log.v(LOG_TAG, "Desktop called");
- onText = context.getString(R.string.displayDesktop);
- offText = context.getString(R.string.displayDesktop);
- }
- /*
+ private static Activity context;
+ private ListView listViewService;
+ private ListView listViewLive;
+ private int currentService = -1;
+ private int currentLive = -1;
+ private String itemId = "";
+
+ private static int currentPage = 0;
+
+ public static final String PAGE_KEY = "openlp.pageKey";
+ public static final int PAGE_SERVICE = 0;
+ public static final int PAGE_LIVE = 1;
+ public static final int PAGE_DISPLAY = 2;
+ public static final int PAGE_STAGE = 3;
+ public static final int PAGE_ALERT = 4;
+ public static final int PAGE_SEARCH = 5;
+
+ private String displayType;
+ private WebView webView;
+ private SharedPreferences preferences;
+
+ public Intent pingIntent;
+ public Intent apiCallIntent;
+
+ public OpenLPController(Activity context) {
+ OpenLPController.context = context;
+ preferences = context.getApplicationContext().getSharedPreferences(
+ context.getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE);
+ pingIntent = new Intent(context, PingIntent.class);
+ apiCallIntent = new Intent(context, ApiCallIntent.class);
+
+ IntentFilter apiCallFilter =
+ new IntentFilter(ApiCallIntent.API_CALL_RECEIVE);
+ apiCallFilter.addCategory(Intent.CATEGORY_DEFAULT);
+ context.registerReceiver(apiCallReceiver, apiCallFilter);
+ }
+
+ public final BroadcastReceiver apiCallReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context broadcastedContext, Intent intent) {
+ Log.v(LOG_TAG, String
+ .format("%s broadcast received: intent(%s), context(%s)",
+ ApiCallIntent.API_CALL_RECEIVE, intent,
+ broadcastedContext));
+ if (intent.hasExtra("error")) {
+ context.stopService(pingIntent);
+ Log.w(LOG_TAG, "Stopping PingIntent. Got erroneous intent: " +
+ intent.getStringExtra("error"));
+ Toast.makeText(broadcastedContext, String
+ .format("%s: %s", context.getString(R.string.requestFailed),
+ intent.getStringExtra("error")), Toast.LENGTH_LONG)
+ .show();
+ } else {
+ if (intent.hasExtra("apiBase")) {
+ String apiBase = intent.getStringExtra("apiBase");
+ if (apiBase.equals(Api.ALERT)) {
+ Toast.makeText(broadcastedContext, "Alert sent!",
+ Toast.LENGTH_SHORT).show();
+ }
+ if (apiBase.equals(Api.DISPLAY_BASE)) {
+ controller.poll();
+ }
+ if (apiBase.equals(Api.POLL_STATUS)) {
+ handlePollResponse(intent.getStringExtra("pollJson"));
+ }
+ if (apiBase.equals(Api.LIVE_TEXT)) {
+ handleLiveItemsResponse(
+ intent.getStringExtra("itemsJson"));
+ }
+ if (apiBase.equals(Api.SERVICE_LIST)) {
+ handleServiceItemsResponse(
+ intent.getStringExtra("itemsJson"));
+ }
+ }
+ }
+ }
+ };
+
+ private void handlePollResponse(final String pollResponse) {
+ try {
+
+ Poll poll = JSONHandler.getPollFromString(pollResponse);
+ if (poll != null) {
+ if (currentPage == PAGE_DISPLAY) {
+ setDisplayFromPoll(poll);
+ } else {
+ setServiceOrLiveFromPoll(poll);
+ }
+ } else {
+ Log.w(LOG_TAG, "Parsed poll is null. This is not expected!");
+ }
+ } catch (JSONHandler.JSONHandlerException e) {
+ Log.e(LOG_TAG, e.toString());
+ Toast.makeText(context, String.format("%s: %s",
+ context.getString(R.string.couldNotHandlePollResponse),
+ e.getMessage()), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ private void setDisplayFromPoll(Poll poll) {
+ final ToggleButton toggleButton = (ToggleButton)
+ context.findViewById(R.id.toggleDisplayButton);
+ if (poll == null) {
+ toggleButton.setEnabled(false);
+ } else {
+ String onText;
+ String offText;
+
+ displayType = getDisplayType();
+ Log.d(LOG_TAG, "onPostExecute Display Type = " + displayType
+ + " " + poll.isDisplayHidden());
+ if (displayType.equals(context.getString(R.string.displayScreen))) {
+ Log.v(LOG_TAG, "Blank called");
+ onText = context.getString(R.string.displayScreen);
+ offText = context.getString(R.string.displayScreen);
+ } else if (displayType
+ .equals(context.getString(R.string.displayTheme))) {
+ Log.v(LOG_TAG, "Theme called");
+ onText = context.getString(R.string.displayTheme);
+ offText = context.getString(R.string.displayTheme);
+ } else {
+ Log.v(LOG_TAG, "Desktop called");
+ onText = context.getString(R.string.displayDesktop);
+ offText = context.getString(R.string.displayDesktop);
+ }
+ /*
Set display blanked to the off value to that of the screen
*/
- if (poll.isDisplayHidden()) {
- if (poll.isBlankedDisplayed()) {
- Log.v(LOG_TAG, "Hidden Blank called");
- onText = context.getString(R.string.displayScreen);
- }
- else if (poll.isThemeDisplayed()) {
- Log.v(LOG_TAG, "Hidden Theme called");
- onText = context.getString(R.string.displayTheme);
- }
- else {
- Log.v(LOG_TAG, "Hidden Desktop called");
- onText = context.getString(R.string.displayDesktop);
- }
- }
- toggleButton.setTextOn(
- context.getString(R.string.displayBlankOn) + " " + onText);
- toggleButton.setTextOff(
- context.getString(R.string.displayBlankOff) + " " + offText);
- toggleButton.setEnabled(true);
- toggleButton.setChecked(false);
- if (poll.isDisplayHidden()) {
- toggleButton.setChecked(true);
- }
- }
- }
-
- private void setServiceOrLiveFromPoll(Poll poll) {
- if (currentPage == PAGE_LIVE) {
- if (!itemId.equals(poll.getItem()) ||
- currentLive != poll.getSlide()) {
- Log.v(LOG_TAG, "Slide Changed. Polling update...");
- currentLive = poll.getSlide();
- itemId = poll.getItem();
- controller.fetchItems(Api.LIVE_TEXT);
- }
- }
- else if (currentPage == PAGE_SERVICE) {
- if (currentService < poll.getService()) {
- Log.v(LOG_TAG, "Service Changed. Polling update...");
- currentService = poll.getService();
- controller.fetchItems(Api.SERVICE_LIST);
- }
- }
- }
-
- private void handleLiveItemsResponse(final String itemsJson) {
- try {
- List<SlideItem> liveItems =
- JSONHandler.getSlideItemsFromString(itemsJson);
- listViewLive
- .setAdapter(new SlideAdapter(context, liveItems, currentLive));
+ if (poll.isDisplayHidden()) {
+ if (poll.isBlankedDisplayed()) {
+ Log.v(LOG_TAG, "Hidden Blank called");
+ onText = context.getString(R.string.displayScreen);
+ } else if (poll.isThemeDisplayed()) {
+ Log.v(LOG_TAG, "Hidden Theme called");
+ onText = context.getString(R.string.displayTheme);
+ } else {
+ Log.v(LOG_TAG, "Hidden Desktop called");
+ onText = context.getString(R.string.displayDesktop);
+ }
+ }
+ toggleButton.setTextOn(
+ context.getString(R.string.displayBlankOn) + " " + onText);
+ toggleButton.setTextOff(
+ context.getString(R.string.displayBlankOff) + " " + offText);
+ toggleButton.setEnabled(true);
+ toggleButton.setChecked(false);
+ if (poll.isDisplayHidden()) {
+ toggleButton.setChecked(true);
+ }
+ }
+ }
+
+ private void setServiceOrLiveFromPoll(Poll poll) {
+ if (currentPage == PAGE_LIVE) {
+ if (!itemId.equals(poll.getItem()) ||
+ currentLive != poll.getSlide()) {
+ Log.v(LOG_TAG, "Slide Changed. Polling update...");
+ currentLive = poll.getSlide();
+ itemId = poll.getItem();
+ controller.fetchItems(Api.LIVE_TEXT);
+ }
+ } else if (currentPage == PAGE_SERVICE) {
+ if (currentService < poll.getService()) {
+ Log.v(LOG_TAG, "Service Changed. Polling update...");
+ currentService = poll.getService();
+ controller.fetchItems(Api.SERVICE_LIST);
+ }
+ }
+ }
+
+ private void handleLiveItemsResponse(final String itemsJson) {
+ try {
+ List<SlideItem> liveItems =
+ JSONHandler.getSlideItemsFromString(itemsJson);
+ listViewLive
+ .setAdapter(new SlideAdapter(context, liveItems, currentLive));
listViewLive.setSelection(currentLive);
- }
- catch (JSONHandler.JSONHandlerException e) {
- Log.e(LOG_TAG, e.toString());
- Toast.makeText(context, String.format("%s: %s",
- context.getString(R.string.couldNotHandleLiveItems),
- e.getMessage()), Toast.LENGTH_LONG).show();
- }
- }
-
- private void handleServiceItemsResponse(final String itemsJson) {
- try {
- List<SlideItem> serviceItems =
- JSONHandler.getServiceItemsFromString(itemsJson);
- listViewService.setAdapter(
- new SlideAdapter(context, serviceItems, currentService));
- }
- catch (JSONHandler.JSONHandlerException e) {
- Log.e(LOG_TAG, e.toString());
- Toast.makeText(context, String.format("%s: %s",
- context.getString(R.string.couldNotHandleServiceItems),
- e.getMessage()), Toast.LENGTH_LONG).show();
- }
- }
-
- private OpenLPNavigate controller = new OpenLPNavigate() {
- @Override
- public void navigate(final String navigationRequest) {
- Intent navigationIntent = new Intent(context, ApiCallIntent.class);
- if (currentPage == PAGE_SERVICE) {
- navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);
- }
- if (currentPage == PAGE_LIVE) {
- navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);
- }
- context.startService(navigationIntent);
- }
-
- @Override
- public void setData(String apiPart, int id) {
- Intent setDataIntent = new Intent(context, ApiCallIntent.class);
- setDataIntent.putExtra(apiPart, id);
- context.startService(setDataIntent);
- }
-
- @Override
- public void setDisplay(String displayRequest) {
- Log.d(LOG_TAG, String
- .format("Setting Display: displayRequest(%s)", displayRequest));
- Intent displayIntent = new Intent(context, ApiCallIntent.class);
- displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);
- context.startService(displayIntent);
- }
-
- @Override
- public void poll() {
- Intent pollIntent = new Intent(context, ApiCallIntent.class);
- pollIntent.putExtra(Api.POLL_STATUS, "");
- context.startService(pollIntent);
- }
-
- @Override
- public void fetchItems(String apiPart) {
- Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);
- fetchItemsIntent.putExtra(apiPart, "");
- context.startService(fetchItemsIntent);
- }
- };
-
- @Override
- public Object instantiateItem(final ViewGroup container, int position) {
- LayoutInflater inflater = (LayoutInflater) container.getContext()
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- int res = 0;
- try {
- res = getLayoutForPosition(position);
- }
- catch (NoLayoutForPositionException e) {
- Log.e(LOG_TAG, e.getMessage());
- }
-
- View view = inflater.inflate(res, null);
-
- if (position == PAGE_SERVICE || position == PAGE_LIVE) {
- if (position == PAGE_SERVICE) {
- listViewService = (ListView) view.findViewById(R.id.list);
- listViewService
- .setOnItemClickListener(onItemClickListenerService);
- listViewService.setOnItemLongClickListener(
- adapterViewOnItemLongClickListener);
- }
-
- if (position == PAGE_LIVE) {
- listViewLive = (ListView) view.findViewById(R.id.list);
- listViewLive.setOnItemClickListener(onItemClickListenerSetLive);
- }
-
- view.findViewById(R.id.prev)
- .setOnClickListener(onClickListenerNavigate);
- view.findViewById(R.id.next)
- .setOnClickListener(onClickListenerNavigate);
- }
-
- if (position == PAGE_STAGE) {
- webView = getWebViewFromView(view);
- }
- if (position == PAGE_ALERT) {
- view.findViewById(R.id.send).setOnClickListener(mSend);
- }
- if (position == PAGE_DISPLAY) {
- view.findViewById(R.id.toggleDisplayButton)
- .setOnClickListener(onClickListenerToggleDisplay);
- }
-
- container.addView(view, 0);
- return view;
- }
-
- private WebView getWebViewFromView(View view) {
- WebView myWebView = (WebView) view.findViewById(R.id.stageview);
+ } catch (JSONHandler.JSONHandlerException e) {
+ Log.e(LOG_TAG, e.toString());
+ Toast.makeText(context, String.format("%s: %s",
+ context.getString(R.string.couldNotHandleLiveItems),
+ e.getMessage()), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ private void handleServiceItemsResponse(final String itemsJson) {
+ try {
+ List<SlideItem> serviceItems =
+ JSONHandler.getServiceItemsFromString(itemsJson);
+ listViewService.setAdapter(
+ new SlideAdapter(context, serviceItems, currentService));
+ } catch (JSONHandler.JSONHandlerException e) {
+ Log.e(LOG_TAG, e.toString());
+ Toast.makeText(context, String.format("%s: %s",
+ context.getString(R.string.couldNotHandleServiceItems),
+ e.getMessage()), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ private OpenLPNavigate controller = new OpenLPNavigate() {
+ @Override
+ public void navigate(final String navigationRequest) {
+ Intent navigationIntent = new Intent(context, ApiCallIntent.class);
+ if (currentPage == PAGE_SERVICE) {
+ navigationIntent.putExtra(Api.SERVICE_BASE, navigationRequest);
+ }
+ if (currentPage == PAGE_LIVE) {
+ navigationIntent.putExtra(Api.LIVE_BASE, navigationRequest);
+ }
+ context.startService(navigationIntent);
+ }
+
+ @Override
+ public void setData(String apiPart, int id) {
+ Intent setDataIntent = new Intent(context, ApiCallIntent.class);
+ setDataIntent.putExtra(apiPart, id);
+ context.startService(setDataIntent);
+ }
+
+ @Override
+ public void setDisplay(String displayRequest) {
+ Log.d(LOG_TAG, String
+ .format("Setting Display: displayRequest(%s)", displayRequest));
+ Intent displayIntent = new Intent(context, ApiCallIntent.class);
+ displayIntent.putExtra(Api.DISPLAY_BASE, displayRequest);
+ context.startService(displayIntent);
+ }
+
+ @Override
+ public void poll() {
+ Intent pollIntent = new Intent(context, ApiCallIntent.class);
+ pollIntent.putExtra(Api.POLL_STATUS, "");
+ context.startService(pollIntent);
+ }
+
+ @Override
+ public void fetchItems(String apiPart) {
+ Intent fetchItemsIntent = new Intent(context, ApiCallIntent.class);
+ fetchItemsIntent.putExtra(apiPart, "");
+ context.startService(fetchItemsIntent);
+ }
+ };
+
+ @Override
+ public Object instantiateItem(final ViewGroup container, int position) {
+ LayoutInflater inflater = (LayoutInflater) container.getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ int res = 0;
+ try {
+ res = getLayoutForPosition(position);
+ } catch (NoLayoutForPositionException e) {
+ Log.e(LOG_TAG, e.getMessage());
+ }
+
+ View view = inflater.inflate(res, null);
+
+ if (position == PAGE_SERVICE || position == PAGE_LIVE) {
+ if (position == PAGE_SERVICE) {
+ listViewService = (ListView) view.findViewById(R.id.list);
+ listViewService
+ .setOnItemClickListener(onItemClickListenerService);
+ listViewService.setOnItemLongClickListener(
+ adapterViewOnItemLongClickListener);
+ }
+
+ if (position == PAGE_LIVE) {
+ listViewLive = (ListView) view.findViewById(R.id.list);
+ listViewLive.setOnItemClickListener(onItemClickListenerSetLive);
+ }
+
+ view.findViewById(R.id.prev)
+ .setOnClickListener(onClickListenerNavigate);
+ view.findViewById(R.id.next)
+ .setOnClickListener(onClickListenerNavigate);
+ }
+
+ if (position == PAGE_STAGE) {
+ webView = getWebViewFromView(view);
+ }
+ if (position == PAGE_ALERT) {
+ view.findViewById(R.id.send).setOnClickListener(mSend);
+ }
+ if (position == PAGE_DISPLAY) {
+ view.findViewById(R.id.toggleDisplayButton)
+ .setOnClickListener(onClickListenerToggleDisplay);
+ }
+
+ container.addView(view, 0);
+ return view;
+ }
+
+ private WebView getWebViewFromView(View view) {
+ WebView myWebView = (WebView) view.findViewById(R.id.stageview);
/*
* Handle SSL self signed certificates and refresh the screen if the certificate
* page appears.
*/
myWebView.setWebViewClient(new WebViewClient() {
- public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
- handler.proceed() ;
- }
- } );
- WebSettings webSettings = myWebView.getSettings();
- webSettings.setJavaScriptEnabled(true);
- webSettings.setBuiltInZoomControls(true);
- webSettings.setLoadWithOverviewMode(true);
- webSettings.setUseWideViewPort(true);
- myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
- myWebView.setScrollbarFadingEnabled(true);
-
- myWebView.loadUrl(getUrlBase());
- return myWebView;
- }
-
- public static int getPageForButton(View view) {
- final int buttonId = view.getId();
- if (buttonId == R.id.buttonAlert) {
- return PAGE_ALERT;
- }
- if (buttonId == R.id.buttonDisplay) {
- return PAGE_DISPLAY;
- }
- if (buttonId == R.id.buttonLive) {
- return PAGE_LIVE;
- }
- if (buttonId == R.id.buttonSearch) {
- return PAGE_SEARCH;
- }
- if (buttonId == R.id.buttonService) {
- return PAGE_SERVICE;
- }
- if (buttonId == R.id.buttonStage) {
- return PAGE_STAGE;
- }
-
- Log.e(OpenLPController.class.getName(),
- "No Button connected to the requested view, with id: " + buttonId);
- return 0;
- }
-
- public ViewPager.OnPageChangeListener onPageChangeListener =
- new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int i, float v, int i1) {
- }
-
- @Override
- public void onPageSelected(int selectedPage) {
- Log.d(LOG_TAG, String
- .format("Selected Page: position(%s) title(%s)",
- selectedPage, getPageTitle(selectedPage)));
- currentPage = selectedPage;
-
- if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {
- context.startService(pingIntent);
- if (currentPage == PAGE_SERVICE) {
- controller.fetchItems(Api.SERVICE_LIST);
- }
- if (currentPage == PAGE_LIVE) {
- controller.fetchItems(Api.LIVE_TEXT);
- }
- }
- else {
- context.stopService(pingIntent);
- }
-
- if (currentPage == PAGE_STAGE) {
- if (webView == null) {
- webView = getWebViewFromView(context.getLayoutInflater()
- .inflate(R.layout.stageview, null));
- }
- }
-
- if (currentPage == PAGE_DISPLAY) {
- controller.poll();
- }
- }
-
- @Override
- public void onPageScrollStateChanged(int i) {
- }
- };
-
-
- @Override
- public CharSequence getPageTitle(int position) {
- String page = "none";
- switch (position) {
- case PAGE_SERVICE:
- page = context.getString(R.string.tabService);
- break;
- case PAGE_LIVE:
- page = context.getString(R.string.tabLive);
- break;
- case PAGE_DISPLAY:
- page = context.getString(R.string.tabDisplay);
- break;
- case PAGE_STAGE:
- page = context.getString(R.string.tabStage);
- break;
- case PAGE_ALERT:
- page = context.getString(R.string.tabAlert);
- break;
- case PAGE_SEARCH:
- page = context.getString(R.string.buttonSearchText);
- break;
- }
- return page;
- }
-
- private int getLayoutForPosition(int position)
- throws NoLayoutForPositionException {
- switch (position) {
- case PAGE_SERVICE:
- return R.layout.slide_service;
- case PAGE_LIVE:
- return R.layout.slide_service;
- case PAGE_DISPLAY:
- return R.layout.misc;
- case PAGE_STAGE:
- return R.layout.stageview;
- case PAGE_ALERT:
- return R.layout.alert;
- case PAGE_SEARCH:
- return R.layout.search;
- default:
- throw new NoLayoutForPositionException(
- "No Layout for position (" + position + ")");
- }
- }
-
- private AdapterView.OnItemClickListener onItemClickListenerSetLive =
- new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view,
- int i, long l) {
- controller.setData(Api.LIVE_SET, i);
- }
- };
-
- private AdapterView.OnItemLongClickListener
- adapterViewOnItemLongClickListener =
- new AdapterView.OnItemLongClickListener() {
- @Override
- public boolean onItemLongClick(AdapterView<?> adapterView,
- View view, int i, long l) {
- controller.setData(Api.SERVICE_SET, i);
- ((PagerActivity) context).setCurrentPage(PAGE_LIVE);
- return true;
- }
- };
-
- private ListView.OnItemClickListener onItemClickListenerService =
- new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view,
- int i, long l) {
- controller.setData(Api.SERVICE_SET, i);
- }
- };
-
- private Button.OnClickListener onClickListenerNavigate =
- new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.prev) {
- controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);
- }
- else if (v.getId() == R.id.next) {
- controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);
- }
- }
- };
-
- /**
- * Alert Button Listener
- */
- private Button.OnClickListener mSend = new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- EditText edittext = (EditText) context.findViewById(R.id.alert);
-
- if (edittext.getText().toString().trim().length() > 0) {
- apiCallIntent
- .putExtra(Api.ALERT, edittext.getText().toString());
- context.startService(apiCallIntent);
- }
- else {
- Toast.makeText(context,
- context.getString(R.string.alertTextNull),
- Toast.LENGTH_SHORT).show();
- }
- }
- };
-
- public View.OnClickListener onClickListenerToggleDisplay =
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- ToggleButton toggleButton = (ToggleButton) view;
-
- String displayType = getDisplayType();
- if (!toggleButton.isChecked()) {
- controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);
- }
- else {
- if (displayType
- .equals(context.getString(R.string.displayScreen))) {
- controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);
- }
- else if (displayType
- .equals(context.getString(R.string.displayTheme))) {
- controller.setDisplay(OpenLPNavigate.HIDE_THEME);
- }
- else {
- controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);
- }
- }
- }
- };
-
- @Override
- public int getCount() {
- return 5;
- }
-
- @Override
- public boolean isViewFromObject(View view, Object o) {
- return view == o;
- }
-
- @Override
- public void destroyItem(ViewGroup container, int position, Object object) {
- container.removeView((View) object);
- }
-
- private static final String LOG_TAG = OpenLPController.class.getName();
-
- private String getDisplayType() {
- displayType = preferences
- .getString(context.getString(R.string.keyDisplayBlankType),
- context.getString(R.string.displayTypeValue));
- return displayType;
- }
-
- private String getUrlBase() {
- Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
-
- return String.format("%s://%s:%s/stage",
- useSsl ? "https" : "http",
- preferences.getString(context.getString(R.string.keyHost),
- context.getString(R.string.hostDefaultValue)),
- preferences.getString(context.getString(R.string.keyPort),
- context.getString(R.string.portDefaultValue)));
- }
-
- class NoLayoutForPositionException extends Exception {
- NoLayoutForPositionException(String detailMessage) {
- super(detailMessage);
- }
- }
+ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
+ handler.proceed();
+ }
+ });
+ WebSettings webSettings = myWebView.getSettings();
+ webSettings.setJavaScriptEnabled(true);
+ webSettings.setBuiltInZoomControls(true);
+ webSettings.setLoadWithOverviewMode(true);
+ webSettings.setUseWideViewPort(true);
+ myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
+ myWebView.setScrollbarFadingEnabled(true);
+
+ myWebView.loadUrl(getUrlBase());
+ return myWebView;
+ }
+
+ public static int getPageForButton(View view) {
+ final int buttonId = view.getId();
+ if (buttonId == R.id.buttonAlert) {
+ return PAGE_ALERT;
+ }
+ if (buttonId == R.id.buttonDisplay) {
+ return PAGE_DISPLAY;
+ }
+ if (buttonId == R.id.buttonLive) {
+ return PAGE_LIVE;
+ }
+ if (buttonId == R.id.buttonSearch) {
+ return PAGE_SEARCH;
+ }
+ if (buttonId == R.id.buttonService) {
+ return PAGE_SERVICE;
+ }
+ if (buttonId == R.id.buttonStage) {
+ return PAGE_STAGE;
+ }
+
+ Log.e(OpenLPController.class.getName(),
+ "No Button connected to the requested view, with id: " + buttonId);
+ return 0;
+ }
+
+ public ViewPager.OnPageChangeListener onPageChangeListener =
+ new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int i, float v, int i1) {
+ }
+
+ @Override
+ public void onPageSelected(int selectedPage) {
+ Log.d(LOG_TAG, String
+ .format("Selected Page: position(%s) title(%s)",
+ selectedPage, getPageTitle(selectedPage)));
+ currentPage = selectedPage;
+
+ if (currentPage == PAGE_SERVICE || currentPage == PAGE_LIVE) {
+ context.startService(pingIntent);
+ if (currentPage == PAGE_SERVICE) {
+ controller.fetchItems(Api.SERVICE_LIST);
+ }
+ if (currentPage == PAGE_LIVE) {
+ controller.fetchItems(Api.LIVE_TEXT);
+ }
+ } else {
+ context.stopService(pingIntent);
+ }
+
+ if (currentPage == PAGE_STAGE) {
+ if (webView == null) {
+ webView = getWebViewFromView(context.getLayoutInflater()
+ .inflate(R.layout.stageview, null));
+ }
+ }
+
+ if (currentPage == PAGE_DISPLAY) {
+ controller.poll();
+ }
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int i) {
+ }
+ };
+
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ String page = "none";
+ switch (position) {
+ case PAGE_SERVICE:
+ page = context.getString(R.string.tabService);
+ break;
+ case PAGE_LIVE:
+ page = context.getString(R.string.tabLive);
+ break;
+ case PAGE_DISPLAY:
+ page = context.getString(R.string.tabDisplay);
+ break;
+ case PAGE_STAGE:
+ page = context.getString(R.string.tabStage);
+ break;
+ case PAGE_ALERT:
+ page = context.getString(R.string.tabAlert);
+ break;
+ case PAGE_SEARCH:
+ page = context.getString(R.string.buttonSearchText);
+ break;
+ }
+ return page;
+ }
+
+ private int getLayoutForPosition(int position)
+ throws NoLayoutForPositionException {
+ switch (position) {
+ case PAGE_SERVICE:
+ return R.layout.slide_service;
+ case PAGE_LIVE:
+ return R.layout.slide_service;
+ case PAGE_DISPLAY:
+ return R.layout.misc;
+ case PAGE_STAGE:
+ return R.layout.stageview;
+ case PAGE_ALERT:
+ return R.layout.alert;
+ case PAGE_SEARCH:
+ return R.layout.search;
+ default:
+ throw new NoLayoutForPositionException(
+ "No Layout for position (" + position + ")");
+ }
+ }
+
+ private AdapterView.OnItemClickListener onItemClickListenerSetLive =
+ new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view,
+ int i, long l) {
+ controller.setData(Api.LIVE_SET, i);
+ }
+ };
+
+ private AdapterView.OnItemLongClickListener
+ adapterViewOnItemLongClickListener =
+ new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> adapterView,
+ View view, int i, long l) {
+ controller.setData(Api.SERVICE_SET, i);
+ ((PagerActivity) context).setCurrentPage(PAGE_LIVE);
+ return true;
+ }
+ };
+
+ private ListView.OnItemClickListener onItemClickListenerService =
+ new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view,
+ int i, long l) {
+ controller.setData(Api.SERVICE_SET, i);
+ }
+ };
+
+ private Button.OnClickListener onClickListenerNavigate =
+ new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.prev) {
+ controller.navigate(OpenLPNavigate.NAVIGATE_PREVIOUS);
+ } else if (v.getId() == R.id.next) {
+ controller.navigate(OpenLPNavigate.NAVIGATE_NEXT);
+ }
+ }
+ };
+
+ /**
+ * Alert Button Listener
+ */
+ private Button.OnClickListener mSend = new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ EditText edittext = (EditText) context.findViewById(R.id.alert);
+
+ if (edittext.getText().toString().trim().length() > 0) {
+ apiCallIntent
+ .putExtra(Api.ALERT, edittext.getText().toString());
+ context.startService(apiCallIntent);
+ } else {
+ Toast.makeText(context,
+ context.getString(R.string.alertTextNull),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ };
+
+ public View.OnClickListener onClickListenerToggleDisplay =
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ ToggleButton toggleButton = (ToggleButton) view;
+
+ String displayType = getDisplayType();
+ if (!toggleButton.isChecked()) {
+ controller.setDisplay(OpenLPNavigate.DISPLAY_SHOW);
+ } else {
+ if (displayType
+ .equals(context.getString(R.string.displayScreen))) {
+ controller.setDisplay(OpenLPNavigate.HIDE_SCREEN);
+ } else if (displayType
+ .equals(context.getString(R.string.displayTheme))) {
+ controller.setDisplay(OpenLPNavigate.HIDE_THEME);
+ } else {
+ controller.setDisplay(OpenLPNavigate.HIDE_DESKTOP);
+ }
+ }
+ }
+ };
+
+ @Override
+ public int getCount() {
+ return 5;
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object o) {
+ return view == o;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ container.removeView((View) object);
+ }
+
+ private static final String LOG_TAG = OpenLPController.class.getName();
+
+ private String getDisplayType() {
+ displayType = preferences
+ .getString(context.getString(R.string.keyDisplayBlankType),
+ context.getString(R.string.displayTypeValue));
+ return displayType;
+ }
+
+ private String getUrlBase() {
+ Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
+
+ return String.format("%s://%s:%s/stage",
+ useSsl ? "https" : "http",
+ preferences.getString(context.getString(R.string.keyHost),
+ context.getString(R.string.hostDefaultValue)),
+ preferences.getString(context.getString(R.string.keyPort),
+ context.getString(R.string.portDefaultValue)));
+ }
+
+ class NoLayoutForPositionException extends Exception {
+ NoLayoutForPositionException(String detailMessage) {
+ super(detailMessage);
+ }
+ }
}
=== 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 @@
*/
public class OpenLPHttpClient extends DefaultHttpClient {
- private HttpGet httpGet;
- private URL url;
- private final String urlBase;
- private SSLSocketFactory sslSocketFactory;
+ private HttpGet httpGet;
+ private URL url;
+ private final String urlBase;
+ private SSLSocketFactory sslSocketFactory;
private Context context;
- public OpenLPHttpClient(Context context) {
- SharedPreferences preferences = context.getSharedPreferences(
- context.getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE);
- HttpParams httpParams = new BasicHttpParams();
+ public OpenLPHttpClient(Context context) {
+ SharedPreferences preferences = context.getSharedPreferences(
+ context.getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE);
+ HttpParams httpParams = new BasicHttpParams();
this.context = context;
- Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
-
- String port = preferences.getString(
- context.getString(R.string.keyPort),
- context.getString(R.string.portDefaultValue)
- );
-
- SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
- if (!useSsl) {
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
- } else {
- try {
- initSsl();
- schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
- } catch (NoSuchAlgorithmException e) {
- Log.e(LOG_TAG, e.toString());
- } catch (KeyManagementException e) {
- Log.e(LOG_TAG, e.toString());
- } catch (KeyStoreException e) {
- Log.e(LOG_TAG, e.toString());
- } catch (UnrecoverableKeyException e) {
- Log.e(LOG_TAG, e.toString());
- } catch (CertificateException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
+ Boolean useSsl = preferences.getBoolean(context.getString(R.string.key_ssl_use), false);
+
+ String port = preferences.getString(
+ context.getString(R.string.keyPort),
+ context.getString(R.string.portDefaultValue)
+ );
+
+ SchemeRegistry schemeRegistry = getConnectionManager().getSchemeRegistry();
+ if (!useSsl) {
+ schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(port)));
+ } else {
+ try {
+ initSsl();
+ schemeRegistry.register(new Scheme("https", sslSocketFactory, Integer.valueOf(port)));
+ } catch (NoSuchAlgorithmException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (KeyManagementException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (KeyStoreException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (UnrecoverableKeyException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (CertificateException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
String userid = preferences.getString(
context.getString(R.string.key_userid),
@@ -123,131 +123,131 @@
context.getString(R.string.passwordDefaultValue)
);
- Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
+ Log.d(LOG_TAG, "Credentials set to " + userid + " : " + password);
Credentials creds = new UsernamePasswordCredentials(userid, password);
getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);
urlBase = String.format("http%s://%s:%s",
- useSsl ? "s" : "",
- preferences.getString(
- context.getString(R.string.keyHost),
- context.getString(R.string.hostDefaultValue)), port);
-
- int connectionTimeout = context.getResources().getInteger(
- R.integer.connectionTimeoutDefaultValue);
- int socketTimeout = context.getResources().getInteger(
- R.integer.socketTimeoutDefaultValue);
-
- if (preferences.getBoolean(
- context.getString(R.string.keyEnableCustomTimeout), false)) {
- Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",
- context.getString(R.string.keyConnectionTimeout),
- context.getString(R.string.keySocketTimeout)));
- connectionTimeout = Integer.parseInt(preferences.getString(
- context.getString(R.string.keyConnectionTimeout),
- String.valueOf(context.getResources().getInteger(
- R.integer.connectionTimeoutDefaultValue))));
- socketTimeout = Integer.parseInt(preferences.getString(
- context.getString(R.string.keySocketTimeout),
- String.valueOf(context.getResources().getInteger(
- R.integer.socketTimeoutDefaultValue))));
- }
- HttpConnectionParams
- .setConnectionTimeout(httpParams, connectionTimeout);
- HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
- setParams(httpParams);
- httpGet = new HttpGet();
- }
-
- public URL getUrl() {
- return url;
- }
-
- public void setUrl(String apiPart) throws URISyntaxException,
- MalformedURLException {
- url = new URL(urlBase.concat(apiPart));
- try {
- Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());
- }
- httpGet.setURI(getUrl().toURI());
- }
-
- public HttpResponse execute() throws IOException {
- return super.execute(httpGet);
- }
-
- public HttpReturn handleExecute() throws IOException {
- HttpResponse response = this.execute();
+ useSsl ? "s" : "",
+ preferences.getString(
+ context.getString(R.string.keyHost),
+ context.getString(R.string.hostDefaultValue)), port);
+
+ int connectionTimeout = context.getResources().getInteger(
+ R.integer.connectionTimeoutDefaultValue);
+ int socketTimeout = context.getResources().getInteger(
+ R.integer.socketTimeoutDefaultValue);
+
+ if (preferences.getBoolean(
+ context.getString(R.string.keyEnableCustomTimeout), false)) {
+ Log.d(LOG_TAG, String.format("Retrieving values for %s and %s",
+ context.getString(R.string.keyConnectionTimeout),
+ context.getString(R.string.keySocketTimeout)));
+ connectionTimeout = Integer.parseInt(preferences.getString(
+ context.getString(R.string.keyConnectionTimeout),
+ String.valueOf(context.getResources().getInteger(
+ R.integer.connectionTimeoutDefaultValue))));
+ socketTimeout = Integer.parseInt(preferences.getString(
+ context.getString(R.string.keySocketTimeout),
+ String.valueOf(context.getResources().getInteger(
+ R.integer.socketTimeoutDefaultValue))));
+ }
+ HttpConnectionParams
+ .setConnectionTimeout(httpParams, connectionTimeout);
+ HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
+ setParams(httpParams);
+ httpGet = new HttpGet();
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public void setUrl(String apiPart) throws URISyntaxException,
+ MalformedURLException {
+ url = new URL(urlBase.concat(apiPart));
+ try {
+ Log.d(LOG_TAG, "URL set to: " + URLDecoder.decode(url.toString(), "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ Log.e(LOG_TAG, "Unable to decode url: " + e.getMessage());
+ }
+ httpGet.setURI(getUrl().toURI());
+ }
+
+ public HttpResponse execute() throws IOException {
+ return super.execute(httpGet);
+ }
+
+ public HttpReturn handleExecute() throws IOException {
+ HttpResponse response = this.execute();
Log.d(LOG_TAG, "Http response code " + String.valueOf(response.getStatusLine().getStatusCode()));
- if (response.getStatusLine().getStatusCode() == 200) {
- BufferedReader bufferedReader;
- HttpEntity entity = response.getEntity();
-
- if (entity != null) {
- bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
- StringBuilder stringBuilder = new StringBuilder();
-
- String line = bufferedReader.readLine();
- while (line != null) {
- stringBuilder.append(line);
- line = bufferedReader.readLine();
- }
- bufferedReader.close();
- return new HttpReturn(0, stringBuilder.toString(), this.context);
- }
- }
- return new HttpReturn(response.getStatusLine().getStatusCode() , null, this.context);
- }
-
- public HttpEntity handleAndReturnEntity() throws IOException {
- HttpResponse response = this.execute();
-
- if (response.getStatusLine().getStatusCode() == 200) {
- return response.getEntity();
- }
- return null;
- }
-
- private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
+ if (response.getStatusLine().getStatusCode() == 200) {
+ BufferedReader bufferedReader;
+ HttpEntity entity = response.getEntity();
+
+ if (entity != null) {
+ bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
+ StringBuilder stringBuilder = new StringBuilder();
+
+ String line = bufferedReader.readLine();
+ while (line != null) {
+ stringBuilder.append(line);
+ line = bufferedReader.readLine();
+ }
+ bufferedReader.close();
+ return new HttpReturn(0, stringBuilder.toString(), this.context);
+ }
+ }
+ return new HttpReturn(response.getStatusLine().getStatusCode(), null, this.context);
+ }
+
+ public HttpEntity handleAndReturnEntity() throws IOException {
+ HttpResponse response = this.execute();
+
+ if (response.getStatusLine().getStatusCode() == 200) {
+ return response.getEntity();
+ }
+ return null;
+ }
+
+ private void initSsl() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException,
UnrecoverableKeyException, IOException, CertificateException {
- final SSLContext sslContext = SSLContext.getInstance("TLS");
- X509TrustManager trustManager = new X509TrustManager() {
- @Override
- public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
- }
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- };
- sslContext.init(null, new TrustManager[]{trustManager}, null);
-
- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
- keyStore.load(null, null);
- sslSocketFactory = new SSLSocketFactory(keyStore) {
- @Override
- public Socket createSocket() throws IOException {
- return sslContext.getSocketFactory().createSocket();
- }
-
- @Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
+ final SSLContext sslContext = SSLContext.getInstance("TLS");
+ X509TrustManager trustManager = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ };
+ sslContext.init(null, new TrustManager[]{trustManager}, null);
+
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ keyStore.load(null, null);
+ sslSocketFactory = new SSLSocketFactory(keyStore) {
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
+
+ @Override
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
UnknownHostException {
- return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
- }
- };
- sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
- }
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+ };
+ sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ }
- private final String LOG_TAG = OpenLPHttpClient.class.getName();
+ private final String LOG_TAG = OpenLPHttpClient.class.getName();
}
=== 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 @@
import org.openlp.android.data.SlideItem;
public class SlideAdapter extends BaseAdapter {
- List<SlideItem> items;
- Activity context;
- LayoutInflater inflater;
- boolean useTagDisplay = true;
- private int[] colors = new int[] { 0x74717000, 0x00000000 };
- private int currentSlide = -1;
- SharedPreferences prefs;
-
- public SlideAdapter(Activity context, List<SlideItem> items, int slide) {
- this.context = context;
- this.items = items;
- this.currentSlide = slide;
- inflater = context.getLayoutInflater();
-
- prefs = context.getSharedPreferences(
- context.getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE);
- }
-
- public SlideAdapter(Activity context, List<SlideItem> items,
- boolean useTagDisplay) {
- this.context = context;
- this.items = items;
- this.useTagDisplay = useTagDisplay;
- inflater = context.getLayoutInflater();
-
- prefs = context.getSharedPreferences(
- context.getString(R.string.keySharedPreferences),
- Context.MODE_PRIVATE);
- }
-
- @Override
- public int getCount() {
- return items.size();
- }
-
- @Override
- public Object getItem(int i) {
- return items.get(i);
- }
-
- @Override
- public long getItemId(int i) {
- return items.indexOf(items.get(i));
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder holder;
- View view = convertView;
-
- SlideItem item = items.get(position);
-
- if (view == null) {
- view = inflater.inflate(R.layout.slide_list_item, null);
- holder = new ViewHolder();
-
- holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
- holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
-
- view.setTag(holder);
- }
- else {
- holder = (ViewHolder) view.getTag();
- }
-
- int size = Integer.parseInt(prefs.getString(
- context.getString(R.string.keyTextSize),
- String.valueOf(context.getResources().getInteger(
- R.integer.textSizeDefaultValue))));
-
- holder.rowMarker.setText(item.getTag());
- holder.rowItem.setText(item.getText());
- holder.rowItem.setTextSize(size);
-
- if (useTagDisplay) {
- holder.rowMarker.setMinWidth(40);
- }
- if (position == this.currentSlide) {
- holder.rowItem.setTextColor(Color.WHITE);
- view.setBackgroundColor(Color.argb(99, 200, 200, 200));
- } else {
- holder.rowItem.setTextColor(Color.LTGRAY);
- view.setBackgroundColor(colors[position % colors.length]);
- }
-
- return view;
- }
-
- static class ViewHolder {
- TextView rowMarker;
- TextView rowItem;
- }
-
- private final String LOG_TAG = SlideAdapter.class.getName();
+ List<SlideItem> items;
+ Activity context;
+ LayoutInflater inflater;
+ boolean useTagDisplay = true;
+ private int[] colors = new int[]{0x74717000, 0x00000000};
+ private int currentSlide = -1;
+ SharedPreferences prefs;
+
+ public SlideAdapter(Activity context, List<SlideItem> items, int slide) {
+ this.context = context;
+ this.items = items;
+ this.currentSlide = slide;
+ inflater = context.getLayoutInflater();
+
+ prefs = context.getSharedPreferences(
+ context.getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE);
+ }
+
+ public SlideAdapter(Activity context, List<SlideItem> items,
+ boolean useTagDisplay) {
+ this.context = context;
+ this.items = items;
+ this.useTagDisplay = useTagDisplay;
+ inflater = context.getLayoutInflater();
+
+ prefs = context.getSharedPreferences(
+ context.getString(R.string.keySharedPreferences),
+ Context.MODE_PRIVATE);
+ }
+
+ @Override
+ public int getCount() {
+ return items.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ return items.get(i);
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return items.indexOf(items.get(i));
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ View view = convertView;
+
+ SlideItem item = items.get(position);
+
+ if (view == null) {
+ view = inflater.inflate(R.layout.slide_list_item, null);
+ holder = new ViewHolder();
+
+ holder.rowMarker = (TextView) view.findViewById(R.id.rowItemMarker);
+ holder.rowItem = (TextView) view.findViewById(R.id.rowItemText);
+
+ view.setTag(holder);
+ } else {
+ holder = (ViewHolder) view.getTag();
+ }
+
+ int size = Integer.parseInt(prefs.getString(
+ context.getString(R.string.keyTextSize),
+ String.valueOf(context.getResources().getInteger(
+ R.integer.textSizeDefaultValue))));
+
+ holder.rowMarker.setText(item.getTag());
+ holder.rowItem.setText(item.getText());
+ holder.rowItem.setTextSize(size);
+
+ if (useTagDisplay) {
+ holder.rowMarker.setMinWidth(40);
+ }
+ if (position == this.currentSlide) {
+ holder.rowItem.setTextColor(Color.WHITE);
+ view.setBackgroundColor(Color.argb(99, 200, 200, 200));
+ } else {
+ holder.rowItem.setTextColor(Color.LTGRAY);
+ view.setBackgroundColor(colors[position % colors.length]);
+ }
+
+ return view;
+ }
+
+ static class ViewHolder {
+ TextView rowMarker;
+ TextView rowItem;
+ }
+
+ private final String LOG_TAG = SlideAdapter.class.getName();
}
=== 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 @@
* String helper utility to do common string processing.
*/
public class StringHelper {
- public synchronized static String convertStreamToString(InputStream is) {
- /*
+ public synchronized static String convertStreamToString(InputStream is) {
+ /*
* To convert the InputStream to String we use the
* BufferedReader.readLine() method. We iterate until the BufferedReader
* return null which means there's no more data to read. Each line will
* appended to a StringBuilder and returned as String.
*/
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
- String line = null;
- try {
- while ((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- finally {
- try {
- is.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
+ String line = null;
+ try {
+ while ((line = reader.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return sb.toString();
+ }
}
=== 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 @@
import java.io.InputStreamReader;
public class WebCallReturningAsyncTask extends AsyncTask<String, Void, String> {
- private Activity context;
- private String apiPart;
-
- public WebCallReturningAsyncTask(Activity context) {
- this.context = context;
- }
-
- public WebCallReturningAsyncTask(Activity context, String apiPart) {
- this.context = context;
- this.apiPart = apiPart;
- }
-
- @Override
- protected String doInBackground(String... apiCall) {
- OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
- HttpResponse response = null;
- BufferedReader bufferedReader = null;
-
- try {
- if (apiPart == null) {
- httpClient.setUrl(apiCall[0]);
- }
- else {
- httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
- }
-
- if (httpClient.getUrl().getHost().trim().length() <= 0) {
- context.startActivity(new Intent(context, Preferences.class));
- }
- else {
- response = httpClient.execute();
- }
-
- if (response != null
- && response.getStatusLine().getStatusCode() == 200) {
- HttpEntity entity = response.getEntity();
-
- if (entity != null) {
- bufferedReader = new BufferedReader(
- new InputStreamReader(entity.getContent()));
- StringBuilder stringBuilder = new StringBuilder();
-
- String line = bufferedReader.readLine();
- while (line != null) {
- stringBuilder.append(line);
- line = bufferedReader.readLine();
- }
-
- Log.i(LOG_TAG, String.format("entity: %s",
- stringBuilder.toString()));
- bufferedReader.close();
- return stringBuilder.toString();
- }
- }
- }
- catch (Exception e) {
- Log.e(LOG_TAG, e.toString());
- Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
- if (bufferedReader != null) {
- try {
- bufferedReader.close();
- }
- catch (IOException e1) {
- // do nothing as we are in an error state anyway
- }
- }
- }
- return null;
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
-
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- }
-
- private final String LOG_TAG = this.getClass().getName();
+ private Activity context;
+ private String apiPart;
+
+ public WebCallReturningAsyncTask(Activity context) {
+ this.context = context;
+ }
+
+ public WebCallReturningAsyncTask(Activity context, String apiPart) {
+ this.context = context;
+ this.apiPart = apiPart;
+ }
+
+ @Override
+ protected String doInBackground(String... apiCall) {
+ OpenLPHttpClient httpClient = new OpenLPHttpClient(context);
+ HttpResponse response = null;
+ BufferedReader bufferedReader = null;
+
+ try {
+ if (apiPart == null) {
+ httpClient.setUrl(apiCall[0]);
+ } else {
+ httpClient.setUrl(String.format("%s%s", apiPart, apiCall[0]));
+ }
+
+ if (httpClient.getUrl().getHost().trim().length() <= 0) {
+ context.startActivity(new Intent(context, Preferences.class));
+ } else {
+ response = httpClient.execute();
+ }
+
+ if (response != null
+ && response.getStatusLine().getStatusCode() == 200) {
+ HttpEntity entity = response.getEntity();
+
+ if (entity != null) {
+ bufferedReader = new BufferedReader(
+ new InputStreamReader(entity.getContent()));
+ StringBuilder stringBuilder = new StringBuilder();
+
+ String line = bufferedReader.readLine();
+ while (line != null) {
+ stringBuilder.append(line);
+ line = bufferedReader.readLine();
+ }
+
+ Log.i(LOG_TAG, String.format("entity: %s",
+ stringBuilder.toString()));
+ bufferedReader.close();
+ return stringBuilder.toString();
+ }
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, e.toString());
+ Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
+ if (bufferedReader != null) {
+ try {
+ bufferedReader.close();
+ } catch (IOException e1) {
+ // do nothing as we are in an error state anyway
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ }
+
+ @Override
+ protected void onPostExecute(String s) {
+ super.onPostExecute(s);
+ }
+
+ private final String LOG_TAG = this.getClass().getName();
}
Follow ups