• Stars
    star
    469
  • Rank 93,595 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“ธ ๐Ÿ–ผ๏ธ Shows a DialogFragment with camera and gallery options. User can choose which provider wants to pick images from.

Buy Me a Coffee at ko-fi.com Get it on Google Play

PickImage

This is an Android project. It shows a DialogFragment with Camera or Gallery options. The user can choose from which provider wants to pick an image.




JitPack Android Arsenal MaterialUp Hits

Dialog screenshots

Default icons.

Colored icons.

Custom dialog.

System dialog.

Appetize.io Demo Codacy Badge API

Setup

Step #1. Add the JitPack repository to your build.gradle file:

allprojects {
    repositories {
	maven { url "https://jitpack.io" }
    }
}

Step #1.1 Or add the JitPack repository to the settings.gradle file:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
       maven { url 'https://jitpack.io' }
    }
}

Step #2. Add the dependency (See latest release).

dependencies {
    implementation 'com.github.jrvansuita:PickImage:+'
}

Implementation

Step #1. Overriding the library file provider authority to avoid installation conflicts.

The use of this library can cause INSTALL_FAILED_CONFLICTING_PROVIDER if you skip this step. Update your AndroidManifest.xml with this exact provider declaration below.

<manifest ...>
    <application ...>
        <provider
            android:name="com.vansuita.pickimage.provider.PickImageFileProvider"
            android:authorities="${applicationId}.com.vansuita.pickimage.provider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/picker_provider_paths" />
        </provider>
    </application>	
</manifest> 

Step #2 - Showing the dialog.

PickImageDialog.build(new PickSetup()).show(this);

Step #3 - Applying the listeners.

Method #3.1 - Make your AppCompatActivity implements IPickResult.
@Override
public void onPickResult(PickResult r) {
    if (r.getError() == null) {
        //If you want the Uri.
        //Mandatory to refresh image from Uri.
        //getImageView().setImageURI(null);

        //Setting the real returned image.
        //getImageView().setImageURI(r.getUri());

        //If you want the Bitmap.
        getImageView().setImageBitmap(r.getBitmap());

        //Image path
        //r.getPath();
    } else {
        //Handle possible errors
        //TODO: do what you have to do with r.getError();
        Toast.makeText(this, r.getError().getMessage(), Toast.LENGTH_LONG).show();
    }
}
Method #3.2 - Set the listener using the public method (Good for Fragments).
PickImageDialog.build(new PickSetup())
               .setOnPickResult(new IPickResult() {
                  @Override
                  public void onPickResult(PickResult r) {
                     //TODO: do what you have to...
                  }
               })
	       .setOnPickCancel(new IPickCancel() {
		  @Override
		  public void onCancelClick() {
			//TODO: do what you have to if user clicked cancel
		   }
		}).show(getSupportFragmentManager());

Step #4 - Customize you Dialog using PickSetup.

PickSetup setup = new PickSetup()
            .setTitle(yourText)
            .setTitleColor(yourColor)
            .setBackgroundColor(yourColor)
            .setProgressText(yourText)
            .setProgressTextColor(yourColor)
            .setCancelText(yourText)
            .setCancelTextColor(yourColor)
            .setButtonTextColor(yourColor)
            .setDimAmount(yourFloat)
            .setFlip(true)
            .setMaxSize
            .setPickTypes(EPickType.GALLERY, EPickType.CAMERA)
            .setCameraButtonText(yourText)
            .setGalleryButtonText(yourText)
            .setIconGravity(Gravity.LEFT)
            .setButtonOrientation(LinearLayoutCompat.VERTICAL)
            .setSystemDialog(false)
            .setGalleryIcon(yourIcon)
            .setCameraIcon(yourIcon)
            .setGalleryChooserTitle(yourText)
            .setCameraChooserTitle(yourText);
/*... and more to come. */

Additionals

Own click implementations.

If you want to write your own button click event, just use IPickClick listener like in the example below. You may want to take a look at the sample app.

PickImageDialog.build(setup)
        .setOnClick(new IPickClick() {
            @Override
            public void onGalleryClick() {
                Toast.makeText(SampleActivity.this, "Gallery Click!", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCameraClick() {
                Toast.makeText(SampleActivity.this, "Camera Click!", Toast.LENGTH_LONG).show();
            }
         }).show(this);

For dismissing the dialog.

PickImageDialog dialog = PickImageDialog.build(...);
dialog.dismiss();

Force a specific width and height.

new PickSetup().setWidth(600).setHeight(800);

Not just an ImagePicker anymore! You can pick video too.

You can tell the setup to pick video instead of photo! (default option if you don't mention is to pick Image)

new PickSetup().setVideo(true);

Sample app code.

You can take a look at the sample app located on this project.

Instagram Github Google Play Store E-mail

More Repositories

1

MaterialAbout

๐Ÿ”– It's a material-design about screen to use on your Android apps. A developer profile and application information easy to integrate.
Java
1,524
star
2

GaussianBlur

๐ŸŽฉ An easy and fast library to apply gaussian blur filter on any images.
Java
504
star
3

CheckNewAppVersionAvailable

It makes a request to Play Store to check if there is a new version of your published app
Java
73
star
4

IconHandler

๐Ÿ‘“ Tint you Icons, change the size, apply alpha color and set a position easily.
Java
67
star
5

SQLiteHelper

๐Ÿ—„ This project comes in handy when you want to write a sql statement easily and smarter.
Java
58
star
6

ShoppingList

๐Ÿ“ My very first Android app, a shopping list app.
Java
17
star
7

crime-pay

๐Ÿ•น Police And Thief P2E Game
JavaScript
14
star
8

InscricoesBR

Essa classe ajuda vocรช a fazer a formataรงรฃo de CNPJ, CPF, CEP e Telefones.
Java
12
star
9

password-vault

๐Ÿ” Manage passwords, emails, credentials and notes. All on a safe, personal and synced vault.
Java
2
star
10

RxJava3

Learning more about RX Java 3 ๐Ÿ‘จโ€๐Ÿซ
Kotlin
2
star
11

view-binding

๐Ÿ–‡ This is an Android library. It makes your life easier by reducing boilerplate code and avoiding typecasting and redundant lines of code when using View Binding
Kotlin
2
star
12

MyDesignPatterns

Kotlin
1
star
13

SolidKotlin

SOLID study using Kotlin ๐Ÿ‘จโ€๐Ÿซ
Kotlin
1
star
14

git-commands

a bunch of git commands from basics to advanced ones.
1
star
15

DreamShop

This is a project from Vanhackathon 2.0 (October 2016) and was created for the challenges of Dreamify and Shopify.
Java
1
star