Java Code Examples for android.view.ViewGroup#getId()

The following examples show how to use android.view.ViewGroup#getId() . These examples are extracted from open source projects. 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
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);
}
 
Example 2
Source Project: react-native-GPay   File: TouchTargetHelper.java    License: MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
/**
 * 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;
    }
}
 
Example 4
Source Project: backstack   File: LinearBackStack.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source Project: backstack   File: BackStackManager.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source Project: droidtestrec   File: ActivityProcessor.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 7
Source Project: moviedb-android   File: TVSlideAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 8
@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 9
@Override
public void startUpdate(ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
Example 10
Source Project: dynamic-support   File: DynamicActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 11
@Override
public void startUpdate(@NonNull ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
Example 12
Source Project: cwac-pager   File: ArrayPagerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: AndroidUiKit   File: TabPagerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startUpdate(ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
Example 14
Source Project: AndroidDigIn   File: DragViewGroup.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 15
Source Project: backstack   File: LinearBackStack.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
@Override
public void startUpdate(@NonNull ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
Example 17
Source Project: island   File: SetupWizardFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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;
	}
 
Example 18
/**
 * @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;
}
 
Example 19
@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");
    }
}
 
Example 20
Source Project: scene   File: GroupScene.java    License: Apache License 2.0 4 votes vote down vote up
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);
    }
}