Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui; |
| 18 | |
| 19 | import android.content.Intent; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.util.SparseArray; |
| 23 | |
| 24 | import com.android.documentsui.model.DocumentInfo; |
| 25 | import com.android.documentsui.model.DocumentStack; |
| 26 | import com.android.documentsui.model.DurableUtils; |
Daichi Hirono | 3b36c5a | 2016-01-07 15:29:12 +0900 | [diff] [blame^] | 27 | import com.android.documentsui.model.RootInfo; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 28 | |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.HashMap; |
| 31 | import java.util.List; |
| 32 | |
| 33 | public 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 Mikolajewski | 5351e3f | 2015-12-28 17:57:30 +0900 | [diff] [blame] | 40 | public int derivedMode = MODE_GRID; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 41 | |
| 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 McKay | 9f9d5b4 | 2015-09-23 15:44:24 -0700 | [diff] [blame] | 48 | public boolean forceSize; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 49 | public boolean showSize; |
Steve McKay | 9f9d5b4 | 2015-09-23 15:44:24 -0700 | [diff] [blame] | 50 | public boolean localOnly; |
| 51 | public boolean forceAdvanced; |
| 52 | public boolean showAdvanced; |
Steve McKay | 9f9d5b4 | 2015-09-23 15:44:24 -0700 | [diff] [blame] | 53 | public boolean restored; |
| 54 | public boolean directoryCopy; |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 55 | public boolean openableOnly; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 56 | /** 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 Kwa | 84cebbe | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 79 | public static final int ACTION_PICK_COPY_DESTINATION = 8; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 80 | |
| 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 Hirono | 3b36c5a | 2016-01-07 15:29:12 +0900 | [diff] [blame^] | 90 | private boolean mStackTouched; |
| 91 | |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 92 | 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 Hirono | 3b36c5a | 2016-01-07 15:29:12 +0900 | [diff] [blame^] | 101 | 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 McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 126 | @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 McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 143 | 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 Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 149 | out.writeInt(openableOnly ? 1 : 0); |
Daichi Hirono | 3b36c5a | 2016-01-07 15:29:12 +0900 | [diff] [blame^] | 150 | out.writeInt(mStackTouched ? 1 : 0); |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 151 | } |
| 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 McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 167 | 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 Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 173 | state.openableOnly = in.readInt() != 0; |
Daichi Hirono | 3b36c5a | 2016-01-07 15:29:12 +0900 | [diff] [blame^] | 174 | state.mStackTouched = in.readInt() != 0; |
Steve McKay | 7a3b88c | 2015-09-23 17:21:40 -0700 | [diff] [blame] | 175 | return state; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public State[] newArray(int size) { |
| 180 | return new State[size]; |
| 181 | } |
| 182 | }; |
Ben Kwa | 84cebbe | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 183 | } |