Skip to content

Commit

Permalink
[F] selected tag color does not show up when Tag background is black
Browse files Browse the repository at this point in the history
  • Loading branch information
anhtuan23 committed Sep 3, 2018
1 parent 0eb6a88 commit fbbda6c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion androidtagview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 21
targetSdkVersion 27
versionCode 114
versionName "1.1.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private void initTagView(TagView tagView, int position) {
int[] colors;
if (mColorArrayList != null && mColorArrayList.size() > 0) {
if (mColorArrayList.size() == mTags.size() &&
mColorArrayList.get(position).length >= 3) {
mColorArrayList.get(position).length >= 4) {
colors = mColorArrayList.get(position);
} else {
throw new RuntimeException("Illegal color list!");
Expand All @@ -559,10 +559,9 @@ private void initTagView(TagView tagView, int position) {
}

tagView.setTagBackgroundColor(colors[0]);
//TODO make selectedBackgroundColorSelectable configurable
tagView.setTagSelectedBackgroundColor(Utils.manipulateColorBrigthness(colors[0], 0.7f));
tagView.setTagBorderColor(colors[1]);
tagView.setTagTextColor(colors[2]);
tagView.setTagSelectedBackgroundColor(colors[3]);
tagView.setTagMaxLength(mTagMaxLength);
tagView.setTextDirection(mTagTextDirection);
tagView.setTypeface(mTagTypeface);
Expand Down
29 changes: 19 additions & 10 deletions androidtagview/src/main/java/co/lujun/androidtagview/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,29 @@ public static float sp2px(Context context, float sp) {
}

/**
*Manipulate Birghtness of color
*
* @param color in int, brightness factor
* If the color is Dark -> make it lighter and vice versa
*
* @param color in int,
* @param factor 0.0 < factor < 1.0
* @return int
*/
public static int manipulateColorBrigthness(int color, float factor) {
public static int manipulateColorBrightness(int color, float factor) {
int a = Color.alpha(color);
int r = Math.round(Color.red(color) * factor);
int g = Math.round(Color.green(color) * factor);
int b = Math.round(Color.blue(color) * factor);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
// if (r + b + g < 128 * 3) factor = 1 / factor;// check if the color is bright or dark
// r = Math.round(r * factor);
// b = Math.round(b * factor);
// g = Math.round(g * factor);
if (r > 127) r = 255 - Math.round((255 - r) * factor);
if (g > 127) g = 255 - Math.round((255 - g) * factor);
if (b > 127) b = 255 - Math.round((255 - b) * factor);

return Color.argb(a,
Math.min(r,255),
Math.min(g,255),
Math.min(b,255));
Math.min(r, 255),
Math.min(g, 255),
Math.min(b, 255)
);
}
}
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "co.lujun.sample"
minSdkVersion 14
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
Expand Down

0 comments on commit fbbda6c

Please sign in to comment.