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.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void hideFragment(final Fragment fragment, final boolean removeParentView,
        final boolean addedToBackStack, final String tag) {
    final FragmentManager manager = getFragmentManager();
    if (manager.findFragmentByTag(tag) != null) {
        final FragmentTransaction transaction = manager.beginTransaction();
        transaction.remove(fragment);//from  w  ww.java2  s. co m
        transaction.commit();
        if (addedToBackStack) {
            manager.popBackStack();
        }

        final int viewId = getParentId(fragment);
        if (removeParentView && viewId != 0) {
            mContentContainer.removeBorderView(viewId);
        }
    }
}

From source file:it.scoppelletti.mobilepower.app.AbstractActivity.java

/**
 * Ripristina lo stato dell’istanza.
 * //from w w w .j  a v a2 s  .  com
 * @param savedInstanceState Stato dell’istanza.
 */
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    Fragment fragment;
    DialogFragment dlg;
    FragmentManager fragmentMgr;

    super.onRestoreInstanceState(savedInstanceState);

    fragmentMgr = getSupportFragmentManager();
    for (String tag : myDialogSet) {
        fragment = fragmentMgr.findFragmentByTag(tag);
        if (fragment == null) {
            myLogger.trace("Fragment {} not found.", tag);
            continue;
        }
        if (!(fragment instanceof DialogFragment)) {
            myLogger.warn("Fragment {} is not dialog.", tag);
            continue;
        }

        dlg = (DialogFragment) fragment;
        dlg.dismiss();
    }
}

From source file:com.ffmpeger.card.MainNativeActivity.java

private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("carddemo_dialog");
        if (prev != null) {
            ft.remove(prev);/*w  w  w  .j a  v  a 2  s.c o m*/
        }
        //ft.addToBackStack(null);

        dialogStandardFragment.show(ft, "carddemo_dialog");
    }
}

From source file:geeshang.nasaimage.MainActivity.java

private void downloadOrReload() {
    FragmentManager fragmentManager = getFragmentManager();
    dataReloader = (DataReloader) fragmentManager.findFragmentByTag("dataReloader");
    //To prevent MainActivity restart from rotating the screen,
    //if dataReloader is null, download the data and store in the DataReloader.
    if (dataReloader == null) {
        download();//from   w ww . j  a v  a 2  s .com
        dataReloader = new DataReloader();
        fragmentManager.beginTransaction().add(dataReloader, "dataReloader").commit();
        dataReloader.setData(this);
    } else {
        title_data = dataReloader.getData().title_data;
        date_data = dataReloader.getData().date_data;
        image_url = dataReloader.getData().image_url;
        image_data = dataReloader.getData().image_data;
        dayIndex = dataReloader.getData().dayIndex;
        description_data = dataReloader.getData().description_data;
        setProgressBarGone();
        resetView();
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java

private void hideFragments(boolean animate) {
    FragmentManager fm = getFragmentManager();

    Fragment prevRoms = fm.findFragmentByTag(SwitcherListFragment.TAG);
    Fragment prevPatchFile = fm.findFragmentByTag(PatchFileFragment.TAG);
    Fragment prevFreeSpace = fm.findFragmentByTag(FreeSpaceFragment.TAG);
    Fragment prevAbout = fm.findFragmentByTag(AboutFragment.TAG);

    FragmentTransaction ft = fm.beginTransaction();

    if (animate) {
        ft.setCustomAnimations(0, R.animator.fragment_out);
    }/*from w w w .j  a  va  2 s. co m*/

    if (prevRoms != null) {
        ft.hide(prevRoms);
    }
    if (prevPatchFile != null) {
        ft.hide(prevPatchFile);
    }
    if (prevFreeSpace != null) {
        ft.hide(prevFreeSpace);
    }
    if (prevAbout != null) {
        ft.hide(prevAbout);
    }

    ft.commit();
    fm.executePendingTransactions();
}

From source file:org.sleepydragon.rgbclient.MainFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    LOG.v("onActivityCreated()");
    super.onActivityCreated(savedInstanceState);

    final FragmentManager fm = getFragmentManager();
    mNetworkClientFragment = (NetworkClientFragment) fm.findFragmentByTag(NetworkClientFragment.TAG);
    if (mNetworkClientFragment == null) {
        mNetworkClientFragment = new NetworkClientFragment();
        mNetworkClientFragment.setTargetFragment(this, 0);
        fm.beginTransaction().add(mNetworkClientFragment, NetworkClientFragment.TAG).commit();
    }/* w  w w . j  a v  a 2s  .  c  o  m*/

    updateDisplayedColor();

    // add any color commands that were received during the configuration change
    synchronized (mCommandQueue) {
        final ColorCommand lastCommand;
        if (mCommandQueue.size() > 0) {
            lastCommand = mCommandQueue.get(mCommandQueue.size() - 1);
        } else {
            lastCommand = mColorState.getLastAddedCommand();
        }
        final UUID lastCommandId = (lastCommand == null) ? null : lastCommand.id;
        mNetworkClientFragment.getCommandsSince(lastCommandId, mCommandQueue);
    }
    mHandler.removeMessages(R.id.MSG_PROCESS_QUEUED_COMMANDS);
    mHandler.sendEmptyMessage(R.id.MSG_PROCESS_QUEUED_COMMANDS);
}

From source file:com.evandroid.musica.MainLyricActivity.java

public Fragment[] getActiveFragments() {
    FragmentManager fragmentManager = this.getFragmentManager();
    Fragment[] fragments = new Fragment[4];
    fragments[0] = fragmentManager.findFragmentByTag(LYRICS_FRAGMENT_TAG);
    fragments[1] = fragmentManager.findFragmentByTag(SEARCH_FRAGMENT_TAG);
    fragments[2] = fragmentManager.findFragmentByTag(SETTINGS_FRAGMENT);
    fragments[3] = fragmentManager.findFragmentByTag(LOCAL_LYRICS_FRAGMENT_TAG);
    return fragments;
}

From source file:com.evandroid.musica.MainLyricActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }//from  w  ww .  ja va  2s.co m

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}

