Java Code Examples for android.widget.CheckedTextView#setCheckMarkDrawable()

The following examples show how to use android.widget.CheckedTextView#setCheckMarkDrawable() . 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: MDTintHelper.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull CheckedTextView textView, @ColorInt int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_checked},
            new int[]{android.R.attr.state_checked}
    }, new int[]{
            ThemeHelper.resolveColor(textView.getContext(), R.attr.colorControlNormal),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textView.setCheckMarkTintList(sl);
    } else {
        Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(textView.getContext(), R.drawable.abc_btn_radio_material));
        DrawableCompat.setTintList(d, sl);
        textView.setCheckMarkDrawable(d);
    }
}
 
Example 2
Source File: EmTintUtils.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull CheckedTextView textView, @ColorInt int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_checked},
            new int[]{android.R.attr.state_checked}
    }, new int[]{
            ThemeHelper.resolveColor(textView.getContext(), R.attr.colorControlNormal),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textView.setCheckMarkTintList(sl);
    } else {
        Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(textView.getContext(), R.drawable.abc_btn_check_material));
        DrawableCompat.setTintList(d, sl);
        textView.setCheckMarkDrawable(d);
    }
}
 
Example 3
Source File: ImageListPreference.java    From Identiconizer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
    View row = inflater.inflate(R.layout.image_list_item, parent, false);

    ImageView imageView = row.findViewById(R.id.image);
    imageView.setImageResource(resourceIds[position]);

    CheckedTextView checkedTextView = row.findViewById(R.id.check);

    checkedTextView.setText(getItem(position));
    checkedTextView.setCheckMarkDrawable(Resources.getSystem().getDrawable(mRadioDrawableId));

    if (position == index) {
        checkedTextView.setChecked(true);
    }

    return row;
}
 
Example 4
Source File: AppEditActivity.java    From smartcard-reader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final View itemView = super.getView(position, convertView, parent);
    if (itemView == null) {
        return null;
    }
    final CheckedTextView checkedTextView = (CheckedTextView)itemView;

    if (hasCheckbox(position)) {
        checkedTextView.setEnabled(isEnabled(position));
    } else {
        checkedTextView.setCheckMarkDrawable(null);
        checkedTextView.setTextColor(getResources().getColor(R.color.accent));
    }
    return checkedTextView;
}
 
Example 5
Source File: SelectPopupAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (position < 0 || position >= getCount()) return null;

    convertView = super.getView(position, convertView, parent);
    ((TextView) convertView).setText(mItems.get(position).getLabel());

    // Currently select_dialog_(single|multi)choice uses CheckedTextViews.
    // If that changes, the class cast will no longer be valid.
    // The WebView build cannot rely on this being the case, so
    // we must check.
    if (convertView instanceof CheckedTextView) {
        // <optgroup> elements do not have check marks. If an item previously used as an
        // <optgroup> gets reused for a non-<optgroup> element, we need to get the check mark
        // back. Inflating a new View from XML can be slow, for both the inflation part and GC
        // afterwards. Even creating a new Drawable can be tricky, considering getting the
        // check/radio type and theme right.
        // Saving the previously removed Drawables and reuse them when needed is faster,
        // and the memory implication should be fine.
        CheckedTextView view = (CheckedTextView) convertView;
        if (mItems.get(position).getType() == PopupItemType.GROUP) {
            if (view.getCheckMarkDrawable() != null) {
                view.setTag(view.getCheckMarkDrawable());
                view.setCheckMarkDrawable(null);
            }
        } else {
            if (view.getCheckMarkDrawable() == null) {
                view.setCheckMarkDrawable((Drawable) view.getTag());
            }
        }
    }
    // Draw the disabled element in a disabled state.
    convertView.setEnabled(mItems.get(position).getType() != PopupItemType.DISABLED);

    return convertView;
}
 
Example 6
Source File: PXVirtualCheckedTextViewIconAdapter.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean updateStyle(List<PXRuleSet> ruleSets, List<PXStylerContext> contexts) {
    if (!super.updateStyle(ruleSets, contexts)) {
        return false;
    }
    // Style the check mark. We will construct the
    // drawable from the context states, and then set the constructed
    // drawable as the check mark using the
    // CheckedTextView#setCheckMarkDrawable call. Note that this is
    // different than the View#setBackground(Drawable) call that is handled
    // in the default View adapter.

    CheckedTextView view = (CheckedTextView) contexts.get(0).getStyleable();
    Drawable currentDrawable = getCheckMarkDrawable(view);

    Map<int[], Drawable> existingStates = PXDrawableUtil.getExistingStates(currentDrawable);

    Drawable newDrawable = null;

    if (MapUtil.isEmpty(existingStates)) {
        // create a new StateListDrawable for the icon,
        // using the checked text view's adapter
        // as the source of possible drawable states.
        if (contexts.size() == 1) {
            newDrawable = contexts.get(0).getBackgroundImage();
        } else {
            newDrawable = PXDrawableUtil.createNewStateListDrawable(
                    PXStyleAdapter.getStyleAdapter(view), ruleSets, contexts);
        }
    } else {
        // create a drawable that will hold a merge of the existing states
        // and the new states. Use the checked text view's
        // adapter as the source of possible drawable states.
        newDrawable = PXDrawableUtil.createDrawable(PXStyleAdapter.getStyleAdapter(view),
                existingStates, ruleSets, contexts);
    }

    view.setCheckMarkDrawable(newDrawable);
    return true;
}