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.
master
Raph Levien 11 years ago
parent facbb3cc94
commit 34074ffd8c
  1. 32
      android/res/layout/piano2.xml
  2. 1
      android/res/values/attrs.xml
  3. 19
      android/src/com/levien/synthesizer/android/widgets/knob/KnobView.java

@ -8,29 +8,6 @@
android:layout_height="fill_parent"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow>
<TextView
android:text="@string/cutoff"
android:id="@+id/cutoffLabel"
android:gravity="center_horizontal" />
<TextView
android:text="@string/resonance"
android:id="@+id/resonanceLabel"
android:gravity="center_horizontal" />
<TextView
android:text="@string/overdrive"
android:id="@+id/overdriveLabel"
android:gravity="center_horizontal" />
<TextView
android:text=""
android:gravity="center_horizontal" />
<TextView
android:text=""
android:gravity="center_horizontal" />
<TextView
android:text=""
android:gravity="center_horizontal" />
</TableRow>
<TableRow>
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/cutoffKnob"
@ -39,7 +16,8 @@
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:layout_margin="2dp" />
android:layout_margin="2dp"
app:label="@+string/cutoff" />
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/resonanceKnob"
app:value="0.0"
@ -47,7 +25,8 @@
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:layout_margin="2dp" />
android:layout_margin="2dp"
app:label="@+string/resonance"/>
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/overdriveKnob"
app:value="0.0"
@ -55,7 +34,8 @@
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:layout_margin="2dp" />
android:layout_margin="2dp"
app:label="@+string/overdrive"/>
<LinearLayout
android:orientation="vertical"
android:layout_span="3" >

@ -7,6 +7,7 @@
<attr name="value" format="float" />
<attr name="min" format="float" />
<attr name="max" format="float" />
<attr name="label" format="string" />
</declare-styleable>
<declare-styleable name="PianoView">
<attr name="octaves" format="integer" />

@ -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_;

Loading…
Cancel
Save