AutoCompleteTextView in LocationPickerDialog

pull/281/head
Alex Baker 11 years ago
parent 3388b69333
commit f0fc904b78

@ -1,16 +1,19 @@
package org.tasks.dialogs;
import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
@ -55,25 +58,13 @@ public class LocationPickerDialog extends InjectingDialogFragment implements Goo
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
googleApi.connect(this);
View layout = inflater.inflate(R.layout.location_picker_dialog, null);
EditText addressEntry = (EditText) layout.findViewById(R.id.address_entry);
addressEntry.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
CharSequence search = v.getText();
mAdapter.getAutocomplete(search);
return true;
}
return false;
}
});
Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.Tasks_Dialog);
LayoutInflater themedInflater = inflater.cloneInContext(contextThemeWrapper);
View layout = themedInflater.inflate(R.layout.location_picker_dialog, null);
AutoCompleteTextView addressEntry = (AutoCompleteTextView) layout.findViewById(R.id.address_entry);
addressEntry.setOnItemClickListener(mAutocompleteClickListener);
mAdapter = new PlaceAutocompleteAdapter(googleApi, fragmentActivity, android.R.layout.simple_list_item_1);
ListView list = (ListView) layout.findViewById(R.id.list);
list.setAdapter(mAdapter);
list.setOnItemClickListener(mAutocompleteClickListener);
addressEntry.setAdapter(mAdapter);
return layout;
}

@ -2,6 +2,7 @@ package org.tasks.location;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Toast;
import com.google.android.gms.common.api.ResultCallback;
@ -43,6 +44,25 @@ public class PlaceAutocompleteAdapter
googleApi.getAutocompletePredictions(constraint.toString(), onResults);
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
getAutocomplete(constraint);
FilterResults filterResults = new FilterResults();
filterResults.values = mResultList;
filterResults.count = mResultList.size();
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
}
};
}
private ResultCallback<AutocompletePredictionBuffer> onResults = new ResultCallback<AutocompletePredictionBuffer>() {
@Override
public void onResult(AutocompletePredictionBuffer autocompletePredictions) {

@ -9,15 +9,14 @@
android:paddingTop="@dimen/vertical_page_margin"
android:paddingBottom="@dimen/vertical_page_margin">
<EditText
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:layout_gravity="top"
android:inputType="textPostalAddress"
android:imeOptions="actionSearch"
android:imeOptions="flagNoExtractUi"
android:hint="@string/type_a_location"
android:ems="10"
android:id="@+id/address_entry" />
<ImageView
@ -26,9 +25,4 @@
android:src="@drawable/powered_by_google_light"
android:layout_gravity="end"/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

@ -106,7 +106,11 @@
<item name="colorControlHighlight">#3fff</item>
</style>
<style name="Tasks.Dialog" parent="@style/Theme.AppCompat.Light.Dialog"/>
<style name="Tasks.Dialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary</item>
</style>
<!--================================================== General == -->

Loading…
Cancel
Save