예제 #1
0
 public void setVolume(int volume) {
   mVolume = Math.max(0, Math.min(mVolumeMax, volume));
   final Rect r = mBar.getBounds();
   if (mVertical) {
     mCover.setBounds(
         r.left + mVolume * (r.right - r.left) / mVolumeMax, r.top, r.right, r.bottom);
   } else {
     mCover.setBounds(r.left, r.top, r.right, r.top + mVolume * (r.bottom - r.top) / mVolumeMax);
   }
   this.invalidate();
 }
예제 #2
0
 private void drawKeyboardBackground(Canvas canvas, String colour) {
   ShapeDrawable background = new ShapeDrawable(new RectShape());
   background.getPaint().setColor(Color.parseColor(colour));
   background.setBounds(
       (int) getX(), (int) getY(), (int) getX() + getWidth(), (int) getY() + getHeight());
   background.draw(canvas);
 }
예제 #3
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int right = r - l;
    int height = b - t;

    for (int i = 0; i < getChildCount(); i++) {
      // Put all the children outside of the view, then use setPosition
      // to put the ones that need to be seen back. This will be where
      // we set the top and bottom of every view though.
      TextView view = (TextView) getChildAt(i);
      int viewWidth = view.getMeasuredWidth();
      int viewHeight = view.getMeasuredHeight();
      int textTop =
          (height / 2) - (viewHeight - ((view.getLineHeight() * view.getLineCount()) / 2));
      view.layout(right, textTop, right + viewWidth, textTop + viewHeight);
    }
    setPosition(mDisplayedPage, 0, 0);

    mShadow.setBounds(0, 0, right, mShadowHeight);
    mBottomBar.setBounds(0, height - mBottomBarHeight, right, height);

    // Set up the fading edges
    mFadingEdgeLeft.setBounds(0, mShadowHeight, mFadingEdgeLength, height - mBottomBarHeight);
    mFadingEdgeRight.setBounds(
        right - mFadingEdgeLength, mShadowHeight, right, height - mBottomBarHeight);
  }
  @Override
  protected void onDraw(Canvas canvas) {

    canvas.save();
    // 去除状态栏高度偏差
    canvas.translate(0, -mStatusBarHeight);

    if (!isDisappear) {
      if (!isOutOfRange) {
        // 画两圆连接处
        ShapeDrawable drawGooView = drawGooView();
        drawGooView.setBounds(rect);
        drawGooView.draw(canvas);

        // 画固定圆
        canvas.drawCircle(mStickCenter.x, mStickCenter.y, stickCircleTempRadius, mPaintRed);
      }
      // 画拖拽圆
      canvas.drawCircle(mDragCenter.x, mDragCenter.y, dragCircleRadius, mPaintRed);
      // 画数字
      canvas.drawText(text, mDragCenter.x, mDragCenter.y + dragCircleRadius / 2f, mTextPaint);
    }

    canvas.restore();
  }
예제 #5
0
  /**
   * Generates bitmap used for drawing button.
   *
   * @param radius Radius of button in pixels.
   */
  @Override
  void generateBitmap() {
    super.generateBitmap();
    // Size and shape
    buttonShape.setShape(new OvalShape());
    buttonShape.setBounds(
        new Rect(PADDING, PADDING, (int) radius * 2 - PADDING, (int) radius * 2 - PADDING));

    // Create button bitmap and render shape
    buttonBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444);
    Canvas handleCanvas = new Canvas(buttonBitmap);
    buttonShape.getPaint().set(parent.fillPaint);
    buttonShape.draw(handleCanvas);

    // Set text style
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setColor(Color.BLACK);
    // Set size (one character has a standard design, more has dynamic size)
    if (label.length() == 1) textPaint.setTextSize(radius);
    else textPaint.setTextSize(radius / label.length() * 2.5f);

    // Set paint to clear text from button
    textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    // Render the button
    handleCanvas.drawText(label, radius, radius + (textPaint.getTextSize() * .33333f), textPaint);
  }
  public DrawableLayeredButton(Context context, int topLayer, boolean hasBorder) {
    Drawable topLayerDrawable = context.getResources().getDrawable(topLayer);
    Drawable greenButtonDrawable = context.getResources().getDrawable(mGreenButtonResource);

    InsetDrawable topLayerInset = new InsetDrawable(topLayerDrawable, Utilities.convertToPx(8));
    InsetDrawable greenButtonInset =
        new InsetDrawable(greenButtonDrawable, Utilities.convertToPx(5));

    int width = Utilities.convertToPx(40);
    int height = Utilities.convertToPx(40);

    ShapeDrawable border = new ShapeDrawable(new OvalShape());
    border.getPaint().setColor(0xffabab25);
    border.setBounds(0, 0, width, height);

    Drawable[] nonActivatedlayers = new Drawable[2];
    nonActivatedlayers[0] = greenButtonInset;
    nonActivatedlayers[1] = topLayerInset;

    LayerDrawable nonActivatedLayer = new LayerDrawable(nonActivatedlayers);

    Drawable[] activatedlayers = new Drawable[3];
    activatedlayers[0] = border;
    activatedlayers[1] = greenButtonInset;
    activatedlayers[2] = topLayerInset;

    LayerDrawable activatedLayer = new LayerDrawable(activatedlayers);

    mDrawable = new StateListDrawable();
    if (hasBorder) {
      mDrawable.addState(new int[] {android.R.attr.state_checked}, activatedLayer);
    }

    mDrawable.addState(new int[] {}, nonActivatedLayer);
  }
