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 <rickbarrette@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center|center_horizontal"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@@ -19,17 +20,27 @@
|
|||||||
android:id="@+id/ok"
|
android:id="@+id/ok"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignLeft="@+id/search_progress"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_toLeftOf="@id/search_progress"
|
android:layout_alignParentTop="true"
|
||||||
|
android:gravity="center|center_horizontal"
|
||||||
android:text="@android:string/ok" />
|
android:text="@android:string/ok" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/address"
|
android:id="@+id/address"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toLeftOf="@id/ok"
|
android:layout_alignBaseline="@+id/ok"
|
||||||
|
android:layout_alignBottom="@+id/ok"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_toLeftOf="@+id/ok"
|
||||||
|
android:ems="10"
|
||||||
android:hint="@string/address"
|
android:hint="@string/address"
|
||||||
android:inputType="textPostalAddress" />
|
android:imeOptions="actionSearch"
|
||||||
|
android:inputType="textPostalAddress" >
|
||||||
|
|
||||||
|
<requestFocus />
|
||||||
|
</EditText>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A convince class containing debugging variables
|
* A convince class containing debugging variables
|
||||||
* @author ricky barrette
|
* @author ricky barrette */
|
||||||
*/
|
|
||||||
public class Debug {
|
public class Debug {
|
||||||
|
|
||||||
public static final boolean SUPPORTS_FROYO;
|
public static final boolean SUPPORTS_FROYO;
|
||||||
@@ -51,6 +50,4 @@ public class Debug {
|
|||||||
* Max radius that can be set by a ringer
|
* Max radius that can be set by a ringer
|
||||||
*/
|
*/
|
||||||
public static final int MAX_RADIUS_IN_METERS = 600;
|
public static final int MAX_RADIUS_IN_METERS = 600;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ import android.app.Dialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
@@ -24,6 +25,8 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
|
|
||||||
import com.TwentyCodes.android.LocationRinger.R;
|
import com.TwentyCodes.android.LocationRinger.R;
|
||||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||||
@@ -35,7 +38,7 @@ import com.google.android.maps.GeoPoint;
|
|||||||
* This dialog will be used to get users input for the address that they want to search for. A GeoPoint location will be returned via LocationSelectedListener
|
* This dialog will be used to get users input for the address that they want to search for. A GeoPoint location will be returned via LocationSelectedListener
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class SearchDialog extends Dialog implements android.view.View.OnClickListener, OnItemClickListener{
|
public class SearchDialog extends Dialog implements android.view.View.OnClickListener, OnItemClickListener, OnEditorActionListener{
|
||||||
|
|
||||||
protected static final String TAG = "SearchDialog";
|
protected static final String TAG = "SearchDialog";
|
||||||
private ListView mAddressList;
|
private ListView mAddressList;
|
||||||
@@ -59,6 +62,7 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis
|
|||||||
mAddressList = (ListView) findViewById(R.id.address_list);
|
mAddressList = (ListView) findViewById(R.id.address_list);
|
||||||
mAddressList.setOnItemClickListener(this);
|
mAddressList.setOnItemClickListener(this);
|
||||||
mAddress = (EditText) findViewById(R.id.address);
|
mAddress = (EditText) findViewById(R.id.address);
|
||||||
|
mAddress.setOnEditorActionListener(this);
|
||||||
mProgress = (ProgressBar) findViewById(R.id.search_progress);
|
mProgress = (ProgressBar) findViewById(R.id.search_progress);
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -106,12 +110,48 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the search button is clicked
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
switch(v.getId()){
|
switch(v.getId()){
|
||||||
case R.id.ok:
|
case R.id.ok:
|
||||||
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
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)
|
||||||
|
Log.d(TAG,"slected "+ (int) id);
|
||||||
|
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);
|
imm.hideSoftInputFromWindow(this.mAddress.getWindowToken(), 0);
|
||||||
|
final View v = this.findViewById(R.id.ok);
|
||||||
v.setEnabled(false);
|
v.setEnabled(false);
|
||||||
mProgress.setVisibility(View.VISIBLE);
|
mProgress.setVisibility(View.VISIBLE);
|
||||||
mProgress.setIndeterminate(true);
|
mProgress.setIndeterminate(true);
|
||||||
@@ -159,16 +199,5 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
if(Debug.DEBUG)
|
|
||||||
Log.d(TAG,"slected "+ (int) id);
|
|
||||||
mListener.onLocationSelected(getCoords((int) id));
|
|
||||||
this.dismiss();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user