Beispiel #1
1
  /** Put a nice border on the bitmap. */
  private static View applyFrame(
      final PhotoTable table, final BitmapFactory.Options options, Bitmap decodedPhoto) {
    LayoutInflater inflater =
        (LayoutInflater) table.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View photo = inflater.inflate(R.layout.photo, null);
    ImageView image = (ImageView) photo;
    Drawable[] layers = new Drawable[2];
    int photoWidth = options.outWidth;
    int photoHeight = options.outHeight;
    if (decodedPhoto == null || options.outWidth <= 0 || options.outHeight <= 0) {
      photo = null;
    } else {
      decodedPhoto.setHasMipMap(true);
      layers[0] = new BitmapDrawable(table.mResources, decodedPhoto);
      layers[1] = table.mResources.getDrawable(R.drawable.frame);
      LayerDrawable layerList = new LayerDrawable(layers);
      layerList.setLayerInset(0, table.mInset, table.mInset, table.mInset, table.mInset);
      image.setImageDrawable(layerList);

      photo.setTag(R.id.photo_width, Integer.valueOf(photoWidth));
      photo.setTag(R.id.photo_height, Integer.valueOf(photoHeight));

      photo.setOnTouchListener(new PhotoTouchListener(table.getContext(), table));
    }
    return photo;
  }
Beispiel #2
0
  private LayerDrawable createDrawable(int radius, int topColor, int bottomColor) {

    float[] outerRadius =
        new float[] {radius, radius, radius, radius, radius, radius, radius, radius};

    // Top
    RoundRectShape topRoundRect = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable topShapeDrawable = new ShapeDrawable(topRoundRect);
    topShapeDrawable.getPaint().setColor(topColor);
    // Bottom
    RoundRectShape roundRectShape = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable bottomShapeDrawable = new ShapeDrawable(roundRectShape);
    bottomShapeDrawable.getPaint().setColor(bottomColor);
    // Create array
    Drawable[] drawArray = {bottomShapeDrawable, topShapeDrawable};
    LayerDrawable layerDrawable = new LayerDrawable(drawArray);

    // Set shadow height
    if (isShadowEnabled && topColor != Color.TRANSPARENT) {
      // unpressed drawable
      layerDrawable.setLayerInset(0, 0, 0, 0, 0); /*index, left, top, right, bottom*/
    } else {
      // pressed drawable
      layerDrawable.setLayerInset(0, 0, mShadowHeight, 0, 0); /*index, left, top, right, bottom*/
    }
    layerDrawable.setLayerInset(1, 0, 0, 0, mShadowHeight); /*index, left, top, right, bottom*/

    return layerDrawable;
  }
  public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] {R.attr.colorAccent});
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] {d, d2, d1});

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
  }
 public void a(int paramInt) {
   int i = FeedUtils.a(this.b, paramInt);
   Resources localResources = this.b.getResources();
   int j = i - localResources.getDimensionPixelSize(2131230788);
   int k = localResources.getDimensionPixelSize(2131230789);
   Drawable localDrawable = getBackground();
   if (localDrawable != null) ((LayerDrawable) localDrawable).setLayerInset(0, j, k, j, k);
 }
  private void shiftLayer(LayerDrawable pieceDrawable, int level) {

    int l = level * shiftSize;
    int r = 0;
    int t = 0;
    int b = 0;
    pieceDrawable.setLayerInset(level, l, t, r, b);
    ((BitmapDrawable) pieceDrawable.getDrawable(level)).setGravity(Gravity.LEFT | Gravity.TOP);
  }
 private LayerDrawable makeClusterBackground() {
   mColoredCircleBackground = new ShapeDrawable(new OvalShape());
   ShapeDrawable outline = new ShapeDrawable(new OvalShape());
   outline.getPaint().setColor(0x80ffffff); // Transparent white.
   LayerDrawable background =
       new LayerDrawable(new Drawable[] {outline, mColoredCircleBackground});
   int strokeWidth = (int) (mDensity * 3);
   background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
   return background;
 }
  void updateBackground() {
    final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
    final float halfStrokeWidth = strokeWidth / 2f;

    LayerDrawable layerDrawable =
        new LayerDrawable(
            new Drawable[] {
              getResources()
                  .getDrawable(
                      mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini),
              createFillDrawable(strokeWidth),
              createOuterStrokeDrawable(strokeWidth),
              getIconDrawable()
            });

    int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;

    int circleInsetHorizontal = (int) (mShadowRadius);
    int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
    int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);

    layerDrawable.setLayerInset(
        1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom);

    layerDrawable.setLayerInset(
        2,
        (int) (circleInsetHorizontal - halfStrokeWidth),
        (int) (circleInsetTop - halfStrokeWidth),
        (int) (circleInsetHorizontal - halfStrokeWidth),
        (int) (circleInsetBottom - halfStrokeWidth));

    layerDrawable.setLayerInset(
        3,
        circleInsetHorizontal + iconOffset,
        circleInsetTop + iconOffset,
        circleInsetHorizontal + iconOffset,
        circleInsetBottom + iconOffset);

    setBackgroundCompat(layerDrawable);
  }
