Skip to content

Commit

Permalink
Implemented File Piker Source
Browse files Browse the repository at this point in the history
  • Loading branch information
HariharanEswaran authored and Hariharan committed Nov 15, 2021
1 parent 5afc178 commit 397ebf1
Show file tree
Hide file tree
Showing 88 changed files with 3,585 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.braver.tool.filepicker"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
//implementation 'androidx.core:core:1.7.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
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')
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.braver.tool.filepicker;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.braver.tool.filepicker", appContext.getPackageName());
}
}
48 changes: 48 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.braver.tool.filepicker">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_app_logo"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_app_logo"
android:supportsRtl="true"
android:theme="@style/Theme.FilePicker">
<activity
android:name=".LaunchActivity"
android:exported="true"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PickerActivity"
android:exported="true" />
<activity android:name="com.braver.tool.picker.CameraActivity" />
<activity android:name=".PreviewActivity" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"
tools:replace="android:resource" />
</provider>
</application>
</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/com/braver/tool/filepicker/AppUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +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()); } }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.braver.tool.filepicker;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;

import static com.braver.tool.filepicker.PermissionUtils.IS_PERMISSION_DIALOG_ANDROID_11;

public class CustomPreferencesManager {
private static final String NOTIFICATION_PREFERENCES_NAME = "braver_preferences";
public final SharedPreferences notificationPrefManager;

/**
* Method used to initiate Notification User Defaults
*
* @param context - Current Activity
*/
public CustomPreferencesManager(Context context) {
Context storageContext;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
final Context deviceContext = context.createDeviceProtectedStorageContext();
if (!deviceContext.moveSharedPreferencesFrom(context, NOTIFICATION_PREFERENCES_NAME)) {
AppUtils.printLogConsole("CustomPreferencesManager", "Failed to migrate shared preferences.");
}
storageContext = deviceContext;
} else {
storageContext = context;
}
notificationPrefManager = storageContext.getSharedPreferences(NOTIFICATION_PREFERENCES_NAME, Context.MODE_PRIVATE);
}

/**
* Method used to get UserDefault
*/
public String getPermissionDialogData() {
String data = "";
if (notificationPrefManager != null) {
data = notificationPrefManager.getString(IS_PERMISSION_DIALOG_ANDROID_11, "");
}
return data;
}

/**
* Method used to set UserDefault
*
* @param permissionType - String data
*/
public void setPermissionDialogData(String permissionType) {
if (notificationPrefManager != null) {
SharedPreferences.Editor editor = notificationPrefManager.edit();
editor.putString(IS_PERMISSION_DIALOG_ANDROID_11, permissionType);
editor.apply();
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/braver/tool/filepicker/LaunchActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.braver.tool.filepicker;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.appcompat.app.AppCompatActivity;

public class LaunchActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
new Handler().postDelayed(() -> {
startActivity(new Intent(LaunchActivity.this, PickerActivity.class));
finish();
}, 800);
}
}
Loading

0 comments on commit 397ebf1

Please sign in to comment.