Example usage for android.graphics.drawable Drawable setColorFilter

List of usage examples for android.graphics.drawable Drawable setColorFilter

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setColorFilter.

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:in.andres.kandroid.ui.TaskEditActivity.java

private void setButtonColor() {
    if (kanboardColors == null || defaultColor == null)
        return;//from  ww w . java 2 s.co m

    btnColor.setEnabled(true);

    Drawable dot = ResourcesCompat.getDrawable(getResources(), R.drawable.shape_circle, null);
    if (colorId != null) {
        dot.setColorFilter(kanboardColors.get(colorId).getBackground(), PorterDuff.Mode.MULTIPLY);
        btnColor.setText(
                Utils.fromHtml(getString(R.string.taskedit_color, kanboardColors.get(colorId).getName())));
    } else {
        dot.setColorFilter(kanboardColors.get(defaultColor).getBackground(), PorterDuff.Mode.MULTIPLY);
        btnColor.setText(
                Utils.fromHtml(getString(R.string.taskedit_color, kanboardColors.get(defaultColor).getName())));
    }
    btnColor.setCompoundDrawablesRelativeWithIntrinsicBounds(dot, null, null, null);
}

From source file:org.onebusaway.android.ui.TripResultsFragment.java

private void setTabDrawable(TabLayout.Tab tab, @DrawableRes int res) {
    View view = tab.getCustomView();
    TextView tv = ((TextView) view.findViewById(android.R.id.text1));

    Drawable drawable = getResources().getDrawable(res);

    int dp = (int) getResources().getDimension(R.dimen.trip_results_icon_size);
    drawable.setBounds(0, 0, dp, dp);/*w ww.j av  a  2s  . c o m*/

    drawable.setColorFilter(getResources().getColor(R.color.trip_option_icon_tint), PorterDuff.Mode.SRC_IN);

    tv.setCompoundDrawables(drawable, null, null, null);
}

From source file:com.irccloud.android.activity.EditConnectionActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_connection);

    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(R.layout.actionbar_edit_connection);
    getSupportActionBar().setElevation(0);

    TextView t = findViewById(R.id.action_cancel);
    Drawable d;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        d = VectorDrawableCompat.create(getResources(), R.drawable.ic_action_cancel, null).mutate();
    else//ww  w.j  a  va2  s  . c  o  m
        d = getResources().getDrawable(R.drawable.ic_action_cancel, null).mutate();
    d.setColorFilter(ColorScheme.getInstance().navBarHeadingColor, PorterDuff.Mode.SRC_ATOP);
    t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);

    t = findViewById(R.id.action_done);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        d = VectorDrawableCompat.create(getResources(), R.drawable.ic_action_save, null).mutate();
    else
        d = getResources().getDrawable(R.drawable.ic_action_save, null).mutate();
    d.setColorFilter(ColorScheme.getInstance().navBarHeadingColor, PorterDuff.Mode.SRC_ATOP);
    t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    final EditConnectionFragment newFragment = new EditConnectionFragment();
    if (getIntent() != null && getIntent().hasExtra("cid")) {
        newFragment.setCid(getIntent().getIntExtra("cid", -1));
        cid = getIntent().getIntExtra("cid", -1);
    }
    if (getIntent() != null && getIntent().hasExtra("hostname"))
        newFragment.default_hostname = getIntent().getStringExtra("hostname");
    if (getIntent() != null && getIntent().hasExtra("channels"))
        newFragment.default_channels = getIntent().getStringExtra("channels");
    newFragment.default_port = getIntent().getIntExtra("port", 6667);
    ft.replace(R.id.EditConnectionFragment, newFragment);
    ft.commit();

    getSupportActionBar().getCustomView().findViewById(R.id.action_cancel)
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (ServersList.getInstance().count() < 1) {
                        NetworkConnection.getInstance().logout();
                        Intent i = new Intent(EditConnectionActivity.this, LoginActivity.class);
                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(i);
                    }
                    finish();
                }

            });

    getSupportActionBar().getCustomView().findViewById(R.id.action_done)
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    reqid = newFragment.save();
                }

            });

    NetworkConnection.getInstance().addHandler(this);
}

