Java Code Examples for android.widget.ImageView#requestLayout()

The following examples show how to use android.widget.ImageView#requestLayout() . 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: BadgeDialogFactory.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
private void setupMedal(ImageView badge, boolean isBadgeSelected, int badgeColor,
    Resources resources) {
  if (isBadgeSelected) {
    badge.getLayoutParams().width = selectedMedalSize;
    badge.getLayoutParams().height = selectedMedalSize;
    badge.setScaleType(ImageView.ScaleType.FIT_XY);
    badge.requestLayout();
  } else {
    badge.getLayoutParams().width = normalMedalSize;
    badge.getLayoutParams().height = normalMedalSize;
    badge.setScaleType(ImageView.ScaleType.FIT_XY);
    badge.requestLayout();
  }
  Drawable drawable = badge.getDrawable();
  setDrawableColor(resources, badgeColor, drawable);
  badge.setImageDrawable(drawable);
  setBackground(badge, resources.getColor(R.color.white));
}
 
Example 2
Source File: ImageUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调整图片的frame
 *
 * @param imageView
 */
public static void adjustSize(ImageView imageView) {
    if (imageView != null && imageView.getLayoutParams() != null && imageView.getDrawable() != null) {
         int width = (imageView.getDrawable()).getIntrinsicWidth();
         int height = (imageView.getDrawable()).getIntrinsicHeight();
        if (width != imageView.getLayoutParams().width || height != imageView.getLayoutParams().height) {
            imageView.getLayoutParams().width = width;
            imageView.getLayoutParams().height = height;
            imageView.requestLayout();
        }
    }
}
 
Example 3
Source File: ViewUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the image for an ImageView.
 */
public static void setImage(ImageView view, Drawable drawable) {
  view.setImageDrawable(drawable);
  if (drawable != null) {
    view.setAdjustViewBounds(true);
  }
  view.requestLayout();
}
 
Example 4
Source File: AlbumPreviewAdapter.java    From LiveSourceCode with Apache License 2.0 5 votes vote down vote up
public PreviewViewHolder(View itemView, int size) {
    super(itemView);

    imageView = (ImageView) itemView.findViewById(R.id.image_view);
    imageView.getLayoutParams().width = size;
    imageView.getLayoutParams().height = size;
    imageView.requestLayout();
}
 
Example 5
Source File: MovieHolder.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@NonNull
public static MovieHolder create(@NonNull Context context, int imageHeight, int imageWidth) {
    View view = View.inflate(context, R.layout.image_item, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.image);
    ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.height = imageHeight;
    layoutParams.width = imageWidth;
    imageView.requestLayout();
    return new MovieHolder(view);
}
 
Example 6
Source File: MoviesAdapter.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = View.inflate(parent.getContext(), R.layout.image_item, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.image);
    ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.height = mImageHeight;
    layoutParams.width = mImageWidth;
    imageView.requestLayout();
    return new ViewHolder(view);
}
 
Example 7
Source File: MovieHolder.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@NonNull
public static MovieHolder create(@NonNull Context context, int imageHeight, int imageWidth) {
    View view = View.inflate(context, R.layout.image_item, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.image);
    ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.height = imageHeight;
    layoutParams.width = imageWidth;
    imageView.requestLayout();
    return new MovieHolder(view);
}
 
Example 8
Source File: MovieHolder.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@NonNull
public static MovieHolder create(@NonNull Context context, int imageHeight, int imageWidth) {
    View view = View.inflate(context, R.layout.image_item, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.image);
    ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.height = imageHeight;
    layoutParams.width = imageWidth;
    imageView.requestLayout();
    return new MovieHolder(view);
}
 
Example 9
Source File: MovieDetailsFragment.java    From MovieGuide with MIT License 5 votes vote down vote up
@Override
public void showTrailers(List<Video> trailers) {
    if (trailers.isEmpty()) {
        label.setVisibility(View.GONE);
        this.trailers.setVisibility(View.GONE);
        horizontalScrollView.setVisibility(View.GONE);

    } else {
        label.setVisibility(View.VISIBLE);
        this.trailers.setVisibility(View.VISIBLE);
        horizontalScrollView.setVisibility(View.VISIBLE);

        this.trailers.removeAllViews();
        LayoutInflater inflater = getActivity().getLayoutInflater();
        RequestOptions options = new RequestOptions()
                .placeholder(R.color.colorPrimary)
                .centerCrop()
                .override(150, 150);

        for (Video trailer : trailers) {
            View thumbContainer = inflater.inflate(R.layout.video, this.trailers, false);
            ImageView thumbView = thumbContainer.findViewById(R.id.video_thumb);
            thumbView.setTag(R.id.glide_tag, Video.getUrl(trailer));
            thumbView.requestLayout();
            thumbView.setOnClickListener(this);
            Glide.with(requireContext())
                    .load(Video.getThumbnailUrl(trailer))
                    .apply(options)
                    .into(thumbView);
            this.trailers.addView(thumbContainer);
        }
    }
}
 
