Skip to content

Commit

Permalink
Merge pull request #144 from yogeshchoudhary-gts/hotfix/improvement
Browse files Browse the repository at this point in the history
Use Picker Option added
  • Loading branch information
yogeshpaliyal committed Jul 23, 2021
2 parents 626f770 + aaac371 commit 0a660a3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

dependencies {

classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line
}
}
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Sep 26 15:59:33 AMT 2018
#Thu Jul 22 17:41:01 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
2 changes: 2 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
android:configChanges="orientation"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:screenOrientation="portrait">

<provider
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/com/vansuita/pickimage/bundle/PickSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class PickSetup implements Serializable {

private String galleryChooserTitle = "";
private String cameraChooserTitle = "";
private boolean useChooser = true;

private boolean isCameraToPictures;

Expand Down Expand Up @@ -82,6 +83,15 @@ public PickSetup setCancelText(String text) {
return this;
}

public boolean isUseChooser() {
return useChooser;
}

public PickSetup setUseChooser(boolean useChooser) {
this.useChooser = useChooser;
return this;
}

public String getTitle() {
return title;
}
Expand Down Expand Up @@ -330,6 +340,7 @@ public PickSetup() {
.setProgressText("Loading...")
.setButtonOrientation(LinearLayout.VERTICAL)
.setCameraIcon(R.drawable.camera)
.setUseChooser(false)
.setSystemDialog(false)
.setCameraToPictures(true)
.setGalleryIcon(R.drawable.gallery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import com.vansuita.pickimage.bundle.PickSetup;
import com.vansuita.pickimage.keep.Keep;
Expand Down Expand Up @@ -87,10 +88,10 @@ public PickImageDialog setOnPickCancel(IPickCancel onPickCancel)
return (PickImageDialog) super.setOnPickCancel(onPickCancel);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("onActivityResult","requestCode => "+requestCode +"; Result Code => "+resultCode);
if (requestCode == IntentResolver.REQUESTER) {
if (resultCode == RESULT_OK) {
//Show progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Keep {
private static final String ASKED_FOR_PERMISSION = "ASKED_FOR_PERMISSION";

Keep(Context context) {
this.pref = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
this.pref = context.getSharedPreferences("testing", Context.MODE_PRIVATE);
}

public static Keep with(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;

import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION;

/**
* Created by jrvansuita build 07/02/17.
*/
Expand Down Expand Up @@ -87,6 +90,8 @@ private Intent getCameraIntent() {
} else {
cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}
cameraIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraUriForProvider());

applyProviderPermission();
Expand All @@ -97,9 +102,16 @@ private Intent getCameraIntent() {

public void launchCamera(Fragment listener) {


cameraFile().delete();
saveFile = null;



Intent chooser = Intent.createChooser(getCameraIntent(), setup.getCameraChooserTitle());
Intent chooser = getCameraIntent();
if (setup.isUseChooser()){
chooser = Intent.createChooser(chooser, setup.getCameraChooserTitle());
}
listener.startActivityForResult(chooser, REQUESTER);
}

Expand All @@ -110,7 +122,7 @@ private void applyProviderPermission() {
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
activity.grantUriPermission(packageName, cameraUriForProvider(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.grantUriPermission(packageName, cameraUriForProvider(), FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_READ_URI_PERMISSION);
}
}

Expand Down Expand Up @@ -138,7 +150,9 @@ private File cameraFile() {
}

// File directory = new File(activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES),"teste");
directory.mkdirs();
if (!directory.exists())
directory.mkdirs();

saveFile = new File(directory, fileName);
Log.i("File-PickImage", saveFile.getAbsolutePath());

Expand Down Expand Up @@ -167,7 +181,14 @@ private Uri cameraUriForProvider() {

private Intent getGalleryIntent() {
if (galleryIntent == null) {
galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
galleryIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
galleryIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
galleryIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
}else{
galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
if (setup.isVideo()) {
galleryIntent.setType(activity.getString(R.string.video_content_type));
} else {
Expand All @@ -179,7 +200,10 @@ private Intent getGalleryIntent() {
}

public void launchGallery(Fragment listener,String title) {
Intent intent = Intent.createChooser(getGalleryIntent(),title);
Intent intent = getGalleryIntent();
if (setup.isUseChooser()){
intent = Intent.createChooser(intent, title);
}
try {
listener.startActivityForResult(intent, REQUESTER);
} catch (ActivityNotFoundException e) {
Expand Down

0 comments on commit 0a660a3

Please sign in to comment.