PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/cyanogenmod/filemanager/parcelables/SearchInfoParcelable.java

https://bitbucket.org/androidarmv6/android_packages_apps_cmfilemanager
Java | 234 lines | 106 code | 25 blank | 103 comment | 16 complexity | 9bf07e65cee17c0f66783a42a84e0606 MD5 | raw file
  1. /*
  2. * Copyright (C) 2012 The CyanogenMod Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.cyanogenmod.filemanager.parcelables;
  17. import android.os.Parcel;
  18. import android.os.Parcelable;
  19. import com.cyanogenmod.filemanager.FileManagerApplication;
  20. import com.cyanogenmod.filemanager.R;
  21. import com.cyanogenmod.filemanager.model.Query;
  22. import com.cyanogenmod.filemanager.model.SearchResult;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * A serializer/deserializer class for {@link "SearchActivity"}.
  27. */
  28. public class SearchInfoParcelable extends HistoryNavigable {
  29. private static final long serialVersionUID = 3051428434374087971L;
  30. private String mSearchDirectory;
  31. private List<SearchResult> mSearchResultList;
  32. private Query mSearchQuery;
  33. private boolean mSuccessNavigation = false;
  34. /**
  35. * Constructor of <code>SearchInfoParcelable</code>.
  36. */
  37. public SearchInfoParcelable() {
  38. super();
  39. }
  40. /**
  41. * Constructor of <code>SearchInfoParcelable</code>.
  42. *
  43. * @param in The parcel information
  44. */
  45. public SearchInfoParcelable(Parcel in) {
  46. readFromParcel(in);
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. @Override
  52. public String getTitle() {
  53. return FileManagerApplication.getInstance().
  54. getResources().
  55. getString(
  56. R.string.search_result_name,
  57. this.mSearchQuery.getTerms());
  58. }
  59. /**
  60. * {@inheritDoc}
  61. */
  62. @Override
  63. public String getDescription() {
  64. return this.mSearchDirectory;
  65. }
  66. /**
  67. * Method that returns the directory where to search.
  68. *
  69. * @return String The directory where to search
  70. */
  71. public String getSearchDirectory() {
  72. return this.mSearchDirectory;
  73. }
  74. /**
  75. * Method that sets the directory where to search.
  76. *
  77. * @param searchDirectory The directory where to search
  78. */
  79. public void setSearchDirectory(String searchDirectory) {
  80. this.mSearchDirectory = searchDirectory;
  81. }
  82. /**
  83. * Method that returns the search result list.
  84. *
  85. * @return List<SearchResult> The search result list
  86. */
  87. public List<SearchResult> getSearchResultList() {
  88. return this.mSearchResultList;
  89. }
  90. /**
  91. * Method that sets the search result list.
  92. *
  93. * @param searchResultList The search result list
  94. */
  95. public void setSearchResultList(List<SearchResult> searchResultList) {
  96. this.mSearchResultList = searchResultList;
  97. }
  98. /**
  99. * Method that returns the query terms of the search.
  100. *
  101. * @return Query The query terms of the search
  102. */
  103. public Query getSearchQuery() {
  104. return this.mSearchQuery;
  105. }
  106. /**
  107. * Method that sets the query terms of the search.
  108. *
  109. * @param searchQuery The query terms of the search
  110. */
  111. public void setSearchQuery(Query searchQuery) {
  112. this.mSearchQuery = searchQuery;
  113. }
  114. /**
  115. * Method that returns if the search navigation was success.
  116. *
  117. * @return boolean If the search navigation was success
  118. */
  119. public boolean isSuccessNavigation() {
  120. return this.mSuccessNavigation;
  121. }
  122. /**
  123. * Method that returns if the search navigation was success.
  124. *
  125. * @param successNavigation If the search navigation was success
  126. */
  127. public void setSuccessNavigation(boolean successNavigation) {
  128. this.mSuccessNavigation = successNavigation;
  129. }
  130. /**
  131. * {@inheritDoc}
  132. */
  133. @Override
  134. public int describeContents() {
  135. return 0;
  136. }
  137. /**
  138. * {@inheritDoc}
  139. */
  140. @Override
  141. public void writeToParcel(Parcel dest, int flags) {
  142. //- 0
  143. dest.writeInt(this.mSearchDirectory == null ? 0 : 1);
  144. if (this.mSearchDirectory != null) {
  145. dest.writeString(this.mSearchDirectory);
  146. }
  147. //- 1
  148. dest.writeInt(this.mSearchResultList == null ? 0 : 1);
  149. if (this.mSearchResultList != null) {
  150. dest.writeList(this.mSearchResultList);
  151. }
  152. //- 2
  153. dest.writeInt(this.mSearchQuery == null ? 0 : 1);
  154. if (this.mSearchQuery != null) {
  155. dest.writeSerializable(this.mSearchQuery);
  156. }
  157. //- 3
  158. dest.writeInt(this.mSuccessNavigation ? 1 : 0);
  159. }
  160. /**
  161. * Fill the object from the parcel information.
  162. *
  163. * @param in The parcel information to recreate the object
  164. */
  165. private void readFromParcel(Parcel in) {
  166. //- 0
  167. int hasSearchDirectory = in.readInt();
  168. if (hasSearchDirectory == 1) {
  169. this.mSearchDirectory = in.readString();
  170. }
  171. //- 1
  172. int hasSearchResultList = in.readInt();
  173. if (hasSearchResultList == 1) {
  174. List<SearchResult> searchResultList = new ArrayList<SearchResult>();
  175. in.readList(searchResultList, SearchInfoParcelable.class.getClassLoader());
  176. this.mSearchResultList = new ArrayList<SearchResult>(searchResultList);
  177. }
  178. //- 2
  179. int hasSearchQuery = in.readInt();
  180. if (hasSearchQuery == 1) {
  181. this.mSearchQuery = (Query)in.readSerializable();
  182. }
  183. //- 3
  184. this.mSuccessNavigation = in.readInt() != 1;
  185. }
  186. /**
  187. * The {@link android.os.Parcelable.Creator}.
  188. *
  189. * This field is needed for Android to be able to
  190. * create new objects, individually or as arrays.
  191. */
  192. public static final Parcelable.Creator<SearchInfoParcelable> CREATOR =
  193. new Parcelable.Creator<SearchInfoParcelable>() {
  194. /**
  195. * {@inheritDoc}
  196. */
  197. @Override
  198. public SearchInfoParcelable createFromParcel(Parcel in) {
  199. return new SearchInfoParcelable(in);
  200. }
  201. /**
  202. * {@inheritDoc}
  203. */
  204. @Override
  205. public SearchInfoParcelable[] newArray(int size) {
  206. return new SearchInfoParcelable[size];
  207. }
  208. };
  209. }