Search in sources :

Example 41 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutPickerControllerTest method testOnDeviceRemove_getDifferentDevice_shouldNotFinish.

@Test
@Config(shadows = ShadowInputDevice.class)
public void testOnDeviceRemove_getDifferentDevice_shouldNotFinish() {
    final int TARGET_DEVICE_ID = 1;
    final int ANOTHER_DEVICE_ID = 2;
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    final String[] enableKeyboardLayouts = { "layout1" };
    final InputDevice device = ShadowInputDevice.makeInputDevicebyId(TARGET_DEVICE_ID);
    when(mFragment.getActivity()).thenReturn(activity);
    when(mInputManager.getInputDeviceByDescriptor(anyString())).thenReturn(device);
    when(mInputManager.getEnabledKeyboardLayoutsForInputDevice(any(InputDeviceIdentifier.class))).thenReturn(enableKeyboardLayouts);
    mController.onStart();
    mController.onInputDeviceRemoved(ANOTHER_DEVICE_ID);
    assertThat(activity.isFinishing()).isFalse();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) InputDeviceIdentifier(android.hardware.input.InputDeviceIdentifier) InputDevice(android.view.InputDevice) ShadowInputDevice(com.android.settings.testutils.shadow.ShadowInputDevice) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 42 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutPickerControllerTest method testOnDeviceRemove_getSameDevice_shouldFinish.

@Test
@Config(shadows = ShadowInputDevice.class)
public void testOnDeviceRemove_getSameDevice_shouldFinish() {
    final int TARGET_DEVICE_ID = 1;
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    final String[] enableKeyboardLayouts = { "layout1" };
    final InputDevice device = ShadowInputDevice.makeInputDevicebyId(TARGET_DEVICE_ID);
    when(mFragment.getActivity()).thenReturn(activity);
    when(mInputManager.getInputDeviceByDescriptor(anyString())).thenReturn(device);
    when(mInputManager.getEnabledKeyboardLayoutsForInputDevice(any(InputDeviceIdentifier.class))).thenReturn(enableKeyboardLayouts);
    mController.onStart();
    mController.onInputDeviceRemoved(TARGET_DEVICE_ID);
    assertThat(activity.isFinishing()).isTrue();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) InputDeviceIdentifier(android.hardware.input.InputDeviceIdentifier) InputDevice(android.view.InputDevice) ShadowInputDevice(com.android.settings.testutils.shadow.ShadowInputDevice) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 43 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SurveyMixinTest method onPause_removesReceiverIfPreviouslySet.

@Test
public void onPause_removesReceiverIfPreviouslySet() {
    // Pretend there is a survey in memory
    when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
    // Pretend we are an activity that starts and stops
    FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
    when(mFragment.getActivity()).thenReturn(temp);
    when(mProvider.createAndRegisterReceiver(any())).thenReturn(mReceiver);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(temp);
    SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
    mixin.onResume();
    manager.registerReceiver(mReceiver, new IntentFilter());
    mixin.onPause();
    // Verify we remove the receiver
    HashMap<BroadcastReceiver, ArrayList<IntentFilter>> map = ReflectionHelpers.getField(manager, "mReceivers");
    assertThat(map.containsKey(mReceiver)).isFalse();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) Test(org.junit.Test)

Example 44 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Presentation by StanKocken.

the class FormPresenter method onClickGoFormDialogFragment.

@Override
public void onClickGoFormDialogFragment() {
    Activity activity = getActivity();
    if (activity instanceof FragmentActivity) {
        FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
        new FormDialogFragment().show(fragmentManager, "");
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FormDialogFragment(com.skocken.presentation.sample.fragment.FormDialogFragment) FormWithFragmentActivity(com.skocken.presentation.sample.activity.FormWithFragmentActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) FormActivity(com.skocken.presentation.sample.activity.FormActivity) FormWithFragmentActivity(com.skocken.presentation.sample.activity.FormWithFragmentActivity) Activity(android.app.Activity) FragmentActivity(androidx.fragment.app.FragmentActivity)

Example 45 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android-oss by kickstarter.

the class BaseBottomSheetDialogFragment method onResume.

@CallSuper
@Override
public void onResume() {
    super.onResume();
    Timber.d("onResume %s", this.toString());
    this.lifecycle.onNext(FragmentEvent.RESUME);
    assignViewModel(null);
    if (this.viewModel != null) {
        this.viewModel.onResume(this);
        final FragmentActivity activity = getActivity();
        if (activity != null) {
            activity.registerReceiver(this.optimizelyReadyReceiver, new IntentFilter(ExperimentsClientTypeKt.EXPERIMENTS_CLIENT_READY));
        }
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) IntentFilter(android.content.IntentFilter) CallSuper(androidx.annotation.CallSuper)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)181 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 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Resources (android.content.res.Resources)7 Fragment (androidx.fragment.app.Fragment)7 FragmentManager (androidx.fragment.app.FragmentManager)7 Activity (android.app.Activity)6 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