From 8df842f0d628537a0850813bd34a7e042bd5f2b5 Mon Sep 17 00:00:00 2001 From: drizea Date: Sat, 4 Aug 2012 21:09:39 +0300 Subject: [PATCH] advanced search added and working --- Open-ILS/src/Android/AndroidManifest.xml | 6 +- .../Android/res/drawable/rounded_contentbox.xml | 7 + ...anced_search_dialog.xml => advanced_search.xml} | 17 ++- Open-ILS/src/Android/res/values/resources.xml | 2 +- Open-ILS/src/Android/res/values/strings.xml | 6 +- .../searchCatalog/AdvancedSearchActivity.java | 152 +++++++++++++++++++++ .../searchCatalog/SearchCatalogListView.java | 71 +++------- .../android/views/splashscreen/SplashActivity.java | 5 - 8 files changed, 200 insertions(+), 66 deletions(-) create mode 100644 Open-ILS/src/Android/res/drawable/rounded_contentbox.xml rename Open-ILS/src/Android/res/layout/{advanced_search_dialog.xml => advanced_search.xml} (86%) create mode 100644 Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/AdvancedSearchActivity.java diff --git a/Open-ILS/src/Android/AndroidManifest.xml b/Open-ILS/src/Android/AndroidManifest.xml index 0cd612e7d7..7685a0dd3b 100644 --- a/Open-ILS/src/Android/AndroidManifest.xml +++ b/Open-ILS/src/Android/AndroidManifest.xml @@ -49,15 +49,15 @@ > - - - + + diff --git a/Open-ILS/src/Android/res/drawable/rounded_contentbox.xml b/Open-ILS/src/Android/res/drawable/rounded_contentbox.xml new file mode 100644 index 0000000000..56da1bfd11 --- /dev/null +++ b/Open-ILS/src/Android/res/drawable/rounded_contentbox.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/res/layout/advanced_search_dialog.xml b/Open-ILS/src/Android/res/layout/advanced_search.xml similarity index 86% rename from Open-ILS/src/Android/res/layout/advanced_search_dialog.xml rename to Open-ILS/src/Android/res/layout/advanced_search.xml index 3fd28b94c7..75a8dcbf54 100644 --- a/Open-ILS/src/Android/res/layout/advanced_search_dialog.xml +++ b/Open-ILS/src/Android/res/layout/advanced_search.xml @@ -3,19 +3,26 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > - + + + + @@ -53,6 +60,7 @@ android:layout_width="fill_parent" android:layout_height="100dip" android:layout_below="@id/advanced_search_filter_container" + android:background="@drawable/rounded_contentbox" > @@ -88,8 +95,10 @@ android:layout_height="wrap_content" android:layout_below="@id/advanced_search_scrollview" android:layout_toRightOf="@id/advanced_search_cancel" - android:text="search" + android:text="@string/advanced_search" /> + + \ No newline at end of file diff --git a/Open-ILS/src/Android/res/values/resources.xml b/Open-ILS/src/Android/res/values/resources.xml index edba3c1082..bda6a7087f 100644 --- a/Open-ILS/src/Android/res/values/resources.xml +++ b/Open-ILS/src/Android/res/values/resources.xml @@ -3,7 +3,7 @@ Keyword Title - Author + Suthor Subject Series diff --git a/Open-ILS/src/Android/res/values/strings.xml b/Open-ILS/src/Android/res/values/strings.xml index f500c53ea5..1fe47d98cf 100644 --- a/Open-ILS/src/Android/res/values/strings.xml +++ b/Open-ILS/src/Android/res/values/strings.xml @@ -31,10 +31,12 @@ Password: - cancel - connect + Cancel + Connect What are you looking for? + Search + Enter text here Add filter Added filters: diff --git a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/AdvancedSearchActivity.java b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/AdvancedSearchActivity.java new file mode 100644 index 0000000000..70fe36ba08 --- /dev/null +++ b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/AdvancedSearchActivity.java @@ -0,0 +1,152 @@ +package org.evergreen.android.searchCatalog; + +import java.util.StringTokenizer; + +import org.evergreen.android.R; +import org.evergreen.android.accountAccess.AccountAccess; +import org.evergreen.android.views.AccountScreenDashboard; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup.LayoutParams; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +public class AdvancedSearchActivity extends Activity{ + + private String TAG = "AdvancedSearchActivity"; + + private AccountAccess accountAccess = null; + + private Context context; + + private ImageButton homeButton; + + private Button myAccountButton; + + private TextView headerTitle; + + private StringBuilder advancedSearchFormattedText; + + public static final int RESULT_ADVANCED_SEARCH = 10; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.advanced_search); + + + //header portion actions + homeButton = (ImageButton) findViewById(R.id.library_logo); + myAccountButton = (Button) findViewById(R.id.my_account_button); + headerTitle = (TextView) findViewById(R.id.header_title); + headerTitle.setText(R.string.advanced_search); + + advancedSearchFormattedText = new StringBuilder(); + + myAccountButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getApplicationContext(),AccountScreenDashboard.class); + startActivity(intent); + } + }); + + homeButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getApplicationContext(),SearchCatalogListView.class); + startActivity(intent); + } + }); + //end header portion actions + + context = this; + + final LinearLayout layout = (LinearLayout) findViewById(R.id.advanced_search_filters); + + Button addFilter = (Button) findViewById(R.id.advanced_search_add_filter_button); + + final Spinner search_index = (Spinner) findViewById(R.id.advanced_spinner_index); + final Spinner search_option = (Spinner) findViewById(R.id.advanced_spinner_option); + final EditText search_filter_text = (EditText) findViewById(R.id.advanced_search_text); + + addFilter.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + int searchOptionVal = search_option.getSelectedItemPosition(); + + String searchText = search_index.getSelectedItem().toString().toLowerCase() + ": "; + + advancedSearchFormattedText.append(search_index.getSelectedItem().toString().toLowerCase() + ": "); + + switch(searchOptionVal){ + + case 0 : { + //contains + advancedSearchFormattedText.append(search_filter_text.getText().toString()); + searchText = searchText + search_filter_text.getText().toString(); + }break; + case 1 : { + //excludes + + StringTokenizer str = new StringTokenizer(search_filter_text.getText().toString()); + + while(str.hasMoreTokens()){ + String token = str.nextToken(" "); + advancedSearchFormattedText.append(" -"+token); + searchText = searchText + " -"+token; + } + + }break; + case 2 : { + //matches exactly + advancedSearchFormattedText.append(" \"" + search_filter_text.getText().toString() + "\""); + searchText = searchText + " \"" + search_filter_text.getText().toString() + "\""; + }break; + + } + + TextView text = new TextView(context); + text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); + text.setText(searchText); + layout.addView(text); + + } + }); + + Button cancel = (Button) findViewById(R.id.advanced_search_cancel); + + cancel.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + } + }); + + Button search = (Button) findViewById(R.id.advanced_search_button); + + search.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + Intent returnIntent = new Intent(); + returnIntent.putExtra("advancedSearchText",advancedSearchFormattedText.toString()); + setResult(RESULT_ADVANCED_SEARCH,returnIntent); + finish(); + } + }); + + } + +} diff --git a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java index db99ef974e..3804917210 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java @@ -140,41 +140,8 @@ public class SearchCatalogListView extends Activity{ @Override public void onClick(View v) { //show advanced view dialog - - final Dialog dialog = new Dialog(context); - dialog.setContentView(R.layout.advanced_search_dialog); - dialog.setTitle("Advanced search"); - - final LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.advanced_search_filters); - - Button addFilter = (Button) dialog.findViewById(R.id.advanced_search_add_filter_button); - - final Spinner search_index = (Spinner) dialog.findViewById(R.id.advanced_spinner_index); - final Spinner search_option = (Spinner) dialog.findViewById(R.id.advanced_spinner_option); - final EditText search_filter_text = (EditText) dialog.findViewById(R.id.advanced_search_text); - - addFilter.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - TextView text = new TextView(context); - text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - text.setText(search_index.getSelectedItem().toString() + " " + search_option.getSelectedItem().toString() + " " + search_filter_text.getText().toString()); - layout.addView(text); - - } - }); - - - Button cancel = (Button) dialog.findViewById(R.id.advanced_search_cancel); - - cancel.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - dialog.dismiss(); - } - }); - dialog.setCancelable(true); - dialog.show(); + Intent advancedSearch = new Intent(context,AdvancedSearchActivity.class); + startActivityForResult(advancedSearch, 2); } }); //get bookbags @@ -217,19 +184,6 @@ public class SearchCatalogListView extends Activity{ searchOptionsMenu = findViewById(R.id.search_preference_options); - // Creating a button - Load More - Button btnLoadMore = new Button(this); - btnLoadMore.setText("Load More"); - - // Adding button to listview at footer - //lv.addFooterView(btnLoadMore); - - View footerView = findViewById(R.layout.search_result_footer_view); - //call before set adapter - //lv.addFooterView(footerView); - - //System.out.println("Here it is " + lv); - progressDialog = new ProgressDialog(context); progressDialog.setMessage("Fetching data"); @@ -478,9 +432,9 @@ public class SearchCatalogListView extends Activity{ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; menu.setHeaderTitle("Options"); - menu.add(Menu.NONE, DETAILS,0,"Details"); - menu.add(Menu.NONE,PLACE_HOLD,1,"Place Hold"); - menu.add(Menu.NONE,BOOK_BAG,2,"Add to bookbag"); + menu.add(Menu.NONE, DETAILS,0,"Details"); + menu.add(Menu.NONE,PLACE_HOLD,1,"Place Hold"); + menu.add(Menu.NONE,BOOK_BAG,2,"Add to bookbag"); } } @@ -602,6 +556,21 @@ public class SearchCatalogListView extends Activity{ return super.onContextItemSelected(item); } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + + switch(resultCode){ + + case AdvancedSearchActivity.RESULT_ADVANCED_SEARCH : { + Log.d(TAG, "result text"+data.getStringExtra("advancedSearchText")); + searchText.setText(data.getStringExtra("advancedSearchText")); + Thread searchThread = new Thread(searchForResultsRunnable); + searchThread.start(); + } break; + + } + } class SearchArrayAdapter extends ArrayAdapter { private static final String tag = "SearchArrayAdapter"; diff --git a/Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java b/Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java index 2e63daeb2b..182e5b1f72 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java @@ -39,7 +39,6 @@ public class SplashActivity extends Activity implements private ProgressBar progressBar; - private String TAG = "SplashActivity"; @Override @@ -89,11 +88,7 @@ public class SplashActivity extends Activity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - - Log.d(TAG, "Result code return " + resultCode); - switch(resultCode){ - case ConfigureApplicationActivity.RESULT_CONFIGURE_SUCCESS : { new LoadingTask(progressBar, this, this, progressText, this).execute("download"); -- 2.11.0