Java Code Examples for android.app.FragmentManager#findFragmentById()

The following examples show how to use android.app.FragmentManager#findFragmentById() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(toolbar);

    FragmentManager fm = getFragmentManager();
    Fragment f = fm.findFragmentById(R.id.content);
    if (f == null) {
        fm.beginTransaction()
                .replace(R.id.content,
                        new SettingsFragment())
                .commit();
    }
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setTitle(R.string.settings);
}
 
Example 2
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_settings);
	FragmentManager fm = getFragmentManager();
	mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.settings_content);
	if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
		mSettingsFragment = new SettingsFragment();
		fm.beginTransaction().replace(R.id.settings_content, mSettingsFragment).commit();
	}
	mSettingsFragment.setActivityIntent(getIntent());
	this.mTheme = findTheme();
	setTheme(this.mTheme);
	getWindow().getDecorView().setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_primary));
	setSupportActionBar(findViewById(R.id.toolbar));
	configureActionBar(getSupportActionBar());
}
 
Example 3
private void setResultAndFinish() {
    Intent data = new Intent();
    FragmentManager fm = getFragmentManager();
    SettingsFragment f = (SettingsFragment) fm.findFragmentById(R.id.content);
    data.putExtra("bufferChanged", f.getBufferChanged());
    setResult(RESULT_OK, data);
    finish();
}
 
Example 4
public static ConversationFragment get(Activity activity) {
    FragmentManager fragmentManager = activity.getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
    if (fragment != null && fragment instanceof ConversationFragment) {
        return (ConversationFragment) fragment;
    } else {
        fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
        return fragment != null && fragment instanceof ConversationFragment ? (ConversationFragment) fragment : null;
    }
}
 
Example 5
private void setResultAndFinish() {
    Intent data = new Intent();
    FragmentManager fm = getFragmentManager();
    SettingsFragment f = (SettingsFragment) fm.findFragmentById(R.id.content);
    data.putExtra("bufferChanged", f.getBufferChanged());
    setResult(RESULT_OK, data);
    finish();
}
 
Example 6
Source Project: VCL-Android   File: MainTvActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (mMediaLibrary.getMediaItems().isEmpty()) {
        if (mSettings.getBoolean(PreferencesActivity.AUTO_RESCAN, true))
            mMediaLibrary.scanMediaItems(false);
        else
            mMediaLibrary.loadMedaItems();
    }

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

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

    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);

    if (!Build.MANUFACTURER.equalsIgnoreCase("amazon")) { //Hide search for Amazon Fire TVs
        mBrowseFragment.setOnSearchClickedListener(this);
        // set search icon color
        mBrowseFragment.setSearchAffordanceColor(getResources().getColor(R.color.orange500));
    }
    mRootContainer = mBrowseFragment.getView();
}
 
Example 7
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        ThrottledLoaderListFragment list = new ThrottledLoaderListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }
}
 
Example 8
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        AppListFragment list = new AppListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }
}
 
Example 9
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResId());
    FragmentManager manager = getFragmentManager();
    Fragment fragment = manager.findFragmentById(R.id.fragmentContainer);

    if (fragment == null) {
        fragment = createFragment();
        manager.beginTransaction()
            .add(R.id.fragmentContainer, fragment)
            .commit();
    }
}
 
Example 10
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        CursorLoaderListFragment list = new CursorLoaderListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }
}
 
Example 11
public static ConversationFragment get(Activity activity) {
    FragmentManager fragmentManager = activity.getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
    if (fragment != null && fragment instanceof ConversationFragment) {
        return (ConversationFragment) fragment;
    } else {
        fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
        return fragment != null && fragment instanceof ConversationFragment ? (ConversationFragment) fragment : null;
    }
}
 
Example 12
private void checkIdNotExist(FragmentManager fragmentManager, @IdRes int id)
        throws IllegalStateException {
    if (fragmentManager.findFragmentById(id) != null) {
        throw new IllegalStateException("fragment with id "
                + id
                + " already exist: "
                + fragmentManager.findFragmentById(id));
    }
}
 
