mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add button to show/hide input player in TransformerActivity
PiperOrigin-RevId: 479003655
This commit is contained in:
parent
278853a2a1
commit
50df923b25
@ -31,6 +31,7 @@ import android.view.SurfaceHolder;
|
|||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -77,6 +78,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
public final class TransformerActivity extends AppCompatActivity {
|
public final class TransformerActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "TransformerActivity";
|
private static final String TAG = "TransformerActivity";
|
||||||
|
|
||||||
|
private @MonotonicNonNull Button displayInputButton;
|
||||||
private @MonotonicNonNull MaterialCardView inputCardView;
|
private @MonotonicNonNull MaterialCardView inputCardView;
|
||||||
private @MonotonicNonNull PlayerView inputPlayerView;
|
private @MonotonicNonNull PlayerView inputPlayerView;
|
||||||
private @MonotonicNonNull PlayerView outputPlayerView;
|
private @MonotonicNonNull PlayerView outputPlayerView;
|
||||||
@ -106,6 +108,8 @@ 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);
|
||||||
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.setOnClickListener(this::toggleInputVideoDisplay);
|
||||||
|
|
||||||
transformationStopwatch =
|
transformationStopwatch =
|
||||||
Stopwatch.createUnstarted(
|
Stopwatch.createUnstarted(
|
||||||
@ -130,6 +134,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
checkNotNull(debugTextView);
|
checkNotNull(debugTextView);
|
||||||
checkNotNull(progressViewGroup);
|
checkNotNull(progressViewGroup);
|
||||||
checkNotNull(debugFrame);
|
checkNotNull(debugFrame);
|
||||||
|
checkNotNull(displayInputButton);
|
||||||
startTransformation();
|
startTransformation();
|
||||||
|
|
||||||
inputPlayerView.onResume();
|
inputPlayerView.onResume();
|
||||||
@ -159,6 +164,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
"inputCardView",
|
"inputCardView",
|
||||||
"inputPlayerView",
|
"inputPlayerView",
|
||||||
"outputPlayerView",
|
"outputPlayerView",
|
||||||
|
"displayInputButton",
|
||||||
"debugTextView",
|
"debugTextView",
|
||||||
"informationTextView",
|
"informationTextView",
|
||||||
"progressIndicator",
|
"progressIndicator",
|
||||||
@ -228,6 +234,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
"inputCardView",
|
"inputCardView",
|
||||||
"inputPlayerView",
|
"inputPlayerView",
|
||||||
"outputPlayerView",
|
"outputPlayerView",
|
||||||
|
"displayInputButton",
|
||||||
"debugTextView",
|
"debugTextView",
|
||||||
"informationTextView",
|
"informationTextView",
|
||||||
"transformationStopwatch",
|
"transformationStopwatch",
|
||||||
@ -463,6 +470,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
"inputCardView",
|
"inputCardView",
|
||||||
"inputPlayerView",
|
"inputPlayerView",
|
||||||
"outputPlayerView",
|
"outputPlayerView",
|
||||||
|
"displayInputButton",
|
||||||
"debugTextView",
|
"debugTextView",
|
||||||
"informationTextView",
|
"informationTextView",
|
||||||
"progressViewGroup",
|
"progressViewGroup",
|
||||||
@ -478,6 +486,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
debugFrame.removeAllViews();
|
debugFrame.removeAllViews();
|
||||||
inputCardView.setVisibility(View.VISIBLE);
|
inputCardView.setVisibility(View.VISIBLE);
|
||||||
outputPlayerView.setVisibility(View.VISIBLE);
|
outputPlayerView.setVisibility(View.VISIBLE);
|
||||||
|
displayInputButton.setVisibility(View.VISIBLE);
|
||||||
playMediaItems(inputMediaItem, MediaItem.fromUri("file://" + filePath));
|
playMediaItems(inputMediaItem, MediaItem.fromUri("file://" + filePath));
|
||||||
Log.d(TAG, "Output file path: file://" + filePath);
|
Log.d(TAG, "Output file path: file://" + filePath);
|
||||||
}
|
}
|
||||||
@ -540,6 +549,21 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
Toast.makeText(getApplicationContext(), getString(messageResource), Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), getString(messageResource), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull({
|
||||||
|
"inputCardView",
|
||||||
|
"displayInputButton",
|
||||||
|
})
|
||||||
|
private void toggleInputVideoDisplay(View view) {
|
||||||
|
if (inputCardView.getVisibility() == View.GONE) {
|
||||||
|
inputCardView.setVisibility(View.VISIBLE);
|
||||||
|
displayInputButton.setText(getString(R.string.hide_input_video));
|
||||||
|
} else if (inputCardView.getVisibility() == View.VISIBLE) {
|
||||||
|
checkNotNull(inputPlayer).pause();
|
||||||
|
inputCardView.setVisibility(View.GONE);
|
||||||
|
displayInputButton.setText(getString(R.string.show_input_video));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final class DemoDebugViewProvider implements DebugViewProvider {
|
private final class DemoDebugViewProvider implements DebugViewProvider {
|
||||||
|
|
||||||
private @MonotonicNonNull SurfaceView surfaceView;
|
private @MonotonicNonNull SurfaceView surfaceView;
|
||||||
|
@ -29,12 +29,28 @@
|
|||||||
app:cardElevation="2dp"
|
app:cardElevation="2dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical" >
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/information_text_view"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="8dp" />
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/information_text_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="8dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/display_input_button"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hide_input_video"
|
||||||
|
android:layout_margin="8dp" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
@ -61,4 +61,6 @@
|
|||||||
<string name="lightness_adjustment">Lightness adjustment</string>
|
<string name="lightness_adjustment">Lightness adjustment</string>
|
||||||
<string name="input_video">Input video:</string>
|
<string name="input_video">Input video:</string>
|
||||||
<string name="output_video">Output video:</string>
|
<string name="output_video">Output video:</string>
|
||||||
|
<string name="hide_input_video">Hide input video</string>
|
||||||
|
<string name="show_input_video">Show input video</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user