Example usage for android.app FragmentManager findFragmentById

List of usage examples for android.app FragmentManager findFragmentById

Introduction

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

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

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

Usage

From source file:it.gmariotti.cardslib.demo.extras.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_extras_activity_main);

    // The attacher should always be created in the Activity's onCreate
    //mPullToRefreshAttacher = PullToRefreshAttacher.get(this);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout_extras);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();/*  ww  w.  ja  v a 2 s .c o m*/
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });
    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main_extras) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new PicassoFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java

public static DirectoryFragment get(FragmentManager fm) {
    // TODO: deal with multiple directories shown at once
    return (DirectoryFragment) fm.findFragmentById(R.id.container_directory);
}

From source file:it.gmariotti.cardslib.demo.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();/*from w  w w . j  a va  2s. c o  m*/
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });

    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new HeaderFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

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

public void setFragment(Fragment fragment, Integer position, String tag) {

    updateDrawer(position);//w  w w  . ja  v  a 2s . co  m
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Bundle args = new Bundle();
    args.putInt(MainActivity.FRAGMENT_POS, position);
    fragment.setArguments(args);
    String cTag = "empty";
    Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        cTag = currentFragment.getTag();
        if (!cTag.equals(tag)) {
            if (currentFragment instanceof WelcomeFragment
                    || currentFragment instanceof MonitoredSyslogngFragment
                    || currentFragment instanceof AboutFragment) {
                stackCount = 0;
                transaction.addToBackStack(cTag);
                stackCount++;
            } else {
                if (stackCount < 2) {
                    transaction.addToBackStack(cTag);
                    stackCount++;
                }
            }
        }
    }
    transaction.replace(R.id.container, fragment, tag).commit();
}

From source file:it.gmariotti.cardslib.demo.MainNativeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();//from w  w w .  j  av  a 2s.  c o m
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });

    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new TodoNativeCardFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:com.ffmpeger.card.MainNativeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.ffmpeger.card.R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(com.ffmpeger.card.R.id.drawer_layout);

    mDrawer.setDrawerShadow(com.ffmpeger.card.R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();//ww  w  . j ava  2 s  .  c  o m
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });

    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(com.ffmpeger.card.R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new TodoNativeCardFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:it.gmariotti.cardslib.demo.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();/*from  w  ww  . j a  va  2  s  .  c o  m*/
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });

    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new HeaderFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:org.videolan.vlc.gui.tv.MainTvActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (mSettings.getBoolean(PreferencesActivity.AUTO_RESCAN, true) && Permissions.canReadStorage())
        mMediaLibrary.reload();/*from w  w w. ja  va  2  s. c  om*/

    if (!VLCInstance.testCompatibleCPU(this)) {
        finish();
        return;
    }

    Permissions.checkReadStoragePermission(this, false);

    mContext = this;
    setContentView(R.layout.tv_main);

    mDefaultBackground = getResources().getDrawable(R.drawable.background);
    final FragmentManager fragmentManager = getFragmentManager();
    mBrowseFragment = (BrowseFragment) fragmentManager.findFragmentById(R.id.browse_fragment);
    mProgressBar = (ProgressBar) findViewById(R.id.tv_main_progress);

    // Set display parameters for the BrowseFragment
    mBrowseFragment.setHeadersState(BrowseFragment.HEADERS_ENABLED);
    mBrowseFragment.setTitle(getString(R.string.app_name));
    mBrowseFragment.setBadgeDrawable(getResources().getDrawable(R.drawable.icon));

    // add a listener for selected items
    mBrowseFragment.setOnItemViewClickedListener(this);
    mBrowseFragment.setOnItemViewSelectedListener(this);

    //Enable search feature only if we detect Google Play Services.
    if (AndroidDevices.hasPlayServices()) {
        mBrowseFragment.setOnSearchClickedListener(this);
        // set search icon color
        mBrowseFragment.setSearchAffordanceColor(getResources().getColor(R.color.orange500));
    }

    mRootContainer = mBrowseFragment.getView();
}

