Optimizations for hex color view

This commit is contained in:
Moez Bhatti
2016-07-08 11:18:05 -10:00
parent b500228b66
commit c7dd045f79
2 changed files with 13 additions and 3 deletions
@@ -553,7 +553,10 @@ public class ThemeManager {
setActiveColor(color); setActiveColor(color);
String colorString = Integer.toHexString(color); String colorString = Integer.toHexString(color);
holder.mHex.setTextChangedListenerEnabled(false);
holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0)); holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0));
holder.mHex.setTextChangedListenerEnabled(true);
holder.mError.setVisibility(View.INVISIBLE);
} }
@Override @Override
@@ -606,7 +609,7 @@ public class ThemeManager {
return false; return false;
}); });
holder.mHex.setTextChangedListener(s -> { holder.mHex.setTextChangedListener(s -> {
try { if (s.length() == 6) {
int color = Color.parseColor("#" + s.toString()); int color = Color.parseColor("#" + s.toString());
holder.mError.setVisibility(View.INVISIBLE); holder.mError.setVisibility(View.INVISIBLE);
if (color != getColor()) { if (color != getColor()) {
@@ -614,7 +617,7 @@ public class ThemeManager {
holder.mGreen.setProgress(Color.green(color)); holder.mGreen.setProgress(Color.green(color));
holder.mBlue.setProgress(Color.blue(color)); holder.mBlue.setProgress(Color.blue(color));
} }
} catch (IllegalArgumentException e) { } else {
holder.mError.setVisibility(View.VISIBLE); holder.mError.setVisibility(View.VISIBLE);
} }
}); });
@@ -21,6 +21,7 @@ public class QKEditText extends android.widget.EditText {
} }
private Context mContext; private Context mContext;
private boolean mTextChangedListenerEnabled = true;
public QKEditText(Context context) { public QKEditText(Context context) {
super(context); super(context);
@@ -77,6 +78,10 @@ public class QKEditText extends android.widget.EditText {
super.setText(text, type); super.setText(text, type);
} }
public void setTextChangedListenerEnabled(boolean textChangedListenerEnabled) {
mTextChangedListenerEnabled = textChangedListenerEnabled;
}
public void setTextChangedListener(final TextChangedListener listener) { public void setTextChangedListener(final TextChangedListener listener) {
if (listener != null) { if (listener != null) {
addTextChangedListener(new TextWatcher() { addTextChangedListener(new TextWatcher() {
@@ -91,7 +96,9 @@ public class QKEditText extends android.widget.EditText {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
listener.onTextChanged(s); if (mTextChangedListenerEnabled) {
listener.onTextChanged(s);
}
} }
}); });
} }