blob: 8039b71f736760cb6652324999b4f977bf93f971 [file] [log] [blame]
Steve McKaye934ce62015-03-25 14:35:33 -07001/*
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
17package com.android.documentsui;
18
Daichi Hironocf0e9ac2015-04-17 16:19:15 +090019import java.util.ArrayList;
Steve McKaye934ce62015-03-25 14:35:33 -070020import java.util.HashMap;
21import java.util.List;
22
23import android.app.Activity;
24import android.app.Fragment;
25import android.content.pm.ResolveInfo;
26import android.os.Parcel;
27import android.os.Parcelable;
28import android.util.SparseArray;
29
30import com.android.documentsui.model.DocumentInfo;
31import com.android.documentsui.model.DocumentStack;
32import com.android.documentsui.model.DurableUtils;
33import com.android.documentsui.model.RootInfo;
34import com.google.common.collect.Maps;
35
36abstract class BaseActivity extends Activity {
Steve McKaye934ce62015-03-25 14:35:33 -070037 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 Hirono1a2fdb42015-04-15 13:41:18 +090056 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 McKaye934ce62015-03-25 14:35:33 -070068 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 Hirono9be34292015-04-14 17:12:54 +090089 public boolean directoryCopy = false;
Steve McKaye934ce62015-03-25 14:35:33 -070090
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 Hironocf0e9ac2015-04-17 16:19:15 +090099 /** Currently copying file */
100 public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>();
101
Steve McKaye934ce62015-03-25 14:35:33 -0700102 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 Sharkey59d577a2015-04-11 21:27:21 -0700107 public static final int ACTION_BROWSE = 6;
108 public static final int ACTION_BROWSE_ALL = 7;
Daichi Hironobbe22922015-04-10 15:50:38 +0900109 public static final int ACTION_OPEN_COPY_DESTINATION = 8;
Steve McKaye934ce62015-03-25 14:35:33 -0700110
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 Hironocf0e9ac2015-04-17 16:19:15 +0900141 out.writeList(selectedDocumentsForCopy);
Steve McKaye934ce62015-03-25 14:35:33 -0700142 }
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 Hironocf0e9ac2015-04-17 16:19:15 +0900162 in.readList(state.selectedDocumentsForCopy, null);
Steve McKaye934ce62015-03-25 14:35:33 -0700163 return state;
164 }
165
166 @Override
167 public State[] newArray(int size) {
168 return new State[size];
169 }
170 };
171 }
172}