Skip to content

Commit

Permalink
Merge pull request #26 from shiraji/tag_padding
Browse files Browse the repository at this point in the history
[Proposal] Support tag's padding
  • Loading branch information
mabbas007 authored Dec 5, 2016
2 parents de12637 + 5882678 commit 86e8d4c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public class TagsEditText extends AutoCompleteTextView {
private static final String LEFT_DRAWABLE_RESOURCE = "leftDrawable";
private static final String RIGHT_DRAWABLE_RESOURCE = "rightDrawable";
private static final String DRAWABLE_PADDING = "drawablePadding";
private static final String TAGS_PADDING_LEFT = "tagsPaddingLeft";
private static final String TAGS_PADDING_RIGHT = "tagsPaddingRight";
private static final String TAGS_PADDING_TOP = "tagsPaddingTop";
private static final String TAGS_PADDING_BOTTOM = "tagsPaddingBottom";

private String mLastString = "";
private boolean mIsAfterTextWatcherEnabled = true;
Expand All @@ -81,6 +85,11 @@ public class TagsEditText extends AutoCompleteTextView {

private int mDrawablePadding;

private int mTagsPaddingLeft;
private int mTagsPaddingRight;
private int mTagsPaddingTop;
private int mTagsPaddingBottom;

private boolean mIsSpacesAllowedInTags = false;
private boolean mIsSetTextDisabled = false;

Expand Down Expand Up @@ -370,6 +379,10 @@ private void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRe
mTagsBackground = ContextCompat.getDrawable(context, R.drawable.oval);
mRightDrawable = ContextCompat.getDrawable(context, R.drawable.tag_close);
mDrawablePadding = ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsCloseImagePadding);
mTagsPaddingRight = ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding);
mTagsPaddingLeft = ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding);
mTagsPaddingTop = ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding);
mTagsPaddingBottom = ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding);
} else {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TagsEditText, defStyleAttr, defStyleRes);
try {
Expand All @@ -383,6 +396,14 @@ private void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRe
mLeftDrawable = typedArray.getDrawable(R.styleable.TagsEditText_tagsCloseImageLeft);
mDrawablePadding = typedArray.getDimensionPixelOffset(R.styleable.TagsEditText_tagsCloseImagePadding,
ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsCloseImagePadding));
mTagsPaddingRight = typedArray.getDimensionPixelSize(R.styleable.TagsEditText_tagsPaddingRight,
ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding));
mTagsPaddingLeft = typedArray.getDimensionPixelSize(R.styleable.TagsEditText_tagsPaddingLeft,
ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding));
mTagsPaddingTop = typedArray.getDimensionPixelSize(R.styleable.TagsEditText_tagsPaddingTop,
ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding));
mTagsPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.TagsEditText_tagsPaddingBottom,
ResourceUtils.getDimensionPixelSize(context, R.dimen.defaultTagsPadding));
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -596,6 +617,7 @@ private TextView createTextView(String text) {
textView.setText(text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTagsTextSize);
textView.setTextColor(mTagsTextColor);
textView.setPadding(mTagsPaddingLeft, mTagsPaddingTop, mTagsPaddingRight, mTagsPaddingBottom);

// check Android version for set background
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Expand Down
4 changes: 4 additions & 0 deletions TagsEditText/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<attr name="tagsCloseImageLeft" format="integer"/>
<attr name="tagsCloseImageRight" format="integer"/>
<attr name="tagsCloseImagePadding" format="dimension" />
<attr name="tagsPaddingLeft" format="dimension"/>
<attr name="tagsPaddingRight" format="dimension"/>
<attr name="tagsPaddingTop" format="dimension"/>
<attr name="tagsPaddingBottom" format="dimension"/>
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions TagsEditText/src/main/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<color name="defaultTagsTextColor">#FFFFFF</color>
<dimen name="defaultTagsTextSize">16sp</dimen>
<dimen name="defaultTagsCloseImagePadding">10dp</dimen>
<dimen name="defaultTagsPadding">0dp</dimen>
</resources>

0 comments on commit 86e8d4c

Please sign in to comment.