blob: 14ff902a56a84d7dad4ff05e49d640b3b0f24677 [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
19import android.content.Intent;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.util.SparseArray;
23
24import com.android.documentsui.model.DocumentInfo;
25import com.android.documentsui.model.DocumentStack;
26import com.android.documentsui.model.DurableUtils;
Daichi Hirono3b36c5a2016-01-07 15:29:12 +090027import com.android.documentsui.model.RootInfo;
Steve McKay7a3b88c2015-09-23 17:21:40 -070028
29import java.util.ArrayList;
30import java.util.HashMap;
31import java.util.List;
32
33public class State implements android.os.Parcelable {
34 public int action;
35 public String[] acceptMimes;
36
37 /** Explicit user choice */
38 public int userMode = MODE_UNKNOWN;
39 /** Derived after loader */
Tomasz Mikolajewski5351e3f2015-12-28 17:57:30 +090040 public int derivedMode = MODE_GRID;
Steve McKay7a3b88c2015-09-23 17:21:40 -070041
42 /** Explicit user choice */
43 public int userSortOrder = SORT_ORDER_UNKNOWN;
44 /** Derived after loader */
45 public int derivedSortOrder = SORT_ORDER_DISPLAY_NAME;
46
47 public boolean allowMultiple;
Steve McKay9f9d5b42015-09-23 15:44:24 -070048 public boolean forceSize;
Steve McKay7a3b88c2015-09-23 17:21:40 -070049 public boolean showSize;
Steve McKay9f9d5b42015-09-23 15:44:24 -070050 public boolean localOnly;
51 public boolean forceAdvanced;
52 public boolean showAdvanced;
Steve McKay9f9d5b42015-09-23 15:44:24 -070053 public boolean restored;
54 public boolean directoryCopy;
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +090055 public boolean openableOnly;
Steve McKay7a3b88c2015-09-23 17:21:40 -070056 /** Transfer mode for file copy/move operations. */
57 public int transferMode;
58
59 /** Current user navigation stack; empty implies recents. */
60 public DocumentStack stack = new DocumentStack();
61 /** Currently active search, overriding any stack. */
62 public String currentSearch;
63
64 /** Instance state for every shown directory */
65 public HashMap<String, SparseArray<Parcelable>> dirState = new HashMap<>();
66
67 /** Currently copying file */
68 public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>();
69
70 /** Name of the package that started DocsUI */
71 public List<String> excludedAuthorities = new ArrayList<>();
72
73 public static final int ACTION_OPEN = 1;
74 public static final int ACTION_CREATE = 2;
75 public static final int ACTION_GET_CONTENT = 3;
76 public static final int ACTION_OPEN_TREE = 4;
77 public static final int ACTION_MANAGE = 5;
78 public static final int ACTION_BROWSE = 6;
Ben Kwa84cebbe2015-09-25 14:48:29 -070079 public static final int ACTION_PICK_COPY_DESTINATION = 8;
Steve McKay7a3b88c2015-09-23 17:21:40 -070080
81 public static final int MODE_UNKNOWN = 0;
82 public static final int MODE_LIST = 1;
83 public static final int MODE_GRID = 2;
84
85 public static final int SORT_ORDER_UNKNOWN = 0;
86 public static final int SORT_ORDER_DISPLAY_NAME = 1;
87 public static final int SORT_ORDER_LAST_MODIFIED = 2;
88 public static final int SORT_ORDER_SIZE = 3;
89
Daichi Hirono3b36c5a2016-01-07 15:29:12 +090090 private boolean mStackTouched;
91
Steve McKay7a3b88c2015-09-23 17:21:40 -070092 public void initAcceptMimes(Intent intent) {
93 if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
94 acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
95 } else {
96 String glob = intent.getType();
97 acceptMimes = new String[] { glob != null ? glob : "*/*" };
98 }
99 }
100
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900101 public void onRootChanged(RootInfo root) {
102 stack.root = root;
103 stack.clear();
104 mStackTouched = true;
105 }
106
107 public void pushDocument(DocumentInfo info) {
108 stack.add(info);
109 mStackTouched = true;
110 }
111
112 public void popDocument() {
113 stack.pop();
114 mStackTouched = true;
115 }
116
117 public void setStack(DocumentStack stack) {
118 this.stack = stack;
119 mStackTouched = true;
120 }
121
122 public boolean hasLocationChanged() {
123 return mStackTouched;
124 }
125
Steve McKay7a3b88c2015-09-23 17:21:40 -0700126 @Override
127 public int describeContents() {
128 return 0;
129 }
130
131 @Override
132 public void writeToParcel(Parcel out, int flags) {
133 out.writeInt(action);
134 out.writeInt(userMode);
135 out.writeStringArray(acceptMimes);
136 out.writeInt(userSortOrder);
137 out.writeInt(allowMultiple ? 1 : 0);
138 out.writeInt(forceSize ? 1 : 0);
139 out.writeInt(showSize ? 1 : 0);
140 out.writeInt(localOnly ? 1 : 0);
141 out.writeInt(forceAdvanced ? 1 : 0);
142 out.writeInt(showAdvanced ? 1 : 0);
Steve McKay7a3b88c2015-09-23 17:21:40 -0700143 out.writeInt(restored ? 1 : 0);
144 DurableUtils.writeToParcel(out, stack);
145 out.writeString(currentSearch);
146 out.writeMap(dirState);
147 out.writeList(selectedDocumentsForCopy);
148 out.writeList(excludedAuthorities);
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +0900149 out.writeInt(openableOnly ? 1 : 0);
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900150 out.writeInt(mStackTouched ? 1 : 0);
Steve McKay7a3b88c2015-09-23 17:21:40 -0700151 }
152
153 public static final Creator<State> CREATOR = new Creator<State>() {
154 @Override
155 public State createFromParcel(Parcel in) {
156 final State state = new State();
157 state.action = in.readInt();
158 state.userMode = in.readInt();
159 state.acceptMimes = in.readStringArray();
160 state.userSortOrder = in.readInt();
161 state.allowMultiple = in.readInt() != 0;
162 state.forceSize = in.readInt() != 0;
163 state.showSize = in.readInt() != 0;
164 state.localOnly = in.readInt() != 0;
165 state.forceAdvanced = in.readInt() != 0;
166 state.showAdvanced = in.readInt() != 0;
Steve McKay7a3b88c2015-09-23 17:21:40 -0700167 state.restored = in.readInt() != 0;
168 DurableUtils.readFromParcel(in, state.stack);
169 state.currentSearch = in.readString();
170 in.readMap(state.dirState, null);
171 in.readList(state.selectedDocumentsForCopy, null);
172 in.readList(state.excludedAuthorities, null);
Tomasz Mikolajewskia8057a92015-11-16 11:41:28 +0900173 state.openableOnly = in.readInt() != 0;
Daichi Hirono3b36c5a2016-01-07 15:29:12 +0900174 state.mStackTouched = in.readInt() != 0;
Steve McKay7a3b88c2015-09-23 17:21:40 -0700175 return state;
176 }
177
178 @Override
179 public State[] newArray(int size) {
180 return new State[size];
181 }
182 };
Ben Kwa84cebbe2015-09-25 14:48:29 -0700183}