Beispiel #8
0
 public Drawable getFaviconDrawable(Bitmap icon) {
   Drawable[] array = new Drawable[3];
   array[0] = new PaintDrawable(Color.BLACK);
   PaintDrawable p = new PaintDrawable(Color.WHITE);
   array[1] = p;
   if (icon == null) {
     array[2] = mGenericFavicon;
   } else {
     array[2] = new BitmapDrawable(icon);
   }
   LayerDrawable d = new LayerDrawable(array);
   d.setLayerInset(1, 1, 1, 1, 1);
   d.setLayerInset(2, 2, 2, 2, 2);
   return d;
 }
 @Override
 public Drawable getFaviconDrawable(Bitmap icon) {
   if (ENABLE_BORDER_AROUND_FAVICON) {
     Drawable[] array = new Drawable[2];
     array[0] = getFaviconBackground();
     if (icon == null) {
       array[1] = getGenericFavicon();
     } else {
       array[1] = new BitmapDrawable(mActivity.getResources(), icon);
     }
     LayerDrawable d = new LayerDrawable(array);
     d.setLayerInset(1, 2, 2, 2, 2);
     return d;
   }
   return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
 }
  private Drawable createDrawable(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);

    if (mShadow && !hasLollipopApi()) {
      Drawable shadowDrawable =
          getResources()
              .getDrawable(mType == TYPE_NORMAL ? R.drawable.shadow : R.drawable.shadow_mini);
      LayerDrawable layerDrawable =
          new LayerDrawable(new Drawable[] {shadowDrawable, shapeDrawable});
      layerDrawable.setLayerInset(1, mShadowSize, mShadowSize, mShadowSize, mShadowSize);
      return layerDrawable;
    } else {
      return shapeDrawable;
    }
  }
Beispiel #11
0
  public Drawable getActionBarDrawable(
      Activity activity, int theme, boolean dark, float borderBottom) {
    int[] colors = activity.getResources().getIntArray(theme);

    int color1 = colors[2];
    int color2 = colors[1];

    if (dark) {
      color1 = colors[1];
      color2 = colors[0];
    }

    borderBottom = dipToPx(activity, borderBottom);

    PaintDrawable front = new PaintDrawable(color1);
    PaintDrawable bottom = new PaintDrawable(color2);
    Drawable[] d = {bottom, front};
    LayerDrawable drawable = new LayerDrawable(d);
    drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
    return drawable;
  }
  private Drawable createOval(int color) {
    ShapeDrawable shape = new ShapeDrawable(new OvalShape());
    shape.getPaint().setColor(color);
    shape.getPaint().setStyle(Paint.Style.FILL);

    // on lollipop we let elevation take care of the shadow
    if (mIsLollipop) {
      return shape;
    }

    Drawable shadow = getContext().getResources().getDrawable(R.drawable.fab_shadow);
    Drawable[] layers = {shadow, shape};
    LayerDrawable layerDrawable = new LayerDrawable(layers);

    // inset the shape drawable so the shadow is uncovered
    int oneDp = DisplayUtils.dpToPx(getContext(), 1);
    int twoDp = DisplayUtils.dpToPx(getContext(), 2);
    layerDrawable.setLayerInset(1, oneDp, oneDp, twoDp, twoDp);

    return layerDrawable;
  }
  private Drawable createCircleDrawable(int color, float strokeWidth) {
    int alpha = Color.alpha(color);
    int opaqueColor = opaque(color);

    ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());

    final Paint paint = fillDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setColor(opaqueColor);

    Drawable[] layers = {fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth)};

    LayerDrawable drawable =
        alpha == 255 || !mStrokeVisible
            ? new LayerDrawable(layers)
            : new TranslucentLayerDrawable(alpha, layers);

    int halfStrokeWidth = (int) (strokeWidth / 2f);
    drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);

    return drawable;
  }
  void updateBackground() {
    LayerDrawable layerDrawable;
    if (hasShadow()) {
      layerDrawable =
          new LayerDrawable(new Drawable[] {new Shadow(), createFillDrawable(), getIconDrawable()});
    } else {
      layerDrawable = new LayerDrawable(new Drawable[] {createFillDrawable(), getIconDrawable()});
    }

    int iconSize = -1;
    if (getIconDrawable() != null) {
      iconSize =
          Math.max(getIconDrawable().getIntrinsicWidth(), getIconDrawable().getIntrinsicHeight());
    }
    int iconOffset = (getCircleSize() - (iconSize > 0 ? iconSize : mIconSize)) / 2;
    int circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    int circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
      circleInsetHorizontal += mProgressWidth;
      circleInsetVertical += mProgressWidth;
    }

    /*layerDrawable.setLayerInset(
            mShowShadow ? 1 : 0,
            circleInsetHorizontal,
            circleInsetVertical,
            circleInsetHorizontal,
            circleInsetVertical
    );*/
    layerDrawable.setLayerInset(
        hasShadow() ? 2 : 1,
        circleInsetHorizontal + iconOffset,
        circleInsetVertical + iconOffset,
        circleInsetHorizontal + iconOffset,
        circleInsetVertical + iconOffset);

    setBackgroundCompat(layerDrawable);
  }
  public View getView(String path, Boolean editMode, final Context C) {
    ImageView button = new ImageView(C);
    final String videoPath = path + content;
    button.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent(C, VideoPlayerActivity.class);
            intent.putExtra("VIDEO_PATH", videoPath);
            C.startActivity(intent);
          }
        });

    Drawable[] layers = new Drawable[2];
    layers[0] =
        new BitmapDrawable(
            C.getResources(), ThumbnailUtils.createVideoThumbnail(videoPath, Thumbnails.MINI_KIND));
    layers[1] = (C.getResources().getDrawable(R.drawable.ic_action_play));
    LayerDrawable ld = new LayerDrawable(layers);
    ld.setLayerInset(1, 40, 0, 40, 0);
    ((BitmapDrawable) ld.getDrawable(1)).setGravity(Gravity.CENTER);
    button.setImageDrawable(ld);
    return button;
  }
