From fdaf2a8538e382f0e03982b13d468081c2d6ea89 Mon Sep 17 00:00:00 2001 From: Hariharan Date: Mon, 15 Nov 2021 17:58:52 +0530 Subject: [PATCH] Added CopyRights and Update ReadME File --- .gitignore | 1 + README.md | 64 ++++++++++++++++++- app/build.gradle | 11 +++- .../filepicker/ExampleInstrumentedTest.java | 8 +++ app/src/main/AndroidManifest.xml | 8 +++ .../com/braver/tool/filepicker/AppUtils.java | 2 +- .../filepicker/CustomPreferencesManager.java | 8 +++ .../tool/filepicker/LaunchActivity.java | 8 +++ .../tool/filepicker/PermissionUtils.java | 2 +- .../tool/filepicker/PickerActivity.java | 8 +++ .../tool/filepicker/PreviewActivity.java | 8 +++ app/src/main/res/drawable/alert_btn_bg.xml | 8 +++ app/src/main/res/drawable/ic_close.xml | 8 +++ app/src/main/res/drawable/ic_file.xml | 8 +++ .../main/res/drawable/ic_permission_audio.xml | 8 +++ .../res/drawable/ic_permission_camera.xml | 8 +++ .../res/drawable/ic_permission_storage.xml | 8 +++ .../main/res/drawable/ic_video_play_lib.xml | 8 +++ app/src/main/res/drawable/preview_btn_bg.xml | 8 +++ .../main/res/drawable/shape_circle_lib.xml | 8 +++ app/src/main/res/drawable/splash_bg_grad.xml | 8 +++ app/src/main/res/layout/activity_launch.xml | 8 +++ app/src/main/res/layout/activity_main.xml | 8 +++ app/src/main/res/layout/activity_preview.xml | 8 +++ .../res/layout/permission_alert_popup.xml | 8 +++ .../res/mipmap-anydpi-v26/ic_app_logo.xml | 8 +++ app/src/main/res/values/attrs.xml | 8 +++ app/src/main/res/values/colors.xml | 8 +++ app/src/main/res/values/strings.xml | 8 +++ app/src/main/res/xml/provider_paths.xml | 8 +++ .../tool/filepicker/ExampleUnitTest.java | 8 +++ build.gradle | 8 +++ gradle.properties | 8 +++ gradle/wrapper/gradle-wrapper.properties | 8 +++ picker/build.gradle | 8 +++ .../tool/picker/ExampleInstrumentedTest.java | 8 +++ picker/src/main/AndroidManifest.xml | 8 +++ .../braver/tool/picker/BraveFileGetter.java | 8 +++ .../com/braver/tool/picker/BraveFilePath.java | 8 +++ .../braver/tool/picker/BraveFilePicker.java | 8 +++ .../com/braver/tool/picker/BraveFileType.java | 8 +++ .../braver/tool/picker/BraveFileUtils.java | 8 +++ .../braver/tool/picker/CameraActivity.java | 8 +++ .../braver/tool/picker/image/ImageUtil.java | 8 +++ .../src/main/res/drawable/bg_record_video.xml | 8 +++ .../main/res/drawable/ic_automatic_flash.xml | 8 +++ .../res/drawable/ic_capture_image_icon.xml | 8 +++ picker/src/main/res/drawable/ic_flash_off.xml | 8 +++ picker/src/main/res/drawable/ic_flash_on.xml | 8 +++ .../res/drawable/ic_rotate_arrow_icon.xml | 8 +++ .../res/drawable/ic_solid_dot_circle_red.xml | 8 +++ .../drawable/ic_solid_dot_circle_white.xml | 8 +++ .../src/main/res/layout/camera_activity.xml | 8 +++ picker/src/main/res/values/color.xml | 8 +++ .../braver/tool/picker/ExampleUnitTest.java | 8 +++ settings.gradle | 8 +++ 56 files changed, 484 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index aa724b7..565a541 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.iml .gradle +.idea /local.properties /.idea/caches /.idea/libraries diff --git a/README.md b/README.md index 674b204..2ed49ff 100644 --- a/README.md +++ b/README.md @@ -1 +1,63 @@ -# Android11FilePicker \ No newline at end of file +# Android FilePicker + +# Description + +This app can make the file picking process easy, which allows you to select Pictures, Videos, and Documents. Also, that has Capturing Photo/Video option. +For using this library, you need to migrate your project to AndroidX(If your project is not migrated to AndroidX). + + + + + +# Getting Started + +To add this library to your project, please follow below steps + +Add this in your root `build.gradle` file (project level gradle file): + +```gradle +allprojects { + repositories { + maven { url "https://www.jitpack.io" } + } +} + +buildscript { + repositories { + maven { url "https://www.jitpack.io" } + } +} +``` + +Then, Add this in your root `build.gradle` file (app level gradle file): + + add implementation 'implementation 'com.github.braver-tool:Android11FilePicker:0.1.1' to your build.gradle dependencies block. + + for example: + + ``` + dependencies { + implementation 'com.github.braver-tool:Android11FilePicker:0.1.1' + } + ``` + +# Key Features : + +- Fully Handled Android's Dangerous Permissions +- Compressing option for selected images included, +- To Preview your selected images using 'PhotoView' +- To Preview your selected videos using exoplayer + +This library compatible with Android 6 and above + + +## Version Compatibility +It depends on your targetAPI: +- `targetAPI <= 28`, you are fine ;) +- `targetAPI >= 29`, please enable `requestLegacyExternalStorage` on your Manifest.xml file + +## Permissions Needed : + +* android.permission.READ_EXTERNAL_STORAGE +* android.permission.CAMERA +* android.permission.RECORD_AUDIO \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 9325c36..e38b1e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + apply plugin: 'com.android.application' android { compileSdkVersion 30 @@ -34,5 +42,6 @@ dependencies { implementation 'com.intuit.sdp:sdp-android:1.0.6' implementation 'com.google.android.exoplayer:exoplayer:2.15.0' implementation 'com.github.chrisbanes:PhotoView:2.3.0' - implementation project(':picker') + //implementation project(':picker') + implementation 'com.github.braver-tool:Android11FilePicker:0.1.0' } \ No newline at end of file diff --git a/app/src/androidTest/java/com/braver/tool/filepicker/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/braver/tool/filepicker/ExampleInstrumentedTest.java index ca8779b..fa62cf5 100644 --- a/app/src/androidTest/java/com/braver/tool/filepicker/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/braver/tool/filepicker/ExampleInstrumentedTest.java @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + package com.braver.tool.filepicker; import android.content.Context; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 01e4952..ec3169b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,4 +1,12 @@ + + diff --git a/app/src/main/java/com/braver/tool/filepicker/AppUtils.java b/app/src/main/java/com/braver/tool/filepicker/AppUtils.java index ff294ef..4442200 100644 --- a/app/src/main/java/com/braver/tool/filepicker/AppUtils.java +++ b/app/src/main/java/com/braver/tool/filepicker/AppUtils.java @@ -1 +1 @@ -package com.braver.tool.filepicker; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.util.Log; import androidx.core.content.FileProvider; import java.io.File; import java.util.Random; public class AppUtils { private static final boolean IS_DEBUG = false; public static final String DOC_ALERT_MSG = "You have to allow permission to access this feature"; public static final String START_POINT = "Source file path is \n ***/***/"; public static String getRandomImageFileName(Context context) { File mediaStorageDir = context.getFilesDir(); int random = new Random().nextInt(8997); String mImageName = "Braver_Img".concat("_") + random + ".jpg"; return new File(mediaStorageDir.getPath() + "/" + mImageName).getAbsolutePath(); } /** * @param tag - Contains class name * @param msg - Log message as String * Method used to print log in console for development */ public static void printLogConsole(String tag, String msg) { if (IS_DEBUG) { Log.d("##@" + tag, msg); } } /** * This method is a string return method * Method used get file name from local file path */ public static String getFileNameFromPath(String filePath) { String fileName = ""; try { fileName = filePath.substring(filePath.lastIndexOf('/') + 1); } catch (Exception e) { AppUtils.printLogConsole("getFileNameFromPath", "Exception-------->" + e.getMessage()); } return fileName; } public static void openDocument(Context context, String filePath) { try { Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", new File(filePath)); Intent intent = new Intent(Intent.ACTION_VIEW); if (filePath.contains(".doc") || filePath.contains(".docx")) { intent.setDataAndType(uri, "application/msword"); } else if (filePath.contains(".pdf")) { intent.setDataAndType(uri, "application/pdf"); } else if (filePath.contains(".ppt") || filePath.contains(".pptx")) { intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (filePath.contains(".xls") || filePath.contains(".xlsx")) { intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (filePath.contains(".zip") || filePath.contains(".rar")) { intent.setDataAndType(uri, "application/x-wav"); } else if (filePath.contains(".rtf")) { intent.setDataAndType(uri, "application/rtf"); } else if (filePath.contains(".wav") || filePath.contains(".mp3")) { intent.setDataAndType(uri, "audio/x-wav"); } else if (filePath.contains(".gif")) { intent.setDataAndType(uri, "image/gif"); } else if (filePath.contains(".jpg") || filePath.contains(".jpeg") || filePath.contains(".png")) { intent.setDataAndType(uri, "image/jpeg"); } else if (filePath.contains(".txt")) { intent.setDataAndType(uri, "text/plain"); } else if (filePath.contains(".3gp") || filePath.contains(".mpg") || filePath.contains(".mpeg") || filePath.contains(".mpe") || filePath.contains(".mp4") || filePath.contains(".avi")) { intent.setDataAndType(uri, "video/*"); } else { intent.setDataAndType(uri, "*/*"); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (Exception e) { AppUtils.printLogConsole("openDocument", "Exception-------->" + e.getMessage()); } } } \ No newline at end of file +/* * * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM * * Copyright (c) 2021 . All rights reserved. * * Last modified 15/11/21, 05:50 PM * */ package com.braver.tool.filepicker; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.util.Log; import androidx.core.content.FileProvider; import java.io.File; import java.util.Random; public class AppUtils { private static final boolean IS_DEBUG = false; public static final String DOC_ALERT_MSG = "You have to allow permission to access this feature"; public static final String START_POINT = "Source file path is \n ***/***/"; public static String getRandomImageFileName(Context context) { File mediaStorageDir = context.getFilesDir(); int random = new Random().nextInt(8997); String mImageName = "Braver_Img".concat("_") + random + ".jpg"; return new File(mediaStorageDir.getPath() + "/" + mImageName).getAbsolutePath(); } /** * @param tag - Contains class name * @param msg - Log message as String * Method used to print log in console for development */ public static void printLogConsole(String tag, String msg) { if (IS_DEBUG) { Log.d("##@" + tag, msg); } } /** * This method is a string return method * Method used get file name from local file path */ public static String getFileNameFromPath(String filePath) { String fileName = ""; try { fileName = filePath.substring(filePath.lastIndexOf('/') + 1); } catch (Exception e) { AppUtils.printLogConsole("getFileNameFromPath", "Exception-------->" + e.getMessage()); } return fileName; } public static void openDocument(Context context, String filePath) { try { Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", new File(filePath)); Intent intent = new Intent(Intent.ACTION_VIEW); if (filePath.contains(".doc") || filePath.contains(".docx")) { intent.setDataAndType(uri, "application/msword"); } else if (filePath.contains(".pdf")) { intent.setDataAndType(uri, "application/pdf"); } else if (filePath.contains(".ppt") || filePath.contains(".pptx")) { intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (filePath.contains(".xls") || filePath.contains(".xlsx")) { intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (filePath.contains(".zip") || filePath.contains(".rar")) { intent.setDataAndType(uri, "application/x-wav"); } else if (filePath.contains(".rtf")) { intent.setDataAndType(uri, "application/rtf"); } else if (filePath.contains(".wav") || filePath.contains(".mp3")) { intent.setDataAndType(uri, "audio/x-wav"); } else if (filePath.contains(".gif")) { intent.setDataAndType(uri, "image/gif"); } else if (filePath.contains(".jpg") || filePath.contains(".jpeg") || filePath.contains(".png")) { intent.setDataAndType(uri, "image/jpeg"); } else if (filePath.contains(".txt")) { intent.setDataAndType(uri, "text/plain"); } else if (filePath.contains(".3gp") || filePath.contains(".mpg") || filePath.contains(".mpeg") || filePath.contains(".mpe") || filePath.contains(".mp4") || filePath.contains(".avi")) { intent.setDataAndType(uri, "video/*"); } else { intent.setDataAndType(uri, "*/*"); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (Exception e) { AppUtils.printLogConsole("openDocument", "Exception-------->" + e.getMessage()); } } } \ No newline at end of file diff --git a/app/src/main/java/com/braver/tool/filepicker/CustomPreferencesManager.java b/app/src/main/java/com/braver/tool/filepicker/CustomPreferencesManager.java index e3e2e51..53eaa37 100644 --- a/app/src/main/java/com/braver/tool/filepicker/CustomPreferencesManager.java +++ b/app/src/main/java/com/braver/tool/filepicker/CustomPreferencesManager.java @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + package com.braver.tool.filepicker; diff --git a/app/src/main/java/com/braver/tool/filepicker/LaunchActivity.java b/app/src/main/java/com/braver/tool/filepicker/LaunchActivity.java index 3ed3356..2fb45a1 100644 --- a/app/src/main/java/com/braver/tool/filepicker/LaunchActivity.java +++ b/app/src/main/java/com/braver/tool/filepicker/LaunchActivity.java @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + package com.braver.tool.filepicker; import android.content.Intent; diff --git a/app/src/main/java/com/braver/tool/filepicker/PermissionUtils.java b/app/src/main/java/com/braver/tool/filepicker/PermissionUtils.java index fc47916..33b8492 100644 --- a/app/src/main/java/com/braver/tool/filepicker/PermissionUtils.java +++ b/app/src/main/java/com/braver/tool/filepicker/PermissionUtils.java @@ -1 +1 @@ -package com.braver.tool.filepicker; import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.Settings; import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; import androidx.core.app.ActivityCompat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Class for android 6.0 and above live permission handling */ public class PermissionUtils { public static final String PERMISSION_CAMERA = "Camera"; public static final String PERMISSION_GALLERY = "Gallery"; public static final String PERMISSION_MIC = "Audio"; public static final int MANDATORY_GALLERY_PERMISSION_REQ_CODE = 3646; public static final String READ_EXTERNAL_STORAGE_PERMISSION = Manifest.permission.READ_EXTERNAL_STORAGE; public static final String IS_PERMISSION_DIALOG_ANDROID_11 = "is_permission_dialog_android_11"; /** * Method helps to add a permission into permission list */ private static void checkPermissionGrant(Context context, ArrayList permissionList, String permission) { if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { permissionList.add(permission); } } /** * Method handling the permissions to getting camera and storage access * * @param context activity context * @return boolean variable */ public static boolean isFileAccessPermissionGranted(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); checkPermissionGrant(context, locationPermissionList, Manifest.permission.READ_EXTERNAL_STORAGE); //checkPermissionGrant(context, locationPermissionList, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (locationPermissionList.size() > 0) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && locationPermissionList.contains(Manifest.permission.READ_EXTERNAL_STORAGE) && locationPermissionList.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE) && Environment.isExternalStorageManager()) { locationPermissionList.remove(Manifest.permission.READ_EXTERNAL_STORAGE); //locationPermissionList.remove(Manifest.permission.WRITE_EXTERNAL_STORAGE); } } if (locationPermissionList.size() > 0) { status = false; } return status; } /** * Method to display the dialog alert for camera and storage permission * * @param context activity context */ public static void showFileAccessPermissionRequestDialog(Context context) { ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); checkPermissionGrant(context, locationPermissionList, Manifest.permission.READ_EXTERNAL_STORAGE); //checkPermissionGrant(context, locationPermissionList, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (locationPermissionList.size() > 0) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && locationPermissionList.contains(Manifest.permission.READ_EXTERNAL_STORAGE) && locationPermissionList.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE) && Environment.isExternalStorageManager()) { locationPermissionList.remove(Manifest.permission.READ_EXTERNAL_STORAGE); //locationPermissionList.remove(Manifest.permission.WRITE_EXTERNAL_STORAGE); } } if (locationPermissionList.size() > 0) { ActivityCompat.requestPermissions((Activity) context, locationPermissionList.toArray(new String[locationPermissionList.size()]), MANDATORY_GALLERY_PERMISSION_REQ_CODE); } } /** * Method handling the permissions to isCameraAccessed * * @param context activity context * @return boolean variable */ public static boolean isCameraAccessed(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); if (locationPermissionList.size() > 0) { status = false; } return status; } /** * Method handling the permissions to isAudioAccessed * * @param context activity context * @return boolean variable */ public static boolean isAudioAccessed(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); if (locationPermissionList.size() > 0) { status = false; } return status; } /** * @param context - Dialog call from * @param permissionType - Permission for ? */ public static void showAlertForAppInfoScreen(Context context, String permissionType) { if (!isValidPermissionDialog(context, permissionType)) { return; } final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.permission_alert_popup); Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent); Window window = dialog.getWindow(); WindowManager.LayoutParams wlp; if (window != null) { wlp = window.getAttributes(); wlp.gravity = Gravity.CENTER; window.setAttributes(wlp); } ImageView permissionAlertTypeImageView = dialog.findViewById(R.id.permissionAlertTypeImageView); TextView permissionAlertContentTextView = dialog.findViewById(R.id.permissionAlertContentTextView); TextView permissionAlertNotNowTextView = dialog.findViewById(R.id.permissionAlertNotNowTextView); TextView permissionAlertSettingsTextView = dialog.findViewById(R.id.permissionAlertSettingsTextView); permissionAlertContentTextView.setText(getSpecialPermissionContent(context, permissionType)); permissionAlertTypeImageView.setImageResource(getSpecialPermissionVector(permissionType)); permissionAlertNotNowTextView.setOnClickListener(v -> dialog.dismiss()); permissionAlertSettingsTextView.setOnClickListener(v -> { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", context.getPackageName(), null); intent.setData(uri); context.startActivity(intent); dialog.dismiss(); }); dialog.show(); } /** * @param context - context * @param permissionType - String data * @return - boolean data * Method used to return isPermissionDialog is shown for Android 11 */ private static boolean isValidPermissionDialog(Context context, String permissionType) { boolean isValid = false; CustomPreferencesManager customPreferencesManager = new CustomPreferencesManager(context); String callType = customPreferencesManager.getPermissionDialogData(); callType = callType.isEmpty() ? permissionType : callType.concat(",").concat(permissionType); customPreferencesManager.setPermissionDialogData(callType); List permissionTypeList = Arrays.asList(callType.split(",")); int count = Collections.frequency(permissionTypeList, permissionType); if (count > 1) { isValid = true; } return isValid; } /** * @param context - current activity * @param permissionType - String data * @return - */ private static String getSpecialPermissionContent(Context context, String permissionType) { String msg = ""; if (permissionType.equalsIgnoreCase(PERMISSION_CAMERA)) { msg = context.getResources().getString(R.string.camera_video_permission); } else if (permissionType.equalsIgnoreCase(PERMISSION_GALLERY)) { msg = context.getResources().getString(R.string.storage_permission); } else if (permissionType.equalsIgnoreCase(PERMISSION_MIC)) { msg = context.getResources().getString(R.string.call_permission); } return msg; } /** * @param permissionType - String data * @return - */ private static int getSpecialPermissionVector(String permissionType) { int vector; if (permissionType.equalsIgnoreCase(PERMISSION_CAMERA)) { vector = R.drawable.ic_permission_camera; return vector; } else if (permissionType.equalsIgnoreCase(PERMISSION_GALLERY)) { vector = R.drawable.ic_permission_storage; return vector; } return 0; } } \ No newline at end of file +/* * * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM * * Copyright (c) 2021 . All rights reserved. * * Last modified 15/11/21, 05:50 PM * */ package com.braver.tool.filepicker; import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.Settings; import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; import androidx.core.app.ActivityCompat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Class for android 6.0 and above live permission handling */ public class PermissionUtils { public static final String PERMISSION_CAMERA = "Camera"; public static final String PERMISSION_GALLERY = "Gallery"; public static final String PERMISSION_MIC = "Audio"; public static final int MANDATORY_GALLERY_PERMISSION_REQ_CODE = 3646; public static final String READ_EXTERNAL_STORAGE_PERMISSION = Manifest.permission.READ_EXTERNAL_STORAGE; public static final String IS_PERMISSION_DIALOG_ANDROID_11 = "is_permission_dialog_android_11"; /** * Method helps to add a permission into permission list */ private static void checkPermissionGrant(Context context, ArrayList permissionList, String permission) { if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { permissionList.add(permission); } } /** * Method handling the permissions to getting camera and storage access * * @param context activity context * @return boolean variable */ public static boolean isFileAccessPermissionGranted(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); checkPermissionGrant(context, locationPermissionList, Manifest.permission.READ_EXTERNAL_STORAGE); //checkPermissionGrant(context, locationPermissionList, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (locationPermissionList.size() > 0) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && locationPermissionList.contains(Manifest.permission.READ_EXTERNAL_STORAGE) && locationPermissionList.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE) && Environment.isExternalStorageManager()) { locationPermissionList.remove(Manifest.permission.READ_EXTERNAL_STORAGE); //locationPermissionList.remove(Manifest.permission.WRITE_EXTERNAL_STORAGE); } } if (locationPermissionList.size() > 0) { status = false; } return status; } /** * Method to display the dialog alert for camera and storage permission * * @param context activity context */ public static void showFileAccessPermissionRequestDialog(Context context) { ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); checkPermissionGrant(context, locationPermissionList, Manifest.permission.READ_EXTERNAL_STORAGE); //checkPermissionGrant(context, locationPermissionList, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (locationPermissionList.size() > 0) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && locationPermissionList.contains(Manifest.permission.READ_EXTERNAL_STORAGE) && locationPermissionList.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE) && Environment.isExternalStorageManager()) { locationPermissionList.remove(Manifest.permission.READ_EXTERNAL_STORAGE); //locationPermissionList.remove(Manifest.permission.WRITE_EXTERNAL_STORAGE); } } if (locationPermissionList.size() > 0) { ActivityCompat.requestPermissions((Activity) context, locationPermissionList.toArray(new String[locationPermissionList.size()]), MANDATORY_GALLERY_PERMISSION_REQ_CODE); } } /** * Method handling the permissions to isCameraAccessed * * @param context activity context * @return boolean variable */ public static boolean isCameraAccessed(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.CAMERA); if (locationPermissionList.size() > 0) { status = false; } return status; } /** * Method handling the permissions to isAudioAccessed * * @param context activity context * @return boolean variable */ public static boolean isAudioAccessed(Context context) { boolean status = true; ArrayList locationPermissionList = new ArrayList<>(); checkPermissionGrant(context, locationPermissionList, Manifest.permission.RECORD_AUDIO); if (locationPermissionList.size() > 0) { status = false; } return status; } /** * @param context - Dialog call from * @param permissionType - Permission for ? */ public static void showAlertForAppInfoScreen(Context context, String permissionType) { if (!isValidPermissionDialog(context, permissionType)) { return; } final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.permission_alert_popup); Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent); Window window = dialog.getWindow(); WindowManager.LayoutParams wlp; if (window != null) { wlp = window.getAttributes(); wlp.gravity = Gravity.CENTER; window.setAttributes(wlp); } ImageView permissionAlertTypeImageView = dialog.findViewById(R.id.permissionAlertTypeImageView); TextView permissionAlertContentTextView = dialog.findViewById(R.id.permissionAlertContentTextView); TextView permissionAlertNotNowTextView = dialog.findViewById(R.id.permissionAlertNotNowTextView); TextView permissionAlertSettingsTextView = dialog.findViewById(R.id.permissionAlertSettingsTextView); permissionAlertContentTextView.setText(getSpecialPermissionContent(context, permissionType)); permissionAlertTypeImageView.setImageResource(getSpecialPermissionVector(permissionType)); permissionAlertNotNowTextView.setOnClickListener(v -> dialog.dismiss()); permissionAlertSettingsTextView.setOnClickListener(v -> { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", context.getPackageName(), null); intent.setData(uri); context.startActivity(intent); dialog.dismiss(); }); dialog.show(); } /** * @param context - context * @param permissionType - String data * @return - boolean data * Method used to return isPermissionDialog is shown for Android 11 */ private static boolean isValidPermissionDialog(Context context, String permissionType) { boolean isValid = false; CustomPreferencesManager customPreferencesManager = new CustomPreferencesManager(context); String callType = customPreferencesManager.getPermissionDialogData(); callType = callType.isEmpty() ? permissionType : callType.concat(",").concat(permissionType); customPreferencesManager.setPermissionDialogData(callType); List permissionTypeList = Arrays.asList(callType.split(",")); int count = Collections.frequency(permissionTypeList, permissionType); if (count > 1) { isValid = true; } return isValid; } /** * @param context - current activity * @param permissionType - String data * @return - */ private static String getSpecialPermissionContent(Context context, String permissionType) { String msg = ""; if (permissionType.equalsIgnoreCase(PERMISSION_CAMERA)) { msg = context.getResources().getString(R.string.camera_video_permission); } else if (permissionType.equalsIgnoreCase(PERMISSION_GALLERY)) { msg = context.getResources().getString(R.string.storage_permission); } else if (permissionType.equalsIgnoreCase(PERMISSION_MIC)) { msg = context.getResources().getString(R.string.call_permission); } return msg; } /** * @param permissionType - String data * @return - */ private static int getSpecialPermissionVector(String permissionType) { int vector; if (permissionType.equalsIgnoreCase(PERMISSION_CAMERA)) { vector = R.drawable.ic_permission_camera; return vector; } else if (permissionType.equalsIgnoreCase(PERMISSION_GALLERY)) { vector = R.drawable.ic_permission_storage; return vector; } return 0; } } \ No newline at end of file diff --git a/app/src/main/java/com/braver/tool/filepicker/PickerActivity.java b/app/src/main/java/com/braver/tool/filepicker/PickerActivity.java index f250354..0f6e1d0 100644 --- a/app/src/main/java/com/braver/tool/filepicker/PickerActivity.java +++ b/app/src/main/java/com/braver/tool/filepicker/PickerActivity.java @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + package com.braver.tool.filepicker; import android.app.Dialog; diff --git a/app/src/main/java/com/braver/tool/filepicker/PreviewActivity.java b/app/src/main/java/com/braver/tool/filepicker/PreviewActivity.java index 6674f4a..a112bd1 100644 --- a/app/src/main/java/com/braver/tool/filepicker/PreviewActivity.java +++ b/app/src/main/java/com/braver/tool/filepicker/PreviewActivity.java @@ -1,3 +1,11 @@ +/* + * + * * Created by https://github.com/braver-tool on 12/10/21, 08:30 PM + * * Copyright (c) 2021 . All rights reserved. + * * Last modified 15/11/21, 05:50 PM + * + */ + package com.braver.tool.filepicker; import android.graphics.Bitmap; diff --git a/app/src/main/res/drawable/alert_btn_bg.xml b/app/src/main/res/drawable/alert_btn_bg.xml index 6212d91..755184c 100644 --- a/app/src/main/res/drawable/alert_btn_bg.xml +++ b/app/src/main/res/drawable/alert_btn_bg.xml @@ -1,5 +1,13 @@ + + diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml index 2590d02..23994f1 100644 --- a/app/src/main/res/drawable/ic_close.xml +++ b/app/src/main/res/drawable/ic_close.xml @@ -1,3 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_permission_audio.xml b/app/src/main/res/drawable/ic_permission_audio.xml index a49b71b..875c396 100644 --- a/app/src/main/res/drawable/ic_permission_audio.xml +++ b/app/src/main/res/drawable/ic_permission_audio.xml @@ -1,3 +1,11 @@ + + + + + + + diff --git a/app/src/main/res/drawable/shape_circle_lib.xml b/app/src/main/res/drawable/shape_circle_lib.xml index 9fac508..08a406a 100644 --- a/app/src/main/res/drawable/shape_circle_lib.xml +++ b/app/src/main/res/drawable/shape_circle_lib.xml @@ -1,4 +1,12 @@ + + diff --git a/app/src/main/res/drawable/splash_bg_grad.xml b/app/src/main/res/drawable/splash_bg_grad.xml index 2000ccf..b7d5d26 100644 --- a/app/src/main/res/drawable/splash_bg_grad.xml +++ b/app/src/main/res/drawable/splash_bg_grad.xml @@ -1,5 +1,13 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 33d7d02..80ff64a 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -1,5 +1,13 @@ + +