Example usage for android.widget ImageView setColorFilter

List of usage examples for android.widget ImageView setColorFilter

Introduction

In this page you can find the example usage for android.widget ImageView setColorFilter.

Prototype

public final void setColorFilter(int color, PorterDuff.Mode mode) 

Source Link

Document

Sets a tinting option for the image.

Usage

From source file:Main.java

public static void lightenImage(ImageView v) {
    v.setColorFilter(0x99FFFFFF, PorterDuff.Mode.SRC_ATOP);
}

From source file:Main.java

public static void darkenImage(ImageView v) {
    v.setColorFilter(0x55000000, PorterDuff.Mode.SRC_ATOP);
}

From source file:com.fa.mastodon.util.ThemeUtils.java

public static void setImageViewTint(ImageView view, @AttrRes int attribute) {
    view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN);
}

From source file:com.keylesspalace.tusky.ThemeUtils.java

static void setImageViewTint(ImageView view, @AttrRes int attribute) {
    view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN);
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java

@BindingAdapter("colorFilter")
public static void setColorFiler(@NonNull final ImageView imageView, @ColorInt final int color) {
    imageView.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}

From source file:Main.java

public static void traverseAndRecolor(View root, int color, boolean withStates,
        boolean setClickableItemBackgrounds) {
    Context context = root.getContext();

    if (setClickableItemBackgrounds && root.isClickable()) {
        StateListDrawable selectableItemBackground = new StateListDrawable();
        selectableItemBackground.addState(new int[] { android.R.attr.state_pressed },
                new ColorDrawable((color & 0xffffff) | 0x33000000));
        selectableItemBackground.addState(new int[] { android.R.attr.state_focused },
                new ColorDrawable((color & 0xffffff) | 0x44000000));
        selectableItemBackground.addState(new int[] {}, null);
        root.setBackground(selectableItemBackground);
    }/*  w w  w .j  a  v a2s.  co  m*/

    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            traverseAndRecolor(parent.getChildAt(i), color, withStates, setClickableItemBackgrounds);
        }

    } else if (root instanceof ImageView) {
        ImageView imageView = (ImageView) root;
        Drawable sourceDrawable = imageView.getDrawable();
        if (withStates && sourceDrawable != null && sourceDrawable instanceof BitmapDrawable) {
            imageView.setImageDrawable(
                    makeRecoloredDrawable(context, (BitmapDrawable) sourceDrawable, color, true));
        } else {
            imageView.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }

    } else if (root instanceof TextView) {
        TextView textView = (TextView) root;
        if (withStates) {
            int sourceColor = textView.getCurrentTextColor();
            ColorStateList colorStateList = new ColorStateList(
                    new int[][] { new int[] { android.R.attr.state_pressed },
                            new int[] { android.R.attr.state_focused }, new int[] {} },
                    new int[] { sourceColor, sourceColor, color });
            textView.setTextColor(colorStateList);
        } else {
            textView.setTextColor(color);
        }

    } else if (root instanceof AnalogClock) {
        AnalogClock analogClock = (AnalogClock) root;
        try {
            Field hourHandField = AnalogClock.class.getDeclaredField("mHourHand");
            hourHandField.setAccessible(true);
            Field minuteHandField = AnalogClock.class.getDeclaredField("mMinuteHand");
            minuteHandField.setAccessible(true);
            Field dialField = AnalogClock.class.getDeclaredField("mDial");
            dialField.setAccessible(true);
            BitmapDrawable hourHand = (BitmapDrawable) hourHandField.get(analogClock);
            if (hourHand != null) {
                Drawable d = makeRecoloredDrawable(context, hourHand, color, withStates);
                d.setCallback(analogClock);
                hourHandField.set(analogClock, d);
            }
            BitmapDrawable minuteHand = (BitmapDrawable) minuteHandField.get(analogClock);
            if (minuteHand != null) {
                Drawable d = makeRecoloredDrawable(context, minuteHand, color, withStates);
                d.setCallback(analogClock);
                minuteHandField.set(analogClock, d);
            }
            BitmapDrawable dial = (BitmapDrawable) dialField.get(analogClock);
            if (dial != null) {
                Drawable d = makeRecoloredDrawable(context, dial, color, withStates);
                d.setCallback(analogClock);
                dialField.set(analogClock, d);
            }
        } catch (NoSuchFieldException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (ClassCastException ignored) {
        } // TODO: catch all exceptions?
    }
}

