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.kubotaku.android.sample.sensordataviewer.MainActivity.java

private void showLicenseDialog() {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.findFragmentByTag(FRAGMENT_TAG_LICENSE) == null) {
        final LicenseDialogFragment fragment = LicenseDialogFragment.newInstance();
        fragment.show(fragmentManager, FRAGMENT_TAG_LICENSE);
    }/*from ww  w.  java2  s.c om*/
}

From source file:com.example.levelup.core.app.example1.LoginAndPaymentActivity.java

/**
 * Shows the payment code fragment. This will replace any existing fragments loaded into the
 * destination frames (in this case, that would be the {@link LoginFragment}).
 */// w  w  w . jav a  2 s .  co  m
private void showPaymentCodeFragment() {
    FragmentManager fm = getSupportFragmentManager();

    /*
     * For easy management of fragment tags, the full classname is used to identify a given
     * fragment.
     */
    PaymentCodeFragment paymentCodeFragment = (PaymentCodeFragment) fm
            .findFragmentByTag(PaymentCodeFragment.class.getName());

    FragmentTransaction transaction = fm.beginTransaction();

    if (paymentCodeFragment == null) {
        paymentCodeFragment = new PaymentCodeFragment();
    }

    /* At this point, paymentCodeFragment will be a valid, possibly-unadded fragment. */

    if (!paymentCodeFragment.isAdded()) {
        transaction.replace(android.R.id.content, paymentCodeFragment, PaymentCodeFragment.class.getName());
    }

    commitUiChange(transaction);
}

From source file:com.money.manager.ex.sync.CloudFilePickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.base_toolbar_activity);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    FragmentManager fm = getSupportFragmentManager();

    // intent// ww w .  j  a  v a 2  s.c o  m
    //        if (getIntent() != null && getIntent().getExtras().containsKey(INTENT_DROBPOXFILE_PATH)) {
    //            dropboxFile = getIntent().getExtras().getString(INTENT_DROBPOXFILE_PATH);
    //        }

    // attach fragment to activity
    if (fm.findFragmentById(R.id.content) == null) {
        if (fm.findFragmentByTag(CloudFilePickerFragment.class.getSimpleName()) == null) {
            CloudFilePickerFragment fragment = new CloudFilePickerFragment();
            fm.beginTransaction().add(R.id.content, fragment, CloudFilePickerFragment.class.getSimpleName())
                    .commit();
        }
    }
}

From source file:click.kobaken.rxirohaandroid_sample.view.activity.MainActivity.java

private void initFragments(Bundle savedInstanceState) {
    final FragmentManager manager = getSupportFragmentManager();
    assetReceiveFragment = (AssetReceiveFragment) manager.findFragmentByTag(AssetReceiveFragment.TAG);
    walletFragment = (WalletFragment) manager.findFragmentByTag(WalletFragment.TAG);
    assetSenderFragment = (AssetSenderFragment) manager.findFragmentByTag(AssetSenderFragment.TAG);

    if (assetReceiveFragment == null) {
        assetReceiveFragment = AssetReceiveFragment.newInstance(uuid);
    }/*  w  w  w .  j  a  v  a2  s. c o m*/
    if (walletFragment == null) {
        walletFragment = WalletFragment.newInstance(uuid);
    }
    if (assetSenderFragment == null) {
        assetSenderFragment = AssetSenderFragment.newInstance();
    }
    if (libsFragment == null) {
        libsFragment = new LibsBuilder().withAboutIconShown(true).withAboutVersionShown(true)
                .withAboutDescription(getString(R.string.library_description)).supportFragment();
    }

    if (savedInstanceState == null) {
        switchFragment(assetReceiveFragment, AssetReceiveFragment.TAG);
    }
}

