From 647be33b48707270fa3729826a1eaeb83b12db38 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 22 Mar 2020 01:55:53 +0100 Subject: [PATCH] Cleanup in ColorPicker code Also remove trackball event support from ColorPickerView. --- .../colorpicker/ColorPickerView.java | 86 ++----------------- 1 file changed, 7 insertions(+), 79 deletions(-) diff --git a/DroidFishApp/src/main/java/net/margaritov/preference/colorpicker/ColorPickerView.java b/DroidFishApp/src/main/java/net/margaritov/preference/colorpicker/ColorPickerView.java index 5f4b30d..cd495cf 100644 --- a/DroidFishApp/src/main/java/net/margaritov/preference/colorpicker/ColorPickerView.java +++ b/DroidFishApp/src/main/java/net/margaritov/preference/colorpicker/ColorPickerView.java @@ -108,12 +108,6 @@ public class ColorPickerView extends View { private int mBorderColor = 0xff6E6E6E; private boolean mShowAlphaPanel = false; - /* - * To remember which panel that has the "focus" when - * processing hardware button data. - */ - private int mLastTouchedPanel = PANEL_SAT_VAL; - /** * Offset from the edge we must have or else * the finger tracker will get clipped when @@ -270,7 +264,8 @@ public class ColorPickerView extends View { } if (mHueShader == null) { - mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP); + mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, + buildHueColorArray(), null, TileMode.CLAMP); mHuePaint.setShader(mHueShader); } @@ -425,70 +420,6 @@ public class ColorPickerView extends View { return 0xff - (x * 0xff / width); } - @Override - public boolean onTrackballEvent(MotionEvent event) { - float x = event.getX(); - float y = event.getY(); - - boolean update = false; - - if (event.getAction() == MotionEvent.ACTION_MOVE) { - switch (mLastTouchedPanel) { - case PANEL_SAT_VAL: - float sat, val; - sat = mSat + x/50f; - val = mVal - y/50f; - if (sat < 0f) - sat = 0f; - else if (sat > 1f) - sat = 1f; - if (val < 0f) - val = 0f; - else if (val > 1f) - val = 1f; - mSat = sat; - mVal = val; - update = true; - break; - - case PANEL_HUE: - float hue = mHue - y * 10f; - if (hue < 0f) - hue = 0f; - else if (hue > 360f) - hue = 360f; - mHue = hue; - update = true; - break; - - case PANEL_ALPHA: - if (!mShowAlphaPanel || mAlphaRect == null) { - update = false; - } else { - int alpha = (int) (mAlpha - x*10); - if (alpha < 0) - alpha = 0; - else if (alpha > 0xff) - alpha = 0xff; - mAlpha = alpha; - update = true; - } - break; - } - } - - if (update) { - if (mListener != null) { - mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSat, mVal})); - } - - invalidate(); - return true; - } - - return super.onTrackballEvent(event); - } - @Override public boolean onTouchEvent(MotionEvent event) { boolean update = false; @@ -525,17 +456,14 @@ public class ColorPickerView extends View { int startY = mStartTouchPoint.y; if (mHueRect.contains(startX, startY)) { - mLastTouchedPanel = PANEL_HUE; mHue = pointToHue(event.getY()); update = true; } else if (mSatValRect.contains(startX, startY)) { - mLastTouchedPanel = PANEL_SAT_VAL; float[] result = pointToSatVal(event.getX(), event.getY()); mSat = result[0]; mVal = result[1]; update = true; } else if (mAlphaRect != null && mAlphaRect.contains(startX, startY)) { - mLastTouchedPanel = PANEL_ALPHA; mAlpha = pointToAlpha((int)event.getX()); update = true; } @@ -584,7 +512,7 @@ public class ColorPickerView extends View { if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) { return size; } else { // (mode == MeasureSpec.UNSPECIFIED) - return getPrefferedWidth(); + return getPreferredWidth(); } } @@ -592,18 +520,18 @@ public class ColorPickerView extends View { if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) { return size; } else { // (mode == MeasureSpec.UNSPECIFIED) - return getPrefferedHeight(); + return getPreferredHeight(); } } - private int getPrefferedWidth() { - int width = getPrefferedHeight(); + private int getPreferredWidth() { + int width = getPreferredHeight(); if (mShowAlphaPanel) width -= (PANEL_SPACING + ALPHA_PANEL_HEIGHT); return (int) (width + HUE_PANEL_WIDTH + PANEL_SPACING); } - private int getPrefferedHeight() { + private int getPreferredHeight() { int height = (int)(200 * mDensity); if (mShowAlphaPanel) height += PANEL_SPACING + ALPHA_PANEL_HEIGHT;