Service List Start

This commit is contained in:
Tim Bentley 2014-11-15 22:03:01 +00:00
parent a9c5561028
commit 43e6d60836
20 changed files with 352 additions and 191 deletions

View File

@ -39,7 +39,7 @@ 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.ServiceListFragment;
public class OpenLP extends Activity
@ -77,7 +77,7 @@ public class OpenLP extends Activity
switch (position) {
case 0:
fragmentManager.beginTransaction()
.replace(R.id.container, ServicelistFragment.newInstance())
.replace(R.id.container, ServiceListFragment.newInstance())
.commit();
mTitle = getString(R.string.service_list);
break;

View File

@ -0,0 +1,92 @@
/******************************************************************************
* 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.common;
import android.app.ListFragment;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;
import org.apache.http.Header;
import org.openlp.android2.R;
import org.openlp.android2.api.Api;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
abstract public class OpenLPFragment extends ListFragment{
private String LOG_TAG = OpenLPFragment.class.getName();
public Context context;
protected String calledURL;
protected OpenLPHttpClient httpClient;
abstract public void itemClicked(int position);
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
itemClicked(position);
}
private static AsyncHttpClient client = new AsyncHttpClient();
protected void populateDisplay(String responseString) {}
protected void processUpdate(String responseString) {}
protected void errorDisplay(int statusCode, String responseString) {}
protected void triggerTextRequest(String url) {
calledURL = url;
Log.d(LOG_TAG, "Trigger Request for url " + url);
String callurl = String.format("%s%s", httpClient.getAbsoluteUrl(client), url );
client.get(callurl, null, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
// called when response HTTP status is "200 OK"
manageResponse(responseString);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
if (statusCode == 401) {
Toast.makeText(context, R.string.httpreturn_unauthorised, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, R.string.unable, Toast.LENGTH_LONG).show();
}
errorDisplay(statusCode, responseString);
}
});
}
public void manageResponse(String response) {
if (calledURL.equals(Api.POLL_STATUS)) {
populateDisplay(response);
}else {
processUpdate(response);
}
}
}

View File

@ -0,0 +1,226 @@
/******************************************************************************
* 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.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openlp.android2.R;
import org.openlp.android2.api.Api;
import org.openlp.android2.common.JsonHelpers;
import org.openlp.android2.common.OpenLPFragment;
import org.openlp.android2.fragments.dummy.DummyContent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ServiceListFragment extends OpenLPFragment {
private final String LOG_TAG = ServiceListFragment.class.getName();
private boolean noScreenUpdate = false;
private boolean isDoubleClick = false;
/**
* The fragment's ListView/GridView.
*/
private AbsListView mListView;
/**
* The Adapter which will be used to populate the ListView/GridView with
* Views.
*/
private ListAdapter mAdapter;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public ServiceListFragment() {
}
// TODO: Rename and change types of parameters
public static ServiceListFragment newInstance() {
ServiceListFragment fragment = new ServiceListFragment();
Bundle args = new Bundle();
//args.putString(ARG_PARAM1, param1);
//args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = getActivity();
noScreenUpdate = false;
isDoubleClick = false;
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AdapterView.OnItemLongClickListener listener = new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long id) {
Toast.makeText(getActivity().getBaseContext(), "Long Clicked ", Toast.LENGTH_SHORT).show();
itemClicked(position);
noScreenUpdate = true;
isDoubleClick = true;
//((OpenLP) getActivity()).makeBackArrowVisible(true);
//((OpenLP) getActivity()).menuVisible(R.id.action_back);
//((OpenLP) getActivity()).selectItem(NavigationOptions.LiveList);
return false;
}
};
getListView().setOnItemLongClickListener(listener);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
@Override
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "Resuming...");
triggerTextRequest(Api.SERVICE_LIST);
Log.d(LOG_TAG, "Resumed...");
}
@Override
public void populateDisplay(String json) {
Log.i(LOG_TAG, "populate_display - entry");
if (noScreenUpdate || isDoubleClick) {
noScreenUpdate = false;
return;
}
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
try {
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
for (int i = 0; i < items.length(); ++i) {
JSONObject item = items.getJSONObject(i);
HashMap<String, String> hm = new HashMap<String, String>();
if (item.getString("plugin").equals("songs")) {
hm.put("icon", Integer.toString(R.drawable.ic_my_library_music));
} else if (item.getString("plugin").equals("bibles")) {
hm.put("icon", Integer.toString(R.drawable.ic_my_library_add));
} else if (item.getString("plugin").equals("media")) {
hm.put("icon", Integer.toString(R.drawable.ic_local_movies));
} else if (item.getString("plugin").equals("presentations")) {
hm.put("icon", Integer.toString(R.drawable.ic_dvr));
} else if (item.getString("plugin").equals("images")) {
hm.put("icon", Integer.toString(R.drawable.ic_image));
} else {
hm.put("icon", Integer.toString(R.drawable.ic_edit));
}
hm.put("title", item.getString("title"));
aList.add(hm);
}
} catch (JSONException e) {
e.printStackTrace();
}
// Keys used in Hashmap
String[] from = {"icon", "title"};
// Ids of views in service_list_fragment
int[] to = {R.id.icon, R.id.serviceListText};
SharedPreferences prefs = context.getSharedPreferences(
context.getString(R.string.keySharedPreferences),
Context.MODE_PRIVATE);
final int size = Integer.parseInt(prefs.getString(
context.getString(R.string.keyTextSize),
String.valueOf(context.getResources().getInteger(
R.integer.textSizeDefaultValue))));
// Instantiating an adapter to store each items
ListAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList,
R.layout.fragment_service_list, from, to) {
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = (TextView) view.findViewById(R.id.serviceListText);
text1.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
return view;
}
;
};
setListAdapter(adapter);
Log.i(LOG_TAG, "populate_display - exit");
}
/**
* The default content for this Fragment has a TextView that is shown when
* the list is empty. If you would like to change the text, call this method
* to supply the text it should use.
*/
public void setEmptyText(CharSequence emptyText) {
View emptyView = mListView.getEmptyView();
if (emptyText instanceof TextView) {
((TextView) emptyView).setText(emptyText);
}
}
public void itemClicked(int position) {
try {
noScreenUpdate = true;
String request = JsonHelpers.createRequestJSON("id", Integer.toString(position));
triggerTextRequest(String.format("%s%s", Api.SERVICE_SET, request));
String message = String.format("Setting list data. apiBase(%s), position(%s)",
Api.SERVICE_SET, position);
Log.d(LOG_TAG, message);
Toast.makeText(getActivity().getBaseContext(), "Service Item selected", Toast.LENGTH_SHORT).show();
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
Toast.makeText(getActivity().getBaseContext(), "Request Failed", Toast.LENGTH_SHORT).show();
}
triggerTextRequest(Api.SERVICE_LIST);
}
}

