use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class PathMeasure_Delegate method native_getSegment.
@LayoutlibDelegate
static /*package*/
boolean native_getSegment(long native_instance, float startD, float stopD, long native_dst_path, boolean startWithMoveTo) {
if (startD < 0) {
startD = 0;
}
if (startD >= stopD) {
return false;
}
PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
assert pathMeasure != null;
CachedPathIterator iterator = pathMeasure.mOriginalPathIterator.iterator();
float accLength = startD;
// Whether the output has zero length or not
boolean isZeroLength = true;
float[] points = new float[6];
iterator.jumpToSegment(accLength);
while (!iterator.isDone() && (stopD - accLength > 0.1f)) {
int type = iterator.currentSegment(points, stopD - accLength);
if (accLength - iterator.getCurrentSegmentLength() <= stopD) {
if (startWithMoveTo) {
startWithMoveTo = false;
// a first moveto
if (type != PathIterator.SEG_MOVETO) {
float[] lastPoint = new float[2];
iterator.getCurrentSegmentEnd(lastPoint);
Path_Delegate.native_moveTo(native_dst_path, lastPoint[0], lastPoint[1]);
}
}
isZeroLength = isZeroLength && iterator.getCurrentSegmentLength() > 0;
switch(type) {
case PathIterator.SEG_MOVETO:
Path_Delegate.native_moveTo(native_dst_path, points[0], points[1]);
break;
case PathIterator.SEG_LINETO:
Path_Delegate.native_lineTo(native_dst_path, points[0], points[1]);
break;
case PathIterator.SEG_CLOSE:
Path_Delegate.native_close(native_dst_path);
break;
case PathIterator.SEG_CUBICTO:
Path_Delegate.native_cubicTo(native_dst_path, points[0], points[1], points[2], points[3], points[4], points[5]);
break;
case PathIterator.SEG_QUADTO:
Path_Delegate.native_quadTo(native_dst_path, points[0], points[1], points[2], points[3]);
break;
default:
assert false;
}
}
accLength += iterator.getCurrentSegmentLength();
iterator.next();
}
return !isZeroLength;
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class PathMeasure_Delegate method native_isClosed.
@LayoutlibDelegate
static /*package*/
boolean native_isClosed(long native_instance) {
PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
assert pathMeasure != null;
Path_Delegate path = Path_Delegate.getDelegate(pathMeasure.mNativePath);
if (path == null) {
return false;
}
int type = 0;
float[] segment = new float[6];
for (PathIterator pi = path.getJavaShape().getPathIterator(null); !pi.isDone(); pi.next()) {
type = pi.currentSegment(segment);
}
// A path is a closed path if the last element is SEG_CLOSE
return type == PathIterator.SEG_CLOSE;
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class AnimatedVectorDrawable_Delegate method nCreatePathPropertyHolder.
@LayoutlibDelegate
static /*package*/
long nCreatePathPropertyHolder(long nativePtr, int propertyId, float startValue, float endValue) {
VFullPath_Delegate path = VNativeObject.getDelegate(nativePtr);
Consumer<Float> setter = path.getFloatPropertySetter(propertyId);
return sHolders.addNewDelegate(FloatPropertySetter.of(setter, startValue, endValue));
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class AnimatedVectorDrawable_Delegate method nAddAnimator.
@LayoutlibDelegate
static /*package*/
void nAddAnimator(long setPtr, long propertyValuesHolder, long nativeInterpolator, long startDelay, long duration, int repeatCount) {
PropertySetter holder = sHolders.getDelegate(propertyValuesHolder);
if (holder == null || holder.getValues() == null) {
return;
}
ObjectAnimator animator = new ObjectAnimator();
animator.setValues(holder.getValues());
animator.setInterpolator(NativeInterpolatorFactoryHelper_Delegate.getDelegate(nativeInterpolator));
animator.setStartDelay(startDelay);
animator.setDuration(duration);
animator.setRepeatCount(repeatCount);
animator.setTarget(holder);
animator.setPropertyName(holder.getValues().getPropertyName());
AnimatorSetHolder set = sAnimatorSets.getDelegate(setPtr);
assert set != null;
set.addAnimator(animator);
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class GradientDrawable_Delegate method buildRing.
/**
* The ring can be built either by drawing full circles, or by drawing arcs in case the
* circle isn't complete. LayoutLib cannot handle drawing full circles (requires path
* subtraction). So, if we need to draw full circles, we switch to drawing 99% circle.
*/
@LayoutlibDelegate
static /*package*/
Path buildRing(GradientDrawable thisDrawable, GradientState st) {
boolean useLevel = st.mUseLevelForShape;
int level = thisDrawable.getLevel();
// 10000 is the max level. See android.graphics.drawable.Drawable#getLevel()
float sweep = useLevel ? (360.0f * level / 10000.0f) : 360f;
Field mLevel = null;
if (sweep >= 360 || sweep <= -360) {
st.mUseLevelForShape = true;
// dirty again.
try {
mLevel = Drawable.class.getDeclaredField("mLevel");
mLevel.setAccessible(true);
// set to one less than max.
mLevel.setInt(thisDrawable, 9999);
} catch (NoSuchFieldException e) {
// The field has been removed in a recent framework change. Fall back to old
// buggy behaviour.
} catch (IllegalAccessException e) {
// We've already set the field to be accessible.
assert false;
}
}
Path path = thisDrawable.buildRing_Original(st);
st.mUseLevelForShape = useLevel;
if (mLevel != null) {
try {
mLevel.setInt(thisDrawable, level);
} catch (IllegalAccessException e) {
assert false;
}
}
return path;
}
Aggregations