Example 10
Source File: TabLayout.java    From a with GNU General Public License v3.0 4 votes vote down vote up
private void updateTextAndIcon(@Nullable final TextView textView,
                               @Nullable final ImageView iconView) {
    final Drawable icon = mTab != null ? mTab.getIcon() : null;
    final CharSequence text = mTab != null ? mTab.getText() : null;
    final CharSequence contentDesc = mTab != null ? mTab.getContentDescription() : null;

    if (iconView != null) {
        if (icon != null) {
            iconView.setImageDrawable(icon);
            iconView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            iconView.setVisibility(GONE);
            iconView.setImageDrawable(null);
        }
        iconView.setContentDescription(contentDesc);
    }

    final boolean hasText = !TextUtils.isEmpty(text);
    if (textView != null) {
        if (hasText) {
            textView.setText(text);
            textView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            textView.setVisibility(GONE);
            textView.setText(null);
        }
        textView.setContentDescription(contentDesc);
    }

    if (iconView != null) {
        MarginLayoutParams lp = ((MarginLayoutParams) iconView.getLayoutParams());
        int bottomMargin = 0;
        if (hasText && iconView.getVisibility() == VISIBLE) {
            // If we're showing both text and icon, add some margin bottom to the icon
            bottomMargin = dpToPx(DEFAULT_GAP_TEXT_ICON);
        }
        if (bottomMargin != lp.bottomMargin) {
            lp.bottomMargin = bottomMargin;
            iconView.requestLayout();
        }
    }
    TooltipCompat.setTooltipText(this, hasText ? null : contentDesc);
}
 
Example 11
Source File: PlatformPageAdapter.java    From YiZhi with Apache License 2.0 4 votes vote down vote up
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
Example 12
Source File: PlatformPageAdapter.java    From enjoyshop with Apache License 2.0 4 votes vote down vote up
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
Example 13
Source File: DynamicHint.java    From dynamic-toasts with Apache License 2.0 4 votes vote down vote up
/**
 * Make a themed toast with text, icon, background and the tint color.
 *
 * @param context The context to use.
 * @param text The text to show. Can be formatted text.
 * @param icon The toast icon to show.
 * @param tintColor The toast tint color based on the toast background.
 *                  <p>It will automatically check for the contrast to provide best visibility.
 * @param backgroundColor The toast background color.
 * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT}
 *                 or {@link Toast#LENGTH_LONG}.
 *
 * @return The toast with the supplied parameters.
 *         <p>Use {@link Toast#show()} to display the toast.
 */
