[*] 删除预览视频复用布局
This commit is contained in:
@@ -15,6 +15,7 @@ import android.os.Message;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.GridLayout;
|
import android.widget.GridLayout;
|
||||||
@@ -33,6 +34,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.RandomUtils;
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private MainHandler mainHandler;
|
private MainHandler mainHandler;
|
||||||
private ActivityMainBinding binding;
|
private ActivityMainBinding binding;
|
||||||
private MediaProjectionManager mediaProjectionManager;
|
private MediaProjectionManager mediaProjectionManager;
|
||||||
|
private List<ViewGroup.LayoutParams> removeLayoutParams;
|
||||||
private ActivityResultLauncher<Intent> activityResultLauncher;
|
private ActivityResultLauncher<Intent> activityResultLauncher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,6 +74,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
this.binding.record.setOnClickListener(this::record);
|
this.binding.record.setOnClickListener(this::record);
|
||||||
this.binding.settings.setOnClickListener(this::settings);
|
this.binding.settings.setOnClickListener(this::settings);
|
||||||
this.binding.photograph.setOnClickListener(this::photograph);
|
this.binding.photograph.setOnClickListener(this::photograph);
|
||||||
|
this.removeLayoutParams = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -293,26 +298,34 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
*
|
*
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
*/
|
*/
|
||||||
private synchronized void previewVideo(Message message) {
|
private void previewVideo(Message message) {
|
||||||
|
synchronized (this) {
|
||||||
final GridLayout video = this.binding.video;
|
final GridLayout video = this.binding.video;
|
||||||
final int count = video.getChildCount();
|
final int count = video.getChildCount();
|
||||||
final GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(
|
final ViewGroup.LayoutParams layoutParams;
|
||||||
|
if(this.removeLayoutParams.isEmpty()) {
|
||||||
|
layoutParams = new GridLayout.LayoutParams(
|
||||||
GridLayout.spec(count / 2, 1.0F),
|
GridLayout.spec(count / 2, 1.0F),
|
||||||
GridLayout.spec(count % 2, 1.0F)
|
GridLayout.spec(count % 2, 1.0F)
|
||||||
);
|
);
|
||||||
layoutParams.width = 0;
|
layoutParams.width = 0;
|
||||||
layoutParams.height = 0;
|
layoutParams.height = 0;
|
||||||
|
} else {
|
||||||
|
layoutParams = this.removeLayoutParams.remove(0);
|
||||||
|
}
|
||||||
final SurfaceView surfaceView = (SurfaceView) message.obj;
|
final SurfaceView surfaceView = (SurfaceView) message.obj;
|
||||||
surfaceView.setZ(0F);
|
surfaceView.setZ(0F);
|
||||||
video.addView(surfaceView, layoutParams);
|
video.addView(surfaceView, layoutParams);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除视频预览
|
* 移除视频预览
|
||||||
*
|
*
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
*/
|
*/
|
||||||
private synchronized void removePreviewVideo(Message message) {
|
private void removePreviewVideo(Message message) {
|
||||||
|
synchronized (this) {
|
||||||
final GridLayout video = this.binding.video;
|
final GridLayout video = this.binding.video;
|
||||||
final SurfaceView surfaceView = (SurfaceView) message.obj;
|
final SurfaceView surfaceView = (SurfaceView) message.obj;
|
||||||
final int index = video.indexOfChild(surfaceView);
|
final int index = video.indexOfChild(surfaceView);
|
||||||
@@ -320,6 +333,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
video.removeViewAt(index);
|
video.removeViewAt(index);
|
||||||
|
this.removeLayoutParams.add(surfaceView.getLayoutParams());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user