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

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

Introduction

In this page you can find the example usage for android.support.v4.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.filemanager.free.fragments.Main.java

public void onListItemClicked(int position, View v) {
    if (position >= LIST_ELEMENTS.size())
        return;//from w ww. ja  v a  2 s  . co m
    if (results) {
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        SearchAsyncHelper fragment = (SearchAsyncHelper) fragmentManager
                .findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
        if (fragment != null) {

            if (fragment.mSearchTask.getStatus() == AsyncTask.Status.RUNNING) {

                fragment.mSearchTask.cancel(true);
            }
            getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
        }

        mRetainSearchTask = true;
        results = false;
    } else {
        mRetainSearchTask = false;
        MainActivityHelper.SEARCH_TEXT = null;
    }
    if (selection == true) {
        if (!LIST_ELEMENTS.get(position).getSize().equals(goback)) {
            adapter.toggleChecked(position);
        } else {
            selection = false;
            if (mActionMode != null)
                mActionMode.finish();
            mActionMode = null;
        }

    } else {
        if (!LIST_ELEMENTS.get(position).getSize().equals(goback)) {

            String path;
            Layoutelements l = LIST_ELEMENTS.get(position);
            if (!l.hasSymlink()) {

                path = l.getDesc();
            } else {

                path = l.getSymlink();
            }
            if (LIST_ELEMENTS.get(position).isDirectory()) {
                computeScroll();
                loadlist(path, false, openMode);
            } else {
                if (l.getMode() == HFile.SMB_MODE)
                    try {
                        SmbFile smbFile = new SmbFile(l.getDesc());
                        launch(smbFile, l.getlongSize());
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                else if (MAIN_ACTIVITY.mReturnIntent) {
                    returnIntentResults(new File(l.getDesc()));
                } else {

                    utils.openFile(new File(l.getDesc()), (MainActivity) getActivity());
                }
                DataUtils.addHistoryFile(l.getDesc());
            }
        } else {

            goBackItemClick();

        }
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    PasswdSafeApp.setupTheme(this);
    super.onCreate(savedInstanceState);
    ApiCompat.setRecentAppsVisible(getWindow(), false);
    setContentView(R.layout.activity_passwdsafe);
    itsIsTwoPane = (findViewById(R.id.two_pane) != null);

    itsNavDrawerFrag = (PasswdSafeNavDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    itsNavDrawerFrag.setUp((DrawerLayout) findViewById(R.id.drawer_layout));

    itsQueryPanel = findViewById(R.id.query_panel);
    View queryClearBtn = findViewById(R.id.query_clear_btn);
    assert queryClearBtn != null;
    queryClearBtn.setOnClickListener(this);
    itsQuery = (TextView) findViewById(R.id.query);

    itsExpiryPanel = findViewById(R.id.expiry_panel);
    assert itsExpiryPanel != null;
    itsExpiryPanel.setOnClickListener(this);
    GuiUtils.setVisible(itsExpiryPanel, false);
    View expiryClearBtn = findViewById(R.id.expiry_clear_btn);
    assert expiryClearBtn != null;
    expiryClearBtn.setOnClickListener(this);
    itsExpiry = (TextView) findViewById(R.id.expiry);

    FragmentManager fragMgr = getSupportFragmentManager();
    itsFileDataFrag = (PasswdSafeFileDataFragment) fragMgr.findFragmentByTag(FRAG_DATA);
    if (itsFileDataFrag == null) {
        itsFileDataFrag = new PasswdSafeFileDataFragment();
        fragMgr.beginTransaction().add(itsFileDataFrag, FRAG_DATA).commit();
    }/*from ww w. ja  va  2s.  c o  m*/
    boolean newFileDataFrag = itsFileDataFrag.checkNew();

    itsTimeoutReceiver = new FileTimeoutReceiver(this);

    if (newFileDataFrag || (savedInstanceState == null)) {
        itsTitle = getTitle();
        doUpdateView(ViewMode.INIT, new PasswdLocation());
        changeInitialView();

        Intent intent = getIntent();
        PasswdSafeUtil.dbginfo(TAG, "onCreate: %s", intent);
        switch (intent.getAction()) {
        case PasswdSafeUtil.VIEW_INTENT:
        case Intent.ACTION_VIEW: {
            changeFileOpenView(intent);
            break;
        }
        case PasswdSafeUtil.NEW_INTENT: {
            changeFileNewView(intent);
            break;
        }
        default: {
            Log.e(TAG, "Unknown action for intent: " + intent);
            finish();
            break;
        }
        }
    } else {
        itsTitle = savedInstanceState.getCharSequence(STATE_TITLE);
        itsQuery.setText(savedInstanceState.getCharSequence(STATE_QUERY));
        if (savedInstanceState.getBoolean(STATE_EXPIRY_VISIBLE, false)) {
            itsFileDataFrag.getFileDataView().resetExpiryChanged();
        }
    }
}

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

/**
 * Removes a fragment with the DIALOG_TAG. The FragmentManager is a parameter so that it plays nice with nested
 * fragments and getChildFragmentManager()
 *
 * @param fragmentManager The FragmentManager to use for this transaction
 *//*from   ww w.  j  ava  2 s .  c  o m*/
public void removeDialogFragment(FragmentManager fragmentManager) {
    if (fragmentManager != null) {
        Fragment prev = fragmentManager.findFragmentByTag(FamiliarActivity.DIALOG_TAG);
        if (prev != null) {
            if (prev instanceof DialogFragment) {
                ((DialogFragment) prev).dismiss();
            }
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.remove(prev);
            ft.commit();
        }
    }
}

From source file:com.chatwing.whitelabel.activities.CommunicationActivity.java

@Override
public void onContextMenuClosed(Menu menu) {
    super.onContextMenuClosed(menu);
    String fragmentTag = getString(R.string.tag_communication_messages);
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment currentFragment = fragmentManager.findFragmentByTag(fragmentTag);
    if (currentFragment instanceof CommunicationMessagesFragment) {
        ((CommunicationMessagesFragment) currentFragment).onContextMenuClosed(menu);
    }/*from  w  w w  . j a v a  2s.  c  o m*/
}

From source file:com.igniva.filemanager.fragments.Main.java

/**
 * method called when list item is clicked in the adapter
 * @param position the {@link int} position of the list item
 * @param imageView the check {@link RoundedImageView} that is to be animated
 *//*  w  w w  .  jav  a2  s  .  c om*/
public void onListItemClicked(int position, ImageView imageView) {
    if (position >= LIST_ELEMENTS.size())
        return;

    if (results) {

        // check to initialize search results
        // if search task is been running, cancel it
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        SearchAsyncHelper fragment = (SearchAsyncHelper) fragmentManager
                .findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
        if (fragment != null) {

            if (fragment.mSearchTask.getStatus() == AsyncTask.Status.RUNNING) {

                fragment.mSearchTask.cancel(true);
            }
            getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
        }

        mRetainSearchTask = true;
        results = false;
    } else {
        mRetainSearchTask = false;
        MainActivityHelper.SEARCH_TEXT = null;
    }
    if (selection == true) {
        if (!LIST_ELEMENTS.get(position).getSize().equals(goback)) {
            // the first {goback} item if back navigation is enabled
            adapter.toggleChecked(position, imageView);
        } else {
            selection = false;
            if (mActionMode != null)
                mActionMode.finish();
            mActionMode = null;
        }

    } else {
        if (!LIST_ELEMENTS.get(position).getSize().equals(goback)) {

            // hiding search view if visible
            if (MainActivity.isSearchViewEnabled)
                MAIN_ACTIVITY.hideSearchView();

            String path;
            Layoutelements l = LIST_ELEMENTS.get(position);
            if (!l.hasSymlink()) {

                path = l.getDesc();
            } else {

                path = l.getSymlink();
            }
            if (LIST_ELEMENTS.get(position).isDirectory()) {
                computeScroll();
                loadlist(path, false, openMode);
            } else {
                if (l.getMode() == HFile.SMB_MODE)
                    try {
                        SmbFile smbFile = new SmbFile(l.getDesc());
                        launch(smbFile, l.getlongSize());
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                else if (MAIN_ACTIVITY.mReturnIntent) {
                    returnIntentResults(new File(l.getDesc()));
                } else {

                    utils.openFile(new File(l.getDesc()), (MainActivity) getActivity());
                }
                DataUtils.addHistoryFile(l.getDesc());
            }
        } else {

            goBackItemClick();

        }
    }
}

From source file:com.chatwing.whitelabel.activities.CommunicationActivity.java

protected void setupMode(CommunicationModeManager newMode, Fragment newFragment) {
    /*/* w  w w  .j  a  va 2 s.co  m*/
     * Update fragments
     */
    String fragmentTag = getString(R.string.tag_communication_messages);
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment oldFragment = fragmentManager.findFragmentByTag(fragmentTag);
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (oldFragment != null) {
        fragmentTransaction.remove(oldFragment);
    }
    fragmentTransaction.add(R.id.fragment_container, newFragment, fragmentTag);
    fragmentTransaction.commit();

    /*
     * Deactivate old mode and activate the new one
     */
    if (mCurrentCommunicationMode != null) {
        mCurrentCommunicationMode.deactivate();
    }
    mCurrentCommunicationMode = newMode;
    mCurrentCommunicationMode.activate();

    /*
     * Setup drawer layout
     */
    // Set custom shadows that overlay the main content when a drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
    mDrawerToggle = mCurrentCommunicationMode.getDrawerToggleListener();
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Don't allow the drawer layout to catch back button and close itself
    // on back key is pressed. This activity will handle it.
    mDrawerLayout.setFocusableInTouchMode(false);

    invalidateOptionsMenu();
}

From source file:com.chatwing.whitelabel.activities.CommunicationActivity.java

@Override
public void showPasswordDialogFragment() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    PasswordDialogFragment oldFragment = (PasswordDialogFragment) fragmentManager
            .findFragmentByTag(PASSWORD_DIALOG_FRAGMENT_TAG);
    if (oldFragment == null || oldFragment.isDismissingByUser()) {
        PasswordDialogFragment newFragment = new PasswordDialogFragment();
        newFragment.show(getSupportFragmentManager(), PASSWORD_DIALOG_FRAGMENT_TAG);
    }//w  ww  .  j ava  2s .c  om
}

From source file:com.chatwing.whitelabel.activities.CommunicationActivity.java

@Override
public void showBlockUserDialogFragment(Message message) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    BlockUserDialogFragment oldFragment = (BlockUserDialogFragment) fragmentManager
            .findFragmentByTag(BLOCK_USER_DIALOG_FRAGMENT_TAG);
    if (oldFragment == null || oldFragment.isDismissingByUser()) {
        BlockUserDialogFragment newFragment = BlockUserDialogFragment.newInstance(message);
        newFragment.show(getSupportFragmentManager(), BLOCK_USER_DIALOG_FRAGMENT_TAG);
    }/*w ww  .  j ava2 s.  c  o m*/
}

From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        TabGroup currentTabGroup = (TabGroup) fragmentManager.findFragmentByTag(
                fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1).getName());
        if (currentTabGroup != null) {
            renderer.invalidateListViews(currentTabGroup);
            renderer.setCurrentTabGroup(currentTabGroup);
            getActionBar().setTitle(currentTabGroup.getLabel());
        }/* w ww.j av a  2  s  .c o  m*/
        super.onBackPressed();
    } else {
        if (syncStarted) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Stop Syncing");
            builder.setMessage(
                    "Syncing is still in progress. Do you want to exit the activity and stop the sync?");
            builder.setPositiveButton("Yes", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    syncStarted = false;
                    stopSync();
                    ShowModuleActivity.super.onBackPressed();
                }
            });
            builder.setNegativeButton("No", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });
            builder.show();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Exit Module");
            builder.setMessage("Do you want to exit module?");
            builder.setPositiveButton("Yes", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ShowModuleActivity.super.onBackPressed();
                }
            });
            builder.setNegativeButton("No", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });
            builder.show();
        }
    }
}

