Search in sources :

Example 1 with DropDownMenu

use of carbon.internal.DropDownMenu in project Carbon by ZieIony.

the class DropDown method initSpinner.

private void initSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
    VectorDrawable drawable = new VectorDrawable(getResources(), R.raw.carbon_dropdown);
    int size = (int) (Carbon.getDip(getContext()) * 24);
    drawable.setBounds(0, 0, size, size);
    setCompoundDrawables(null, null, drawable, null);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DropDown, defStyleAttr, R.style.carbon_DropDown);
    int theme = a.getResourceId(R.styleable.DropDown_carbon_popupTheme, -1);
    defaultAdapter = new Adapter();
    dropDownMenu = new DropDownMenu(new ContextThemeWrapper(context, theme));
    dropDownMenu.setAdapter(defaultAdapter);
    dropDownMenu.setOnItemClickedListener(onItemClickedListener);
    dropDownMenu.setOnDismissListener(() -> isShowingPopup = false);
    dropDownMenu.setMode(Mode.values()[a.getInt(R.styleable.DropDown_carbon_mode, Mode.Over.ordinal())]);
    setOnClickListener(view -> {
        dropDownMenu.show(DropDown.this);
        isShowingPopup = true;
    });
    a.recycle();
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray) DropDownMenu(carbon.internal.DropDownMenu) ArrayAdapter(carbon.recycler.ArrayAdapter) VectorDrawable(carbon.drawable.VectorDrawable)

Example 2 with DropDownMenu

use of carbon.internal.DropDownMenu in project Carbon by ZieIony.

the class DropDown method initDropDown.

private void initDropDown(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DropDown, defStyleAttr, defStyleRes);
    int theme = a.getResourceId(R.styleable.DropDown_carbon_popupTheme, -1);
    dropDownMenu = new DropDownMenu(new ContextThemeWrapper(getContext(), theme));
    dropDownMenu.setOnDismissListener(() -> isShowingPopup = false);
    dropDownMenu.setPopupMode(PopupMode.values()[a.getInt(R.styleable.DropDown_carbon_popupMode, PopupMode.Over.ordinal())]);
    setMode(Mode.values()[a.getInt(R.styleable.DropDown_carbon_mode, Mode.SingleSelect.ordinal())]);
    dropDownMenu.setOnItemClickedListener(onItemClickedListener);
    setButtonDrawable(Carbon.getDrawable(this, a, R.styleable.DropDown_android_button, R.drawable.carbon_dropdown));
    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.DropDown_android_drawablePadding) {
            drawablePadding = a.getDimension(attr, 0);
        } else if (attr == R.styleable.DropDown_carbon_buttonGravity) {
            buttonGravity = ButtonGravity.values()[a.getInt(attr, 0)];
        }
    }
    a.recycle();
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray) DropDownMenu(carbon.internal.DropDownMenu) SuppressLint(android.annotation.SuppressLint)

Aggregations

TypedArray (android.content.res.TypedArray)2 ContextThemeWrapper (android.view.ContextThemeWrapper)2 DropDownMenu (carbon.internal.DropDownMenu)2 SuppressLint (android.annotation.SuppressLint)1 VectorDrawable (carbon.drawable.VectorDrawable)1 ArrayAdapter (carbon.recycler.ArrayAdapter)1