TimeZonePickerViewpublic class TimeZonePickerView extends android.widget.LinearLayout implements android.widget.AdapterView.OnItemClickListener, android.text.TextWatcher, android.view.View.OnClickListener
Fields Summary |
---|
private static final String | TAG | private android.content.Context | mContext | private android.widget.AutoCompleteTextView | mAutoCompleteTextView | private TimeZoneFilterTypeAdapter | mFilterAdapter | private boolean | mHideFilterSearchOnStart | private boolean | mFirstTime | TimeZoneResultAdapter | mResultAdapter | private android.widget.ImageButton | mClearButton |
Constructors Summary |
---|
public TimeZonePickerView(android.content.Context context, android.util.AttributeSet attrs, String timeZone, long timeMillis, OnTimeZoneSetListener l, boolean hideFilterSearch)
super(context, attrs);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.timezonepickerview, this, true);
mHideFilterSearchOnStart = hideFilterSearch;
TimeZoneData tzd = new TimeZoneData(mContext, timeZone, timeMillis);
mResultAdapter = new TimeZoneResultAdapter(mContext, tzd, l);
ListView timeZoneList = (ListView) findViewById(R.id.timezonelist);
timeZoneList.setAdapter(mResultAdapter);
timeZoneList.setOnItemClickListener(mResultAdapter);
mFilterAdapter = new TimeZoneFilterTypeAdapter(mContext, tzd, mResultAdapter);
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.searchBox);
mAutoCompleteTextView.addTextChangedListener(this);
mAutoCompleteTextView.setOnItemClickListener(this);
mAutoCompleteTextView.setOnClickListener(this);
updateHint(R.string.hint_time_zone_search, R.drawable.ic_search_holo_light);
mClearButton = (ImageButton) findViewById(R.id.clear_search);
mClearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mAutoCompleteTextView.getEditableText().clear();
}
});
|
Methods Summary |
---|
public void | afterTextChanged(android.text.Editable s)
if (mClearButton != null) {
mClearButton.setVisibility(s.length() > 0 ? View.VISIBLE : View.GONE);
}
| public void | beforeTextChanged(java.lang.CharSequence s, int start, int count, int after)
| private void | filterOnString(java.lang.String string)
if (mAutoCompleteTextView.getAdapter() == null) {
mAutoCompleteTextView.setAdapter(mFilterAdapter);
}
mHideFilterSearchOnStart = false;
mFilterAdapter.getFilter().filter(string);
| public boolean | getHideFilterSearchOnStart()
return mHideFilterSearchOnStart;
| public java.lang.String | getLastFilterString()
return mResultAdapter != null ? mResultAdapter.getLastFilterString() : null;
| public int | getLastFilterTime()
return mResultAdapter != null ? mResultAdapter.getLastFilterType() : -1;
| public int | getLastFilterType()
return mResultAdapter != null ? mResultAdapter.getLastFilterType() : -1;
| public boolean | hasResults()
return mResultAdapter != null && mResultAdapter.hasResults();
| public void | onClick(android.view.View v)
if (mAutoCompleteTextView != null && !mAutoCompleteTextView.isPopupShowing()) {
filterOnString(mAutoCompleteTextView.getText().toString());
}
| public void | onItemClick(android.widget.AdapterView parent, android.view.View view, int position, long id)
// Hide the keyboard since the user explicitly selected an item.
InputMethodManager manager =
(InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
manager.hideSoftInputFromWindow(mAutoCompleteTextView.getWindowToken(), 0);
// An onClickListener for the view item because I haven't figured out a
// way to update the AutoCompleteTextView without causing an infinite loop.
mHideFilterSearchOnStart = true;
mFilterAdapter.onClick(view);
| public void | onTextChanged(java.lang.CharSequence s, int start, int before, int count)
if (mFirstTime && mHideFilterSearchOnStart) {
mFirstTime = false;
return;
}
filterOnString(s.toString());
| public void | showFilterResults(int type, java.lang.String string, int time)
if (mResultAdapter != null) {
mResultAdapter.onSetFilter(type, string, time);
}
| private void | updateHint(int hintTextId, int imageDrawableId)
String hintText = getResources().getString(hintTextId);
Drawable searchIcon = getResources().getDrawable(imageDrawableId);
SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon
ssb.append(hintText);
int textSize = (int) (mAutoCompleteTextView.getTextSize() * 1.25);
searchIcon.setBounds(0, 0, textSize, textSize);
ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mAutoCompleteTextView.setHint(ssb);
|
|