예제 #7
0
 private void updateControllerPosition() {
   mController.setBounds(
       mControllerX,
       mControllerY,
       mControllerX + mControllerWidth,
       mControllerY + mControllerHeight);
 }
예제 #8
0
 public VistaAMedida(Context contexto) {
   super(contexto);
   int x = 10, y = 10;
   int ancho = 300, alto = 50;
   miDrawable = new ShapeDrawable(new OvalShape());
   miDrawable.getPaint().setColor(0xff0000ff);
   miDrawable.setBounds(x, y, x + ancho, y + alto);
 }
예제 #9
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    final Rect r = mBar.getBounds();
    final int newX = (int) event.getX();
    final int newY = (int) event.getY();
    final int coverBottom = Math.min(r.bottom, Math.max(r.top, newY));
    final int coverRight = Math.min(r.right, Math.max(r.left, newX));
    final int action = event.getAction();

    // begin of touch event, check if touch was in range
    if (MotionEvent.ACTION_DOWN == action) {
      mEmbraceTouch = (r.left <= newX && newX <= r.right);
    }

    // we can ignore all further touch events
    if (!mEmbraceTouch) {
      return false;
    }

    // check for end of touch gesture
    if (MotionEvent.ACTION_UP == action) {
      mEmbraceTouch = false;
      if (null != mOnVolumeChangedListener) {
        if (mVertical) {
          mVolume = mVolumeMax * (coverRight - r.left) / (r.right - r.left);
          mOnVolumeChangedListener.onVolumeChanged(mVolume);
        } else {
          mVolume = mVolumeMax - mVolumeMax * (coverBottom - r.top) / (r.bottom - r.top);
          mOnVolumeChangedListener.onVolumeChanged(mVolume);
        }
      }
    }

    // we moved the selection -> repaint
    if (mVertical) {
      mCover.setBounds(coverRight, r.top, r.right, r.bottom);
    } else {
      mCover.setBounds(r.left, r.top, r.right, coverBottom);
    }
    this.invalidate();
    return true;
  }
예제 #10
0
    private void setFakeImage(InputStream input) {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeStream(input, null, options);

      int[] sizes = calculateSize(options.outWidth, options.outHeight);

      ShapeDrawable draw = new ShapeDrawable(new RectShape());
      draw.setBounds(0, 0, sizes[0], sizes[1]);

      setImageSpan(builder, draw, start, end);
    }
예제 #11
0
  public PuzzleView(Context context) {
    super(context);

    mDrawable = new ShapeDrawable(new OvalShape());
    int x = 10;
    int y = 10;
    int width = 300;
    int height = 50;

    mDrawable.getPaint().setColor(0xff74AC23);
    mDrawable.setBounds(x, y, x + width, y + height);
  }
