android.view.ViewGroup#getId ( )源码实例Demo

下面列出了android.view.ViewGroup#getId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected synchronized final void addRootViewGroup(
    int tag,
    ViewGroup view,
    ThemedReactContext themedContext) {
  if (view.getId() != View.NO_ID) {
    throw new IllegalViewOperationException(
        "Trying to add a root view with an explicit id already set. React Native uses " +
        "the id field to track react tags and will overwrite this field. If that is fine, " +
        "explicitly overwrite the id field to View.NO_ID before calling addRootView.");
  }

  mTagsToViews.put(tag, view);
  mTagsToViewManagers.put(tag, mRootViewManager);
  mRootTags.put(tag, true);
  view.setId(tag);
}
 
源代码2 项目: react-native-GPay   文件: TouchTargetHelper.java
/**
 * Find touch event target view within the provided container given the coordinates provided
 * via {@link MotionEvent}.
 *
 * @param eventX the X screen coordinate of the touch location
 * @param eventY the Y screen coordinate of the touch location
 * @param viewGroup the container view to traverse
 * @param viewCoords an out parameter that will return the X,Y value in the target view
 * @param nativeViewTag an out parameter that will return the native view id
 * @return the react tag ID of the child view that should handle the event
 */
public static int findTargetTagAndCoordinatesForTouch(
    float eventX,
    float eventY,
    ViewGroup viewGroup,
    float[] viewCoords,
    @Nullable int[] nativeViewTag) {
  UiThreadUtil.assertOnUiThread();
  int targetTag = viewGroup.getId();
  // Store eventCoords in array so that they are modified to be relative to the targetView found.
  viewCoords[0] = eventX;
  viewCoords[1] = eventY;
  View nativeTargetView = findTouchTargetView(viewCoords, viewGroup);
  if (nativeTargetView != null) {
    View reactTargetView = findClosestReactAncestor(nativeTargetView);
    if (reactTargetView != null) {
      if (nativeViewTag != null) {
        nativeViewTag[0] = reactTargetView.getId();
      }
      targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
    }
  }
  return targetTag;
}
 
/**
 * Call this method in the onCreateView() of any subclasses
 *
 * @param container          The container passed into onCreateView()
 * @param savedInstanceState The Instance state bundle passed into the onCreateView() method
 */
protected void init(final ViewGroup container,
                    final Bundle savedInstanceState) {
    mContainerViewId = container.getId();
    long lastScreenTime = 0l;
    if (savedInstanceState != null) {
        mAddUserInfoDialogFragment = (AddUserInfoDialogFragment) getFragmentManager()
                .findFragmentByTag(FragmentTags.DIALOG_ADD_NAME);
        lastScreenTime = savedInstanceState.getLong(Keys.LAST_SCREEN_TIME);
    }

    if (Utils.shouldReportScreenHit(lastScreenTime)) {
        mShouldReportScreenHit = true;
    } else {
        mShouldReportScreenHit = false;
    }
}
 
源代码4 项目: backstack   文件: LinearBackStack.java
/**
 * Adds a new view onto the stack. This will add it to the container specified. Only containers that
 * are lower or equal position in the view hierarchy as the default container are allowed.
 * Views that aren't at the top of the stack will non-clickable.
 * @param viewCreator The view creator for the new view
 * @param container The container to add the view to
 */
public void add(ViewCreator viewCreator, ViewGroup container){
    if (container.getId() == -1){
        throw new RuntimeException("Container must have an id set");
    }
    if (!s.allowDuplicates && checkForDuplicates(viewCreator)){
        return;
    }

    BackStackNode backStackNode = new BackStackNode(viewCreator, container.getId());
    final ViewGroup tempView = currentView;
    final BackStackNode tempNode = s.nodeStack.peek();

    disable(tempView);
    s.nodeStack.add(backStackNode);
    currentView = addView(backStackNode);
    removeView(tempNode, tempView);
}
 
源代码5 项目: backstack   文件: BackStackManager.java
private LinearBackStack buildLinearBackStack(String TAG, ViewGroup container, ViewGroup currentView, ViewCreator viewCreator, boolean shouldRetain, boolean allowDuplicates){
    LinearBackStack.State state = linearStateMap.get(TAG);
    if (state == null){
        BackStackNode backStackNode = new BackStackNode(viewCreator, container.getId(), shouldRetain);
        state = new LinearBackStack.State(TAG, backStackNode);
        state.allowDuplicates = allowDuplicates;
        linearStateMap.put(TAG, state);
        //
    }

    LinearBackStack linearBackStack = new LinearBackStack(state, container, activity);
    if (currentView == null){
        linearBackStack.init();
    } else {
        if (state.nodeStack.size() != 1 && !shouldRetain){
            container.removeView(currentView);
        }
        linearBackStack.initWithoutFirst(currentView);
    }
    backStackMap.put(TAG, linearBackStack);
    setDefaultRootBackStack(TAG);

    return linearBackStack;
}
 