From source file:com.xbm.android.matisse.ui.MatisseActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    // programmatically set theme before super.onCreate()
    mSpec = SelectionSpec.getInstance();
    setTheme(mSpec.themeId);/*from  w  w  w  .  j ava 2s. co  m*/
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_matisse);

    if (mSpec.needOrientationRestriction()) {
        setRequestedOrientation(mSpec.orientation);
    }

    if (mSpec.capture) {
        mMediaStoreCompat = new MediaStoreCompat(this);
        if (mSpec.captureStrategy == null)
            throw new RuntimeException("Don't forget to set CaptureStrategy.");
        mMediaStoreCompat.setCaptureStrategy(mSpec.captureStrategy);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    Drawable navigationIcon = toolbar.getNavigationIcon();
    TypedArray ta = getTheme().obtainStyledAttributes(new int[] { R.attr.album_element_color });
    int color = ta.getColor(0, 0);
    ta.recycle();
    navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN);

    mButtonPreview = (TextView) findViewById(R.id.button_preview);
    mButtonApply = (TextView) findViewById(R.id.button_apply);
    mButtonPreview.setOnClickListener(this);
    mButtonApply.setOnClickListener(this);
    mContainer = findViewById(R.id.container);
    mEmptyView = findViewById(R.id.empty_view);

    mSelectedCollection.onCreate(savedInstanceState);
    updateBottomToolbar();

    mAlbumsAdapter = new AlbumsAdapter(this, null, false);
    mAlbumsSpinner = new AlbumsSpinner(this);
    mAlbumsSpinner.setOnItemSelectedListener(this);
    mAlbumsSpinner.setSelectedTextView((TextView) findViewById(R.id.selected_album));
    mAlbumsSpinner.setPopupAnchorView(findViewById(R.id.toolbar));
    mAlbumsSpinner.setAdapter(mAlbumsAdapter);
    mAlbumCollection.onCreate(this, this);
    mAlbumCollection.onRestoreInstanceState(savedInstanceState);
    mAlbumCollection.loadAlbums();
}

From source file:org.gnucash.android.ui.chart.PieChartActivity.java

/**
 * Sets the image button to the given state and grays-out the icon
 *
 * @param enabled the button's state/*  w w w  . jav a2s.  c  om*/
 * @param button the button item to modify
 */
private void setImageButtonEnabled(ImageButton button, boolean enabled) {
    button.setEnabled(enabled);
    Drawable originalIcon = button.getDrawable();
    if (enabled) {
        originalIcon.clearColorFilter();
    } else {
        originalIcon.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    }
    button.setImageDrawable(originalIcon);
}

From source file:com.mercandalli.android.apps.files.file.local.FileLocalPagerFragment.java

private void syncTabLayout() {
    final int position = mViewPager.getCurrentItem();
    mSetToolbarCallback.setTitleToolbar(getTitleRes(position));
    for (int i = 0; i < getCount(); i++) {
        final TabLayout.Tab tab = mTabLayout.getTabAt(i);
        if (tab != null) {
            tab.setIcon(getImageRes(i));
            final Drawable drawable = tab.getIcon();
            if (drawable != null) {
                drawable.setColorFilter(i == position ? Color.WHITE : Color.parseColor("#85455A64"),
                        PorterDuff.Mode.SRC_ATOP);
            }// w  w w.j a va 2  s  .c om
        }
    }
}

