Java Code Examples for android.widget.Button#setCompoundDrawablesWithIntrinsicBounds()

The following examples show how to use android.widget.Button#setCompoundDrawablesWithIntrinsicBounds() . 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: EmTintUtils.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull Button button, @ColorInt int color) {
    ColorStateList s1 = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        button.setCompoundDrawableTintList(s1);
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        Drawable drawable = DrawableCompat.wrap(button.getCompoundDrawables()[1]);
        button.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        DrawableCompat.setTintList(drawable, s1);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (button.getCompoundDrawables()[1] != null)
            button.getCompoundDrawables()[1].setColorFilter(color, mode);
    }
}
 
Example 2
Source File: L5Dark.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {
    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(
            R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    button.setTextColor(Color.WHITE);
    if (icon != null) {
        icon.mutate().setColorFilter(getColorFilter(Color.WHITE));
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 3
Source File: HoloDark.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {

    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(
            R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    button.setTextColor(Color.WHITE);
    if (icon != null) {
        icon.mutate().setColorFilter(getColorFilter(Color.WHITE));
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 4
Source File: L5Light.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {
    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(
            R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    button.setTextColor(Color.BLACK);
    //Typeface typeface = Typeface.createFromAsset(actionButtons.getContext().getAssets(), "RobotoCondensed-Regular.ttf");
    //button.setTypeface(typeface);
    if (icon != null) {
        icon.mutate().setColorFilter(getColorFilter(Color.DKGRAY));
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 5
Source File: HoloLight.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {

    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(
            R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    button.setTextColor(Color.DKGRAY);
    if (icon != null) {
        icon.mutate().setColorFilter(Color.BLACK, PorterDuff.Mode.MULTIPLY);
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 6
Source File: Ubuntu.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {
    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(
            R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    button.setTextColor(Color.WHITE);
    if (icon != null) {
        icon.mutate().setColorFilter(getColorFilter(Color.WHITE));
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 7
Source File: PaneledChoiceDialog.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public static void populateChoicePanel(Context context, Button choicePanel,
                                       DialogChoiceItem item, boolean iconToLeft) {
    choicePanel.setText(item.text);
    if (item.listener != null) {
        choicePanel.setOnClickListener(item.listener);
    } else {
        // needed to propagate clicks down to the ListView's ItemClickListener
        choicePanel.setFocusable(false);
        choicePanel.setClickable(false);
    }
    if (item.iconResId != -1) {
        Drawable icon = ContextCompat.getDrawable(context, item.iconResId);
        if (iconToLeft) {
            if (LocalePreferences.isLocaleRTL())
                choicePanel.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
            else
                choicePanel.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
        } else {
            choicePanel.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
        }
    }
}
 
Example 8
Source File: DictionariesFragment.java    From aard2-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = super.onCreateView(inflater, container, savedInstanceState);
    View extraEmptyView = inflater.inflate(R.layout.dictionaries_empty_view_extra, container, false);
    Button btn = (Button)extraEmptyView.findViewById(R.id.dictionaries_empty_btn_scan);
    btn.setCompoundDrawablesWithIntrinsicBounds(
            IconMaker.list(getActivity(), IconMaker.IC_RELOAD),
            null, null, null);
    btn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            findDictionaries();
        }
    });
    LinearLayout emptyViewLayout = (LinearLayout)emptyView;
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    );
    emptyViewLayout.addView(extraEmptyView, layoutParams);
    return result;
}
 
Example 9
Source File: MainFragmentNew.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    Option option = getItem(position);

    if(convertView == null)
    {
        convertView = ((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_main_option_button_item, parent, false);
    }
    Button btn = (Button)convertView;

    btn.setCompoundDrawablesWithIntrinsicBounds(option.iconRes, 0, 0, 0);
    btn.setText(option.textRes);

    return convertView;
}
 
Example 10
Source File: ThemeClass.java    From heads-up with GNU General Public License v3.0 5 votes vote down vote up
/**
 Add an action button to the layout.
 */
public void addActionButton(ViewGroup actionButtons, String actionTitle, Drawable icon, View.OnClickListener clickListener, float fontMultiplier) {
    LayoutInflater inflater = LayoutInflater.from(actionButtons.getContext());
    ViewGroup v = (ViewGroup) inflater.inflate(R.layout.button_notification, actionButtons);

    Button button = (Button) v.getChildAt(v.getChildCount() - 1);
    button.setText(actionTitle);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontMultiplier * button.getTextSize());
    if (icon != null) {
        icon.mutate().setColorFilter(getColorFilter(Color.BLACK));
        button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    }
    button.setOnClickListener(clickListener);
}
 
Example 11
Source File: ButtonMenu.java    From ButtonMenu with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.CUPCAKE)
private void renderImageResource(View view, int viewResourceToChange, int imageResourceId) {
	Button button = (Button) view.findViewById(viewResourceToChange);
	if (button != null) {
		button.setCompoundDrawablesWithIntrinsicBounds(0, imageResourceId, 0, 0);
	}
}
 
Example 12
Source File: ProjectAdapter.java    From microbit with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Project project = mProjects.get(position);
    if(convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
        convertView = inflater.inflate(R.layout.project_items, null);
    }

    Button appNameButton = (Button) convertView.findViewById(R.id.appNameButton);
    appNameButton.setTypeface(MBApp.getApp().getRobotoTypeface());

    ExtendedEditText appNameEdit = (ExtendedEditText) convertView.findViewById(R.id.appNameEdit);
    appNameEdit.setTypeface(MBApp.getApp().getRobotoTypeface());

    LinearLayout actionBarLayout = (LinearLayout) convertView.findViewById(R.id.actionBarForProgram);
    if(actionBarLayout != null) {
        if(project.actionBarExpanded) {
            actionBarLayout.setVisibility(View.VISIBLE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_down), null);
        } else {
            actionBarLayout.setVisibility(View.GONE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_left), null);
        }
    }

    appNameButton.setText(project.name);
    appNameButton.setTag(R.id.positionId, position);
    appNameButton.setTag(R.id.textEdit, appNameEdit);
    appNameButton.setOnClickListener(appNameClickListener);
    appNameButton.setOnLongClickListener(appNameLongClickListener);

    appNameEdit.setTag(R.id.positionId, position);
    appNameEdit.setTag(R.id.editbutton, appNameButton);
    appNameEdit.setOnEditorActionListener(editorOnActionListener);
    appNameEdit.setFilters(new InputFilter[]{renameFilter});

    if(project.inEditMode) {
        appNameEdit.setVisibility(View.VISIBLE);

        appNameEdit.setText(project.name);
        appNameEdit.setSelection(project.name.length());
        appNameEdit.requestFocus();
        appNameButton.setVisibility(View.INVISIBLE);

    } else {
        appNameEdit.setVisibility(View.INVISIBLE);
        appNameButton.setVisibility(View.VISIBLE);
        //dismissKeyBoard(appNameEdit, false);
    }

    //appNameEdit.setOnClickListener(appNameClickListener);

    TextView flashBtnText = (TextView) convertView.findViewById(R.id.project_item_text);
    flashBtnText.setTypeface(MBApp.getApp().getRobotoTypeface());
    LinearLayout sendBtnLayout = (LinearLayout) convertView.findViewById(R.id.sendBtn);
    sendBtnLayout.setTag(position);
    sendBtnLayout.setOnClickListener(sendBtnClickListener);

    ImageButton deleteBtn = (ImageButton) convertView.findViewById(R.id.deleteBtn);
    deleteBtn.setTag(position);
    deleteBtn.setOnClickListener(deleteBtnClickListener);
    deleteBtn.setEnabled(true);


    Drawable myIcon;
    if(project.runStatus) {
        flashBtnText.setText("");
        myIcon = convertView.getResources().getDrawable(R.drawable.green_btn);
    } else {
        flashBtnText.setText(R.string.flash);
        myIcon = convertView.getResources().getDrawable(R.drawable.blue_btn);
    }
    sendBtnLayout.setBackground(myIcon);

    sendBtnLayout.setClickable(true);
    return convertView;
}
 
Example 13
Source File: HomeActivity.java    From LoveTalkClient with Apache License 2.0 4 votes vote down vote up
private void setTopDrawable(Button v, int resId) {
	v.setCompoundDrawablesWithIntrinsicBounds(null, mContext.getResources().getDrawable(resId), null, null);
}
 
Example 14
Source File: EntitySelectActivity.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private void displayReferenceAwesome(final TreeReference selection, int detailIndex) {
    selectedIntent = EntityDetailUtils.getDetailIntent(getApplicationContext(),
            selection, getIntent(), selectDatum, asw);
    //this should be 100% "fragment" able
    if (!rightFrameSetup) {
        findViewById(R.id.screen_compound_select_prompt).setVisibility(View.GONE);
        View.inflate(this, R.layout.entity_detail, rightFrame);
        Button next = findViewById(R.id.entity_select_button);
        //use the old method here because some Android versions don't like Spannables for titles
        next.setText(Localization.get("select.detail.confirm"));
        next.setOnClickListener(v -> performEntitySelect());

        if (mViewMode) {
            next.setVisibility(View.GONE);
            next.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }

        String passedCommand = selectedIntent.getStringExtra(SessionFrame.STATE_COMMAND_ID);

        if (passedCommand != null) {
            mViewMode = session.isViewCommand(passedCommand);
        } else {
            mViewMode = session.isViewCommand(session.getCommand());
        }

        detailView = rightFrame.findViewById(R.id.entity_detail_tabs);
        detailView.setRoot(detailView);

        Detail detail = session.getDetail(selectedIntent.getStringExtra(EntityDetailActivity.DETAIL_ID));
        factory = new NodeEntityFactory(detail, session.getEvaluationContext(new AndroidInstanceInitializer(session)));
        detailView.showMenu();

        if (detail.isCompound()) {
            // border around right panel doesn't look right when there are tabs
            rightFrame.setBackgroundDrawable(null);
        }

        rightFrameSetup = true;
    }

    detailView.refresh(factory.getDetail(), selection, detailIndex);
}
 
Example 15
Source File: EventResponseAdapter.java    From Klyph with MIT License 4 votes vote down vote up
private void setButtonDrawable(Button button, int drawableAttr)
{
	button.setCompoundDrawablesWithIntrinsicBounds(AttrUtil.getDrawable(getContext(button), drawableAttr), null, null,
			null);
}