Search in sources :

Example 61 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project collect by opendatakit.

the class BackgroundAudioPermissionDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    setCancelable(false);
    final FragmentActivity activity = requireActivity();
    return new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.background_audio_permission_explanation).setPositiveButton(R.string.ok, (dialog, which) -> {
        onOKClicked(activity);
    }).create();
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Dialog(android.app.Dialog) PermissionListener(org.odk.collect.permissions.PermissionListener) Timber(timber.log.Timber) FragmentActivity(androidx.fragment.app.FragmentActivity) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) Toast(android.widget.Toast) R(org.odk.collect.android.R) DialogFragment(androidx.fragment.app.DialogFragment) PermissionsProvider(org.odk.collect.permissions.PermissionsProvider) FragmentActivity(androidx.fragment.app.FragmentActivity) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) NonNull(androidx.annotation.NonNull)

Example 62 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android by nextcloud.

the class GalleryFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    setLoading(photoSearchQueryRunning);
    final FragmentActivity activity = getActivity();
    if (activity instanceof FileDisplayActivity) {
        FileDisplayActivity fileDisplayActivity = ((FileDisplayActivity) activity);
        fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_gallery));
        fileDisplayActivity.setMainFabVisible(false);
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity)

Example 63 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project collect by opendatakit.

the class BackgroundAudioPermissionDialogFragmentTest method clickingOk_andGrantingPermissions_whenGrantPermissionsThrowsIllegalStateException_finishesActivity.

@Test
public void clickingOk_andGrantingPermissions_whenGrantPermissionsThrowsIllegalStateException_finishesActivity() {
    doThrow(IllegalStateException.class).when(backgroundAudioViewModel).grantAudioPermission();
    FragmentScenario<BackgroundAudioPermissionDialogFragment> scenario = launcherRule.launchDialogFragment(BackgroundAudioPermissionDialogFragment.class);
    scenario.onFragment(f -> {
        // Need to grab this here as `getActivity()` will return null later
        FragmentActivity activity = f.getActivity();
        AlertDialog dialog = (AlertDialog) f.getDialog();
        Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
        fakePermissionsProvider.setPermissionGranted(true);
        button.performClick();
        RobolectricHelpers.runLooper();
        assertThat(activity.isFinishing(), is(true));
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) FragmentActivity(androidx.fragment.app.FragmentActivity) Button(android.widget.Button) Test(org.junit.Test)

Example 64 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project collect by opendatakit.

the class DialogFragmentUtilsTest method showIfNotShowing_onlyEverOpensOneDialog.

@Test
public void showIfNotShowing_onlyEverOpensOneDialog() {
    FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    DialogFragmentUtils.showIfNotShowing(DialogFragment.class, fragmentManager);
    assertThat(fragmentManager.getFragments().size(), equalTo(1));
    Fragment dialog1 = fragmentManager.getFragments().get(0);
    DialogFragmentUtils.showIfNotShowing(DialogFragment.class, fragmentManager);
    assertThat(fragmentManager.getFragments().size(), equalTo(1));
    assertThat(fragmentManager.getFragments().get(0), equalTo(dialog1));
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Fragment(androidx.fragment.app.Fragment) DialogFragment(androidx.fragment.app.DialogFragment) Test(org.junit.Test)

Example 65 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project collect by opendatakit.

the class DialogFragmentUtilsTest method showIfNotShowing_whenActivityDestroyed_doesNotShowDialog.

@Test
public void showIfNotShowing_whenActivityDestroyed_doesNotShowDialog() {
    ActivityController<FragmentActivity> activityController = Robolectric.buildActivity(FragmentActivity.class).setup();
    activityController.pause().stop().destroy();
    FragmentManager fragmentManager = activityController.get().getSupportFragmentManager();
    DialogFragmentUtils.showIfNotShowing(DialogFragment.class, fragmentManager);
    assertThat(fragmentManager.getFragments().size(), equalTo(0));
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Test(org.junit.Test)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)185 Test (org.junit.Test)71 Intent (android.content.Intent)25 Bundle (android.os.Bundle)19 View (android.view.View)11 Config (org.robolectric.annotation.Config)11 TextView (android.widget.TextView)10 Before (org.junit.Before)10 BroadcastReceiver (android.content.BroadcastReceiver)8 Fragment (androidx.fragment.app.Fragment)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Activity (android.app.Activity)7 Resources (android.content.res.Resources)7 FragmentManager (androidx.fragment.app.FragmentManager)7 IntentFilter (android.content.IntentFilter)6 UserHandle (android.os.UserHandle)6 Preference (androidx.preference.Preference)6 SwitchPreference (androidx.preference.SwitchPreference)6 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)6 Tile (com.android.settingslib.drawer.Tile)6