1 /*
2  * Copyright (C) 2019 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 
17 package com.android.documentsui.picker;
18 
19 import android.net.Uri;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import com.android.documentsui.MetricConsts;
24 
25 public class PickResult implements android.os.Parcelable {
26     private int mActionCount;
27     private long mDuration;
28     private int mFileCount;
29     private boolean mIsSearching;
30     private @MetricConsts.Root int mRoot;
31     private @MetricConsts.Mime int mMimeType;
32     private int mRepeatedPickTimes;
33 
34     // only used for single-select case to get the mRepeatedPickTimes and mMimeType
35     private Uri mFileUri;
36     private long mPickStartTime;
37 
38     /**
39      * get total action count during picking.
40      *
41      * @return action count
42      */
getActionCount()43     public int getActionCount() {
44         return mActionCount;
45     }
46 
47     /**
48      * increase action count.
49      */
increaseActionCount()50     public void increaseActionCount() {
51         mActionCount++;
52     }
53 
54     /**
55      * get pick duration
56      *
57      * @return pick duration
58      */
getDuration()59     public long getDuration() {
60         return mDuration;
61     }
62 
63     /**
64      * increase pick duration.
65      *
66      * @param currentMillis current time millis
67      */
increaseDuration(long currentMillis)68     public void increaseDuration(long currentMillis) {
69         mDuration += currentMillis - mPickStartTime;
70         setPickStartTime(currentMillis);
71     }
72 
73     /**
74      * set the pick start time.
75      *
76      * @param millis
77      */
setPickStartTime(long millis)78     public void setPickStartTime(long millis) {
79         mPickStartTime = millis;
80     }
81 
82     /**
83      * get number of files picked.
84      *
85      * @return file count
86      */
getFileCount()87     public int getFileCount() {
88         return mFileCount;
89     }
90 
91     /**
92      * set number of files picked.
93      *
94      * @param count
95      */
setFileCount(int count)96     public void setFileCount(int count) {
97         mFileCount = count;
98     }
99 
100     /**
101      * check whether this pick is under searching.
102      *
103      * @return under searching or not
104      */
isSearching()105     public boolean isSearching() {
106         return mIsSearching;
107     }
108 
109     /**
110      * set whether this pick is under searching.
111      *
112      * @param isSearching
113      */
setIsSearching(boolean isSearching)114     public void setIsSearching(boolean isSearching) {
115         this.mIsSearching = isSearching;
116     }
117 
118     /**
119      * get the root where the file is picked.
120      *
121      * @return root
122      */
getRoot()123     public int getRoot() {
124         return mRoot;
125     }
126 
127     /**
128      * set the root where the file is picked.
129      *
130      * @param root
131      */
setRoot(@etricConsts.Root int root)132     public void setRoot(@MetricConsts.Root int root) {
133         this.mRoot = root;
134     }
135 
136     /**
137      * get the mime type of the pick file.
138      *
139      * @return mime type
140      */
getMimeType()141     public int getMimeType() {
142         return mMimeType;
143     }
144 
145     /**
146      * set the mime type of the pick file.
147      *
148      * @param mimeType
149      */
setMimeType(@etricConsts.Mime int mimeType)150     public void setMimeType(@MetricConsts.Mime int mimeType) {
151         this.mMimeType = mimeType;
152     }
153 
154     /**
155      * get number of time the selected file is picked repeatedly.
156      *
157      * @return repeatedly pick count
158      */
getRepeatedPickTimes()159     public int getRepeatedPickTimes() {
160         return mRepeatedPickTimes;
161     }
162 
163     /**
164      * set number of time the selected file is picked repeatedly.
165      *
166      * @param times the repeatedly pick times
167      */
setRepeatedPickTimes(int times)168     public void setRepeatedPickTimes(int times) {
169         mRepeatedPickTimes = times;
170     }
171 
172     /**
173      * get the uri of the selected doc.
174      *
175      * @return file uri
176      */
getFileUri()177     public Uri getFileUri() {
178         return mFileUri;
179     }
180 
181     /**
182      * set the uri of the selected doc.
183      *
184      * @param fileUri the selected doc uri
185      */
setFileUri(Uri fileUri)186     public void setFileUri(Uri fileUri) {
187         this.mFileUri = fileUri;
188     }
189 
190     @Override
describeContents()191     public int describeContents() {
192         return 0;
193     }
194 
195     @Override
writeToParcel(Parcel out, int flags)196     public void writeToParcel(Parcel out, int flags) {
197         out.writeInt(mActionCount);
198         out.writeLong(mDuration);
199         out.writeInt(mFileCount);
200         out.writeInt(mIsSearching ? 1 : 0);
201         out.writeInt(mRoot);
202         out.writeInt(mMimeType);
203         out.writeInt(mRepeatedPickTimes);
204     }
205 
206     public static final Parcelable.ClassLoaderCreator<PickResult>
207             CREATOR = new Parcelable.ClassLoaderCreator<PickResult>() {
208         @Override
209         public PickResult createFromParcel(Parcel in) {
210             return createFromParcel(in, null);
211         }
212 
213         @Override
214         public PickResult createFromParcel(Parcel in, ClassLoader loader) {
215             final PickResult result = new PickResult();
216             result.mActionCount = in.readInt();
217             result.mDuration = in.readLong();
218             result.mFileCount = in.readInt();
219             result.mIsSearching = in.readInt() != 0;
220             result.mRoot = in.readInt();
221             result.mMimeType = in.readInt();
222             result.mRepeatedPickTimes = in.readInt();
223             return result;
224         }
225 
226         @Override
227         public PickResult[] newArray(int size) {
228             return new PickResult[size];
229         }
230     };
231 
232     @Override
toString()233     public String toString() {
234         return "PickResults{" +
235                 "actionCount=" + mActionCount +
236                 ", mDuration=" + mDuration +
237                 ", mFileCount=" + mFileCount +
238                 ", mIsSearching=" + mIsSearching +
239                 ", mRoot=" + mRoot +
240                 ", mMimeType=" + mMimeType +
241                 ", mRepeatedPickTimes=" + mRepeatedPickTimes +
242                 '}';
243     }
244 }
245