Skip to content

Commit

Permalink
[BottomSheet] Recycle the TypedArray after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pubiqq committed Feb 6, 2024
1 parent 8921204 commit f9ac4cf
Showing 1 changed file with 12 additions and 17 deletions.
Expand Up @@ -90,38 +90,33 @@ public class BottomSheetDialog extends AppCompatDialog {

public BottomSheetDialog(@NonNull Context context) {
this(context, 0);

edgeToEdgeEnabled =
getContext()
.getTheme()
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
.getBoolean(0, false);
initialize();
}

public BottomSheetDialog(@NonNull Context context, @StyleRes int theme) {
super(context, getThemeResId(context, theme));
// We hide the title bar for any style configuration. Otherwise, there will be a gap
// above the bottom sheet when it is expanded.
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

edgeToEdgeEnabled =
getContext()
.getTheme()
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
.getBoolean(0, false);
initialize();
}

protected BottomSheetDialog(
@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
this.cancelable = cancelable;
initialize();
}

private void initialize() {
final TypedArray a = getContext()
.getTheme()
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge});

edgeToEdgeEnabled = a.getBoolean(0, false);

edgeToEdgeEnabled =
getContext()
.getTheme()
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
.getBoolean(0, false);
a.recycle();
}

@Override
Expand Down

0 comments on commit f9ac4cf

Please sign in to comment.