From source file:biz.easymenu.easymenung.ItemFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    WindowManager.LayoutParams WMLP = this.getDialog().getWindow().getAttributes();
    WMLP.windowAnimations = R.style.PauseDialogAnimation;
    this.getDialog().getWindow().setAttributes(WMLP);

    v = li.inflate(R.layout.itemdialog, container, false);

    np = (NumberPicker) v.findViewById(R.id.itemnumpick);
    ((TextView) v.findViewById(R.id.itemLabel)).setText(item.getLabel());
    ((TextView) v.findViewById(R.id.itemDescription)).setText(item.getDescription());
    try {//  w ww  .  j  a v  a  2  s  .  c o m
        ((ImageView) v.findViewById(R.id.itemImage)).setImageBitmap(BitmapFactory
                .decodeStream(getActivity().openFileInput(Integer.toString(item.getIdImage()) + ".img")));
    } catch (FileNotFoundException e) {
        Log.e(EasymenuNGActivity.TAG, "Error image file not found: " + e.getMessage());
    }

    this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

    new Thread(new NumberRun()).start();

    btnOk = (Button) v.findViewById(R.id.itembtnOK);
    btnOk.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                if (oldNr > 0 || np.getValue() > 0)
                    rpc.addToOrder(sid, item.getIdMenulists(), np.getValue(), note);
            } catch (Exception e) {
                FragmentManager fm = getActivity().getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                ErrorFragment f = new ErrorFragment(e.getMessage());
                Fragment prev = fm.findFragmentByTag("errorDialog");
                if (prev != null) {
                    ft.remove(prev);
                    ft.commit();
                }
                f.show(ft, "errorDialog");
            } finally {
                dismiss();
            }
        }
    });

    btnNote = (Button) v.findViewById(R.id.itembtnNote);
    btnNote.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            NoteDialog f = new NoteDialog(itemFrag, note);
            Fragment prev = fm.findFragmentByTag("noteDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "noteDialog");
        }

    });

    return v;
}

From source file:com.akop.bach.activity.RibbonedSinglePane.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(getLayout());//from w  ww. j  a va 2  s  . c om

    if (mAccount == null)
        mAccount = (BasicAccount) getIntent().getParcelableExtra("account");

    if (mAccount == null) {
        if (App.getConfig().logToConsole())
            App.logv("Account is null");

        finish();
        return;
    }

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        new ActionBarHelper().init();
    }

    FragmentManager fm = getSupportFragmentManager();
    Fragment titleFrag;

    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    if ((titleFrag = fm.findFragmentByTag("details")) == null) {
        titleFrag = createFragment();
        ft.replace(R.id.fragment_titles, titleFrag, "details");
    }

    ft.commit();
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.MainActivity.java

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

    // setup event bus
    mAppEventReceiver = new AppEventReceiver(this);
    eventBus().register(mAppEventReceiver);

    // set content view
    setContentView(R.layout.activity_main);

    // set ToolBar as a ActionBar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.app_toolbar_title_text));
    setSupportActionBar(toolbar);//  www  . j  av a 2  s  . com
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // instantiate NavigationDrawerFragment
    FragmentManager fm = getSupportFragmentManager();

    NavigationDrawerFragment fragment = (NavigationDrawerFragment) fm
            .findFragmentByTag(FRAGMENT_TAG_NAVIGATION_DRAWER);

    if (fragment == null) {
        fragment = (NavigationDrawerFragment) Fragment.instantiate(this,
                NavigationDrawerFragment.class.getName());
        fm.beginTransaction().replace(R.id.drawer_container, fragment, FRAGMENT_TAG_NAVIGATION_DRAWER).commit();
    } else {
        fm.beginTransaction().attach(fragment).commit();
    }

    mNavigationDrawerFragment = fragment;

    // set initial contents
    if (savedInstanceState == null) {
        switchContents(NavigationDrawerReqEvents.SECTION_INDEX_PLAYER_CONTROL);
    }
}

