Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for loading images via Internet + minor fixes. #84

Open
wants to merge 6 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
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}

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 @@
#Tue Mar 28 20:31:03 CEST 2017
#Thu Jan 11 02:21:39 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
17 changes: 10 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 9
versionName "1.0.8"
targetSdkVersion 27
versionCode 10
versionName "1.1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -27,11 +27,11 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:appcompat-v7:27.0.2'
testCompile 'junit:junit:4.12'

// recycler
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.android.support:recyclerview-v7:27.0.2'
compile 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'

// circle image view
Expand All @@ -40,6 +40,9 @@ dependencies {
// butter knife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

// glide
compile 'com.github.bumptech.glide:glide:4.1.1'
}

apply plugin: 'com.github.dcendents.android-maven'
Expand Down
72 changes: 38 additions & 34 deletions library/src/main/java/com/pchmn/materialchips/ChipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pchmn.materialchips.model.Chip;
import com.bumptech.glide.Glide;
import com.pchmn.materialchips.model.ChipInterface;
import com.pchmn.materialchips.util.LetterTileProvider;
import com.pchmn.materialchips.util.ViewUtil;
Expand All @@ -32,17 +30,21 @@ public class ChipView extends RelativeLayout {
// context
private Context mContext;
// xml elements
@BindView(R2.id.content) LinearLayout mContentLayout;
@BindView(R2.id.icon) CircleImageView mAvatarIconImageView;
@BindView(R2.id.label) TextView mLabelTextView;
@BindView(R2.id.delete_button) ImageButton mDeleteButton;
@BindView(R2.id.content)
LinearLayout mContentLayout;
@BindView(R2.id.icon)
CircleImageView mAvatarIconImageView;
@BindView(R2.id.label)
TextView mLabelTextView;
@BindView(R2.id.delete_button)
ImageButton mDeleteButton;
// attributes
private static final int NONE = -1;
private String mLabel;
private ColorStateList mLabelColor;
private boolean mHasAvatarIcon = false;
private Drawable mAvatarIconDrawable;
private Uri mAvatarIconUri;
private String mAvatarIconUri;
private boolean mDeletable = false;
private Drawable mDeleteIcon;
private ColorStateList mDeleteIconColor;
Expand Down Expand Up @@ -78,7 +80,7 @@ private void init(AttributeSet attrs) {
mLetterTileProvider = new LetterTileProvider(mContext);

// attributes
if(attrs != null) {
if (attrs != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ChipView,
Expand All @@ -91,17 +93,18 @@ private void init(AttributeSet attrs) {
// avatar icon
mHasAvatarIcon = a.getBoolean(R.styleable.ChipView_hasAvatarIcon, false);
int avatarIconId = a.getResourceId(R.styleable.ChipView_avatarIcon, NONE);
if(avatarIconId != NONE) mAvatarIconDrawable = ContextCompat.getDrawable(mContext, avatarIconId);
if(mAvatarIconDrawable != null) mHasAvatarIcon = true;
if (avatarIconId != NONE)
mAvatarIconDrawable = ContextCompat.getDrawable(mContext, avatarIconId);
if (mAvatarIconDrawable != null) mHasAvatarIcon = true;
// delete icon
mDeletable = a.getBoolean(R.styleable.ChipView_deletable, false);
mDeleteIconColor = a.getColorStateList(R.styleable.ChipView_deleteIconColor);
int deleteIconId = a.getResourceId(R.styleable.ChipView_deleteIcon, NONE);
if(deleteIconId != NONE) mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
if (deleteIconId != NONE)
mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
// background color
mBackgroundColor = a.getColorStateList(R.styleable.ChipView_backgroundColor);
}
finally {
} finally {
a.recycle();
}
}
Expand All @@ -116,7 +119,7 @@ private void init(AttributeSet attrs) {
private void inflateWithAttributes() {
// label
setLabel(mLabel);
if(mLabelColor != null)
if (mLabelColor != null)
setLabelColor(mLabelColor);

// avatar
Expand All @@ -126,7 +129,7 @@ private void inflateWithAttributes() {
setDeletable(mDeletable);

// background color
if(mBackgroundColor != null)
if (mBackgroundColor != null)
setChipBackgroundColor(mBackgroundColor);
}

Expand Down Expand Up @@ -189,29 +192,31 @@ public void setLabelColor(@ColorInt int color) {
public void setHasAvatarIcon(boolean hasAvatarIcon) {
mHasAvatarIcon = hasAvatarIcon;

if(!mHasAvatarIcon) {
if (!mHasAvatarIcon) {
// hide icon
mAvatarIconImageView.setVisibility(GONE);
// adjust padding
if(mDeleteButton.getVisibility() == VISIBLE)
if (mDeleteButton.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, ViewUtil.dpToPx(12), 0);

}
else {
} else {
// show icon
mAvatarIconImageView.setVisibility(VISIBLE);
// adjust padding
if(mDeleteButton.getVisibility() == VISIBLE)
if (mDeleteButton.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, ViewUtil.dpToPx(12), 0);

// set icon
if(mAvatarIconUri != null)
mAvatarIconImageView.setImageURI(mAvatarIconUri);
else if(mAvatarIconDrawable != null)
if (mAvatarIconUri != null)
//mAvatarIconImageView.setImageURI(mAvatarIconUri);
Glide.with(this)
.load(mAvatarIconUri)
.into(mAvatarIconImageView);
else if (mAvatarIconDrawable != null)
mAvatarIconImageView.setImageDrawable(mAvatarIconDrawable);
else
mAvatarIconImageView.setImageBitmap(mLetterTileProvider.getLetterTile(getLabel()));
Expand All @@ -234,7 +239,7 @@ public void setAvatarIcon(Drawable avatarIcon) {
*
* @param avatarUri the uri of the icon to set
*/
public void setAvatarIcon(Uri avatarUri) {
public void setAvatarIcon(String avatarUri) {
mAvatarIconUri = avatarUri;
mHasAvatarIcon = true;
inflateWithAttributes();
Expand All @@ -247,28 +252,27 @@ public void setAvatarIcon(Uri avatarUri) {
*/
public void setDeletable(boolean deletable) {
mDeletable = deletable;
if(!mDeletable) {
if (!mDeletable) {
// hide delete icon
mDeleteButton.setVisibility(GONE);
// adjust padding
if(mAvatarIconImageView.getVisibility() == VISIBLE)
if (mAvatarIconImageView.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, ViewUtil.dpToPx(12), 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, ViewUtil.dpToPx(12), 0);
}
else {
} else {
// show icon
mDeleteButton.setVisibility(VISIBLE);
// adjust padding
if(mAvatarIconImageView.getVisibility() == VISIBLE)
if (mAvatarIconImageView.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, 0, 0);

// set icon
if(mDeleteIcon != null)
if (mDeleteIcon != null)
mDeleteButton.setImageDrawable(mDeleteIcon);
if(mDeleteIconColor != null)
if (mDeleteIconColor != null)
mDeleteButton.getDrawable().mutate().setColorFilter(mDeleteIconColor.getDefaultColor(), PorterDuff.Mode.SRC_ATOP);
}
}
Expand Down Expand Up @@ -361,7 +365,7 @@ public static class Builder {
private String label;
private ColorStateList labelColor;
private boolean hasAvatarIcon = false;
private Uri avatarIconUri;
private String avatarIconUri;
private Drawable avatarIconDrawable;
private boolean deletable = false;
private Drawable deleteIcon;
Expand All @@ -388,7 +392,7 @@ public Builder hasAvatarIcon(boolean hasAvatarIcon) {
return this;
}

public Builder avatarIcon(Uri avatarUri) {
public Builder avatarIcon(String avatarUri) {
this.avatarIconUri = avatarUri;
return this;
}
Expand Down
34 changes: 18 additions & 16 deletions library/src/main/java/com/pchmn/materialchips/ChipsInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;

import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;
import com.pchmn.materialchips.adapter.ChipsAdapter;
Expand All @@ -37,7 +36,8 @@ public class ChipsInput extends ScrollViewMaxHeight {
// context
private Context mContext;
// xml element
@BindView(R2.id.chips_recycler) RecyclerView mRecyclerView;
@BindView(R2.id.chips_recycler)
RecyclerView mRecyclerView;
// adapter
private ChipsAdapter mChipsAdapter;
// attributes
Expand Down Expand Up @@ -91,7 +91,7 @@ private void init(AttributeSet attrs) {
ButterKnife.bind(this, rootView);

// attributes
if(attrs != null) {
if (attrs != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ChipsInput,
Expand All @@ -113,7 +113,8 @@ private void init(AttributeSet attrs) {
mChipDeletable = a.getBoolean(R.styleable.ChipsInput_chip_deletable, false);
mChipDeleteIconColor = a.getColorStateList(R.styleable.ChipsInput_chip_deleteIconColor);
int deleteIconId = a.getResourceId(R.styleable.ChipsInput_chip_deleteIcon, NONE);
if(deleteIconId != NONE) mChipDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
if (deleteIconId != NONE)
mChipDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
// chip background color
mChipBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_chip_backgroundColor);
// show chip detailed
Expand All @@ -125,8 +126,7 @@ private void init(AttributeSet attrs) {
// filterable list
mFilterableListBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_backgroundColor);
mFilterableListTextColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_textColor);
}
finally {
} finally {
a.recycle();
}
}
Expand All @@ -143,7 +143,7 @@ private void init(AttributeSet attrs) {
// set window callback
// will hide DetailedOpenView and hide keyboard on touch outside
Activity activity = ActivityUtil.scanForActivity(mContext);
if(activity == null)
if (activity == null)
throw new ClassCastException("android.view.Context cannot be cast to android.app.Activity");

android.view.Window.Callback mCallBack = (activity).getWindow().getCallback();
Expand All @@ -164,7 +164,7 @@ public void addChip(Drawable icon, String label, String info) {
mChipsAdapter.addChip(chip);
}

public void addChip(Object id, Uri iconUri, String label, String info) {
public void addChip(Object id, String iconUri, String label, String info) {
Chip chip = new Chip(id, iconUri, label, info);
mChipsAdapter.addChip(chip);
}
Expand Down Expand Up @@ -213,9 +213,9 @@ public ChipView getChipView() {

public ChipsInputEditText getEditText() {
ChipsInputEditText editText = new ChipsInputEditText(mContext);
if(mHintColor != null)
if (mHintColor != null)
editText.setHintTextColor(mHintColor);
if(mTextColor != null)
if (mTextColor != null)
editText.setTextColor(mTextColor);

return editText;
Expand All @@ -236,25 +236,25 @@ public void addChipsListener(ChipsListener chipsListener) {
}

public void onChipAdded(ChipInterface chip, int size) {
for(ChipsListener chipsListener: mChipsListenerList) {
for (ChipsListener chipsListener : mChipsListenerList) {
chipsListener.onChipAdded(chip, size);
}
}

public void onChipRemoved(ChipInterface chip, int size) {
for(ChipsListener chipsListener: mChipsListenerList) {
for (ChipsListener chipsListener : mChipsListenerList) {
chipsListener.onChipRemoved(chip, size);
}
}

public void onTextChanged(CharSequence text) {
if(mChipsListener != null) {
for(ChipsListener chipsListener: mChipsListenerList) {
if (mChipsListener != null) {
for (ChipsListener chipsListener : mChipsListenerList) {
chipsListener.onTextChanged(text);
}
// show filterable list
if(mFilterableListView != null) {
if(text.length() > 0)
if (mFilterableListView != null) {
if (text.length() > 0)
mFilterableListView.filterList(text);
else
mFilterableListView.fadeOut();
Expand Down Expand Up @@ -357,7 +357,9 @@ public void setChipValidator(ChipValidator mChipValidator) {

public interface ChipsListener {
void onChipAdded(ChipInterface chip, int newSize);

void onChipRemoved(ChipInterface chip, int newSize);

void onTextChanged(CharSequence text);
}

Expand Down
Loading