Java Code Examples for androidx.fragment.app.fragment#isVisible()

The following examples show how to use androidx.fragment.app.fragment#isVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DashboardActivity.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void showDeprecatedState(@Nullable DashboardState state) {
    Fragment frag = BackstackManager.getInstance().getFragmentOnStack(DeprecatedAlertFragment.class);
    if(state.getSafetyActivated()) {
        if(frag == null) {
            setToolbarSafety();
            BackstackManager.getInstance().navigateToFragment(DeprecatedAlertFragment.newInstance(DeprecatedAlertFragment.SAFETY_ALARM), true);
        }
    } else if(state.getSecurityActivated()) {
        if(frag == null) {
            setToolbarSecurity();
            BackstackManager.getInstance().navigateToFragment(DeprecatedAlertFragment.newInstance(DeprecatedAlertFragment.SECURITY_ALARM), true);
        }
    } else {
        showState(state);
        if(frag != null && frag.isVisible()) {
            setToPreviousToolbarColor();
            BackstackManager.getInstance().navigateBack();
        }
        AlarmSubsystemController.getInstance().activate();
    }
}
 
Example 2
Source File: SettingsPlaceFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    // If we're currently saving data - don't do anything.
    if (isSaving.get()) {
        return true;
    }

    // Don't do anything if we're showing the tz fragment.
    Fragment tzFragment = BackstackManager.getInstance().getFragmentOnStack(TimezonePickerPopup.class);
    if (tzFragment != null && tzFragment instanceof TimezonePickerPopup && tzFragment.isVisible()) {
        return true;
    }

    // If for some reason we clicked on something that shouldn't be there....
    if (item.getItemId() != R.id.menu_edit_contact) {
        return super.onOptionsItemSelected(item);
    }

    // Else update the editing/not editing mode.
    String menuTitle = String.valueOf(item.getTitle());
    boolean editing = edit.equalsIgnoreCase(menuTitle);
    item.setTitle(editing ? done : edit);
    enableInput(editing);

    return true;
}
 
Example 3
Source File: ViewCheckInfoDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
private String getVisibleFragment(Activity activity) {
    if (activity == null) {
        return null;
    }
    StringBuilder builder = new StringBuilder();
    if (activity instanceof AppCompatActivity) {
        AppCompatActivity compatActivity = (AppCompatActivity) activity;
        FragmentManager fragmentManager = compatActivity.getSupportFragmentManager();
        List<Fragment> fragments = fragmentManager.getFragments();
        if (fragments != null && fragments.size() != 0) {
            for (int i = 0; i < fragments.size(); i++) {
                Fragment fragment = fragments.get(i);
                if (fragment != null && fragment.isVisible()) {
                    builder.append(fragment.getClass().getSimpleName() + "#" + fragment.getId());
                    if (i < fragments.size() - 1) {
                        builder.append(";");
                    }
                }
            }
            return builder.toString();
        } else {
            return getFragmentForActivity(activity);
        }
    } else {
        return getFragmentForActivity(activity);
    }
}
 
Example 4
Source File: BackPressEventDispatchHelper.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isBackPressedIntercepted(Fragment fragment) {
    return fragment != null &&
            fragment.isVisible() &&
            fragment.getUserVisibleHint() &&
            fragment instanceof BackPressedListener &&
            ((BackPressedListener) fragment).onInterceptBackPressed();
}
 
Example 5
Source File: FragmentIdlingResource.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean isFragmentWasShow() {
    Fragment fragmentByTag = fragmentManager.findFragmentByTag(fragmentTag);

    if (fragmentByTag != null) {
        return fragmentByTag.isVisible();
    } else {
        return false;
    }
}
 
Example 6
Source File: BackPressEventDispatchHelper.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isBackPressedIntercepted(Fragment fragment) {
    return fragment != null &&
            fragment.isVisible() &&
            fragment.getUserVisibleHint() &&
            fragment instanceof BackPressedListener &&
            ((BackPressedListener) fragment).interceptBackPress();
}
 
Example 7
Source File: MainActivity.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
private void hideFragment(Fragment fragment) {
    if (fragment != null && fragment.isVisible()) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.hide(fragment);
        ft.commit();
    }
}
 
Example 8
Source File: MainActivity.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public BaseFragment getVisibleFragment()
{
    FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
    List<Fragment> fragments = fragmentManager.getFragments();
    for (Fragment fragment : fragments)
    {
        if (fragment != null && fragment.isVisible() && (fragment instanceof BaseFragment))
        {
            return (BaseFragment) fragment;
        }
    }
    return null;
}
 
Example 9
Source File: UiUtils.java    From tindroid with Apache License 2.0 5 votes vote down vote up
@Nullable
static Fragment getVisibleFragment(@NonNull FragmentManager fm) {
    List<Fragment> fragments = fm.getFragments();
    for (Fragment f : fragments) {
        if (f.isVisible()) {
            return f;
        }
    }
    return null;
}
 
Example 10
Source File: SharedElementTransition.java    From Kore with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the transition for the entering fragment
 * @param fragmentTransaction
 * @param fragment entering fragment
 * @param sharedElement must have the transition name set
 */
