Java Code Examples for android.view.View.NO_ID

The following are Jave code examples for showing how to use NO_ID 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: RelativeRadioGroup   File: RelativeRadioGroup.java   Source Code and License Vote up 7 votes
/**
 * {@inheritDoc}
 */
public RelativeRadioGroup(Context context, AttributeSet attrs) {
    super(context, attrs);

    // retrieve selected radio button as requested by the user in the
    // XML layout file
    TypedArray attributes = context.obtainStyledAttributes(
            attrs, R.styleable.RelativeRadioGroup, 0, 0);

    int value = attributes.getResourceId(R.styleable.RelativeRadioGroup_checkedButton, View.NO_ID);
    if (value != View.NO_ID) {
        mCheckedId = value;
    }

    attributes.recycle();
    init();
}
 
Example 3
Project: Multi-SwipeToRefreshLayout   File: OverScrollLayout.java   Source Code and License Vote up 7 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (null != mContentView) {
        return;
    }
    if (View.NO_ID != contentLayoutId) {
        mContentView = findViewById(contentLayoutId);
        return;
    }
    for (int i = 0; i < getChildCount(); i++) {//判断是否是addView进来的,不是的话默认其为首选的View,就可以不设置contentLayoutId了,如果没有就抛异常
        View v = getChildAt(i);
        if (v.equals(mLeftView) || v.equals(mTopView) || v.equals(mRightView) || v.equals(mBottomView)) {
            continue;
        }
        mContentView = v;
        return;
    }
    throw new IllegalStateException("请为OverScrollLayout添加contentLayoutId属性,以索引目标View");
}
 
Example 4
Project: ToggleButtons   File: ToggleGroup.java   Source Code and License Vote up 7 votes
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof CompoundButton) {
        final CompoundButton button = (CompoundButton) child;
        if (button.isChecked()) {
            mProtectFromCheckedChange = true;
         int currentCheck = getExclusiveCheckedId();
            if (mExclusive && currentCheck != View.NO_ID) {
                setCheckedStateForView(currentCheck, false);
            }
            mProtectFromCheckedChange = false;
            addCheckedId(button.getId());
        }
    }

    super.addView(child, index, params);
}
 
Example 5
Project: CSipSimple   File: MenuBuilder.java   Source Code and License Vote up 7 votes
public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }

    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}
 
Example 6
Project: LimitedDatePicker   File: NumberPicker.java   Source Code and License Vote up 7 votes
@Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
    switch (virtualViewId) {
        case View.NO_ID:
            return createAccessibilityNodeInfoForNumberPicker( getScrollX(), getScrollY(),
                    getScrollX() + (getRight() - getLeft()), getScrollY() + (getBottom() - getTop()));
        case VIRTUAL_VIEW_ID_DECREMENT:
            return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_DECREMENT,
                    getVirtualDecrementButtonText(), getScrollX(), getScrollY(),
                    getScrollX() + (getRight() - getLeft()),
                    mTopSelectionDividerTop + mSelectionDividerHeight);
        case VIRTUAL_VIEW_ID_INPUT:
            return createAccessibiltyNodeInfoForInputText();
        case VIRTUAL_VIEW_ID_INCREMENT:
            return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_INCREMENT,
                    getVirtualIncrementButtonText(), getScrollX(),
                    mBottomSelectionDividerBottom - mSelectionDividerHeight,
                    getScrollX() + (getRight() - getLeft()), getScrollY() + (getBottom() - getTop()));
    }
    return super.createAccessibilityNodeInfo(virtualViewId);
}
 
Example 7
Project: AndroidUiKit   File: TabPagerAdapter.java   Source Code and License Vote up 6 votes
@Override
public void startUpdate(ViewGroup container) {
    if (container.getId() == View.NO_ID) {
        throw new IllegalStateException("ViewPager with adapter " + this
                + " requires a view id");
    }
}
 
