@Test public void testGetPromptParentView() { final DialogFragment dialogFragment = spy(new DialogFragment()); final ViewGroup parent = mock(ViewGroup.class); final ViewGroup view = mock(ViewGroup.class); final SupportFragmentResourceFinder resourceFinder = new SupportFragmentResourceFinder(dialogFragment); when(dialogFragment.getView()).thenReturn(view); when(view.getParent()).thenReturn(parent); assertEquals(parent, resourceFinder.getPromptParentView()); assertEquals(parent, resourceFinder.getPromptParentView()); }
@Test public void testBuilder_SupportDialogFragment() { final DialogFragment dialogFragment = spy(new DialogFragment()); startFragment(dialogFragment); final ViewGroup view = mock(ViewGroup.class); when(dialogFragment.getView()).thenReturn(view); final Activity activity = Robolectric.buildActivity(Activity.class).create().get(); final Dialog dialog = mock(Dialog.class); when(dialogFragment.getDialog()).thenReturn(dialog); when(dialog.getOwnerActivity()).thenReturn(activity); when(dialog.findViewById(android.R.id.content)).thenReturn(activity.findViewById(android.R.id.content)); final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(dialogFragment); assertTrue(builder.getResourceFinder() instanceof SupportFragmentResourceFinder); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (!mShowsDialog) { return; } View view = getView(); if (view != null) { if (view.getParent() != null) { throw new IllegalStateException("DialogFragment can not be attached to a container view"); } mDialog.setContentView(view); } mDialog.setOwnerActivity(getActivity()); mDialog.setCancelable(mCancelable); mDialog.setOnCancelListener(this); mDialog.setOnDismissListener(this); if (savedInstanceState != null) { Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG); if (dialogState != null) { mDialog.onRestoreInstanceState(dialogState); } } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (!mShowsDialog) { return; } View view = getView(); if (view != null) { if (view.getParent() != null) { throw new IllegalStateException("DialogFragment can not be attached to a container view"); } mDialog.setContentView(view); } mDialog.setOwnerActivity(getActivity()); mDialog.setCancelable(mCancelable); mDialog.setOnCancelListener(this); mDialog.setOnDismissListener(this); if (savedInstanceState != null) { Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG); if (dialogState != null) { mDialog.onRestoreInstanceState(dialogState); } } }