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