Example 8
Project: ToggleButtons   File: ToggleGroup.java   Source Code and License Vote up 6 votes
/**
   * {@inheritDoc}
   */
  @Override
  protected void onFinishInflate() {
      super.onFinishInflate();

      // checks the appropriate radio button as requested in the XML file
int initialCheck = getExclusiveCheckedId();
      if (initialCheck != View.NO_ID) {
          mProtectFromCheckedChange = true;
          setCheckedStateForView(initialCheck, true);
          mProtectFromCheckedChange = false;
          addCheckedId(initialCheck);
      }
  }
 
Example 9
Project: GitHub   File: FragmentTabHost.java   Source Code and License Vote up 6 votes
public void setup(Context context, FragmentManager manager, int containerId) {
    ensureHierarchy(context); // Ensure views required by super.setup()
    super.setup();
    mContext = context;
    mFragmentManager = manager;
    mContainerId = containerId;
    ensureContent();
    mRealTabContent.setId(containerId);

    // We must have an ID to be able to save/restore our state. If
    // the owner hasn't set one at this point, we will set it ourself.
    if (getId() == View.NO_ID) {
        setId(android.R.id.tabhost);
    }
}
 
Example 10
Project: zabbkit-android   File: FixedFragmentTabHost.java   Source Code and License Vote up 6 votes
public void setup(final Context context, final FragmentManager manager,
		final int containerId) {
	super.setup();
	mContext = context;
	mFragmentManager = manager;
	mContainerId = containerId;
	ensureContent();
	mRealTabContent.setId(containerId);

	// We must have an ID to be able to save/restore our state. If
	// the owner hasn't set one at this point, we will set it ourself.
	if (getId() == View.NO_ID) {
		setId(android.R.id.tabhost);
	}
}
 
Example 11
Project: DateTimePicker   File: NumberPicker.java   Source Code and License Vote up 6 votes
@Override
public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String searched,
                                                                    int virtualViewId) {
    if (TextUtils.isEmpty(searched)) {
        return Collections.emptyList();
    }
    String searchedLowerCase = searched.toLowerCase();
    List<AccessibilityNodeInfo> result = new ArrayList<AccessibilityNodeInfo>();
    switch (virtualViewId) {
        case View.NO_ID: {
            findAccessibilityNodeInfosByTextInChild(searchedLowerCase,
                    VIRTUAL_VIEW_ID_DECREMENT, result);
            findAccessibilityNodeInfosByTextInChild(searchedLowerCase,
                    VIRTUAL_VIEW_ID_INPUT, result);
            findAccessibilityNodeInfosByTextInChild(searchedLowerCase,
                    VIRTUAL_VIEW_ID_INCREMENT, result);
            return result;
        }
        case VIRTUAL_VIEW_ID_DECREMENT:
        case VIRTUAL_VIEW_ID_INCREMENT:
        case VIRTUAL_VIEW_ID_INPUT: {
            findAccessibilityNodeInfosByTextInChild(searchedLowerCase, virtualViewId,
                    result);
            return result;
        }
    }
    return super.findAccessibilityNodeInfosByText(searched, virtualViewId);
}
 
