Example usage for android.app Fragment isVisible

List of usage examples for android.app Fragment isVisible

Introduction

In this page you can find the example usage for android.app Fragment isVisible.

Prototype

final public boolean isVisible() 

Source Link

Document

Return true if the fragment is currently visible to the user.

Usage

From source file:Main.java

public static boolean isFragmentShowing(FragmentManager fm, String tag) {
    Fragment f = fm.findFragmentByTag(tag);
    if (f != null && f.isVisible()) {
        return true;
    } else {/*from  w w w  .  ja v a  2 s  . c o  m*/
        return false;
    }
}

From source file:com.poloure.simplerss.Utilities.java

private static void switchToFragment(Fragment fragment, boolean addToBackStack) {
    if (fragment.isHidden()) {
        Fragment[] fragments = { s_fragmentFavourites, s_fragmentManage, s_fragmentFeeds, s_fragmentSettings };
        FragmentTransaction transaction = s_fragmentManager.beginTransaction();

        for (Fragment frag : fragments) {
            if (frag.isVisible()) {
                transaction.hide(frag);//from  w ww  . ja v  a 2 s.  c  o  m
            }
        }
        transaction.show(fragment);
        if (addToBackStack) {
            transaction.addToBackStack(null);

            // Set the default transition for adding to the stack.
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        }
        transaction.commit();
        s_fragmentManager.executePendingTransactions();
        fragment.getActivity().invalidateOptionsMenu();
    }
}

From source file:am.project.x.business.main.MainActivity.java

private void setFragment(String tag) {
    final String oldTag = mCurrent;
    mCurrent = tag;/*from  ww w  .ja v  a  2s  . co  m*/
    final FragmentManager manager = getFragmentManager();
    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();
}

From source file:org.openmrs.mobile.activities.FormDisplayActivity.java

public List<Fragment> getActiveFragments() {
    ArrayList<Fragment> ret = new ArrayList<Fragment>();
    for (WeakReference<Fragment> ref : fragList) {
        Fragment f = ref.get();
        if (f != null) {
            if (f.isVisible()) {
                ret.add(f);/*from  w  ww. ja  va2 s  .  com*/
            }
        }
    }
    return ret;
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

public boolean isProgressDialogVisible() {
    final Fragment dialog = mFragmentManager.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
    return dialog != null && dialog.isVisible();
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

private String checkFragment() {
    String currentFragment = null;
    Fragment importFragment = getFragmentManager().findFragmentByTag("fragment_importcert_tag");
    Fragment addSyslogngFragment = getFragmentManager().findFragmentByTag("fragment_addsyslogng_tag");
    if ((importFragment != null && importFragment.isVisible())) {
        currentFragment = importFragment.getTag();
    } else if (addSyslogngFragment != null && addSyslogngFragment.isVisible()) {
        currentFragment = addSyslogngFragment.getTag();
    }// w ww  .j  a  va 2  s. co m
    return currentFragment;
}

From source file:com.esri.android.mapsapp.MapsAppActivity.java

/**
 * Opens the content browser that shows the user's maps.
 *///from w w  w .j  a v a 2s .c o m
private void showContentBrowser() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG);
    if (browseFragment == null) {
        browseFragment = new ContentBrowserFragment();
    }

    if (!browseFragment.isVisible()) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();

        invalidateOptionsMenu(); // reload the options menu
    }

    mDrawerLayout.closeDrawers();
}

From source file:org.catnut.ui.MainActivity.java

/**
 * ?fragment/*  w w  w  .jav a  2s . c o  m*/
 *
 * @param fragment
 * @param tag      null??
 */
private void pendingFragment(Fragment fragment, String tag) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment tmp = fragmentManager.findFragmentByTag(tag);
    if (tmp == null || !tmp.isVisible()) {
        fragmentManager.beginTransaction()
                .setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                        R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit)
                .replace(R.id.fragment_container, fragment, tag).addToBackStack(null).commit();
        mScrollSettleHandler.post(new Runnable() {
            @Override
            public void run() {
                invalidateOptionsMenu();
            }
        });
    }
}

