Java Code Examples for android.support.v4.app.Fragment#isHidden()

The following examples show how to use android.support.v4.app.Fragment#isHidden() . 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: SwipeLayout.java    From FragmentRigger with MIT License 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!mIsEnable || canSwipe(SwipeEdge.NONE)) return super.onInterceptTouchEvent(event);
    try {
        Fragment preFragment = getPreFragment();
        if (preFragment == null && mStickyWithHost) {
            return mDragHelper.shouldInterceptTouchEvent(event);
        }
        Fragment topFragment = getTopFragment();
        if (topFragment != null) {
            boolean ableSwipeBack = Rigger.getRigger(topFragment).isAbleSwipeBack();
            if (ableSwipeBack && topFragment.getView() != null && !topFragment.isHidden()) {
                return false;
            }
        }
        return mDragHelper.shouldInterceptTouchEvent(event);
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    return false;
}
 
Example 2
Source File: _Rigger.java    From FragmentRigger with MIT License 6 votes vote down vote up
@Override
public void showFragment(@NonNull Fragment fragment, @IdRes int containerViewId, boolean showRepeatAnim) {
    String fragmentTAG = Rigger.getRigger(fragment).getFragmentTAG();
    if (mStackManager.add(fragmentTAG, containerViewId)) {
        addFragmentWithAnim(fragment, containerViewId);
    }
    String[] fragmentTags = mStackManager.getFragmentTags(containerViewId);
    for (String tag : fragmentTags) {
        Fragment hideFrag = mRiggerTransaction.find(tag);
        if (hideFrag == null) continue;
        hideFrag.setUserVisibleHint(false);
    }
    fragment.setUserVisibleHint(true);
    boolean hidden = fragment.isHidden();
    boolean added = fragment.isAdded();
    if (!added || hidden || showRepeatAnim) {
        mRiggerTransaction.hide(getVisibleFragmentTags(containerViewId));
        showFragmentWithAnim(fragment);
    }
    mRiggerTransaction.commit();
}
 
Example 3
Source File: Main2Activity.java    From CoreModule with Apache License 2.0 6 votes vote down vote up
/**
 * 用Fragment替换内容区
 *
 * @param targetFragment 用来替换的Fragment
 */
public void changeFragment(Fragment targetFragment) {
    if (targetFragment.equals(currentFragment)) {
        return;
    }
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(R.id.main_body, targetFragment, targetFragment.getClass()
                .getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
    }
    if (currentFragment != null && currentFragment.isVisible()) {
        transaction.hide(currentFragment);
    }
    currentFragment = targetFragment;
    transaction.commit();
}
 
Example 4
Source File: TabStripView.java    From LLApp with Apache License 2.0 6 votes vote down vote up
private boolean isFragmentShown(FragmentTransaction transaction, String newTag) {
        if (TextUtils.equals(newTag, mCurrentTag)) {
            return true;
        }

        if (TextUtils.isEmpty(mCurrentTag)) {
            return false;
        }

//        Fragment fragment = mFragmentActivity.getFragmentManager().findFragmentByTag(mCurrentTag);
        Fragment fragment = mFragmentActivity.getSupportFragmentManager().findFragmentByTag(mCurrentTag);
        if (fragment != null && !fragment.isHidden()) {
            transaction.hide(fragment);
        }

        return false;
    }
 
Example 5
Source File: TabStripView.java    From LLApp with Apache License 2.0 6 votes vote down vote up
private void hideAllFragment() {
        if (mViewHolderList == null || mViewHolderList.size() == 0) {
            return;
        }
//        FragmentTransaction transaction = mFragmentActivity.getFragmentManager().beginTransaction();
        FragmentTransaction transaction = mFragmentActivity.getSupportFragmentManager().beginTransaction();

        for (ViewHolder holder : mViewHolderList) {
//            Fragment fragment = mFragmentActivity.getFragmentManager().findFragmentByTag(holder.tag);
            Fragment fragment = mFragmentActivity.getSupportFragmentManager().findFragmentByTag(holder.tag);
            if (fragment != null && !fragment.isHidden()) {
                transaction.hide(fragment);
            }
        }
        transaction.commit();
    }
 
Example 6
Source File: ShakeHelper.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
@Nullable
private List<Fragment> getSupportTopFragments() {
    if (manager == null) {
        return null;
    }
    List<Fragment> fragments = manager.getFragments();
    List<Fragment> topFragments = new ArrayList<>();
    if (fragments == null) {
        return null;
    }
    int size = fragments.size();
    for (int i = size - 1; i >= 0; i--) {
        Fragment f = fragments.get(i);
        if (f.isAdded() && !f.isHidden() && f.getUserVisibleHint()) {
            Fragment t = getSupportTopFragment(f.getChildFragmentManager());//递归
            if (t != null) {
                topFragments.add(t);
            } else {
                topFragments.add(f);
            }
        }

    }
    return topFragments;
}
 
