Skip to content

Commit 397ebf1

Browse files
HariharanEswaranHariharan
authored andcommitted
Implemented File Piker Source
1 parent 5afc178 commit 397ebf1

File tree

88 files changed

+3585
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3585
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apply plugin: 'com.android.application'
2+
android {
3+
compileSdkVersion 30
4+
defaultConfig {
5+
applicationId "com.braver.tool.filepicker"
6+
minSdkVersion 23
7+
targetSdkVersion 30
8+
versionCode 1
9+
versionName "1.0"
10+
11+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12+
}
13+
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_1_8
22+
targetCompatibility JavaVersion.VERSION_1_8
23+
}
24+
}
25+
26+
dependencies {
27+
implementation 'androidx.appcompat:appcompat:1.3.1'
28+
implementation 'com.google.android.material:material:1.4.0'
29+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
30+
//implementation 'androidx.core:core:1.7.0'
31+
testImplementation 'junit:junit:4.+'
32+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
33+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
34+
implementation 'com.intuit.sdp:sdp-android:1.0.6'
35+
implementation 'com.google.android.exoplayer:exoplayer:2.15.0'
36+
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
37+
implementation project(':picker')
38+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.braver.tool.filepicker;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.braver.tool.filepicker", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.braver.tool.filepicker">
5+
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.CAMERA" />
8+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
9+
<uses-permission
10+
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
11+
tools:ignore="ScopedStorage" />
12+
13+
<application
14+
android:allowBackup="true"
15+
android:icon="@mipmap/ic_app_logo"
16+
android:label="@string/app_name"
17+
android:requestLegacyExternalStorage="true"
18+
android:roundIcon="@mipmap/ic_app_logo"
19+
android:supportsRtl="true"
20+
android:theme="@style/Theme.FilePicker">
21+
<activity
22+
android:name=".LaunchActivity"
23+
android:exported="true"
24+
android:theme="@style/SplashTheme">
25+
<intent-filter>
26+
<action android:name="android.intent.action.MAIN" />
27+
28+
<category android:name="android.intent.category.LAUNCHER" />
29+
</intent-filter>
30+
</activity>
31+
<activity
32+
android:name=".PickerActivity"
33+
android:exported="true" />
34+
<activity android:name="com.braver.tool.picker.CameraActivity" />
35+
<activity android:name=".PreviewActivity" />
36+
37+
<provider
38+
android:name="androidx.core.content.FileProvider"
39+
android:authorities="${applicationId}.provider"
40+
android:exported="false"
41+
android:grantUriPermissions="true">
42+
<meta-data
43+
android:name="android.support.FILE_PROVIDER_PATHS"
44+
android:resource="@xml/provider_paths"
45+
tools:replace="android:resource" />
46+
</provider>
47+
</application>
48+
</manifest>

app/src/main/java/com/braver/tool/filepicker/AppUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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()); } }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.braver.tool.filepicker;
2+
3+
4+
import android.content.Context;
5+
import android.content.SharedPreferences;
6+
import android.os.Build;
7+
8+
import static com.braver.tool.filepicker.PermissionUtils.IS_PERMISSION_DIALOG_ANDROID_11;
9+
10+
public class CustomPreferencesManager {
11+
private static final String NOTIFICATION_PREFERENCES_NAME = "braver_preferences";
12+
public final SharedPreferences notificationPrefManager;
13+
14+
/**
15+
* Method used to initiate Notification User Defaults
16+
*
17+
* @param context - Current Activity
18+
*/
19+
public CustomPreferencesManager(Context context) {
20+
Context storageContext;
21+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
22+
final Context deviceContext = context.createDeviceProtectedStorageContext();
23+
if (!deviceContext.moveSharedPreferencesFrom(context, NOTIFICATION_PREFERENCES_NAME)) {
24+
AppUtils.printLogConsole("CustomPreferencesManager", "Failed to migrate shared preferences.");
25+
}
26+
storageContext = deviceContext;
27+
} else {
28+
storageContext = context;
29+
}
30+
notificationPrefManager = storageContext.getSharedPreferences(NOTIFICATION_PREFERENCES_NAME, Context.MODE_PRIVATE);
31+
}
32+
33+
/**
34+
* Method used to get UserDefault
35+
*/
36+
public String getPermissionDialogData() {
37+
String data = "";
38+
if (notificationPrefManager != null) {
39+
data = notificationPrefManager.getString(IS_PERMISSION_DIALOG_ANDROID_11, "");
40+
}
41+
return data;
42+
}
43+
44+
/**
45+
* Method used to set UserDefault
46+
*
47+
* @param permissionType - String data
48+
*/
49+
public void setPermissionDialogData(String permissionType) {
50+
if (notificationPrefManager != null) {
51+
SharedPreferences.Editor editor = notificationPrefManager.edit();
52+
editor.putString(IS_PERMISSION_DIALOG_ANDROID_11, permissionType);
53+
editor.apply();
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)