Example usage for android.app FragmentManager findFragmentByTag

List of usage examples for android.app FragmentManager findFragmentByTag

Introduction

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

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

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

Usage

From source file:com.blue.leaves.util.task.SugarTask.java

private void unregisterHookToContext(@NonNull android.support.v4.app.Fragment fragment) {
    android.support.v4.app.FragmentManager manager = fragment.getChildFragmentManager();

    HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK);
    if (hookSupportFragment != null) {
        hookSupportFragment.postEnable = false;
        manager.beginTransaction().remove(hookSupportFragment).commitAllowingStateLoss();
    }/*from  w ww.  j ava2s  .com*/
}

From source file:com.blue.leaves.util.task.SugarTask.java

private void registerHookToContext(@NonNull FragmentActivity activity) {
    android.support.v4.app.FragmentManager manager = activity.getSupportFragmentManager();

    HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK);
    if (hookSupportFragment == null) {
        hookSupportFragment = new HookSupportFragment();
        manager.beginTransaction().add(hookSupportFragment, TAG_HOOK).commitAllowingStateLoss();
    }//w  w  w  . j  ava  2 s.  c o m
}

From source file:com.blue.leaves.util.task.SugarTask.java

private void unregisterHookToContext(@NonNull FragmentActivity activity) {
    android.support.v4.app.FragmentManager manager = activity.getSupportFragmentManager();

    HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK);
    if (hookSupportFragment != null) {
        hookSupportFragment.postEnable = false;
        manager.beginTransaction().remove(hookSupportFragment).commitAllowingStateLoss();
    }//w ww .  j  av  a 2s  . com
}

From source file:com.cloudbees.gasp.activity.TwitterStreamActivity.java

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

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Use simple FrameLayout for ListFragment
    setContentView(R.layout.gasp_frame_layout);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ListFragment list = new ListFragment();
    ft.add(R.id.fragment_content, list);

    // Use a simple TextView layout for ArrayAdapter constructor
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_generic_textview);

    // Map ArrayAdapter to ListFragment
    list.setListAdapter(mAdapter);/*from  w  w w  .  ja  v a2 s  . com*/

    // RESTResponderFragments call setRetainedInstance(true) in onCreate()
    TwitterResponderFragment responder = (TwitterResponderFragment) fm
            .findFragmentByTag(getString(R.string.twitter_responder));
    if (responder == null) {
        responder = new TwitterResponderFragment();

        ft.add(responder, getString(R.string.twitter_responder));
    }

    ft.commit();
}

From source file:org.catnut.ui.MainActivity.java

/**
 * ?fragment//ww  w  . j  ava  2  s  . c  om
 *
 * @param fragment
 * @param tag      null??
 */
private void pendingFragment(Fragment fragment, String tag) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment tmp = fragmentManager.findFragmentByTag(tag);
    if (tmp == null || !tmp.isVisible()) {
        fragmentManager.beginTransaction()
                .setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                        R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit)
                .replace(R.id.fragment_container, fragment, tag).addToBackStack(null).commit();
        mScrollSettleHandler.post(new Runnable() {
            @Override
            public void run() {
                invalidateOptionsMenu();
            }
        });
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showFragment(final FragmentManager fragmentManager, final Fragment fragment,
        final boolean addToBackStack, final String tag) {
    // hide the full screen container
    hideFullScreenView();/*  w w w  .  ja v  a  2  s.co  m*/

    if (fragmentManager.findFragmentByTag(tag) == null) {
        final int viewId = mContentContainer.addBorderView(this);
        updateCurrentPresenterClass(fragment, viewId);

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(viewId, fragment, tag);
        if (addToBackStack) {
            transaction.addToBackStack(tag);
        }
        transaction.commitAllowingStateLoss();
    } else {
        fragmentManager.beginTransaction().detach(fragment).attach(fragment).commitAllowingStateLoss();
    }
}

From source file:com.versobit.kmark.clarity.DbProcessorFragment.java

public void bind() {
    FragmentManager fm = getFragmentManager();
    if (fm == null) {
        return;/*from  w w  w  .  ja  va  2s . c om*/
    }
    callback = (Callbacks) fm.findFragmentByTag(getArguments().getString(ARG_REPORTS_TO));
}

From source file:by.zatta.pilight.MainActivity.java

@Override
public void onViewChangeListener(Boolean forceList) {
    FragmentManager fm = getFragmentManager();
    BaseFragment prev = (BaseFragment) fm.findFragmentByTag("DeviceList");
    if (prev != null)
        prev.onCreate(null);//from   w  ww.  j  a  v  a 2  s .  c  om
}

From source file:by.zatta.pilight.MainActivity.java

private void closeDialogFragments() {
    FragmentManager fm = getFragmentManager();
    DialogFragment prev = (DialogFragment) fm.findFragmentByTag("dialog");
    if (prev != null) {
        prev.dismiss();// w  w  w .  j  ava 2  s . c  o m
    }
}

From source file:org.opendatakit.survey.android.fragments.InstanceUploaderListFragment.java

@Override
public void onResume() {
    super.onResume();

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    getListView().setItemsCanFocus(false);

    // if current activity is being reinitialized due to changing
    // orientation restore all checkmarks for ones selected
    ListView ls = getListView();//from   w  w  w.jav a 2 s . co m
    for (String id : mSelected) {
        for (int pos = 0; pos < ls.getCount(); pos++) {
            Cursor c = (Cursor) ls.getItemAtPosition(pos);
            String uuid = ODKDatabaseUtils.get().getIndexAsString(c, c.getColumnIndex(InstanceColumns._ID));
            if (id.equals(uuid)) {
                ls.setItemChecked(pos, true);
                break;
            }
        }

    }

    FragmentManager mgr = getFragmentManager();
    BackgroundTaskFragment f = (BackgroundTaskFragment) mgr.findFragmentByTag("background");

    f.establishInstanceUploaderListener(this);

    if (mDialogState == DialogState.Progress) {
        restoreProgressDialog();
    } else if (mDialogState == DialogState.Alert) {
        restoreAlertDialog();
    }
}