Java Code Examples for android.view.View#generateViewId()

The following examples show how to use android.view.View#generateViewId() . 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
private int generateId() {
    // for API 17 or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return View.generateViewId();

        // for API lower than 17
    } else {

        while (true) {
            final int result = sNextGeneratedId.get();

            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF)
                newValue = 1; // Roll over to 1, not 0.

            if (sNextGeneratedId.compareAndSet(result, newValue))
                return result;
        }

    }
}
 
Example 2
Source Project: android_9.0.0_r45   File: RadioGroup.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onChildViewAdded(View parent, View child) {
    if (parent == RadioGroup.this && child instanceof RadioButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = View.generateViewId();
            child.setId(id);
        }
        ((RadioButton) child).setOnCheckedChangeWidgetListener(
                mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 3
Source Project: DoraemonKit   File: MultiLineRadioGroup.java    License: Apache License 2.0 6 votes vote down vote up
private int generateId() {
    // for API 17 or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return View.generateViewId();

        // for API lower than 17
    } else {

        while (true) {
            final int result = sNextGeneratedId.get();

            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF)
                newValue = 1; // Roll over to 1, not 0.

            if (sNextGeneratedId.compareAndSet(result, newValue))
                return result;
        }

    }
}
 
Example 4
private void createVideoView(final RemoteParticipant remoteParticipant) {
    Handler mainHandler = new Handler(videoConferenceActivity.getMainLooper());

    Runnable myRunnable = new Runnable() {
        @Override
        public void run() {
            View rowView = videoConferenceActivity.getLayoutInflater().inflate(R.layout.peer_video, null);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(0, 0, 0, 20);
            rowView.setLayoutParams(lp);
            int rowId = View.generateViewId();
            rowView.setId(rowId);
            views_container.addView(rowView);
            SurfaceViewRenderer videoView = (SurfaceViewRenderer)((ViewGroup)rowView).getChildAt(0);
            remoteParticipant.setVideoView(videoView);
            videoView.setMirror(false);
            EglBase rootEglBase = EglBase.create();
            videoView.init(rootEglBase.getEglBaseContext(), null);
            videoView.setZOrderMediaOverlay(true);
            View textView = ((ViewGroup)rowView).getChildAt(1);
            remoteParticipant.setParticipantNameText((TextView) textView);
            remoteParticipant.setView(rowView);
        }
    };
    mainHandler.post(myRunnable);
}
 
Example 5
Source Project: sealrtc-android   File: BeautyBoxGroup.java    License: MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void onChildViewAdded(View parent, View child) {
    if (parent == BeautyBoxGroup.this && child instanceof BaseBeautyBox) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = View.generateViewId();
            child.setId(id);
        }
        ((BaseBeautyBox) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 6
Source Project: ToggleButtons   File: ToggleGroup.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == ToggleGroup.this && child instanceof CompoundButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
         if (Build.VERSION.SDK_INT < 17)
          id = child.hashCode();
         else
             id = View.generateViewId();
            child.setId(id);
        }
        ((CompoundButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 7
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == BeautyBoxGroup.this && child instanceof BeautyBox) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = View.generateViewId();
            child.setId(id);
        }
        ((BeautyBox) child).setOnCheckedChangeListener(
                mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 8
Source Project: PLDroidShortVideo   File: CheckGroup.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onChildViewAdded(View parent, View child) {
    if (parent == CheckGroup.this && child instanceof CheckBox) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = View.generateViewId();
            child.setId(id);
        }
        ((CheckBox) child).setOnCheckedChangeListener(
                mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 9
Source Project: weex-uikit   File: WXViewUtils.java    License: MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
public static int generateViewId() {

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
    for (;;) {
      final int result = sNextGeneratedId.get();
      // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
      int newValue = result + 1;
      if (newValue > 0x00FFFFFF)
        newValue = 1; // Roll over to 1, not 0.
      if (sNextGeneratedId.compareAndSet(result, newValue)) {
        return result;
      }
    }
  } else {
    return View.generateViewId();
  }
}
 
Example 10
@Override
public void onChildViewAdded(View parent, View child) {
  if (parent == ChipGroup.this && child instanceof Chip) {
    int id = child.getId();
    // generates an id if it's missing
    if (id == View.NO_ID) {
      if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
        id = View.generateViewId();
      } else {
        id = child.hashCode();
      }
      child.setId(id);
    }
    ((Chip) child).setOnCheckedChangeListenerInternal(checkedStateTracker);
  }

  if (onHierarchyChangeListener != null) {
    onHierarchyChangeListener.onChildViewAdded(parent, child);
  }
}
 