From source file:com.hijridatepicker.HijriDatePickerAndroidModule.java

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved./* w  ww .j  a v a2s. c  o  m*/
 * <p>
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 * Show a date picker dialog.
 *
 * @param options a map containing options. Available keys are:
 *                <p>
 *                <ul>
 *                <li>{@code date} (timestamp in milliseconds) the date to show by default</li>
 *                <li>
 *                {@code minDate} (timestamp in milliseconds) the minimum date the user should be allowed
 *                to select
 *                </li>
 *                <li>
 *                {@code maxDate} (timestamp in milliseconds) the maximum date the user should be allowed
 *                to select
 *                </li>
 *                <li>
 *                {@code mode} To set the date picker mode to ' no_arrows/default' ,
 *                currently there's only one mode for HijriDatePicker, so this field works only with mode no_arrows/default
 *                </li>
 *                <li>
 *                {@code weekDayLabels} (array of strings) the day labels that appears on the calendar
 *                </li>
 *                </ul>
 * @param promise This will be invoked with parameters action, year,
 *                month (0-11), day, where action is {@code dateSetAction} or
 *                {@code dismissedAction}, depending on what the user did. If the action is
 *                dismiss, year, month and date are undefined.
 */
@ReactMethod
public void open(@Nullable final ReadableMap options, Promise promise) {
    try {
        Activity activity = getCurrentActivity();
        if (activity == null) {
            promise.reject(ERROR_NO_ACTIVITY,
                    "Tried to open a DatePicker dialog while not attached to an Activity");
            return;
        }
        // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
        // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
        if (activity instanceof android.support.v4.app.FragmentActivity) {
            android.support.v4.app.FragmentManager fragmentManager = ((android.support.v4.app.FragmentActivity) activity)
                    .getSupportFragmentManager();
            android.support.v4.app.DialogFragment oldFragment = (android.support.v4.app.DialogFragment) fragmentManager
                    .findFragmentByTag(FRAGMENT_TAG);
            if (oldFragment != null) {
                oldFragment.dismiss();
            }
            SupportHijriDatePickerDialogFragment fragment = new SupportHijriDatePickerDialogFragment();
            if (options != null) {
                final Bundle args = createFragmentArguments(options, promise);
                if (args == null)
                    return;
                fragment.setArguments(args);
            }
            final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
            fragment.setOnDismissListener(listener);
            fragment.setOnDateSetListener(listener);
            fragment.setOnExceptionListener(listener);
            fragment.show(fragmentManager, FRAGMENT_TAG);
        } else {
            FragmentManager fragmentManager = activity.getFragmentManager();
            DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
            if (oldFragment != null) {
                oldFragment.dismiss();
            }
            HijriDatePickerDialogFragment fragment = new HijriDatePickerDialogFragment();
            if (options != null) {
                final Bundle args = createFragmentArguments(options, promise);
                if (args == null)
                    return;
                fragment.setArguments(args);
            }
            final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
            fragment.setOnDismissListener(listener);
            fragment.setOnDateSetListener(listener);
            fragment.setOnExceptionListener(listener);
            fragment.show(fragmentManager, FRAGMENT_TAG);
        }
    } catch (Exception e) {
        promise.reject(ERROR_OPEN,
                "Exception happened while executing open method, details: " + e.getMessage());
    }
}

From source file:com.afollestad.polar.ui.MainActivity.java

@Override
public void onBackPressed() {
    if (mPager != null) {
        FragmentManager fm = getFragmentManager();
        Fragment current = fm.findFragmentByTag("page:" + mPager.getCurrentItem());
        if (current != null && current instanceof RequestsFragment
                && ((RequestsFragment) current).onBackPressed()) {
            return;
        }/*w ww.  j av a  2s .  c o m*/
    }
    super.onBackPressed();
}