getNumberOfLayers()源码实例Demo

android.graphics.drawable.LayerDrawable#getNumberOfLayers()源码实例Demo

下面列出了android.graphics.drawable.LayerDrawable#getNumberOfLayers() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: UltimateAndroid   文件: RoundedImageView.java
private void updateAttrs(Drawable drawable) {
  if (drawable == null) { return; }

  if (drawable instanceof RoundedDrawable) {
    ((RoundedDrawable) drawable)
        .setScaleType(mScaleType)
        .setCornerRadius(cornerRadius)
        .setBorderWidth(borderWidth)
        .setBorderColor(borderColor)
        .setOval(isOval);
  } else if (drawable instanceof LayerDrawable) {
    // loop through layers to and set drawable attrs
    LayerDrawable ld = ((LayerDrawable) drawable);
    for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
      updateAttrs(ld.getDrawable(i));
    }
  }
}
 
源代码2 项目: Common   文件: RoundedDrawable.java
public static Drawable fromDrawable(Drawable drawable) {
    if (drawable != null) {
        if (drawable instanceof RoundedDrawable) {
            // just return if it's already a RoundedDrawable
            return drawable;
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            int num = ld.getNumberOfLayers();

            // loop through layers to and change to RoundedDrawables if possible
            for (int i = 0; i < num; i++) {
                Drawable d = ld.getDrawable(i);
                ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
            }
            return ld;
        }

        // try to get a bitmap from the drawable and
        Bitmap bm = drawableToBitmap(drawable);
        if (bm != null) {
            return new RoundedDrawable(bm);
        }
    }
    return drawable;
}
 
源代码3 项目: ImageLetterIcon   文件: RoundedDrawable.java
public static Drawable fromDrawable(Drawable drawable) {
    if (drawable != null) {
        if (drawable instanceof RoundedDrawable) {
            // just return if it's already a RoundedDrawable
            return drawable;
        } else if (drawable instanceof ColorDrawable) {
            // FIXME we don't support ColorDrawables yet
            return drawable;
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            int num = ld.getNumberOfLayers();
            // loop through layers to and change to RoundedDrawables if possible
            for (int i = 0; i < num; i++) {
                Drawable d = ld.getDrawable(i);
                ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
            }
            return ld;
        }
        // try to get a bitmap from the drawable and
        Bitmap bm = drawableToBitmap(drawable);
        if (bm != null) {
            return new RoundedDrawable(bm);
        }
    }
    return drawable;
}
 
源代码4 项目: UltimateAndroid   文件: RoundedImageView.java
private void updateAttrs(Drawable drawable) {
  if (drawable == null) { return; }

  if (drawable instanceof RoundedDrawable) {
    ((RoundedDrawable) drawable)
        .setScaleType(mScaleType)
        .setCornerRadius(cornerRadius)
        .setBorderWidth(borderWidth)
        .setBorderColor(borderColor)
        .setOval(isOval);
  } else if (drawable instanceof LayerDrawable) {
    // loop through layers to and set drawable attrs
    LayerDrawable ld = ((LayerDrawable) drawable);
    for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
      updateAttrs(ld.getDrawable(i));
    }
  }
}
 
源代码5 项目: AndroidMaterialDesign   文件: RoundedImageView.java
public static Drawable fromDrawable(Drawable drawable, Resources r) {
    if (drawable != null) {
        if (drawable instanceof SelectableRoundedCornerDrawable) {
            return drawable;
        }
        else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            final int num = ld.getNumberOfLayers();
            for (int i = 0; i < num; i++) {
                Drawable d = ld.getDrawable(i);
                ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r));
            }
            return ld;
        }

        Bitmap bm = drawableToBitmap(drawable);
        if (bm != null) {
            return new SelectableRoundedCornerDrawable(bm, r);
        } else {
            Log.w(TAG, "Failed to create bitmap from drawable!");
        }
    }
    return drawable;
}
 
源代码6 项目: ClipCircleHeadLikeQQ   文件: RoundedDrawable.java
public static Drawable fromDrawable(Drawable drawable) {
  if (drawable != null) {
    if (drawable instanceof RoundedDrawable) {
      // just return if it's already a RoundedDrawable
      return drawable;
    } else if (drawable instanceof LayerDrawable) {
      LayerDrawable ld = (LayerDrawable) drawable;
      int num = ld.getNumberOfLayers();

      // loop through layers to and change to RoundedDrawables if possible
      for (int i = 0; i < num; i++) {
        Drawable d = ld.getDrawable(i);
        ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
      }
      return ld;
    }

    // try to get a bitmap from the drawable and
    Bitmap bm = drawableToBitmap(drawable);
    if (bm != null) {
      return new RoundedDrawable(bm);
    }
  }
  return drawable;
}
 
