Java Code Examples for android.support.v7.widget.AppCompatImageView#setImageResource()
The following examples show how to use
android.support.v7.widget.AppCompatImageView#setImageResource() .
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: AddTagAdapter.java From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License | 6 votes |
@NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { final RuuviTag tag = getItem(position); if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_item_add, parent, false); } ((TextView)convertView.findViewById(R.id.address)).setText(tag.id); ((TextView)convertView.findViewById(R.id.rssi)).setText(String.format(getContext().getResources().getString(R.string.signal_reading), tag.rssi)); AppCompatImageView signalIcon = convertView.findViewById(R.id.signalIcon); if (tag.rssi < -80) signalIcon.setImageResource(R.drawable.icon_connection_1); else if (tag.rssi < -50) signalIcon.setImageResource(R.drawable.icon_connection_2); else signalIcon.setImageResource(R.drawable.icon_connection_3); return convertView; }
Example 2
Source File: InstaLikeView.java From InstaLikeView with Apache License 2.0 | 6 votes |
private void init(Context context, AttributeSet attrs, int defStyleAttr) { mImageHeart = new AppCompatImageView(context); TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.InstaLikeView, defStyleAttr, 0); int likeColor = a.getColor(R.styleable.InstaLikeView_likeColor, ContextCompat.getColor(context, R.color.heartColor)); int likeSrc = a.getResourceId(R.styleable.InstaLikeView_likeSrc, R.drawable.img_heart); int likeSize = a.getDimensionPixelSize(R.styleable.InstaLikeView_likeSize, getResources().getDimensionPixelSize(R.dimen.likeSize)); LayoutParams heartParams = new LayoutParams(likeSize, likeSize); heartParams.addRule(CENTER_IN_PARENT, TRUE); mImageHeart.setLayoutParams(heartParams); mImageHeart.setVisibility(GONE); mImageHeart.setImageResource(likeSrc); mImageHeart.setColorFilter(likeColor); addView(mImageHeart); }
Example 3
Source File: BottomBarTab.java From BottomBar with Apache License 2.0 | 6 votes |
void prepareLayout() { inflate(getContext(), getLayoutResource(), this); setOrientation(VERTICAL); setGravity(isTitleless? Gravity.CENTER : Gravity.CENTER_HORIZONTAL); setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); setBackgroundResource(MiscUtils.getDrawableRes(getContext(), R.attr.selectableItemBackgroundBorderless)); iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon); iconView.setImageResource(iconResId); if (type != Type.TABLET && !isTitleless) { titleView = (TextView) findViewById(R.id.bb_bottom_bar_title); titleView.setVisibility(VISIBLE); if (type == Type.SHIFTING) { findViewById(R.id.spacer).setVisibility(VISIBLE); } updateTitle(); } updateCustomTextAppearance(); updateCustomTypeface(); }
Example 4
Source File: SlideFragment.java From Android-9-Development-Cookbook with MIT License | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_slide, container, false); AppCompatImageView imageView = rootView.findViewById(R.id.imageView); imageView.setImageResource(mImageResourceID); return rootView; }
Example 5
Source File: ProSwipeButton.java From proSwipeButton with MIT License | 5 votes |
public void showResultIcon(boolean isSuccess, boolean shouldReset) { animateFadeHide(context, progressBar); final AppCompatImageView failureIcon = new AppCompatImageView(context); RelativeLayout.LayoutParams icLayoutParams = new RelativeLayout.LayoutParams(dpToPx(50), dpToPx(50)); failureIcon.setLayoutParams(icLayoutParams); failureIcon.setVisibility(GONE); int icon; if (isSuccess) icon = R.drawable.ic_check_circle_36dp; else icon = R.drawable.ic_cancel_full_24dp; failureIcon.setImageResource(icon); contentContainer.addView(failureIcon); animateFadeShow(context, failureIcon); if (shouldReset) { // expand the btn again new Handler().postDelayed(new Runnable() { @Override public void run() { animateFadeHide(context, failureIcon); morphToRect(); arrowHintContainer.setX(0); animateFadeShow(context, arrowHintContainer); animateFadeShow(context, contentTv); } }, 1000); } }
Example 6
Source File: JSCItemLayout.java From CameraMaskDemo with Apache License 2.0 | 4 votes |
private void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JSCItemLayout, defStyleAttr, 0); LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); contentParams.gravity = Gravity.CENTER_VERTICAL; LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setGravity(Gravity.CENTER_VERTICAL); addView(layout, contentParams); //icon iconView = new AppCompatImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); layout.addView(iconView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); iconView.setImageResource(a.getResourceId(R.styleable.JSCItemLayout_il_icon, R.drawable.kit_ic_assignment_blue_24dp)); //label labelView = new TextView(context); labelView.setTextColor(0xFF666666); labelView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); layout.addView(labelView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (a.hasValue(R.styleable.JSCItemLayout_il_label)) { labelView.setText(a.getString(R.styleable.JSCItemLayout_il_label)); } //value valueView = new TextView(context); valueView.setTextColor(0xFF333333); valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); layout.addView(valueView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); if (a.hasValue(R.styleable.JSCItemLayout_il_value)) { valueView.setText(a.getString(R.styleable.JSCItemLayout_il_value)); } //red dot int size = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_8); dotView = new DotView(context); dotView.setBackgroundColor(Color.RED); dotView.setTextColor(Color.WHITE); if (a.hasValue(R.styleable.JSCItemLayout_il_dotSize)){ size = a.getDimensionPixelSize(R.styleable.JSCItemLayout_il_dotSize, 0); } dotView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10); layout.addView(dotView, new LinearLayout.LayoutParams(size, size)); showDotView(a.getBoolean(R.styleable.JSCItemLayout_il_showDot, false)); //right arrow arrowView = new AppCompatImageView(context); arrowView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); layout.addView(arrowView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); arrowView.setImageResource(a.getResourceId(R.styleable.JSCItemLayout_il_arrowIcon, R.drawable.kit_ic_chevron_right_gray_24dp)); a.recycle(); }
Example 7
Source File: JSCItemLayout.java From WheelViewDemo with Apache License 2.0 | 4 votes |
private void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JSCItemLayout, defStyleAttr, 0); LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); contentParams.gravity = Gravity.CENTER_VERTICAL; LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setGravity(Gravity.CENTER_VERTICAL); addView(layout, contentParams); //icon iconView = new AppCompatImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); layout.addView(iconView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); iconView.setImageResource(a.getResourceId(R.styleable.JSCItemLayout_il_icon, R.drawable.kit_ic_assignment_blue_24dp)); //label labelView = new TextView(context); labelView.setTextColor(0xFF666666); labelView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); layout.addView(labelView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (a.hasValue(R.styleable.JSCItemLayout_il_label)) { labelView.setText(a.getString(R.styleable.JSCItemLayout_il_label)); } //value valueView = new TextView(context); valueView.setTextColor(0xFF333333); valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); layout.addView(valueView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); if (a.hasValue(R.styleable.JSCItemLayout_il_value)) { valueView.setText(a.getString(R.styleable.JSCItemLayout_il_value)); } //red dot int size = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_8); dotView = new DotView(context); dotView.setBackgroundColor(Color.RED); dotView.setTextColor(Color.WHITE); if (a.hasValue(R.styleable.JSCItemLayout_il_dotSize)){ size = a.getDimensionPixelSize(R.styleable.JSCItemLayout_il_dotSize, 0); } dotView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10); layout.addView(dotView, new LinearLayout.LayoutParams(size, size)); showDotView(a.getBoolean(R.styleable.JSCItemLayout_il_showDot, false)); //right arrow arrowView = new AppCompatImageView(context); arrowView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); layout.addView(arrowView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); arrowView.setImageResource(a.getResourceId(R.styleable.JSCItemLayout_il_arrowIcon, R.drawable.kit_ic_chevron_right_gray_24dp)); a.recycle(); }
Example 8
Source File: RuuviTagAdapter.java From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { final RuuviTag tag = getItem(position); if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_item_main, parent, false); } TextView txtId = convertView.findViewById(R.id.id); TextView lastseen = convertView.findViewById(R.id.lastseen); TextView temp = convertView.findViewById(R.id.row_main_temperature); TextView humid = convertView.findViewById(R.id.row_main_humidity); TextView pres = convertView.findViewById(R.id.row_main_pressure); TextView signal = convertView.findViewById(R.id.row_main_signal); txtId.setText(tag.getDispayName()); int ballColorRes = (position % 2 == 0) ? R.color.main : R.color.mainLight; ((ImageView)convertView.findViewById(R.id.row_main_letter)) .setImageBitmap(Utils.createBall((int)getContext().getResources().getDimension(R.dimen.letter_ball_radius), getContext().getResources().getColor(ballColorRes), Color.WHITE, txtId.getText().charAt(0) + "")); convertView.findViewById(R.id.row_main_root).setTag(tag); //convertView.findViewById(R.id.row_main_letter).setOnClickListener(tagMenuClickListener); String updatedAt = getContext().getResources().getString(R.string.updated) + " " + Utils.strDescribingTimeSince(tag.updateAt); lastseen.setText(updatedAt); AppCompatImageView bell = convertView.findViewById(R.id.bell); int status = AlarmChecker.getStatus(tag); switch (status) { case -1: bell.setVisibility(View.VISIBLE); bell.setImageResource(R.drawable.ic_notifications_off_24px); break; case 0: bell.setVisibility(View.VISIBLE); bell.setImageResource(R.drawable.ic_notifications_on_24px); break; case 1: bell.setImageResource(R.drawable.ic_notifications_active_24px); bell.setVisibility(bell.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE); break; } ImageViewCompat.setImageTintList(bell, ColorStateList.valueOf(getContext().getResources().getColor(R.color.main))); temp.setText(tag.getTemperatureString(getContext())); humid.setText(String.format(getContext().getString(R.string.humidity_reading), tag.humidity)); pres.setText(String.format(getContext().getString(R.string.pressure_reading), tag.pressure)); signal.setText(String.format(getContext().getString(R.string.signal_reading), tag.rssi)); return convertView; }
Example 9
Source File: SpotlightView.java From Spotlight with Apache License 2.0 | 4 votes |
/** * Add arc above/below the circular target overlay. */ private void addArcAnimation(final Activity activity) { AppCompatImageView mImageView = new AppCompatImageView(activity); mImageView.setImageResource(R.drawable.ic_spotlight_arc); LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc), 2 * (circleShape.getRadius() + extraPaddingForArc)); if (targetView.getPoint().y > getHeight() / 2) {//bottom if (targetView.getPoint().x > getWidth() / 2) {//Right params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc; params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc; params.gravity = Gravity.RIGHT | Gravity.BOTTOM; } else { params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc; params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc; params.gravity = Gravity.LEFT | Gravity.BOTTOM; } } else {//up mImageView.setRotation(180); //Reverse the view if (targetView.getPoint().x > getWidth() / 2) {//Right params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc; params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc; params.gravity = Gravity.RIGHT | Gravity.BOTTOM; } else { params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc; params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc; params.gravity = Gravity.LEFT | Gravity.BOTTOM; } } mImageView.postInvalidate(); mImageView.setLayoutParams(params); addView(mImageView); PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(lineAndArcColor, PorterDuff.Mode.SRC_ATOP); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AnimatedVectorDrawable avd = (AnimatedVectorDrawable) ContextCompat.getDrawable(activity, R.drawable.avd_spotlight_arc); avd.setColorFilter(porterDuffColorFilter); mImageView.setImageDrawable(avd); avd.start(); } else { AnimatedVectorDrawableCompat avdc = AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc); avdc.setColorFilter(porterDuffColorFilter); mImageView.setImageDrawable(avdc); avdc.start(); } new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { addPathAnimation(activity); } }, 400); }