Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Add option to set check icon tint while in Unchecked state #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileSdkVersion 27

defaultConfig {
applicationId "net.yazeed44.imagepicker.sample"
minSdkVersion 15
targetSdkVersion 23
versionCode 3
versionName "1.3.1"
targetSdkVersion 27
versionCode 5
versionName "1.3.3"
}
buildTypes {
release {
Expand All @@ -33,11 +32,12 @@ repositories {


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':imagepicker')
compile('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':imagepicker')
implementation('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') {
transitive = true
}
implementation 'com.github.bumptech.glide:glide:4.9.0'
}

// Remove comment to exclude cwac-cam2 dependency to make the capture feature unavailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void onClickPickImageMultipleWithLimit(View view) {
new Picker.Builder(this, this, R.style.MIP_theme)
.setPickMode(Picker.PickMode.MULTIPLE_IMAGES)
.setLimit(6)
.setMessageForLimit("You can't check more than 6 images")
.build()
.startActivity();
}
Expand Down Expand Up @@ -177,7 +178,6 @@ private void loadImage(final String path, final ImageView imageView) {

Glide.with(MainActivity.this)
.load(path)
.asBitmap()
.into(imageView);


Expand Down
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ buildscript {


repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()

}


dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -22,11 +25,15 @@ buildscript {

allprojects {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()

maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
url "https://s3.amazonaws.com/repo.commonsware.com"
}

}


Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jul 22 16:23:45 AST 2015
#Tue May 28 09:22:12 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
28 changes: 14 additions & 14 deletions imagepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ ext {


android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileSdkVersion 27

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 27

}
buildTypes {
Expand All @@ -51,17 +50,18 @@ repositories {


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.octo.android.robospice:robospice:1.4.14'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.commonsware.cwac:cam2:0.2.3'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation "com.android.support:support-v4:27.1.1"
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.octo.android.robospice:robospice:1.4.14'
implementation 'com.melnykov:floatingactionbutton:1.3.0'
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'com.github.chrisbanes.photoview:library:1.2.3'
implementation 'com.commonsware.cwac:cam2:0.2.3'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public void setupAlbum(final AlbumViewHolder holder, final AlbumEntry album) {

Glide.with(mFragment)
.load(album.coverImage.path)
.asBitmap()
.centerCrop()
.into(holder.thumbnail);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public Object instantiateItem(ViewGroup container, int position) {

Glide.with(mFragment)
.load(imageEntry.path)
.asBitmap()
.into(view);

container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ImagesThumbnailAdapter extends RecyclerView.Adapter<ImagesThumbnail
protected final Picker mPickOptions;

protected final Drawable mCheckIcon;
protected final Drawable mUncheckedIcon;
protected final Drawable mVideoIcon;
protected final Fragment mFragment;

Expand All @@ -46,6 +47,7 @@ public ImagesThumbnailAdapter(final Fragment fragment, final AlbumEntry album, f
mPickOptions = pickOptions;

mCheckIcon = createCheckIcon();
mUncheckedIcon = createUncheckedIcon();
mVideoIcon = createVideoIcon();
}

Expand All @@ -56,6 +58,13 @@ private Drawable createCheckIcon() {
return checkIcon;
}

private Drawable createUncheckedIcon() {
Drawable uncheckedIcon = ContextCompat.getDrawable(mRecyclerView.getContext(), R.drawable.ic_action_done_white);
uncheckedIcon = DrawableCompat.wrap(uncheckedIcon);
DrawableCompat.setTint(uncheckedIcon, mPickOptions.checkIconUncheckedTintColor);
return uncheckedIcon;
}

private Drawable createVideoIcon() {
if (!mPickOptions.videosEnabled) {
return null;
Expand Down Expand Up @@ -107,31 +116,29 @@ public void displayThumbnail(final ImageViewHolder holder, final ImageEntry phot

Glide.with(mFragment)
.load(photo.path)
.asBitmap()
.centerCrop()
.into(holder.thumbnail)
;
.into(holder.thumbnail);


}

public void drawGrid(final ImageViewHolder holder, final ImageEntry imageEntry) {


holder.check.setImageDrawable(mCheckIcon);
holder.videoIcon.setVisibility(View.GONE);

if (imageEntry.isPicked) {
holder.itemView.setBackgroundColor(mPickOptions.imageBackgroundColorWhenChecked);
holder.check.setBackgroundColor(mPickOptions.imageBackgroundColorWhenChecked);

holder.check.setImageDrawable(mCheckIcon);
holder.check.setBackgroundColor(mPickOptions.imageBackgroundColorWhenChecked);

holder.thumbnail.setColorFilter(mPickOptions.checkedImageOverlayColor);
final int padding = mRecyclerView.getContext().getResources().getDimensionPixelSize(R.dimen.image_checked_padding);
holder.itemView.setPadding(padding, padding, padding, padding);
} else {

holder.check.setImageDrawable(mUncheckedIcon);
holder.check.setBackgroundColor(mPickOptions.imageCheckColor);

holder.itemView.setBackgroundColor(mPickOptions.imageBackgroundColor);
holder.thumbnail.setColorFilter(Color.TRANSPARENT);
holder.itemView.setPadding(0, 0, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void initTheme() {
}

private void addToolbarToLayout() {
final AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
final AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);

final AppBarLayout.LayoutParams toolbarParams = new AppBarLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Util.getActionBarHeight(this));
toolbarParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
Expand Down Expand Up @@ -146,7 +146,7 @@ public void initFab() {
doneIcon = DrawableCompat.wrap(doneIcon);
DrawableCompat.setTint(doneIcon, mPickOptions.doneFabIconTintColor);

mDoneFab = (com.melnykov.fab.FloatingActionButton) findViewById(R.id.fab_done);
mDoneFab = findViewById(R.id.fab_done);
mDoneFab.setImageDrawable(doneIcon);
mDoneFab.setColorNormal(mPickOptions.fabBackgroundColor);
mDoneFab.setColorPressed(mPickOptions.fabBackgroundColorWhenPressed);
Expand Down Expand Up @@ -335,8 +335,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_deselect_all, menu);




mSelectAllMenuItem = menu.findItem(R.id.action_select_all);
mDeselectAllMenuItem = menu.findItem(R.id.action_deselect_all);

Expand Down Expand Up @@ -437,7 +435,7 @@ private void selectAllImages() {

if (mPickOptions.limit != NO_LIMIT && sCheckedImages.size() + 1 > mPickOptions.limit) {
//Hit the limit
Toast.makeText(this, R.string.you_cant_check_more_images, Toast.LENGTH_SHORT).show();
Toast.makeText(this,mPickOptions.limitMessage, Toast.LENGTH_SHORT).show();
break;
}

Expand Down Expand Up @@ -539,7 +537,7 @@ private void handleMultipleModeAddition(final ImageEntry imageEntry) {
imageEntry.isPicked = true;
sCheckedImages.add(imageEntry);
} else {
Toast.makeText(this, R.string.you_cant_check_more_images, Toast.LENGTH_SHORT).show();
Toast.makeText(this, mPickOptions.limitMessage, Toast.LENGTH_SHORT).show();
Log.i("onPickImage", "You can't check more images");
}

Expand Down Expand Up @@ -586,7 +584,6 @@ private void handleToolbarVisibility(final boolean show) {
}



public void onEvent(final Events.OnClickAlbumEvent albumEvent) {
mSelectedAlbum = albumEvent.albumEntry;

Expand Down Expand Up @@ -687,6 +684,4 @@ public void onEvent(final Events.OnHidingToolbarEvent hidingToolbarEvent) {
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public final class Picker {

public final int limit;
public final String limitMessage;
public final Context context;
public final int fabBackgroundColor;
public final int fabBackgroundColorWhenPressed;
Expand All @@ -43,6 +44,7 @@ public final class Picker {
public final int doneFabIconTintColor;
public final boolean shouldShowCaptureMenuItem;
public final int checkIconTintColor;
public final int checkIconUncheckedTintColor;
public final boolean videosEnabled;
public final int videoLengthLimit;
public final int videoThumbnailOverlayColor;
Expand All @@ -52,6 +54,7 @@ public final class Picker {
private Picker(final Builder builder) {
context = builder.mContext;
limit = builder.mLimit;
limitMessage = builder.mLimitMessage;
fabBackgroundColor = builder.mFabBackgroundColor;
fabBackgroundColorWhenPressed = builder.mFabBackgroundColorWhenPressed;
imageBackgroundColorWhenChecked = builder.mImageBackgroundColorWhenChecked;
Expand All @@ -69,6 +72,7 @@ private Picker(final Builder builder) {
doneFabIconTintColor = builder.mDoneFabIconTintColor;
shouldShowCaptureMenuItem = builder.mShouldShowCaptureMenuItem;
checkIconTintColor = builder.mCheckIconTintColor;
checkIconUncheckedTintColor = builder.mCheckIconUncheckedTintColor;
videosEnabled = builder.mVideosEnabled;
videoLengthLimit = builder.mVideoLengthLimit;
videoThumbnailOverlayColor = builder.mVideoThumbnailOverlayColor;
Expand Down Expand Up @@ -106,6 +110,7 @@ public static class Builder {
private final PickListener mPickListener;
private final int mThemeResId;
private int mLimit = PickerActivity.NO_LIMIT;
private String mLimitMessage;
private int mFabBackgroundColor;
private int mFabBackgroundColorWhenPressed;
private int mImageBackgroundColorWhenChecked;
Expand All @@ -121,6 +126,7 @@ public static class Builder {
private int mCaptureItemIconTintColor;
private boolean mShouldShowCaptureMenuItem;
private int mCheckIconTintColor;
private int mCheckIconUncheckedTintColor;
private boolean mVideosEnabled;
private int mVideoLengthLimit;
private int mVideoThumbnailOverlayColor;
Expand Down Expand Up @@ -169,6 +175,8 @@ private void init() {
mShouldShowCaptureMenuItem = true;

mCheckIconTintColor = Color.WHITE;
mCheckIconUncheckedTintColor = Color.WHITE;

mVideosEnabled = false;
mVideoLengthLimit = 0; // No limit

Expand All @@ -195,6 +203,16 @@ public Picker.Builder setLimit(final int limit) {
return this;
}

public Picker.Builder setMessageForLimit(final int resId) {
mLimitMessage = mContext.getString(resId);
return this;
}

public Picker.Builder setMessageForLimit(final String message) {
mLimitMessage = message;
return this;
}

public Picker.Builder setFabBackgroundColor(@ColorInt final int color) {
mFabBackgroundColor = color;
return this;
Expand Down Expand Up @@ -271,6 +289,11 @@ public Picker.Builder setCheckIconTintColor(@ColorInt final int color) {
return this;
}

public Picker.Builder setCheckIconUncheckedTintColor(@ColorInt final int color) {
mCheckIconUncheckedTintColor = color;
return this;
}

public Picker.Builder setBackBtnInMainActivity(final boolean backBtn) {
mBackBtnInMainActivity = backBtn;
return this;
Expand Down