List of usage examples for android.app FragmentManager findFragmentByTag
public abstract Fragment findFragmentByTag(String tag);
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.UnitTestJSONArrayActivity.java
@Override protected void initFrags() { super.initFrags(); FragmentManager manager = getFragmentManager(); mListFragment = (UnitTestJSONArrayFragment) manager.findFragmentByTag(TAG_ADAPTER_FRAG); if (mListFragment == null) { mListFragment = UnitTestJSONArrayFragment.newInstance(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frag_container, mListFragment, TAG_ADAPTER_FRAG); transaction.commit();/* w w w. j a v a 2s . c o m*/ } }
From source file:com.kennethmaffei.infinitegrid.HTTPCommManager.java
/** * Sets up a headless fragment that calls an AsyncTask to retrieve records in the db * //from w ww .j ava2s .c o m * @param activity - the activity, needed to access the fragment manager */ public void getDBData() { if (activity == null) return; synchronized (synchronizeObject) { if (!retrievalDone) return; retrievalDone = false; imageCount = 0; FragmentManager fm = activity.getFragmentManager(); TaskFragment taskFragment = (TaskFragment) fm.findFragmentByTag(Constants.TAG_TASK_GETALLRECORDS); //If the Fragment is non-null, then it is currently being retained across a configuration change. if (taskFragment == null) { taskFragment = new TaskFragment(); Bundle args = new Bundle(); args.putInt("type", CALLTYPE.ALL_RECORDS.ordinal()); taskFragment.setArguments(args); fm.beginTransaction().add(taskFragment, Constants.TAG_TASK_GETALLRECORDS).commit(); } } }
From source file:org.peterbaldwin.vlcremote.app.PickServerActivity.java
@SuppressWarnings("unchecked") public <T extends android.app.Fragment> T findOrReplaceFragment(int res, String tag, Class<T> fragmentClass) { try {//from w ww. j a v a2s. com FragmentManager fm = getFragmentManager(); T fragment = (T) fm.findFragmentByTag(tag); if (fragment == null) { fragment = fragmentClass.newInstance(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(res, fragment, tag); fragmentTransaction.commit(); fm.executePendingTransactions(); } return fragment; } catch (InstantiationException e) { throw new IllegalArgumentException(e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } }
From source file:com.android.tv.settings.dialog.DialogFragment.java
public static void add(FragmentManager fm, DialogFragment f) { boolean hasDialog = fm.findFragmentByTag(TAG_LEAN_BACK_DIALOG_FRAGMENT) != null; FragmentTransaction ft = fm.beginTransaction(); if (hasDialog) { ft.setCustomAnimations(ANIMATION_FRAGMENT_ENTER, ANIMATION_FRAGMENT_EXIT, ANIMATION_FRAGMENT_ENTER_POP, ANIMATION_FRAGMENT_EXIT_POP); ft.addToBackStack(null);/* ww w. j a v a 2 s . com*/ } ft.replace(android.R.id.content, f, TAG_LEAN_BACK_DIALOG_FRAGMENT).commit(); }
From source file:com.kennethmaffei.infinitegrid.HTTPCommManager.java
/** * Sets up a headless fragment that calls an asynctask to retrieve an image from a url * /*from w ww .ja va 2s. c o m*/ * @param url - the url which we will get data back from */ public void getURL(RecordDescriptor record) { if (activity == null) return; FragmentManager fm = activity.getFragmentManager(); //Use the url as the fragment tag TaskFragment taskFragment = (TaskFragment) fm.findFragmentByTag(record.url); //If the Fragment is non-null, then it is currently being retained across a configuration change. if (taskFragment == null) { taskFragment = new TaskFragment(); Bundle args = new Bundle(); args.putInt("type", CALLTYPE.IMAGE.ordinal()); args.putParcelable("record", record); taskFragment.setArguments(args); fm.beginTransaction().add(taskFragment, record.url).commit(); } }
From source file:edu.scranton.fisherc5.busybusy.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.findFragmentByTag("PRE_COMPARE") != null) { fragmentManager.popBackStack("PRE_COMPARE_PUSH", FragmentManager.POP_BACK_STACK_INCLUSIVE); }/*from w ww.ja va2 s . co m*/ switch (position) { case 0: Fragment updateFrag = new UpdateFragment(); fragmentManager.beginTransaction().replace(R.id.content_frame, updateFrag).commit(); break; case 1: Fragment precompareFrag = new PreCompareFragment(); fragmentManager.beginTransaction().replace(R.id.content_frame, precompareFrag).commit(); break; case 3: Fragment updateActivityFrag = new UpdateUserActivityFragment(); fragmentManager.beginTransaction().replace(R.id.content_frame, updateActivityFrag).commit(); break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mNavItems[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.breadwallet.tools.animation.BRAnimator.java
/** * Animate the transition on burgerButton/MenuButton pressed *//*from w ww.ja va2 s.com*/ public static void pressMenuButton(final MainActivity context) { try { if (context == null) return; ((BreadWalletApp) context.getApplication()).cancelToast(); final FragmentManager fragmentManager = context.getFragmentManager(); if (level == 0) { if (PLATFORM_ON) new Thread(new Runnable() { @Override public void run() { HTTPServer.startServer(); } }).start(); level++; CustomPagerAdapter.adapter.showFragments(false, context); context.setBurgerButtonImage(BRConstants.CLOSE); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentSettingsAll to = (FragmentSettingsAll) fragmentManager .findFragmentByTag(FragmentSettingsAll.class.getName()); if (to == null) to = new FragmentSettingsAll(); fragmentTransaction.add(R.id.main_layout, to, FragmentSettingsAll.class.getName()); fragmentTransaction.commit(); final FragmentSettingsAll finalTo = to; new Handler().postDelayed(new Runnable() { @Override public void run() { TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0); trans.setDuration(500); trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f)); View view = finalTo.getView(); if (view != null) view.startAnimation(trans); } }, 1); InputMethodManager keyboard = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); if (keyboard != null) keyboard.hideSoftInputFromWindow( CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0); } else if (level == 1) { if (PLATFORM_ON) new Thread(new Runnable() { @Override public void run() { HTTPServer.stopServer(); } }).start(); level--; context.setBurgerButtonImage(BRConstants.BURGER); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom); FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) fragmentManager .findFragmentByTag(FragmentSettingsAll.class.getName()); fragmentTransaction.remove(fragmentSettingsAll); fragmentTransaction.commit(); CustomPagerAdapter.adapter.showFragments(true, context); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.kenny.openimgur.ui.FragmentPagerAdapter.java
/** * @return may return null if the fragment has not been instantiated yet for that position - this depends on if the fragment has been viewed * yet OR is a sibling covered by {@link android.support.v4.view.ViewPager#setOffscreenPageLimit(int)}. Can use this to call methods on * the current positions fragment.//from www.ja v a 2 s .c om */ @Nullable public Fragment getFragmentForPosition(ViewPager viewPager, FragmentManager fragmentManager, int position) { String tag = makeFragmentName(viewPager.getId(), getItemId(position)); Fragment fragment = fragmentManager.findFragmentByTag(tag); return fragment; }
From source file:me.pzheng.conn.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); Fragment fragment;//from www. java2s . co m fragment = fm.findFragmentByTag(SettingsFragment.TAG); if (fragment == null) { fragment = new SettingsFragment(); } transaction.replace(R.id.container, fragment, SettingsFragment.TAG); transaction.addToBackStack(null); transaction.commit(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.nathanson.meterreader.activity.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); // use existing fragment, if possible. String fragmentTag = String.valueOf(position); Fragment frag = fragmentManager.findFragmentByTag(fragmentTag); fragmentManager.beginTransaction()/*from w w w . j a va2s . co m*/ .replace(R.id.container, frag != null ? frag : fragmentFactory(position), fragmentTag).commit(); }