Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui.picker; |
| 18 | |
| 19 | import static com.android.documentsui.base.State.ACTION_CREATE; |
| 20 | import static com.android.documentsui.base.State.ACTION_GET_CONTENT; |
| 21 | import static com.android.documentsui.base.State.ACTION_OPEN; |
| 22 | import static com.android.documentsui.base.State.ACTION_OPEN_TREE; |
| 23 | import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION; |
| 24 | |
| 25 | import android.provider.DocumentsContract.Document; |
| 26 | |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 27 | import com.android.documentsui.ActivityConfig; |
Steve McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 28 | import com.android.documentsui.base.MimeTypes; |
| 29 | import com.android.documentsui.base.State; |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Provides support for Platform specific specializations of DirectoryFragment. |
| 33 | */ |
| 34 | final 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 McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 42 | if (MimeTypes.isDirectoryType(docMimeType)) { |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 43 | 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 McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 59 | if (MimeTypes.isDirectoryType(mimeType)) { |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 60 | 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 McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 77 | return MimeTypes.mimeMatches(state.acceptMimes, mimeType); |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 78 | } |
| 79 | } |