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:com.royclarkson.springagram.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_add_photo) {
        showPhotoAddFragment();//w  w  w .  j a va  2s . c o m
        return true;
    } else if (id == R.id.action_refresh_photo_list) {
        FragmentManager fragmentManager = getFragmentManager();
        PhotoListFragment galleryListFragment = (PhotoListFragment) fragmentManager
                .findFragmentByTag(PhotoListFragment.TAG);
        galleryListFragment.fetchPhotoList();
        return true;
    } else if (id == R.id.action_add_gallery) {
        showGalleryAddFragment();
        return true;
    } else if (id == R.id.action_refresh_gallery_list) {
        FragmentManager fragmentManager = getFragmentManager();
        GalleryListFragment galleryListFragment = (GalleryListFragment) fragmentManager
                .findFragmentByTag(GalleryListFragment.TAG);
        galleryListFragment.fetchGalleryList();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.distantfuture.castcompanionlibrary.lib.cast.player.VideoCastControllerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cast_activity);
    loadAndSetupViews();/*from   ww w.jav a 2 s.  c o  m*/
    mVolumeIncrement = CastUtils.getFloatFromPreference(this, VideoCastManager.PREFS_KEY_VOLUME_INCREMENT);
    try {
        mCastManager = VideoCastManager.getInstance(this);
    } catch (CastException e) {
        // logged already
    }

    setupActionBar();
    Bundle extras = getIntent().getExtras();
    if (null == extras) {
        finish();
        return;
    }

    FragmentManager fm = getFragmentManager();
    VideoCastControllerFragment mediaAuthFragment = (VideoCastControllerFragment) fm.findFragmentByTag("task");

    // if fragment is null, it means this is the first time, so create it
    if (mediaAuthFragment == null) {
        mediaAuthFragment = VideoCastControllerFragment.newInstance(extras);
        fm.beginTransaction().add(mediaAuthFragment, "task").commit();
        mListener = mediaAuthFragment;
        setOnVideoCastControllerChangedListener(mListener);
    } else {
        mListener = mediaAuthFragment;
        mListener.onConfigurationChanged();
    }
}

From source file:com.royclarkson.springagram.MainActivity.java

@Override
public void onPhotoAddComplete() {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack();//from   w ww.jav a  2s . c o m
    PhotoListFragment photoListFragment = (PhotoListFragment) fragmentManager
            .findFragmentByTag(PhotoListFragment.TAG);
    photoListFragment.fetchPhotoList();
}

From source file:com.royclarkson.springagram.MainActivity.java

public void onGalleryAddComplete() {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack();// w w w  . j a v  a  2  s  .  com
    GalleryListFragment galleryListFragment = (GalleryListFragment) fragmentManager
            .findFragmentByTag(GalleryListFragment.TAG);
    galleryListFragment.fetchGalleryList();
}

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

/**
 * Opens the content browser that shows the user's maps.
 *//*w  w w.  ja  v a  2  s  .c om*/
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:it.gmariotti.cardslib.demo.extras.MainActivity.java

private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("carddemo_dialog_extras");
        if (prev != null) {
            ft.remove(prev);//from  w  w  w. j  av a2  s .c  o m
        }
        //ft.addToBackStack(null);

        dialogStandardFragment.show(ft, "carddemo_dialog_extras");
    }
}

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

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map./*from  w  ww  .  j  a  v a 2  s. c  om*/
 */
public void showMap(String portalItemId, String basemapPortalItemId) {

    // remove existing MapFragment explicitly, simply replacing it can cause
    // the app to freeze when switching basemaps
    FragmentTransaction transaction;
    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG);
    if (currentMapFragment != null) {
        transaction = fragmentManager.beginTransaction();
        transaction.remove(currentMapFragment);
        transaction.commit();
    }

    MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId);

    transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG);
    transaction.addToBackStack(null);
    transaction.commit();

    invalidateOptionsMenu(); // reload the options menu
}

From source file:com.ravi.apps.android.newsbytes.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    // Check if it's in two pane mode and preference has been changed.
    // If so, find and remove the details fragment.
    if (mIsTwoPaneMode && mHasPreferenceChanged) {
        // Get the fragment manager.
        FragmentManager fragmentManager = getFragmentManager();

        // Get the details fragment.
        DetailsFragment detailsFragment = (DetailsFragment) fragmentManager
                .findFragmentByTag(DetailsFragment.DETAILS_FRAGMENT_TAG);

        // Remove the details fragment.
        if (detailsFragment != null) {
            fragmentManager.beginTransaction().remove(detailsFragment).commit();
        }//from  w  ww  . j  av a2 s  . com

        // Reset the preference changed flag.
        mHasPreferenceChanged = false;
    }
}

From source file:me.pzheng.conn.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    // debug code
    // Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();

    Fragment fragment;//from w w  w.j a va2 s  .  co m
    switch (position) {
    case 0: //connect
        fragment = fm.findFragmentByTag(ConnectFragment.TAG);
        if (fragment == null) {
            fragment = new ConnectFragment();
        }
        transaction.replace(R.id.container, fragment, ConnectFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    case 1: //settings
        /* fragment = getFragmentManager().findFragmentByTag(StatsFragment.TAG);
        if (fragment == null) {
            fragment = new StatsFragment();
        }
        getFragmentManager().beginTransaction().replace(R.id.container, fragment, StatsFragment.TAG).commit(); */
        fragment = fm.findFragmentByTag(SettingsFragment.TAG);
        if (fragment == null) {
            fragment = new SettingsFragment();
        }
        transaction.replace(R.id.container, fragment, SettingsFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    case 2: //about
        fragment = fm.findFragmentByTag(AboutFragment.TAG);
        if (fragment == null) {
            fragment = new AboutFragment();
        }
        transaction.replace(R.id.container, fragment, AboutFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    }

    //transaction.commit();

}

From source file:com.docd.purefm.ui.activities.BrowserPagerActivity.java

@Override
protected void onPause() {
    super.onPause();
    final FragmentManager fm = getFragmentManager();
    final Fragment f = fm.findFragmentByTag(TAG_DIALOG);
    if (f != null) {
        fm.beginTransaction().remove(f).commit();
        fm.executePendingTransactions();
    }//from ww  w.  jav  a  2  s. c  o m
}