Search in sources :

Example 46 with FragmentManager

use of androidx.fragment.app.FragmentManager in project bitcoin-wallet by bitcoin-wallet.

the class WalletActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.application = getWalletApplication();
    this.config = application.getConfiguration();
    walletActivityViewModel = new ViewModelProvider(this).get(AbstractWalletActivityViewModel.class);
    viewModel = new ViewModelProvider(this).get(WalletActivityViewModel.class);
    setContentView(R.layout.wallet_content);
    contentView = findViewById(android.R.id.content);
    exchangeRatesFragment = findViewById(R.id.wallet_main_twopanes_exchange_rates);
    levitateView = contentView.findViewWithTag("levitate");
    // Make view tagged with 'levitate' scroll away and quickly return.
    if (levitateView != null) {
        final CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(levitateView.getLayoutParams().width, levitateView.getLayoutParams().height);
        layoutParams.setBehavior(new QuickReturnBehavior());
        levitateView.setLayoutParams(layoutParams);
        levitateView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            final int height = bottom - top;
            final View targetList = findViewById(R.id.wallet_transactions_list);
            targetList.setPadding(targetList.getPaddingLeft(), height, targetList.getPaddingRight(), targetList.getPaddingBottom());
            final View targetEmpty = findViewById(R.id.wallet_transactions_empty);
            targetEmpty.setPadding(targetEmpty.getPaddingLeft(), height, targetEmpty.getPaddingRight(), targetEmpty.getPaddingBottom());
        });
    }
    OnFirstPreDraw.listen(contentView, viewModel);
    enterAnimation = buildEnterAnimation(contentView);
    viewModel.walletEncrypted.observe(this, isEncrypted -> invalidateOptionsMenu());
    viewModel.walletLegacyFallback.observe(this, isLegacyFallback -> invalidateOptionsMenu());
    viewModel.showHelpDialog.observe(this, new Event.Observer<Integer>() {

        @Override
        protected void onEvent(final Integer messageResId) {
            HelpDialogFragment.page(getSupportFragmentManager(), messageResId);
        }
    });
    viewModel.showBackupWalletDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            BackupWalletActivity.start(WalletActivity.this);
        }
    });
    viewModel.showRestoreWalletDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            RestoreWalletDialogFragment.showPick(getSupportFragmentManager());
        }
    });
    viewModel.showEncryptKeysDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            EncryptKeysDialogFragment.show(getSupportFragmentManager());
        }
    });
    viewModel.showReportIssueDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            ReportIssueDialogFragment.show(getSupportFragmentManager(), R.string.report_issue_dialog_title_issue, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, null);
        }
    });
    viewModel.showReportCrashDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            ReportIssueDialogFragment.show(getSupportFragmentManager(), R.string.report_issue_dialog_title_crash, R.string.report_issue_dialog_message_crash, Constants.REPORT_SUBJECT_CRASH, null);
        }
    });
    viewModel.enterAnimation.observe(this, state -> {
        if (state == WalletActivityViewModel.EnterAnimationState.WAITING) {
            // API level 26: enterAnimation.setCurrentPlayTime(0);
            for (final Animator animation : enterAnimation.getChildAnimations()) ((ValueAnimator) animation).setCurrentPlayTime(0);
        } else if (state == WalletActivityViewModel.EnterAnimationState.ANIMATING) {
            reportFullyDrawn();
            enterAnimation.start();
            enterAnimation.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(final Animator animation) {
                    viewModel.animationFinished();
                }
            });
        } else if (state == WalletActivityViewModel.EnterAnimationState.FINISHED) {
            getWindow().getDecorView().setBackground(null);
        }
    });
    if (savedInstanceState == null)
        viewModel.animateWhenLoadingFinished();
    else
        viewModel.animationFinished();
    if (savedInstanceState == null && CrashReporter.hasSavedCrashTrace())
        viewModel.showReportCrashDialog.setValue(Event.simple());
    config.touchLastUsed();
    handleIntent(getIntent());
    final FragmentManager fragmentManager = getSupportFragmentManager();
    MaybeMaintenanceFragment.add(fragmentManager);
    AlertDialogsFragment.add(fragmentManager);
}
Also used : View(android.view.View) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) FragmentManager(androidx.fragment.app.FragmentManager) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 47 with FragmentManager

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

the class SyncedFoldersActivity method onSyncFolderSettingsClick.

@Override
public void onSyncFolderSettingsClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.addToBackStack(null);
    syncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(syncedFolderDisplayItem, section);
    syncedFolderPreferencesDialogFragment.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Example 48 with FragmentManager

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

the class FileActivity method showUntrustedCertDialog.

/**
 * Show untrusted cert dialog
 */
public void showUntrustedCertDialog(RemoteOperationResult result) {
    // Show a dialog with the certificate info
    FragmentManager fm = getSupportFragmentManager();
    SslUntrustedCertDialog dialog = (SslUntrustedCertDialog) fm.findFragmentByTag(DIALOG_UNTRUSTED_CERT);
    if (dialog == null) {
        dialog = SslUntrustedCertDialog.newInstanceForFullSslError((CertificateCombinedException) result.getException());
        FragmentTransaction ft = fm.beginTransaction();
        dialog.show(ft, DIALOG_UNTRUSTED_CERT);
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) SslUntrustedCertDialog(com.owncloud.android.ui.dialog.SslUntrustedCertDialog) CertificateCombinedException(com.owncloud.android.lib.common.network.CertificateCombinedException)

Example 49 with FragmentManager

use of androidx.fragment.app.FragmentManager 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 50 with FragmentManager

use of androidx.fragment.app.FragmentManager 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

FragmentManager (androidx.fragment.app.FragmentManager)163 FragmentTransaction (androidx.fragment.app.FragmentTransaction)55 Fragment (androidx.fragment.app.Fragment)42 Bundle (android.os.Bundle)28 Test (org.junit.Test)15 Intent (android.content.Intent)13 FragmentActivity (androidx.fragment.app.FragmentActivity)10 Activity (android.app.Activity)6 View (android.view.View)6 DialogFragment (androidx.fragment.app.DialogFragment)6 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)5 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)3 LayoutInflater (android.view.LayoutInflater)3 MenuInflater (android.view.MenuInflater)3 Window (android.view.Window)3 TextView (android.widget.TextView)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3