Example usage for android.app FragmentManager findFragmentByTag

List of usage examples for android.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction.

Usage

From source file:cx.ring.client.HomeActivity.java

private void popCustomBackStack() {
    FragmentManager fm = getFragmentManager();
    FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt(0);
    fContent = fm.findFragmentByTag(entry.getName());
    for (int i = 0; i < fm.getBackStackEntryCount() - 1; ++i) {
        fm.popBackStack();//from   www . j  a  va 2  s .c  o m
    }
}

From source file:org.opendatakit.survey.android.fragments.InstanceUploaderListFragment.java

@Override
public void onPause() {
    FragmentManager mgr = getFragmentManager();

    // dismiss dialogs...
    AlertDialogFragment alertDialog = (AlertDialogFragment) mgr.findFragmentByTag("alertDialog");
    if (alertDialog != null) {
        alertDialog.dismiss();// ww w.  j  av a 2  s .com
    }
    dismissProgressDialog();
    super.onPause();
}

From source file:by.zatta.pilight.MainActivity.java

private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        DialogFragment prev = (DialogFragment) fm.findFragmentByTag("dialog");
        if (prev != null) {
            prev.dismiss();/*from  w w w . j a  v a2 s.  c  o  m*/
        }
        try {
            dialogStandardFragment.show(ft, "dialog");
        } catch (IllegalStateException e) {
            Log.w(TAG, "activity wasn't yet made");
        }
    }
}

From source file:com.lgallardo.qbittorrentclient.ItemstFragment.java

public void ListItemClicked(int position) {

    ListView lv = this.getListView();

    int count = lv.getCount();

    Torrent torrent = MainActivity.lines[position];

    if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate)
            && getActivity().findViewById(R.id.fragment_container) != null) {

        // Update torrent details

        FragmentManager fragmentManager = getFragmentManager();
        if (!(fragmentManager.findFragmentByTag("secondFragment") instanceof AboutFragment)) {

            detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment");

            if (detailsFragment != null && torrent != null) {

                detailsFragment.updateDetails(torrent);
            }//from   w  w w.  j av a2 s .  co m
        } else {
            newDetailsFragment(position);
        }
    } else {

        newDetailsFragment(position);

    }
}

From source file:com.commonsware.cwac.mediarouter.app.MediaRouteButton.java

/**
 * Show the route chooser or controller dialog.
 * <p>//w  w  w.j  a va 2  s.  c  om
 * If the default route is selected or if the currently selected route does
 * not match the {@link #getRouteSelector selector}, then shows the route chooser dialog.
 * Otherwise, shows the route controller dialog to offer the user
 * a choice to disconnect from the route or perform other control actions
 * such as setting the route's volume.
 * </p><p>
 * The application can customize the dialogs by calling {@link #setDialogFactory}
 * to provide a customized dialog factory.
 * </p>
 *
 * @return True if the dialog was actually shown.
 *
 * @throws IllegalStateException if the activity is not a subclass of
 * FragmentActivity.
 */
public boolean showDialog() {
    if (!mAttachedToWindow) {
        return false;
    }

    final FragmentManager fm = getFragmentManager();
    if (fm == null) {
        throw new IllegalStateException("The activity must be a subclass of FragmentActivity");
    }

    MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    if (route.isDefault() || !route.matchesSelector(mSelector)) {
        if (fm.findFragmentByTag(CHOOSER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route chooser dialog already showing!");
            return false;
        }
        MediaRouteChooserDialogFragment f = mDialogFactory.onCreateChooserDialogFragment();
        f.setRouteSelector(mSelector);
        f.show(fm, CHOOSER_FRAGMENT_TAG);
    } else {
        if (fm.findFragmentByTag(CONTROLLER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route controller dialog already showing!");
            return false;
        }
        MediaRouteControllerDialogFragment f = mDialogFactory.onCreateControllerDialogFragment();
        f.show(fm, CONTROLLER_FRAGMENT_TAG);
    }
    return true;
}

From source file:com.example.office.ui.Office365DemoActivity.java

@Override
protected AuthFragment getCurrentFragment() {
    FragmentManager manager = getFragmentManager();
    if (!TextUtils.isEmpty(mCurrentFragmentTag)) {
        Fragment fragment = manager.findFragmentByTag(mCurrentFragmentTag);
        if (fragment != null) {
            return (AuthFragment) fragment;
        }//from  w  ww.jav  a 2 s . c o m
    }
    return null;
}

From source file:by.zatta.pilight.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    /*//from  w  w w. j a  v  a2  s  . c  o m
    * The action bar home/up should open or close the drawer. ActionBarDrawerToggle will take care of this.
    */
    publishList();
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    switch (item.getItemId()) {
    case R.id.menu_about:
        openDialogFragment(AboutDialog.newInstance());
        return true;
    case R.id.menu_settings:
        Fragment pref = fm.findFragmentByTag("prefs");
        if (pref == null) {
            ft.replace(R.id.fragment_main, new PrefFragment(), "prefs");
            fm.popBackStack();
            ft.addToBackStack(null);
            ft.commit();
        } else {
            ft.remove(fm.findFragmentByTag("prefs"));
            ft.commit();
            fm.popBackStack();
        }
        return true;
    default:
        break;
    }
    // Handle your other action bar items...
    return super.onOptionsItemSelected(item);
}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * Updates the UI after a successful rest response has been received.
 *///from   www  .j av  a  2s  . c o m
void updateUI() {
    dialog.dismiss();
    img_cancel.setVisibility(View.VISIBLE);
    FragmentManager fm = getFragmentManager();
    if (fm.findFragmentByTag("Nav Drawer") == null) {
        FragmentTransaction ft = fm.beginTransaction();
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    } else {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(fm.findFragmentByTag("Nav Drawer"));
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    }
    //img_showDirections.setVisibility(View.VISIBLE);

}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * Clear the graphics and empty the directions list
 *///from   w w  w  . j  a va  2  s . c  o m
public void clearAll() {
    mFeatureLayer.removeAll();
    //Removing the graphics from the layer
    routeLayer.removeAll();
    hiddenSegmentsLayer.removeAll();

    curDirections = new ArrayList<String>();
    mResults = null;
    curRoute = null;

    //Setting to default text
    directionsLabel.setText(getString(R.string.route_label));

    //Locking the Drawer
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    //Removing the cancel icon
    img_cancel.setVisibility(View.GONE);

    //Removing the RoutingListFragment if present
    FragmentManager fm = getFragmentManager();
    if (fm.findFragmentByTag("Nav Drawer") != null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(fm.findFragmentByTag("Nav Drawer"));
        ft.commit();
    }

}

From source file:com.geecko.QuickLyric.MainActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start,
            R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }/*from w  ww.  j a v a 2  s.  c om*/

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}