From source file:com.feytuo.chat.activity.MainActivity.java

/**
 * ?/*  w  w  w .ja  v a2 s .co m*/
 * @param savedInstanceState 
 */
private void initView(Bundle savedInstanceState) {
    mTabs = new Button[4];
    mTabs[0] = (Button) findViewById(R.id.btn_main_invitation);
    mTabs[1] = (Button) findViewById(R.id.btn_find);
    mTabs[2] = (Button) findViewById(R.id.btn_address_list);
    mTabs[3] = (Button) findViewById(R.id.btn_setting);
    // tab?
    mTabs[0].setSelected(true);

    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    // ?
    if (savedInstanceState == null) {
        mainFragment = new MainFragment();
        // ?
        findFragment = new FindFragment();
        // ?fragment
        cacFragment = new ChatAndContactFragment();
        // fragment
        settingFragment = new SettingsFragment();
        transaction.add(R.id.fragment_container, mainFragment, "mainFragment");
        transaction.add(R.id.fragment_container, findFragment, "findFragment");
        transaction.add(R.id.fragment_container, cacFragment, "cacFragment");
        transaction.add(R.id.fragment_container, settingFragment, "settingFragment");
        //         Log.i(TAG, "------> new mainFragment:"+mainFragment);
    } else {
        mainFragment = manager.findFragmentByTag("mainFragment");
        findFragment = (FindFragment) manager.findFragmentByTag("findFragment");
        cacFragment = (ChatAndContactFragment) manager.findFragmentByTag("cacFragment");
        settingFragment = (SettingsFragment) manager.findFragmentByTag("settingFragment");
        //         Log.i(TAG, "------> old mainFragment:"+mainFragment);
    }

    fragments = new Fragment[] { mainFragment, findFragment, cacFragment, settingFragment };
    // fragment
    transaction.hide(cacFragment).hide(findFragment).hide(settingFragment).show(mainFragment).commit();
}