Commit 34f31a2e authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Revert "Use try-with-resources"

Causes crash on lower APIs (no method close in TypedArray)

This reverts commit 20b3763c.
parent 92d20848
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -60,12 +60,13 @@ class ListWithEditTextPreference extends ListPreference implements Preference.On

    }

    @SuppressWarnings("resource")
    // Don't use auto-closable, breaks lower APIs
    private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        setOnPreferenceChangeListener(this);
        try (TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ListWithEditTextPreference,
                defStyleAttr, defStyleRes)) {
            otherSummary = attributes.getText(R.styleable.ListWithEditTextPreference_otherSummary);
        }
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListWithEditTextPreference, defStyleAttr, defStyleRes);
        otherSummary = a.getText(R.styleable.ListWithEditTextPreference_otherSummary);
        a.recycle();
    }


+6 −4
Original line number Diff line number Diff line
@@ -123,15 +123,17 @@ public class ProviderPreferenceDialogFragment extends ListPreferenceDialogWithMe
     * Get default layout for single choice dialog
     * @return Layout resource id
     */
    @SuppressWarnings("resource")
    @SuppressLint("PrivateResource")
    // Don't use auto-closable, breaks lower APIs
    private int getSingleChoiceLayoutResource() {
        int resId = android.R.layout.select_dialog_singlechoice;
        final Context context = getContext();
        if (context != null) {
            try (final TypedArray attributes = context.obtainStyledAttributes(null, R.styleable.AlertDialog,
                    R.attr.alertDialogStyle, 0)) {
                resId = attributes.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, resId);
            }
            final TypedArray typedArray = context.obtainStyledAttributes(null, R.styleable.AlertDialog,
                    R.attr.alertDialogStyle, 0);
            resId = typedArray.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, resId);
            typedArray.recycle();
        }
        return resId;
    }