blob: 959da9fc299ab41b860cea4a03d12ea93b275063 [file] [log] [blame]
Garfield Tan208945c2016-10-04 14:36:38 -07001/*
2 * Copyright (C) 2016 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.picker;
18
19import static com.android.documentsui.base.State.ACTION_CREATE;
20import static com.android.documentsui.base.State.ACTION_GET_CONTENT;
21import static com.android.documentsui.base.State.ACTION_OPEN;
22import static com.android.documentsui.base.State.ACTION_OPEN_TREE;
23import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION;
24
25import android.provider.DocumentsContract.Document;
26
Garfield Tan208945c2016-10-04 14:36:38 -070027import com.android.documentsui.ActivityConfig;
Steve McKayd0718952016-10-10 13:43:36 -070028import com.android.documentsui.base.MimeTypes;
29import com.android.documentsui.base.State;
Garfield Tan208945c2016-10-04 14:36:38 -070030
31/**
32 * Provides support for Platform specific specializations of DirectoryFragment.
33 */
34final class Config extends ActivityConfig {
35
36 @Override
37 public boolean canSelectType(String docMimeType, int docFlags, State state) {
38 if (!isDocumentEnabled(docMimeType, docFlags, state)) {
39 return false;
40 }
41
Steve McKayd0718952016-10-10 13:43:36 -070042 if (MimeTypes.isDirectoryType(docMimeType)) {
Garfield Tan208945c2016-10-04 14:36:38 -070043 return false;
44 }
45
46 if (state.action == ACTION_OPEN_TREE || state.action == ACTION_PICK_COPY_DESTINATION) {
47 // In this case nothing *ever* is selectable...the expected user behavior is
48 // they navigate *into* a folder, then click a confirmation button indicating
49 // that the current directory is the directory they are picking.
50 return false;
51 }
52
53 return true;
54 }
55
56 @Override
57 public boolean isDocumentEnabled(String mimeType, int docFlags, State state) {
58 // Directories are always enabled.
Steve McKayd0718952016-10-10 13:43:36 -070059 if (MimeTypes.isDirectoryType(mimeType)) {
Garfield Tan208945c2016-10-04 14:36:38 -070060 return true;
61 }
62
63 switch (state.action) {
64 case ACTION_CREATE:
65 // Read-only files are disabled when creating.
66 if ((docFlags & Document.FLAG_SUPPORTS_WRITE) == 0) {
67 return false;
68 }
69 case ACTION_OPEN:
70 case ACTION_GET_CONTENT:
71 final boolean isVirtual = (docFlags & Document.FLAG_VIRTUAL_DOCUMENT) != 0;
72 if (isVirtual && state.openableOnly) {
73 return false;
74 }
75 }
76
Steve McKayd0718952016-10-10 13:43:36 -070077 return MimeTypes.mimeMatches(state.acceptMimes, mimeType);
Garfield Tan208945c2016-10-04 14:36:38 -070078 }
79}