@TargetApi(21)
public void setupEnterTransition(Context context,
                                 FragmentTransaction fragmentTransaction,
                                 final Fragment fragment,
                                 View sharedElement) {
    if (!(fragment instanceof SharedElement)) {
        LogUtils.LOGD(TAG, "Enter transition fragment must implement SharedElement interface");
        return;
    }

    androidx.core.app.SharedElementCallback seCallback = new androidx.core.app.SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            // On returning, onMapSharedElements for the exiting fragment is called before the onMapSharedElements
            // for the reentering fragment. We use this to determine if we are returning and if
            // we should clear the shared element lists. Note that, clearing must be done in the reentering fragment
            // as this is called last. Otherwise, the app will crash during transition setup. Not sure, but might
            // be a v4 support package bug.
            if (fragment.isVisible() && (!((SharedElement) fragment).isSharedElementVisible())) {
                // shared element not visible
                clearSharedElements = true;
            }
        }
    };
    fragment.setEnterSharedElementCallback(seCallback);

    fragment.setEnterTransition(TransitionInflater
                                        .from(context)
                                        .inflateTransition(R.transition.media_details));
    fragment.setReturnTransition(null);

    Transition changeImageTransition = TransitionInflater.from(
            context).inflateTransition(R.transition.change_image);
    fragment.setSharedElementReturnTransition(changeImageTransition);
    fragment.setSharedElementEnterTransition(changeImageTransition);

    fragmentTransaction.addSharedElement(sharedElement, sharedElement.getTransitionName());
}
 
Example 11
Source File: MainDiscoveryFragment.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * This function lets the currently shown Fragment know that it has now become visible to
 * the user by calling its {@link Fragment#setUserVisibleHint(boolean)} function.
 */
private void updateShownFragmentsVisibility() {
    for (int i = 0; i < fragmentsArray.size(); i++) {
        final Fragment fragment = fragmentsArray.get(fragmentsArray.keyAt(i));
        if (fragment != null && fragment.getUserVisibleHint()
                && fragment.isVisible()) {
            fragment.setUserVisibleHint(true);
            return;
        }
    }
}
 
Example 12
Source File: MainActivity.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void setFragment(String tag) {
    final String oldTag = mCurrent;
    mCurrent = tag;
    final FragmentManager manager = getSupportFragmentManager();
    final FragmentTransaction transaction = manager.beginTransaction();
    if (!TextUtils.isEmpty(oldTag)) {
        final Fragment old = manager.findFragmentByTag(oldTag);
        if (old != null && old.isVisible()) {
            transaction.hide(old);
        }
    }
    Fragment target = manager.findFragmentByTag(tag);
    if (target != null && target.isVisible())
        return;
    if (target == null) {
        switch (tag) {
            default:
            case TAG_WIDGETS:
                target = WidgetsFragment.newInstance();
                break;
            case TAG_DRAWABLES:
                target = DrawablesFragment.newInstance();
                break;
            case TAG_OTHERS:
                target = OthersFragment.newInstance();
                break;
            case TAG_DEVELOP:
                target = DevelopFragment.newInstance();
                break;
        }
        transaction.add(mVContent.getId(), target, tag);
    }
    transaction.show(target);
    transaction.commit();
}
 
Example 13
Source File: PopupResponsibility.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public <T extends Fragment> boolean isFragmentVisible(Class<T> clazz) {
    Fragment fragment = BackstackManager.getInstance().getCurrentFragment();
    return  (fragment.getClass().isAssignableFrom(clazz)) && fragment.isVisible();
}
 
Example 14
Source File: MessageActivity.java    From tindroid with Apache License 2.0 4 votes vote down vote up
private boolean isFragmentVisible(String tag) {
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
    return fragment != null && fragment.isVisible();
}
 
Example 15
Source File: MessageActivity.java    From tindroid with Apache License 2.0 4 votes vote down vote up
void showFragment(String tag, Bundle args, boolean addToBackstack) {
    if (isFinishing() || isDestroyed()) {
        return;
    }

    FragmentManager fm = getSupportFragmentManager();

    Fragment fragment = fm.findFragmentByTag(tag);
    if (fragment == null) {
        switch (tag) {
            case FRAGMENT_MESSAGES:
                fragment = new MessagesFragment();
                break;
            case FRAGMENT_INFO:
                fragment = new TopicInfoFragment();
                break;
            case FRAGMENT_PERMISSIONS:
                fragment = new TopicPermissionsFragment();
                break;
            case FRAGMENT_EDIT_MEMBERS:
                fragment = new EditMembersFragment();
                break;
            case FRAGMENT_VIEW_IMAGE:
                fragment = new ImageViewFragment();
                break;
            case FRAGMENT_FILE_PREVIEW:
                fragment = new FilePreviewFragment();
                break;
            case FRAGMENT_INVALID:
                fragment = new InvalidTopicFragment();
                break;
        }
    } else if (args == null) {
        // Retain old arguments.
        args = fragment.getArguments();
    }
    if (fragment == null) {
        throw new NullPointerException();
    }

    args = args != null ? args : new Bundle();
    args.putString("topic", mTopicName);
    args.putString(MessagesFragment.MESSAGE_TO_SEND, mMessageText);
    if (fragment.getArguments() != null) {
        fragment.getArguments().putAll(args);
    } else {
        fragment.setArguments(args);
    }

    FragmentTransaction trx = fm.beginTransaction();
    if (!fragment.isAdded()) {
        trx = trx.replace(R.id.contentFragment, fragment, tag)
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    } else if (!fragment.isVisible()) {
        trx = trx.show(fragment);
    } else {
        addToBackstack = false;
    }

    if (FRAGMENT_MESSAGES.equals(tag)) {
        trx.setPrimaryNavigationFragment(fragment);
    }

    if (addToBackstack) {
        trx.addToBackStack(tag);
    }
    if (!trx.isEmpty()) {
        trx.commit();
    }
}