Tidy passing views in transformer demos

PiperOrigin-RevId: 641891515
This commit is contained in:
andrewlewis 2024-06-10 07:15:06 -07:00 committed by Copybara-Service
parent cc046d5ce7
commit 34966f5d86
3 changed files with 20 additions and 23 deletions

View File

@ -18,7 +18,6 @@ package androidx.media3.demo.composition;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -83,8 +82,8 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
setContentView(R.layout.composition_preview_activity); setContentView(R.layout.composition_preview_activity);
playerView = findViewById(R.id.composition_player_view); playerView = findViewById(R.id.composition_player_view);
findViewById(R.id.preview_button).setOnClickListener(this::previewComposition); findViewById(R.id.preview_button).setOnClickListener(view -> previewComposition());
findViewById(R.id.edit_sequence_button).setOnClickListener(this::selectPreset); findViewById(R.id.edit_sequence_button).setOnClickListener(view -> selectPreset());
RecyclerView presetList = findViewById(R.id.composition_preset_list); RecyclerView presetList = findViewById(R.id.composition_preset_list);
presetList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); presetList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
LinearLayoutManager layoutManager = LinearLayoutManager layoutManager =
@ -93,7 +92,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
exportInformationTextView = findViewById(R.id.export_information_text); exportInformationTextView = findViewById(R.id.export_information_text);
exportButton = findViewById(R.id.composition_export_button); exportButton = findViewById(R.id.composition_export_button);
exportButton.setOnClickListener(this::exportComposition); exportButton.setOnClickListener(view -> exportComposition());
presetDescriptions = getResources().getStringArray(R.array.preset_descriptions); presetDescriptions = getResources().getStringArray(R.array.preset_descriptions);
// Select two media items by default. // Select two media items by default.
@ -171,7 +170,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
.build(); .build();
} }
private void previewComposition(View view) { private void previewComposition() {
releasePlayer(); releasePlayer();
Composition composition = prepareComposition(); Composition composition = prepareComposition();
playerView.setPlayer(null); playerView.setPlayer(null);
@ -194,7 +193,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
player.play(); player.play();
} }
private void selectPreset(View view) { private void selectPreset() {
new AlertDialog.Builder(/* context= */ this) new AlertDialog.Builder(/* context= */ this)
.setTitle(R.string.select_preset_title) .setTitle(R.string.select_preset_title)
.setMultiChoiceItems(presetDescriptions, selectedMediaItems, this::selectPresetInDialog) .setMultiChoiceItems(presetDescriptions, selectedMediaItems, this::selectPresetInDialog)
@ -217,7 +216,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
} }
} }
private void exportComposition(View view) { private void exportComposition() {
// Cancel and clean up files from any ongoing export. // Cancel and clean up files from any ongoing export.
cancelExport(); cancelExport();

View File

@ -206,7 +206,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.configuration_activity); setContentView(R.layout.configuration_activity);
findViewById(R.id.export_button).setOnClickListener(this::startExport); findViewById(R.id.export_button).setOnClickListener(view -> startExport());
videoLocalFilePickerLauncher = videoLocalFilePickerLauncher =
registerForActivityResult( registerForActivityResult(
@ -218,7 +218,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
this::overlayLocalFilePickerLauncherResult); this::overlayLocalFilePickerLauncherResult);
selectPresetFileButton = findViewById(R.id.select_preset_file_button); selectPresetFileButton = findViewById(R.id.select_preset_file_button);
selectPresetFileButton.setOnClickListener(this::selectPresetFile); selectPresetFileButton.setOnClickListener(view -> selectPresetFile());
selectLocalFileButton = findViewById(R.id.select_local_file_button); selectLocalFileButton = findViewById(R.id.select_local_file_button);
selectLocalFileButton.setOnClickListener( selectLocalFileButton.setOnClickListener(
@ -286,7 +286,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
rotateAdapter.addAll(SAME_AS_INPUT_OPTION, "0", "10", "45", "60", "90", "180"); rotateAdapter.addAll(SAME_AS_INPUT_OPTION, "0", "10", "45", "60", "90", "180");
trimCheckBox = findViewById(R.id.trim_checkbox); trimCheckBox = findViewById(R.id.trim_checkbox);
trimCheckBox.setOnCheckedChangeListener(this::selectTrimBounds); trimCheckBox.setOnCheckedChangeListener((view, isChecked) -> selectTrimBounds(isChecked));
trimStartMs = C.TIME_UNSET; trimStartMs = C.TIME_UNSET;
trimEndMs = C.TIME_UNSET; trimEndMs = C.TIME_UNSET;
@ -310,14 +310,12 @@ public final class ConfigurationActivity extends AppCompatActivity {
String[] audioEffectsNames = getResources().getStringArray(R.array.audio_effects_names); String[] audioEffectsNames = getResources().getStringArray(R.array.audio_effects_names);
audioEffectsSelections = new boolean[audioEffectsNames.length]; audioEffectsSelections = new boolean[audioEffectsNames.length];
selectAudioEffectsButton = findViewById(R.id.select_audio_effects_button); selectAudioEffectsButton = findViewById(R.id.select_audio_effects_button);
selectAudioEffectsButton.setOnClickListener( selectAudioEffectsButton.setOnClickListener(view -> selectAudioEffects(audioEffectsNames));
view -> selectAudioEffects(view, audioEffectsNames));
String[] videoEffectsNames = getResources().getStringArray(R.array.video_effects_names); String[] videoEffectsNames = getResources().getStringArray(R.array.video_effects_names);
videoEffectsSelections = new boolean[videoEffectsNames.length]; videoEffectsSelections = new boolean[videoEffectsNames.length];
selectVideoEffectsButton = findViewById(R.id.select_video_effects_button); selectVideoEffectsButton = findViewById(R.id.select_video_effects_button);
selectVideoEffectsButton.setOnClickListener( selectVideoEffectsButton.setOnClickListener(view -> selectVideoEffects(videoEffectsNames));
view -> selectVideoEffects(view, videoEffectsNames));
} }
@Override @Override
@ -353,7 +351,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
setIntent(intent); setIntent(intent);
} }
private void startExport(View view) { private void startExport() {
Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class); Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean(SHOULD_REMOVE_AUDIO, removeAudioCheckbox.isChecked()); bundle.putBoolean(SHOULD_REMOVE_AUDIO, removeAudioCheckbox.isChecked());
@ -429,7 +427,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
startActivity(transformerIntent); startActivity(transformerIntent);
} }
private void selectPresetFile(View view) { private void selectPresetFile() {
new AlertDialog.Builder(/* context= */ this) new AlertDialog.Builder(/* context= */ this)
.setTitle(R.string.select_preset_file_title) .setTitle(R.string.select_preset_file_title)
.setSingleChoiceItems( .setSingleChoiceItems(
@ -493,7 +491,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
} }
} }
private void selectAudioEffects(View view, String[] audioEffectsNames) { private void selectAudioEffects(String[] audioEffectsNames) {
new AlertDialog.Builder(/* context= */ this) new AlertDialog.Builder(/* context= */ this)
.setTitle(R.string.select_audio_effects) .setTitle(R.string.select_audio_effects)
.setMultiChoiceItems(audioEffectsNames, audioEffectsSelections, this::selectAudioEffect) .setMultiChoiceItems(audioEffectsNames, audioEffectsSelections, this::selectAudioEffect)
@ -502,7 +500,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
.show(); .show();
} }
private void selectVideoEffects(View view, String[] videoEffectsNames) { private void selectVideoEffects(String[] videoEffectsNames) {
new AlertDialog.Builder(/* context= */ this) new AlertDialog.Builder(/* context= */ this)
.setTitle(R.string.select_video_effects) .setTitle(R.string.select_video_effects)
.setMultiChoiceItems(videoEffectsNames, videoEffectsSelections, this::selectVideoEffect) .setMultiChoiceItems(videoEffectsNames, videoEffectsSelections, this::selectVideoEffect)
@ -511,7 +509,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
.show(); .show();
} }
private void selectTrimBounds(View view, boolean isChecked) { private void selectTrimBounds(boolean isChecked) {
if (!isChecked) { if (!isChecked) {
return; return;
} }

View File

@ -158,12 +158,12 @@ public final class TransformerActivity extends AppCompatActivity {
progressViewGroup = findViewById(R.id.progress_view_group); progressViewGroup = findViewById(R.id.progress_view_group);
progressIndicator = findViewById(R.id.progress_indicator); progressIndicator = findViewById(R.id.progress_indicator);
cancelButton = findViewById(R.id.cancel_button); cancelButton = findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(this::cancelExport); cancelButton.setOnClickListener(view -> cancelExport());
resumeButton = findViewById(R.id.resume_button); resumeButton = findViewById(R.id.resume_button);
resumeButton.setOnClickListener(view -> startExport()); resumeButton.setOnClickListener(view -> startExport());
debugFrame = findViewById(R.id.debug_aspect_ratio_frame_layout); debugFrame = findViewById(R.id.debug_aspect_ratio_frame_layout);
displayInputButton = findViewById(R.id.display_input_button); displayInputButton = findViewById(R.id.display_input_button);
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay); displayInputButton.setOnClickListener(view -> toggleInputVideoDisplay());
exportStopwatch = exportStopwatch =
Stopwatch.createUnstarted( Stopwatch.createUnstarted(
@ -783,7 +783,7 @@ public final class TransformerActivity extends AppCompatActivity {
Toast.makeText(getApplicationContext(), getString(messageResource), Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), getString(messageResource), Toast.LENGTH_LONG).show();
} }
private void toggleInputVideoDisplay(View view) { private void toggleInputVideoDisplay() {
if (inputCardView.getVisibility() == View.GONE) { if (inputCardView.getVisibility() == View.GONE) {
inputCardView.setVisibility(View.VISIBLE); inputCardView.setVisibility(View.VISIBLE);
displayInputButton.setText(getString(R.string.hide_input_video)); displayInputButton.setText(getString(R.string.hide_input_video));
@ -796,7 +796,7 @@ public final class TransformerActivity extends AppCompatActivity {
} }
} }
private void cancelExport(View view) { private void cancelExport() {
transformer.cancel(); transformer.cancel();
transformer = null; transformer = null;
exportStopwatch.stop(); exportStopwatch.stop();