blob: 28f743243234119a4948968889824a7b225e7057 [file] [log] [blame]
Steve McKay7a3b88c2015-09-23 17:21:40 -07001/*
2 * Copyright (C) 2013 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
17package com.android.documentsui;
18
Steve McKay3eb2d072016-01-25 19:00:22 -080019import android.annotation.IntDef;
Steve McKay7a3b88c2015-09-23 17:21:40 -070020import android.content.Intent;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.util.SparseArray;
24
25import com.android.documentsui.model.DocumentInfo;
26import com.android.documentsui.model.DocumentStack;
27import com.android.documentsui.model.DurableUtils;
Daichi Hirono3b36c5a2016-01-07 15:29:12 +090028import com.android.documentsui.model.RootInfo;
Steve McKay7a3b88c2015-09-23 17:21:40 -070029
Steve McKay3eb2d072016-01-25 19:00:22 -080030import java.lang.annotation.Retention;
31import java.lang.annotation.RetentionPolicy;
Steve McKay7a3b88c2015-09-23 17:21:40 -070032import java.util.ArrayList;
33import java.util.HashMap;
34import java.util.List;
35
36public class State implements android.os.Parcelable {
Steve McKay3eb2d072016-01-25 19:00:22 -080037
38 public static final int ACTION_OPEN = 1;
39 public static final int ACTION_CREATE = 2;
40 public static final int ACTION_GET_CONTENT = 3;
41 public static final int ACTION_OPEN_TREE = 4;
42 public static final int ACTION_MANAGE = 5;
43 public static final int ACTION_BROWSE = 6;
44 public static final int ACTION_PICK_COPY_DESTINATION = 8;
45
46 @IntDef(flag = true, value = {
47 MODE_UNKNOWN,
48 MODE_LIST,
49 MODE_GRID
50 })
51 @Retention(RetentionPolicy.SOURCE)
52 public @interface ViewMode {}
53 public static final int MODE_UNKNOWN = 0;
54 public static final int MODE_LIST = 1;
55 public static final int MODE_GRID = 2;
56
57 public static final int SORT_ORDER_UNKNOWN = 0;
58 public static final int SORT_ORDER_DISPLAY_NAME = 1;
59 public static final int SORT_ORDER_LAST_MODIFIED = 2;
60 public static final int SORT_ORDER_SIZE = 3;
61
Steve McKay7a3b88c2015-09-23 17:21:40 -070062 public int action;
63 public String[] acceptMimes;
64
Steve McKay3eb2d072016-01-25 19:00:22 -080065 /** Derived from local preferences */
66 public @ViewMode int derivedMode = MODE_GRID;
Steve McKay7a3b88c2015-09-23 17:21:40 -070067
68 /** Explicit user choice */
69 public int userSortOrder = SORT_ORDER_UNKNOWN;
70 /** Derived after loader */
71 public int derivedSortOrder = SORT_ORDER_DISPLAY_NAME;
72
73 public boolean allowMultiple;
Steve McKay9f9d5b42015-09-23 15:44:24 -070074 public boolean forceSize;
Steve McKay7a3b88c2015-09-23 17:21:40 -070075 public boolean showSize;
Steve McKay9f9d5b42015-09-23 15:44:24 -070076 public boolean localOnly;
77 public boolean forceAdvanced;
78 public boolean showAdvanced;
Steve McKay9f9d5b42015-09-23 15:44:24 -070079 public boolean restored;
80 public boolean directoryCopy;
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +090081 public boolean openableOnly;
Steve McKay7a3b88c2015-09-23 17:21:40 -070082 /** Transfer mode for file copy/move operations. */
83 public int transferMode;
84
85 /** Current user navigation stack; empty implies recents. */
86 public DocumentStack stack = new DocumentStack();
Steve McKay3eb2d072016-01-25 19:00:22 -080087 private boolean mStackTouched;
88
Steve McKay7a3b88c2015-09-23 17:21:40 -070089 /** Currently active search, overriding any stack. */
90 public String currentSearch;
91
92 /** Instance state for every shown directory */
93 public HashMap<String, SparseArray<Parcelable>> dirState = new HashMap<>();
94
95 /** Currently copying file */
96 public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>();
97
98 /** Name of the package that started DocsUI */
99 public List<String> excludedAuthorities = new ArrayList<>();
100
Steve McKay7a3b88c2015-09-23 17:21:40 -0700101 public void initAcceptMimes(Intent intent) {
102 if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
103 acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
104 } else {
105 String glob = intent.getType();
106 acceptMimes = new String[] { glob != null ? glob : "*/*" };
107 }
108 }
109
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900110 public void onRootChanged(RootInfo root) {
111 stack.root = root;
112 stack.clear();
113 mStackTouched = true;
114 }
115
116 public void pushDocument(DocumentInfo info) {
Daichi Hirono7f34b202016-01-08 12:22:09 +0900117 stack.push(info);
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900118 mStackTouched = true;
119 }
120
121 public void popDocument() {
122 stack.pop();
123 mStackTouched = true;
124 }
125
126 public void setStack(DocumentStack stack) {
127 this.stack = stack;
128 mStackTouched = true;
129 }
130
131 public boolean hasLocationChanged() {
132 return mStackTouched;
133 }
134
Steve McKay7a3b88c2015-09-23 17:21:40 -0700135 @Override
136 public int describeContents() {
137 return 0;
138 }
139
140 @Override
141 public void writeToParcel(Parcel out, int flags) {
142 out.writeInt(action);
Steve McKay7a3b88c2015-09-23 17:21:40 -0700143 out.writeStringArray(acceptMimes);
144 out.writeInt(userSortOrder);
145 out.writeInt(allowMultiple ? 1 : 0);
146 out.writeInt(forceSize ? 1 : 0);
147 out.writeInt(showSize ? 1 : 0);
148 out.writeInt(localOnly ? 1 : 0);
149 out.writeInt(forceAdvanced ? 1 : 0);
150 out.writeInt(showAdvanced ? 1 : 0);
Steve McKay7a3b88c2015-09-23 17:21:40 -0700151 out.writeInt(restored ? 1 : 0);
152 DurableUtils.writeToParcel(out, stack);
153 out.writeString(currentSearch);
154 out.writeMap(dirState);
155 out.writeList(selectedDocumentsForCopy);
156 out.writeList(excludedAuthorities);
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +0900157 out.writeInt(openableOnly ? 1 : 0);
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900158 out.writeInt(mStackTouched ? 1 : 0);
Steve McKay7a3b88c2015-09-23 17:21:40 -0700159 }
160
161 public static final Creator<State> CREATOR = new Creator<State>() {
162 @Override
163 public State createFromParcel(Parcel in) {
164 final State state = new State();
165 state.action = in.readInt();
Steve McKay7a3b88c2015-09-23 17:21:40 -0700166 state.acceptMimes = in.readStringArray();
167 state.userSortOrder = in.readInt();
168 state.allowMultiple = in.readInt() != 0;
169 state.forceSize = in.readInt() != 0;
170 state.showSize = in.readInt() != 0;
171 state.localOnly = in.readInt() != 0;
172 state.forceAdvanced = in.readInt() != 0;
173 state.showAdvanced = in.readInt() != 0;
Steve McKay7a3b88c2015-09-23 17:21:40 -0700174 state.restored = in.readInt() != 0;
175 DurableUtils.readFromParcel(in, state.stack);
176 state.currentSearch = in.readString();
177 in.readMap(state.dirState, null);
178 in.readList(state.selectedDocumentsForCopy, null);
179 in.readList(state.excludedAuthorities, null);
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +0900180 state.openableOnly = in.readInt() != 0;
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900181 state.mStackTouched = in.readInt() != 0;
Steve McKay7a3b88c2015-09-23 17:21:40 -0700182 return state;
183 }
184
185 @Override
186 public State[] newArray(int size) {
187 return new State[size];
188 }
189 };
Ben Kwa84cebbe2015-09-25 14:48:29 -0700190}