Java Code Examples for android.graphics.Outline#setOval()

The following examples show how to use android.graphics.Outline#setOval() . 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: ActionButton.java    From fab with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the elevation around the main circle
 * <p>
 * Stroke corrective is used due to ambiguity in drawing stroke in
 * combination with elevation enabled (for API 21 and higher only.
 * In such case there is no possibility to determine the accurate
 * <b>Action Button</b> size, so width and height must be corrected
 * <p>
 * This logic may be changed in future if the better solution is found
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void drawElevation() {
	float halfSize = getSize() / 2;
	final int left = (int) (calculateCenterX() - halfSize);
	final int top = (int) (calculateCenterY() - halfSize);
	final int right = (int) (calculateCenterX() + halfSize);
	final int bottom = (int) (calculateCenterY() + halfSize);
	ViewOutlineProvider provider = new ViewOutlineProvider() {
		@Override
		public void getOutline(View view, Outline outline) {
			outline.setOval(left, top, right, bottom);
		}
	};
	setOutlineProvider(provider);
	LOGGER.trace("Drawn the Action Button elevation");
}
 
Example 2
Source File: DetailActivity.java    From google-io-2014 with Apache License 2.0 5 votes vote down vote up
private void setOutlines(int star, int info) {
    final int size = getResources().getDimensionPixelSize(R.dimen.floating_button_size);

    final ViewOutlineProvider vop = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, size, size);
        }
    };

    findViewById(star).setOutlineProvider(vop);
    findViewById(info).setOutlineProvider(vop);
}
 
Example 3
Source File: DetailActivityL.java    From google-io-2014-compat with Apache License 2.0 5 votes vote down vote up
private void setOutlines(int star, int info) {
    final int size = getResources().getDimensionPixelSize(R.dimen.floating_button_size);

    final ViewOutlineProvider vop = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, size, size);
        }
    };

    findViewById(star).setOutlineProvider(vop);
    findViewById(info).setOutlineProvider(vop);
}
 
Example 4
Source File: ViewUtils.java    From Protein with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(view.getPaddingLeft(),
            view.getPaddingTop(),
            view.getWidth() - view.getPaddingRight(),
            view.getHeight() - view.getPaddingBottom());
}
 
Example 5
Source File: ViewOvalRectOutlineProvider.java    From PlayerBase with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(final View view, final Outline outline) {
    Rect selfRect;
    if(mRect!=null){
        selfRect = mRect;
    }else{
        Rect rect = new Rect();
        view.getGlobalVisibleRect(rect);
        selfRect = RectUtils.getOvalRect(rect);
    }
    outline.setOval(selfRect);
}
 
Example 6
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(view.getPaddingLeft(),
            view.getPaddingTop(),
            view.getWidth() - view.getPaddingRight(),
            view.getHeight() - view.getPaddingBottom());
}
 
Example 7
Source File: ThemeChoiceDrawable.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(Outline outline) {
	Rect bounds = getBounds();
	int radius = (int) ((Math.min(bounds.width(), bounds.height()) / 2) * 0.95f);
	int cx = bounds.centerX();
	int cy = bounds.centerY();
	outline.setOval(cx - radius, cy - radius, cx + radius, cy + radius);
}
 
Example 8
Source File: TapTargetView.java    From TapTargetView with Apache License 2.0 4 votes vote down vote up
protected void applyTargetOptions(Context context) {
  shouldTintTarget = !target.transparentTarget && target.tintTarget;
  shouldDrawShadow = target.drawShadow;
  cancelable = target.cancelable;

  // We can't clip out portions of a view outline, so if the user specified a transparent
  // target, we need to fallback to drawing a jittered shadow approximation
  if (shouldDrawShadow && Build.VERSION.SDK_INT >= 21 && !target.transparentTarget) {
    outlineProvider = new ViewOutlineProvider() {
      @TargetApi(Build.VERSION_CODES.LOLLIPOP)
      @Override
      public void getOutline(View view, Outline outline) {
        if (outerCircleCenter == null) return;
        outline.setOval(
            (int) (outerCircleCenter[0] - outerCircleRadius), (int) (outerCircleCenter[1] - outerCircleRadius),
            (int) (outerCircleCenter[0] + outerCircleRadius), (int) (outerCircleCenter[1] + outerCircleRadius));
        outline.setAlpha(outerCircleAlpha / 255.0f);
        if (Build.VERSION.SDK_INT >= 22) {
          outline.offset(0, SHADOW_DIM);
        }
      }
    };

    setOutlineProvider(outlineProvider);
    setElevation(SHADOW_DIM);
  }

  if (shouldDrawShadow && outlineProvider == null && Build.VERSION.SDK_INT < 18) {
    setLayerType(LAYER_TYPE_SOFTWARE, null);
  } else {
    setLayerType(LAYER_TYPE_HARDWARE, null);
  }

  final Resources.Theme theme = context.getTheme();
  isDark = UiUtil.themeIntAttr(context, "isLightTheme") == 0;

  final Integer outerCircleColor = target.outerCircleColorInt(context);
  if (outerCircleColor != null) {
    outerCirclePaint.setColor(outerCircleColor);
  } else if (theme != null) {
    outerCirclePaint.setColor(UiUtil.themeIntAttr(context, "colorPrimary"));
  } else {
    outerCirclePaint.setColor(Color.WHITE);
  }

  final Integer targetCircleColor = target.targetCircleColorInt(context);
  if (targetCircleColor != null) {
    targetCirclePaint.setColor(targetCircleColor);
  } else {
    targetCirclePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
  }

  if (target.transparentTarget) {
    targetCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  }

  targetCirclePulsePaint.setColor(targetCirclePaint.getColor());

  final Integer targetDimColor = target.dimColorInt(context);
  if (targetDimColor != null) {
    dimColor = UiUtil.setAlpha(targetDimColor, 0.3f);
  } else {
    dimColor = -1;
  }

  final Integer titleTextColor = target.titleTextColorInt(context);
  if (titleTextColor != null) {
    titlePaint.setColor(titleTextColor);
  } else {
    titlePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
  }

  final Integer descriptionTextColor = target.descriptionTextColorInt(context);
  if (descriptionTextColor != null) {
    descriptionPaint.setColor(descriptionTextColor);
  } else {
    descriptionPaint.setColor(titlePaint.getColor());
  }

  if (target.titleTypeface != null) {
    titlePaint.setTypeface(target.titleTypeface);
  }

  if (target.descriptionTypeface != null) {
    descriptionPaint.setTypeface(target.descriptionTypeface);
  }
}
 
