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

Commit

Permalink
Added an option to set the color of check icon
Browse files Browse the repository at this point in the history
  • Loading branch information
yazeed44 committed Jul 23, 2015
1 parent d2cd592 commit 9b34381
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
<orderEntry type="library" exported="" name="robospice-cache-1.4.14" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="robospice-1.4.14" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.0" level="project" />
<orderEntry type="module" module-name="imagepicker" exported="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package net.yazeed44.imagepicker.ui;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -22,25 +25,35 @@
/**
* Created by yazeed44 on 11/23/14.
*/
public class ImagesThumbnailAdapter extends RecyclerView.Adapter<ImagesThumbnailAdapter.ImagesViewHolder> implements Util.OnClickImage {
public class ImagesThumbnailAdapter extends RecyclerView.Adapter<ImagesThumbnailAdapter.ImageViewHolder> implements Util.OnClickImage {


protected final AlbumEntry mAlbum;
protected final RecyclerView mRecyclerView;
protected final Picker mPickOptions;
protected final Drawable mCheckIcon;


public ImagesThumbnailAdapter(final AlbumEntry album, final RecyclerView fragment, Picker pickOptions) {
public ImagesThumbnailAdapter(final AlbumEntry album, final RecyclerView recyclerView, Picker pickOptions) {
this.mAlbum = album;
this.mRecyclerView = fragment;
this.mRecyclerView = recyclerView;
mPickOptions = pickOptions;

mCheckIcon = createCheckIcon();
}

private Drawable createCheckIcon() {
Drawable checkIcon = ContextCompat.getDrawable(mRecyclerView.getContext(), R.drawable.ic_action_done_white);
checkIcon = DrawableCompat.wrap(checkIcon);
DrawableCompat.setTint(checkIcon, mPickOptions.checkIconTintColor);
return checkIcon;
}

@Override
public ImagesViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
public ImageViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
final View imageLayout = LayoutInflater.from(mRecyclerView.getContext()).inflate(R.layout.element_image, viewGroup, false);

return new ImagesViewHolder(imageLayout, this);
return new ImageViewHolder(imageLayout, this);
}

@Override
Expand All @@ -49,19 +62,19 @@ public int getItemCount() {
}

@Override
public void onBindViewHolder(ImagesViewHolder imagesViewHolder, int position) {
final ImageEntry photoEntry = mAlbum.imageList.get(position);
setHeight(imagesViewHolder.itemView);
displayThumbnail(imagesViewHolder, photoEntry);
drawGrid(imagesViewHolder, photoEntry);
public void onBindViewHolder(ImageViewHolder imageViewHolder, int position) {
final ImageEntry imageEntry = mAlbum.imageList.get(position);
setHeight(imageViewHolder.itemView);
displayThumbnail(imageViewHolder, imageEntry);
drawGrid(imageViewHolder, imageEntry);

}

@Override
public void onClickImage(View layout, ImageView thumbnail, ImageView check) {

final int position = Util.getPositionOfChild(layout, R.id.image_layout, mRecyclerView);
final ImagesViewHolder holder = (ImagesViewHolder) mRecyclerView.getChildViewHolder(layout);
final ImageViewHolder holder = (ImageViewHolder) mRecyclerView.getChildViewHolder(layout);
pickImage(holder, mAlbum.imageList.get(position));
}

Expand All @@ -75,7 +88,7 @@ public void setHeight(final View convertView) {

}

public void displayThumbnail(final ImagesViewHolder holder, final ImageEntry photo) {
public void displayThumbnail(final ImageViewHolder holder, final ImageEntry photo) {


Glide.with(mRecyclerView.getContext())
Expand All @@ -88,7 +101,10 @@ public void displayThumbnail(final ImagesViewHolder holder, final ImageEntry pho

}

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


holder.check.setImageDrawable(mCheckIcon);


if (isPicked(imageEntry)) {
Expand All @@ -113,7 +129,7 @@ public void drawGrid(final ImagesViewHolder holder, final ImageEntry imageEntry)
}


public void pickImage(final ImagesViewHolder holder, final ImageEntry imageEntry) {
public void pickImage(final ImageViewHolder holder, final ImageEntry imageEntry) {

final boolean isPicked = isPicked(imageEntry);

Expand Down Expand Up @@ -150,11 +166,11 @@ public boolean isPicked(final ImageEntry pImageEntry) {
}


class ImagesViewHolder extends RecyclerView.ViewHolder {
public static class ImageViewHolder extends RecyclerView.ViewHolder {
private final ImageView thumbnail;
private final ImageView check;

public ImagesViewHolder(final View itemView, final Util.OnClickImage listener) {
public ImageViewHolder(final View itemView, final Util.OnClickImage listener) {
super(itemView);

thumbnail = (ImageView) itemView.findViewById(R.id.image_thumbnail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private void initActionbar() {
}

public void initFab() {
final Drawable doneIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_done_white);
final Drawable doneIconWrapped = DrawableCompat.wrap(doneIcon);
DrawableCompat.setTint(doneIconWrapped, mPickOptions.doneFabIconTintColor);
Drawable doneIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_done_white);
doneIcon = DrawableCompat.wrap(doneIcon);
DrawableCompat.setTint(doneIcon, mPickOptions.doneFabIconTintColor);

mDoneFab = (com.melnykov.fab.FloatingActionButton) findViewById(R.id.fab_done);
mDoneFab.setImageDrawable(doneIconWrapped);
mDoneFab.setImageDrawable(doneIcon);
mDoneFab.setColorNormal(mPickOptions.fabBackgroundColor);
mDoneFab.setColorPressed(mPickOptions.fabBackgroundColorWhenPressed);

Expand Down Expand Up @@ -408,12 +408,6 @@ private void handleMultipleModeAddition(final ImageEntry imageEntry) {
Log.i("onPickImage", "You can't check more images");
}

/*if (shouldShowDeselectAll()) {
//If all the images in the album selected then show de select all menu item
showDeselectAll();
}*/


}

private boolean shouldShowDeselectAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
Expand Down Expand Up @@ -38,7 +39,8 @@ public final class Picker {
public final int popupThemeResId;
public final int captureItemIconTintColor;
public final int doneFabIconTintColor;
public boolean shouldShowCaptureMenuItem;
public final boolean shouldShowCaptureMenuItem;
public final int checkIconTintColor;


private Picker(final Builder builder) {
Expand All @@ -60,6 +62,7 @@ private Picker(final Builder builder) {
captureItemIconTintColor = builder.mCaptureItemIconTintColor;
doneFabIconTintColor = builder.mDoneFabIconTintColor;
shouldShowCaptureMenuItem = builder.mShouldShowCaptureMenuItem;
checkIconTintColor = builder.mCheckIconTintColor;



Expand Down Expand Up @@ -108,7 +111,7 @@ public static class Builder {
private int mDoneFabIconTintColor;
private int mCaptureItemIconTintColor;
private boolean mShouldShowCaptureMenuItem;

private int mCheckIconTintColor;


//Use (Context,PickListener,themeResId) instead
Expand Down Expand Up @@ -152,6 +155,8 @@ private void init() {

mShouldShowCaptureMenuItem = true;

mCheckIconTintColor = Color.WHITE;

}


Expand Down Expand Up @@ -242,6 +247,12 @@ public Picker.Builder disableCaptureImageFromCamera() {
return this;
}

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


public Picker build() {
return new Picker(this);
}
Expand Down
3 changes: 1 addition & 2 deletions imagepicker/src/main/res/layout/element_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
android:background="@color/alter_image_check_color"
android:contentDescription="@string/image_check"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/ic_action_done_white" />
android:focusableInTouchMode="false" />

</FrameLayout>

0 comments on commit 9b34381

Please sign in to comment.