Java Code Examples for android.graphics.drawable.Drawable#resolveOpacity()

The following examples show how to use android.graphics.drawable.Drawable#resolveOpacity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawableContainerCompat.java    From MaterialProgressBar with Apache License 2.0 6 votes vote down vote up
/**
 * @return the resolved opacity of all child drawables.
 */
public final int getOpacity() {
    if (mCheckedOpacity) {
        return mOpacity;
    }
    createAllFutures();
    final int count = mNumChildren;
    final Drawable[] drawables = mDrawables;
    int op = (count > 0) ? drawables[0].getOpacity() : PixelFormat.TRANSPARENT;
    for (int i = 1; i < count; i++) {
        op = Drawable.resolveOpacity(op, drawables[i].getOpacity());
    }
    mOpacity = op;
    mCheckedOpacity = true;
    return op;
}
 
Example 2
Source File: LayerDrawable.java    From RippleDrawable with MIT License 6 votes vote down vote up
public final int getOpacity() {
    if (mHaveOpacity) {
        return mOpacity;
    }

    final ChildDrawable[] array = mChildren;
    final int N = mNum;
    int op = N > 0 ? array[0].mDrawable.getOpacity() : PixelFormat.TRANSPARENT;
    for (int i = 1; i < N; i++) {
        op = Drawable.resolveOpacity(op, array[i].mDrawable.getOpacity());
    }

    mOpacity = op;
    mHaveOpacity = true;
    return op;
}
 
Example 3
Source File: ArrayDrawable.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getOpacity() {
  if (mLayers.length == 0) {
    return PixelFormat.TRANSPARENT;
  }
  int opacity = mLayers[0].getOpacity();
  for (int i = 1; i < mLayers.length; i++) {
    opacity = Drawable.resolveOpacity(opacity, mLayers[i].getOpacity());
  }
  return opacity;
}
 
Example 4
Source File: LayerDrawable.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public final int getOpacity() {
    if (mHaveOpacity) {
        return mOpacity;
    }

    final ChildDrawable[] array = mChildren;
    final int N = mNum;

    // Seek to the first non-null drawable.
    int firstIndex = -1;
    for (int i = 0; i < N; i++) {
        if (array[i].mDrawable != null) {
            firstIndex = i;
            break;
        }
    }

    int op;
    if (firstIndex >= 0) {
        op = array[firstIndex].mDrawable.getOpacity();
    } else {
        op = PixelFormat.TRANSPARENT;
    }

    // Merge all remaining non-null drawables.
    for (int i = firstIndex + 1; i < N; i++) {
        final Drawable dr = array[i].mDrawable;
        if (dr != null) {
            op = Drawable.resolveOpacity(op, dr.getOpacity());
        }
    }

    mOpacity = op;
    mHaveOpacity = true;
    return op;
}
 
Example 5
Source File: ArrayDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public int getOpacity() {
  if (mLayers.length == 0) {
    return PixelFormat.TRANSPARENT;
  }
  int opacity = PixelFormat.OPAQUE;
  for (int i = 1; i < mLayers.length; i++) {
    Drawable drawable = mLayers[i];
    if (drawable != null) {
      opacity = Drawable.resolveOpacity(opacity, drawable.getOpacity());
    }
  }
  return opacity;
}
 
Example 6
Source File: FrameDrawable.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public int getOpacity() {
    if (mItems.isEmpty())
        return PixelFormat.TRANSPARENT;
    int op = mItems.get(0).getDrawable().getOpacity();
    final int count = mItems.size();
    for (int i = 1; i < count; i++) {
        op = Drawable.resolveOpacity(op, mItems.get(i).getDrawable().getOpacity());
    }
    return op;
}
 
Example 7
Source File: LayerDrawable.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public final int getOpacity() {
    if (mHaveOpacity) {
        return mOpacity;
    }

    final int N = mNum;
    final Rec[] array = mArray;
    int op = N > 0 ? array[0].mDrawable.getOpacity() : PixelFormat.TRANSPARENT;
    for (int i = 1; i < N; i++) {
        op = Drawable.resolveOpacity(op, array[i].mDrawable.getOpacity());
    }
    mOpacity = op;
    mHaveOpacity = true;
    return op;
}
 
Example 8
Source File: RhythmDrawable.java    From Rhythm with Apache License 2.0 4 votes vote down vote up
@Override
public int getOpacity() {
    final int overlayOpacity = mOverlay == null ? PixelFormat.TRANSPARENT : PixelFormat.TRANSLUCENT;
    return mDecorated != null ? Drawable.resolveOpacity(mDecorated.getOpacity(), overlayOpacity) : overlayOpacity;
}