State.java revision 9f9d5b432d6b87fe28a9f90f540b229d0f363538
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; 27 28import java.util.ArrayList; 29import java.util.HashMap; 30import java.util.List; 31 32public class State implements android.os.Parcelable { 33 public int action; 34 public String[] acceptMimes; 35 36 /** Explicit user choice */ 37 public int userMode = MODE_UNKNOWN; 38 /** Derived after loader */ 39 public int derivedMode = MODE_LIST; 40 41 /** Explicit user choice */ 42 public int userSortOrder = SORT_ORDER_UNKNOWN; 43 /** Derived after loader */ 44 public int derivedSortOrder = SORT_ORDER_DISPLAY_NAME; 45 46 public boolean allowMultiple; 47 public boolean forceSize; 48 public boolean showSize; 49 public boolean localOnly; 50 public boolean forceAdvanced; 51 public boolean showAdvanced; 52 public boolean stackTouched; 53 public boolean restored; 54 public boolean directoryCopy; 55 /** Transfer mode for file copy/move operations. */ 56 public int transferMode; 57 58 /** Current user navigation stack; empty implies recents. */ 59 public DocumentStack stack = new DocumentStack(); 60 /** Currently active search, overriding any stack. */ 61 public String currentSearch; 62 63 /** Instance state for every shown directory */ 64 public HashMap<String, SparseArray<Parcelable>> dirState = new HashMap<>(); 65 66 /** Currently copying file */ 67 public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>(); 68 69 /** Name of the package that started DocsUI */ 70 public List<String> excludedAuthorities = new ArrayList<>(); 71 72 public static final int ACTION_OPEN = 1; 73 public static final int ACTION_CREATE = 2; 74 public static final int ACTION_GET_CONTENT = 3; 75 public static final int ACTION_OPEN_TREE = 4; 76 public static final int ACTION_MANAGE = 5; 77 public static final int ACTION_BROWSE = 6; 78 public static final int ACTION_OPEN_COPY_DESTINATION = 8; 79 80 public static final int MODE_UNKNOWN = 0; 81 public static final int MODE_LIST = 1; 82 public static final int MODE_GRID = 2; 83 84 public static final int SORT_ORDER_UNKNOWN = 0; 85 public static final int SORT_ORDER_DISPLAY_NAME = 1; 86 public static final int SORT_ORDER_LAST_MODIFIED = 2; 87 public static final int SORT_ORDER_SIZE = 3; 88 89 public void initAcceptMimes(Intent intent) { 90 if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) { 91 acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES); 92 } else { 93 String glob = intent.getType(); 94 acceptMimes = new String[] { glob != null ? glob : "*/*" }; 95 } 96 } 97 98 @Override 99 public int describeContents() { 100 return 0; 101 } 102 103 @Override 104 public void writeToParcel(Parcel out, int flags) { 105 out.writeInt(action); 106 out.writeInt(userMode); 107 out.writeStringArray(acceptMimes); 108 out.writeInt(userSortOrder); 109 out.writeInt(allowMultiple ? 1 : 0); 110 out.writeInt(forceSize ? 1 : 0); 111 out.writeInt(showSize ? 1 : 0); 112 out.writeInt(localOnly ? 1 : 0); 113 out.writeInt(forceAdvanced ? 1 : 0); 114 out.writeInt(showAdvanced ? 1 : 0); 115 out.writeInt(stackTouched ? 1 : 0); 116 out.writeInt(restored ? 1 : 0); 117 DurableUtils.writeToParcel(out, stack); 118 out.writeString(currentSearch); 119 out.writeMap(dirState); 120 out.writeList(selectedDocumentsForCopy); 121 out.writeList(excludedAuthorities); 122 } 123 124 public static final Creator<State> CREATOR = new Creator<State>() { 125 @Override 126 public State createFromParcel(Parcel in) { 127 final State state = new State(); 128 state.action = in.readInt(); 129 state.userMode = in.readInt(); 130 state.acceptMimes = in.readStringArray(); 131 state.userSortOrder = in.readInt(); 132 state.allowMultiple = in.readInt() != 0; 133 state.forceSize = in.readInt() != 0; 134 state.showSize = in.readInt() != 0; 135 state.localOnly = in.readInt() != 0; 136 state.forceAdvanced = in.readInt() != 0; 137 state.showAdvanced = in.readInt() != 0; 138 state.stackTouched = in.readInt() != 0; 139 state.restored = in.readInt() != 0; 140 DurableUtils.readFromParcel(in, state.stack); 141 state.currentSearch = in.readString(); 142 in.readMap(state.dirState, null); 143 in.readList(state.selectedDocumentsForCopy, null); 144 in.readList(state.excludedAuthorities, null); 145 return state; 146 } 147 148 @Override 149 public State[] newArray(int size) { 150 return new State[size]; 151 } 152 }; 153}