Example usage for android.support.v4.app Fragment getClass

List of usage examples for android.support.v4.app Fragment getClass

Introduction

In this page you can find the example usage for android.support.v4.app Fragment getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.umeng.comm.ui.activities.BaseFragmentActivity.java

/**
 * Fragment??//from ww  w.  ja  v a 2s. c  o  m
 * 
 * @param fragment ???Fragment
 * @return
 */
public boolean isFragmentAdded(Fragment fragment) {
    return fragment != null && mFragmentManager.findFragmentByTag(fragment.getClass().getName()) != null;
}

From source file:com.twitt4droid.app.activity.MainActivity.java

private void setUpFragment(Fragment fragment) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment currentFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG);
    if (currentFragment == null || !currentFragment.getClass().equals(fragment.getClass())) {
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, FRAGMENT_TAG).commit();
    }//from w  w  w . ja v  a2 s  .  co  m
}

From source file:com.lamcreations.scaffold.common.activities.DrawerActivity.java

private void addRightEndDrawerFragment() {
    Fragment fragment = getRightEndDrawerFragment();
    View view = findViewById(R.id.scaffold_right_end_drawer_container);
    if (view != null && fragment != null) {
        replaceFragment(R.id.scaffold_right_end_drawer_container, fragment, fragment.getClass().getName());
    } else if (view != null) {
        mDrawerLayout.removeView(view);//from   w w  w.j  a v a  2s  . co  m
    }
}

From source file:com.kuassivi.october.util.Navigator.java

/**
 * Pops back with some specific fragment arguments.
 *
 * @param clazz          The fragment class
 * @param args           Arguments to update into the Fragment
 * @param clearArguments if true clear the current Fragment arguments
 *//*from  w  w w .  j av a2s . co m*/
public void popToFragment(@NonNull Class<?> clazz, Bundle args, boolean clearArguments) {
    if (!(activity instanceof FragmentActivity)) {
        throw new RuntimeException("The activity must inherits from FragmentActivity or AppCompatActivity");
    }

    FragmentActivity fragmentActivity = (FragmentActivity) activity;
    FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();

    /*
     * The method isFinishing() prevents to load a Fragment
     * when the activity is going to be killed or destroyed.
     */
    if (fragmentManager == null || fragmentActivity.isFinishing()) {
        return;
    }

    List<Fragment> fragments = fragmentManager.getFragments();
    int index;

    for (index = 0; index < fragments.size(); index++) {
        Fragment frag = fragments.get(index);
        if (frag.getClass().equals(clazz)) {
            if (args != null && args.size() > 0 && frag.getArguments() == null) {
                throw new IllegalArgumentException("Fragment constructor must call super()");
            }
            if (frag.getArguments() != null && args != null) {
                if (clearArguments) {
                    frag.getArguments().clear();
                }
                frag.getArguments().putAll(args);
            }
            this.fragment = frag;
            popToStack(index + 1);
            break;
        }
    }
}

From source file:com.ibm.mil.readyapps.physio.activities.LandingActivity.java

private boolean isCurrentFragment(Fragment fragment) {
    return fragment.getClass() == fragmentStack.peek().getClass();
}

From source file:com.lamcreations.scaffold.common.activities.DrawerActivity.java

private void addLeftStartDrawerFragment() {
    Fragment fragment = getLeftStartDrawerFragment();
    View view = findViewById(R.id.scaffold_left_start_drawer_container);
    if (view != null && fragment != null) {
        replaceFragment(R.id.scaffold_left_start_drawer_container, fragment, fragment.getClass().getName());
    } else if (view != null) {
        mDrawerLayout.removeView(view);//  w  w  w  .  j a  v a  2 s.c  o  m
    }
}

From source file:it.angelic.soulissclient.TagDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ImageView icon = (ImageView) findViewById(R.id.node_icon);
    switch (item.getItemId()) {
    case android.R.id.home:

        Fragment details = getSupportFragmentManager().findFragmentById(R.id.detailPane);
        Log.w(Constants.TAG, "instanceof: " + details.getClass());
        if (details instanceof TagDetailFragment)
            supportFinishAfterTransition();
        else {//from  w w w  .j  a v  a 2 s.  c  o  m
            getSupportFragmentManager().popBackStack();
            setActionBarInfo(collected.getNiceName());
        }
        return true;
    case R.id.Opzioni:
        Intent settingsActivity = new Intent(this, PreferencesActivity.class);
        startActivity(settingsActivity);
        final Intent preferencesActivity = new Intent(this.getBaseContext(), PreferencesActivity.class);
        // evita doppie aperture per via delle sotto-schermate
        preferencesActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(preferencesActivity);
        return true;
    case R.id.scegliconaTag:
        AlertDialog.Builder alert2 = AlertDialogHelper.chooseIconDialog(this, icon, null, db, collected);
        alert2.show();
        return true;
    case R.id.rinominaTag:
        AlertDialog.Builder alert = AlertDialogHelper.renameSoulissObjectDialog(this, actionTitleTextView, null,
                db, collected);
        alert.show();
        return true;
    case R.id.scegliImmagineTag:
        Intent intent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, collected.getTagId().intValue());
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.dvbviewer.controller.ui.base.BaseActivity.java

/**
 * Change fragment./*  w ww  . j a v a 2 s . c  o m*/
 *
 * @param container the container
 * @param f the f
 * @author RayBa
 * @date 07.04.2013
 */
public void changeFragment(int container, Fragment f) {
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    trans.setCustomAnimations(R.anim.in_from_right, R.anim.out_to_left);
    trans.replace(container, f, f.getClass().getName());
    trans.addToBackStack(f.getClass().getName());
    trans.commit();
}

From source file:com.ameron32.apps.tapnotes.MainActivity.java

public void changeFragment(Fragment newFragment) {
    final int container = R.id.container;
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = fm.beginTransaction();
    final String newTag = newFragment.getClass().getName();

    Fragment fragment = fm.findFragmentByTag(newTag);
    if (fragment == null) {
        fragment = newFragment;/*from w  ww.  j  a  v  a 2s .c  o m*/
    }

    transaction.replace(container, fragment, newTag);
    transaction.addToBackStack(newTag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.commit();
}

From source file:com.belatrix.events.presentation.ui.base.BelatrixBaseActivity.java

@Override
public void replaceFragment(int containerId, Fragment fragment, boolean addToBackStack) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    String tag = fragment.getClass().getSimpleName();
    transaction.replace(containerId, fragment, tag);
    if (addToBackStack)
        transaction.addToBackStack(null);
    transaction.commit();//  ww  w  .j a v a2s  .  c  om
}