1
0
mirror of https://gitlab.com/openlp/android.git synced 2024-12-22 03:42:48 +00:00

Add Search

This commit is contained in:
Tim Bentley 2016-01-11 20:02:36 +00:00
commit a014b61fec
19 changed files with 841 additions and 15 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="OpenLP2" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="OpenLP2_search" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@ -65,27 +65,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
@ -97,4 +90,209 @@
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
</component>
<component name="org.twodividedbyzero.idea.findbugs">
<option name="_basePreferences">
<map>
<entry key="property.analysisEffortLevel" value="default" />
<entry key="property.analyzeAfterAutoMake" value="false" />
<entry key="property.analyzeAfterCompile" value="false" />
<entry key="property.annotationGutterIconEnabled" value="true" />
<entry key="property.annotationSuppressWarningsClass" value="edu.umd.cs.findbugs.annotations.SuppressFBWarnings" />
<entry key="property.annotationTextRangeMarkupEnabled" value="true" />
<entry key="property.exportAsHtml" value="true" />
<entry key="property.exportAsXml" value="true" />
<entry key="property.exportBaseDir" value="" />
<entry key="property.exportCreateArchiveDir" value="false" />
<entry key="property.exportOpenBrowser" value="true" />
<entry key="property.minPriorityToReport" value="Medium" />
<entry key="property.runAnalysisInBackground" value="false" />
<entry key="property.showHiddenDetectors" value="false" />
<entry key="property.toolWindowToFront" value="true" />
</map>
</option>
<option name="_detectors">
<map>
<entry key="AppendingToAnObjectOutputStream" value="true" />
<entry key="AtomicityProblem" value="true" />
<entry key="BadAppletConstructor" value="false" />
<entry key="BadResultSetAccess" value="true" />
<entry key="BadSyntaxForRegularExpression" value="true" />
<entry key="BadUseOfReturnValue" value="true" />
<entry key="BadlyOverriddenAdapter" value="true" />
<entry key="BooleanReturnNull" value="true" />
<entry key="BuildInterproceduralCallGraph" value="false" />
<entry key="BuildObligationPolicyDatabase" value="true" />
<entry key="BuildStringPassthruGraph" value="true" />
<entry key="CallToUnsupportedMethod" value="false" />
<entry key="CalledMethods" value="true" />
<entry key="CheckCalls" value="false" />
<entry key="CheckExpectedWarnings" value="false" />
<entry key="CheckImmutableAnnotation" value="true" />
<entry key="CheckRelaxingNullnessAnnotation" value="true" />
<entry key="CheckTypeQualifiers" value="true" />
<entry key="CloneIdiom" value="true" />
<entry key="ComparatorIdiom" value="true" />
<entry key="ConfusedInheritance" value="true" />
<entry key="ConfusionBetweenInheritedAndOuterMethod" value="true" />
<entry key="CovariantArrayAssignment" value="false" />
<entry key="CrossSiteScripting" value="true" />
<entry key="DefaultEncodingDetector" value="true" />
<entry key="DoInsideDoPrivileged" value="true" />
<entry key="DontCatchIllegalMonitorStateException" value="true" />
<entry key="DontIgnoreResultOfPutIfAbsent" value="true" />
<entry key="DontUseEnum" value="true" />
<entry key="DroppedException" value="true" />
<entry key="DumbMethodInvocations" value="true" />
<entry key="DumbMethods" value="true" />
<entry key="DuplicateBranches" value="true" />
<entry key="EmptyZipFileEntry" value="false" />
<entry key="EqualsOperandShouldHaveClassCompatibleWithThis" value="true" />
<entry key="ExplicitSerialization" value="true" />
<entry key="FieldItemSummary" value="true" />
<entry key="FinalizerNullsFields" value="true" />
<entry key="FindBadCast2" value="true" />
<entry key="FindBadForLoop" value="true" />
<entry key="FindBugsSummaryStats" value="true" />
<entry key="FindCircularDependencies" value="false" />
<entry key="FindComparatorProblems" value="true" />
<entry key="FindDeadLocalStores" value="true" />
<entry key="FindDoubleCheck" value="true" />
<entry key="FindEmptySynchronizedBlock" value="true" />
<entry key="FindFieldSelfAssignment" value="true" />
<entry key="FindFinalizeInvocations" value="true" />
<entry key="FindFloatEquality" value="true" />
<entry key="FindFloatMath" value="false" />
<entry key="FindHEmismatch" value="true" />
<entry key="FindInconsistentSync2" value="true" />
<entry key="FindJSR166LockMonitorenter" value="true" />
<entry key="FindLocalSelfAssignment2" value="true" />
<entry key="FindMaskedFields" value="true" />
<entry key="FindMismatchedWaitOrNotify" value="true" />
<entry key="FindNakedNotify" value="true" />
<entry key="FindNoSideEffectMethods" value="true" />
<entry key="FindNonSerializableStoreIntoSession" value="false" />
<entry key="FindNonSerializableValuePassedToWriteObject" value="false" />
<entry key="FindNonShortCircuit" value="true" />
<entry key="FindNullDeref" value="true" />
<entry key="FindNullDerefsInvolvingNonShortCircuitEvaluation" value="true" />
<entry key="FindOpenStream" value="true" />
<entry key="FindPuzzlers" value="true" />
<entry key="FindRefComparison" value="true" />
<entry key="FindReturnRef" value="true" />
<entry key="FindRoughConstants" value="true" />
<entry key="FindRunInvocations" value="true" />
<entry key="FindSelfComparison" value="true" />
<entry key="FindSelfComparison2" value="true" />
<entry key="FindSleepWithLockHeld" value="true" />
<entry key="FindSpinLoop" value="true" />
<entry key="FindSqlInjection" value="true" />
<entry key="FindTwoLockWait" value="true" />
<entry key="FindUncalledPrivateMethods" value="true" />
<entry key="FindUnconditionalWait" value="true" />
<entry key="FindUninitializedGet" value="true" />
<entry key="FindUnrelatedTypesInGenericContainer" value="true" />
<entry key="FindUnreleasedLock" value="true" />
<entry key="FindUnsatisfiedObligation" value="true" />
<entry key="FindUnsyncGet" value="true" />
<entry key="FindUseOfNonSerializableValue" value="true" />
<entry key="FindUselessControlFlow" value="true" />
<entry key="FindUselessObjects" value="true" />
<entry key="FormatStringChecker" value="true" />
<entry key="FunctionsThatMightBeMistakenForProcedures" value="true" />
<entry key="HugeSharedStringConstants" value="true" />
<entry key="IDivResultCastToDouble" value="true" />
<entry key="IncompatMask" value="true" />
<entry key="InconsistentAnnotations" value="true" />
<entry key="InefficientIndexOf" value="false" />
<entry key="InefficientInitializationInsideLoop" value="false" />
<entry key="InefficientMemberAccess" value="false" />
<entry key="InefficientToArray" value="false" />
<entry key="InfiniteLoop" value="true" />
<entry key="InfiniteRecursiveLoop" value="true" />
<entry key="InheritanceUnsafeGetResource" value="true" />
<entry key="InitializationChain" value="true" />
<entry key="InitializeNonnullFieldsInConstructor" value="true" />
<entry key="InstantiateStaticClass" value="true" />
<entry key="IntCast2LongAsInstant" value="true" />
<entry key="InvalidJUnitTest" value="true" />
<entry key="IteratorIdioms" value="true" />
<entry key="LazyInit" value="true" />
<entry key="LoadOfKnownNullValue" value="true" />
<entry key="LostLoggerDueToWeakReference" value="true" />
<entry key="MethodReturnCheck" value="true" />
<entry key="Methods" value="true" />
<entry key="MultithreadedInstanceAccess" value="true" />
<entry key="MutableEnum" value="true" />
<entry key="MutableLock" value="true" />
<entry key="MutableStaticFields" value="true" />
<entry key="Naming" value="true" />
<entry key="Noise" value="false" />
<entry key="NoiseNullDeref" value="false" />
<entry key="NoteAnnotationRetention" value="true" />
<entry key="NoteCheckReturnValueAnnotations" value="true" />
<entry key="NoteDirectlyRelevantTypeQualifiers" value="true" />
<entry key="NoteJCIPAnnotation" value="true" />
<entry key="NoteNonNullAnnotations" value="false" />
<entry key="NoteNonnullReturnValues" value="false" />
<entry key="NoteSuppressedWarnings" value="true" />
<entry key="NoteUnconditionalParamDerefs" value="true" />
<entry key="NumberConstructor" value="true" />
<entry key="OptionalReturnNull" value="true" />
<entry key="OverridingEqualsNotSymmetrical" value="true" />
<entry key="PreferZeroLengthArrays" value="true" />
<entry key="PublicSemaphores" value="false" />
<entry key="QuestionableBooleanAssignment" value="true" />
<entry key="ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass" value="true" />
<entry key="ReadReturnShouldBeChecked" value="true" />
<entry key="RedundantConditions" value="true" />
<entry key="RedundantInterfaces" value="true" />
<entry key="ReflectiveClasses" value="true" />
<entry key="RepeatedConditionals" value="true" />
<entry key="ResolveAllReferences" value="false" />
<entry key="RuntimeExceptionCapture" value="true" />
<entry key="SerializableIdiom" value="true" />
<entry key="StartInConstructor" value="true" />
<entry key="StaticCalendarDetector" value="true" />
<entry key="StringConcatenation" value="true" />
<entry key="SuperfluousInstanceOf" value="true" />
<entry key="SuspiciousThreadInterrupted" value="true" />
<entry key="SwitchFallthrough" value="true" />
<entry key="SynchronizationOnSharedBuiltinConstant" value="true" />
<entry key="SynchronizeAndNullCheckField" value="true" />
<entry key="SynchronizeOnClassLiteralNotGetClass" value="true" />
<entry key="SynchronizingOnContentsOfFieldToProtectField" value="true" />
<entry key="TestASM" value="false" />
<entry key="TestDataflowAnalysis" value="false" />
<entry key="TestingGround" value="false" />
<entry key="TestingGround2" value="false" />
<entry key="TrainFieldStoreTypes" value="true" />
<entry key="TrainLongInstantfParams" value="true" />
<entry key="TrainNonNullAnnotations" value="true" />
<entry key="TrainUnconditionalDerefParams" value="true" />
<entry key="URLProblems" value="true" />
<entry key="UncallableMethodOfAnonymousClass" value="true" />
<entry key="UnnecessaryMath" value="true" />
<entry key="UnreadFields" value="true" />
<entry key="UselessSubclassMethod" value="false" />
<entry key="VarArgsProblems" value="true" />
<entry key="VolatileUsage" value="true" />
<entry key="WaitInLoop" value="true" />
<entry key="WrongMapIterator" value="true" />
<entry key="XMLFactoryBypass" value="true" />
</map>
</option>
<option name="_reportCategories">
<map>
<entry key="BAD_PRACTICE" value="true" />
<entry key="CORRECTNESS" value="true" />
<entry key="EXPERIMENTAL" value="true" />
<entry key="I18N" value="true" />
<entry key="MALICIOUS_CODE" value="true" />
<entry key="MT_CORRECTNESS" value="true" />
<entry key="PERFORMANCE" value="true" />
<entry key="SECURITY" value="true" />
<entry key="STYLE" value="true" />
</map>
</option>
</component>
</module>

