Merge "Remove dependencies on Activity from common Fragment superclasses" into nyc-dev

This commit is contained in:
Adam Powell
2016-04-22 21:43:15 +00:00
committed by Android (Google) Code Review
4 changed files with 16 additions and 13 deletions

View File

@@ -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(

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -55,6 +55,6 @@ public class MediaRouteControllerDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return onCreateControllerDialog(getActivity(), savedInstanceState);
return onCreateControllerDialog(getContext(), savedInstanceState);
}
}