Example 9
Source File: ElevatedCircleView.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval((int) -getElevation(), 0, (int) (width + getElevation()), height + (int) (0.5f * getElevation()));
    //outline.setOval(0, 0, width, height);
}
 
Example 10
Source File: ElevationDragFragment.java    From android-ElevationDrag with Apache License 2.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
 
Example 11
Source File: BezelImageView.java    From MaterialDrawer-Xamarin with Apache License 2.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, width, height);
}
 
Example 12
Source File: RoundOutlineProvider.java    From CoolSignIn with Apache License 2.0 4 votes vote down vote up
@Override
public final void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, mSize, mSize);
}
 
Example 13
Source File: PingerOutlineProvider.java    From friendlyping with Apache License 2.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    final int size = view.getResources().getDimensionPixelSize(R.dimen.design_fab_size_normal);
    outline.setOval(0, 0, size, size);
}
 
Example 14
Source File: ElevationDragFragment.java    From user-interface-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
 
Example 15
Source File: RoundOutlineProvider.java    From android-topeka with Apache License 2.0 4 votes vote down vote up
@Override
public final void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, mSize, mSize);
}
 
Example 16
Source File: BezelImageView.java    From CoolApk-Console with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(0, 0, width, height);
}
 
Example 17
Source File: CircleImageView.java    From CircularImageView with Apache License 2.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(mRect);
}
 
Example 18
Source File: PassphraseAvatarOutlineProvider.java    From adamant-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    outline.setOval(0 , 0, view.getRight() - view.getLeft(), view.getBottom() - view.getTop());
}
 
Example 19
Source File: TapTargetView.java    From styT with Apache License 2.0 4 votes vote down vote up
protected void applyTargetOptions(Context context) {
    shouldTintTarget = target.tintTarget;
    shouldDrawShadow = target.drawShadow;
    cancelable = target.cancelable;

    // We can't clip out portions of a view outline, so if the user specified a transparent
    // target, we need to fallback to drawing a jittered shadow approximation
    if (shouldDrawShadow && Build.VERSION.SDK_INT >= 21 && !target.transparentTarget) {
        outlineProvider = new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                if (outerCircleCenter == null) return;
                outline.setOval(
                        (int) (outerCircleCenter[0] - outerCircleRadius), (int) (outerCircleCenter[1] - outerCircleRadius),
                        (int) (outerCircleCenter[0] + outerCircleRadius), (int) (outerCircleCenter[1] + outerCircleRadius));
                outline.setAlpha(outerCircleAlpha / 255.0f);
                if (Build.VERSION.SDK_INT >= 22) {
                    outline.offset(0, SHADOW_DIM);
                }
            }
        };

        setOutlineProvider(outlineProvider);
        setElevation(SHADOW_DIM);
    }

    setLayerType(LAYER_TYPE_HARDWARE, null);

    final Resources.Theme theme = context.getTheme();
    isDark = UiUtil.themeIntAttr(context, "isLightTheme") == 0;

    final Integer outerCircleColor = target.outerCircleColorInt(context);
    if (outerCircleColor != null) {
        outerCirclePaint.setColor(outerCircleColor);
    } else if (theme != null) {
        outerCirclePaint.setColor(UiUtil.themeIntAttr(context, "colorPrimary"));
    } else {
        outerCirclePaint.setColor(Color.WHITE);
    }

    final Integer targetCircleColor = target.targetCircleColorInt(context);
    if (targetCircleColor != null) {
        targetCirclePaint.setColor(targetCircleColor);
    } else {
        targetCirclePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
    }

    if (target.transparentTarget) {
        targetCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    }

    targetCirclePulsePaint.setColor(targetCirclePaint.getColor());

    final Integer targetDimColor = target.dimColorInt(context);
    if (targetDimColor != null) {
        dimColor = UiUtil.setAlpha(targetDimColor, 0.3f);
    } else {
        dimColor = -1;
    }

    final Integer titleTextColor = target.titleTextColorInt(context);
    if (titleTextColor != null) {
        titlePaint.setColor(titleTextColor);
    } else {
        titlePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
    }

    final Integer descriptionTextColor = target.descriptionTextColorInt(context);
    if (descriptionTextColor != null) {
        descriptionPaint.setColor(descriptionTextColor);
    } else {
        descriptionPaint.setColor(titlePaint.getColor());
    }

    if (target.titleTypeface != null) {
        titlePaint.setTypeface(target.titleTypeface);
    }

    if (target.descriptionTypeface != null) {
        descriptionPaint.setTypeface(target.descriptionTypeface);
    }
}