Java Code Examples for android.support.v4.app.fragment#setUserVisibleHint()
The following examples show how to use
android.support.v4.app.fragment#setUserVisibleHint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentsAdapter.java From 920-text-editor-v2 with Apache License 2.0 | 6 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) { Fragment fragment = (Fragment)object; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); if(fragment.getFragmentManager() == null) { Log.v(TAG, "fragment manager == null item #"+position+": f="+object); } fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 2
Source File: OpenPagerAdapter.java From OpenPagerAdapter with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("ReferenceEquality") public void setPrimaryItem(ViewGroup container, int position, Object object) { ItemInfo ii = (ItemInfo) object; Fragment fragment = ii.fragment; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 3
Source File: ArrayFragmentStatePagerAdapter.java From ArrayPagerAdapter with Apache License 2.0 | 6 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) { if (mFragments.size() <= position) return; Fragment fragment = mFragments.get(position); if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 4
Source File: FragmentsAdapter.java From 920-text-editor-v2 with Apache License 2.0 | 6 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = getItem(position); if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mCurTransaction.add(container.getId(), fragment); return fragment; }
Example 5
Source File: TaggedFragmentPagerAdapter.java From Storm with Apache License 2.0 | 6 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } final long itemId = getItemId(position); // Do we already have this fragment? String name = createFragmentTag(position); Fragment fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null) { mCurTransaction.attach(fragment); } else { fragment = getItem(position); mCurTransaction.add(container.getId(), fragment, createFragmentTag(position)); } if (fragment != mCurrentPrimaryItem) { fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); } return fragment; }
Example 6
Source File: BaseFragmentPagerAdapter.java From android-common-utils with Apache License 2.0 | 6 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) { ItemData itemData = (ItemData) object; if (itemData == null) { return; } Fragment fragment = itemData.fragment; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 7
Source File: TaggedFragmentStatePagerAdapter.java From yahnac with Apache License 2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { // If we already have this item instantiated, there is nothing // to do. This can happen when we are restoring the entire pager // from its saved state, where the fragment manager has already // taken care of restoring the fragments we previously had instantiated. if (mFragments.size() > position) { Fragment f = mFragments.get(position); if (f != null) { return f; } } if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = getItem(position); if (DEBUG) { Log.v(TAG, "Adding item #" + position + ": f=" + fragment); } if (mSavedState.size() > position) { Fragment.SavedState fss = mSavedState.get(position); if (fss != null) { fragment.setInitialSavedState(fss); } } while (mFragments.size() <= position) { mFragments.add(null); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mFragments.set(position, fragment); mCurTransaction.add(container.getId(), fragment, getTag(position)); return fragment; }
Example 8
Source File: FragmentStatePagerAdapter.java From fragmentviewpager with Apache License 2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { // ----------------------------------------------------------------------------------------- // If we already have this item instantiated, there is nothing to do. This can happen when // we are restoring the entire pager from its saved state, where the fragment manager has // already taken care of restoring the fragments we previously had instantiated. // ----------------------------------------------------------------------------------------- Fragment existingFragment = getFragment(position); if (existingFragment != null) { return existingFragment; } // ----------------------------------------------------------------------------------------- // Else, continue with normal flow. // ----------------------------------------------------------------------------------------- if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = instantiateFragment(position); if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); if (mSavedState.size() > position) { Fragment.SavedState fss = mSavedState.get(position); if (fss != null) { fragment.setInitialSavedState(fss); } } while (mFragments.size() <= position) { mFragments.add(null); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mFragments.set(position, fragment); mCurTransaction.add(container.getId(), fragment); return fragment; }
Example 9
Source File: CustomFragmentStatePagerAdapter.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { // If we already have this item instantiated, there is nothing // to do. This can happen when we are restoring the entire pager // from its saved state, where the fragment manager has already // taken care of restoring the fragments we previously had instantiated. if (mFragments.size() > position) { Fragment f = mFragments.get(position); if (f != null) { return f; } } if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = getItem(position); if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); if (mSavedState.size() > position) { Fragment.SavedState fss = mSavedState.get(position); if (fss != null) { fragment.setInitialSavedState(fss); } } while (mFragments.size() <= position) { mFragments.add(null); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mFragments.set(position, fragment); mCurTransaction.add(container.getId(), fragment); return fragment; }
Example 10
Source File: FragmentManagerAdapter.java From Fishing with GNU General Public License v3.0 | 5 votes |
private void setPrimaryItem(Fragment fragment) { if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); removeItem(mCurrentPrimaryItem); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 11
Source File: ArrayFragmentPagerAdapter.java From ArrayPagerAdapter with Apache License 2.0 | 5 votes |
@SuppressLint("CommitTransaction") @Override public Object instantiateItem(ViewGroup container, int position) { if (currentTransaction == null) { currentTransaction = fragmentManager.beginTransaction(); } // Do we already have this fragment? final IdentifiedItem<T> item = getItemWithId(position); // Do we already have this fragment? String name = makeFragmentName(item.id); Fragment fragment = fragmentManager.findFragmentByTag(name); if (fragment != null) { if (DEBUG) Log.d(TAG, "Attaching item #" + item + ": f=" + fragment); currentTransaction.attach(fragment); } else { fragment = getFragment(item.item, position); if (DEBUG) Log.d(TAG, "Adding item #" + item + ": f=" + fragment); currentTransaction.add(container.getId(), fragment, makeFragmentName(item.id)); } if (fragment != currentPrimaryItem) { fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); } return super.instantiateItem(container, position); }
Example 12
Source File: FragmentStatePagerAdapterFix.java From UMS-Interface with GNU General Public License v3.0 | 5 votes |
@SuppressLint("LongLogTag") @Override public Object instantiateItem(ViewGroup container, int position) { // If we already have this item instantiated, there is nothing // to do. This can happen when we are restoring the entire pager // from its saved state, where the fragment manager has already // taken care of restoring the fragments we previously had instantiated. if (mFragments.size() > position) { Fragment f = mFragments.get(position); if (f != null) { return f; } } if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = getItem(position); if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); if (mSavedState.size() > position) { Fragment.SavedState fss = mSavedState.get(position); if (fss != null) { fragment.setInitialSavedState(fss); } } while (mFragments.size() <= position) { mFragments.add(null); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mFragments.set(position, fragment); mCurTransaction.add(container.getId(), fragment); return fragment; }
Example 13
Source File: ArrayPagerAdapter.java From cwac-pager with Apache License 2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { if (currTransaction == null) { currTransaction=fm.beginTransaction(); } Fragment fragment=getExistingFragment(position); if (fragment != null) { if (fragment.getId() == container.getId()) { retentionStrategy.attach(fragment, currTransaction); } else { fm.beginTransaction().remove(fragment).commit(); fm.executePendingTransactions(); currTransaction.add(container.getId(), fragment, getFragmentTag(position)); } } else { fragment=createFragment(entries.get(position).getDescriptor()); currTransaction.add(container.getId(), fragment, getFragmentTag(position)); } if (fragment != currPrimaryItem) { fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); } return fragment; }
Example 14
Source File: UpdatableFragmentPagerAdapter.java From UpdatableFragmentStatePagerAdapter with Apache License 2.0 | 5 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, @Nullable Object object) { Fragment fragment = (Fragment) object; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 15
Source File: ArrayPagerAdapter.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { if (currTransaction == null) { currTransaction = fm.beginTransaction(); } Fragment fragment = getExistingFragment(position); if (fragment != null) { if (fragment.getId() == container.getId()) { retentionStrategy.attach(fragment, currTransaction); } else { fm.beginTransaction().remove(fragment).commit(); fm.executePendingTransactions(); currTransaction.add(container.getId(), fragment, getFragmentTag(position)); } } else { fragment = createFragment(entries.get(position).getDescriptor()); currTransaction.add(container.getId(), fragment, getFragmentTag(position)); } if (fragment != currPrimaryItem) { fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); } return fragment; }
Example 16
Source File: FragmentRecyclerAdapter.java From RecyclerPager with Apache License 2.0 | 5 votes |
/** * Attach Fragment */ @Override public void onViewAttachedToWindow(@NonNull FragmentViewHolder holder) { String name = makeFragmentName(holder.itemView.getId(), holder.getAdapterPosition()); Fragment fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null && fragment == holder.currentFragment) { // Nothing Changed } else { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); if (fragment != null) { fragmentTransaction.attach(fragment); } else { fragment = getItem(holder.getAdapterPosition()); fragmentTransaction.add(holder.itemView.getId(), fragment, name); } fragmentTransaction.commitNowAllowingStateLoss(); if (holder.currentFragment != null && holder.currentFragment.getUserVisibleHint()) { holder.currentFragment.setMenuVisibility(false); holder.currentFragment.setUserVisibleHint(false); } holder.currentFragment = fragment; if (!fragment.getUserVisibleHint()) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } } }
Example 17
Source File: UpdatableFragmentPagerAdapter.java From Dainty with Apache License 2.0 | 5 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, @Nullable Object object) { Fragment fragment = (Fragment) object; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 18
Source File: HistoryActivity.java From timecat with Apache License 2.0 | 5 votes |
private void updateViewPager(int id) { Fragment fragment = getFragments(id); for (Fragment fragment1:fragmentList) { getSupportFragmentManager().beginTransaction().remove(fragment1).commitNow(); } fragmentList.clear(); fragmentList.add(fragment); fragment.setUserVisibleHint(true); getSupportFragmentManager().beginTransaction().add(R.id.fragments_container, fragment).commitNow(); }
Example 19
Source File: AppFragmentPagerAdapter.java From iBeebo with GNU General Public License v3.0 | 5 votes |
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) { Fragment fragment = (Fragment) object; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } if (fragment != null) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } mCurrentPrimaryItem = fragment; } }
Example 20
Source File: FragmentStatePagerAdapterFix.java From UMS-Interface with GNU General Public License v3.0 | 5 votes |
@SuppressLint("LongLogTag") @Override public Object instantiateItem(ViewGroup container, int position) { // If we already have this item instantiated, there is nothing // to do. This can happen when we are restoring the entire pager // from its saved state, where the fragment manager has already // taken care of restoring the fragments we previously had instantiated. if (mFragments.size() > position) { Fragment f = mFragments.get(position); if (f != null) { return f; } } if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } Fragment fragment = getItem(position); if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); if (mSavedState.size() > position) { Fragment.SavedState fss = mSavedState.get(position); if (fss != null) { fragment.setInitialSavedState(fss); } } while (mFragments.size() <= position) { mFragments.add(null); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); mFragments.set(position, fragment); mCurTransaction.add(container.getId(), fragment); return fragment; }