diff --git a/build.gradle b/build.gradle index 64dc55d3..6a031ca2 100644 --- a/build.gradle +++ b/build.gradle @@ -3,15 +3,14 @@ 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' } } @@ -19,7 +18,7 @@ buildscript { allprojects { repositories { jcenter() - mavenCentral() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7f3b2ff9..ef3b7d53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index 974cc24f..e8899d69 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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" @@ -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 @@ -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' diff --git a/library/src/main/java/com/pchmn/materialchips/ChipView.java b/library/src/main/java/com/pchmn/materialchips/ChipView.java index 07e3aea9..40ecaa6e 100644 --- a/library/src/main/java/com/pchmn/materialchips/ChipView.java +++ b/library/src/main/java/com/pchmn/materialchips/ChipView.java @@ -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; @@ -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; @@ -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, @@ -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(); } } @@ -116,7 +119,7 @@ private void init(AttributeSet attrs) { private void inflateWithAttributes() { // label setLabel(mLabel); - if(mLabelColor != null) + if (mLabelColor != null) setLabelColor(mLabelColor); // avatar @@ -126,7 +129,7 @@ private void inflateWithAttributes() { setDeletable(mDeletable); // background color - if(mBackgroundColor != null) + if (mBackgroundColor != null) setChipBackgroundColor(mBackgroundColor); } @@ -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())); @@ -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(); @@ -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); } } @@ -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; @@ -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; } diff --git a/library/src/main/java/com/pchmn/materialchips/ChipsInput.java b/library/src/main/java/com/pchmn/materialchips/ChipsInput.java index ba3dbd56..623573a2 100644 --- a/library/src/main/java/com/pchmn/materialchips/ChipsInput.java +++ b/library/src/main/java/com/pchmn/materialchips/ChipsInput.java @@ -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; @@ -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 @@ -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, @@ -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 @@ -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(); } } @@ -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(); @@ -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); } @@ -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; @@ -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(); @@ -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); } diff --git a/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java b/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java index 6e000411..3c517439 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java @@ -6,7 +6,6 @@ import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; -import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; @@ -18,10 +17,9 @@ import com.pchmn.materialchips.ChipView; import com.pchmn.materialchips.ChipsInput; import com.pchmn.materialchips.model.ChipInterface; +import com.pchmn.materialchips.util.ViewUtil; import com.pchmn.materialchips.views.ChipsInputEditText; import com.pchmn.materialchips.views.DetailedChipView; -import com.pchmn.materialchips.model.Chip; -import com.pchmn.materialchips.util.ViewUtil; import com.pchmn.materialchips.views.FilterableListView; import java.util.ArrayList; @@ -72,7 +70,7 @@ private class EditTextViewHolder extends RecyclerView.ViewHolder { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - if(viewType == TYPE_EDIT_TEXT) + if (viewType == TYPE_EDIT_TEXT) return new EditTextViewHolder(mEditText); else return new ItemViewHolder(mChipsInput.getChipView()); @@ -82,15 +80,15 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { // edit text - if(position == mChipList.size()) { - if(mChipList.size() == 0) + if (position == mChipList.size()) { + if (mChipList.size() == 0) mEditText.setHint(mHintLabel); // auto fit edit text autofitEditText(); } // chip - else if(getItemCount() > 1) { + else if (getItemCount() > 1) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; itemViewHolder.chipView.inflate(getItem(position)); // handle click @@ -137,10 +135,10 @@ private void initEditText() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // backspace - if(event.getAction() == KeyEvent.ACTION_DOWN + if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { // remove last chip - if(mChipList.size() > 0 && mEditText.getText().toString().length() == 0) + if (mChipList.size() > 0 && mEditText.getText().toString().length() == 0) removeChip(mChipList.size() - 1); } return false; @@ -210,7 +208,7 @@ public void onClick(View v) { }); // show detailed chip - if(mChipsInput.isShowChipDetailed()) { + if (mChipsInput.isShowChipDetailed()) { chipView.setOnChipClicked(new View.OnClickListener() { @Override public void onClick(View v) { @@ -248,13 +246,13 @@ private void setDetailedChipViewPosition(DetailedChipView detailedChipView, int[ layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); // align left window - if(coord[0] <= 0) { + if (coord[0] <= 0) { layoutParams.leftMargin = 0; layoutParams.topMargin = coord[1] - ViewUtil.dpToPx(13); detailedChipView.alignLeft(); } // align right - else if(coord[0] + ViewUtil.dpToPx(300) > windowWidth + ViewUtil.dpToPx(13)) { + else if (coord[0] + ViewUtil.dpToPx(300) > windowWidth + ViewUtil.dpToPx(13)) { layoutParams.leftMargin = windowWidth - ViewUtil.dpToPx(300); layoutParams.topMargin = coord[1] - ViewUtil.dpToPx(13); detailedChipView.alignRight(); @@ -271,12 +269,12 @@ else if(coord[0] + ViewUtil.dpToPx(300) > windowWidth + ViewUtil.dpToPx(13)) { } public void setFilterableListView(FilterableListView filterableListView) { - if(mEditText != null) + if (mEditText != null) mEditText.setFilterableListView(filterableListView); } public void addChip(ChipInterface chip) { - if(!listContains(mChipList, chip)) { + if (!listContains(mChipList, chip)) { mChipList.add(chip); // notify listener mChipsInput.onChipAdded(chip, mChipList.size()); @@ -371,17 +369,16 @@ public List getChipList() { private boolean listContains(List contactList, ChipInterface chip) { - if(mChipsInput.getChipValidator() != null) { - for(ChipInterface item: contactList) { - if(mChipsInput.getChipValidator().areEquals(item, chip)) + if (mChipsInput.getChipValidator() != null) { + for (ChipInterface item : contactList) { + if (mChipsInput.getChipValidator().areEquals(item, chip)) return true; } - } - else { - for(ChipInterface item: contactList) { - if(chip.getId() != null && chip.getId().equals(item.getId())) + } else { + for (ChipInterface item : contactList) { + if (chip.getId() != null && chip.getId().equals(item.getId())) return true; - if(chip.getLabel().equals(item.getLabel())) + if (chip.getLabel().equals(item.getLabel())) return true; } } diff --git a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java index 5fd1273f..e081b8e3 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java @@ -5,28 +5,25 @@ import android.content.res.ColorStateList; import android.graphics.PorterDuff; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; -import android.widget.Toast; +import com.bumptech.glide.Glide; import com.pchmn.materialchips.ChipsInput; import com.pchmn.materialchips.R; import com.pchmn.materialchips.model.ChipInterface; import com.pchmn.materialchips.util.ColorUtil; import com.pchmn.materialchips.util.LetterTileProvider; -import com.pchmn.materialchips.util.ViewUtil; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -73,8 +70,8 @@ public int compare(ChipInterface o1, ChipInterface o2) { }; // remove chips that do not have label Iterator iterator = chipList.iterator(); - while(iterator.hasNext()) { - if(iterator.next().getLabel() == null) + while (iterator.hasNext()) { + if (iterator.next().getLabel() == null) iterator.remove(); } sortList(chipList); @@ -130,19 +127,19 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { final ChipInterface chip = getItem(position); // avatar - if(mChipsInput.chipHasAvatarIcon() && chip.getAvatarUri() != null) { + if (mChipsInput.chipHasAvatarIcon() && chip.getAvatarUri() != null) { itemViewHolder.mAvatar.setVisibility(View.VISIBLE); - itemViewHolder.mAvatar.setImageURI(chip.getAvatarUri()); - } - else if(mChipsInput.chipHasAvatarIcon() && chip.getAvatarDrawable() != null) { + //itemViewHolder.mAvatar.setImageURI(chip.getAvatarUri()); + Glide.with(mContext) + .load(chip.getAvatarUri()) + .into(itemViewHolder.mAvatar); + } else if (mChipsInput.chipHasAvatarIcon() && chip.getAvatarDrawable() != null) { itemViewHolder.mAvatar.setVisibility(View.VISIBLE); itemViewHolder.mAvatar.setImageDrawable(chip.getAvatarDrawable()); - } - else if(mChipsInput.chipHasAvatarIcon()) { + } else if (mChipsInput.chipHasAvatarIcon()) { itemViewHolder.mAvatar.setVisibility(View.VISIBLE); itemViewHolder.mAvatar.setImageBitmap(mLetterTileProvider.getLetterTile(chip.getLabel())); - } - else { + } else { itemViewHolder.mAvatar.setVisibility(GONE); } @@ -150,18 +147,17 @@ else if(mChipsInput.chipHasAvatarIcon()) { itemViewHolder.mLabel.setText(chip.getLabel()); // info - if(chip.getInfo() != null) { + if (chip.getInfo() != null) { itemViewHolder.mInfo.setVisibility(View.VISIBLE); itemViewHolder.mInfo.setText(chip.getInfo()); - } - else { + } else { itemViewHolder.mInfo.setVisibility(GONE); } // colors - if(mBackgroundColor != null) + if (mBackgroundColor != null) itemViewHolder.itemView.getBackground().setColorFilter(mBackgroundColor.getDefaultColor(), PorterDuff.Mode.SRC_ATOP); - if(mTextColor != null) { + if (mTextColor != null) { itemViewHolder.mLabel.setTextColor(mTextColor); itemViewHolder.mInfo.setTextColor(ColorUtil.alpha(mTextColor.getDefaultColor(), 150)); } @@ -170,7 +166,7 @@ else if(mChipsInput.chipHasAvatarIcon()) { itemViewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(mChipsInput != null) + if (mChipsInput != null) mChipsInput.addChip(chip); } }); @@ -187,7 +183,7 @@ private ChipInterface getItem(int position) { @Override public Filter getFilter() { - if(mFilter == null) + if (mFilter == null) mFilter = new ChipFilter(this, mChipList); return mFilter; } @@ -216,8 +212,7 @@ protected FilterResults performFiltering(CharSequence constraint) { for (ChipInterface chip : originalList) { if (chip.getLabel().toLowerCase().contains(filterPattern)) { filteredList.add(chip); - } - else if(chip.getInfo() != null && chip.getInfo().toLowerCase().replaceAll("\\s", "").contains(filterPattern)) { + } else if (chip.getInfo() != null && chip.getInfo().toLowerCase().replaceAll("\\s", "").contains(filterPattern)) { filteredList.add(chip); } } @@ -242,14 +237,14 @@ private void removeChip(ChipInterface chip) { mFilteredList.remove(position); position = mChipList.indexOf(chip); - if(position >= 0) + if (position >= 0) mChipList.remove(position); notifyDataSetChanged(); } private void addChip(ChipInterface chip) { - if(contains(chip)) { + if (contains(chip)) { mChipList.add(chip); mFilteredList.add(chip); // sort original list @@ -262,8 +257,8 @@ private void addChip(ChipInterface chip) { } private boolean contains(ChipInterface chip) { - for(ChipInterface item: mOriginalList) { - if(item.equals(chip)) + for (ChipInterface item : mOriginalList) { + if (item.equals(chip)) return true; } return false; diff --git a/library/src/main/java/com/pchmn/materialchips/model/Chip.java b/library/src/main/java/com/pchmn/materialchips/model/Chip.java index 892e9366..c9c10590 100644 --- a/library/src/main/java/com/pchmn/materialchips/model/Chip.java +++ b/library/src/main/java/com/pchmn/materialchips/model/Chip.java @@ -2,19 +2,18 @@ import android.graphics.drawable.Drawable; -import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; public class Chip implements ChipInterface { private Object id; - private Uri avatarUri; + private String avatarUri; private Drawable avatarDrawable; private String label; private String info; - public Chip(@NonNull Object id, @Nullable Uri avatarUri, @NonNull String label, @Nullable String info) { + public Chip(@NonNull Object id, @Nullable String avatarUri, @NonNull String label, @Nullable String info) { this.id = id; this.avatarUri = avatarUri; this.label = label; @@ -28,7 +27,7 @@ public Chip(@NonNull Object id, @Nullable Drawable avatarDrawable, @NonNull Stri this.info = info; } - public Chip(@Nullable Uri avatarUri, @NonNull String label, @Nullable String info) { + public Chip(@Nullable String avatarUri, @NonNull String label, @Nullable String info) { this.avatarUri = avatarUri; this.label = label; this.info = info; @@ -57,7 +56,7 @@ public Object getId() { } @Override - public Uri getAvatarUri() { + public String getAvatarUri() { return avatarUri; } diff --git a/library/src/main/java/com/pchmn/materialchips/model/ChipInterface.java b/library/src/main/java/com/pchmn/materialchips/model/ChipInterface.java index e942bfb7..3839e649 100644 --- a/library/src/main/java/com/pchmn/materialchips/model/ChipInterface.java +++ b/library/src/main/java/com/pchmn/materialchips/model/ChipInterface.java @@ -2,13 +2,16 @@ import android.graphics.drawable.Drawable; -import android.net.Uri; public interface ChipInterface { Object getId(); - Uri getAvatarUri(); + + String getAvatarUri(); + Drawable getAvatarDrawable(); + String getLabel(); + String getInfo(); } diff --git a/library/src/main/java/com/pchmn/materialchips/util/ActivityUtil.java b/library/src/main/java/com/pchmn/materialchips/util/ActivityUtil.java index c119fad0..c1605a30 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/ActivityUtil.java +++ b/library/src/main/java/com/pchmn/materialchips/util/ActivityUtil.java @@ -11,9 +11,9 @@ public static Activity scanForActivity(Context context) { if (context == null) return null; else if (context instanceof Activity) - return (Activity)context; + return (Activity) context; else if (context instanceof ContextWrapper) - return scanForActivity(((ContextWrapper)context).getBaseContext()); + return scanForActivity(((ContextWrapper) context).getBaseContext()); return null; } diff --git a/library/src/main/java/com/pchmn/materialchips/util/ColorUtil.java b/library/src/main/java/com/pchmn/materialchips/util/ColorUtil.java index c1b118c1..bb762bef 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/ColorUtil.java +++ b/library/src/main/java/com/pchmn/materialchips/util/ColorUtil.java @@ -25,14 +25,14 @@ public static int alpha(int color, int alpha) { return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); } - public static boolean isColorDark(int color){ - double darkness = 1 - (0.2126*Color.red(color) + 0.7152*Color.green(color) + 0.0722*Color.blue(color))/255; + public static boolean isColorDark(int color) { + double darkness = 1 - (0.2126 * Color.red(color) + 0.7152 * Color.green(color) + 0.0722 * Color.blue(color)) / 255; return darkness >= 0.5; } - public static int getThemeAccentColor (final Context context) { - final TypedValue value = new TypedValue (); - context.getTheme ().resolveAttribute (R.attr.colorAccent, value, true); + public static int getThemeAccentColor(final Context context) { + final TypedValue value = new TypedValue(); + context.getTheme().resolveAttribute(R.attr.colorAccent, value, true); return value.data; } } diff --git a/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java b/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java index 9028a528..b711ca32 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java +++ b/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java @@ -4,7 +4,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -16,7 +15,6 @@ import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.text.TextPaint; -import android.util.Log; import com.pchmn.materialchips.R; @@ -27,28 +25,48 @@ */ public class LetterTileProvider { - /** The number of available tile colors (see R.array.letter_tile_colors) */ + /** + * The number of available tile colors (see R.array.letter_tile_colors) + */ private static final int NUM_OF_TILE_COLORS = 8; - /** The {@link TextPaint} used to draw the letter onto the tile */ + /** + * The {@link TextPaint} used to draw the letter onto the tile + */ private final TextPaint mPaint = new TextPaint(); - /** The bounds that enclose the letter */ + /** + * The bounds that enclose the letter + */ private final Rect mBounds = new Rect(); - /** The {@link Canvas} to draw on */ + /** + * The {@link Canvas} to draw on + */ private final Canvas mCanvas = new Canvas(); - /** The first char of the name being displayed */ + /** + * The first char of the name being displayed + */ private final char[] mFirstChar = new char[1]; - /** The background colors of the tile */ + /** + * The background colors of the tile + */ private final TypedArray mColors; - /** The font size used to display the letter */ + /** + * The font size used to display the letter + */ private final int mTileLetterFontSize; - /** The default image to display */ + /** + * The default image to display + */ private final Bitmap mDefaultBitmap; - /** Width */ + /** + * Width + */ private final int mWidth; - /** Height */ + /** + * Height + */ private final int mHeight; /** @@ -76,12 +94,12 @@ public LetterTileProvider(Context context) { /** * @param displayName The name used to create the letter for the tile * @return A {@link Bitmap} that contains a letter used in the English - * alphabet or digit, if there is no letter or digit available, a - * default image is shown instead + * alphabet or digit, if there is no letter or digit available, a + * default image is shown instead */ public Bitmap getLetterTile(String displayName) { // workaround - if(displayName == null || displayName.length() == 0) + if (displayName == null || displayName.length() == 0) return null; final Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); @@ -98,8 +116,7 @@ public Bitmap getLetterTile(String displayName) { mPaint.getTextBounds(mFirstChar, 0, 1, mBounds); c.drawText(mFirstChar, 0, 1, mWidth / 2, mHeight / 2 + (mBounds.bottom - mBounds.top) / 2, mPaint); - } - else { + } else { // (32 - 24) / 2 = 4 c.drawBitmap(mDefaultBitmap, ViewUtil.dpToPx(4), ViewUtil.dpToPx(4), null); } @@ -109,12 +126,12 @@ public Bitmap getLetterTile(String displayName) { /** * @param displayName The name used to create the letter for the tile * @return A circular {@link Bitmap} that contains a letter used in the English - * alphabet or digit, if there is no letter or digit available, a - * default image is shown instead + * alphabet or digit, if there is no letter or digit available, a + * default image is shown instead */ public Bitmap getCircularLetterTile(String displayName) { // workaround - if(displayName == null || displayName.length() == 0) + if (displayName == null || displayName.length() == 0) displayName = "."; final Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); @@ -140,7 +157,7 @@ public Bitmap getCircularLetterTile(String displayName) { /** * @param c The char to check * @return True if c is in the English alphabet or is a digit, - * false otherwise + * false otherwise */ private static boolean isLetterOrDigit(char c) { //return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9'; @@ -150,7 +167,7 @@ private static boolean isLetterOrDigit(char c) { /** * @param key The key used to generate the tile color * @return A new or previously chosen color for key used as the - * tile background color + * tile background color */ private int pickColor(String key) { // String.hashCode() is not supposed to change across java versions, so @@ -196,17 +213,17 @@ private Bitmap getCircularBitmap(Bitmap bitmap) { return output; } - public static Bitmap drawableToBitmap (Drawable drawable) { + public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; - if(bitmapDrawable.getBitmap() != null) { + if (bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } - if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { + if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); diff --git a/library/src/main/java/com/pchmn/materialchips/util/MyWindowCallback.java b/library/src/main/java/com/pchmn/materialchips/util/MyWindowCallback.java index 92435080..3147199c 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/MyWindowCallback.java +++ b/library/src/main/java/com/pchmn/materialchips/util/MyWindowCallback.java @@ -17,7 +17,6 @@ import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; import com.pchmn.materialchips.views.ChipsInputEditText; import com.pchmn.materialchips.views.DetailedChipView; @@ -46,7 +45,7 @@ public boolean dispatchKeyShortcutEvent(KeyEvent keyEvent) { public boolean dispatchTouchEvent(MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { View v = mActivity.getCurrentFocus(); - if(v instanceof DetailedChipView) { + if (v instanceof DetailedChipView) { Rect outRect = new Rect(); v.getGlobalVisibleRect(outRect); if (!outRect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY())) { diff --git a/library/src/main/java/com/pchmn/materialchips/util/ViewUtil.java b/library/src/main/java/com/pchmn/materialchips/util/ViewUtil.java index 1cae87da..f3ca6e28 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/ViewUtil.java +++ b/library/src/main/java/com/pchmn/materialchips/util/ViewUtil.java @@ -22,16 +22,15 @@ public static int pxToDp(int px) { } public static int getWindowWidth(Context context) { - if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ + if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { return getWindowWidthPortrait(context); - } - else { + } else { return getWindowWidthLandscape(context); } } private static int getWindowWidthPortrait(Context context) { - if(windowWidthPortrait == 0) { + if (windowWidthPortrait == 0) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); windowWidthPortrait = metrics.widthPixels; } @@ -40,7 +39,7 @@ private static int getWindowWidthPortrait(Context context) { } private static int getWindowWidthLandscape(Context context) { - if(windowWidthLandscape == 0) { + if (windowWidthLandscape == 0) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); windowWidthLandscape = metrics.widthPixels; } @@ -53,15 +52,15 @@ public static int getNavBarHeight(Context context) { boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); - if(!hasMenuKey && !hasBackKey) { + if (!hasMenuKey && !hasBackKey) { //The device has a navigation bar Resources resources = context.getResources(); int orientation = context.getResources().getConfiguration().orientation; int resourceId; - if (isTablet(context)){ + if (isTablet(context)) { resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android"); - } else { + } else { resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android"); } diff --git a/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java b/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java index d3bb04f5..c878f092 100644 --- a/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java +++ b/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java @@ -3,7 +3,6 @@ import android.content.Context; import android.util.AttributeSet; -import android.util.Log; public class ChipsInputEditText extends android.support.v7.widget.AppCompatEditText { diff --git a/library/src/main/java/com/pchmn/materialchips/views/DetailedChipView.java b/library/src/main/java/com/pchmn/materialchips/views/DetailedChipView.java index 766a2e92..ab5aa5cd 100644 --- a/library/src/main/java/com/pchmn/materialchips/views/DetailedChipView.java +++ b/library/src/main/java/com/pchmn/materialchips/views/DetailedChipView.java @@ -1,15 +1,11 @@ package com.pchmn.materialchips.views; -import android.app.Activity; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.PorterDuff; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; -import android.net.Uri; import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.view.View; @@ -18,14 +14,12 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import com.bumptech.glide.Glide; import com.pchmn.materialchips.R; import com.pchmn.materialchips.R2; -import com.pchmn.materialchips.model.Chip; import com.pchmn.materialchips.model.ChipInterface; import com.pchmn.materialchips.util.ColorUtil; import com.pchmn.materialchips.util.LetterTileProvider; -import com.pchmn.materialchips.util.MyWindowCallback; -import com.pchmn.materialchips.util.ViewUtil; import butterknife.BindView; import butterknife.ButterKnife; @@ -38,11 +32,16 @@ public class DetailedChipView extends RelativeLayout { // context private Context mContext; // xml elements - @BindView(R2.id.content) RelativeLayout mContentLayout; - @BindView(R2.id.avatar_icon) CircleImageView mAvatarIconImageView; - @BindView(R2.id.name) TextView mNameTextView; - @BindView(R2.id.info) TextView mInfoTextView; - @BindView(R2.id.delete_button) ImageButton mDeleteButton; + @BindView(R2.id.content) + RelativeLayout mContentLayout; + @BindView(R2.id.avatar_icon) + CircleImageView mAvatarIconImageView; + @BindView(R2.id.name) + TextView mNameTextView; + @BindView(R2.id.info) + TextView mInfoTextView; + @BindView(R2.id.delete_button) + ImageButton mDeleteButton; // letter tile provider private static LetterTileProvider mLetterTileProvider; // attributes @@ -122,8 +121,10 @@ public void setAvatarIcon(Bitmap icon) { mAvatarIconImageView.setImageBitmap(icon); } - public void setAvatarIcon(Uri icon) { - mAvatarIconImageView.setImageURI(icon); + public void setAvatarIcon(String icon) { + Glide.with(this) + .load(icon) + .into(mAvatarIconImageView); } public void setName(String name) { @@ -131,11 +132,10 @@ public void setName(String name) { } public void setInfo(String info) { - if(info != null) { + if (info != null) { mInfoTextView.setVisibility(VISIBLE); mInfoTextView.setText(info); - } - else { + } else { mInfoTextView.setVisibility(GONE); } } @@ -176,7 +176,7 @@ public void alignRight() { public static class Builder { private Context context; - private Uri avatarUri; + private String avatarUri; private Drawable avatarDrawable; private String name; private String info; @@ -188,7 +188,7 @@ public Builder(Context context) { this.context = context; } - public Builder avatar(Uri avatarUri) { + public Builder avatar(String avatarUri) { this.avatarUri = avatarUri; return this; } @@ -239,29 +239,29 @@ public DetailedChipView build() { private static DetailedChipView newInstance(Builder builder) { DetailedChipView detailedChipView = new DetailedChipView(builder.context); // avatar - if(builder.avatarUri != null) + if (builder.avatarUri != null) detailedChipView.setAvatarIcon(builder.avatarUri); - else if(builder.avatarDrawable != null) + else if (builder.avatarDrawable != null) detailedChipView.setAvatarIcon(builder.avatarDrawable); else detailedChipView.setAvatarIcon(mLetterTileProvider.getLetterTile(builder.name)); // background color - if(builder.backgroundColor != null) + if (builder.backgroundColor != null) detailedChipView.setBackGroundcolor(builder.backgroundColor); // text color - if(builder.textColor != null) + if (builder.textColor != null) detailedChipView.setTextColor(builder.textColor); - else if(ColorUtil.isColorDark(detailedChipView.getBackgroundColor())) + else if (ColorUtil.isColorDark(detailedChipView.getBackgroundColor())) detailedChipView.setTextColor(ColorStateList.valueOf(Color.WHITE)); else detailedChipView.setTextColor(ColorStateList.valueOf(Color.BLACK)); // delete icon color - if(builder.deleteIconColor != null) + if (builder.deleteIconColor != null) detailedChipView.setDeleteIconColor(builder.deleteIconColor); - else if(ColorUtil.isColorDark(detailedChipView.getBackgroundColor())) + else if (ColorUtil.isColorDark(detailedChipView.getBackgroundColor())) detailedChipView.setDeleteIconColor(ColorStateList.valueOf(Color.WHITE)); else detailedChipView.setDeleteIconColor(ColorStateList.valueOf(Color.BLACK)); diff --git a/library/src/main/java/com/pchmn/materialchips/views/FilterableListView.java b/library/src/main/java/com/pchmn/materialchips/views/FilterableListView.java index 8e94cd52..8edcba16 100644 --- a/library/src/main/java/com/pchmn/materialchips/views/FilterableListView.java +++ b/library/src/main/java/com/pchmn/materialchips/views/FilterableListView.java @@ -33,7 +33,8 @@ public class FilterableListView extends RelativeLayout { private static final String TAG = FilterableListView.class.toString(); private Context mContext; // list - @BindView(R2.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R2.id.recycler_view) + RecyclerView mRecyclerView; private FilterableAdapter mAdapter; private List mFilterableList; // others @@ -65,7 +66,7 @@ public void build(List filterableList, ChipsInput chips // adapter mAdapter = new FilterableAdapter(mContext, mRecyclerView, filterableList, chipsInput, backgroundColor, textColor); mRecyclerView.setAdapter(mAdapter); - if(backgroundColor != null) + if (backgroundColor != null) mRecyclerView.getBackground().setColorFilter(backgroundColor.getDefaultColor(), PorterDuff.Mode.SRC_ATOP); // listen to change in the tree @@ -85,7 +86,7 @@ public void onGlobalLayout() { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); - if(mContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ + if (mContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { layoutParams.bottomMargin = ViewUtil.getNavBarHeight(mContext); } @@ -109,7 +110,7 @@ public void filterList(CharSequence text) { @Override public void onFilterComplete(int count) { // show if there are results - if(mAdapter.getItemCount() > 0) + if (mAdapter.getItemCount() > 0) fadeIn(); else fadeOut(); @@ -121,7 +122,7 @@ public void onFilterComplete(int count) { * Fade in */ public void fadeIn() { - if(getVisibility() == VISIBLE) + if (getVisibility() == VISIBLE) return; // get visible window (keyboard shown) @@ -132,11 +133,12 @@ public void fadeIn() { int[] coord = new int[2]; mChipsInput.getLocationInWindow(coord); ViewGroup.MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams(); - layoutParams.topMargin = coord[1] + mChipsInput.getHeight(); - // height of the keyboard - layoutParams.bottomMargin = rootView.getHeight() - r.bottom; - setLayoutParams(layoutParams); - + if (layoutParams != null) { + layoutParams.topMargin = coord[1] + mChipsInput.getHeight(); + // height of the keyboard + layoutParams.bottomMargin = rootView.getHeight() - r.bottom; + setLayoutParams(layoutParams); + } AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(200); startAnimation(anim); @@ -147,7 +149,7 @@ public void fadeIn() { * Fade out */ public void fadeOut() { - if(getVisibility() == GONE) + if (getVisibility() == GONE) return; AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f); diff --git a/library/src/main/java/com/pchmn/materialchips/views/ScrollViewMaxHeight.java b/library/src/main/java/com/pchmn/materialchips/views/ScrollViewMaxHeight.java index db212ff6..09578fc9 100644 --- a/library/src/main/java/com/pchmn/materialchips/views/ScrollViewMaxHeight.java +++ b/library/src/main/java/com/pchmn/materialchips/views/ScrollViewMaxHeight.java @@ -28,8 +28,7 @@ public ScrollViewMaxHeight(Context context, AttributeSet attrs) { try { mMaxHeight = a.getDimensionPixelSize(R.styleable.ScrollViewMaxHeight_maxHeight, ViewUtil.dpToPx(300)); - } - finally { + } finally { a.recycle(); } } diff --git a/sample/build.gradle b/sample/build.gradle index 15b85c09..feef508f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,16 +1,15 @@ apply plugin: 'com.android.application' -apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.jakewharton.butterknife' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "26.0.2" defaultConfig { applicationId "com.pchmn.sample.materialchipsinput" minSdkVersion 15 - targetSdkVersion 25 - versionCode 9 - versionName "1.0.8" + targetSdkVersion 27 + versionCode 10 + versionName "1.1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -33,7 +32,7 @@ dependencies { compile project(path: ':library') // butter knife - compile 'com.android.support:appcompat-v7:25.3.0' + compile 'com.android.support:appcompat-v7:27.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'io.reactivex.rxjava2:rxjava:2.0.8' compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar' diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 15326c11..54ea9ef8 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.pchmn.sample.materialchipsinput"> + - + \ No newline at end of file diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java index 0ec3aa70..cd66d0f4 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java @@ -84,7 +84,6 @@ protected void onCreate(Bundle savedInstanceState) { // programmatically - Uri uri = null; ChipView chipView1 = new ChipView(this); chipView1.setLabel("Pritesh"); chipView1.setPadding(2,2,2,2); @@ -94,7 +93,6 @@ protected void onCreate(Bundle savedInstanceState) { chipView2.setLabel("Test 1"); chipView2.setChipBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent)); chipView2.setLabelColor(ContextCompat.getColor(this, R.color.colorPrimary)); - chipView2.setAvatarIcon(uri); chipView2.setDeleteIconColor(ContextCompat.getColor(this, R.color.colorPrimary)); mLayout.addView(chipView1); diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactChip.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactChip.java index 2706b54d..7a87320d 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactChip.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactChip.java @@ -9,11 +9,11 @@ public class ContactChip implements ChipInterface { private String id; - private Uri avatarUri; + private String avatarUri; private String name; private String phoneNumber; - public ContactChip(String id, Uri avatarUri, String name, String phoneNumber) { + public ContactChip(String id, String avatarUri, String name, String phoneNumber) { this.id = id; this.avatarUri = avatarUri; this.name = name; @@ -26,7 +26,7 @@ public Object getId() { } @Override - public Uri getAvatarUri() { + public String getAvatarUri() { return avatarUri; } diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java index 33c7adba..221de238 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java @@ -115,8 +115,7 @@ private void getContactList() { pCur.close(); } - - ContactChip contactChip = new ContactChip(id, avatarUri, name, phoneNumber); + ContactChip contactChip = new ContactChip(id, avatarUri == null ? null : avatarUri.toString(), name, phoneNumber); // add contact to the list mContactList.add(contactChip); }