am fe75749c: Merge "Fix position and size of searchfield and buttons." into honeycomb
* commit 'fe75749cd9ad2186069037db0238b8596007c4d4': Fix position and size of searchfield and buttons.
This commit is contained in:
@@ -83,6 +83,7 @@ public class SearchView extends LinearLayout {
|
|||||||
private CursorAdapter mSuggestionsAdapter;
|
private CursorAdapter mSuggestionsAdapter;
|
||||||
private View mSearchButton;
|
private View mSearchButton;
|
||||||
private View mSubmitButton;
|
private View mSubmitButton;
|
||||||
|
private View mSubmitArea;
|
||||||
private ImageView mCloseButton;
|
private ImageView mCloseButton;
|
||||||
private View mSearchEditFrame;
|
private View mSearchEditFrame;
|
||||||
private View mVoiceButton;
|
private View mVoiceButton;
|
||||||
@@ -92,6 +93,7 @@ public class SearchView extends LinearLayout {
|
|||||||
private boolean mQueryRefinement;
|
private boolean mQueryRefinement;
|
||||||
private boolean mClearingFocus;
|
private boolean mClearingFocus;
|
||||||
private int mMaxWidth;
|
private int mMaxWidth;
|
||||||
|
private boolean mVoiceButtonEnabled;
|
||||||
|
|
||||||
private SearchableInfo mSearchable;
|
private SearchableInfo mSearchable;
|
||||||
|
|
||||||
@@ -187,6 +189,7 @@ public class SearchView extends LinearLayout {
|
|||||||
mQueryTextView.setSearchView(this);
|
mQueryTextView.setSearchView(this);
|
||||||
|
|
||||||
mSearchEditFrame = findViewById(R.id.search_edit_frame);
|
mSearchEditFrame = findViewById(R.id.search_edit_frame);
|
||||||
|
mSubmitArea = findViewById(R.id.submit_area);
|
||||||
mSubmitButton = findViewById(R.id.search_go_btn);
|
mSubmitButton = findViewById(R.id.search_go_btn);
|
||||||
mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
|
mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
|
||||||
mVoiceButton = findViewById(R.id.search_voice_btn);
|
mVoiceButton = findViewById(R.id.search_voice_btn);
|
||||||
@@ -248,6 +251,8 @@ public class SearchView extends LinearLayout {
|
|||||||
if (mSearchable != null) {
|
if (mSearchable != null) {
|
||||||
updateSearchAutoComplete();
|
updateSearchAutoComplete();
|
||||||
}
|
}
|
||||||
|
// Cache the voice search capability
|
||||||
|
mVoiceButtonEnabled = hasVoiceSearch();
|
||||||
updateViewsVisibility(mIconifiedByDefault);
|
updateViewsVisibility(mIconifiedByDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,18 +518,55 @@ public class SearchView extends LinearLayout {
|
|||||||
mIconified = collapsed;
|
mIconified = collapsed;
|
||||||
// Visibility of views that are visible when collapsed
|
// Visibility of views that are visible when collapsed
|
||||||
final int visCollapsed = collapsed ? VISIBLE : GONE;
|
final int visCollapsed = collapsed ? VISIBLE : GONE;
|
||||||
// Visibility of views that are visible when expanded
|
|
||||||
final int visExpanded = collapsed ? GONE : VISIBLE;
|
|
||||||
// Is there text in the query
|
// Is there text in the query
|
||||||
final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText());
|
final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText());
|
||||||
|
|
||||||
mSearchButton.setVisibility(visCollapsed);
|
mSearchButton.setVisibility(visCollapsed);
|
||||||
mSubmitButton.setVisibility(mSubmitButtonEnabled && hasText ? visExpanded : GONE);
|
updateSubmitButton(hasText);
|
||||||
mSearchEditFrame.setVisibility(visExpanded);
|
mSearchEditFrame.setVisibility(collapsed ? GONE : VISIBLE);
|
||||||
updateCloseButton();
|
updateCloseButton();
|
||||||
updateVoiceButton(!hasText);
|
updateVoiceButton(!hasText);
|
||||||
|
updateSubmitArea();
|
||||||
requestLayout();
|
requestLayout();
|
||||||
invalidate();
|
}
|
||||||
|
|
||||||
|
private boolean hasVoiceSearch() {
|
||||||
|
if (mSearchable != null && mSearchable.getVoiceSearchEnabled()) {
|
||||||
|
Intent testIntent = null;
|
||||||
|
if (mSearchable.getVoiceSearchLaunchWebSearch()) {
|
||||||
|
testIntent = mVoiceWebSearchIntent;
|
||||||
|
} else if (mSearchable.getVoiceSearchLaunchRecognizer()) {
|
||||||
|
testIntent = mVoiceAppSearchIntent;
|
||||||
|
}
|
||||||
|
if (testIntent != null) {
|
||||||
|
ResolveInfo ri = getContext().getPackageManager().resolveActivity(testIntent,
|
||||||
|
PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
return ri != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSubmitAreaEnabled() {
|
||||||
|
return (mSubmitButtonEnabled || mVoiceButtonEnabled) && !isIconified();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSubmitButton(boolean hasText) {
|
||||||
|
mSubmitButton.setVisibility(
|
||||||
|
isSubmitAreaEnabled() ? (hasText ? VISIBLE : INVISIBLE) : GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSubmitArea() {
|
||||||
|
int visibility = GONE;
|
||||||
|
if (isSubmitAreaEnabled()) {
|
||||||
|
if (mSubmitButton.getVisibility() == VISIBLE
|
||||||
|
|| mVoiceButton.getVisibility() == VISIBLE) {
|
||||||
|
visibility = VISIBLE;
|
||||||
|
} else {
|
||||||
|
visibility = INVISIBLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSubmitArea.setVisibility(visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCloseButton() {
|
private void updateCloseButton() {
|
||||||
@@ -790,22 +832,14 @@ public class SearchView extends LinearLayout {
|
|||||||
* be visible - i.e., if the user has typed a query, remove the voice button.
|
* be visible - i.e., if the user has typed a query, remove the voice button.
|
||||||
*/
|
*/
|
||||||
private void updateVoiceButton(boolean empty) {
|
private void updateVoiceButton(boolean empty) {
|
||||||
int visibility = View.GONE;
|
// If the voice button is to be visible, show it
|
||||||
if (mSearchable != null && mSearchable.getVoiceSearchEnabled() && empty
|
// Else, make it gone if the submit button is enabled, otherwise invisible to
|
||||||
&& !isIconified()) {
|
// avoid losing the real-estate
|
||||||
Intent testIntent = null;
|
int visibility = mSubmitButtonEnabled ? GONE : INVISIBLE;
|
||||||
if (mSearchable.getVoiceSearchLaunchWebSearch()) {
|
|
||||||
testIntent = mVoiceWebSearchIntent;
|
if (mVoiceButtonEnabled && !isIconified() && empty) {
|
||||||
} else if (mSearchable.getVoiceSearchLaunchRecognizer()) {
|
visibility = VISIBLE;
|
||||||
testIntent = mVoiceAppSearchIntent;
|
mSubmitButton.setVisibility(GONE);
|
||||||
}
|
|
||||||
if (testIntent != null) {
|
|
||||||
ResolveInfo ri = getContext().getPackageManager().resolveActivity(testIntent,
|
|
||||||
PackageManager.MATCH_DEFAULT_ONLY);
|
|
||||||
if (ri != null) {
|
|
||||||
visibility = View.VISIBLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mVoiceButton.setVisibility(visibility);
|
mVoiceButton.setVisibility(visibility);
|
||||||
}
|
}
|
||||||
@@ -825,12 +859,11 @@ public class SearchView extends LinearLayout {
|
|||||||
CharSequence text = mQueryTextView.getText();
|
CharSequence text = mQueryTextView.getText();
|
||||||
boolean hasText = !TextUtils.isEmpty(text);
|
boolean hasText = !TextUtils.isEmpty(text);
|
||||||
if (isSubmitButtonEnabled()) {
|
if (isSubmitButtonEnabled()) {
|
||||||
mSubmitButton.setVisibility(hasText ? VISIBLE : GONE);
|
updateSubmitButton(hasText);
|
||||||
requestLayout();
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
updateVoiceButton(!hasText);
|
updateVoiceButton(!hasText);
|
||||||
updateCloseButton();
|
updateCloseButton();
|
||||||
|
updateSubmitArea();
|
||||||
if (mOnQueryChangeListener != null) {
|
if (mOnQueryChangeListener != null) {
|
||||||
mOnQueryChangeListener.onQueryTextChanged(newText.toString());
|
mOnQueryChangeListener.onQueryTextChanged(newText.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,8 +100,8 @@
|
|||||||
android:id="@+id/search_close_btn"
|
android:id="@+id/search_close_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingLeft="4dip"
|
android:paddingLeft="8dip"
|
||||||
android:paddingRight="4dip"
|
android:paddingRight="8dip"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:src="?android:attr/searchViewCloseIcon"
|
android:src="?android:attr/searchViewCloseIcon"
|
||||||
@@ -111,26 +111,34 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<LinearLayout
|
||||||
android:id="@+id/search_go_btn"
|
android:id="@+id/submit_area"
|
||||||
|
android:orientation="horizontal"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:paddingLeft="4dip"
|
|
||||||
android:paddingRight="4dip"
|
|
||||||
android:background="?android:attr/selectableItemBackground"
|
|
||||||
android:src="?android:attr/searchViewGoIcon"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/search_voice_btn"
|
android:id="@+id/search_go_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:paddingLeft="4dip"
|
android:paddingLeft="16dip"
|
||||||
android:paddingRight="4dip"
|
android:paddingRight="16dip"
|
||||||
android:src="?android:attr/searchViewVoiceIcon"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:src="?android:attr/searchViewGoIcon"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/search_voice_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingLeft="16dip"
|
||||||
|
android:paddingRight="16dip"
|
||||||
|
android:src="?android:attr/searchViewVoiceIcon"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user