예제 #12
0
 private ShapeDrawable makeShapeDrawable(int x, int y) {
   int maxWidth = getWidth() / 10;
   int maxHeight = getHeight() / 10;
   Shape shape;
   if (Math.random() < 0.5) {
     shape = new OvalShape();
   } else {
     shape = new RectShape();
   }
   ShapeDrawable shapeD = new ShapeDrawable(shape);
   int width = RandomUtils.randomInt(maxWidth) + 5;
   int height = RandomUtils.randomInt(maxHeight) + 5;
   shapeD.setBounds(x - width / 2, y - height / 2, x + width / 2, y + height / 2);
   shapeD.getPaint().setColor(RandomUtils.randomElement(mColors));
   return (shapeD);
 }
예제 #13
0
  public static Bitmap getTransparentBitmap(View parent) {

    // create a bitmap
    if (parent.getWidth() == 0 || parent.getHeight() == 0) {
      return null;
    }
    int width = parent.getWidth();
    int height = parent.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    shapeDrawable.setAlpha(180);
    shapeDrawable.getPaint().setColor(0x66000000);
    shapeDrawable.setBounds(0, 0, width, height);
    shapeDrawable.draw(canvas);
    return bitmap;
  }
예제 #14
0
  public void draw(Canvas canvas, Context context) {
    for (MapCell cell : mMapCells) {
      ShapeDrawable cellShape = new ShapeDrawable(new RectShape());
      Rect cellBounds = cell.getBounds();
      cellShape.setBounds(
          cellBounds.left + mOriginX,
          cellBounds.top + mOriginY,
          cellBounds.right + mOriginX,
          cellBounds.bottom + mOriginY);
      cellShape.getPaint().setColor(ContextCompat.getColor(context, R.color.colorDarkerForeground));
      cellShape.draw(canvas);

      Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      textPaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
      textPaint.setTextSize((float) (14 * 3.5));
      canvas.drawText(
          cell.getName(),
          cellBounds.centerX() + mOriginX,
          cellBounds.centerY() + mOriginY,
          textPaint);
    }
  }
