Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 69984d7

Browse files
author
Alexander Sokol
committed
add an option to keep search view query between close/open events; add gradlew chmod +x permission
1 parent 49710d2 commit 69984d7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

gradlew

100644100755
File mode changed.

simplesearchview/src/main/java/com/ferfalk/simplesearchview/SimpleSearchView.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class SimpleSearchView extends FrameLayout {
9393
private SearchViewListener searchViewListener;
9494

9595
private boolean searchIsClosing = false;
96+
private boolean keepQuery = false;
9697

9798
public SimpleSearchView(Context context) {
9899
this(context, null);
@@ -258,6 +259,7 @@ public Parcelable onSaveInstanceState() {
258259
savedState.query = query != null ? query.toString() : null;
259260
savedState.isSearchOpen = isSearchOpen;
260261
savedState.animationDuration = animationDuration;
262+
savedState.keepQuery = keepQuery;
261263

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

272274
SavedState savedState = (SavedState) state;
273275

276+
query = savedState.query;
277+
animationDuration = savedState.animationDuration;
278+
voiceSearchPrompt = savedState.voiceSearchPrompt;
279+
keepQuery = savedState.keepQuery;
280+
274281
if (savedState.isSearchOpen) {
275282
showSearch(false);
276283
setQuery(savedState.query, false);
@@ -340,6 +347,15 @@ private boolean isVoiceAvailable() {
340347
return !activities.isEmpty();
341348
}
342349

350+
/**
351+
* Saves query value in EditText after close/open events
352+
*
353+
* @param keepQuery keeps query if true
354+
*/
355+
public void setKeepQuery(boolean keepQuery) {
356+
this.keepQuery = keepQuery;
357+
}
358+
343359
/**
344360
* Shows search with animation
345361
*/
@@ -357,7 +373,7 @@ public void showSearch(boolean animate) {
357373
return;
358374
}
359375

360-
searchEditText.setText(null);
376+
searchEditText.setText(keepQuery ? query : null);
361377
searchEditText.requestFocus();
362378

363379
if (animate) {
@@ -815,6 +831,7 @@ public SavedState[] newArray(int size) {
815831
boolean isSearchOpen;
816832
int animationDuration;
817833
String voiceSearchPrompt;
834+
boolean keepQuery;
818835

819836
SavedState(Parcelable superState) {
820837
super(superState);
@@ -826,6 +843,7 @@ private SavedState(Parcel in) {
826843
this.isSearchOpen = in.readInt() == 1;
827844
this.animationDuration = in.readInt();
828845
this.voiceSearchPrompt = in.readString();
846+
this.keepQuery = in.readInt() == 1;
829847
}
830848

831849
@Override
@@ -835,6 +853,7 @@ public void writeToParcel(Parcel out, int flags) {
835853
out.writeInt(isSearchOpen ? 1 : 0);
836854
out.writeInt(animationDuration);
837855
out.writeString(voiceSearchPrompt);
856+
out.writeInt(keepQuery ? 1 : 0);
838857
}
839858
}
840859

0 commit comments

Comments
 (0)