Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Daichi Hirono | cf0e9ac | 2015-04-17 16:19:15 +0900 | [diff] [blame] | 19 | import java.util.ArrayList; |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 20 | import java.util.HashMap; |
| 21 | import java.util.List; |
| 22 | |
| 23 | import android.app.Activity; |
| 24 | import android.app.Fragment; |
| 25 | import android.content.pm.ResolveInfo; |
| 26 | import android.os.Parcel; |
| 27 | import android.os.Parcelable; |
| 28 | import android.util.SparseArray; |
| 29 | |
| 30 | import com.android.documentsui.model.DocumentInfo; |
| 31 | import com.android.documentsui.model.DocumentStack; |
| 32 | import com.android.documentsui.model.DurableUtils; |
| 33 | import com.android.documentsui.model.RootInfo; |
| 34 | import com.google.common.collect.Maps; |
| 35 | |
| 36 | abstract class BaseActivity extends Activity { |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 37 | public abstract State getDisplayState(); |
| 38 | public abstract RootInfo getCurrentRoot(); |
| 39 | public abstract void onStateChanged(); |
| 40 | public abstract void setRootsDrawerOpen(boolean open); |
| 41 | public abstract void onDocumentPicked(DocumentInfo doc); |
| 42 | public abstract void onDocumentsPicked(List<DocumentInfo> docs); |
| 43 | public abstract DocumentInfo getCurrentDirectory(); |
| 44 | public abstract void setPending(boolean pending); |
| 45 | public abstract void onStackPicked(DocumentStack stack); |
| 46 | public abstract void onPickRequested(DocumentInfo pickTarget); |
| 47 | public abstract void onAppPicked(ResolveInfo info); |
| 48 | public abstract void onRootPicked(RootInfo root, boolean closeDrawer); |
| 49 | public abstract void onSaveRequested(DocumentInfo replaceTarget); |
| 50 | public abstract void onSaveRequested(String mimeType, String displayName); |
| 51 | |
| 52 | public static BaseActivity get(Fragment fragment) { |
| 53 | return (BaseActivity) fragment.getActivity(); |
| 54 | } |
| 55 | |
Daichi Hirono | 1a2fdb4 | 2015-04-15 13:41:18 +0900 | [diff] [blame] | 56 | public static abstract class DocumentsIntent { |
| 57 | /** Intent action name to open copy destination. */ |
| 58 | public static String ACTION_OPEN_COPY_DESTINATION = |
| 59 | "com.android.documentsui.OPEN_COPY_DESTINATION"; |
| 60 | |
| 61 | /** |
| 62 | * Extra boolean flag for ACTION_OPEN_COPY_DESTINATION_STRING, which |
| 63 | * specifies if the destination directory needs to create new directory or not. |
| 64 | */ |
| 65 | public static String EXTRA_DIRECTORY_COPY = "com.android.documentsui.DIRECTORY_COPY"; |
| 66 | } |
| 67 | |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 68 | public static class State implements android.os.Parcelable { |
| 69 | public int action; |
| 70 | public String[] acceptMimes; |
| 71 | |
| 72 | /** Explicit user choice */ |
| 73 | public int userMode = MODE_UNKNOWN; |
| 74 | /** Derived after loader */ |
| 75 | public int derivedMode = MODE_LIST; |
| 76 | |
| 77 | /** Explicit user choice */ |
| 78 | public int userSortOrder = SORT_ORDER_UNKNOWN; |
| 79 | /** Derived after loader */ |
| 80 | public int derivedSortOrder = SORT_ORDER_DISPLAY_NAME; |
| 81 | |
| 82 | public boolean allowMultiple = false; |
| 83 | public boolean showSize = false; |
| 84 | public boolean localOnly = false; |
| 85 | public boolean forceAdvanced = false; |
| 86 | public boolean showAdvanced = false; |
| 87 | public boolean stackTouched = false; |
| 88 | public boolean restored = false; |
Daichi Hirono | 9be3429 | 2015-04-14 17:12:54 +0900 | [diff] [blame] | 89 | public boolean directoryCopy = false; |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 90 | |
| 91 | /** Current user navigation stack; empty implies recents. */ |
| 92 | public DocumentStack stack = new DocumentStack(); |
| 93 | /** Currently active search, overriding any stack. */ |
| 94 | public String currentSearch; |
| 95 | |
| 96 | /** Instance state for every shown directory */ |
| 97 | public HashMap<String, SparseArray<Parcelable>> dirState = Maps.newHashMap(); |
| 98 | |
Daichi Hirono | cf0e9ac | 2015-04-17 16:19:15 +0900 | [diff] [blame] | 99 | /** Currently copying file */ |
| 100 | public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>(); |
| 101 | |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 102 | public static final int ACTION_OPEN = 1; |
| 103 | public static final int ACTION_CREATE = 2; |
| 104 | public static final int ACTION_GET_CONTENT = 3; |
| 105 | public static final int ACTION_OPEN_TREE = 4; |
| 106 | public static final int ACTION_MANAGE = 5; |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 107 | public static final int ACTION_BROWSE = 6; |
| 108 | public static final int ACTION_BROWSE_ALL = 7; |
Daichi Hirono | bbe2292 | 2015-04-10 15:50:38 +0900 | [diff] [blame] | 109 | public static final int ACTION_OPEN_COPY_DESTINATION = 8; |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 110 | |
| 111 | public static final int MODE_UNKNOWN = 0; |
| 112 | public static final int MODE_LIST = 1; |
| 113 | public static final int MODE_GRID = 2; |
| 114 | |
| 115 | public static final int SORT_ORDER_UNKNOWN = 0; |
| 116 | public static final int SORT_ORDER_DISPLAY_NAME = 1; |
| 117 | public static final int SORT_ORDER_LAST_MODIFIED = 2; |
| 118 | public static final int SORT_ORDER_SIZE = 3; |
| 119 | |
| 120 | @Override |
| 121 | public int describeContents() { |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void writeToParcel(Parcel out, int flags) { |
| 127 | out.writeInt(action); |
| 128 | out.writeInt(userMode); |
| 129 | out.writeStringArray(acceptMimes); |
| 130 | out.writeInt(userSortOrder); |
| 131 | out.writeInt(allowMultiple ? 1 : 0); |
| 132 | out.writeInt(showSize ? 1 : 0); |
| 133 | out.writeInt(localOnly ? 1 : 0); |
| 134 | out.writeInt(forceAdvanced ? 1 : 0); |
| 135 | out.writeInt(showAdvanced ? 1 : 0); |
| 136 | out.writeInt(stackTouched ? 1 : 0); |
| 137 | out.writeInt(restored ? 1 : 0); |
| 138 | DurableUtils.writeToParcel(out, stack); |
| 139 | out.writeString(currentSearch); |
| 140 | out.writeMap(dirState); |
Daichi Hirono | cf0e9ac | 2015-04-17 16:19:15 +0900 | [diff] [blame] | 141 | out.writeList(selectedDocumentsForCopy); |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | public static final Creator<State> CREATOR = new Creator<State>() { |
| 145 | @Override |
| 146 | public State createFromParcel(Parcel in) { |
| 147 | final State state = new State(); |
| 148 | state.action = in.readInt(); |
| 149 | state.userMode = in.readInt(); |
| 150 | state.acceptMimes = in.readStringArray(); |
| 151 | state.userSortOrder = in.readInt(); |
| 152 | state.allowMultiple = in.readInt() != 0; |
| 153 | state.showSize = in.readInt() != 0; |
| 154 | state.localOnly = in.readInt() != 0; |
| 155 | state.forceAdvanced = in.readInt() != 0; |
| 156 | state.showAdvanced = in.readInt() != 0; |
| 157 | state.stackTouched = in.readInt() != 0; |
| 158 | state.restored = in.readInt() != 0; |
| 159 | DurableUtils.readFromParcel(in, state.stack); |
| 160 | state.currentSearch = in.readString(); |
| 161 | in.readMap(state.dirState, null); |
Daichi Hirono | cf0e9ac | 2015-04-17 16:19:15 +0900 | [diff] [blame] | 162 | in.readList(state.selectedDocumentsForCopy, null); |
Steve McKay | e934ce6 | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 163 | return state; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public State[] newArray(int size) { |
| 168 | return new State[size]; |
| 169 | } |
| 170 | }; |
| 171 | } |
| 172 | } |