From 34074ffd8c27cc149fa64604e50e485ac0e27ee8 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 30 Dec 2013 23:52:54 -0800 Subject: [PATCH] Move labels into KnobView The main reason for these to be inside the KnobView is so that they can be part of the touch target for the knob. A more general approach would be to make the Knob a container that can contain TextView widgets, but this is simpler. --- android/res/layout/piano2.xml | 32 ++++--------------- android/res/values/attrs.xml | 1 + .../android/widgets/knob/KnobView.java | 19 +++++++++-- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/android/res/layout/piano2.xml b/android/res/layout/piano2.xml index f6febe5..b50502b 100644 --- a/android/res/layout/piano2.xml +++ b/android/res/layout/piano2.xml @@ -8,29 +8,6 @@ android:layout_height="fill_parent" android:stretchColumns="*" android:shrinkColumns="*"> - - - - - - - - + android:layout_margin="2dp" + app:label="@+string/cutoff" /> + android:layout_margin="2dp" + app:label="@+string/resonance"/> + android:layout_margin="2dp" + app:label="@+string/overdrive"/> diff --git a/android/res/values/attrs.xml b/android/res/values/attrs.xml index a7519d5..d87905c 100755 --- a/android/res/values/attrs.xml +++ b/android/res/values/attrs.xml @@ -7,6 +7,7 @@ + diff --git a/android/src/com/levien/synthesizer/android/widgets/knob/KnobView.java b/android/src/com/levien/synthesizer/android/widgets/knob/KnobView.java index 8b77308..8196452 100644 --- a/android/src/com/levien/synthesizer/android/widgets/knob/KnobView.java +++ b/android/src/com/levien/synthesizer/android/widgets/knob/KnobView.java @@ -49,6 +49,7 @@ public class KnobView extends View { knobValue_ = a.getFloat(R.styleable.KnobView_value, 0.5f); min_ = a.getFloat(R.styleable.KnobView_min, 0.0f); max_ = a.getFloat(R.styleable.KnobView_max, 1.0f); + label_ = a.getString(R.styleable.KnobView_label); a.recycle(); // Set up the drawing structures. @@ -61,7 +62,7 @@ public class KnobView extends View { rect_ = new Rect(); rectF_ = new RectF(); innerRectF_ = new RectF(); - textHeight_ = 18f * density; // probably should be set by XML parameter + textHeight_ = 16f * density; // probably should be set by XML parameter paint_.setTextSize(textHeight_); // The listener has to be set later. @@ -163,6 +164,12 @@ public class KnobView extends View { getDrawingRect(rect_); rectF_.set(rect_); + // Apply padding. + rectF_.left += getPaddingLeft(); + rectF_.right -= getPaddingRight(); + rectF_.top += getPaddingTop(); + rectF_.bottom -= getPaddingBottom(); + // Make it square. if (rectF_.height() > rectF_.width()) { float center = rectF_.centerY(); @@ -206,7 +213,7 @@ public class KnobView extends View { paint_.setStrokeWidth(strokeWidth_); canvas.drawCircle(rect_.exactCenterX(), rect_.exactCenterY(), - Math.min(rect_.width(), rect_.height()) * 0.45f - border, + rectF_.width() * 0.45f - border, paint_); // Draw text. @@ -219,8 +226,13 @@ public class KnobView extends View { paint_.setStyle(Style.FILL); canvas.drawText(knobValueString, rect_.centerX(), - rect_.top + 0.8f * textHeight_, + rectF_.top + 0.8f * textHeight_, paint_); + + if (label_ != null) { + paint_.setTypeface(Typeface.DEFAULT); + canvas.drawText(label_, rect_.centerX(), rectF_.bottom - 0.2f * textHeight_, paint_); + } } /** @@ -317,6 +329,7 @@ public class KnobView extends View { private final float startAngle_ = 36f; // relative to bottom private final float strokeWidth_; private float sensitivity_; + private String label_ = "labelg"; // State of drag gesture private float xyAtTouch_;