View File

@ -1,172 +0,0 @@
/******************************************************************************
* 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.Activity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import org.openlp.android2.R;
import org.openlp.android2.fragments.dummy.DummyContent;
/**
* A fragment representing a list of Items.
* <p />
* Large screen devices (such as tablets) are supported by replacing the ListView
* with a GridView.
* <p />
* Activities containing this fragment MUST implement the {@link Callbacks}
* interface.
*/
public class ServicelistFragment extends Fragment implements AbsListView.OnItemClickListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
/**
* The fragment's ListView/GridView.
*/
private AbsListView mListView;
/**
* The Adapter which will be used to populate the ListView/GridView with
* Views.
*/
private ListAdapter mAdapter;
// TODO: Rename and change types of parameters
public static ServicelistFragment newInstance() {
ServicelistFragment fragment = new ServicelistFragment();
Bundle args = new Bundle();
//args.putString(ARG_PARAM1, param1);
//args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public ServicelistFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
// TODO: Change Adapter to display your content
mAdapter = new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_servicelist, container, false);
// Set the adapter
mListView = (AbsListView) view.findViewById(android.R.id.list);
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
// Set OnItemClickListener so we can be notified on item clicks
mListView.setOnItemClickListener(this);
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
//try {
// mListener = (OnFragmentInteractionListener) activity;
//} catch (ClassCastException e) {
// throw new ClassCastException(activity.toString()
// + " must implement OnFragmentInteractionListener");
// }
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
}
}
/**
* The default content for this Fragment has a TextView that is shown when
* the list is empty. If you would like to change the text, call this method
* to supply the text it should use.
*/
public void setEmptyText(CharSequence emptyText) {
View emptyView = mListView.getEmptyView();
if (emptyText instanceof TextView) {
((TextView) emptyView).setText(emptyText);
}
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(String id);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

View File

@ -1,16 +1,31 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".OpenLP$PlaceholderFragment">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:smoothScrollbar="true"
android:clickable="false"
android:longClickable="false"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
/>
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
android:id="@+id/serviceListText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="14dp"
android:paddingTop="10dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
/>
</LinearLayout>

View File

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.openlp.android2.fragments.ServicelistFragment">
tools:context="org.openlp.android2.fragments.ServiceListFragment">
<GridView
android:id="@android:id/list"

View File

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.openlp.android2.fragments.ServicelistFragment">
tools:context="org.openlp.android2.fragments.ServiceListFragment">
<ListView
android:id="@android:id/list"

View File

@ -14,7 +14,7 @@
<item android:id="@+id/action_alert"
android:checkable="true"
android:visible="true"
android:icon="@drawable/ic_alarm_off"
android:icon="@drawable/ic_alarm_add"
android:title="@string/action_alert"
android:showAsAction="always" />
<item android:id="@+id/action_refresh"