Skip to content

Commit

Permalink
Add button to show/hide input player in TransformerActivity
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 479003655
  • Loading branch information
Googler authored and marcbaechinger committed Oct 20, 2022
1 parent 0208b1b commit 20c1ae1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -77,6 +78,7 @@
public final class TransformerActivity extends AppCompatActivity {
private static final String TAG = "TransformerActivity";

private @MonotonicNonNull Button displayInputButton;
private @MonotonicNonNull MaterialCardView inputCardView;
private @MonotonicNonNull StyledPlayerView inputPlayerView;
private @MonotonicNonNull StyledPlayerView outputPlayerView;
Expand Down Expand Up @@ -106,6 +108,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
progressViewGroup = findViewById(R.id.progress_view_group);
progressIndicator = findViewById(R.id.progress_indicator);
debugFrame = findViewById(R.id.debug_aspect_ratio_frame_layout);
displayInputButton = findViewById(R.id.display_input_button);
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay);

transformationStopwatch =
Stopwatch.createUnstarted(
Expand All @@ -130,6 +134,7 @@ protected void onStart() {
checkNotNull(debugTextView);
checkNotNull(progressViewGroup);
checkNotNull(debugFrame);
checkNotNull(displayInputButton);
startTransformation();

inputPlayerView.onResume();
Expand Down Expand Up @@ -159,6 +164,7 @@ protected void onStop() {
"inputCardView",
"inputPlayerView",
"outputPlayerView",
"displayInputButton",
"debugTextView",
"informationTextView",
"progressIndicator",
Expand Down Expand Up @@ -228,6 +234,7 @@ private MediaItem createMediaItem(@Nullable Bundle bundle, Uri uri) {
"inputCardView",
"inputPlayerView",
"outputPlayerView",
"displayInputButton",
"debugTextView",
"informationTextView",
"transformationStopwatch",
Expand Down Expand Up @@ -464,6 +471,7 @@ private void onTransformationError(TransformationException exception) {
"inputCardView",
"inputPlayerView",
"outputPlayerView",
"displayInputButton",
"debugTextView",
"informationTextView",
"progressViewGroup",
Expand All @@ -479,6 +487,7 @@ private void onTransformationCompleted(String filePath, MediaItem inputMediaItem
debugFrame.removeAllViews();
inputCardView.setVisibility(View.VISIBLE);
outputPlayerView.setVisibility(View.VISIBLE);
displayInputButton.setVisibility(View.VISIBLE);
playMediaItems(inputMediaItem, MediaItem.fromUri("file://" + filePath));
Log.d(TAG, "Output file path: file://" + filePath);
}
Expand Down Expand Up @@ -541,6 +550,21 @@ private void showToast(@StringRes int messageResource) {
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 @MonotonicNonNull SurfaceView surfaceView;
Expand Down
26 changes: 21 additions & 5 deletions demos/transformer/src/main/res/layout/transformer_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@
app:cardElevation="2dp"
android:gravity="center_vertical" >

<TextView
android:id="@+id/information_text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
<LinearLayout
android:layout_width="match_parent"
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>

Expand Down
2 changes: 2 additions & 0 deletions demos/transformer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@
<string name="lightness_adjustment">Lightness adjustment</string>
<string name="input_video">Input 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>

0 comments on commit 20c1ae1

Please sign in to comment.