@@ -93,6 +93,7 @@ public class SimpleSearchView extends FrameLayout {
93
93
private SearchViewListener searchViewListener ;
94
94
95
95
private boolean searchIsClosing = false ;
96
+ private boolean keepQuery = false ;
96
97
97
98
public SimpleSearchView (Context context ) {
98
99
this (context , null );
@@ -258,6 +259,7 @@ public Parcelable onSaveInstanceState() {
258
259
savedState .query = query != null ? query .toString () : null ;
259
260
savedState .isSearchOpen = isSearchOpen ;
260
261
savedState .animationDuration = animationDuration ;
262
+ savedState .keepQuery = keepQuery ;
261
263
262
264
return savedState ;
263
265
}
@@ -271,6 +273,11 @@ public void onRestoreInstanceState(Parcelable state) {
271
273
272
274
SavedState savedState = (SavedState ) state ;
273
275
276
+ query = savedState .query ;
277
+ animationDuration = savedState .animationDuration ;
278
+ voiceSearchPrompt = savedState .voiceSearchPrompt ;
279
+ keepQuery = savedState .keepQuery ;
280
+
274
281
if (savedState .isSearchOpen ) {
275
282
showSearch (false );
276
283
setQuery (savedState .query , false );
@@ -340,6 +347,15 @@ private boolean isVoiceAvailable() {
340
347
return !activities .isEmpty ();
341
348
}
342
349
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
+
343
359
/**
344
360
* Shows search with animation
345
361
*/
@@ -357,7 +373,7 @@ public void showSearch(boolean animate) {
357
373
return ;
358
374
}
359
375
360
- searchEditText .setText (null );
376
+ searchEditText .setText (keepQuery ? query : null );
361
377
searchEditText .requestFocus ();
362
378
363
379
if (animate ) {
@@ -815,6 +831,7 @@ public SavedState[] newArray(int size) {
815
831
boolean isSearchOpen ;
816
832
int animationDuration ;
817
833
String voiceSearchPrompt ;
834
+ boolean keepQuery ;
818
835
819
836
SavedState (Parcelable superState ) {
820
837
super (superState );
@@ -826,6 +843,7 @@ private SavedState(Parcel in) {
826
843
this .isSearchOpen = in .readInt () == 1 ;
827
844
this .animationDuration = in .readInt ();
828
845
this .voiceSearchPrompt = in .readString ();
846
+ this .keepQuery = in .readInt () == 1 ;
829
847
}
830
848
831
849
@ Override
@@ -835,6 +853,7 @@ public void writeToParcel(Parcel out, int flags) {
835
853
out .writeInt (isSearchOpen ? 1 : 0 );
836
854
out .writeInt (animationDuration );
837
855
out .writeString (voiceSearchPrompt );
856
+ out .writeInt (keepQuery ? 1 : 0 );
838
857
}
839
858
}
840
859
0 commit comments