Update demo transformer app with bitmap overlay demo effect.
Implements milestone 1.4.1 of the [overlays implementation plan](https://docs.google.com/document/d/1EcP2GN8k8N74hHZyD0KTqm9oQo5-W1dZMqIVyqVGtlo/edit#bookmark=id.76uzcie1dg9d) PiperOrigin-RevId: 493291813
This commit is contained in:
parent
feb3b0b919
commit
49c49b34fb
@ -29,6 +29,7 @@ import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -86,6 +87,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
public static final String HSL_ADJUSTMENTS_HUE = "hsl_adjustments_hue";
|
||||
public static final String HSL_ADJUSTMENTS_SATURATION = "hsl_adjustments_saturation";
|
||||
public static final String HSL_ADJUSTMENTS_LIGHTNESS = "hsl_adjustments_lightness";
|
||||
public static final String BITMAP_OVERLAY_URI = "bitmap_overlay_uri";
|
||||
public static final String BITMAP_OVERLAY_ALPHA = "bitmap_overlay_alpha";
|
||||
public static final int COLOR_FILTER_GRAYSCALE = 0;
|
||||
public static final int COLOR_FILTER_INVERTED = 1;
|
||||
public static final int COLOR_FILTER_SEPIA = 2;
|
||||
@ -139,6 +142,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
"3D spin",
|
||||
"Overlay logo & timer",
|
||||
"Zoom in start",
|
||||
"Custom Bitmap Overlay",
|
||||
};
|
||||
private static final ImmutableMap<String, @TransformationRequest.HdrMode Integer>
|
||||
HDR_MODE_DESCRIPTIONS =
|
||||
@ -155,6 +159,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
private static final int HSL_ADJUSTMENT_INDEX = 5;
|
||||
private static final int CONTRAST_INDEX = 6;
|
||||
private static final int PERIODIC_VIGNETTE_INDEX = 7;
|
||||
private static final int BITMAP_OVERLAY_INDEX = 11;
|
||||
private static final float HALF_DIAGONAL = 1f / (float) Math.sqrt(2);
|
||||
|
||||
private @MonotonicNonNull ActivityResultLauncher<Intent> localFilePickerLauncher;
|
||||
@ -195,6 +200,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
private float periodicVignetteCenterY;
|
||||
private float periodicVignetteInnerRadius;
|
||||
private float periodicVignetteOuterRadius;
|
||||
private @MonotonicNonNull String bitmapOverlayUri;
|
||||
private float bitmapOverlayAlpha;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -398,6 +405,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
bundle.putFloat(PERIODIC_VIGNETTE_CENTER_Y, periodicVignetteCenterY);
|
||||
bundle.putFloat(PERIODIC_VIGNETTE_INNER_RADIUS, periodicVignetteInnerRadius);
|
||||
bundle.putFloat(PERIODIC_VIGNETTE_OUTER_RADIUS, periodicVignetteOuterRadius);
|
||||
bundle.putString(BITMAP_OVERLAY_URI, bitmapOverlayUri);
|
||||
bundle.putFloat(BITMAP_OVERLAY_ALPHA, bitmapOverlayAlpha);
|
||||
transformerIntent.putExtras(bundle);
|
||||
|
||||
@Nullable Uri intentUri;
|
||||
@ -527,6 +536,9 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
case PERIODIC_VIGNETTE_INDEX:
|
||||
controlPeriodicVignetteSettings();
|
||||
break;
|
||||
case BITMAP_OVERLAY_INDEX:
|
||||
controlBitmapOverlaySettings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,6 +641,24 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
||||
.show();
|
||||
}
|
||||
|
||||
private void controlBitmapOverlaySettings() {
|
||||
View dialogView =
|
||||
getLayoutInflater().inflate(R.layout.bitmap_overlay_options, /* root= */ null);
|
||||
EditText uriEditText = checkNotNull(dialogView.findViewById(R.id.bitmap_overlay_uri));
|
||||
Slider alphaSlider = checkNotNull(dialogView.findViewById(R.id.bitmap_overlay_alpha_slider));
|
||||
new AlertDialog.Builder(/* context= */ this)
|
||||
.setTitle(R.string.bitmap_overlay_settings)
|
||||
.setView(dialogView)
|
||||
.setPositiveButton(
|
||||
android.R.string.ok,
|
||||
(DialogInterface dialogInterface, int i) -> {
|
||||
bitmapOverlayUri = uriEditText.getText().toString();
|
||||
bitmapOverlayAlpha = alphaSlider.getValue();
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
@RequiresNonNull({
|
||||
"removeVideoCheckbox",
|
||||
"forceSilentAudioCheckbox",
|
||||
|
@ -44,10 +44,13 @@ import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.audio.AudioProcessor;
|
||||
import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.effect.BitmapOverlay;
|
||||
import androidx.media3.effect.Contrast;
|
||||
import androidx.media3.effect.GlEffect;
|
||||
import androidx.media3.effect.GlTextureProcessor;
|
||||
import androidx.media3.effect.HslAdjustment;
|
||||
import androidx.media3.effect.OverlayEffect;
|
||||
import androidx.media3.effect.OverlaySettings;
|
||||
import androidx.media3.effect.RgbAdjustment;
|
||||
import androidx.media3.effect.RgbFilter;
|
||||
import androidx.media3.effect.RgbMatrix;
|
||||
@ -491,6 +494,20 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
if (selectedEffects[10]) {
|
||||
effects.add(MatrixTransformationFactory.createZoomInTransition());
|
||||
}
|
||||
if (selectedEffects[11]) {
|
||||
OverlaySettings overlaySettings =
|
||||
new OverlaySettings.Builder()
|
||||
.setAlpha(
|
||||
bundle.getFloat(
|
||||
ConfigurationActivity.BITMAP_OVERLAY_ALPHA, /* defaultValue= */ 1))
|
||||
.build();
|
||||
|
||||
BitmapOverlay bitmapOverlay =
|
||||
BitmapOverlay.createStaticBitmapOverlay(
|
||||
Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))),
|
||||
overlaySettings);
|
||||
effects.add(new OverlayEffect(ImmutableList.of(bitmapOverlay)));
|
||||
}
|
||||
return effects.build();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
tools:context=".ConfigurationActivity">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="1"
|
||||
android:layout_marginTop="32dp"
|
||||
android:measureWithLargestChild="true"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="12dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
<TableRow
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical" >
|
||||
<TextView
|
||||
android:text="@string/overlay_uri" />
|
||||
<EditText
|
||||
android:id="@+id/bitmap_overlay_uri"
|
||||
android:inputType="textUri|textMultiLine"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
</TableRow>
|
||||
<TableRow
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical" >
|
||||
<TextView android:text="@string/overlay_alpha" />
|
||||
<com.google.android.material.slider.Slider
|
||||
android:id="@+id/bitmap_overlay_alpha_slider"
|
||||
android:valueFrom="0"
|
||||
android:value="1"
|
||||
android:valueTo="1"
|
||||
android:layout_gravity="right|center_vertical"/>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -67,4 +67,7 @@
|
||||
<string name="hide_input_video">Hide input video</string>
|
||||
<string name="show_input_video">Show input video</string>
|
||||
<string name="force_silent_audio">Force silent audio</string>
|
||||
<string name="overlay_alpha">Alpha</string>
|
||||
<string name="overlay_uri">Uri</string>
|
||||
<string name="bitmap_overlay_settings">Specify bitmap overlay settings</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user