Example 11
Source Project: ToggleButtons   File: ToggleGroup.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == ToggleGroup.this && child instanceof CompoundButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
         if (Build.VERSION.SDK_INT < 17)
          id = child.hashCode();
         else
             id = View.generateViewId();
            child.setId(id);
        }
        ((CompoundButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 12
Source Project: scene   File: AsyncInflateSceneDemo.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public ViewGroup onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    id = View.generateViewId();

    FrameLayout frameLayout = new FrameLayout(requireActivity());
    frameLayout.setId(id);
    return frameLayout;
}
 
Example 13
Source Project: Common   File: ViewHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static int generateViewId() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return View.generateViewId();
    } else {
        for (; ; ) {
            final int result = sNextGeneratedId.get();
            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
            if (sNextGeneratedId.compareAndSet(result, newValue)) {
                return result;
            }
        }
    }
}
 
Example 14
Source Project: Android-Image-Slider   File: IdUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int generateViewId(){
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return generateId();
    } else {
        return View.generateViewId();
    }
}
 
Example 15
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    int id = getId();
    // generates an id if it's missing
    if (id == View.NO_ID) {
        id = View.generateViewId();
        setId(id);
    }

    attachToParentNestedRadioGroup((View) getParent());
    if(clickableParentIdRes != View.NO_ID) {
        attachClickableParent((View) getParent());
    }
}
 
Example 16
Source Project: MaterialRadioGroup   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static int generateViewId() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        for (; ; ) {
            final int result = sNextGeneratedId.get();
            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
            if (sNextGeneratedId.compareAndSet(result, newValue)) {
                return result;
            }
        }
    } else {
        return View.generateViewId();
    }
}
 
Example 17
Source Project: VideoMeeting   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int generateViewId() {
	if (Build.VERSION.SDK_INT < 17 /* android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 */) {
		for (;;) {
			final int result = sNextGeneratedId.get();
			// aapt-generated IDs have the high byte nonzero; clamp to the
			// range under that.
			int newValue = result + 1;
			if (newValue > 0x00FFFFFF)
				newValue = 1; // Roll over to 1, not 0.
			if (sNextGeneratedId.compareAndSet(result, newValue))
				return result;
		}
	} else
		return View.generateViewId();
}
 
Example 18
@SuppressLint("NewApi")
public static int generateViewId() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        for (; ; ) {
            final int result = sNextGeneratedId.get();
            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF)
                newValue = 1; // Roll over to 1, not 0.
            if (sNextGeneratedId.compareAndSet(result, newValue))
                return result;
        }
    } else
        return View.generateViewId();
}
 
Example 19
Source Project: EasySettings   File: SettingsObject.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * initializes basic views for this {@link SettingsObject}
 * such as the title, summary, and icon.
 * you should override this method and initialize all other views your
 * {@link SettingsObject} contains (e.g. for {@link CheckBoxSettingsObject},
 * initialize the {@link android.widget.CheckBox})
 * @param root the root view containing this entire {@link SettingsObject}
 */
public void initializeViews(View root)
{
	int rootId = View.generateViewId();
	root.setId(rootId);
	individualSettingsRootId = rootId;

	TextView tvTitle = root.findViewById(textViewTitleId);
	tvTitle.setText(getTitle());

	if (textViewSummaryId != null)
	{
		TextView tvSummary = root.findViewById(textViewSummaryId);
		String summary;

		if (useValueAsSummary())
		{
			summary = getValueHumanReadable();
		}

		else
		{
			summary = getSummary();
		}

		if (summary != null &&
			summary.isEmpty() == false)
		{
			tvSummary.setText(summary);
		}

		else
		{
			tvSummary.setVisibility(View.GONE);
		}
	}

	if(imageViewIconId != null)
	{
		ImageView ivIcon = root.findViewById(imageViewIconId);

		if(iconDrawable != null)
		{
			ivIcon.setImageDrawable(iconDrawable);
		}

		//the user specifically set the value to null
		//which means they want the settings object
		//to align as if it has an icon
		else if(iconDrawableId == null)
		{
			ivIcon.setImageDrawable(null);
		}

		//the user does NOT want the settings object to align
		else if (iconDrawableId.equals(NO_ICON_DONT_ALIGN))
		{
			ivIcon.setVisibility(View.GONE);
		}

		//the user wants an actual icon
		else
		{
			ivIcon.setImageResource(iconDrawableId);
		}
	}
}
 
Example 20
/**
 * While {@link View#generateViewId()} require API Level >= 17, this tool is compatibe with all API.
 *
 * According to current API Level, it decide weather using system API or not. So you can use {@link
 * #generateViewId()} and {@link View#generateViewId()} in the
 * same time and don't worry about getting same id.
 *
 * @return Id
 */
public static int generateViewId() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return generateCompatViewId();
    } else {
        return View.generateViewId();
    }
}