From 75894fdbf88148c21d733ab0e3627239564ea6bb Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 2 Jun 2012 16:05:35 -0400 Subject: [PATCH] Cleaned up the address search dialog I also enabled the IME search action, allowing users to search by pressing the action key on their keyboard Signed-off-by: Ricky Barrette --- LocationRinger/res/layout/address_dialog.xml | 17 ++- .../android/LocationRinger/debug/Debug.java | 7 +- .../LocationRinger/ui/SearchDialog.java | 133 +++++++++++------- 3 files changed, 97 insertions(+), 60 deletions(-) diff --git a/LocationRinger/res/layout/address_dialog.xml b/LocationRinger/res/layout/address_dialog.xml index 279d6e3..a8a1a77 100644 --- a/LocationRinger/res/layout/address_dialog.xml +++ b/LocationRinger/res/layout/address_dialog.xml @@ -2,6 +2,7 @@ + android:imeOptions="actionSearch" + android:inputType="textPostalAddress" > + + + (mContext, android.R.layout.simple_list_item_1, getAddress())); - v.setEnabled(true); - mProgress.setVisibility(View.INVISIBLE); - mProgress.setIndeterminate(false); - if(Debug.DEBUG) - Log.d(TAG,"finished"); - } - }); - } else { - //update the UI - mHandler.post(new Runnable(){ - @Override - public void run(){ - v.setEnabled(true); - mProgress.setVisibility(View.INVISIBLE); - mProgress.setIndeterminate(false); - if(Debug.DEBUG) - Log.d(TAG,"failed"); - } - }); - } - } - }).start(); + search(); break; } } - + /** + * Called when the seach button on the soft keyboard is pressed + * (non-Javadoc) + * @see android.widget.TextView.OnEditorActionListener#onEditorAction(android.widget.TextView, int, android.view.KeyEvent) + */ + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + search(); + return false; + } + + /** + * Called when an Item from the list is selected + * (non-Javadoc) + * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long) + */ @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if(Debug.DEBUG) @@ -171,4 +147,57 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis mListener.onLocationSelected(getCoords((int) id)); this.dismiss(); } -} + + private void search() { + final InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(this.mAddress.getWindowToken(), 0); + final View v = this.findViewById(R.id.ok); + v.setEnabled(false); + mProgress.setVisibility(View.VISIBLE); + mProgress.setIndeterminate(true); + new Thread( new Runnable(){ + @Override + public void run(){ + if(Debug.DEBUG) + Log.d(TAG,"strarting search and parsing") ; + try { + mResults = ReverseGeocoder.addressSearch(mAddress.getText().toString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + if(mResults != null){ + if(Debug.DEBUG) + Log.d(TAG,"finished searching and parsing"); + //update UI + mHandler.post(new Runnable(){ + @Override + public void run(){ + if(Debug.DEBUG) + Log.d(TAG,"populating list"); + mAddressList.setAdapter(new ArrayAdapter(mContext, android.R.layout.simple_list_item_1, getAddress())); + v.setEnabled(true); + mProgress.setVisibility(View.INVISIBLE); + mProgress.setIndeterminate(false); + if(Debug.DEBUG) + Log.d(TAG,"finished"); + } + }); + } else { + //update the UI + mHandler.post(new Runnable(){ + @Override + public void run(){ + v.setEnabled(true); + mProgress.setVisibility(View.INVISIBLE); + mProgress.setIndeterminate(false); + if(Debug.DEBUG) + Log.d(TAG,"failed"); + } + }); + } + } + }).start(); + } +} \ No newline at end of file