1 /*
2  * Copyright (C) 2016 The Android Open Source 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.android.contacts.logging;
17 
18 import android.os.Parcel;
19 import android.os.Parcelable;
20 
21 import com.google.common.base.MoreObjects;
22 
23 /**
24  * Describes the results of a user search for a particular contact.
25  */
26 public final class SearchState implements Parcelable {
27 
28     /** The length of the query string input by the user. */
29     public int queryLength;
30 
31     /** The number of partitions (groups of results) presented to the user. */
32     public int numPartitions;
33 
34     /** The total number of results (across all partitions) presented to the user. */
35     public int numResults;
36 
37     /** The number of results presented to the user in the partition that was selected. */
38     public int numResultsInSelectedPartition = -1;
39 
40     /** The zero-based index of the partition in which the clicked query result resides. */
41     public int selectedPartition = -1;
42 
43     /** The index of the clicked query result within its partition. */
44     public int selectedIndexInPartition = -1;
45 
46     /**
47      * The zero-based index of the clicked query result among all results displayed to the user
48      * (across partitions).
49      */
50     public int selectedIndex = -1;
51 
52     public static final Creator<SearchState> CREATOR = new Creator<SearchState>() {
53         @Override
54         public SearchState createFromParcel(Parcel in) {
55             return new SearchState(in);
56         }
57 
58         @Override
59         public SearchState[] newArray(int size) {
60             return new SearchState[size];
61         }
62     };
63 
SearchState()64     public SearchState() {
65     }
66 
SearchState(Parcel source)67     protected SearchState(Parcel source) {
68         readFromParcel(source);
69     }
70 
71     @Override
toString()72     public String toString() {
73         return MoreObjects.toStringHelper(this)
74                 .add("queryLength", queryLength)
75                 .add("numPartitions", numPartitions)
76                 .add("numResults", numResults)
77                 .add("numResultsInSelectedPartition", numResultsInSelectedPartition)
78                 .add("selectedPartition", selectedPartition)
79                 .add("selectedIndexInPartition", selectedIndexInPartition)
80                 .add("selectedIndex", selectedIndex)
81                 .toString();
82     }
83 
84     @Override
describeContents()85     public int describeContents() {
86         return 0;
87     }
88 
89     @Override
writeToParcel(Parcel dest, int flags)90     public void writeToParcel(Parcel dest, int flags) {
91         dest.writeInt(queryLength);
92         dest.writeInt(numPartitions);
93         dest.writeInt(numResults);
94         dest.writeInt(numResultsInSelectedPartition);
95         dest.writeInt(selectedPartition);
96         dest.writeInt(selectedIndexInPartition);
97         dest.writeInt(selectedIndex);
98     }
99 
readFromParcel(Parcel source)100     private void readFromParcel(Parcel source) {
101         queryLength = source.readInt();
102         numPartitions = source.readInt();
103         numResults = source.readInt();
104         numResultsInSelectedPartition = source.readInt();
105         selectedPartition = source.readInt();
106         selectedIndexInPartition = source.readInt();
107         selectedIndex = source.readInt();
108     }
109 }
110