View File

@ -42,6 +42,7 @@ import org.openlp.android2.fragments.HomeFragment;
import org.openlp.android2.fragments.LiveListFragment;
import org.openlp.android2.fragments.LiveWebFragment;
import org.openlp.android2.fragments.NavigationDrawerFragment;
import org.openlp.android2.fragments.SearchFragment;
import org.openlp.android2.fragments.ServiceListFragment;
import org.openlp.android2.fragments.StageWebFragment;
@ -163,6 +164,24 @@ public class OpenLP extends ActionBarActivity
toggerContainer(R.id.next_button, View.GONE);
toggerContainer(R.id.prev_button, View.GONE);
break;
case NavigationOptions.Search:
singleTab();
fragmentManager.beginTransaction()
.replace(R.id.container, SearchFragment.newInstance())
.commit();
mTitle = getString(R.string.action_search);
toggerContainer(R.id.next_button, View.GONE);
toggerContainer(R.id.prev_button, View.GONE);
break;
default:
singleTab();
fragmentManager.beginTransaction()
.replace(R.id.container, HomeFragment.newInstance())
.commit();
mTitle = getString(R.string.home);
toggerContainer(R.id.next_button, View.GONE);
toggerContainer(R.id.prev_button, View.GONE);
break;
}
}

View File