From source file:com.example.android.supportv7.media.SampleMediaRouterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Be sure to call the super class.
    super.onCreate(savedInstanceState);

    // Get the media router service.
    mMediaRouter = MediaRouter.getInstance(this);

    // Create a route selector for the type of routes that we care about.
    mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
            .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
            .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
            .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build();

    // Add a fragment to take care of media route discovery.
    // This fragment automatically adds or removes a callback whenever the activity
    // is started or stopped.
    FragmentManager fm = getSupportFragmentManager();
    if (fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG) == null) {
        DiscoveryFragment fragment = new DiscoveryFragment();
        fragment.setRouteSelector(mSelector);
        fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit();
    }//from w w  w. j av a  2  s.  c o m

    // Populate an array adapter with fake media items.
    String[] mediaNames = getResources().getStringArray(R.array.media_names);
    String[] mediaUris = getResources().getStringArray(R.array.media_uris);
    mMediaItems = new ArrayAdapter<MediaItem>(this, android.R.layout.simple_list_item_single_choice,
            android.R.id.text1);
    for (int i = 0; i < mediaNames.length; i++) {
        mMediaItems.add(new MediaItem(mediaNames[i], Uri.parse(mediaUris[i])));
    }

    // Initialize the layout.
    setContentView(R.layout.sample_media_router);

    mInfoTextView = (TextView) findViewById(R.id.info);

    mMediaListView = (ListView) findViewById(R.id.media);
    mMediaListView.setAdapter(mMediaItems);
    mMediaListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mMediaListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            updateButtons();
        }
    });

    mPlayButton = (Button) findViewById(R.id.play_button);
    mPlayButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            play();
        }
    });

    mStatisticsButton = (Button) findViewById(R.id.statistics_button);
    mStatisticsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showStatistics();
        }
    });
}

From source file:biz.easymenu.easymenung.TableListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.menupager, container, false);
    ((TextView) v.findViewById(R.id.menuTitle)).setText(R.string.tableList);
    GridView gridview = (GridView) v.findViewById(R.id.gridview);
    adapter = new ItemAdapter(getActivity());
    gridview.setAdapter(adapter);/*from  w  w w  .  ja  va  2 s .  c  o m*/

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            DialogFragment f = new LoginFragment(adapter.itemsList.get(position));
            Fragment prev = fm.findFragmentByTag("loginDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "loginDialog");

            /*DEMO
                    
            Locale pLocale = new Locale("it");
            Resources res = getActivity().getBaseContext().getResources();
            DisplayMetrics dm =  getActivity().getBaseContext().getResources().getDisplayMetrics();
            Configuration conf = res.getConfiguration();
            conf.locale = pLocale;
            res.updateConfiguration(conf, dm);
            getActivity().finish();
            startActivity(getActivity().getIntent());
                    
                    
            END DEMO */
        }
    });

    return v;
}

From source file:com.anxpp.blog.MainActivity.java

/**
 * ?/* www. j a  v  a  2 s.c  o  m*/
 * @param uri ?
 */
public void updateContent(Uri uri) {
    final Fragment fragment;
    final String tag;

    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction tr = fm.beginTransaction();

    if (!currentUri.equals(uri)) {
        final Fragment currentFragment = fm.findFragmentByTag(currentContentFragmentTag);
        if (currentFragment != null)
            tr.hide(currentFragment);
    }
    //about
    if (AboutFragment.ABOUT_URI.equals(uri)) {
        tag = AboutFragment.TAG;
        final Fragment foundFragment = fm.findFragmentByTag(tag);
        if (foundFragment != null) {
            fragment = foundFragment;
        } else {
            fragment = new AboutFragment();
        }
    } else if (SandboxFragment.SETTINGS_URI.equals(uri)) {
        tag = SandboxFragment.TAG;
        final SandboxFragment foundFragment = (SandboxFragment) fm.findFragmentByTag(tag);
        if (foundFragment != null) {
            foundFragment.setOnSettingsChangedListener(mSettingsChangedListener);
            fragment = foundFragment;
        } else {
            final SandboxFragment settingsFragment = new SandboxFragment();
            settingsFragment.setOnSettingsChangedListener(mSettingsChangedListener);
            fragment = settingsFragment;
        }
    } else if (uri != null) {
        //...
        tag = WebViewFragment.TAG;
        final WebViewFragment webViewFragment;
        final Fragment foundFragment = fm.findFragmentByTag(tag);
        if (foundFragment != null) {
            fragment = foundFragment;
            webViewFragment = (WebViewFragment) fragment;
        } else {
            webViewFragment = new WebViewFragment();
            fragment = webViewFragment;
        }
        webViewFragment.setUrl(uri.toString());
    } else {
        return;
    }

    if (fragment.isAdded()) {
        tr.show(fragment);
    } else {
        tr.replace(R.id.content, fragment, tag);
    }
    tr.commit();

    currentUri = uri;
    currentContentFragmentTag = tag;
}