From source file:com.fastbootmobile.encore.app.tv.TvActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tv_browsefragment);

    mHandler = new Handler() {
        @Override//from ww  w.ja  v a 2s.c  om
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MSG_NOTIFY_CHANGES:
                if (mRowsAdapter != null) {
                    mRowsAdapter.notifyArrayItemRangeChanged(0, 2);
                }
                break;
            }
        }
    };

    final FragmentManager fragmentManager = getFragmentManager();
    mBrowseFragment = (BrowseFragment) fragmentManager.findFragmentById(R.id.browse_fragment);

    // Set display parameters for the BrowseFragment
    mBrowseFragment.setHeadersState(BrowseFragment.HEADERS_ENABLED);
    mBrowseFragment.setTitle(getString(R.string.app_name));
    mBrowseFragment.setBadgeDrawable(getResources().getDrawable(R.mipmap.ic_launcher));

    // Set search interface
    mBrowseFragment.setOnSearchClickedListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(TvActivity.this, TvSearchActivity.class);
            startActivity(intent);
        }
    });
    mBrowseFragment.setSearchAffordanceColor(getResources().getColor(R.color.primary_dark));

    // Setup event listeners
    mBrowseFragment.setOnItemViewClickedListener(new OnItemViewClickedListener() {
        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                RowPresenter.ViewHolder rowViewHolder, Row row) {
            if (item instanceof Album) {
                Album album = (Album) item;
                int color = getResources().getColor(R.color.primary);
                if (itemViewHolder.view.getTag() != null && itemViewHolder.view.getTag() instanceof Palette) {
                    color = ((Palette) itemViewHolder.view.getTag()).getDarkVibrantColor(color);
                }

                Intent intent = new Intent(TvActivity.this, TvAlbumDetailsActivity.class);
                intent.putExtra(TvAlbumDetailsActivity.EXTRA_ALBUM, album);
                intent.putExtra(TvAlbumDetailsActivity.EXTRA_COLOR, color);

                Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(TvActivity.this,
                        ((ImageCardView) itemViewHolder.view).getMainImageView(),
                        TvAlbumDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
                startActivity(intent, bundle);
            } else if (item instanceof Artist) {
                Artist artist = (Artist) item;
                int color = getResources().getColor(R.color.primary);
                if (itemViewHolder.view.getTag() != null && itemViewHolder.view.getTag() instanceof Palette) {
                    color = ((Palette) itemViewHolder.view.getTag()).getDarkVibrantColor(color);
                }

                Intent intent = new Intent(TvActivity.this, TvArtistDetailsActivity.class);
                intent.putExtra(TvArtistDetailsActivity.EXTRA_ARTIST, artist);
                intent.putExtra(TvArtistDetailsActivity.EXTRA_COLOR, color);

                Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(TvActivity.this,
                        ((ImageCardView) itemViewHolder.view).getMainImageView(),
                        TvArtistDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
                startActivity(intent, bundle);
            } else if (item instanceof Playlist) {
                Playlist playlist = (Playlist) item;
                int color = getResources().getColor(R.color.primary);
                if (itemViewHolder.view.getTag() != null && itemViewHolder.view.getTag() instanceof Palette) {
                    color = ((Palette) itemViewHolder.view.getTag()).getDarkVibrantColor(color);
                }

                Intent intent = new Intent(TvActivity.this, TvPlaylistDetailsActivity.class);
                intent.putExtra(TvPlaylistDetailsActivity.EXTRA_PLAYLIST, playlist);
                intent.putExtra(TvPlaylistDetailsActivity.EXTRA_COLOR, color);

                Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(TvActivity.this,
                        ((ImageCardView) itemViewHolder.view).getMainImageView(),
                        TvAlbumDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
                startActivity(intent, bundle);
            } else if (item instanceof SettingsItem) {
                SettingsItem sitem = (SettingsItem) item;
                switch (sitem.getType()) {
                case SettingsItem.ITEM_PROVIDERS:
                    startActivity(new Intent(TvActivity.this, TvProvidersActivity.class));
                    break;

                case SettingsItem.ITEM_EFFECTS:
                    Intent intent = new Intent(TvActivity.this, TvProvidersActivity.class);
                    intent.putExtra(TvProvidersActivity.EXTRA_DSP_MODE, true);
                    startActivity(intent);
                    break;
                }
            } else if (item instanceof MyLibraryItem) {
                MyLibraryItem libraryItem = (MyLibraryItem) item;
                Intent intent = new Intent(TvActivity.this, TvEntityGridActivity.class);
                switch (libraryItem.getType()) {
                case MyLibraryItem.TYPE_ALBUMS:
                    intent.putExtra(TvEntityGridActivity.EXTRA_MODE, TvEntityGridActivity.MODE_ALBUM);
                    break;

                case MyLibraryItem.TYPE_ARTISTS:
                    intent.putExtra(TvEntityGridActivity.EXTRA_MODE, TvEntityGridActivity.MODE_ARTIST);
                    break;
                }

                startActivity(intent);
            }
        }
    });

    // Build adapter items
    mHandler.postDelayed(new Runnable() {
        public void run() {
            buildRowsAdapter();
        }
    }, 1500);
}

From source file:edu.ncku.application.fragments.LibMapFragment.java

private MapFragment getMapFragment() {
    FragmentManager fm = null;

    Log.d(TAG, "sdk: " + Build.VERSION.SDK_INT);
    Log.d(TAG, "release: " + Build.VERSION.RELEASE);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Log.d(TAG, "using getFragmentManager");
        fm = getFragmentManager();/*from w w  w. ja va  2  s. co  m*/
    } else {
        Log.d(TAG, "using getChildFragmentManager");
        fm = getChildFragmentManager();
    }

    return (MapFragment) fm.findFragmentById(R.id.map);
}