Search in sources :

Example 76 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Signal-Android by signalapp.

the class RegistrationCompleteFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    FragmentActivity activity = requireActivity();
    RegistrationViewModel viewModel = new ViewModelProvider(activity).get(RegistrationViewModel.class);
    if (SignalStore.storageService().needsAccountRestore()) {
        Log.i(TAG, "Performing pin restore");
        activity.startActivity(new Intent(activity, PinRestoreActivity.class));
    } else if (!viewModel.isReregister()) {
        boolean needsProfile = Recipient.self().getProfileName().isEmpty() || !AvatarHelper.hasAvatar(activity, Recipient.self().getId());
        boolean needsPin = !SignalStore.kbsValues().hasPin();
        Log.i(TAG, "Pin restore flow not required." + " profile name: " + Recipient.self().getProfileName().isEmpty() + " profile avatar: " + !AvatarHelper.hasAvatar(activity, Recipient.self().getId()) + " needsPin:" + needsPin);
        Intent startIntent = MainActivity.clearTop(activity);
        if (needsPin) {
            startIntent = chainIntents(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), startIntent);
        }
        if (needsProfile) {
            startIntent = chainIntents(EditProfileActivity.getIntentForUserProfile(activity), startIntent);
        }
        if (!needsProfile && !needsPin) {
            ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
            RegistrationUtil.maybeMarkRegistrationComplete(requireContext());
        }
        activity.startActivity(startIntent);
    }
    activity.finish();
    ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PinRestoreActivity(org.thoughtcrime.securesms.pin.PinRestoreActivity)

Example 77 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project Signal-Android by signalapp.

the class WelcomeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    viewModel = ViewModelProviders.of(requireActivity()).get(RegistrationViewModel.class);
    if (viewModel.isReregister()) {
        if (viewModel.hasRestoreFlowBeenShown()) {
            Log.i(TAG, "We've come back to the home fragment on a restore, user must be backing out");
            if (!Navigation.findNavController(view).popBackStack()) {
                FragmentActivity activity = requireActivity();
                activity.finish();
                ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
            }
            return;
        }
        initializeNumber();
        Log.i(TAG, "Skipping restore because this is a reregistration.");
        viewModel.setWelcomeSkippedOnRestore();
        SafeNavigation.safeNavigate(Navigation.findNavController(view), WelcomeFragmentDirections.actionSkipRestore());
    } else {
        setDebugLogSubmitMultiTapView(view.findViewById(R.id.image));
        setDebugLogSubmitMultiTapView(view.findViewById(R.id.title));
        continueButton = view.findViewById(R.id.welcome_continue_button);
        continueButton.setOnClickListener(this::continueClicked);
        Button restoreFromBackup = view.findViewById(R.id.welcome_transfer_or_restore);
        restoreFromBackup.setOnClickListener(this::restoreFromBackupClicked);
        TextView welcomeTermsButton = view.findViewById(R.id.welcome_terms_button);
        welcomeTermsButton.setOnClickListener(v -> onTermsClicked());
        if (!canUserSelectBackup()) {
            restoreFromBackup.setText(R.string.registration_activity__transfer_account);
        }
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Button(android.widget.Button) CircularProgressButton(com.dd.CircularProgressButton) TextView(android.widget.TextView) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel)

Example 78 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class PanelFragment method createPanelContent.