源代码6 项目: droidtestrec   文件: ActivityProcessor.java
private boolean isIdDuplicated(ViewGroup view, int viewId, IntegerHolder num) {
    for (int i = 0; i < view.getChildCount(); i++) {
        View child = view.getChildAt(i);

        if (child instanceof ViewGroup) {
            boolean tst = isIdDuplicated((ViewGroup) child, viewId, num);
            if (tst) {
                return true;
            }
        } else {
            if (child.getId() == viewId) {
                num.value++;
                if (num.value > 1) {
                    return true;
                }
            }
        }
    }

    if (view.getId() == viewId) {
        num.value++;
    }

    return num.value > 1;
}
 
源代码7 项目: moviedb-android   文件: TVSlideAdapter.java
/**
 * @param container - our Viewpager
 * Fired when we are in Movie or TV details and we pressed back button.
 * Recreates our fragments.
 */
public void reAttachFragments(ViewGroup container) {
    if (mCurTransaction == null) {
        mCurTransaction = manager.beginTransaction();
    }

    for (int i = 0; i < getCount(); i++) {

        final long itemId = getItemId(i);

        // Do we already have this fragment?
        String name = "android:switcher:" + container.getId() + ":" + itemId;
        Fragment fragment = manager.findFragmentByTag(name);

        if (fragment != null) {
            mCurTransaction.detach(fragment);
        }
    }
    mCurTransaction.commit();
    mCurTransaction = null;
}
 
@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;
}
 
源代码9 项目: OpenPagerAdapter   文件: OpenPagerAdapter.java
@Override
public void startUpdate(ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
源代码10 项目: dynamic-support   文件: DynamicActivity.java
/**
 * Set view group visibility according to the child views.
 *
 * @param viewGroup The view group to set the visibility.
 */
private void setFrameVisibility(@Nullable ViewGroup viewGroup) {
    if (viewGroup == null) {
        return;
    }

    viewGroup.setVisibility(viewGroup.getChildCount() > 0 ? View.VISIBLE : View.GONE);

    if (viewGroup.getId() == R.id.ads_footer_frame && mBottomBarShadow != null) {
        mBottomBarShadow.setVisibility(viewGroup.getVisibility());
    }
}
 
源代码11 项目: Dainty   文件: UpdatableFragmentPagerAdapter.java
@Override
public void startUpdate(@NonNull ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
源代码12 项目: cwac-pager   文件: ArrayPagerAdapter.java
@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;
}
 
源代码13 项目: AndroidUiKit   文件: TabPagerAdapter.java
@Override
public void startUpdate(ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
源代码14 项目: AndroidDigIn   文件: DragViewGroup.java
private ViewGroup findContentLayout(ViewGroup parent) {
    if (parent == null) {
        return null;
    }
    if (parent.getId() != android.R.id.content) {
        return findContentLayout((ViewGroup) parent.getParent());
    } else {
        return parent;
    }
}
 
源代码15 项目: backstack   文件: LinearBackStack.java
/**
 * Sets the parent container for the new view. The parent
 * @param container
 * @return
 */
public Builder setContainer(ViewGroup container){
    if (container.getId() == -1){
        throw new RuntimeException("Parent Container must have id set");
    }

    containerId = container.getId();

    return this;
}
 
@Override
public void startUpdate(@NonNull ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
源代码17 项目: island   文件: SetupWizardFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
		final SetupViewModel vm;
		if (savedInstanceState == null) {
			final Bundle args = getArguments();
			vm = args != null ? args.getParcelable(null) : null;
		} else vm = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL);

		if (vm == null) {
			mViewModel = new SetupViewModel();		// Initial view - "Welcome"
			mViewModel.button_next.set(R.string.setup_accept);	// "Accept" button for device-admin privilege consent, required by Google Play developer policy.
		} else mViewModel = vm;

		mContainerViewId = container.getId();
		final SetupWizardBinding binding = SetupWizardBinding.inflate(inflater, container, false);
		binding.setSetup(mViewModel);
		final View view = binding.getRoot();
		final SetupWizardLayout layout = view.findViewById(R.id.setup_wizard_layout);
		layout.requireScrollToBottom();

		final NavigationBar nav_bar = layout.getNavigationBar();
		nav_bar.setNavigationBarListener(this);
		setButtonText(nav_bar.getBackButton(), mViewModel.button_back);
		setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get());
//		mViewModel.button_back.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) {
//			setButtonText(button_back, mViewModel.button_back);
//		}});
		mViewModel.button_next.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) {
			setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get());
		}});

		return view;
	}
 
