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 androidx.core.view; 18 19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20 21 import android.app.Activity; 22 import android.os.Build; 23 import android.view.DragAndDropPermissions; 24 import android.view.DragEvent; 25 26 import androidx.annotation.Nullable; 27 import androidx.annotation.RestrictTo; 28 29 /** 30 * Helper for accessing features in {@link android.view.DragAndDropPermissions} a backwards 31 * compatible fashion. 32 */ 33 public final class DragAndDropPermissionsCompat { 34 private Object mDragAndDropPermissions; 35 DragAndDropPermissionsCompat(Object dragAndDropPermissions)36 private DragAndDropPermissionsCompat(Object dragAndDropPermissions) { 37 mDragAndDropPermissions = dragAndDropPermissions; 38 } 39 40 /** @hide */ 41 @RestrictTo(LIBRARY_GROUP) 42 @Nullable request(Activity activity, DragEvent dragEvent)43 public static DragAndDropPermissionsCompat request(Activity activity, DragEvent dragEvent) { 44 if (Build.VERSION.SDK_INT >= 24) { 45 DragAndDropPermissions dragAndDropPermissions = 46 activity.requestDragAndDropPermissions(dragEvent); 47 if (dragAndDropPermissions != null) { 48 return new DragAndDropPermissionsCompat(dragAndDropPermissions); 49 } 50 } 51 return null; 52 } 53 54 /** 55 * Revoke the permission grant explicitly. 56 */ release()57 public void release() { 58 if (Build.VERSION.SDK_INT >= 24) { 59 ((DragAndDropPermissions) mDragAndDropPermissions).release(); 60 } 61 } 62 } 63