Beispiel #16
0
  private void setActionBarBackground(boolean isCorrect, float percentage) {
    Point size = new Point();
    getWindowManager().getDefaultDisplay().getSize(size);
    int width = size.x;

    int backgroundColor = mColorLightGray;
    Drawable[] layers;
    LayerDrawable bg;
    if (percentage == 0) {
      layers = new Drawable[2];
      layers[0] = new ColorDrawable(backgroundColor);
      layers[1] = mActionBarBottomBorder;
      bg = new LayerDrawable(layers);
    } else {
      layers = new Drawable[3];
      layers[0] = new ColorDrawable(backgroundColor);
      layers[1] = new ColorDrawable(isCorrect ? mColorCorrect : mColorIncorrect);
      layers[2] = mActionBarBottomBorder;
      bg = new LayerDrawable(layers);
      bg.setLayerInset(1, 0, 0, (int) (width - (width * percentage)), 0);
    }
    mActionBar.setBackgroundDrawable(bg);
  }
  /** Initializes resources. */
  private void initResourcesIfNecessary() {
    if (itemsPaint == null) {
      itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
      // itemsPaint.density = getResources().getDisplayMetrics().density;
      itemsPaint.setTextSize(valueTextSize);
    }

    if (valuePaint == null) {
      valuePaint =
          new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
      // valuePaint.density = getResources().getDisplayMetrics().density;
      valuePaint.setTextSize(valueTextSize);
    }

    if (labelPaint == null) {
      labelPaint =
          new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
      labelPaint.setTextSize(labelTextSize);
      // 设置阴影
      labelPaint.setShadowLayer(0.5f, 0, 1, 0xFFFFFFFF);
    }

    // 如果没设置中间的选中条用默认的颜色
    if (centerSelectDrawable == null) {
      GradientDrawable mGradientDrawable =
          new GradientDrawable(Orientation.BOTTOM_TOP, centerSelectGradientColors);
      mGradientDrawable.setStroke(centerSelectStrokeWidth, centerSelectStrokeColor);
      centerSelectDrawable = mGradientDrawable;
    }

    /* Android中提供了Shader类专门用来渲染图像以及一些几何图形,
    Shader下面包括几个直接子类,分别是BitmapShader、 ComposeShader、LinearGradient、
    RadialGradient、SweepGradient。 BitmapShader主要用来渲染图像,
    LinearGradient 用来进行梯度渲染,RadialGradient 用来进行环形渲染,
    SweepGradient
    用来进行梯度渲染,ComposeShader则是一个 混合渲染,可以和其它几个子类组合起来使用。 */

    // 上边界渐变层
    if (topShadow == null) {
      topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }
    // 下边界渐变层
    if (bottomShadow == null) {
      bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    if (this.getBackground() == null) {
      // 原来用颜色渐变实现setBackgroundDrawable(layerDrawable);
      // 底部的颜色
      GradientDrawable mGradientDrawable1 =
          new GradientDrawable(Orientation.TOP_BOTTOM, topGradientColors);
      GradientDrawable mGradientDrawable2 =
          new GradientDrawable(Orientation.BOTTOM_TOP, bottomGradientColors);

      mGradientDrawable1.setStroke(topStrokeWidth, topStrokeColor);
      mGradientDrawable1.setShape(GradientDrawable.RECTANGLE);
      mGradientDrawable2.setShape(GradientDrawable.RECTANGLE);
      mGradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);
      mGradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);

      GradientDrawable[] mDrawables = new GradientDrawable[2];
      mDrawables[0] = mGradientDrawable1;
      mDrawables[1] = mGradientDrawable2;

      LayerDrawable layerDrawable = new LayerDrawable(mDrawables);
      layerDrawable.setLayerInset(0, 0, 0, 0, 0); // 第一个参数0代表数组的第1个元素
      layerDrawable.setLayerInset(1, 4, 1, 4, 1); // 第一个参数1代表数组的第2个元素
      setBackgroundDrawable(layerDrawable);
    }
  }
 private static void setInsetOnLayers(LayerDrawable[] ary, int l, int t, int r, int b) {
   for (LayerDrawable ld : ary) {
     ld.setLayerInset(0, l, t, r, b);
   }
 }