Example usage for android.support.v4.app FragmentManager findFragmentById

List of usage examples for android.support.v4.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.support.v4.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:com.example.scrumptious.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        userSkippedLogin = savedInstanceState.getBoolean(USER_SKIPPED_LOGIN_KEY);
    }//from   ww w . j a v a2s .  c  o  m
    callbackManager = CallbackManager.Factory.create();

    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (isResumed) {
                FragmentManager manager = getSupportFragmentManager();
                int backStackSize = manager.getBackStackEntryCount();
                for (int i = 0; i < backStackSize; i++) {
                    manager.popBackStack();
                }
                if (currentAccessToken != null) {
                    showFragment(SELECTION, false);
                } else {
                    showFragment(SPLASH, false);
                }
            }
        }
    };

    setContentView(R.layout.main);

    FragmentManager fm = getSupportFragmentManager();
    SplashFragment splashFragment = (SplashFragment) fm.findFragmentById(R.id.splashFragment);
    fragments[SPLASH] = splashFragment;
    fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
    fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);

    FragmentTransaction transaction = fm.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();

    splashFragment.setSkipLoginCallback(new SplashFragment.SkipLoginCallback() {
        @Override
        public void onSkipLoginPressed() {
            userSkippedLogin = true;
            showFragment(SELECTION, false);
        }
    });
}

From source file:com.darizotas.metadatastrip.FileListActivity.java

/**
 * Callback method from {@link FileListFragment.Callbacks} indicating that
 * the item with the given PATH was selected.
 *//*from   w w w .  java2  s  .  c  om*/
@Override
public void onItemSelected(String path) {
    File file = new File(path);
    if (file.canRead()) {
        if (file.isDirectory()) {
            FragmentManager manager = getSupportFragmentManager();

            if (mTwoPane) {
                // Removes the previous detail fragment
                Fragment fragment = manager.findFragmentById(R.id.file_detail_container);
                if (fragment != null) {
                    manager.beginTransaction().remove(fragment).commit();
                    //http://stackoverflow.com/questions/7246479/android-fragmenttransaction-commit-when
                    manager.executePendingTransactions();
                }
            }
            // Updates the list.
            ((FileListFragment) manager.findFragmentById(R.id.file_list)).updateListAdapter(file.getPath());

        } else {
            showDetails(path);
        }
        // The folder cannot be read.
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.ic_launcher)
                .setTitle("[" + file.getName() + "] " + getResources().getText(R.string.error_open_file))
                .setPositiveButton("OK", null).show();
    }
}

From source file:com.jefftharris.passwdsafe.LauncherRecordShortcuts.java

@Override
public void updateViewList(PasswdLocation location) {
    PasswdSafeUtil.dbginfo(TAG, "updateViewList: ", location);
    itsLocation = location;//from   w ww .j a v  a  2s.  c o  m
    itsFileDataView.setCurrGroups(itsLocation.getGroups());

    FragmentManager fragMgr = getSupportFragmentManager();
    Fragment contentsFrag = fragMgr.findFragmentById(R.id.contents);
    if (contentsFrag instanceof PasswdSafeListFragment) {
        ((PasswdSafeListFragment) contentsFrag).updateLocationView(itsLocation,
                PasswdSafeListFragment.Mode.ALL);
    }
}

From source file:com.facebook.reflection.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        userSkippedLogin = savedInstanceState.getBoolean(USER_SKIPPED_LOGIN_KEY);
    }/*from  www . j av a  2 s  .c  o  m*/
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    FragmentManager fm = getSupportFragmentManager();
    SplashFragment splashFragment = (SplashFragment) fm.findFragmentById(R.id.splashFragment);
    fragments[SPLASH] = splashFragment;
    fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
    fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);

    FragmentTransaction transaction = fm.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();

    splashFragment.setSkipLoginCallback(new SplashFragment.SkipLoginCallback() {
        @Override
        public void onSkipLoginPressed() {
            userSkippedLogin = true;
            showFragment(SELECTION, false);
        }
    });
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.home.HomeActivity.java