源代码7 项目: graphics-samples   文件: RecyclingImageView.java
/**
 * Notifies the drawable that it's displayed state has changed.
 */
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
    if (drawable instanceof RecyclingBitmapDrawable) {
        // The drawable is a CountingBitmapDrawable, so notify it
        ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
    } else if (drawable instanceof LayerDrawable) {
        // The drawable is a LayerDrawable, so recurse on each layer
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
        }
    }
}
 
源代码8 项目: Badger   文件: BadgerTest.java
void assertBadged(Drawable drawable, TestBadgeDrawable badge, Drawable... drawables) {
    assertThat(drawable, instanceOf(LayerDrawable.class));
    LayerDrawable layer = (LayerDrawable) drawable;
    assertThat(layer.findDrawableByLayerId(R.id.badger_drawable), is((Drawable) badge));
    int size = layer.getNumberOfLayers();
    if (drawables.length < size) {
        assertThat(layer.getDrawable(--size), is((Drawable) badge));
    }
    List<Drawable> layers = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        layers.add(layer.getDrawable(i));
    }
    assertThat(layers, contains(drawables));
}
 
源代码9 项目: cube-sdk   文件: CubeImageView.java
/**
 * Notifies the drawable that it's displayed state has changed.
 *
 * @param drawable
 * @param isDisplayed
 */
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
    if (drawable instanceof RecyclingBitmapDrawable) {
        // The drawable is a CountingBitmapDrawable, so notify it
        ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
    } else if (drawable instanceof LayerDrawable) {
        // The drawable is a LayerDrawable, so recurse on each layer
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
        }
    }
}
 
private void updateBackground(Drawable background) {
    if (background instanceof LayerDrawable) {
        LayerDrawable layers = (LayerDrawable) background;
        if (layers.getNumberOfLayers() == 2) {
            Drawable shadow = layers.getDrawable(0);
            Drawable circle = layers.getDrawable(1);

            if (shadow instanceof GradientDrawable) {
                if (mShadow) {
                    ((GradientDrawable) shadow.mutate()).setGradientRadius(getShadowRadius(shadow, circle));
                } else {
                    shadow.setAlpha(0);
                }
            }

            if (circle instanceof GradientDrawable) {
                initCircleDrawable(circle);
            }
        }
    } else if (background instanceof GradientDrawable) {
        initCircleDrawable(background);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mImplicitElevation) {
            setElevation(mShadow ? getResources().getDimension(R.dimen.floating_action_button_elevation) : 0f);
        }
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        setBackgroundDrawable(background);
    } else {
        setBackground(background);
    }
}
 
源代码11 项目: FanXin-based-HuanXin   文件: RecyclingImageView.java
/**
 * Notifies the drawable that it's displayed state has changed.
 *
 * @param drawable
 * @param isDisplayed
 */
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
    if (drawable instanceof RecyclingBitmapDrawable) {
        // The drawable is a CountingBitmapDrawable, so notify it
        ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
    } else if (drawable instanceof LayerDrawable) {
        // The drawable is a LayerDrawable, so recurse on each layer
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
        }
    }
}
 
源代码12 项目: MyBlogDemo   文件: RoundedDrawable.java
public static Drawable fromDrawable(Drawable drawable) {
    if (drawable != null) {
        if (drawable instanceof RoundedDrawable) {
            // just return if it's already a RoundedDrawable
            return drawable;
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            int num = ld.getNumberOfLayers();

            // loop through layers to and change to RoundedDrawables if possible
            for (int i = 0; i < num; i++) {
                Drawable d = ld.getDrawable(i);
                ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
            }
            return ld;
        }

        // try to get a bitmap from the drawable and
        Bitmap bm = drawableToBitmap(drawable);
        if (bm != null) {
            return new RoundedDrawable(bm);
        } else {
            Log.w(TAG, "Failed to create bitmap from drawable!");
        }
    }
    return drawable;
}
 
源代码13 项目: sketch   文件: RequestFunction.java
/**
 * 修改Drawable显示状态
 *
 * @param callingStation 调用位置
 * @param drawable       Drawable
 * @param isDisplayed    是否已显示
 * @return true:drawable或其子Drawable是SketchDrawable
 */