From source file:com.agenmate.lollipop.addedit.AddEditFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        getActivity().onBackPressed();//from w w  w.j  a va2  s .co  m
        return true;
    case R.id.action_save:
        String title = emptyStringChecker(titleEdit.getText().toString());
        if (title == null) {
            Snackbar.make(background, "Title can't be Empty", Snackbar.LENGTH_LONG).show();
            return true;
        }
        String description = emptyStringChecker(descEdit.getText().toString());
        int priority = getPriority();

        long dueAt = getDueDate();
        if (dueAt < 0) {
            Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG)
                    .show();
            return true;
        }

        presenter.saveTask(title, description, priority, selectedColor, dueAt, hasAlarm, isCompleted);

        return true;
    case R.id.action_alarm:
        if (!hasAlarm) {
            if (getDueDate() < 0) {
                Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG)
                        .show();
                return true;
            }
        }
        boolean setWhite = selectedColor == 0 || selectedColor == 5 || selectedColor == 6;
        item.setIcon(hasAlarm ? R.drawable.ic_alarm_off : R.drawable.ic_alarm_on);
        Drawable drawable = item.getIcon();
        drawable.mutate();
        drawable.setColorFilter(setWhite ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        hasAlarm = !hasAlarm;
        return true;

    case R.id.action_delete:
        presenter.deleteTask();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.doomy.decode.ScanActivity.java

private void openAboutDialog() {
    LayoutInflater mLayoutInflater = LayoutInflater.from(ScanActivity.this);
    View mView = mLayoutInflater.inflate(R.layout.view_about, null);

    ImageView mImageViewMrDoomy = (ImageView) mView.findViewById(R.id.imageViewMrDoomy);
    ImageView mImageViewStudio = (ImageView) mView.findViewById(R.id.imageViewStudio);
    ImageView mImageViewGitHub = (ImageView) mView.findViewById(R.id.imageViewGitHub);
    Drawable mMrDoomy = mImageViewMrDoomy.getDrawable();
    Drawable mStudio = mImageViewStudio.getDrawable();
    Drawable mGitHub = mImageViewGitHub.getDrawable();
    mMrDoomy.setColorFilter(getResources().getColor(R.color.greenDark), PorterDuff.Mode.SRC_ATOP);
    mStudio.setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_ATOP);
    mGitHub.setColorFilter(getResources().getColor(R.color.greyMaterialDark), PorterDuff.Mode.SRC_ATOP);

    mImageViewGitHub.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww.j ava  2s .  com*/
        public void onClick(View v) {
            Intent mIntent = new Intent();
            mIntent.setAction(Intent.ACTION_VIEW);
            mIntent.addCategory(Intent.CATEGORY_BROWSABLE);
            mIntent.setData(Uri.parse(getString(R.string.url)));
            startActivity(mIntent);
        }
    });

    AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(ScanActivity.this, Utils.setThemeDialog());

    mAlertDialog.setTitle(getString(R.string.about));
    mAlertDialog.setView(mView);
    mAlertDialog.setPositiveButton(getString(R.string.okay), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    mAlertDialog.show();
}

From source file:com.z299studio.pb.PasswordGenerator.java

private void tintSeekBar(SeekBar sb) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable thumb = ContextCompat.getDrawable(getContext(), R.drawable.thumb);
        LayerDrawable progress = (LayerDrawable) ContextCompat.getDrawable(getContext(), R.drawable.progress);
        progress.getDrawable(0).setColorFilter(C.ThemedColors[C.colorIconNormal], PorterDuff.Mode.SRC_ATOP);
        progress.getDrawable(1).setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
        sb.setProgressDrawable(progress);
        thumb.setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
        sb.setThumb(thumb);//from  w ww. j a  va2s .c o  m
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(getMenuResourceId(), menu);
    // Make menu icon color same as toolbar up arrow. Both use ?colorControlNormal
    // By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay
    int colorControlNormal = Util.getThemeColor(ApptentiveInternal.getInstance().getApptentiveToolbarTheme(),
            R.attr.colorControlNormal);//from  w  w  w .j a v a2 s  .  c  o m
    for (int i = 0; i < menu.size(); i++) {
        Drawable drawable = menu.getItem(i).getIcon();
        if (drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP);
        }
    }
    attachFragmentMenuListeners(menu);
    super.onCreateOptionsMenu(menu, inflater);
}