From source file:org.catnut.ui.MainActivity.java

@Override
public void onClick(View v) {
    int id = v.getId();
    Fragment fragment = null;/*from   ww  w .ja  va 2s  .co m*/
    String tag = null;
    mDrawerLayout.closeDrawer(mQuickReturnDrawer);
    switch (id) {
    case R.id.tweets_count:
    case R.id.action_my_tweets:
        fragment = UserTimelineFragment.getFragment(mApp.getAccessToken().uid,
                mApp.getPreferences().getString(User.screen_name, null));
        tag = UserTimelineFragment.TAG;
        break;
    case R.id.following_count:
        fragment = MyRelationshipFragment.getFragment(true);
        tag = "true";
        break;
    case R.id.followers_count:
        fragment = MyRelationshipFragment.getFragment(false);
        tag = "false";
        break;
    case R.id.action_my_favorites:
        fragment = FavoriteFragment.getFragment();
        tag = FavoriteFragment.TAG;
        break;
    case R.id.action_my_drafts:
        fragment = DraftFragment.getFragment();
        tag = DraftFragment.TAG;
        break;
    case R.id.action_share_app:
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType(getString(R.string.mime_image));
        intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_app));
        intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
        intent.putExtra(Intent.EXTRA_STREAM,
                Uri.fromFile(new File(getExternalCacheDir() + File.separator + Constants.SHARE_IMAGE)));
        startActivity(intent);
        return;
    case R.id.action_view_source_code:
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github_link))));
        return;
    case R.id.new_tweet:
        // 
        Fragment home = getFragmentManager().findFragmentByTag(HomeTimelineFragment.TAG);
        // never null, but we still check it.
        if (home == null || !home.isVisible()) {
            fragment = HomeTimelineFragment.getFragment();
            tag = HomeTimelineFragment.TAG;
        } else {
            if (mRefreshCallback != null) {
                mRefreshCallback.callback(null);
            }
        }
        mNewTweet.setText("0");
        break;
    case R.id.new_mention:
        fragment = MentionTimelineFragment.getFragment();
        tag = MentionTimelineFragment.TAG;
        mNewMention.setText("0");
        break;
    case R.id.new_comment:
        fragment = ConversationFragment.getFragment();
        tag = ConversationFragment.TAG;
        mNewComment.setText("0");
        break;
    case R.id.action_my_list:
    default:
        Toast.makeText(this, "sorry, not yet implemented =.=", Toast.LENGTH_SHORT).show();
        return;
    }
    if (fragment != null) {
        pendingFragment(fragment, tag);
    }
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    if (mTwoPane) {
        Fragment editFrag = getFragmentManager().findFragmentByTag(CConst.CONTACT_EDIT_FRAGMENT_TAG);
        if (editFrag != null && editFrag.isVisible()) {
            inflater.inflate(R.menu.contact_list_contact_edit, menu);
            LogUtil.log("=============CLA.onOptionsMenu: contact_list_contact_edit");
        } else {/*from  www .  j  ava 2  s.  c om*/

            inflater.inflate(R.menu.contact_list_contact_detail, menu);
            LogUtil.log("=============CLA.onOptionsMenu: contact_list_contact_detail");
        }
    } else {

        inflater.inflate(R.menu.contact_list_single_menu, menu);
        LogUtil.log("=============CLA.onOptionsMenu: contact_list_single_menu");
    }

    if ((LicenseManager.mIsWhitelistUser || Boolean.valueOf(m_act.getString(R.string.verbose_logging)))
            && DeveloperDialog.isEnabled()) {

        Util.showMenu(menu, R.id.menu_developer);
    }

    return super.onCreateOptionsMenu(menu);
}