Example #1
0
 /** @param color color. */
 public void setColor(int color) {
   mColor = color;
   mThumb.setColor(color);
   setProgressDrawable(
       new CustomDrawable(
           (CustomDrawable) this.getProgressDrawable(),
           this,
           mThumb.getRadius(),
           mDots,
           color,
           mTextSize,
           mIsMultiline));
 }
Example #2
0
  /**
   * @param context context.
   * @param attrs attrs.
   */
  public ComboSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ComboSeekBar);

    mColor = a.getColor(R.styleable.ComboSeekBar_color, Color.WHITE);
    mTextSize = a.getDimensionPixelSize(R.styleable.ComboSeekBar_textSize, 5);
    mIsMultiline = a.getBoolean(R.styleable.ComboSeekBar_multiline, false);
    // do something with str

    a.recycle();
    mThumb = new CustomThumbDrawable(context, mColor);
    setThumb(mThumb);
    setProgressDrawable(
        new CustomDrawable(
            this.getProgressDrawable(),
            this,
            mThumb.getRadius(),
            mDots,
            mColor,
            mTextSize,
            mIsMultiline));

    // по умолчанию не равно 0 и это проблема
    setPadding(0, 0, 0, 0);
  }
Example #3
0
  @Override
  protected synchronized void onDraw(Canvas canvas) {
    if ((mThumb != null) && (mDots.size() > 1)) {
      if (isSelected) {
        for (Dot dot : mDots) {
          if (dot.isSelected) {
            Rect bounds = mThumb.copyBounds();
            bounds.right = dot.mX;
            bounds.left = dot.mX;
            mThumb.setBounds(bounds);
            break;
          }
        }
      } else {
        int intervalWidth = mDots.get(1).mX - mDots.get(0).mX;
        Rect bounds = mThumb.copyBounds();
        // find nearest dot
        if ((mDots.get(mDots.size() - 1).mX - bounds.centerX()) < 0) {
          bounds.right = mDots.get(mDots.size() - 1).mX;
          bounds.left = mDots.get(mDots.size() - 1).mX;
          mThumb.setBounds(bounds);

          for (Dot dot : mDots) {
            dot.isSelected = false;
          }
          mDots.get(mDots.size() - 1).isSelected = true;
          handleClick(mDots.get(mDots.size() - 1));
        } else {
          for (int i = 0; i < mDots.size(); i++) {
            if (Math.abs(mDots.get(i).mX - bounds.centerX()) <= (intervalWidth / 2)) {
              bounds.right = mDots.get(i).mX;
              bounds.left = mDots.get(i).mX;
              mThumb.setBounds(bounds);
              mDots.get(i).isSelected = true;
              handleClick(mDots.get(i));
            } else {
              mDots.get(i).isSelected = false;
            }
          }
        }
      }
    }
    super.onDraw(canvas);
  }
Example #4
0
  @Override
  protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    CustomDrawable d = (CustomDrawable) getProgressDrawable();

    int thumbHeight = mThumb == null ? 0 : mThumb.getIntrinsicHeight();
    int dw = 0;
    int dh = 0;
    if (d != null) {
      dw = d.getIntrinsicWidth();
      dh = Math.max(thumbHeight, d.getIntrinsicHeight());
    }

    dw += getPaddingLeft() + getPaddingRight();
    dh += getPaddingTop() + getPaddingBottom();

    setMeasuredDimension(resolveSize(dw, widthMeasureSpec), resolveSize(dh, heightMeasureSpec));
  }
Example #5
0
 /** dot coordinates. */
 private void initDotsCoordinates() {
   float intervalWidth = (getWidth() - (mThumb.getRadius() * 2)) / (mDots.size() - 1);
   for (Dot dot : mDots) {
     dot.mX = (int) (mThumb.getRadius() + intervalWidth * (dot.id));
   }
 }