This is not a duplicated question, I know that were some questions asked like mine, but I need help on how I can implement to my app.
I'm trying to make a android app that can capture the colors, but i've only discoverd how I can get the Hex value, but I really need the name of the color! please help, someone! Below it's the whole code but where it says
public static String makeHexString(int value) {
return "#" + Integer.toHexString(value).substring(2);}
this line here, Integer.toHexString How can I make it to get the color name instead hex value?
public class ColorItem implements Parcelable {
protected final long mId;
protected int mColor;
protected String mName;
protected final long mCreationTime;
protected transient String mHexString;
protected transient String mRgbString;
protected transient String mHsvString;
public ColorItem(long id, int color) {
mId = id;
mColor = color;
mCreationTime = System.currentTimeMillis();
}
private ColorItem(Parcel in) {
this.mId = in.readLong();
this.mColor = in.readInt();
this.mCreationTime = in.readLong();
this.mName = in.readString();
}
public ColorItem(int color) {
mId = mCreationTime = System.currentTimeMillis();
mColor = color;
}
public long getId() {
return mId;
}
public int getColor() {
return mColor;
}
public void setColor(int color) {
if (mColor != color) {
mColor = color;
mHexString = makeHexString(mColor);
mRgbString = makeRgbString(mColor);
mHsvString = makeHsvString(mColor);
}
}
public long getCreationTime() {
return mCreationTime;
}
public String getHexString() {
if (mHexString == null) {
mHexString = makeHexString(mColor);
}
return mHexString;
}
public String getRgbString() {
if (mRgbString == null) {
mRgbString = makeRgbString(mColor);
}
return mRgbString;
}
public String getHsvString() {
if (mHsvString == null) {
mHsvString = makeHsvString(mColor);
}
return mHsvString;
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
public static String makeHexString(int value) {
return "#" + Integer.toHexString(value).substring(2);
}
public static String makeRgbString(int value) {
return "rgb(" + Color.red(value) + ", " + Color.green(value) + ", " + Color.blue(value) + ")";
}
public static String makeHsvString(int value) {
float[] hsv = new float[3];
Color.colorToHSV(value, hsv);
return "hsv(" + (int) hsv[0] + "°, " + (int) (hsv[1] * 100) + "%, " + (int) (hsv[2] * 100) + "%)";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.mId);
dest.writeInt(this.mColor);
dest.writeLong(this.mCreationTime);
dest.writeString(this.mName);
}
public static final Creator<ColorItem> CREATOR = new Creator<ColorItem>() {
public ColorItem createFromParcel(Parcel source) {
return new ColorItem(source);
}
public ColorItem[] newArray(int size) {
return new ColorItem[size];
}
};
}