public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text,
        @Nullable Drawable icon, @ColorInt int tintColor, @ColorInt int backgroundColor,
        int duration) {
    if (context instanceof Activity && ((Activity) context).isFinishing()) {
        context = context.getApplicationContext();
    }

    tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);

    ToastCompat toast = new ToastCompat(context, new Toast(context));
    View toastLayout = LayoutInflater.from(context).inflate(
            R.layout.adt_layout_hint, new LinearLayout(context), false);
    ImageView toastIcon = toastLayout.findViewById(R.id.adt_hint_icon);
    TextView toastText = toastLayout.findViewById(R.id.adt_hint_text);

    if (icon != null && !disableIcon) {
        if (iconSize != ADT_DEFAULT_ICON_SIZE) {
            toastIcon.getLayoutParams().width = iconSize;
            toastIcon.getLayoutParams().height = iconSize;
            toastIcon.requestLayout();
        }
        toastIcon.setColorFilter(tintColor);
        toastIcon.setImageDrawable(icon);
    } else {
        toastIcon.setVisibility(View.GONE);
    }

    if (textTypeface != null) {
        toastText.setTypeface(textTypeface);
    }
    if (textSize != ADT_DEFAULT_TEXT_SIZE) {
        toastText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    }
    toastText.setTextColor(tintColor);
    toastText.setText(text);

    if (toastBackground != null) {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(toastBackground,
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    } else {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(
                        ContextCompat.getDrawable(context, R.drawable.adt_hint_background),
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    }

    toast.setDuration(duration);
    toast.setView(toastLayout);

    return toast;
}
 
Example 14
Source File: DynamicToast.java    From dynamic-toasts with Apache License 2.0 4 votes vote down vote up
/**
 * Make a themed toast with text, icon, background and the tint color.
 *
 * @param context The context to use.
 * @param text The text to show. Can be formatted text.
 * @param icon The toast icon to show.
 * @param tintColor The toast tint color based on the toast background.
 *                  <p>It will automatically check for the contrast to provide best visibility.
 * @param backgroundColor The toast background color.
 * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT}
 *                 or {@link Toast#LENGTH_LONG}.
 *
 * @return The toast with the supplied parameters.
 *         <p>Use {@link Toast#show()} to display the toast.
 */
public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text,
        @Nullable Drawable icon, @ColorInt int tintColor, @ColorInt int backgroundColor,
        int duration) {
    if (context instanceof Activity && ((Activity) context).isFinishing()) {
        context = context.getApplicationContext();
    }

    tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);

    ToastCompat toast = new ToastCompat(context, new Toast(context));
    View toastLayout = LayoutInflater.from(context).inflate(
            R.layout.adt_layout_toast, new LinearLayout(context), false);
    ImageView toastIcon = toastLayout.findViewById(R.id.adt_toast_icon);
    TextView toastText = toastLayout.findViewById(R.id.adt_toast_text);

    if (icon != null && !disableIcon) {
        if (iconSize != ADT_DEFAULT_ICON_SIZE) {
            toastIcon.getLayoutParams().width = iconSize;
            toastIcon.getLayoutParams().height = iconSize;
            toastIcon.requestLayout();
        }
        toastIcon.setColorFilter(tintColor);
        toastIcon.setImageDrawable(icon);
    } else {
        toastIcon.setVisibility(View.GONE);
    }

    if (textTypeface != null) {
        toastText.setTypeface(textTypeface);
    }
    if (textSize != ADT_DEFAULT_TEXT_SIZE) {
        toastText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    }
    toastText.setTextColor(tintColor);
    toastText.setText(text);

    if (toastBackground != null) {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(toastBackground,
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    } else {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(
                        ContextCompat.getDrawable(context, R.drawable.adt_toast_background),
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    }

    toast.setDuration(duration);
    toast.setView(toastLayout);

    return toast;
}
 
Example 15
Source File: PlatformPageAdapter.java    From LQRWeChat with MIT License 4 votes vote down vote up
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = ResHelper.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = ResHelper.forceCast(llCells[i].getChildAt(0));
		TextView tvName = ResHelper.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			ivLogo.requestLayout();
			tvName.requestLayout();
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = ResHelper.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = ResHelper.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = ResHelper.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = ResHelper.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
Example 16
Source File: TabLayout.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void updateTextAndIcon(
    @Nullable final TextView textView, @Nullable final ImageView iconView) {
  final Drawable icon =
      (tab != null && tab.getIcon() != null)
          ? DrawableCompat.wrap(tab.getIcon()).mutate()
          : null;
  final CharSequence text = tab != null ? tab.getText() : null;

  if (iconView != null) {
    if (icon != null) {
      iconView.setImageDrawable(icon);
      iconView.setVisibility(VISIBLE);
      setVisibility(VISIBLE);
    } else {
      iconView.setVisibility(GONE);
      iconView.setImageDrawable(null);
    }
  }

  final boolean hasText = !TextUtils.isEmpty(text);
  if (textView != null) {
    if (hasText) {
      textView.setText(text);
      if (tab.labelVisibilityMode == TAB_LABEL_VISIBILITY_LABELED) {
        textView.setVisibility(VISIBLE);
      } else {
        textView.setVisibility(GONE);
      }
      setVisibility(VISIBLE);
    } else {
      textView.setVisibility(GONE);
      textView.setText(null);
    }
  }

  if (iconView != null) {
    MarginLayoutParams lp = ((MarginLayoutParams) iconView.getLayoutParams());
    int iconMargin = 0;
    if (hasText && iconView.getVisibility() == VISIBLE) {
      // If we're showing both text and icon, add some margin bottom to the icon
      iconMargin = (int) ViewUtils.dpToPx(getContext(), DEFAULT_GAP_TEXT_ICON);
    }
    if (inlineLabel) {
      if (iconMargin != MarginLayoutParamsCompat.getMarginEnd(lp)) {
        MarginLayoutParamsCompat.setMarginEnd(lp, iconMargin);
        lp.bottomMargin = 0;
        // Calls resolveLayoutParams(), necessary for layout direction
        iconView.setLayoutParams(lp);
        iconView.requestLayout();
      }
    } else {
      if (iconMargin != lp.bottomMargin) {
        lp.bottomMargin = iconMargin;
        MarginLayoutParamsCompat.setMarginEnd(lp, 0);
        // Calls resolveLayoutParams(), necessary for layout direction
        iconView.setLayoutParams(lp);
        iconView.requestLayout();
      }
    }
  }

  final CharSequence contentDesc = tab != null ? tab.contentDesc : null;
  TooltipCompat.setTooltipText(this, hasText ? null : contentDesc);
}