Example 7
Source File: ShakeHelper.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Fragment getSupportTopFragment(FragmentManager manager) {
    List<Fragment> fragments = manager.getFragments();
    if (fragments == null) {
        return null;
    }
    int size = fragments.size();
    for (int i = size - 1; i >= 0; i--) {
        Fragment f = fragments.get(i);
        if (f.isAdded() && !f.isHidden() && f.getUserVisibleHint()) {
            Fragment tTopFragment = getSupportTopFragment(f.getChildFragmentManager());
            return tTopFragment == null ? f : tTopFragment;
        }
    }
    return null;
}
 
Example 8
Source File: MainActivity.java    From ListBuddies with Apache License 2.0 6 votes vote down vote up
private void manageFragment(Fragment newInstanceFragment, FragmentTags tag, boolean addToBackStack) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment currentIntanceFragment = findFragmentByTag(tag);
    if (currentIntanceFragment == null || (currentIntanceFragment != null && currentIntanceFragment.isHidden())) {
        if (currentIntanceFragment != null) {
            ft.show(currentIntanceFragment);
        } else {
            currentIntanceFragment = newInstanceFragment;
            ft.add(R.id.container, currentIntanceFragment, tag.toString());
            if (addToBackStack) {
                ft.addToBackStack(null);
            }
        }
    } else {
        ft.hide(currentIntanceFragment);
        fm.popBackStack();
    }
    ft.commit();
}
 
Example 9
Source File: FragmentCompat.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @date 创建时间 2018/4/22
 * @author a2
 * @Description 是否是当前fragment
 * @version
 */
public static boolean isCurrent(FragmentManager fragmentManager, Fragment currentPage) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments != null && fragments.size() > 0) {
        for (Fragment fragment : fragments) {
            if (fragment != null && !fragment.isHidden() && fragment == currentPage) {
                return true;
            }
        }
    }

    return false;
}
 
Example 10
Source File: FragmentLifecycleListener.java    From Tracker with MIT License 5 votes vote down vote up
@Override
public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f) {
	super.onFragmentResumed(fm, f);
	if (!f.isHidden() && f.getUserVisibleHint()) {
		onVisibleChanged(f, true);
	}
	LogUtil.i(f.getClass().getSimpleName() + " onFragmentResumed");
}
 
Example 11
Source File: FragmentLifecycleListener.java    From Tracker with MIT License 5 votes vote down vote up
@Override
public void onFragmentPaused(@NonNull FragmentManager fm, @NonNull Fragment f) {
	super.onFragmentPaused(fm, f);
	if (!f.isHidden() && f.getUserVisibleHint()) {
		onVisibleChanged(f, false);
	}
	// 解决viewpager中fragment切换时事件统计失效的问题
	eventTrackerMap.put(f, false);
	LogUtil.i(f.getClass().getSimpleName() + " onFragmentPaused");
}
 
Example 12
Source File: ShowFragment.java    From FragmentRigger with MIT License 5 votes vote down vote up
private void showFragment(int position) {
  Fragment fragment = Rigger.getRigger(this).findFragmentByTag(mFragmentTags.get(position));
  Rigger.getRigger(this).showFragment(mFragmentTags.get(position), false);
  if (position == 2) return;
  if (fragment.isHidden()) {
    Rigger.getRigger(this).showFragment(mFragmentTags.get(position));
  } else {
    Rigger.getRigger(this).showFragment(mContainerTags.get(position));
  }
}
 
Example 13
Source File: _Rigger.java    From FragmentRigger with MIT License 5 votes vote down vote up
/**
 * Return fragments tag which the fragment's view is visible and is add onto the container view.
 *
 * @param containerViewId The container view's id to be found.
 *
 * @return The fragment tags.
 */
private String[] getVisibleFragmentTags(@IdRes int containerViewId) {
    List<String> result = new ArrayList<>();
    String[] fragmentTags = mStackManager.getFragmentTags(containerViewId);
    for (String tag : fragmentTags) {
        Fragment fragment = mRiggerTransaction.find(tag);
        if (fragment != null && !fragment.isHidden() &&
                fragment.getView() != null && fragment.getView().getVisibility() == View.VISIBLE) {
            result.add(tag);
        }
    }
    return result.toArray(new String[result.size()]);
}
 
Example 14
Source File: TabManager.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
private void hideTabs(FragmentTransaction transaction) {
    for (Fragment fragment : existingFragments) {
        if (fragment != null && !fragment.isHidden()) {
            transaction.hide(fragment);
            fragment.onPause();
        }
    }
}
 
Example 15
Source File: AbstractLazyLoadFragment.java    From Yuan-WanAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 当前Fragment是否可见
 */
private boolean isFragmentVisible(Fragment fragment) {
    return !fragment.isHidden() && fragment.getUserVisibleHint();
}
 
Example 16
Source File: BaseLazyFragment.java    From Yuan-SxMusic with Apache License 2.0 4 votes vote down vote up
private boolean isFragmentVisible(Fragment fragment){
    return fragment.getUserVisibleHint()&&!fragment.isHidden();
}