Example 13
@Override protected void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setTitle(R.string.more_fragment_item_open_source);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    FragmentManager fragmentManager = getFragmentManager();
    ScrollViewLicenseFragment licenseFragment
        = (ScrollViewLicenseFragment) fragmentManager.findFragmentById(R.id.fragment_license);
    licenseFragment.setLog(true);
    licenseFragment.addLicense(
        new int[] { LicenseID.GSON, LicenseID.LICENSE_FRAGMENT, LicenseID.OKHTTP,
            LicenseID.RETROFIT, LicenseID.PICASSO });
    ArrayList<License> customLicenses = new ArrayList<>();
    customLicenses.add(
        new License(this, "MaterialPreference", LicenseType.MIT_LICENSE, "2015",
            "Jens Driller"));
    customLicenses.add(
        new License(this, "ActiveAndroid", LicenseType.APACHE_LICENSE_20, "2010",
            "Michael Pardo"));
    customLicenses.add(
        new License(this, "MaterialBottomNavigation ", LicenseType.MIT_LICENSE, "2016",
            " Alessandro Crugnola"));
    customLicenses.add(
        new License(this, "PhotoView", LicenseType.APACHE_LICENSE_20, "2011-2012",
            "Chris Banes"));
    customLicenses.add(
        new License(this, "MagicaSakura", LicenseType.APACHE_LICENSE_20, "2016", "Bilibili"));
    customLicenses.add(
        new License(this, "Android Open Source Project", LicenseType.APACHE_LICENSE_20,
            "2009-2012", "Android Open Source Project"));
    licenseFragment.addCustomLicense(customLicenses);
}
 
Example 14
Source Project: coursera-android   File: QuoteViewerActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.i(TAG, getClass().getSimpleName() + ":entered onCreate()");

    // Get the string arrays with the titles and quotes
    mTitleArray = getResources().getStringArray(R.array.Titles);
    mQuoteArray = getResources().getStringArray(R.array.Quotes);
    mNoQuoteSelectedString = getResources().getString(R.string.noQuoteSelected);

    setContentView(R.layout.quote_activity);

    // Get a reference to the FragmentManager
    FragmentManager fragmentManager = getFragmentManager();


    if (null == fragmentManager.findFragmentById(R.id.title_frame)) {

        // Begin a new FragmentTransaction
        FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction();

        // Add the TitleFragment
        fragmentTransaction.add(R.id.title_frame, new TitlesFragment());

        // Add the QuoteFragment
        mQuoteFragment = new QuotesFragment();
        fragmentTransaction.add(R.id.quote_frame, mQuoteFragment);

        // Commit the FragmentTransaction
        fragmentTransaction.commit();
    } else {
        mQuoteFragment = (QuotesFragment) fragmentManager.findFragmentById(R.id.quote_frame);
    }
}
 
Example 15
/**
 * サービスとバインドされたことをを通知します.
 */
private void notifyBindService() {
    FragmentManager manager = getFragmentManager();
    Fragment f = manager.findFragmentById(R.id.fragment_container);
    if (f != null && f instanceof FaBoArduinoFragment) {
        ((FaBoArduinoFragment) f).onBindService();
    }

}
 
Example 16
@Override
    public void onNavigationDrawerItemSelected(int position) {
//        if (true) return;
        FragmentManager fragmentManager = getFragmentManager();
        Fragment fragment;

        ArrayList<Integer> licenseIds = new ArrayList<>();
        licenseIds.add(LicenseID.GSON);
        licenseIds.add(LicenseID.RETROFIT);

        switch (position) {
            case 0:
                if (fragmentManager.findFragmentById(R.id.container) instanceof ScrollViewLicenseFragment) return;
                fragment = ScrollViewLicenseFragment.newInstance(licenseIds);   // Call newInstance() using parameter ArrayList<Integer>
                break;
            case 1:
                if (fragmentManager.findFragmentById(R.id.container) instanceof ListViewLicenseFragment) return;
                fragment = ListViewLicenseFragment.newInstance(new int[]{LicenseID.PICASSO}) // Call newInstance() using parameter array
                        .withLicenseChain(false);                                               // Disable license chain
                break;
            case 2:
                if (fragmentManager.findFragmentById(R.id.container) instanceof RecyclerViewLicenseFragment) return;
                ArrayList<License> licenses = new ArrayList<>();
                licenses.add(new License(this, "Test Library 1", LicenseType.MIT_LICENSE, "2000-2001", "Test Owner 1"));
                licenses.add(new License(this, "Test Library 2", LicenseType.GPL_30, "2002", "Test Owner 2"));
                licenses.add(new License(this, "Test Library 3", LicenseType.EPL_10, "2003", "Test Owner 3"));
                licenses.add(new License(this, "Custom License 1", R.raw.wtfpl, "2004", "Test Owner 3"));
                licenses.add(new License(this, "Custom License 2", R.raw.x11, "2005", "Test Owner 4"));
                fragment = RecyclerViewLicenseFragment.newInstance()    // Call newInstance() using without parameter
                        .setLog(true)                                   // Enable Log
                        .withLicenseChain(true)                         // Enable license chain (default)
                        .addLicense(new int[] { LicenseID.PICASSO })    // Add array (same call newInstance)
                        .addLicense(licenseIds)                         // Add ArrayList<Integer> (same call newInstance)
                        .addCustomLicense(licenses)                     // Add Custom License
                        .setCustomUI(new CustomUI()                     // Set Custom UI
                                .setTitleBackgroundColor(Color.parseColor("#7fff7f"))
                                .setTitleTextColor(getResources().getColor(android.R.color.holo_green_dark))
                                .setLicenseBackgroundColor(Color.rgb(127, 223, 127))
                                .setLicenseTextColor(Color.DKGRAY));
                break;
            default:
                return;
        }

//        ((LicenseFragmentBase) fragment).setLog(true);

        // update the main content by replacing fragments
        fragmentManager.beginTransaction()
                .replace(R.id.container, fragment)
                .commit();

        fragmentId = position + 1;
    }
 
