android.view.View#generateViewId ( )源码实例Demo

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

源代码1 项目: MultiLineRadioGroup   文件: MultiLineRadioGroup.java
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;
        }

    }
}
 
源代码2 项目: android_9.0.0_r45   文件: RadioGroup.java
/**
 * {@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);
    }
}
 
源代码3 项目: DoraemonKit   文件: MultiLineRadioGroup.java
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;
        }

    }
}
 
源代码4 项目: WebRTCapp   文件: CustomWebSocketListener.java
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);
}
 
源代码5 项目: sealrtc-android   文件: BeautyBoxGroup.java
/** {@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);
    }
}
 
源代码6 项目: ToggleButtons   文件: ToggleGroup.java
/**
 * {@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);
    }
}
 
源代码7 项目: PLDroidShortVideo   文件: BeautyBoxGroup.java
/**
 * {@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);
    }
}
 
源代码8 项目: PLDroidShortVideo   文件: CheckGroup.java
/**
 * {@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);
    }
}
 
源代码9 项目: weex-uikit   文件: WXViewUtils.java
@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();
  }
}
 
源代码10 项目: material-components-android   文件: ChipGroup.java
@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);
  }
}
 
源代码11 项目: ToggleButtons   文件: ToggleGroup.java
/**
 * {@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);
    }
}
 
源代码12 项目: scene   文件: AsyncInflateSceneDemo.java
@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;
}
 
源代码13 项目: Common   文件: ViewHelper.java
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;
            }
        }
    }
}
 
源代码14 项目: Android-Image-Slider   文件: IdUtils.java
public static int generateViewId(){
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return generateId();
    } else {
        return View.generateViewId();
    }
}
 
源代码15 项目: NestedRadioButton   文件: NestedRadioButton.java
@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());
    }
}
 
源代码16 项目: MaterialRadioGroup   文件: Utils.java
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();
    }
}
 
源代码17 项目: VideoMeeting   文件: ViewUtils.java
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();
}
 
源代码18 项目: ankihelper   文件: ViewUtil.java
@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();
}
 
源代码19 项目: EasySettings   文件: SettingsObject.java
/**
 * 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);
		}
	}
}
 
源代码20 项目: nono-android   文件: PinViewUtils.java
/**
 * 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();
    }
}
 
 方法所在类
 同类方法