源代码18 项目: moviedb-android   文件: MovieSlideAdapter.java
/**
 * @param container - our Viewpager
 *                  Fired when we are in Movie or TV details and we pressed back button.
 *                  Recreates our fragments.
 */
public void reAttachFragments(ViewGroup container) {
    if (mCurTransaction == null) {
        mCurTransaction = manager.beginTransaction();
    }

    for (int i = 0; i < getCount(); i++) {

        final long itemId = getItemId(i);

        // Do we already have this fragment?
        String name = "android:switcher:" + container.getId() + ":" + itemId;
        Fragment fragment = manager.findFragmentByTag(name);

        if (fragment != null) {
            mCurTransaction.detach(fragment);
        }
    }
    // Add this check for JUnit testing
    // This try block is added, because JUnit test fails in MainActivityTest.java, setUp() method.
    // java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    try {
        mCurTransaction.commit();
    } catch (java.lang.IllegalStateException e) {
    }
    mCurTransaction = null;
}
 
源代码19 项目: ProjectX   文件: FragmentRemovePagerAdapter.java
@Override
public void startUpdate(@NonNull ViewGroup container) {
    mViewGroupId = container.getId();
    if (mViewGroupId == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
源代码20 项目: scene   文件: GroupScene.java
private void replacePlaceHolderViewToTargetScene() {
    List<ScenePlaceHolderView> holderViewList = new ArrayList<>();
    extractScenePlaceHolder(holderViewList, (ViewGroup) requireView());
    if (holderViewList.size() == 0) {
        return;
    }

    if (isSupportRestore()) {
        //We can't handle user remove Scene, then add same tag Scene to another ViewGroup
        throw new IllegalStateException("ScenePlaceHolderView can only be used when support restore is disabled");
    }

    SparseArray<ViewGroup> parentIdViewMap = new SparseArray<>();
    for (int i = 0, N = holderViewList.size(); i < N; i++) {
        ScenePlaceHolderView holderView = holderViewList.get(i);
        ViewGroup parent = (ViewGroup) holderView.getParent();
        int parentId = parent.getId();
        if (parentId == View.NO_ID) {
            throw new IllegalArgumentException("ScenePlaceHolderView parent id can't be View.NO_ID");
        }
        if (parentIdViewMap.get(parentId) == null) {
            parentIdViewMap.put(parentId, parent);
        } else if (parentIdViewMap.get(parentId) != parent) {
            throw new IllegalArgumentException("ScenePlaceHolderView' parent ViewGroup should have unique id," +
                    " the duplicate id is " + Utility.getIdName(requireSceneContext(), parentId));
        }
        ViewGroup.LayoutParams layoutParams = holderView.getLayoutParams();
        String name = holderView.getSceneName();
        String tag = holderView.getSceneTag();
        Bundle arguments = holderView.getArguments();

        Scene scene = null;
        SceneComponentFactory componentFactory = holderView.getSceneComponentFactory();
        if (componentFactory != null) {
            scene = componentFactory.instantiateScene(requireSceneContext().getClassLoader(), name, arguments);
        }
        if (scene == null) {
            scene = SceneInstanceUtility.getInstanceFromClassName(requireSceneContext(), name, arguments);
        }
        int index = parent.indexOfChild(holderView);
        parent.removeView(holderView);
        if (holderView.getVisibility() == View.VISIBLE) {
            add(parentId, scene, tag);
        } else if (holderView.getVisibility() == View.GONE) {
            beginTransaction();
            add(parentId, scene, tag);
            hide(scene);
            commitTransaction();
        } else {
            throw new IllegalStateException("ScenePlaceHolderView's visibility can't be View.INVISIBLE, use View.VISIBLE or View.GONE instead");
        }
        View sceneView = scene.requireView();
        if (holderView.getId() != View.NO_ID) {
            if (sceneView.getId() == View.NO_ID) {
                sceneView.setId(holderView.getId());
            } else if (holderView.getId() != sceneView.getId()) {
                String holderViewIdName = Utility.getIdName(requireSceneContext(), holderView.getId());
                String sceneViewIdName = Utility.getIdName(requireSceneContext(), sceneView.getId());
                throw new IllegalStateException(String.format("ScenePlaceHolderView's id %s is different from Scene root view's id %s"
                        , holderViewIdName, sceneViewIdName));
            }
        }
        parent.removeView(sceneView);
        parent.addView(sceneView, index, layoutParams);
    }
}
 
 方法所在类