Example 17
Source Project: FireFiles   File: RootsFragment.java    License: Apache License 2.0 4 votes vote down vote up
public static RootsFragment get(FragmentManager fm) {
    return (RootsFragment) fm.findFragmentById(R.id.container_roots);
}
 
Example 18
Source Project: FireFiles   File: DirectoryFragment.java    License: Apache License 2.0 4 votes vote down vote up
public static Fragment get(FragmentManager fm) {
	// TODO: deal with multiple directories shown at once
	return fm.findFragmentById(R.id.container_directory);
}
 
Example 19
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FragmentManager fragmentManager = getFragmentManager();

        mNavigationDrawerFragment = (NavigationDrawerFragment)
                fragmentManager.findFragmentById(R.id.navigation_drawer);
        if (savedInstanceState == null) mTitle = getTitle();

        // Set up the drawer.
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));

//        ScrollViewLicenseFragment scrollViewLicenseFragment = (ScrollViewLicenseFragment) fragmentManager.findFragmentById(R.id.fragment);
//        scrollViewLicenseFragment.setLog(true);
//        scrollViewLicenseFragment.addLicense(new int[]{LicenseID.PICASSO, LicenseID.STATED_FRAGMENT, LicenseID.GSON});

//        ListViewLicenseFragment listViewLicenseFragment = (ListViewLicenseFragment) fragmentManager.findFragmentById(R.id.fragment);
//
//        listViewLicenseFragment.setLog(true);
//        listViewLicenseFragment.addLicense(new int[]{LicenseID.PICASSO, LicenseID.STATED_FRAGMENT, LicenseID.GSON});
//        listViewLicenseFragment.withLicenseChain(false);
//
//        ArrayList<License> licenses = new ArrayList<>();
//        licenses.add(new License(this, "Title", LicenseType.BSD_3_CLAUSE, "YEAR", "OWNER"));
//        listViewLicenseFragment.addCustomLicense(licenses);

//        RecyclerViewLicenseFragment recyclerViewLicenseFragment = (RecyclerViewLicenseFragment) fragmentManager.findFragmentById(R.id.fragment);
//
//        recyclerViewLicenseFragment.setLog(true);
//        recyclerViewLicenseFragment.addLicense(new int[]{LicenseID.PICASSO, LicenseID.STATED_FRAGMENT, LicenseID.GSON});
//        recyclerViewLicenseFragment.withLicenseChain(false);
//
//        ArrayList<License> licenses = new ArrayList<>();
//        licenses.add(new License(this, "Title", LicenseType.BSD_3_CLAUSE, "YEAR", "OWNER"));
//        recyclerViewLicenseFragment.addCustomLicense(licenses);
//        recyclerViewLicenseFragment.setCustomUI(new CustomUI().setTitleBackgroundColor(Color.RED));
    }
 
Example 20
public <T extends Fragment> T find(@IdRes int id) {
    FragmentManager fm = getFragmentManager();
    return (T) fm.findFragmentById(id);
}