private static boolean notifyDrawable(@NonNull String callingStation, @Nullable Drawable drawable, final boolean isDisplayed) {
    if (drawable == null) {
        return false;
    }

    boolean isSketchDrawable = false;

    if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            isSketchDrawable |= notifyDrawable(callingStation, layerDrawable.getDrawable(i), isDisplayed);
        }
    } else {
        if (!isDisplayed && drawable instanceof SketchLoadingDrawable) {
            SketchLoadingDrawable loadingDrawable = (SketchLoadingDrawable) drawable;
            DisplayRequest displayRequest = loadingDrawable.getRequest();
            if (displayRequest != null && !displayRequest.isFinished()) {
                displayRequest.cancel(CancelCause.BE_REPLACED_ON_SET_DRAWABLE);
            }
        }

        if (drawable instanceof SketchRefDrawable) {
            ((SketchRefDrawable) drawable).setIsDisplayed(callingStation, isDisplayed);
        } else if (drawable instanceof SketchGifDrawable) {
            if (!isDisplayed) {
                ((SketchGifDrawable) drawable).recycle();
            }
        }

        isSketchDrawable = drawable instanceof SketchDrawable;
    }

    return isSketchDrawable;
}
 
源代码14 项目: ClipCircleHeadLikeQQ   文件: RoundedImageView.java
private void updateAttrs(Drawable drawable) {
  if (drawable == null) { return; }

  if (drawable instanceof RoundedDrawable) {
    ((RoundedDrawable) drawable)
        .setScaleType(mScaleType)
        .setBorderWidth(mBorderWidth)
        .setBorderColor(mBorderColor)
        .setOval(mIsOval)
        .setTileModeX(mTileModeX)
        .setTileModeY(mTileModeY);

    if (mCornerRadii != null) {
      ((RoundedDrawable) drawable).setCornerRadius(mCornerRadii[CORNER_TOP_LEFT],
          mCornerRadii[CORNER_TOP_RIGHT], mCornerRadii[CORNER_BOTTOM_RIGHT],
          mCornerRadii[CORNER_BOTTOM_LEFT]);
    }

    applyColorMod();
  } else if (drawable instanceof LayerDrawable) {
    // loop through layers to and set drawable attrs
    LayerDrawable ld = ((LayerDrawable) drawable);
    for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
      updateAttrs(ld.getDrawable(i));
    }
  }
}
 
源代码15 项目: letv   文件: ActiveItemImageView.java
private void updateAttrs(Drawable drawable) {
    if (drawable != null) {
        if (drawable instanceof RoundedDrawable) {
            ((RoundedDrawable) drawable).setScaleType(this.mScaleType).setCornerRadius(this.cornerRadius).setBorderWidth(this.borderWidth).setBorderColor(this.borderColor).setOval(this.isOval);
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            int layers = ld.getNumberOfLayers();
            for (int i = 0; i < layers; i++) {
                updateAttrs(ld.getDrawable(i));
            }
        }
    }
}
 
源代码16 项目: UltimateAndroid   文件: RoundedDrawable.java
public static Drawable fromDrawable(Drawable drawable) {
  if (drawable != null) {
    if (drawable instanceof RoundedDrawable) {
      // just return if it's already a RoundedDrawable
      return drawable;
    } else if (drawable instanceof LayerDrawable) {
      LayerDrawable ld = (LayerDrawable) drawable;
      int num = ld.getNumberOfLayers();

      // loop through layers to and change to RoundedDrawables if possible
      for (int i = 0; i < num; i++) {
        Drawable d = ld.getDrawable(i);
        ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
      }
      return ld;
    }

    // try to get a bitmap from the drawable and
    Bitmap bm = drawableToBitmap(drawable);
    if (bm != null) {
      return new RoundedDrawable(bm);
    } else {
      Log.w(TAG, "Failed to create bitmap from drawable!");
    }
  }
  return drawable;
}
 
源代码17 项目: DMusic   文件: RoundedImageView.java
private void updateAttrs(Drawable drawable, ScaleType scaleType) {
    if (drawable == null) {
        return;
    }

    if (drawable instanceof RoundedDrawable) {
        ((RoundedDrawable) drawable)
                .setScaleType(scaleType)
                .setBorderWidth(mBorderWidth)
                .setBorderColor(mBorderColor)
                .setOval(mIsOval)
                .setTileModeX(mTileModeX)
                .setTileModeY(mTileModeY);

        if (mCornerRadii != null) {
            ((RoundedDrawable) drawable).setCornerRadius(
                    mCornerRadii[Corner.TOP_LEFT],
                    mCornerRadii[Corner.TOP_RIGHT],
                    mCornerRadii[Corner.BOTTOM_RIGHT],
                    mCornerRadii[Corner.BOTTOM_LEFT]);
        }

        applyColorMod();
    } else if (drawable instanceof LayerDrawable) {
        // loop through layers to and set drawable attrs
        LayerDrawable ld = ((LayerDrawable) drawable);
        for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
            updateAttrs(ld.getDrawable(i), scaleType);
        }
    }
}
 