From source file:com.slensky.focussis.fragments.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_about, container, false);

    //        ImageView logo = (ImageView) view.findViewById(R.id.image_logo);
    //        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) logo.getLayoutParams();
    //        lp.setMargins(lp.leftMargin, ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight() / 10, lp.rightMargin, lp.bottomMargin);
    //        logo.setLayoutParams(lp);

    TextView version = (TextView) view.findViewById(R.id.text_version);
    version.setText("Version " + this.version);
    //TextView copyright = (TextView) view.findViewById(R.id.text_copyright);
    //copyright.setText(String.format(getString(R.string.copyright), Calendar.getInstance().get(Calendar.YEAR)));
    //TextView license = (TextView) view.findViewById(R.id.text_license);

    ImageView mailIcon = (ImageView) view.findViewById(R.id.email_icon);
    mailIcon.setColorFilter(Color.argb(132, 0, 0, 0), PorterDuff.Mode.MULTIPLY);
    ImageView githubIcon = (ImageView) view.findViewById(R.id.github_icon);
    githubIcon.setColorFilter(Color.argb(132, 0, 0, 0), PorterDuff.Mode.MULTIPLY);
    ImageView licenseIcon = (ImageView) view.findViewById(R.id.version_icon);
    licenseIcon.setColorFilter(Color.argb(132, 0, 0, 0), PorterDuff.Mode.MULTIPLY);

    /*license.setOnClickListener(new View.OnClickListener() {
    @Override//w  ww .  j av a2  s.  co m
    public void onClick(View v) {
        Uri uri = Uri.parseRequirements(getString(R.string.about_license_link));
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
    });*/

    RelativeLayout emailLayout = (RelativeLayout) view.findViewById(R.id.email_layout);
    emailLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", getString(R.string.about_email), null));
            startActivity(Intent.createChooser(intent, "Send Email"));
        }
    });

    RelativeLayout githubLayout = (RelativeLayout) view.findViewById(R.id.github_layout);
    githubLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse(getString(R.string.about_github_link));
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });

    return view;
}

From source file:org.sufficientlysecure.keychain.ui.CertifyKeyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.certify_key_fragment, null);

    mCertifyKeySpinner = (CertifyKeySpinner) view.findViewById(R.id.certify_key_spinner);
    mUploadKeyCheckbox = (CheckBox) view.findViewById(R.id.sign_key_upload_checkbox);
    mMultiUserIdsFragment = (MultiUserIdsFragment) getChildFragmentManager()
            .findFragmentById(R.id.multi_user_ids_fragment);

    // make certify image gray, like action icons
    ImageView vActionCertifyImage = (ImageView) view.findViewById(R.id.certify_key_action_certify_image);
    vActionCertifyImage.setColorFilter(
            FormattingUtils.getColorFromAttr(getActivity(), R.attr.colorTertiaryText), PorterDuff.Mode.SRC_IN);

    View vCertifyButton = view.findViewById(R.id.certify_key_certify_button);
    vCertifyButton.setOnClickListener(new OnClickListener() {

        @Override//from w w  w  .jav  a2  s  .co  m
        public void onClick(View v) {
            long selectedKeyId = mCertifyKeySpinner.getSelectedKeyId();
            if (selectedKeyId == Constants.key.none) {
                Notify.create(getActivity(), getString(R.string.select_key_to_certify), Notify.Style.ERROR)
                        .show();
            } else {
                cryptoOperation(new CryptoInputParcel(new Date()));
            }
        }
    });

    // If this is a debug build, don't upload by default
    if (Constants.DEBUG) {
        mUploadKeyCheckbox.setChecked(false);
    }

    return view;
}

From source file:org.sufficientlysecure.keychain.ui.SafeSlingerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.safe_slinger_activity);

    mMasterKeyId = getIntent().getLongExtra(EXTRA_MASTER_KEY_ID, 0);

    // NOTE: there are two versions of this layout, for API >= 11 and one for < 11
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        NumberPicker picker = (NumberPicker) findViewById(R.id.safe_slinger_picker);
        picker.setMinValue(2);/*from   ww w  .  j a  va  2s  . c  o m*/
        picker.setMaxValue(10);
        picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                mSelectedNumber = newVal;
            }
        });
    } else {
        Spinner spinner = (Spinner) findViewById(R.id.safe_slinger_spinner);

        List<String> list = new ArrayList<String>();
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        list.add("7");
        list.add("8");
        list.add("9");
        list.add("10");

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(dataAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                mSelectedNumber = position + 2;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    ImageView buttonIcon = (ImageView) findViewById(R.id.safe_slinger_button_image);
    buttonIcon.setColorFilter(getResources().getColor(R.color.tertiary_text_light), PorterDuff.Mode.SRC_IN);

    View button = findViewById(R.id.safe_slinger_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startExchange(mMasterKeyId, mSelectedNumber);
        }
    });
}

From source file:com.layer.atlas.AtlasMessageComposer.java

private void addAttachmentMenuItem(AttachmentSender sender) {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    LinearLayout menuLayout = (LinearLayout) mAttachmentMenu.getContentView();

    View menuItem = inflater.inflate(R.layout.atlas_message_composer_attachment_menu_item, menuLayout, false);
    ((TextView) menuItem.findViewById(R.id.title)).setText(sender.getTitle());
    menuItem.setTag(sender);//from w  ww . java 2s  .c om
    menuItem.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAttachmentMenu.dismiss();
            ((AttachmentSender) v.getTag()).requestSend();
        }
    });
    if (sender.getIcon() != null) {
        ImageView iconView = ((ImageView) menuItem.findViewById(R.id.icon));
        iconView.setColorFilter(getResources().getColor(R.color.atlas_cell_attachment_title),
                PorterDuff.Mode.MULTIPLY);
        iconView.setImageResource(sender.getIcon());
        iconView.setVisibility(VISIBLE);
        Drawable d = DrawableCompat.wrap(iconView.getDrawable());
        DrawableCompat.setTint(d, getResources().getColor(R.color.atlas_icon_enabled));
    }
    menuLayout.addView(menuItem);
}