Example 12
Project: Multi-SwipeToRefreshLayout   File: SwipeDrawerLayout.java   Source Code and License Vote up 6 votes
public SwipeDrawerLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallback());

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SwipeToRefreshLayout);
    contentLayoutId = ta.getResourceId(R.styleable.SwipeToRefreshLayout_contentLayoutId, View.NO_ID);
    int leftLayoutId = ta.getResourceId(R.styleable.SwipeToRefreshLayout_leftView, View.NO_ID);
    int topLayoutId = ta.getResourceId(R.styleable.SwipeToRefreshLayout_topView, View.NO_ID);
    int rightLayoutId = ta.getResourceId(R.styleable.SwipeToRefreshLayout_rightView, View.NO_ID);
    int bottomLayoutId = ta.getResourceId(R.styleable.SwipeToRefreshLayout_bottomView, View.NO_ID);
    mDirectionMask = ta.getInt(R.styleable.SwipeToRefreshLayout_swipeDirection, mDirectionMask);
    mFactor = ta.getFloat(R.styleable.SwipeToRefreshLayout_horizontalRangeFactor, 0.3f);
    ta.recycle();

    LayoutInflater inflater = LayoutInflater.from(context);

    if (View.NO_ID != leftLayoutId) {
        mLeftView = inflater.inflate(leftLayoutId, this, false);
        addView(mLeftView);
    }
    if (View.NO_ID != topLayoutId) {
        mTopView = inflater.inflate(topLayoutId, this, false);
        addView(mTopView);
    }
    if (View.NO_ID != rightLayoutId) {
        mRightView = inflater.inflate(rightLayoutId, this, false);
        addView(mRightView);
    }
    if (View.NO_ID != bottomLayoutId) {
        mBottomView = inflater.inflate(bottomLayoutId, this, false);
        addView(mBottomView);
    }
    enableSwipe = true;
}
 
Example 13
Project: GongXianSheng   File: FragmentTabHost.java   Source Code and License Vote up 6 votes
public void setup(Context context, FragmentManager manager, int containerId) {
    ensureHierarchy(context); // Ensure views required by super.setup()
    super.setup();
    mContext = context;
    mFragmentManager = manager;
    mContainerId = containerId;
    ensureContent();
    mRealTabContent.setId(containerId);

    // We must have an ID to be able to save/restore our state. If
    // the owner hasn't set one at this point, we will set it ourself.
    if (getId() == View.NO_ID) {
        setId(android.R.id.tabhost);
    }
}
 
Example 14
Project: CSipSimple   File: MenuItemImpl.java   Source Code and License Vote up 6 votes
public MenuItem setActionView(View view) {
    mActionView = view;
    mActionProvider = null;
    if (view != null && view.getId() == View.NO_ID && mId > 0) {
        view.setId(mId);
    }
    mMenu.onItemActionRequestChanged(this);
    return this;
}
 
Example 15
Project: Quran   File: FragmentStatePagerAdapter.java   Source Code and License Vote up 6 votes
@Override
public void startUpdate(ViewGroup container) {
  if (container.getId() == View.NO_ID) {
    throw new IllegalStateException("ViewPager with adapter " + this
        + " requires a view id");
  }
}
 
Example 16
Project: NestRadioGroup   File: NestRadioGroup.java   Source Code and License Vote up 5 votes
private void init() {
    mCheckedId = View.NO_ID;
    mChildOnCheckedChangeListener = new CheckedStateTracker();
    mPassThroughListener = new PassThroughHierarchyChangeListener();
    super.setOnHierarchyChangeListener(mPassThroughListener);
}
 
Example 17
Project: DroidTelescope   File: ViewUtils.java   Source Code and License Vote up 5 votes
/**
 * 获取View的签名
 *
 * @param view
 * @return
 */
public static String getViewSign(View view) {
    StringBuilder sign = new StringBuilder(128);
    sign.append(view.getClass().getName());
    sign.append('{');
    sign.append(Integer.toHexString(System.identityHashCode(view)));
    sign.append(' ');
    sign.append(view.getLeft());
    sign.append(',');
    sign.append(view.getTop());
    sign.append('-');
    sign.append(view.getRight());
    sign.append(',');
    sign.append(view.getBottom());
    final int id = view.getId();
    if (id != View.NO_ID) {
        sign.append(" #");
        sign.append(Integer.toHexString(id));
        final Resources r = view.getResources();
        if (id > 0 && resourceHasPackage(id) && r != null) {
            try {
                String pkgname;
                switch (id & 0xff000000) {
                    case 0x7f000000:
                        pkgname = "app";
                        break;
                    case 0x01000000:
                        pkgname = "android";
                        break;
                    default:
                        pkgname = r.getResourcePackageName(id);
                        break;
                }
                String typename = r.getResourceTypeName(id);
                String entryname = r.getResourceEntryName(id);
                sign.append(" ");
                sign.append(pkgname);
                sign.append(":");
                sign.append(typename);
                sign.append("/");
                sign.append(entryname);
                if ("android".equals(pkgname) && "id".equals(typename) && "content".equals(entryname)) {
                    //找到android:id/content的父View,认为是根View了,不再查找
                    isRootParent = true;
                }
            } catch (Resources.NotFoundException e) {
            }
        }
    }
    sign.append('}');
    return sign.toString();
}
 