private void createPanelContent() {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        return;
    }
    if (mLayoutView == null) {
        activity.finish();
        return;
    }
    final ViewGroup.LayoutParams params = mLayoutView.getLayoutParams();
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLayoutView.setLayoutParams(params);
    mPanelSlices = mLayoutView.findViewById(R.id.panel_parent_layout);
    mSeeMoreButton = mLayoutView.findViewById(R.id.see_more);
    mDoneButton = mLayoutView.findViewById(R.id.done);
    mTitleView = mLayoutView.findViewById(R.id.panel_title);
    mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
    mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
    mTitleGroup = mLayoutView.findViewById(R.id.title_group);
    mHeaderLayout = mLayoutView.findViewById(R.id.header_layout);
    mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
    mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
    mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
    mProgressBar = mLayoutView.findViewById(R.id.progress_bar);
    mHeaderDivider = mLayoutView.findViewById(R.id.header_divider);
    // Make the panel layout gone here, to avoid janky animation when updating from old panel.
    // We will make it visible once the panel is ready to load.
    mPanelSlices.setVisibility(View.GONE);
    final Bundle arguments = getArguments();
    final String callingPackageName = arguments.getString(SettingsPanelActivity.KEY_CALLING_PACKAGE_NAME);
    mPanel = FeatureFactory.getFactory(activity).getPanelFeatureProvider().getPanel(activity, arguments);
    if (mPanel == null) {
        activity.finish();
        return;
    }
    mPanel.registerCallback(new LocalPanelCallback());
    if (mPanel instanceof LifecycleObserver) {
        getLifecycle().addObserver((LifecycleObserver) mPanel);
    }
    mMetricsProvider = FeatureFactory.getFactory(activity).getMetricsFeatureProvider();
    updateProgressBar();
    mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
    // Add predraw listener to remove the animation and while we wait for Slices to load.
    mLayoutView.getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
    // Start loading Slices. When finished, the Panel will animate in.
    loadAllSlices();
    final IconCompat icon = mPanel.getIcon();
    final CharSequence title = mPanel.getTitle();
    final CharSequence subtitle = mPanel.getSubTitle();
    if (icon != null || (subtitle != null && subtitle.length() > 0)) {
        enablePanelHeader(icon, title, subtitle);
    } else {
        enableTitle(title);
    }
    mFooterDivider.setVisibility(View.GONE);
    mSeeMoreButton.setOnClickListener(getSeeMoreListener());
    mDoneButton.setOnClickListener(getCloseListener());
    if (mPanel.isCustomizedButtonUsed()) {
        enableCustomizedButton();
    } else if (mPanel.getSeeMoreIntent() == null) {
        // If getSeeMoreIntent() is null hide the mSeeMoreButton.
        mSeeMoreButton.setVisibility(View.GONE);
    }
    // Log panel opened.
    mMetricsProvider.action(0, /* attribution */
    SettingsEnums.PAGE_VISIBLE, /* opened panel - Action */
    mPanel.getMetricsCategory(), callingPackageName, 0);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) IconCompat(androidx.core.graphics.drawable.IconCompat) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LifecycleObserver(androidx.lifecycle.LifecycleObserver)

Example 79 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class PanelFragment method loadPanelWhenReady.

/**
 * When all of the Slices have loaded for the first time, then we can setup the
 * {@link RecyclerView}.
 * <p>
 * When the Recyclerview has been laid out, we can begin the animation with the
 * {@link mOnGlobalLayoutListener}, which calls {@link #animateIn()}.
 */
private void loadPanelWhenReady() {
    if (mPanelSlicesLoaderCountdownLatch.isPanelReadyToLoad()) {
        mAdapter = new PanelSlicesAdapter(this, mSliceLiveData, mPanel.getMetricsCategory());
        mPanelSlices.setAdapter(mAdapter);
        mPanelSlices.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
        mPanelSlices.setVisibility(View.VISIBLE);
        final FragmentActivity activity = getActivity();
        if (activity == null) {
            return;
        }
        final DividerItemDecoration itemDecoration = new DividerItemDecoration(activity);
        itemDecoration.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
        if (mPanelSlices.getItemDecorationCount() == 0) {
            mPanelSlices.addItemDecoration(itemDecoration);
        }
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) DividerItemDecoration(com.google.android.setupdesign.DividerItemDecoration)

Example 80 with FragmentActivity

use of androidx.fragment.app.FragmentActivity in project android_packages_apps_Settings by omnirom.

the class TetherSettingsTest method onReceive_mediaIsShared_tetheringPreferenceIsDisabled.

@Test
public void onReceive_mediaIsShared_tetheringPreferenceIsDisabled() {
    RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
    FragmentActivity mockActivity = mock(FragmentActivity.class);
    ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
    setupUsbStateComponents(tetheringPreference, captor, mockActivity);
    BroadcastReceiver receiver = captor.getValue();
    Intent mediaIsShared = new Intent(ACTION_MEDIA_SHARED);
    receiver.onReceive(mockActivity, mediaIsShared);
    verify(tetheringPreference).setEnabled(false);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) 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