Android/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcCopy.java

39 lines
1.0 KiB
Java
Raw Normal View History

2024-01-24 20:17:59 +08:00
package com.xixun.xixunplayer;
2025-07-28 19:14:00 +08:00
import android.annotation.SuppressLint;
2024-01-24 20:17:59 +08:00
import android.content.Context;
import android.graphics.Canvas;
import android.view.View;
import androidx.annotation.NonNull;
2025-07-28 19:14:00 +08:00
@SuppressLint("ViewConstructor")
2024-01-24 20:17:59 +08:00
public class SrcCopy extends View {
2025-07-28 19:14:00 +08:00
Prog.Source source;
2024-01-24 20:17:59 +08:00
float scaleX = 1, scaleY = 1;
2025-07-28 19:14:00 +08:00
public SrcCopy(Context context, Prog.Source source) {
2024-01-24 20:17:59 +08:00
super(context);
2025-07-28 19:14:00 +08:00
this.source = source;
2024-01-24 20:17:59 +08:00
}
@Override
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
2025-07-28 19:14:00 +08:00
if(source==null || source.view==null) return;
2024-01-24 20:17:59 +08:00
if(scaleX==0) {
2025-07-28 19:14:00 +08:00
if(source.view.getWidth()!=0 && getWidth()!=0) {
scaleX = getWidth() / (float) source.view.getWidth();
scaleY = getHeight() / (float) source.view.getHeight();
2024-01-24 20:17:59 +08:00
} else {
invalidate();
return;
}
}
if(scaleX!=1 || scaleY!=1) canvas.scale(scaleX, scaleY);
2025-07-28 19:14:00 +08:00
source.view.draw(canvas);
2024-01-24 20:17:59 +08:00
invalidate();
}
}