State.java revision 7f34b20a70603070b7634acc011b4ff45608dcf7
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 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; 27import com.android.documentsui.model.RootInfo; 28 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 */ 40 public int derivedMode = MODE_GRID; 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; 48 public boolean forceSize; 49 public boolean showSize; 50 public boolean localOnly; 51 public boolean forceAdvanced; 52 public boolean showAdvanced; 53 public boolean restored; 54 public boolean directoryCopy; 55 public boolean openableOnly; 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; 79 public static final int ACTION_PICK_COPY_DESTINATION = 8; 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 90 private boolean mStackTouched; 91 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 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.push(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 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); 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); 149 out.writeInt(openableOnly ? 1 : 0); 150 out.writeInt(mStackTouched ? 1 : 0); 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; 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); 173 state.openableOnly = in.readInt() != 0; 174 state.mStackTouched = in.readInt() != 0; 175 return state; 176 } 177 178 @Override 179 public State[] newArray(int size) { 180 return new State[size]; 181 } 182 }; 183} 184