예제 #15
0
  public void setPosition(int position, float positionOffset, int positionOffsetPixels) {
    mTouchZonesAccurate = false;
    int width = getWidth();
    int center = width / 2;

    // Move the view at position. This will be the label for the left
    // of the two fragments that may be on the screen
    if (position >= 0 && position < getChildCount()) {
      TextView view = (TextView) getChildAt(position);
      int viewWidth = view.getWidth();
      int leftMin = 0;
      if (position + 1 < getChildCount()) {
        int nextViewWidth = getChildAt(position + 1).getWidth();
        leftMin = Math.min(0, center - (nextViewWidth / 2) - mPaddingPush - viewWidth);
      }
      int leftMax = center - (viewWidth / 2);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mInactiveTextColor.red, mActiveTextColor.red),
              map(positionOffset, 1, 0, mInactiveTextColor.green, mActiveTextColor.green),
              map(positionOffset, 1, 0, mInactiveTextColor.blue, mActiveTextColor.blue)));
    }

    // Move the view at position + 1. This will be the label for the
    // right of the two fragments that may be visible on screen
    if ((position + 1) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 1);
      int viewWidth = view.getWidth();
      int prevViewWidth = getChildAt(position).getWidth();
      int leftMin = center - (viewWidth / 2);
      int leftMax = Math.max(width - viewWidth, center + (prevViewWidth / 2) + mPaddingPush);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mActiveTextColor.red, mInactiveTextColor.red),
              map(positionOffset, 1, 0, mActiveTextColor.green, mInactiveTextColor.green),
              map(positionOffset, 1, 0, mActiveTextColor.blue, mInactiveTextColor.blue)));
    }

    // Move the view at position - 1. This will be the label for the
    // fragment that is off the screen to the left, if it exists
    if (position > 0) {
      TextView view = (TextView) getChildAt(position - 1);
      int plusOneLeft = getChildAt(position).getLeft();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (plusOneLeft < newLeft + viewWidth + mPaddingPush || newLeft < 0) {
        newLeft = Math.min(0, plusOneLeft - viewWidth - mPaddingPush);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 1, 0, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Move the view at position + 2. This will be the label for the
    // fragment that is off the screen to the right, if it exists
    if ((position + 2) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 2);
      int minusOneRight = getChildAt(position + 1).getRight();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (minusOneRight > (newLeft - mPaddingPush) || newLeft + viewWidth > width) {
        newLeft = Math.max(minusOneRight + mPaddingPush, width - viewWidth);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 0, 1, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Draw the tab under the active or oncoming TextView based on the
    // positionOffset
    View view = getChildAt(positionOffset < 0.5f ? position : position + 1);
    int viewLeft = view.getLeft();
    int viewRight = view.getRight();
    float percent = (Math.abs(positionOffset - 0.5f) / 0.5f);
    int tabHeight = (int) (mTabHeight * percent);
    int alpha = (int) (255 * percent);
    mTabDrawable.setBounds(
        viewLeft - mTabPadding, getHeight() - tabHeight, viewRight + mTabPadding, getHeight());
    mTabDrawable.setAlpha(alpha);
  }
예제 #16
0
  public void OnSepsButtonClick(final View v) {
    if (isProofing()) {

      //  get the current page
      final int currentPage = mDocView.getDisplayedViewIndex();

      //  buid a popup menu based on the given separations
      final PopupMenu menu = new PopupMenu(this, v);

      //  This makes the popup menu display icons, which by default it does not do.
      //  I worry that this relies on the internals of PopupMenu, which could change.
      try {
        Field[] fields = menu.getClass().getDeclaredFields();
        for (Field field : fields) {
          if ("mPopup".equals(field.getName())) {
            field.setAccessible(true);
            Object menuPopupHelper = field.get(menu);
            Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
            Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
            setForceIcons.invoke(menuPopupHelper, true);
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      //  get the maximum number of seps on any page.
      //  We use this to dimension an array further down
      int maxSeps = 0;
      int numPages = core.countPages();
      for (int page = 0; page < numPages; page++) {
        int numSeps = core.getNumSepsOnPage(page);
        if (numSeps > maxSeps) maxSeps = numSeps;
      }

      //  if this is the first time, create the "enabled" array
      if (mSepEnabled == null) {
        mSepEnabled = new boolean[numPages][maxSeps];
        for (int page = 0; page < numPages; page++) {
          for (int i = 0; i < maxSeps; i++) mSepEnabled[page][i] = true;
        }
      }

      //  count the seps on this page
      int numSeps = core.getNumSepsOnPage(currentPage);

      //  for each sep,
      for (int i = 0; i < numSeps; i++) {

        //				//  Robin use this to skip separations
        //				if (i==12)
        //					break;

        //  get the name
        Separation sep = core.getSep(currentPage, i);
        String name = sep.name;

        //  make a checkable menu item with that name
        //  and the separation index as the id
        MenuItem item = menu.getMenu().add(0, i, 0, name + "    ");
        item.setCheckable(true);

        //  set an icon that's the right color
        int iconSize = 48;
        int alpha = (sep.rgba >> 24) & 0xFF;
        int red = (sep.rgba >> 16) & 0xFF;
        int green = (sep.rgba >> 8) & 0xFF;
        int blue = (sep.rgba >> 0) & 0xFF;
        int color = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

        ShapeDrawable swatch = new ShapeDrawable(new RectShape());
        swatch.setIntrinsicHeight(iconSize);
        swatch.setIntrinsicWidth(iconSize);
        swatch.setBounds(new Rect(0, 0, iconSize, iconSize));
        swatch.getPaint().setColor(color);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        item.setIcon(swatch);

        //  check it (or not)
        item.setChecked(mSepEnabled[currentPage][i]);

        //  establishing a menu item listener
        item.setOnMenuItemClickListener(
            new OnMenuItemClickListener() {
              @Override
              public boolean onMenuItemClick(MenuItem item) {
                //  someone tapped a menu item.  get the ID
                int sep = item.getItemId();

                //  toggle the sep
                mSepEnabled[currentPage][sep] = !mSepEnabled[currentPage][sep];
                item.setChecked(mSepEnabled[currentPage][sep]);
                core.controlSepOnPage(currentPage, sep, !mSepEnabled[currentPage][sep]);

                //  prevent the menu from being dismissed by these items
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
                item.setActionView(new View(v.getContext()));
                item.setOnActionExpandListener(
                    new MenuItem.OnActionExpandListener() {
                      @Override
                      public boolean onMenuItemActionExpand(MenuItem item) {
                        return false;
                      }

                      @Override
                      public boolean onMenuItemActionCollapse(MenuItem item) {
                        return false;
                      }
                    });
                return false;
              }
            });

        //  tell core to enable or disable each sep as appropriate
        //  but don't refresh the page yet.
        core.controlSepOnPage(currentPage, i, !mSepEnabled[currentPage][i]);
      }

      //  add one for done
      MenuItem itemDone = menu.getMenu().add(0, 0, 0, "Done");
      itemDone.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              //  refresh the view
              mDocView.refresh(false);
              return true;
            }
          });

      //  show the menu
      menu.show();
    }
  }
예제 #17
0
  /** 绘画 */
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Log.v(TAG, "onDraw()");

    vWidth = getWidth();
    vHeight = getHeight();
    // Log.v(TAG, vWidth + "--" + vHeight);
    // 中心
    vLenght = vWidth / 2;
    // 弧度
    double randian30 = 30 * Math.PI / 180; // Math.PI 圆周长和直径比值
    a = (float) (vLenght * Math.sin(randian30));
    b = (float) (vLenght * Math.cos(randian30));
    c = (vHeight - 2 * b) / 2;

    // 画笔初始化
    if (paint == null) {
      paint = new Paint();
      // 去锯齿
      paint.setAntiAlias(true);
      paint.setStyle(Style.FILL);
      paint.setColor(backColor);
      paint.setAlpha(100);
    } else {
      paint.setStyle(Style.FILL);
      paint.setColor(backColor);
      paint.setAlpha(100);
    }

    if (paint1 == null) {
      paint1 = new Paint();
      // 去锯齿
      paint1.setAntiAlias(true);
      // 重设画笔颜色
      paint1.setColor(textColor);
      // 根据视图大小自动控制字体大小
      if (textSize == -1) {
        if (src == null) {
          textSize = vWidth >= vHeight ? vHeight - 120 : vWidth - 120;
          if (textSize < 5) {
            textSize = 20;
          }
        } else {
          textSize = 24;
        }
      }
      paint1.setTextSize(textSize);
      // 画笔水平居中
      paint1.setTextAlign(Align.CENTER);
    }
    // 画六边形
    Path path = new Path();
    path.moveTo(vWidth, vHeight / 2);
    path.lineTo(vWidth - a, vHeight - c);
    path.lineTo(vWidth - a - vLenght, vHeight - c);
    path.lineTo(0, vHeight / 2);
    path.lineTo(a, c);
    path.lineTo(vWidth - a, c);
    path.close();
    // 画图形
    canvas.drawPath(path, paint);

    // 画图片
    if (src != null) {
      // paint.setAlpha(255);
      // 从Drawable中获取Bitmap
      BitmapDrawable bitmapD = (BitmapDrawable) src;
      Bitmap bitmap = bitmapD.getBitmap();
      // 画背景图片,矩阵
      // Matrix matrix = new Matrix();
      // 转换矩阵,定位xy
      // matrix.postTranslate(vWidth / 2 - bitmap.getWidth() / 2, vHeight
      // / 2 - bitmap.getHeight() / 2);

      // 生成正六边形
      mDrawable = new ShapeDrawable(new PathShape(path, vWidth, vHeight));
      Shader aShader =
          new BitmapShader(
              zoomBitmap(bitmap, vWidth, vHeight), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

      mDrawable.getPaint().setShader(aShader); // 填充位图
      mDrawable.setBounds(0, 0, vWidth, vHeight); // 设置边界尺寸
      mDrawable.draw(canvas);

      // 绘制图片
      // canvas.drawBitmap(bitmap, matrix, paint);
    }

    if (text != null) {
      // 计算文字高度,处理垂直居中
      FontMetrics fontMetrics = paint1.getFontMetrics();
      // 计算文字高度
      float fontHeight = fontMetrics.bottom - fontMetrics.top;
      // 画字体
      if (src != null) { // 如果有图片文字在底部
        // Log.v(TAG, "src not null!");
        canvas.drawText(text, vWidth / 2, 2 * b + c - 3, paint1);
      } else { // 没有图片时文字居于视图中央
        float textBaseY = vHeight - (vHeight - fontHeight) / 2 - fontMetrics.bottom;
        canvas.drawText(text, vWidth / 2, textBaseY, paint1);
      }
    }
    // 六边形顶点位置
    if (list == null) {
      list = new ArrayList<PointF>();
    } else {
      list.clear();
    }
    PointF pf = new PointF();
    pf.set(vWidth, vHeight / 2);
    list.add(pf);
    PointF pf1 = new PointF();
    pf1.set(vWidth - a, vHeight - c);
    list.add(pf1);
    PointF pf2 = new PointF();
    pf2.set(vWidth - a - vLenght, vHeight - c);
    list.add(pf2);
    PointF pf3 = new PointF();
    pf3.set(0, vHeight / 2);
    list.add(pf3);
    PointF pf4 = new PointF();
    pf4.set(a, c);
    list.add(pf4);
    PointF pf5 = new PointF();
    pf5.set(vWidth - a, c);
    list.add(pf5);

    lasso = LassoUtils.getInstance();
    lasso.setLassoList(list);

    if (pf != null) {
      pf = null;
      pf1 = null;
      pf2 = null;
      pf3 = null;
      pf4 = null;
      pf5 = null;
    }
  }
예제 #18
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    final int padding = (mVertical ? h : w) / 8;
    final int innerLeft = padding;
    final int innerTop = padding;
    final int innerRight = w - innerLeft;
    final int innerBottom = h - innerTop;
    final int innerWidth = w - 2 * padding;
    final int innerHeight = h - 2 * padding;
    final int outerLeft = 0;
    final int outerTop = 0;
    final int outerRight = w;
    final int outerBottom = h;

    mBar.setBounds(innerLeft, innerTop, innerRight, innerBottom);
    if (mVertical) {
      final int left = innerLeft + (mVolume * (innerRight - innerLeft) / 100);
      mCover.setBounds(left, innerTop, innerRight, innerBottom);
    } else {
      final int bottom = innerBottom - (mVolume * (innerBottom - innerTop) / 100);
      mCover.setBounds(innerLeft, innerTop, innerRight, bottom);
    }

    if (mVertical) {
      Shader barShader =
          new LinearGradient(
              0,
              innerBottom - innerTop,
              w,
              innerBottom - innerTop,
              Color.BLACK,
              mColor,
              Shader.TileMode.REPEAT);
      mBar.getPaint().setShader(barShader);

      Shader frameShader =
          new LinearGradient(
              0, 0, innerHeight, 0, Color.GRAY, Color.DKGRAY, Shader.TileMode.MIRROR);
      mFramePaint.setShader(frameShader);

      mFramePath.reset();
      mFramePath.moveTo(innerRight, h / 2 + padding);
      mFramePath.lineTo(outerRight, h / 2);
      mFramePath.lineTo(outerRight, outerTop);
      mFramePath.lineTo(outerLeft, outerTop);
      mFramePath.lineTo(outerLeft, outerBottom);
      mFramePath.lineTo(outerRight, outerBottom);
      mFramePath.lineTo(outerRight, h / 2);
      mFramePath.lineTo(innerRight, h / 2 - padding);
      mFramePath.lineTo(innerRight, innerBottom);
      mFramePath.lineTo(innerLeft, h / 2 + padding);
      mFramePath.lineTo(innerLeft, h / 2 - padding);
      mFramePath.lineTo(innerRight, innerTop);
      mFramePath.close();
    } else {
      Shader barShader =
          new LinearGradient(
              innerRight - innerLeft,
              0,
              innerRight - innerLeft,
              h,
              mColor,
              Color.BLACK,
              Shader.TileMode.REPEAT);
      mBar.getPaint().setShader(barShader);

      Shader frameShader =
          new LinearGradient(0, 0, innerWidth, 0, Color.GRAY, Color.DKGRAY, Shader.TileMode.MIRROR);
      mFramePaint.setShader(frameShader);

      mFramePath.reset();
      mFramePath.moveTo(w / 2 + padding, innerTop);
      mFramePath.lineTo(w / 2, outerTop);
      mFramePath.lineTo(outerLeft, outerTop);
      mFramePath.lineTo(outerLeft, outerBottom);
      mFramePath.lineTo(outerRight, outerBottom);
      mFramePath.lineTo(outerRight, outerTop);
      mFramePath.lineTo(w / 2, outerTop);
      mFramePath.lineTo(w / 2 - padding, innerTop);
      mFramePath.lineTo(innerRight, innerTop);
      mFramePath.lineTo(w / 2 + padding, innerBottom);
      mFramePath.lineTo(w / 2 - padding, innerBottom);
      mFramePath.lineTo(innerLeft, innerTop);
      mFramePath.close();
    }
  }
예제 #19
0
  public void draw(Canvas canvas) {
    // This current version draws will draw the icon, and will draw
    // a colored rectangle around the person's icon if selected

    super.onDraw(canvas);
    //  Log.v("UserView", "UserView's onDraw()");
    int b = Values.iconBorderPadding;
    int namebox = Values.iconTextH; // the namebox height
    if (isSelected) {
      RectShape rect2 = new RectShape();
      ShapeDrawable s = new ShapeDrawable(rect2);
      s.getPaint().setColor(Color.YELLOW);
      s.setBounds(
          x - b - Values.selectedBorder,
          y - b - Values.selectedBorder,
          x + image.getWidth() + 2 * Values.selectedBorder + b,
          y + image.getHeight() + 2 * Values.selectedBorder + b + namebox);
      s.draw(canvas);
    }

    /*if(nameBoxImage!=null){
        canvas.drawBitmap(nameBoxImage, x, y + Values.userIconH - Values.iconTextH, null);
        canvas.drawText(person.getUsername(), 0, Math.min(11,(person.getUsername()).length()), x + Values.iconTextPadding,
            y + Values.userIconH - Values.iconTextPadding, paint);
    }*/
    // Crystal

    if (person != null) {
      // Crystal
      //  Log.v(LOG_TAG, "FINAL!");
      RectShape rect1 = new RectShape();
      ShapeDrawable bord = new ShapeDrawable(rect1);
      // Log.v(LOG_TAG,"person color"+person.user_color);
      // bord.getPaint().setStyle(Style.STROKE);
      // bord.getPaint().setStrokeWidth(b);
      bord.getPaint().setColor(getResources().getColor(person.user_color));
      bord.setAlpha(204);
      bord.setBounds(x - b, y - b, x + image.getWidth() + b, y + image.getHeight() + b);
      Log.v(LOG_TAG, "SIZE" + (image.getWidth() + 2 * b) + "" + (image.getHeight() + 2 * b));
      // border.setPadding(b,b,b,b);
      bord.draw(canvas);
      // Crystal image
      Bitmap overlay =
          Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(overlay);

      paint.setAntiAlias(true);
      paint.setTextSize(Values.nameTextSize);

      c.drawBitmap(image, 0, 0, null);
      RectShape nTag = new RectShape();
      ShapeDrawable nameTag = new ShapeDrawable(nTag);
      nameTag.getPaint().setColor(getResources().getColor(person.user_color));
      nameTag.setAlpha(204);
      nameTag.setBounds(0, image.getHeight() - namebox, image.getWidth(), image.getHeight());
      nameTag.draw(c);
      c.drawText(
          person.getUsername(),
          0,
          Math.min(11, (person.getUsername()).length()),
          0 /*Values.iconTextPadding*/,
          image.getHeight() - namebox + Values.nameTextSize /*5/2*Values.iconBorderPadding+10*/,
          paint);
      canvas.drawBitmap(overlay, x, y, null);

      if (person == space.getOwner()) {

        Bitmap adminTag =
            Bitmap.createBitmap(image.getWidth() + 2 * b, 20, Bitmap.Config.ARGB_8888);
        Canvas ac = new Canvas(adminTag);
        Paint ad = new Paint();
        ad.setColor(Color.rgb(0, 0, 0));
        ad.setAlpha(204);
        ac.drawRect(0, 0, image.getWidth() + 2 * b, 20, ad);
        ad.setAlpha(255);
        ad.setColor(Color.WHITE);
        ad.setStyle(Paint.Style.FILL);
        ad.setAntiAlias(true);
        ad.setTextSize(Values.adminTextSize);
        ac.drawText("admin", Values.textAdjust, (Values.adminBox - Values.textAdjust), ad);
        canvas.drawBitmap(adminTag, x - b, y - b, null);
      }
    } else {
      canvas.drawBitmap(image, x, y, null);
    }
  }