diff options
author | Sam Blitzstein <sblitz@google.com> | 2013-04-08 16:32:58 -0700 |
---|---|---|
committer | Sam Blitzstein <sblitz@google.com> | 2013-04-08 17:26:24 -0700 |
commit | dba26e2a0025a404fba38a44500c0f072735a610 (patch) | |
tree | 9126484465531713b7c1373ab858d605b40652f6 /src/com/android | |
parent | 215ec1009ae3b52ed491fde7b2aa0a13dd4387be (diff) | |
download | android_frameworks_opt_timezonepicker-dba26e2a0025a404fba38a44500c0f072735a610.tar.gz android_frameworks_opt_timezonepicker-dba26e2a0025a404fba38a44500c0f072735a610.tar.bz2 android_frameworks_opt_timezonepicker-dba26e2a0025a404fba38a44500c0f072735a610.zip |
Iconified the search bar.
Added magnifying glass and clear icons.
Change-Id: I12422ee0abe78a34a44004d84237fc60422f260f
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/timezonepicker/TimeZonePickerView.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/com/android/timezonepicker/TimeZonePickerView.java b/src/com/android/timezonepicker/TimeZonePickerView.java index fc7e5e0..50b7afb 100644 --- a/src/com/android/timezonepicker/TimeZonePickerView.java +++ b/src/com/android/timezonepicker/TimeZonePickerView.java @@ -17,14 +17,19 @@ package com.android.timezonepicker; import android.content.Context; +import android.graphics.drawable.Drawable; import android.text.Editable; +import android.text.Spannable; +import android.text.SpannableStringBuilder; import android.text.TextWatcher; +import android.text.style.ImageSpan; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AutoCompleteTextView; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ListView; @@ -36,6 +41,8 @@ public class TimeZonePickerView extends LinearLayout implements TextWatcher, OnI private TimeZoneFilterTypeAdapter mFilterAdapter; TimeZoneResultAdapter mResultAdapter; + private ImageButton mClearButton; + public interface OnTimeZoneSetListener { void onTimeZoneSet(TimeZoneInfo tzi); } @@ -59,6 +66,27 @@ public class TimeZonePickerView extends LinearLayout implements TextWatcher, OnI mAutoCompleteTextView.setAdapter(mFilterAdapter); mAutoCompleteTextView.addTextChangedListener(this); mAutoCompleteTextView.setOnItemClickListener(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(); + } + }); + } + + 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); } // Implementation of TextWatcher @@ -75,6 +103,9 @@ public class TimeZonePickerView extends LinearLayout implements TextWatcher, OnI // Implementation of TextWatcher @Override public void afterTextChanged(Editable s) { + if (mClearButton != null) { + mClearButton.setVisibility(s.length() > 0 ? View.VISIBLE : View.GONE); + } } @Override |