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