private void setMainFragment(@NonNull final String name) {
    final FragmentManager fm = getSupportFragmentManager();
    final Fragment fragment = fm.findFragmentById(R.id.content);
    FragmentTransaction ft = null;/*w ww .j a  v  a2  s .  c  o  m*/
    if (fragment == null) {
        ft = fm.beginTransaction();
        ft.add(R.id.content, Fragment.instantiate(this, name));
    } else if (!name.equals(fragment.getClass().getCanonicalName())) {
        ft = fm.beginTransaction();
        ft.replace(R.id.content, Fragment.instantiate(this, name));
    }
    if (ft != null) {
        ft.commit();
    }
}

From source file:com.physphil.android.restaurantroulette.MainActivity.java

/**
 * This is called once selected fragment is loaded and drawer is closed
 *///from   w  w w. j  a va2s .com
public void restoreActionBar() {
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);

    if (mTitle != null) {
        actionBar.setTitle(mTitle);
    }

    // Set up filtering in action bar in RestaurantListFragment
    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.container);

    if (fragment instanceof RestaurantListFragment) {

        ((RestaurantListFragment) fragment).setupListFiltering();
    }
}

From source file:com.goliathonline.android.kegbot.ui.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!EulaHelper.hasAcceptedEula(this)) {
        EulaHelper.showEula(false, this);
    }//  w  ww  .j a  va 2  s  .c om

    if (!PrefsHelper.hasAPIUrl(this)) {
        final Intent launchPreferencesIntent = new Intent().setClass(this, PreferencesActivity.class);

        AlertDialog.Builder eula = new AlertDialog.Builder(this).setTitle("Setup API URL")
                .setIcon(android.R.drawable.ic_dialog_info)
                .setMessage("The kegbot api url needs to be entered to continue.").setCancelable(false)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                        // Make it a subactivity so we know when it returns
                        startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
                    }
                });
        eula.show();

    }

    AnalyticsUtils.getInstance(this).trackPageView("/Home");

    setContentView(R.layout.activity_home);
    getActivityHelper().setupActionBar(null, 0);

    FragmentManager fm = getSupportFragmentManager();

    mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream);

    mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm
            .findFragmentByTag(SyncStatusUpdaterFragment.TAG);
    if (mSyncStatusUpdaterFragment == null) {
        mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment();
        fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit();

        triggerRefresh();
    }
}

From source file:mobisocial.bento.todo.ui.BentoListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // create Musubi Instance
    InitialHelper initHelper = new InitialHelper(this, mInitCompleteListener);
    Musubi musubi = initHelper.initMusubiInstance();
    if (musubi == null) {
        return;//  w  w  w  .j a  va  2s .c  om
    }

    setContentView(R.layout.activity_bento_list);

    final ActionBar actionBar = getSupportActionBar();
    // set defaults for logo & home up
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    FragmentManager fm = getSupportFragmentManager();
    mBentoListFragment = (BentoListFragment) fm.findFragmentById(R.id.fragment_bento_list);
    mManager.addListener(mStateUpdatedListener);
}

From source file:ch.corten.aha.worldclock.EditClockActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    LayoutInflater inflator = (LayoutInflater) actionBar.getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflator.inflate(R.layout.actionbar_custom_view_done_discard, null);
    customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(new View.OnClickListener() {
        @Override/*  w w  w.j  a va  2  s . c om*/
        public void onClick(View v) {
            finish();
        }
    });
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragment().done();
        }
    });

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    FragmentManager fm = getSupportFragmentManager();
    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        EditClockFragment fragment = new EditClockFragment();
        fm.beginTransaction().add(android.R.id.content, fragment).commit();
    }
}

From source file:com.dwdesign.tweetings.activity.SearchActivity.java

@Override
public void onBackStackChanged() {
    super.onBackStackChanged();
    if (!isDualPaneMode())
        return;//from w  w  w .  j a  va  2  s .c o  m
    final FragmentManager fm = getSupportFragmentManager();
    final Fragment left_pane_fragment = fm.findFragmentById(PANE_LEFT);
    final boolean left_pane_used = left_pane_fragment != null && left_pane_fragment.isAdded();
    setPagingEnabled(!left_pane_used);
    final int count = fm.getBackStackEntryCount();
    if (mActionBar != null && mDisplayAppIcon) {
        mActionBar.setDisplayHomeAsUpEnabled(count > 0);
    }
    if (count == 0) {
        bringLeftPaneToFront();
    }
}