Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 31479e33 authored by Adam Powell's avatar Adam Powell
Browse files

Remove dependencies on Activity from common Fragment superclasses

Allow common Fragments to be used in non-Activity hosts.

Bug 28337394

Change-Id: Id3baa3ef19ea41ff43ca76be89ced7530fbadfab
parent ca2ce9b7
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -361,8 +361,8 @@ public class DialogFragment extends Fragment
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    public void onAttach(Context context) {
        super.onAttach(context);
        if (!mShownByMe) {
            // If not explicitly shown through our API, take this as an
            // indication that the dialog is no longer dismissed.
@@ -394,7 +394,6 @@ public class DialogFragment extends Fragment
            mShowsDialog = savedInstanceState.getBoolean(SAVED_SHOWS_DIALOG, mShowsDialog);
            mBackStackId = savedInstanceState.getInt(SAVED_BACK_STACK_ID, -1);
        }
        
    }

    /** @hide */
@@ -473,11 +472,15 @@ public class DialogFragment extends Fragment
        View view = getView();
        if (view != null) {
            if (view.getParent() != null) {
                throw new IllegalStateException("DialogFragment can not be attached to a container view");
                throw new IllegalStateException(
                        "DialogFragment can not be attached to a container view");
            }
            mDialog.setContentView(view);
        }
        mDialog.setOwnerActivity(getActivity());
        final Activity activity = getActivity();
        if (activity != null) {
            mDialog.setOwnerActivity(activity);
        }
        mDialog.setCancelable(mCancelable);
        if (!mDialog.takeCancelAndDismissListeners("DialogFragment", this, this)) {
            throw new IllegalStateException(
+6 −6
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ public class ListFragment extends Fragment {
    }

    /**
     * Get the activity's list view widget.
     * Get the fragment's list view widget.
     */
    public ListView getListView() {
        ensureList();
@@ -346,9 +346,9 @@ public class ListFragment extends Fragment {
        if (shown) {
            if (animate) {
                mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_out));
                        getContext(), android.R.anim.fade_out));
                mListContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_in));
                        getContext(), android.R.anim.fade_in));
            } else {
                mProgressContainer.clearAnimation();
                mListContainer.clearAnimation();
@@ -358,9 +358,9 @@ public class ListFragment extends Fragment {
        } else {
            if (animate) {
                mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_in));
                        getContext(), android.R.anim.fade_in));
                mListContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_out));
                        getContext(), android.R.anim.fade_out));
            } else {
                mProgressContainer.clearAnimation();
                mListContainer.clearAnimation();
@@ -371,7 +371,7 @@ public class ListFragment extends Fragment {
    }
    
    /**
     * Get the ListAdapter associated with this activity's ListView.
     * Get the ListAdapter associated with this fragment's ListView.
     */
    public ListAdapter getListAdapter() {
        return mAdapter;
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class WebViewFragment extends Fragment {
        if (mWebView != null) {
            mWebView.destroy();
        }
        mWebView = new WebView(getActivity());
        mWebView = new WebView(getContext());
        mIsWebViewAvailable = true;
        return mWebView;
    }
+1 −1
Original line number Diff line number Diff line
@@ -55,6 +55,6 @@ public class MediaRouteControllerDialogFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return onCreateControllerDialog(getActivity(), savedInstanceState);
        return onCreateControllerDialog(getContext(), savedInstanceState);
    }
}