Example usage for android.app Fragment instantiate

List of usage examples for android.app Fragment instantiate

Introduction

In this page you can find the example usage for android.app Fragment instantiate.

Prototype

public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) 

Source Link

Document

Create a new instance of a Fragment with the given class name.

Usage

From source file:net.sakuramilk.kbcupdater.TabsFragmentAdapter.java

@Override
public Fragment getItem(int position) {
    TabInfo info = mTabs.get(position);/*from  w w  w. j av a2s  . c  o m*/
    Fragment f = Fragment.instantiate(mContext, info.clss.getName(), info.args);
    return f;
}

From source file:net.zhuoweizhang.scripteval.TabsAdapter.java

@Override
public Fragment getItem(int position) {
    TabInfo info = mTabs.get(position);
    return Fragment.instantiate(mActivity, info.clss.getName(), info.args);
}

From source file:com.codebutler.farebot.ui.TabPagerAdapter.java

@Override
@SuppressLint("CommitTransaction")
@SuppressWarnings("deprecation")
public Object instantiateItem(View view, int position) {
    TabInfo info = mTabs.get(position);// w  w w .j a v a  2 s . c  om

    if (mCurTransaction == null) {
        mCurTransaction = mActivity.getFragmentManager().beginTransaction();
    }

    Fragment fragment = Fragment.instantiate(mActivity, info.mClass.getName(), info.mArgs);
    mCurTransaction.add(R.id.pager, fragment);
    return fragment;
}

From source file:ca.mymenuapp.ui.widgets.SwipeableActionBarTabsAdapter.java

@Override
public Fragment getItem(int position) {
    TabInfo info = tabs.get(position);
    return Fragment.instantiate(context, info.clss.getName(), info.args);
}

From source file:com.first3.viz.utils.TabsAdapter.java

public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
    mTabs.add(clss.getName());/*ww w .  j a v a2 s  . co m*/
    mArgs.add(args);
    mActionBar.addTab(tab.setTabListener(this));

    Fragment frag = Fragment.instantiate(mContext, clss.getName(), args);
    mFragments.put(tab, frag);

    notifyDataSetChanged();
}

From source file:com.epitrack.guardioes.view.base.BaseActivity.java

@Override
public int add(final Class<? extends Fragment> fragmentClass, final String tag, final Bundle bundle,
        final boolean addToBackStack) {

    if (fragmentClass == null) {
        throw new IllegalArgumentException("The fragmentClass cannot be null.");
    }//from   www.ja  v  a2s.  c  o m

    if (tag == null) {
        throw new IllegalArgumentException("The tag cannot be null.");
    }

    if (fragmentMap == null) {
        fragmentMap = new ReferenceMap<>();
    }

    Fragment fragment = fragmentMap.get(tag);

    if (fragment == null) {

        fragment = Fragment.instantiate(this, fragmentClass.getName(), bundle);

        fragmentMap.put(tag, fragment);
    }

    if (addToBackStack) {

        return getFragmentManager().beginTransaction().add(getLayout(), fragment, tag).addToBackStack(tag)
                .commit();
    }

    return getFragmentManager().beginTransaction().add(getLayout(), fragment, tag).commit();
}

From source file:com.android.settings.profiles.TriggerPagerAdapter.java

/**
 * {@inheritDoc}/*from www  .  j  a va 2s.  c om*/
 */
@Override
public Fragment getItem(final int position) {
    final Holder mCurrentHolder = mHolderList.get(position);
    final Fragment mFragment = Fragment.instantiate(mFragmentActivity, mCurrentHolder.mClassName,
            mCurrentHolder.mParams);
    return mFragment;
}

From source file:net.lacolaco.smileessence.view.adapter.PageListAdapter.java

@Override
public synchronized Fragment getItem(int position) {
    PageInfo info = pages.get(position);
    return Fragment.instantiate(context, info.fragmentClass.getName(), info.args);
}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

@SuppressFBWarnings("DM_EXIT")
@SuppressLint("InlinedApi")
@Override// www. j av  a  2  s .  c  om
protected void onCreate(Bundle savedInstanceState) {
    ensureActivityNotExported();

    // The browser process must be started here because this Activity may be started explicitly
    // from Android notifications, when Android is restoring Preferences after Chrome was
    // killed, or for tests. This should happen before super.onCreate() because it might
    // recreate a fragment, and a fragment might depend on the native library.
    try {
        ((ChromeApplication) getApplication()).startBrowserProcessesAndLoadLibrariesSync(true);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // This can only ever happen, if at all, when the activity is started from an Android
        // notification (or in tests). As such we don't want to show an error messsage to the
        // user. The application is completely broken at this point, so close it down
        // completely (not just the activity).
        System.exit(-1);
        return;
    }

    super.onCreate(savedInstanceState);

    mIsNewlyCreated = savedInstanceState == null;

    String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
    Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    boolean displayHomeAsUp = getIntent().getBooleanExtra(EXTRA_DISPLAY_HOME_AS_UP, true);

    if (displayHomeAsUp)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // This must be called before the fragment transaction below.
    workAroundPlatformBugs();

    // If savedInstanceState is non-null, then the activity is being
    // recreated and super.onCreate() has already recreated the fragment.
    if (savedInstanceState == null) {
        if (initialFragment == null)
            initialFragment = MainPreferences.class.getName();
        Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
        getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
    }

    if (checkPermission(Manifest.permission.NFC, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
        // Disable Android Beam on JB and later devices.
        // In ICS it does nothing - i.e. we will send a Play Store link if NFC is used.
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(null, this);
    }

    Resources res = getResources();
    ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name),
            BitmapFactory.decodeResource(res, R.mipmap.app_icon),
            ApiCompatibilityUtils.getColor(res, R.color.default_primary_color));
}

From source file:android.app.FragmentState.java

public Fragment instantiate(Activity activity, Fragment parent) {
    if (mInstance != null) {
        return mInstance;
    }/*  ww w  .ja  va2s . co  m*/

    if (mArguments != null) {
        mArguments.setClassLoader(activity.getClassLoader());
    }

    mInstance = Fragment.instantiate(activity, mClassName, mArguments);

    if (mSavedFragmentState != null) {
        mSavedFragmentState.setClassLoader(activity.getClassLoader());
        mInstance.mSavedFragmentState = mSavedFragmentState;
    }
    mInstance.setIndex(mIndex, parent);
    mInstance.mFromLayout = mFromLayout;
    mInstance.mRestored = true;
    mInstance.mFragmentId = mFragmentId;
    mInstance.mContainerId = mContainerId;
    mInstance.mTag = mTag;
    mInstance.mRetainInstance = mRetainInstance;
    mInstance.mDetached = mDetached;
    mInstance.mFragmentManager = activity.mFragments;
    if (FragmentManagerImpl.DEBUG)
        Log.v(FragmentManagerImpl.TAG, "Instantiated fragment " + mInstance);

    return mInstance;
}