Skip to content

Commit

Permalink
add an option to keep search view query between close/open events; ad…
Browse files Browse the repository at this point in the history
…d gradlew chmod +x permission
  • Loading branch information
Alexander Sokol committed Apr 9, 2019
1 parent 49710d2 commit 69984d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Empty file modified gradlew 100644 → 100755
Empty file.
Expand Up @@ -93,6 +93,7 @@ public class SimpleSearchView extends FrameLayout {
private SearchViewListener searchViewListener;

private boolean searchIsClosing = false;
private boolean keepQuery = false;

public SimpleSearchView(Context context) {
this(context, null);
Expand Down Expand Up @@ -258,6 +259,7 @@ public Parcelable onSaveInstanceState() {
savedState.query = query != null ? query.toString() : null;
savedState.isSearchOpen = isSearchOpen;
savedState.animationDuration = animationDuration;
savedState.keepQuery = keepQuery;

return savedState;
}
Expand All @@ -271,6 +273,11 @@ public void onRestoreInstanceState(Parcelable state) {

SavedState savedState = (SavedState) state;

query = savedState.query;
animationDuration = savedState.animationDuration;
voiceSearchPrompt = savedState.voiceSearchPrompt;
keepQuery = savedState.keepQuery;

if (savedState.isSearchOpen) {
showSearch(false);
setQuery(savedState.query, false);
Expand Down Expand Up @@ -340,6 +347,15 @@ private boolean isVoiceAvailable() {
return !activities.isEmpty();
}

/**
* Saves query value in EditText after close/open events
*
* @param keepQuery keeps query if true
*/
public void setKeepQuery(boolean keepQuery) {
this.keepQuery = keepQuery;
}

/**
* Shows search with animation
*/
Expand All @@ -357,7 +373,7 @@ public void showSearch(boolean animate) {
return;
}

searchEditText.setText(null);
searchEditText.setText(keepQuery ? query : null);
searchEditText.requestFocus();

if (animate) {
Expand Down Expand Up @@ -815,6 +831,7 @@ public SavedState[] newArray(int size) {
boolean isSearchOpen;
int animationDuration;
String voiceSearchPrompt;
boolean keepQuery;

SavedState(Parcelable superState) {
super(superState);
Expand All @@ -826,6 +843,7 @@ private SavedState(Parcel in) {
this.isSearchOpen = in.readInt() == 1;
this.animationDuration = in.readInt();
this.voiceSearchPrompt = in.readString();
this.keepQuery = in.readInt() == 1;
}

@Override
Expand All @@ -835,6 +853,7 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(isSearchOpen ? 1 : 0);
out.writeInt(animationDuration);
out.writeString(voiceSearchPrompt);
out.writeInt(keepQuery ? 1 : 0);
}
}

Expand Down

0 comments on commit 69984d7

Please sign in to comment.