package com.cyanogenmod.filemanager.model;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.text.TextUtils;
import java.io.Serializable;
* A class that restrict the number of queries that can
* be made to the application search system.
*/
-public class Query implements Serializable {
+public class Query implements Serializable, Parcelable {
- private static final long serialVersionUID = 3485374541081012723L;
+ private static final long serialVersionUID = 638590514968634860L;
//IMP! This need to be sync which the command_list.xml resource
//to have the same slots as the filled for the find command
}
/**
+ * Constructor of <code>Query</code>.
+ *
+ * @param in The parcel information
+ */
+ public Query(Parcel in) {
+ readFromParcel(in);
+ }
+
+ /**
* Method that returns the value of an slot.
*
* @param slot The slot number
}
return terms;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeStringArray(this.mQUERIES);
+ }
+
+ /**
+ * Fill the object from the parcel information.
+ *
+ * @param in The parcel information to recreate the object
+ */
+ private void readFromParcel(Parcel in) {
+ String[] queries = in.readStringArray();
+ if (queries != null) {
+ int count = Math.min(SLOTS_COUNT, queries.length);
+ for (int i = 0; i < count; i++) {
+ mQUERIES[i] = queries[i];
+ }
+ }
+ }
+
+ /**
+ * The {@link android.os.Parcelable.Creator}.
+ *
+ * This field is needed for Android to be able to
+ * create new objects, individually or as arrays.
+ */
+ public static final Parcelable.Creator<Query> CREATOR =
+ new Parcelable.Creator<Query>() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Query createFromParcel(Parcel in) {
+ return new Query(in);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Query[] newArray(int size) {
+ return new Query[size];
+ }
+ };
}
private String mSearchDirectory;
private List<SearchResult> mSearchResultList;
private Query mSearchQuery;
+ private String mTitle;
private boolean mSuccessNavigation = false;
/**
*/
public SearchInfoParcelable() {
super();
+ setTitle();
}
/**
*/
@Override
public String getTitle() {
- return FileManagerApplication.getInstance().
- getResources().
- getString(
- R.string.search_result_name,
- this.mSearchQuery.getTerms());
+ return mTitle;
+ }
+
+ private void setTitle() {
+ String terms = "";
+ if (this.mSearchQuery != null) {
+ terms = this.mSearchQuery.getTerms();
+ }
+ mTitle = FileManagerApplication.getInstance().getResources().getString(
+ R.string.search_result_name, terms);
}
/**
*/
public void setSearchQuery(Query searchQuery) {
this.mSearchQuery = searchQuery;
+ setTitle();
}
/**
//- 2
dest.writeInt(this.mSearchQuery == null ? 0 : 1);
if (this.mSearchQuery != null) {
- dest.writeSerializable(this.mSearchQuery);
+ dest.writeParcelable(this.mSearchQuery, 0);
}
//- 3
dest.writeInt(this.mSuccessNavigation ? 1 : 0);
//- 2
int hasSearchQuery = in.readInt();
if (hasSearchQuery == 1) {
- this.mSearchQuery = (Query)in.readSerializable();
+ this.mSearchQuery = (Query)in.readParcelable(getClass().getClassLoader());
}
+ setTitle();
//- 3
this.mSuccessNavigation = in.readInt() != 1;
}