Java Code Examples for android.view.View#generateViewId()
The following examples show how to use
android.view.View#generateViewId() .
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: MultiLineRadioGroup.java From MultiLineRadioGroup with MIT License | 6 votes |
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 File: ToggleGroup.java From ToggleButtons with MIT License | 6 votes |
/** * {@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 3
Source File: ChipGroup.java From material-components-android with Apache License 2.0 | 6 votes |
@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 4
Source File: WXViewUtils.java From weex-uikit with MIT License | 6 votes |
@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 5
Source File: CheckGroup.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
/** * {@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 6
Source File: BeautyBoxGroup.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
/** * {@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 7
Source File: ToggleGroup.java From ToggleButtons with MIT License | 6 votes |
/** * {@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 8
Source File: BeautyBoxGroup.java From sealrtc-android with MIT License | 6 votes |
/** {@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 9
Source File: CustomWebSocketListener.java From WebRTCapp with Apache License 2.0 | 6 votes |
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 10
Source File: MultiLineRadioGroup.java From DoraemonKit with Apache License 2.0 | 6 votes |
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 11
Source File: RadioGroup.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * {@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 12
Source File: NestedRadioButton.java From NestedRadioButton with Apache License 2.0 | 5 votes |
@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 13
Source File: IdUtils.java From Android-Image-Slider with Apache License 2.0 | 5 votes |
public static int generateViewId(){ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return generateId(); } else { return View.generateViewId(); } }
Example 14
Source File: ViewHelper.java From Common with Apache License 2.0 | 5 votes |
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 15
Source File: Utils.java From MaterialRadioGroup with Apache License 2.0 | 5 votes |
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 16
Source File: AsyncInflateSceneDemo.java From scene with Apache License 2.0 | 5 votes |
@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 17
Source File: ViewUtils.java From VideoMeeting with Apache License 2.0 | 5 votes |
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
Source File: ViewUtil.java From ankihelper with GNU General Public License v3.0 | 5 votes |
@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 File: SettingsObject.java From EasySettings with Apache License 2.0 | 4 votes |
/** * 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
Source File: PinViewUtils.java From nono-android with GNU General Public License v3.0 | 3 votes |
/** * 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(); } }