Skip to content

Commit 216a429

Browse files
runningcodeclaude
andcommitted
ref(feedback): Use the dialog theme as the form's default
Drop resolveTheme so the form follows Dialog's default of android:dialogTheme. Showing the form under both themes in Robolectric gave the same width in portrait and landscape, so the only differences left are the window animation on DeviceDefault themes and apps that customize android:alertDialogTheme, which the changelog now covers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent adc7f95 commit 216a429

3 files changed

Lines changed: 16 additions & 47 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- See the [Navigation for Android docs](https://docs.sentry.io/platforms/android/integrations/navigation/#supported-setups) for a detailed list of supported vs unsupported app setups.
5353
- `SentryUserFeedbackForm` now extends `android.app.Dialog` instead of `android.app.AlertDialog` ([#6338](https://github.com/getsentry/sentry-java/pull/6338))
5454
- The form never used `AlertDialog` features. Code that calls `AlertDialog`-only methods on it, such as `setButton` or `setMessage`, no longer compiles.
55+
- Without an explicit theme, the form now uses your theme's `android:dialogTheme` instead of `android:alertDialogTheme`. If you styled the form through `android:alertDialogTheme`, pass that theme to `SentryUserFeedbackForm.Builder(context, themeResId)` instead.
5556

5657
### Fixes
5758

‎sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackForm.java‎

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.net.Uri;
1111
import android.os.Bundle;
1212
import android.provider.OpenableColumns;
13-
import android.util.TypedValue;
1413
import android.view.View;
1514
import android.webkit.MimeTypeMap;
1615
import android.widget.Button;
@@ -59,7 +58,7 @@ public class SentryUserFeedbackForm extends Dialog {
5958
final @Nullable SentryId associatedEventId,
6059
final @Nullable OptionsConfiguration configuration,
6160
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
62-
super(context, resolveTheme(context, themeResId));
61+
super(context, themeResId);
6362
this.associatedEventId = associatedEventId;
6463
final @NotNull SentryOptions options = Sentry.getCurrentScopes().getOptions();
6564
@NotNull
@@ -210,19 +209,6 @@ public void onActivitySaveInstanceState(
210209
final @NotNull Activity activity, final @NotNull Bundle outState) {}
211210
}
212211

213-
/**
214-
* {@link Dialog} falls back to {@link android.R.attr#dialogTheme} for {@code 0}, but the form has
215-
* always defaulted to {@link android.R.attr#alertDialogTheme}, as {@code AlertDialog} does.
216-
*/
217-
static int resolveTheme(final @NotNull Context context, final int themeResId) {
218-
if (themeResId != 0) {
219-
return themeResId;
220-
}
221-
final @NotNull TypedValue outValue = new TypedValue();
222-
context.getTheme().resolveAttribute(android.R.attr.alertDialogTheme, outValue, true);
223-
return outValue.resourceId;
224-
}
225-
226212
@Override
227213
public void setCancelable(boolean cancelable) {
228214
super.setCancelable(cancelable);
@@ -671,11 +657,10 @@ public static class Builder {
671657
final int themeResId;
672658

673659
/**
674-
* Creates a builder for a {@link SentryUserFeedbackForm} that uses the default alert dialog
675-
* theme.
660+
* Creates a builder for a {@link SentryUserFeedbackForm} that uses the default dialog theme.
676661
*
677-
* <p>The default alert dialog theme is defined by {@link android.R.attr#alertDialogTheme}
678-
* within the parent {@code context}'s theme.
662+
* <p>The default dialog theme is defined by {@link android.R.attr#dialogTheme} within the
663+
* parent {@code context}'s theme.
679664
*
680665
* @param context the parent context
681666
*/
@@ -694,26 +679,26 @@ public Builder(final @NotNull Context context) {
694679
* <p>To preserve attributes such as primary and accent colors, the {@code themeResId} may
695680
* instead be specified as an overlay theme such as {@link
696681
* android.R.style#ThemeOverlay_Material_Dialog}. This will override only the window attributes
697-
* necessary to style the alert window as a dialog.
682+
* necessary to style the window as a dialog.
698683
*
699684
* <p>Alternatively, the {@code themeResId} may be specified as {@code 0} to use the parent
700-
* {@code context}'s resolved value for {@link android.R.attr#alertDialogTheme}.
685+
* {@code context}'s resolved value for {@link android.R.attr#dialogTheme}.
701686
*
702687
* @param context the parent context
703688
* @param themeResId the resource ID of the theme against which to inflate this dialog, or
704-
* {@code 0} to use the parent {@code context}'s default alert dialog theme
689+
* {@code 0} to use the parent {@code context}'s default dialog theme
705690
*/
706691
public Builder(Context context, int themeResId) {
707692
this(context, themeResId, null);
708693
}
709694

710695
/**
711-
* Creates a builder for a {@link SentryUserFeedbackForm} that uses the default alert dialog
712-
* theme. The {@code configuration} can be used to configure the feedback options for this
713-
* specific dialog.
696+
* Creates a builder for a {@link SentryUserFeedbackForm} that uses the default dialog theme.
697+
* The {@code configuration} can be used to configure the feedback options for this specific
698+
* dialog.
714699
*
715-
* <p>The default alert dialog theme is defined by {@link android.R.attr#alertDialogTheme}
716-
* within the parent {@code context}'s theme.
700+
* <p>The default dialog theme is defined by {@link android.R.attr#dialogTheme} within the
701+
* parent {@code context}'s theme.
717702
*
718703
* @param context the parent context
719704
* @param configuration the configuration for the feedback options, can be {@code null} to use
@@ -737,14 +722,14 @@ public Builder(
737722
* <p>To preserve attributes such as primary and accent colors, the {@code themeResId} may
738723
* instead be specified as an overlay theme such as {@link
739724
* android.R.style#ThemeOverlay_Material_Dialog}. This will override only the window attributes
740-
* necessary to style the alert window as a dialog.
725+
* necessary to style the window as a dialog.
741726
*
742727
* <p>Alternatively, the {@code themeResId} may be specified as {@code 0} to use the parent
743-
* {@code context}'s resolved value for {@link android.R.attr#alertDialogTheme}.
728+
* {@code context}'s resolved value for {@link android.R.attr#dialogTheme}.
744729
*
745730
* @param context the parent context
746731
* @param themeResId the resource ID of the theme against which to inflate this dialog, or
747-
* {@code 0} to use the parent {@code context}'s default alert dialog theme
732+
* {@code 0} to use the parent {@code context}'s default dialog theme
748733
* @param configuration the configuration for the feedback options, can be {@code null} to use
749734
* the global feedback options.
750735
*/

‎sentry-android-core/src/test/java/io/sentry/android/core/SentryUserFeedbackFormTest.kt‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.database.Cursor
1010
import android.net.Uri
1111
import android.os.Looper
1212
import android.provider.OpenableColumns
13-
import android.view.ContextThemeWrapper
1413
import android.view.View
1514
import android.view.WindowManager
1615
import android.widget.Button
@@ -245,22 +244,6 @@ class SentryUserFeedbackFormTest {
245244
assertEquals(0, flags and WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
246245
}
247246

248-
@Test
249-
fun `default theme resolves to the context's alert dialog theme`() {
250-
val context = ContextThemeWrapper(fixture.application, android.R.style.Theme_Material_Light)
251-
252-
assertThat(SentryUserFeedbackForm.resolveTheme(context, 0))
253-
.isEqualTo(android.R.style.Theme_Material_Light_Dialog_Alert)
254-
}
255-
256-
@Test
257-
fun `explicit theme is used as is`() {
258-
val context = ContextThemeWrapper(fixture.application, android.R.style.Theme_Material_Light)
259-
260-
assertThat(SentryUserFeedbackForm.resolveTheme(context, android.R.style.Theme_Material_Dialog))
261-
.isEqualTo(android.R.style.Theme_Material_Dialog)
262-
}
263-
264247
@Test
265248
fun `a crashing onFormClose callback does not crash the app when the dialog is closed`() {
266249
fixture.options.isEnabled = true

0 commit comments

Comments
 (0)