List of usage examples for android.widget TextView getCompoundDrawablesRelative
@NonNull
public Drawable[] getCompoundDrawablesRelative()
From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java
/** * Apply a vector drawable, using backwards compatibility as needed. This throws an exception * if your {@code resId} is actually a bitmap drawable. */// ww w .j ava2s . c om public static void applyVectorDrawableLeft(TextView view, @DrawableRes int resId) { if (Build.VERSION.SDK_INT >= 21) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0); view.getCompoundDrawablesRelative()[0].setTint(ResourcesCompat.getColor(view.getResources(), R.color.sebastiaan_blue, view.getContext().getTheme())); } else { final Context context = view.getContext(); final Drawable drawable = loadVectorDrawable(context, resId); if (Build.VERSION.SDK_INT >= 17) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null); } else { view.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } } }
From source file:com.stepstone.stepper.internal.util.TintUtil.java
/** * Tints TextView's text color and it's compound drawables * @param textview text view to tint//from w ww . j a v a2 s .c om * @param tintColor color state list to use for tinting */ public static void tintTextView(@NonNull TextView textview, ColorStateList tintColor) { textview.setTextColor(tintColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable[] drawables = textview.getCompoundDrawablesRelative(); textview.setCompoundDrawablesRelative(tintDrawable(drawables[0], tintColor), tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor), tintDrawable(drawables[3], tintColor)); } else { Drawable[] drawables = textview.getCompoundDrawables(); textview.setCompoundDrawables(tintDrawable(drawables[0], tintColor), tintDrawable(drawables[1], tintColor), tintDrawable(drawables[2], tintColor), tintDrawable(drawables[3], tintColor)); } }
From source file:net.fabiszewski.ulogger.MainActivity.java
/** * Set status led color/*from ww w . j a va 2 s .c o m*/ * @param led Led text view * @param color Color (red, yellow or green) */ private void setLedColor(TextView led, int color) { Drawable l; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { l = led.getCompoundDrawables()[0]; } else { l = led.getCompoundDrawablesRelative()[0]; } switch (color) { case LED_RED: l.setColorFilter(ContextCompat.getColor(this, R.color.colorRed), PorterDuff.Mode.SRC_ATOP); break; case LED_GREEN: l.setColorFilter(ContextCompat.getColor(this, R.color.colorGreen), PorterDuff.Mode.SRC_ATOP); break; case LED_YELLOW: l.setColorFilter(ContextCompat.getColor(this, R.color.colorYellow), PorterDuff.Mode.SRC_ATOP); break; } l.invalidateSelf(); }
From source file:com.google.android.apps.forscience.whistlepunk.EditNoteDialog.java
@Override public AlertDialog onCreateDialog(Bundle savedInstanceState) { mLabel = getArguments().getParcelable(KEY_SAVED_LABEL); String timeText = getArguments().getString(KEY_SAVED_TIME_TEXT, ""); String timeTextContentDescription = getArguments().getString(KEY_SAVED_TIME_TEXT_DESCRIPTION); mTimestamp = getArguments().getLong(KEY_SAVED_TIMESTAMP); try {/*from w ww.j a v a2 s . c o m*/ mSelectedValue = GoosciLabelValue.LabelValue.parseFrom(getArguments().getByteArray(KEY_SELECTED_VALUE)); } catch (InvalidProtocolBufferNanoException ex) { Log.wtf(TAG, "Couldn't parse label value"); } AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); LinearLayout rootView = (LinearLayout) LayoutInflater.from(getActivity()) .inflate(R.layout.run_review_label_edit, null); alertDialog.setView(rootView); ImageView imageView = (ImageView) rootView.findViewById(R.id.picture_note_preview_image); final EditText editText = (EditText) rootView.findViewById(R.id.edit_note_text); TextView autoTextView = (TextView) rootView.findViewById(R.id.auto_note_text); // Use mSelectedValue to load content, because the user may have changed the value since // it was stored in the label. Note that picture labels can't be edited at this time, // but in the future this will apply to picture labels as well. if (mLabel instanceof PictureLabel) { imageView.setVisibility(View.VISIBLE); autoTextView.setVisibility(View.GONE); editText.setText(PictureLabel.getCaption(mSelectedValue)); editText.setHint(R.string.picture_note_caption_hint); Glide.with(getActivity()).load(PictureLabel.getFilePath(mSelectedValue)).into(imageView); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PictureUtils.launchExternalViewer(getActivity(), (PictureLabel.getFilePath(mSelectedValue))); } }); } else if (mLabel instanceof TextLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.GONE); editText.setText(TextLabel.getText(mSelectedValue)); } else if (mLabel instanceof SensorTriggerLabel) { imageView.setVisibility(View.GONE); autoTextView.setVisibility(View.VISIBLE); editText.setText(SensorTriggerLabel.getCustomText(mSelectedValue)); String autoText = SensorTriggerLabel.getAutogenText(mSelectedValue); TriggerHelper.populateAutoTextViews(autoTextView, autoText, R.drawable.ic_label_black_24dp, getResources()); } alertDialog.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mLabel.setTimestamp(mTimestamp); if (mLabel instanceof TextLabel) { ((TextLabel) mLabel).setText(editText.getText().toString()); } else if (mLabel instanceof PictureLabel) { ((PictureLabel) mLabel).setCaption(editText.getText().toString()); } else if (mLabel instanceof SensorTriggerLabel) { ((SensorTriggerLabel) mLabel).setCustomText(editText.getText().toString()); } getDataController().editLabel(mLabel, ((EditNoteDialogListener) getParentFragment()).onLabelEdit(mLabel)); } }); alertDialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.setCancelable(true); TextView timeTextView = (TextView) rootView.findViewById(R.id.edit_note_time); timeTextView.setText(timeText); timeTextView.setContentDescription(timeTextContentDescription); if (labelBelongsToRun() && mLabel.canEditTimestamp()) { timeTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GoosciLabelValue.LabelValue value = new GoosciLabelValue.LabelValue(); if (mLabel instanceof PictureLabel) { // Captions can be edited, but the picture path cannot be edited at this // time. PictureLabel.populateStorageValue(value, ((PictureLabel) mLabel).getFilePath(), editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } else if (mLabel instanceof TextLabel) { TextLabel.populateStorageValue(value, editText.getText().toString()); ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value, mTimestamp); } } }); } else if (labelBelongsToRun()) { Drawable lockDrawable = getResources().getDrawable(R.drawable.ic_lock_black_18dp); DrawableCompat.setTint(lockDrawable, getResources().getColor(R.color.text_color_light_grey)); // There is already a start drawable. Use it again. Drawable[] drawables = timeTextView.getCompoundDrawablesRelative(); timeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], null, lockDrawable, null); } AlertDialog dialog = alertDialog.create(); if (mLabel instanceof TextLabel || mLabel instanceof SensorTriggerLabel) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } return dialog; }