源代码18 项目: vocefiscal-android   文件: RecyclingImageView.java
/**
 * Notifies the drawable that it's displayed state has changed.
 *
 * @param drawable
 * @param isDisplayed
 */
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
    if (drawable instanceof RecyclingBitmapDrawable) {
        // The drawable is a CountingBitmapDrawable, so notify it
        ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
    } else if (drawable instanceof LayerDrawable) {
        // The drawable is a LayerDrawable, so recurse on each layer
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
        }
    }
}
 
源代码19 项目: RoMote   文件: RecyclingImageView.java
/**
 * Notifies the drawable that it's displayed state has changed.
 *
 * @param drawable
 * @param isDisplayed
 */
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
    if (drawable instanceof RecyclingBitmapDrawable) {
        // The drawable is a CountingBitmapDrawable, so notify it
        ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
    } else if (drawable instanceof LayerDrawable) {
        // The drawable is a LayerDrawable, so recurse on each layer
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
            notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
        }
    }
}
 
源代码20 项目: Augendiagnose   文件: OverlayPinchImageView.java
/**
 * Add the current overlay to the partial Bitmap. (This is done similar to refresh().)
 *
 * @param partialBitmap the partial bitmap before applying the overlay
 * @return the partial bitmap with overlay.
 */
public final Bitmap addOverlayToPartialBitmap(@NonNull final Bitmap partialBitmap) {
	List<Integer> overlayPositions = getOverlayPositions();
	if (overlayPositions.size() == 0) {
		return partialBitmap;
	}

	Drawable[] layers = new Drawable[overlayPositions.size() + 1];

	layers[0] = new BitmapDrawable(getResources(), partialBitmap);

	for (int i = 0; i < overlayPositions.size(); i++) {
		layers[i + 1] = getOverlayDrawable(overlayPositions.get(i));
	}
	LayerDrawable layerDrawable = new LayerDrawable(layers);

	// position overlays
	for (int i = 1; i < layerDrawable.getNumberOfLayers(); i++) {
		boolean isPupil = overlayPositions.get(i - 1) == OVERLAY_PUPIL_INDEX;

		if (isPupil) {
			float totalPupilOverlayScaleFactor = mPupilOverlayScaleFactor * mOverlayScaleFactor * OVERLAY_SIZE / 2;
			float pupilAdjustedOverlayX =
					mOverlayX + mPupilOverlayX * mOverlayScaleFactor * OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO / mBitmap.getWidth();
			float pupilAdjustedOverlayY =
					mOverlayY + mPupilOverlayY * mOverlayScaleFactor * OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO / mBitmap.getHeight();
			layerDrawable.setLayerInset(i,
					(int) (((pupilAdjustedOverlayX - mPosX) * mBitmap.getWidth() - totalPupilOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getWidth() / 2),
					(int) (((pupilAdjustedOverlayY - mPosY) * mBitmap.getHeight() - totalPupilOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getHeight() / 2),
					(int) (((mPosX - pupilAdjustedOverlayX) * mBitmap.getWidth() - totalPupilOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getWidth() / 2),
					(int) (((mPosY - pupilAdjustedOverlayY) * mBitmap.getHeight() - totalPupilOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getHeight() / 2));
		}
		else {
			layerDrawable.setLayerInset(i,
					(int) (((mOverlayX - mPosX) * mBitmap.getWidth() - OVERLAY_SIZE / 2 * mOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getWidth() / 2),
					(int) (((mOverlayY - mPosY) * mBitmap.getHeight() - OVERLAY_SIZE / 2 * mOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getHeight() / 2),
					(int) (((mPosX - mOverlayX) * mBitmap.getWidth() - OVERLAY_SIZE / 2 * mOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getWidth() / 2),
					(int) (((mPosY - mOverlayY) * mBitmap.getHeight() - OVERLAY_SIZE / 2 * mOverlayScaleFactor) * mScaleFactor
							+ (float) partialBitmap.getHeight() / 2));
		}
	}

	layerDrawable.setBounds(0, 0, partialBitmap.getWidth(), partialBitmap.getHeight());

	Bitmap canvasBitmap = Bitmap.createBitmap(partialBitmap.getWidth(), partialBitmap.getHeight(), Bitmap.Config.ARGB_8888);
	Canvas canvas = new Canvas(canvasBitmap);
	layerDrawable.draw(canvas);

	return canvasBitmap;
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。