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

The following examples show how to use android.app.FragmentManager#findFragmentById() . 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
Source File: SettingsActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: SettingsActivity.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: LoaderCustom.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@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 4
Source File: FaBoArduinoActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * サービスとバインドされたことをを通知します.
 */
private void notifyBindService() {
    FragmentManager manager = getFragmentManager();
    Fragment f = manager.findFragmentById(R.id.fragment_container);
    if (f != null && f instanceof FaBoArduinoFragment) {
        ((FaBoArduinoFragment) f).onBindService();
    }

}
 
Example 5
Source File: QuoteViewerActivity.java    From coursera-android with 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 6
Source File: LicenseActivity.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: FragmentTransactionBuilder.java    From SafelyAndroid with MIT License 5 votes vote down vote up
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 8
Source File: ConversationFragment.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: LoaderCursor.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@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 10
Source File: SingleFragmentActivity.java    From AndroidProgramming3e with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: LoaderThrottle.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@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 12
Source File: MainTvActivity.java    From VCL-Android with 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 13
Source File: SettingsActivity.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: ConversationFragment.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
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 15
Source File: SettingsActivity.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
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 16
Source File: MainActivity.java    From Android-License-Fragment with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: DirectoryFragment.java    From FireFiles with 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 18
Source File: RootsFragment.java    From FireFiles with 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 19
Source File: FragmentManagerHelper.java    From JianshuApp with GNU General Public License v3.0 4 votes vote down vote up
public <T extends Fragment> T find(@IdRes int id) {
    FragmentManager fm = getFragmentManager();
    return (T) fm.findFragmentById(id);
}
 
Example 20
Source File: MainActivity.java    From Android-License-Fragment with Apache License 2.0 4 votes vote down vote up
@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;
    }