@ -24,4 +24,5 @@ public class NavigationOptions{
public final static int LiveList = 2;
public final static int StageView = 3;
public final static int LiveView = 4;
public final static int Search = 5;
}

View File

@ -46,6 +46,7 @@ abstract public class OpenLPDialog extends DialogFragment {
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) {

View File

@ -76,7 +76,7 @@ public class OpenLPHttpClient {
client.setSSLSocketFactory(sf);
}
catch (Exception e){
//
Log.d(LOG_TAG, "Unable to support SSL");
}
}
return urlBase;

View File

@ -0,0 +1,135 @@
/******************************************************************************
* 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;
import org.openlp.android2.common.OpenLPHttpClient;
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();
httpClient = new OpenLPHttpClient(context);
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

@ -42,7 +42,6 @@ import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.openlp.android2.R;
@ -152,6 +151,11 @@ public class NavigationDrawerFragment extends Fragment {
hm4.put("icon", Integer.toString(R.drawable.ic_ondemand_video_black));
aList.add(hm4);
HashMap<String, String> hm5 = new HashMap<String, String>();
hm5.put("title", getString(R.string.action_search));
hm5.put("icon", Integer.toString(R.drawable.ic_search_black));
aList.add(hm5);
// Keys used in Hashmap
String[] from = {"icon", "title"};

View File

@ -0,0 +1,283 @@
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.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;
import org.apache.http.Header;
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.OpenLPHttpClient;
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;
private static AsyncHttpClient client = new AsyncHttpClient();
public Context context;
protected String calledURL;
protected OpenLPHttpClient httpClient;
protected String updateUrl;
protected String searchedPlugin;
protected Map<String, String> pluginMap = new HashMap<String, String>();
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;
httpClient = new OpenLPHttpClient(context);
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();
}
public void manageResponse(String response, boolean notInError) {
if (calledURL.equals(updateUrl)) {
populatePluginList(response, notInError);
} else {
populateListDisplay(response, notInError);
}
}
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 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, true);
}
@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();
}
manageResponse(responseString, false);
}
});
}
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();
}
}
final StableArrayAdapter adapter = new StableArrayAdapter(context,
android.R.layout.simple_list_item_1, listitems);
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) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
JSONArray item = objects.get(i);
try {
mIdMap.put(item.get(1).toString(), Integer.valueOf(item.get(0).toString()));
} 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,11 @@
<?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">
<TextView
android:id="@+id/serachitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
</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" />

View File

@ -29,7 +29,7 @@
<string name="display_blank_summary">Select the required display</string>
<string name="display_desktop">Display Desktop background</string>
<string name="display_list_autoscroll">Allow the selected item to scroll to the centre of the list</string>
<string name="display_reset">Show Live display</string>
<string name="display_reset">Live display</string>
<string name="display_settings">Display Setting</string>
<string name="display_screen">Display Black only</string>
<string name="display_theme">Display Theme only</string>
@ -48,6 +48,10 @@
<string name="previous">Previous</string>
<string name="process">Process</string>
<string name="service_list">Service List</string>
<string name="searchResults">Search Results</string>
<string name="searchSendLive">Send Live</string>
<string name="searchAddToService">Add to Service</string>
<string name="showingResults">Showing Results for \'%s\'</string>
<string name="stage_view">Stage View</string>
<string name="text_size">Select display text size</string>
<string name="text_size_summary">Change the Service text size</string>