Example 18
Project: TabPager   File: NavView.java   Source Code and License Vote up 5 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    // 动态配置ViewPager
    if (getChildCount() == 1) {
        // 如果有一个子控件,就尝试把它当作ViewPager
        View child = getChildAt(0);
        if (child instanceof ViewPager && child instanceof Pager) {
            vpContent = (ViewPager) child;
        } else {
            throw new IllegalStateException("NavView must has 0 or 1 child that implement 'Pager' interface and exptend 'ViewPager' class at same time.");
        }
    } else {
        // 否则默认创建
        vpContent = new TpgViewPager(getContext());
    }
    // 设置默认Id
    if (vpContent.getId() == View.NO_ID) {
        vpContent.setId(vpContent.hashCode());
    }

    //获取控件
    View view = LayoutInflater.from(getContext()).inflate(R.layout.widget_nav, this);
    vDivider = view.findViewById(R.id.v_divider);
    rgTabs = view.findViewById(R.id.rg_tabs);
    flContent = view.findViewById(R.id.fl_content);

    // 将ViewPager添加到界面
    if (null != vpContent) {
        ViewUtils.removeFromParent(vpContent);
        flContent.addView(vpContent);
    }

    setNavHeight((int) DensityUtils.px2dp(getContext(), mNavHeight));

    //设置整个导航栏的背景。如果同时设置了颜色和图片做背景,以图片为主
    rgTabs.setBackgroundColor(mNavBgColor);
    if (null != mNavBgImg) {
        rgTabs.setBackgroundDrawable(mNavBgImg);
    }

    if (mNavDividerLineColor == Color.TRANSPARENT) {
        //如果颜色透明,就隐藏分割线
        vDivider.setVisibility(View.GONE);
    } else {
        //否则就显示分割线,并设置相应颜色
        vDivider.setBackgroundColor(mNavDividerLineColor);
        vDivider.setVisibility(View.VISIBLE);
    }

    //设置是否可滑动
    setScrollAble(mScrollAble);
}
 
Example 19
Project: GitHub   File: CalligraphyFactory.java   Source Code and License Vote up 3 votes
/**
 * Use to match a view against a potential view id. Such as ActionBar title etc.
 *
 * @param view    not null view you want to see has resource matching name.
 * @param matches not null resource name to match against. Its not case sensitive.
 * @return true if matches false otherwise.
 */
protected static boolean matchesResourceIdName(View view, String matches) {
    if (view.getId() == View.NO_ID) return false;
    final String resourceEntryName = view.getResources().getResourceEntryName(view.getId());
    return resourceEntryName.equalsIgnoreCase(matches);
}
 
Example 20
Project: DownloadableCalligraphy   File: CalligraphyFactory.java   Source Code and License Vote up 3 votes
/**
 * Use to match a view against a potential view id. Such as ActionBar title etc.
 *
 * @param view    not null view you want to see has resource matching name.
 * @param matches not null resource name to match against. Its not case sensitive.
 * @return true if matches false otherwise.
 */
protected static boolean matchesResourceIdName(View view, String matches) {
    if (view.getId() == View.NO_ID) return false;
    final String resourceEntryName = view.getResources().getResourceEntryName(view.getId());
    return resourceEntryName.equalsIgnoreCase(matches);
}