1
0
mirror of https://gitlab.com/openlp/android.git synced 2024-12-22 11:52:49 +00:00

add files

This commit is contained in:
Tim Bentley 2016-06-13 21:43:38 +01:00
parent 26cd14c2b5
commit 2d7ae5f127
12 changed files with 668 additions and 0 deletions

View File

@ -0,0 +1,133 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2015 OpenLP Android Developers *
* --------------------------------------------------------------------------- *
* 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.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
import org.openlp.android2.R;
import org.openlp.android2.api.Api;
import org.openlp.android2.common.JsonHelpers;
import org.openlp.android2.common.OpenLPDialog;
public class SearchSelectionDialog extends OpenLPDialog {
private final String LOG_TAG = SearchSelectionDialog.class.getName();
public AlertDialog dialog;
private String key;
private String plugin;
private String text;
private RadioButton sendLive;
private RadioButton addToService;
/**
* The system calls this only when creating the layout in a dialog.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// The only reason you might override this method when using onCreateView() is
// to modify any dialog characteristics. For example, the dialog includes a
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
key = getArguments().getString("key");
plugin = getArguments().getString("plugin");
text = getArguments().getString("text");
context = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View view = inflater.inflate(R.layout.search_action_dialog, null);
builder.setView(view);
sendLive = (RadioButton) view.findViewById(R.id.buttonLive);
sendLive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createLive();
SearchSelectionDialog.this.getDialog().cancel();
}
});
addToService = (RadioButton) view.findViewById(R.id.buttonService);
addToService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createService();
SearchSelectionDialog.this.getDialog().cancel();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SearchSelectionDialog.this.getDialog().cancel();
}
});
dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogI) {
Button btnNegative = dialog.getButton(Dialog.BUTTON_NEGATIVE);
btnNegative.setTextSize(20);
}
});
return dialog;
}
@Override
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "Resuming...");
}
public void createLive() {
try {
String request = JsonHelpers.createRequestJSON("id", key);
String url = String.format(Api.SEARCH_PLUGIN_LIVE, plugin.toLowerCase());
triggerTextRequest(String.format("%s%s", url, request));
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), text(%s)", Api.SEARCH_PLUGIN_LIVE, text));
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show();
}
}
public void createService() {
try {
String request = JsonHelpers.createRequestJSON("id", key);
String url = String.format(Api.SEARCH_PLUGIN_ADD, plugin.toLowerCase());
triggerTextRequest(String.format("%s%s", url, request));
Log.d(LOG_TAG, String.format("Setting list data. apiBase(%s), text(%s)", Api.SEARCH_PLUGIN_ADD, text));
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
Toast.makeText(context, "Request Failed", Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -0,0 +1,346 @@
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2011-2016 OpenLP Android Developers *
* --------------------------------------------------------------------------- *
* 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.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.ClientError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
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.RequestQueueService;
import org.openlp.android2.dialogs.SearchSelectionDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*/
public class SearchFragment extends Fragment {
private final String LOG_TAG = SearchFragment.class.getName();
private Spinner spinner;
public Context context;
protected String calledURL;
protected String updateUrl;
protected String searchedPlugin;
protected Map<String, String> pluginMap = new HashMap<String, String>();
protected ArrayList<JSONArray> jsonCache = new ArrayList<JSONArray>();
public SearchFragment() {
Log.d(LOG_TAG, "Constructor");
}
public static SearchFragment newInstance() {
SearchFragment fragment = new SearchFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = getActivity();
updateUrl = Api.SEARCHABLE_PLUGINS;
View view = inflater.inflate(R.layout.fragment_search, container, false);
spinner = (Spinner) view.findViewById(R.id.search_spinner);
triggerTextRequest(Api.SEARCHABLE_PLUGINS);
// Add search listener to text field
EditText editText = (EditText) view.findViewById(R.id.search_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView tv, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// Now close the keyboard as finished with
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager imm =
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
searchedPlugin = pluginMap.get(spinner.getSelectedItem().toString());
requestSearch(tv.getText().toString());
return true;
}
return false;
}
});
return view;
}
@Override
public void onDetach() {
super.onDetach();
}
private void populatePluginList(String response, Boolean notInError) {
Log.i(LOG_TAG, "populatePluginList - entry");
List<String> categories = new ArrayList<String>();
pluginMap.clear();
if (notInError) {
try {
JSONArray items = new JSONObject(response).getJSONObject("results").getJSONArray("items");
for (int i = 0; i < items.length(); ++i) {
JSONArray item = items.getJSONArray(i);
categories.add(item.get(1).toString());
pluginMap.put(item.get(1).toString(), item.get(0).toString());
}
} catch (JSONException e) {
Log.e(LOG_TAG, response);
e.printStackTrace();
}
ArrayAdapter<String> LTRadapter = new ArrayAdapter<String>(getActivity(),
R.layout.spinner_list_item, categories);
LTRadapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(LTRadapter);
Log.i(LOG_TAG, "populatePluginList - exit");
}
}
protected void triggerTextRequest(String urlbase) {
Log.d(LOG_TAG, "Trigger Request for url " + urlbase);
String url = RequestQueueService.getInstance(this.context).getUrl(urlbase);
calledURL = urlbase;
StringRequest request = new StringRequest(
Request.Method.GET,
url,
listener,
errorListener) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return createBasicAuthHeader("user", "passwd");
}
};
//Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions.
// Volley does retry for you if you have specified the policy.
request.setRetryPolicy(new DefaultRetryPolicy(
RequestQueueService.getInstance(this.context).getConnectionTimeout(),
DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
request.setTag("OpenLP");
RequestQueueService.getInstance(this.context).addToRequestQueue(request);
}
Map<String, String> createBasicAuthHeader(String username, String password) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", RequestQueueService.getInstance(context).getBasicAuth());
return headers;
}
Response.Listener<String> listener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (calledURL.equals(updateUrl)) {
populatePluginList(response, true);
} else {
populateListDisplay(response, true);
}
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(LOG_TAG, String.format("Call response error = %s", error.toString()));
if (error instanceof NetworkError) {
} else if (error instanceof ClientError) {
} else if (error instanceof ServerError) {
} else if (error instanceof AuthFailureError) {
Toast.makeText(context, R.string.httpreturn_unauthorised,
Toast.LENGTH_LONG).show();
} else if (error instanceof ParseError) {
} else if (error instanceof NoConnectionError) {
} else if (error instanceof TimeoutError) {
}
Toast.makeText(context, R.string.unable,
Toast.LENGTH_LONG).show();
}
};
public void requestSearch(String text) {
updateUrl = Api.SEARCH_PLUGIN_FORMATTED;
try {
String request = JsonHelpers.createRequestJSON("text", text);
String url = String.format(Api.SEARCH_PLUGIN_FORMATTED, searchedPlugin);
triggerTextRequest(String.format("%s%s", url, request));
Log.d(LOG_TAG, String.format("Search request. apiBase(%s), text(%s)", searchedPlugin, text));
} catch (JsonHelpers.JSONHandlerException e) {
e.printStackTrace();
Toast.makeText(context, "Search Request Failed", Toast.LENGTH_SHORT).show();
}
}
public void populateListDisplay(String json, boolean notInError) {
Log.i(LOG_TAG, "populateListDisplay - entry");
ListView list = (ListView) getActivity().findViewById(R.id.searchlistView);
final ArrayList<JSONArray> listitems = new ArrayList<JSONArray>();
if (notInError) {
try {
JSONArray items = new JSONObject(json).getJSONObject("results").getJSONArray("items");
for (int i = 0; i < items.length(); ++i) {
JSONArray item = items.getJSONArray(i);
listitems.add(item);
}
} catch (JSONException e) {
Log.e(LOG_TAG, json);
e.printStackTrace();
}
}
jsonCache = new ArrayList<JSONArray>();
final StableArrayAdapter adapter = new StableArrayAdapter(context,
android.R.layout.simple_list_item_1,
listitems,
jsonCache);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
final JSONArray item = (JSONArray) parent.getItemAtPosition(position);
//Toast.makeText(context, "Item Pressed " + String.valueOf(position) + item,
// Toast.LENGTH_SHORT).show();
String it = "";
try {
it = (String) item.get(1);
} catch (JSONException e) {
e.printStackTrace();
}
Bundle args = new Bundle();
args.putString("plugin", searchedPlugin);
args.putString("text", it);
args.putString("key", Long.toString(id));
DialogFragment newFragment = new SearchSelectionDialog();
newFragment.setArguments(args);
newFragment.show(getFragmentManager(), "TAG");
}
});
Log.i(LOG_TAG, "populateListDisplay - exit");
}
private class StableArrayAdapter extends ArrayAdapter<JSONArray> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context,
int textViewResourceId,
List<JSONArray> objects,
ArrayList<JSONArray> jsonCache) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
JSONArray item = objects.get(i);
try {
jsonCache.add(item);
mIdMap.put(item.get(1).toString(), i);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
//User user = getItem(position);
String item = null;
try {
item = getItem(position).get(1).toString();
} catch (JSONException e) {
e.printStackTrace();
}
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.search_result_row,
parent, false);
}
// Lookup view for data population
TextView tvItem = (TextView) convertView.findViewById(R.id.searchListRow);
// Populate the data into the template view using the data object
tvItem.setText(item);
// Return the completed view to render on screen
return convertView;
}
@Override
public long getItemId(int position) {
String item = null;
try {
item = getItem(position).get(1).toString();
} catch (JSONException e) {
e.printStackTrace();
}
return mIdMap.get(item);
}
@Override
public boolean hasStableIds() {
return true;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:paddingRight="15dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Plugin"
android:id="@+id/search_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="40px"
android:height="70px"
android:paddingLeft="30dp"
android:paddingRight="30dp"/>
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/search_spinner"
android:layout_weight="0.4"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Search Text"
android:textSize="40px"
android:height="70px"
android:id="@+id/search_value_desc"
android:paddingLeft="30dp"
android:paddingRight="30dp"/>
<EditText
android:imeOptions="actionSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search_text"
style="@android:style/Animation.InputMethod"
android:layout_weight="0.87"
android:inputType="text"
android:textSize="40px"
android:height="70px"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/searchlistView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:textSize="40px"
android:height="70px"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="315dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/searchResults"
android:id="@+id/textView"
android:textStyle="bold|italic"
android:textSize="40px"
android:height="70px"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/searchSendLive"
android:id="@+id/buttonLive"
android:textSize="20sp"
android:height="30dp"
android:clickable="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/searchAddToService"
android:id="@+id/buttonService"
android:textSize="20sp"
android:height="40dp"
android:clickable="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
</LinearLayout>

View File

@ -0,0 +1,18 @@
<?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="vertical" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="40sp"
android:paddingTop="10dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingEnd="5dp"
android:paddingBottom="10dp"
android:id="@+id/searchListRow"/>
</LinearLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:textColor="#000"
android:textStyle="bold|italic"
android:textAppearance="?android:attr/textAppearanceLarge"/>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:textStyle="bold|italic" />

19
fixssl.iml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="fixssl" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>