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

The following are Jave code examples for showing how to use generateViewId() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RelativeRadioGroup   File: RelativeRadioGroup.java   Source Code and License Vote up 8 votes
/**
 * {@inheritDoc}
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onChildViewAdded(View parent, View child) {
    if (parent == RelativeRadioGroup.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).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 2
Project: ToggleButtons   File: ToggleGroup.java   Source Code and License Vote up 7 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
Project: NestRadioGroup   File: NestRadioGroup.java   Source Code and License Vote up 6 votes
/**
 * {@inheritDoc}
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onChildViewAdded(View parent, View child) {
    if (parent == NestRadioGroup.this) {

        final List<CompoundButton> list = findCheckedView(child);
        for(CompoundButton view : list){
            if (view != null) {
                int id = view.getId();
                // generates an id if it's missing
                if (id == View.NO_ID && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    id = View.generateViewId();
                    view.setId(id);
                }
                view.setOnCheckedChangeListener(mChildOnCheckedChangeListener);
            }
        }

    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 4
Project: Bigbang   File: ViewUtil.java   Source Code and License Vote up 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
Project: ucar-weex-core   File: WXViewUtils.java   Source Code and License Vote up 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 6
Project: jackknife   File: MultiRadioGroup.java   Source Code and License Vote up 6 votes
/**
 * {@inheritDoc}
 */
public void onChildViewAdded(View parent, View child) {
    if (parent == MultiRadioGroup.this ) {
        List<RadioButton> btns = getAllRadioButton(child);
        if(btns != null && btns.size() > 0){
            for(RadioButton btn : btns){
                int id = btn.getId();
                // generates an id if it's missing
                if (id == View.NO_ID && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    id = View.generateViewId();
                    btn.setId(id);
                }
                btn.setOnCheckedChangeListener(
                        mChildOnCheckedChangeListener);
            }
        }
    }
    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 7
Project: recycler-view-pager   File: FragmentPagerAdapter.java   Source Code and License Vote up 6 votes
@Override
public long getItemId(int position) {
    int id = mFragmentList.get(position).getId();
    if (id == 0) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            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)) {
                    id = result;
                    break;
                }
            }
        } else {
            id = View.generateViewId();
        }
    }
    mIdArray[position] = id;
    return id;
}
 
Example 8
Project: MaterialAbout   File: ViewIdGenerator.java   Source Code and License Vote up 6 votes
@SuppressLint("NewApi")
public static int generateViewId() {

    if (Build.VERSION.SDK_INT < 17) {
        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 9
Project: weex-uikit   File: WXViewUtils.java   Source Code and License Vote up 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 10
Project: quiz_helper   File: ViewUtil.java   Source Code and License Vote up 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 11
Project: qmui   File: QMUIViewHelper.java   Source Code and License Vote up 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 12
Project: XinFramework   File: ViewFinder.java   Source Code and License Vote up 5 votes
public static int generateViewId() {
    if (SysUtils.hasJellyBeanMr1()) {
        return View.generateViewId();
    } else {
        return UUID.randomUUID().hashCode();
    }
}
 
Example 13
Project: android-radiobutton-extended   File: CompoundFrameLayoutRadioGroup.java   Source Code and License Vote up 5 votes
public void onChildViewAdded(View parent, View child) {
    if (parent == CompoundFrameLayoutRadioGroup.this && child instanceof CompoundFrameLayout) {
        int id = child.getId();
        if (id == View.NO_ID) {
            id = View.generateViewId();
            child.setId(id);
        }
        ((CompoundFrameLayout) child).setOnCheckedChangeWidgetListener(mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 14
Project: QMUI_Android   File: QMUIViewHelper.java   Source Code and License Vote up 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
Project: ankihelper   File: ViewUtil.java   Source Code and License Vote up 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 16
Project: GitHub   File: UltimateGridLayoutAdapter.java   Source Code and License Vote up 4 votes
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public long generateHeaderId(int position) {
    return View.generateViewId();
}