下面列出了android.widget.ImageView#invalidate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onAnimationUpdate(ValueAnimator animation) {
ImageMatrixCorrector corrector = getCorrector();
ImageView imageView = corrector.getImageView();
Matrix matrix = imageView.getImageMatrix();
float[] values = getValues();
matrix.getValues(values);
float dx = (float) animation.getAnimatedValue(PROPERTY_TRANSLATE_X);
dx = corrector.correctAbsolute(Matrix.MTRANS_X, dx) - values[Matrix.MTRANS_X];
float dy = (float) animation.getAnimatedValue(PROPERTY_TRANSLATE_Y);
dy = corrector.correctAbsolute(Matrix.MTRANS_Y, dy) - values[Matrix.MTRANS_Y];
matrix.postTranslate(dx, dy);
imageView.invalidate();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
ImageMatrixCorrector corrector = getCorrector();
ImageView imageView = corrector.getImageView();
if(imageView.getDrawable() != null) {
Matrix matrix = imageView.getImageMatrix();
float[] values = getValues();
matrix.getValues(values);
float sx = (float) animation.getAnimatedValue();
sx = corrector.correctAbsolute(Matrix.MSCALE_X, sx) / values[Matrix.MSCALE_X];
if (translate) {
matrix.postScale(sx, sx, px, py);
} else {
matrix.postScale(sx, sx);
}
corrector.performAbsoluteCorrections();
imageView.invalidate();
}
}
/**
* Sets the thumbnail of given file, but only if there is a view for it at the moment
*
* @param file the file to display the thumbnail of
*/
private void displayThumbnail(IndexedFile file) {
// Get the view associated with this file. However, note that the view might be assigned to
// some other item already... so let's also check if the information is still up to date
View v = mItemToView.get(file);
int i = mViewToPositions.get(v);
if (mContentItems.get(i) != file) {
return; // information was out of date
}
if (file.getThumbnail() != null) {
v.findViewById(R.id.content_texts).setVisibility(View.INVISIBLE);
ImageView thumbImage = (ImageView) v.findViewById(R.id.file_preview);
thumbImage.setImageBitmap(file.getThumbnail());
thumbImage.invalidate();
}
else {
Utils.d("We failed to get the bitmap :(");
}
}
/**
* inject a image touch overley
* @param v
* @param event
*/
public static boolean imageOverlay(View v, MotionEvent event) {
ImageView view = (ImageView) v;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// overlay is black with transparency of 0x77 (119)
view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
view.invalidate();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: {
// clear the overlay
view.getDrawable().clearColorFilter();
view.invalidate();
break;
}
}
return false;
}
@Override
public void didReceivedNotification(int id, int account, Object... args){
if(id==NotificationCenter.emojiDidLoaded){
for(ImageView iv:keyEmojiViews){
iv.invalidate();
}
}
if(id==NotificationCenter.closeInCallActivity){
finish();
}
}
@Override
public void didReceivedNotification(int id, int account, Object... args){
if(id==NotificationCenter.emojiDidLoaded){
for(ImageView iv:keyEmojiViews){
iv.invalidate();
}
}
if(id==NotificationCenter.closeInCallActivity){
finish();
}
}
/**
* load a bitmap as background image from a ImageView.
*
* @param imageView the {@link ImageView} we need to use.
*/
private void backgroundFromImageView(ImageView imageView) {
imageView.invalidate();
if (imageView.getDrawable() != null) {
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
if (resizeBackgroundImg) {
backgroundImg = resizeBitmap(drawable.getBitmap(), MAX_IMAGE_SIZE);
} else {
backgroundImg = drawable.getBitmap();
}
}
}
/**
* load a bitmap as watermark image from a ImageView.
*
* @param imageView the ImageView we need to use.
*/
private void watermarkFromImageView(ImageView imageView) {
imageView.invalidate();
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
// set the limitation of input bitmap.
this.image = resizeBitmap(drawable.getBitmap(), MAX_IMAGE_SIZE);
}
static void internalSetTint(ImageView imageView, int color) {
if(imageView == null) {
return;
}
Drawable d = DrawableCompat.wrap(imageView.getDrawable());
if(d != null) {
DrawableCompat.setTint(d.mutate(), color);
}
imageView.invalidate();
}
/**
* Invalidates the pressed/focused states.
*/
void invalidatePressedFocusedStates(ImageView v) {
mStatesUpdated = false;
if (v != null) {
v.invalidate();
}
}
private static void setColor(ImageView image, TextView text, int color) {
// set color
GradientDrawable sd = (GradientDrawable) image.getDrawable();
sd.setColor(color);
image.invalidate();
// set color name
text.setText(getColorName(color));
}
@Override
public void onClick(View v) {
ImageView image = (ImageView) v;
((ImageView) v).getDrawable().clearColorFilter();
image.invalidate();
Integer index = (Integer) v.getTag();
Intent intent = SingleFragmentActivity.getIntent(getActivity(), SingleFragmentActivity.GALLERY);
intent.putExtra(GalleryPagerFragment.CUR_INDEX, index);
intent.putExtra(GalleryPagerFragment.URLS, mImageUrls);
intent.putExtra(GalleryPagerFragment.TITLE, getString(R.string.view_photos));
startActivity(intent);
}
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.emojiDidLoad) {
for (ImageView iv : keyEmojiViews) {
iv.invalidate();
}
}
if (id == NotificationCenter.closeInCallActivity) {
finish();
}
}
public void load() {
ImageView imageView = this.imageView.get();
if (imageView != null) {
if(inProgressLoads.containsKey(imageView)) {
inProgressLoads.get(imageView).cancelRequest();
inProgressLoads.remove(imageView);
}
inProgressLoads.put(imageView, this);
imageView.getViewTreeObserver().addOnPreDrawListener(this);
imageView.invalidate(dirtyRect);
}
}
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.emojiDidLoad) {
for (ImageView iv : keyEmojiViews) {
iv.invalidate();
}
}
if (id == NotificationCenter.closeInCallActivity) {
finish();
}
}
public void onShutter() {
ImageView blinkRect = (ImageView) findViewById(R.id.blink_rectangle);
blinkRect.setVisibility(View.VISIBLE);
blinkRect.bringToFront();
blinkRect.invalidate();
}
void DrawBlink() {
SystemClock.sleep(500);
ImageView blinkRect = (ImageView) findViewById(R.id.blink_rectangle);
blinkRect.setVisibility(View.INVISIBLE);
blinkRect.invalidate();
}
public static void setIconColor(ImageView iconHolder, int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(iconHolder.getDrawable());
DrawableCompat.setTint(wrappedDrawable, color);
iconHolder.setImageDrawable(wrappedDrawable);
iconHolder.invalidate();
}
private void invalidateView() {
ImageView imageView = imageZoomer.getImageView();
if (imageView != null) {
imageView.invalidate();
}
}