List of usage examples for android.app Fragment getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:me.raatiniemi.worker.presentation.settings.view.SettingsActivity.java
@Override public void onBackPressed() { FragmentManager fragmentManager = getFragmentManager(); // Depending on which fragment is contained within the // container, the back button will behave differently. Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container); Class<SettingsFragment> settings = SettingsFragment.class; if (!settings.equals(fragment.getClass())) { fragmentManager.popBackStack();/*from w ww . ja va 2 s . com*/ } else { super.onBackPressed(); } }
From source file:net.sf.aria2.MainActivity.java
@Override public void onAttachFragment(Fragment fragment) { super.onAttachFragment(fragment); lastChosenFragment = fragment.getClass().getName(); }
From source file:org.eyeseetea.malariacare.DashboardActivity.java
private boolean isFragmentActive(Class fragmentClass, int layout) { Fragment currentFragment = this.getFragmentManager().findFragmentById(layout); if (currentFragment.getClass().equals(fragmentClass)) { return true; }// ww w. ja v a 2 s .c o m return false; }
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dev_home); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// w ww. jav a 2 s.c o m mTitle = mDrawerTitle = getTitle(); mSubtitle = ""; mDrawerTitles = getResources().getStringArray(R.array.drawer_array); mDrawerTitlesSecondary = getResources().getStringArray(R.array.drawer_array2); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerArea = (LinearLayout) findViewById(R.id.drawer_area); fragmentCache = new Fragment[] { null, null, null }; mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerListSecondary = (ListView) findViewById(R.id.left_drawer2); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new DrawerArrayAdapter(this, mDrawerTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerListSecondary.setAdapter(new DrawerArrayAdapter2(this, mDrawerTitlesSecondary)); mDrawerListSecondary.setOnItemClickListener(new DrawerItemClickListener2()); routeListCache = null; // enable ActionBar app icon to behave as action to toggle nav drawer //getSupportActionBar().setIcon(R.drawable.ic_logo_white_nobezel_small); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ toolbar, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() FragmentManager fragmentManager = getFragmentManager(); Fragment fragment = fragmentManager.findFragmentById(R.id.content_frame); if (fragment.getClass() == MapFragment.class) { MapFragment mf = (MapFragment) fragment; mf.resetSubtitle(); } } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); getSupportActionBar().setSubtitle(""); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0, true); } fetchWeather(); initPreferences(); }
From source file:android.app.FragmentState.java
/** * Create a new instance of a Fragment with the given class name. This is * the same as calling its empty constructor. * * @param context The calling context being used to instantiate the fragment. * This is currently just used to get its ClassLoader. * @param fname The class name of the fragment to instantiate. * @param args Bundle of arguments to supply to the fragment, which it * can retrieve with {@link #getArguments()}. May be null. * @return Returns a new fragment instance. * @throws InstantiationException If there is a failure in instantiating * the given fragment class. This is a runtime exception; it is not * normally expected to happen.//from w w w .j a va 2 s .co m */ public static Fragment instantiate(Context context, String fname, Bundle args) { try { Class<?> clazz = sClassMap.get(fname); if (clazz == null) { // Class not found in the cache, see if it's real, and try to add it clazz = context.getClassLoader().loadClass(fname); sClassMap.put(fname, clazz); } Fragment f = (Fragment) clazz.newInstance(); if (args != null) { args.setClassLoader(f.getClass().getClassLoader()); f.mArguments = args; } return f; } catch (ClassNotFoundException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } catch (java.lang.InstantiationException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } catch (IllegalAccessException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } }
From source file:org.servDroid.ui.activity.MainActivityTwoPanes.java
private synchronized void setRighFragment(android.app.Fragment fragment) { android.app.FragmentManager fManager = getFragmentManager(); if (fragment == null && mCurrentFragmentTag != null) { fManager.beginTransaction().remove(fManager.findFragmentByTag(mCurrentFragmentTag)).commit(); mCurrentFragmentTag = null;// w w w . j a v a2 s .c o m return; } if (mCurrentFragmentTag != null && mCurrentFragmentTag.equals(fragment.getTag())) { return; } if (fragment != null) { setRightSuportFragment(null); } if (mCurrentFragmentTag != null) { fManager.beginTransaction().remove(fManager.findFragmentByTag(mCurrentFragmentTag)).commit(); } else if (fragment == null) { mCurrentFragmentTag = null; return; } fManager.beginTransaction().add(R.id.fillableFrameLayout, fragment, fragment.getClass().getSimpleName()) .commit(); mCurrentFragmentTag = fragment.getClass().getSimpleName(); }
From source file:android.app.FragmentState.java
/** * Create a new instance of a Fragment with the given class name. This is * the same as calling its empty constructor. * * @param context The calling context being used to instantiate the fragment. * This is currently just used to get its ClassLoader. * @param fname The class name of the fragment to instantiate. * @param args Bundle of arguments to supply to the fragment, which it * can retrieve with {@link #getArguments()}. May be null. * @return Returns a new fragment instance. * @throws InstantiationException If there is a failure in instantiating * the given fragment class. This is a runtime exception; it is not * normally expected to happen.//from w ww. j a v a 2s .c o m */ public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { try { Class<?> clazz = sClassMap.get(fname); if (clazz == null) { // Class not found in the cache, see if it's real, and try to add it clazz = context.getClassLoader().loadClass(fname); if (!Fragment.class.isAssignableFrom(clazz)) { throw new InstantiationException( "Trying to instantiate a class " + fname + " that is not a Fragment", new ClassCastException()); } sClassMap.put(fname, clazz); } Fragment f = (Fragment) clazz.newInstance(); if (args != null) { args.setClassLoader(f.getClass().getClassLoader()); f.mArguments = args; } return f; } catch (ClassNotFoundException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } catch (java.lang.InstantiationException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } catch (IllegalAccessException e) { throw new InstantiationException("Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } }
From source file:co.taqat.call.LinphoneActivity.java
public void onMessageSent(String to, String message) { Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer); if (fragment.getClass() == ChatListFragment.class) { ((ChatListFragment) fragment).refresh(); }/* w ww .j a va 2 s . c o m*/ }
From source file:android.app.FragmentState.java
public FragmentState(Fragment frag) { mClassName = frag.getClass().getName(); mIndex = frag.mIndex;//from w ww.j a va2 s . c om mFromLayout = frag.mFromLayout; mFragmentId = frag.mFragmentId; mContainerId = frag.mContainerId; mTag = frag.mTag; mRetainInstance = frag.mRetainInstance; mDetached = frag.mDetached; mArguments = frag.mArguments; }