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

The following examples show how to use android.view.View#setId() . 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: ToolButtonGroup.java    From kolabnotes-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void onChildViewAdded(View parent, View child) {
    if (parent == ToolButtonGroup.this && child instanceof ToolButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = generateViewId();
            child.setId(id);
        }
        ((ToolButton) child).setOnCheckedChangeListener(
                mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 2
Source File: CheckGroup.java    From sealrtc-android with MIT License 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 3
Source File: RadioGridGroup.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onChildViewAdded(View parent, View child) {
    if (parent == RadioGridGroup.this && child instanceof RadioButton) {
        int id = child.getId();
        // generates an id if it's missing
        if (id == View.NO_ID) {
            id = ViewUtils.generateViewId();
            child.setId(id);
        }
        ((RadioButton) child).setOnCheckedChangeListener(
                mChildOnCheckedChangeListener);
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 4
Source File: KlyphFragment2.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
	// Log.d("KlyphFragment2", "onCreateView");
	View view = inflater.inflate(getCustomLayout(), container, false);

	gridView = (KlyphGridView) view.findViewById(R.id.grid);
	
	View emptyView = getEmptyView();
	
	if (emptyView != null)
	{
		emptyView.setId(android.R.id.empty);
		
		((ViewGroup) gridView.getParent()).addView(emptyView);
		
		gridView.setEmptyView(emptyView);
	}
	
	// Now set the ScrollView as the refreshable view, and the refresh listener (this)
	if (requestNewestType != Query.NONE)
		attachViewToPullToRefresh();

	return view;
}
 
Example 5
Source File: GridFragment.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
	View view = inflater.inflate(getCustomLayout(), container, false);

	gridView = (GridView) view.findViewById(R.id.grid);

	View emptyView = getEmptyView();

	if (emptyView != null)
	{
		emptyView.setId(android.R.id.empty);

		((ViewGroup) gridView.getParent()).addView(emptyView);

		gridView.setEmptyView(emptyView);
	}

	return view;
}
 
Example 6
Source File: LinearScrollView.java    From Tangram-Android with MIT License 6 votes vote down vote up
private void bindFooterView(BaseCell cell) {
    if (cell != null && cell.isValid()) {
        View footer = getViewFromRecycler(cell);
        if (footer != null) {
            footer.setId(R.id.TANGRAM_BANNER_FOOTER_ID);
            //为了解决在 item 复用过程中,itemView 的 layoutParams 复用造成 layout 错误,这里要提供一个新的 layoutParams。
            LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.topMargin = cell.style.margin[Style.MARGIN_TOP_INDEX];
            lp.leftMargin = cell.style.margin[Style.MARGIN_LEFT_INDEX];
            lp.bottomMargin = cell.style.margin[Style.MARGIN_BOTTOM_INDEX];
            lp.rightMargin = cell.style.margin[Style.MARGIN_RIGHT_INDEX];
            addView(footer, lp);
        }
    }
}
 
Example 7
Source File: ToggleGroup.java    From ToggleButtons with 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 8
Source File: ZoomHoverGridView.java    From CustomViewSets with Apache License 2.0 6 votes vote down vote up
/**
 * 计算子view的个数并添加到list中
 */
private void calculateChild() {
    mViewList.clear();
    mItemList.clear();

    for (int i = 0; i < mZoomHoverAdapter.getCount(); i++) {
        View childView = mZoomHoverAdapter.getView(this, i, mZoomHoverAdapter.getItem(i));
        //添加view到mViewList
        mViewList.add(childView);
        childView.setId(i + 1);
        if (mSpanMap.containsKey(i)) {
            int tempRowSpan = mSpanMap.get(i).getRowSpan();
            int tempColumnSpan = mSpanMap.get(i).getColumnSpan();
            tempRowSpan = tempRowSpan >= 1 ? tempRowSpan : 1;
            tempColumnSpan = tempColumnSpan >= 1 ? tempColumnSpan : 1;
            if (tempColumnSpan > mColumnNum) {
                tempColumnSpan = mColumnNum;
            }
            //添加item到mItemList
            mItemList.add(new ZoomHoverItem(tempRowSpan, tempColumnSpan));
        } else {
            //添加item到mItemList
            mItemList.add(new ZoomHoverItem(1, 1));
        }
    }
}
 
Example 9
Source File: CustomWebSocketListener.java    From WebRTCapp with Apache License 2.0 6 votes vote down vote up
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: ToggleButtonGroup.java    From ToggleButtonGroup with Apache License 2.0 6 votes vote down vote up
public void onChildViewAdded(View parent, View child) {
    if (parent == ToggleButtonGroup.this && child instanceof Checkable) {
        if (child.getId() == View.NO_ID) {
            child.setId(generateIdForView(child));
        }
        if (child instanceof ToggleButton) {
            setStateTracker((ToggleButton) child);
        } else if (child instanceof CompoundButton) {
            setStateTracker((CompoundButton) child);
        }
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example 11
Source File: EmoticonsToolBarView.java    From ChatKeyboard-master with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void addFixedView(View view, boolean isRight) {
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    LayoutParams hsvParams = (LayoutParams) hsv_toolbar.getLayoutParams();
    if (view.getId() <= 0) {
        view.setId(getIdValue());
    }
    if (isRight) {
        params.addRule(ALIGN_PARENT_RIGHT);
        hsvParams.addRule(LEFT_OF, view.getId());
    } else {
        params.addRule(ALIGN_PARENT_LEFT);
        hsvParams.addRule(RIGHT_OF, view.getId());
    }
    addView(view, params);
    hsv_toolbar.setLayoutParams(hsvParams);
}
 
Example 12
Source File: OpenTabTitleAdapter.java    From Android-tv-widget with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	parent.getContext();
	String title = titleList.get(position);
	if (convertView == null) {
		convertView = newTabIndicator(parent.getContext(), title, false);
		convertView.setId(ids.get(position)); // 设置ID.
	} else {
		// ... ...
	}
	return convertView;
}
 
Example 13
Source File: ViewMatchersTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void withIdTest() {
  View view = new View(context);
  view.setId(R.id.testId1);
  assertTrue(withId(is(R.id.testId1)).matches(view));
  assertFalse(withId(is(R.id.testId2)).matches(view));
  assertFalse(withId(is(1234)).matches(view));
}
 
Example 14
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 创建半透明矩形 View
 *
 * @param alpha 透明值
 * @return 半透明 View
 */
private static View createTranslucentStatusBarView(Activity activity, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    View statusBarView = new View(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
    statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID);
    return statusBarView;
}
 
Example 15
Source File: StatusBarUtil.java    From MNProgressHUD with Apache License 2.0 5 votes vote down vote up
/**
 * 生成一个和状态栏大小相同的半透明矩形条
 *
 * @param activity 需要设置的activity
 * @param color    状态栏颜色值
 * @param alpha    透明值
 * @return 状态栏矩形条
 */
private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    View statusBarView = new View(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
    statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
    return statusBarView;
}
 
Example 16
Source File: InputLayout.java    From Carbon with Apache License 2.0 4 votes vote down vote up
private void setInputChild(View child) {
    this.child = child;
    if (child.isDuplicateParentStateEnabled())
        container.setDuplicateParentStateEnabled(true);
    if (child instanceof ViewGroup && ((ViewGroup) child).addStatesFromChildren())
        container.setAddStatesFromChildren(true);

    if (child.getId() == NO_ID)
        child.setId(R.id.carbon_input);

    if (child instanceof EditText) {
        final EditText editText = (EditText) child;
        if (labelTextView.getText().length() == 0)
            setLabel(editText.getHint());
        editText.addOnValidChangedListener(valid -> {
            updateError(valid);
            updateCounter(editText);
        });
        showPasswordImageView.setOnTouchListener((view, motionEvent) -> {
            int selectionStart = editText.getSelectionStart();
            int selectionEnd = editText.getSelectionEnd();
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                transformationMethod = editText.getTransformationMethod();
                editText.setTransformationMethod(null);
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                editText.setTransformationMethod(transformationMethod);
            }
            editText.setSelection(selectionStart, selectionEnd);
            return false;
        });
        clearImageView.setOnClickListener(view -> editText.setText(""));

        labelTextView.setInAnimator(null);
        labelTextView.setOutAnimator(null);
        setLabel(label);
        errorTextView.setInAnimator(null);
        errorTextView.setOutAnimator(null);
        updateError(editText.isValid());
        updateHint(editText);
        updateCounter(editText);
        labelTextView.setInAnimator(AnimUtils.getFlyInAnimator());
        labelTextView.setOutAnimator(AnimUtils.getFadeOutAnimator());
        errorTextView.setInAnimator(AnimUtils.getFadeInAnimator());
        errorTextView.setOutAnimator(AnimUtils.getFadeOutAnimator());
    } else if (child instanceof InputView) {
        InputView inputView = (InputView) child;
        inputView.addOnValidChangedListener(this::updateError);

        labelTextView.setInAnimator(null);
        labelTextView.setOutAnimator(null);
        errorTextView.setInAnimator(null);
        errorTextView.setOutAnimator(null);
        updateError(inputView.isValid());
        updateHint(child);
        labelTextView.setInAnimator(AnimUtils.getFlyInAnimator());
        labelTextView.setOutAnimator(AnimUtils.getFadeOutAnimator());
        errorTextView.setInAnimator(AnimUtils.getFadeInAnimator());
        errorTextView.setOutAnimator(AnimUtils.getFadeOutAnimator());
    }

    if (actionButton != ActionButton.None) {
        int buttonPadding = getResources().getDimensionPixelSize(R.dimen.carbon_padding) + getResources().getDimensionPixelSize(R.dimen.carbon_iconSize);
        child.setPadding(child.getPaddingLeft(), child.getPaddingTop(), child.getPaddingRight() + buttonPadding, child.getPaddingBottom());
    }
}
 
Example 17
Source File: ReuseGroupSceneTests.java    From scene with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.setId(mId);
}
 
