2 Star 1 Fork 2

冰雪情缘TV / OpenDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TestFramntLayout.java 14.08 KB
一键复制 编辑 原始数据 按行查看 历史
package com.open.demo.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.Region;
import android.graphics.Region.Op;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class TestFramntLayout extends FrameLayout {
public TestFramntLayout(@NonNull final Context context) {
super(context);
}
public TestFramntLayout(@NonNull final Context context, @Nullable final AttributeSet attrs) {
super(context, attrs);
}
public TestFramntLayout(@NonNull final Context context, @Nullable final AttributeSet attrs,
final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
float _currentRevealPercent;
public void revealForPercentage(float percent) {
// setBackgroundColor(Color.parseColor("#6200EE"));
setWillNotDraw(false);
if (percent == _currentRevealPercent) {
return;
}
_currentRevealPercent = percent;
getPath(percent, this);
invalidate();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
revealForPercentage(getWidth()/2);
}
@Override
public void draw(final Canvas canvas) {
try {
canvas.save();
canvas.clipPath(mPath, mRegionOp);
super.draw(canvas);
} finally {
canvas.restore();
}
}
void getPath(float percent, View view) {
Path path = mPath;
// waveCenterY = (waveCenterY == 0.0f) ? view.getHeight() / 2 : waveCenterY;
// waveHorizontalRadius = getWaveHorRadius(1 - (percent / getWidth()), view);
// waveVerticalRadius = getWaveVertRadius(1 - (percent / view.getHeight()), view);
// sideWidth = getSideWidth(1 - (percent / 100), view);
//
// path.reset();
// float maskWidth = view.getWidth() - sideWidth;
// path.moveTo(maskWidth - sideWidth, 0f);
// path.lineTo(0f, 0f);
// path.lineTo(0f, view.getHeight());
// path.lineTo(maskWidth, view.getHeight());
//
// if (percent == 100f) {
// path.close();
// return;
// }
//
// float curveStartY = waveCenterY + waveVerticalRadius;
// path.lineTo(maskWidth, curveStartY);
//
// path.cubicTo(
// maskWidth,
// (float) (curveStartY - waveVerticalRadius * 0.1346194756),
// (float) (maskWidth - waveHorizontalRadius * 0.05341339583),
// (float) (curveStartY - waveVerticalRadius * 0.2412779634),
// (float) (maskWidth - waveHorizontalRadius * 0.1561501458),
// (float) (curveStartY - waveVerticalRadius * 0.3322374268)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.2361659167),
// (float) (curveStartY - waveVerticalRadius * 0.4030805244),
// (float) (maskWidth - waveHorizontalRadius * 0.3305285625),
// (float) (curveStartY - waveVerticalRadius * 0.4561193293),
// (float) (maskWidth - waveHorizontalRadius * 0.5012484792),
// (float) (curveStartY - waveVerticalRadius * 0.5350576951)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.515878125),
// (float) (curveStartY - waveVerticalRadius * 0.5418222317),
// (float) (maskWidth - waveHorizontalRadius * 0.5664134792),
// (float) (curveStartY - waveVerticalRadius * 0.5650349878),
// (float) (maskWidth - waveHorizontalRadius * 0.574934875),
// (float) (curveStartY - waveVerticalRadius * 0.5689655122)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.7283715208),
// (float) (curveStartY - waveVerticalRadius * 0.6397387195),
// (float) (maskWidth - waveHorizontalRadius * 0.8086618958),
// (float) (curveStartY - waveVerticalRadius * 0.6833456585),
// (float) (maskWidth - waveHorizontalRadius * 0.8774032292),
// (float) (curveStartY - waveVerticalRadius * 0.7399037439)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.9653464583),
// (float) (curveStartY - waveVerticalRadius * 0.8122605122),
// maskWidth - waveHorizontalRadius,
// (float) (curveStartY - waveVerticalRadius * 0.8936183659),
// maskWidth - waveHorizontalRadius, curveStartY - waveVerticalRadius
// );
// path.cubicTo(
// maskWidth - waveHorizontalRadius,
// (float) (curveStartY - waveVerticalRadius * 1.100142878),
// (float) (maskWidth - waveHorizontalRadius * 0.9595746667),
// (float) (curveStartY - waveVerticalRadius * 1.1887991951),
// (float) (maskWidth - waveHorizontalRadius * 0.8608411667),
// (float) (curveStartY - waveVerticalRadius * 1.270484439)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.7852123333),
// (float) (curveStartY - waveVerticalRadius * 1.3330544756),
// (float) (maskWidth - waveHorizontalRadius * 0.703382125),
// (float) (curveStartY - waveVerticalRadius * 1.3795848049),
// (float) (maskWidth - waveHorizontalRadius * 0.5291125625),
// (float) (curveStartY - waveVerticalRadius * 1.4665102805)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.5241858333),
// (float) (curveStartY - waveVerticalRadius * 1.4689677195),
// (float) (maskWidth - waveHorizontalRadius * 0.505739125),
// (float) (curveStartY - waveVerticalRadius * 1.4781625854),
// (float) (maskWidth - waveHorizontalRadius * 0.5015305417),
// (float) (curveStartY - waveVerticalRadius * 1.4802616098)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.3187486042),
// (float) (curveStartY - waveVerticalRadius * 1.5714239024),
// (float) (maskWidth - waveHorizontalRadius * 0.2332057083),
// (float) (curveStartY - waveVerticalRadius * 1.6204116463),
// (float) (maskWidth - waveHorizontalRadius * 0.1541165417),
// (float) (curveStartY - waveVerticalRadius * 1.687403)
// );
// path.cubicTo(
// (float) (maskWidth - waveHorizontalRadius * 0.0509933125),
// (float) (curveStartY - waveVerticalRadius * 1.774752061),
// maskWidth, (float) (curveStartY - waveVerticalRadius * 1.8709256829),
// maskWidth, curveStartY - waveVerticalRadius * 2
// );
//
// path.lineTo(maskWidth, 0f);
// path.close();
path.reset();
path.moveTo(percent, 0f);
path.lineTo(0f, 0f);
path.lineTo(0f, getHeight());
path.lineTo(percent, getHeight());
float curveStartY = waveCenterY + waveVerticalRadius;
float maskWidth = percent;
waveCenterY = (waveCenterY == 0.0f) ? view.getHeight() / 2 : waveCenterY;
waveHorizontalRadius = getWaveHorRadius(1 - (percent / getWidth()), view);
waveVerticalRadius = getWaveVertRadius(1 - (percent / view.getHeight()), view);
path.lineTo(maskWidth, curveStartY);
path.cubicTo(
maskWidth,
(float) (curveStartY - waveVerticalRadius * 0.1346194756),
(float) (maskWidth - waveHorizontalRadius * 0.05341339583),
(float) (curveStartY - waveVerticalRadius * 0.2412779634),
(float) (maskWidth - waveHorizontalRadius * 0.1561501458),
(float) (curveStartY - waveVerticalRadius * 0.3322374268)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.2361659167),
(float) (curveStartY - waveVerticalRadius * 0.4030805244),
(float) (maskWidth - waveHorizontalRadius * 0.3305285625),
(float) (curveStartY - waveVerticalRadius * 0.4561193293),
(float) (maskWidth - waveHorizontalRadius * 0.5012484792),
(float) (curveStartY - waveVerticalRadius * 0.5350576951)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.515878125),
(float) (curveStartY - waveVerticalRadius * 0.5418222317),
(float) (maskWidth - waveHorizontalRadius * 0.5664134792),
(float) (curveStartY - waveVerticalRadius * 0.5650349878),
(float) (maskWidth - waveHorizontalRadius * 0.574934875),
(float) (curveStartY - waveVerticalRadius * 0.5689655122)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.7283715208),
(float) (curveStartY - waveVerticalRadius * 0.6397387195),
(float) (maskWidth - waveHorizontalRadius * 0.8086618958),
(float) (curveStartY - waveVerticalRadius * 0.6833456585),
(float) (maskWidth - waveHorizontalRadius * 0.8774032292),
(float) (curveStartY - waveVerticalRadius * 0.7399037439)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.9653464583),
(float) (curveStartY - waveVerticalRadius * 0.8122605122),
maskWidth - waveHorizontalRadius,
(float) (curveStartY - waveVerticalRadius * 0.8936183659),
maskWidth - waveHorizontalRadius, curveStartY - waveVerticalRadius
);
path.cubicTo(
maskWidth - waveHorizontalRadius,
(float) (curveStartY - waveVerticalRadius * 1.100142878),
(float) (maskWidth - waveHorizontalRadius * 0.9595746667),
(float) (curveStartY - waveVerticalRadius * 1.1887991951),
(float) (maskWidth - waveHorizontalRadius * 0.8608411667),
(float) (curveStartY - waveVerticalRadius * 1.270484439)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.7852123333),
(float) (curveStartY - waveVerticalRadius * 1.3330544756),
(float) (maskWidth - waveHorizontalRadius * 0.703382125),
(float) (curveStartY - waveVerticalRadius * 1.3795848049),
(float) (maskWidth - waveHorizontalRadius * 0.5291125625),
(float) (curveStartY - waveVerticalRadius * 1.4665102805)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.5241858333),
(float) (curveStartY - waveVerticalRadius * 1.4689677195),
(float) (maskWidth - waveHorizontalRadius * 0.505739125),
(float) (curveStartY - waveVerticalRadius * 1.4781625854),
(float) (maskWidth - waveHorizontalRadius * 0.5015305417),
(float) (curveStartY - waveVerticalRadius * 1.4802616098)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.3187486042),
(float) (curveStartY - waveVerticalRadius * 1.5714239024),
(float) (maskWidth - waveHorizontalRadius * 0.2332057083),
(float) (curveStartY - waveVerticalRadius * 1.6204116463),
(float) (maskWidth - waveHorizontalRadius * 0.1541165417),
(float) (curveStartY - waveVerticalRadius * 1.687403)
);
path.cubicTo(
(float) (maskWidth - waveHorizontalRadius * 0.0509933125),
(float) (curveStartY - waveVerticalRadius * 1.774752061),
maskWidth, (float) (curveStartY - waveVerticalRadius * 1.8709256829),
maskWidth, curveStartY - waveVerticalRadius * 2
);
path.lineTo(maskWidth, 0f);
//
path.close();
}
float initialSideWidth = 0f;
float initialHorizontalRadius = 0f;
Path mPath = new Path();
Region.Op mRegionOp = Op.INTERSECT;
float sideWidth = 0f;
float waveCenterY = 0f;
float waveHorizontalRadius = 0f;
float waveVerticalRadius = 0f;
float getSideWidth(float percent, View view) {
float p1 = 0.2f;
float p2 = 0.8f;
if (percent <= p1) {
return initialSideWidth;
}
if (percent >= p2) {
return (float)view.getWidth();
}
return initialSideWidth + (view.getWidth() - initialSideWidth) * ((percent - p1) / (p2 - p1));
}
float getWaveHorRadius(float percent, View view) {
if (percent <= 0) {
return initialHorizontalRadius;
}
if (percent >= 1) {
return 0f;
}
float p1 = 0.4f;
if (percent <= p1) {
return initialHorizontalRadius + percent / p1 * (getMaxHorizontalRadius(view) - initialHorizontalRadius);
}
float t = (float) ((percent - p1) / (1.0 - p1));
float A = getMaxHorizontalRadius(view);
float r = 40f;
float m = 9.8f;
float beta = r / (2 * m);
float k = 50f;
float omega0 = k / m;
// float omega = (-beta.pow(2) + omega0.pow(2)).pow(0.5f);
float omega = (float) (-Math.pow(beta, 2) + Math.pow(Math.pow(omega0, 2), 0.5f));
return (float) (A * Math.exp(-beta * t) * Math.cos(omega * t));
}
float getMaxHorizontalRadius(View view) {
return ((float)view.getWidth()) * 0.8f;
}
float initialVerticalRadius = 82;
float getWaveVertRadius(float percent, View view) {
float p1 = 0.4f;
if (percent <= 0) {
return initialVerticalRadius;
}
if (percent >= p1) {
return getMaxVerticalRadius(view);
}
return initialVerticalRadius + (getMaxVerticalRadius(view) - initialVerticalRadius) * percent / p1;
}
float getMaxVerticalRadius(View view) {
return ((float)view.getHeight()) * 0.9f;
}
}
Android
1
https://gitee.com/hailongqiu/OpenDemo.git
git@gitee.com:hailongqiu/OpenDemo.git
hailongqiu
OpenDemo
OpenDemo
6712a2432900e9feb1f983a26c11e2517daf13c9

搜索帮助