diff --git a/app/src/main/java/org/openlp/android2/OpenLP.java b/app/src/main/java/org/openlp/android2/OpenLP.java index ee1dad7..b546c4b 100644 --- a/app/src/main/java/org/openlp/android2/OpenLP.java +++ b/app/src/main/java/org/openlp/android2/OpenLP.java @@ -35,11 +35,10 @@ import android.view.ViewGroup; import android.support.v4.widget.DrawerLayout; import org.openlp.android2.activities.ConnectionActivity; import org.openlp.android2.activities.SettingsActivity; +import org.openlp.android2.common.NavigationOptions; import org.openlp.android2.dialogs.AlertDisplayDialog; import org.openlp.android2.dialogs.BlankDisplayDialog; -import org.openlp.android2.fragments.LiveListFragment; -import org.openlp.android2.fragments.NavigationDrawerFragment; -import org.openlp.android2.fragments.ServiceListFragment; +import org.openlp.android2.fragments.*; public class OpenLP extends Activity @@ -75,27 +74,33 @@ public class OpenLP extends Activity // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); switch (position) { - case 0: + case NavigationOptions.Home: + fragmentManager.beginTransaction() + .replace(R.id.container, HomeFragment.newInstance()) + .commit(); + mTitle = getString(R.string.service_list); + break; + case NavigationOptions.ServiceList: fragmentManager.beginTransaction() .replace(R.id.container, ServiceListFragment.newInstance()) .commit(); mTitle = getString(R.string.service_list); break; - case 1: + case NavigationOptions.LiveList: fragmentManager.beginTransaction() .replace(R.id.container, LiveListFragment.newInstance()) .commit(); mTitle = getString(R.string.live_list); break; - case 2: + case NavigationOptions.StageView: fragmentManager.beginTransaction() - .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .replace(R.id.container, StageWebFragment.newInstance()) .commit(); mTitle = getString(R.string.stage_view); break; - case 3: + case NavigationOptions.LiveView: fragmentManager.beginTransaction() - .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .replace(R.id.container, LiveWebFragment.newInstance()) .commit(); mTitle = getString(R.string.live_view); break; @@ -104,6 +109,9 @@ public class OpenLP extends Activity public void onSectionAttached(int number) { switch (number) { + case 0: + mTitle = getString(R.string.service_list); + break; case 1: mTitle = getString(R.string.service_list); break; @@ -145,26 +153,30 @@ public class OpenLP extends Activity // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.action_preferences) { - Intent intent = new Intent(this, SettingsActivity.class); - startActivity(intent); - return true; + Intent intent; + switch (item.getItemId()) { + + case R.id.action_preferences: + intent = new Intent(this, SettingsActivity.class); + startActivity(intent); + return true; + case R.id.action_connections: + intent = new Intent(this, ConnectionActivity.class); + startActivity(intent); + return true; + case R.id.action_blank: + new BlankDisplayDialog().show(getFragmentManager(), "BlankDialog"); + return true; + case R.id.action_alert: + new AlertDisplayDialog().show(getFragmentManager(), "AlertDialog"); + return true; + case R.id.action_about: + getFragmentManager().beginTransaction() + .replace(R.id.container, AboutFragment.newInstance()) + .commit(); + default: + return super.onOptionsItemSelected(item); } - if (id == R.id.action_connections) { - Intent intent = new Intent(this, ConnectionActivity.class); - startActivity(intent); - return true; - } - if (id == R.id.action_blank) { - new BlankDisplayDialog().show(getFragmentManager(), "BlankDialog"); - return true; - } - if (id == R.id.action_alert) { - new AlertDisplayDialog().show(getFragmentManager(), "AlertDialog"); - return true; - } - return super.onOptionsItemSelected(item); } /** diff --git a/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java b/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java index 1c2da77..079880e 100644 --- a/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java +++ b/app/src/main/java/org/openlp/android2/common/OpenLPHttpClient.java @@ -70,24 +70,10 @@ public class OpenLPHttpClient { public String getAbsoluteUrl(AsyncHttpClient client) { - if (useSSL){ - try { - KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); - trustStore.load(null, null); - MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); - sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - client.setSSLSocketFactory(sf); - } - catch (Exception e) {; - } - } - Map preferences = context.getSharedPreferences(context.getString(R.string.keySharedPreferences), Context.MODE_PRIVATE).getAll(); - - useSSL = getPreference(preferences, context.getString(R.string.key_ssl_use), false); - String host = getPreference(preferences, context.getString(R.string.keyHost), - context.getString(R.string.hostDefaultValue)); - String port = getPreference(preferences, context.getString(R.string.keyPort), "4316"); + String urlBase = getBaseUrl(); + Map preferences = context.getSharedPreferences(context.getString(R.string.keySharedPreferences), + Context.MODE_PRIVATE).getAll(); String userid = getPreference(preferences, context.getString(R.string.key_userid), "openlp"); @@ -98,8 +84,6 @@ public class OpenLPHttpClient { Credentials creds = new UsernamePasswordCredentials(userid, password); - String urlBase = String.format("http%s://%s:%s", useSSL ? "s" : "", host, port); - int connectionTimeout = context.getResources().getInteger( R.integer.connectionTimeoutDefaultValue); @@ -127,31 +111,16 @@ public class OpenLPHttpClient { return urlBase; } + public String getBaseUrl(){ + Map preferences = context.getSharedPreferences(context.getString(R.string.keySharedPreferences), Context.MODE_PRIVATE).getAll(); -/* public OpenLPHttpReturn handleExecute() throws IOException { - //HttpResponse response = this.execute(); + useSSL = getPreference(preferences, context.getString(R.string.key_ssl_use), false); + String host = getPreference(preferences, context.getString(R.string.keyHost), + context.getString(R.string.hostDefaultValue)); + String port = getPreference(preferences, context.getString(R.string.keyPort), "4316"); - 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 OpenLPHttpReturn(0, stringBuilder.toString(), this.context); - } - } - return new OpenLPHttpReturn(response.getStatusLine().getStatusCode(), null, this.context); - }*/ + return String.format("http%s://%s:%s", useSSL ? "s" : "", host, port); + } } diff --git a/app/src/main/java/org/openlp/android2/fragments/AboutFragment.java b/app/src/main/java/org/openlp/android2/fragments/AboutFragment.java new file mode 100644 index 0000000..aee7551 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/AboutFragment.java @@ -0,0 +1,72 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import org.openlp.android2.R; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class AboutFragment extends Fragment { + + public AboutFragment() { + // Empty constructor required for fragment subclasses + } + + public static AboutFragment newInstance() { + AboutFragment fragment = new AboutFragment(); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_about, container, false); + + String date = new SimpleDateFormat("yyyy").format(new Date()); + + StringBuilder html = new StringBuilder(); + html.append(getString(R.string.about_display_1)); + html.append("\n"); + html.append(getString(R.string.about_display_2)); + html.append(" http://www.openlp.org"); + html.append("\n\n\n"); + 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"); + html.append("\n\n\n"); + html.append(getString(R.string.about_display_6)); + html.append("\n"); + html.append(getString(R.string.about_display_7)); + html.append("\n"); + html.append(getString(R.string.about_display_8)); + + ((TextView) view.findViewById(R.id.about_text)).setText(html); + + return view; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openlp/android2/fragments/HomeFragment.java b/app/src/main/java/org/openlp/android2/fragments/HomeFragment.java new file mode 100644 index 0000000..0371fd9 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/HomeFragment.java @@ -0,0 +1,60 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import org.openlp.android2.R; + + +public class HomeFragment extends Fragment { + private View displayView; + + public HomeFragment() { + // Empty constructor required for fragment subclasses + } + + public static HomeFragment newInstance() { + HomeFragment fragment = new HomeFragment(); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { + displayView = inflater.inflate(R.layout.fragment_home, container, false); + displayIcon(); + return displayView; + } + + @Override + public void onResume() { + super.onResume(); + displayIcon(); + } + + private void displayIcon(){ + int imageId = getResources().getIdentifier("openlp_splash_screen","drawable", getActivity().getPackageName()); + ((ImageView) displayView.findViewById(R.id.home_image)).setImageResource(imageId); + } +} diff --git a/app/src/main/java/org/openlp/android2/fragments/LiveWebFragment.java b/app/src/main/java/org/openlp/android2/fragments/LiveWebFragment.java new file mode 100644 index 0000000..d1403a4 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/LiveWebFragment.java @@ -0,0 +1,35 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import org.openlp.android2.api.Api; + +public class LiveWebFragment extends WebFragment { + public LiveWebFragment() { + super(); + curURL = Api.LIVE_VIEW; + } + + public static LiveWebFragment newInstance() { + LiveWebFragment fragment = new LiveWebFragment(); + return fragment; + } +} + diff --git a/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java b/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java index 2313b0d..0b1839b 100644 --- a/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/org/openlp/android2/fragments/NavigationDrawerFragment.java @@ -102,6 +102,7 @@ public class NavigationDrawerFragment extends Fragment { R.layout.fragment_navigation_drawer_list, android.R.id.text1, new String[]{ + getString(R.string.home), getString(R.string.service_list), getString(R.string.live_list), getString(R.string.stage_view), diff --git a/app/src/main/java/org/openlp/android2/fragments/StageWebFragment.java b/app/src/main/java/org/openlp/android2/fragments/StageWebFragment.java new file mode 100644 index 0000000..1fac747 --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/StageWebFragment.java @@ -0,0 +1,36 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import org.openlp.android2.api.Api; + +public class StageWebFragment extends WebFragment { + + public StageWebFragment(){ + super(); + curURL = Api.STAGE_VIEW; + } + + + public static StageWebFragment newInstance() { + StageWebFragment fragment = new StageWebFragment(); + return fragment; + } +} diff --git a/app/src/main/java/org/openlp/android2/fragments/WebFragment.java b/app/src/main/java/org/openlp/android2/fragments/WebFragment.java new file mode 100644 index 0000000..0edee8f --- /dev/null +++ b/app/src/main/java/org/openlp/android2/fragments/WebFragment.java @@ -0,0 +1,86 @@ +/****************************************************************************** + * OpenLP - Open Source Lyrics Projection * + * --------------------------------------------------------------------------- * + * Copyright (c) 2011-2014 Raoul Snyman * + * Portions copyright (c) 2011-2014 Tim Bentley, Johan Mynhardt * + * --------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the Free * + * Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT * + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * + * more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., 59 * + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *******************************************************************************/ +package org.openlp.android2.fragments; + +import android.app.Fragment; +import android.net.http.SslError; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.SslErrorHandler; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import org.openlp.android2.R; +import org.openlp.android2.common.OpenLPHttpClient; + +public class WebFragment extends Fragment { + + protected String curURL; + private OpenLPHttpClient httpClient; + private WebView webview; + + public WebFragment(){ + super(); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { + httpClient = new OpenLPHttpClient(getActivity()); + View view = inflater.inflate(R.layout.fragment_web, container, false); + + if (curURL != null) { + webview = (WebView) view.findViewById(R.id.webPage); + webview.getSettings().setJavaScriptEnabled(true); + webview.getSettings().setBuiltInZoomControls(true); + webview.getSettings().setLoadWithOverviewMode(true); + webview.getSettings().setUseWideViewPort(true); + webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); + webview.setScrollbarFadingEnabled(true); + webview.setWebViewClient(new webClient()); + webview.loadUrl(String.format("%s%s", httpClient.getBaseUrl(), curURL)); + } + return view; + } + + @Override + public void onDestroyView() { + if (webview != null) { + webview.destroy(); + } + super.onDestroyView(); + } + + private class webClient extends WebViewClient { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + return false; + } + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { + handler.proceed(); // Ignore SSL certificate errors + } + } +} diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 0000000..bb3f203 --- /dev/null +++ b/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml new file mode 100644 index 0000000..974c838 --- /dev/null +++ b/app/src/main/res/layout/fragment_home.xml @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_web.xml b/app/src/main/res/layout/fragment_web.xml new file mode 100644 index 0000000..44b7c6f --- /dev/null +++ b/app/src/main/res/layout/fragment_web.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7b26e3..37faa31 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,6 +46,7 @@ Blank display to Theme Enable Custom Timeouts Enter Alert Text + Home Unauthorised Access, please enter valid userid and password Live List LiveView