Example 18
Source File: SettingsObject.java    From EasySettings with 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 19
Source File: CommonViewController.java    From Carpaccio with Apache License 2.0 4 votes vote down vote up
public <T extends View> T replaceViewithTagToRemove(View view, String viewIdentifier, String tagToRemove) {
    Context context = view.getContext();
    View newView = null;
    if (viewIdentifier.startsWith("R.layout.") || !viewIdentifier.contains("."))
        newView = replaceByLayout(context, view, viewIdentifier);
    else
        newView = replaceByViewClass(context, view, viewIdentifier);

    if (newView != null) {
        ViewGroup parent = (ViewGroup) view.getParent();

        newView.setLayoutParams(view.getLayoutParams());
        newView.setId(view.getId());

        newView.setTag(CarpaccioHelper.removeTag(view, tagToRemove));

        if (view.getBackground() != null)
            newView.setBackgroundDrawable(view.getBackground());

        if (view instanceof ImageView && newView instanceof ImageView) {
            ImageView imgView = (ImageView) view;
            ImageView imgNewView = (ImageView) newView;

            if (imgView.getDrawable() != null)
                imgNewView.setImageDrawable(imgView.getDrawable());
        }

        if (view instanceof TextView && newView instanceof TextView) {
            TextView txtView = (TextView) view;
            TextView txtNewView = (TextView) newView;

            if (txtView.getText() != null)
                txtNewView.setText(txtView.getText());
            if (txtView.getHint() != null)
                txtNewView.setHint(txtView.getText());
        }

        int index = parent.indexOfChild(view);
        parent.addView(newView, index);
        parent.removeView(view);
    }

    Carpaccio carpaccio = CarpaccioHelper.registerToParentCarpaccio(newView);
    if(carpaccio != null){
        carpaccio.getCarpaccioManager().executeActionsOnView(newView);
    }


    return (T) newView;
}
 
Example 20
Source File: ViewHolderState.java    From epoxy with Apache License 2.0 2 votes vote down vote up
/**
 * If a view hasn't had an id set we need to set a temporary one in order to save state, since a
 * view won't save its state unless it has an id. The view's id is also the key into the sparse
 * array for its saved state, so the temporary one we choose just needs to be consistent between
 * saving and restoring state.
 */
private void setIdIfNoneExists(View view) {
  if (view.getId() == View.NO_ID) {
    view.setId(R.id.view_model_state_saving_id);
  }
}