package org.odk.collect.android.adapters;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/*
 * Copyright (c) 2015 Diona Ltd.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Diona
 * ("Confidential Information"). You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license agreement you
 * entered into with Diona.
 */

/**
 * A row displaying a line size.
 */
public class DrawSizeRow extends AppCompatImageView {

  private Paint mPaint;

  public DrawSizeRow(Context context) {
    this(context, null);
  }

  public DrawSizeRow(final Context context, final AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public DrawSizeRow(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }

  private void init() {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.BLACK);
    mPaint.setStrokeWidth(4);
  }

  /**
   * @param width
   *     the width of the line drawn.
   */
  public void setStrokeWidth(final int width) {
    mPaint.setStrokeWidth(width);
    invalidate();
  }

  /**
   * @param color
   *     the color of the line drawn.
   */
  public void setPaintColor(final int color) {
    mPaint.setColor(color);
    invalidate();
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final int y = getHeight() / 2;
    canvas.drawLine(0, y, getWidth(), y, mPaint);
  }
}
