use of com.nostra13.universalimageloader.core.assist.ImageLoadingProgressListener in project 9GAG by stormzhang.
the class ImageViewActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imageview);
ButterKnife.inject(this);
setTitle(R.string.view_big_image);
mAttacher = new PhotoViewAttacher(photoView);
mAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float x, float y) {
finish();
}
});
String imageUrl = getIntent().getStringExtra(IMAGE_URL);
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisc(true).considerExifParams(true).build();
ImageLoader.getInstance().displayImage(imageUrl, photoView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
progressWheel.setVisibility(View.GONE);
mAttacher.update();
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
progressWheel.setProgress(360 * current / total);
}
});
}
use of com.nostra13.universalimageloader.core.assist.ImageLoadingProgressListener in project Slide by ccrama.
the class TumblrPager method loadImage.
private static void loadImage(final View rootView, Fragment f, String url) {
final SubsamplingScaleImageView image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
image.setMinimumDpi(70);
image.setMinimumTileDpi(240);
ImageView fakeImage = new ImageView(f.getActivity());
final TextView size = (TextView) rootView.findViewById(R.id.size);
fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight()));
fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
((Reddit) f.getActivity().getApplication()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {
private View mView;
@Override
public void onLoadingStarted(String imageUri, View view) {
mView = view;
size.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Log.v("Slide", "LOADING FAILED");
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
size.setVisibility(View.GONE);
image.setImage(ImageSource.bitmap(loadedImage));
(rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
Log.v("Slide", "LOADING CANCELLED");
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
size.setText(readableFileSize(total));
((ProgressBar) rootView.findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
}
});
}
use of com.nostra13.universalimageloader.core.assist.ImageLoadingProgressListener in project Slide by ccrama.
the class MediaFragmentComment method displayImage.
public void displayImage(final String url) {
if (!imageShown) {
actuallyLoaded = url;
final SubsamplingScaleImageView i = (SubsamplingScaleImageView) rootView.findViewById(R.id.submission_image);
i.setMinimumDpi(70);
i.setMinimumTileDpi(240);
final ProgressBar bar = (ProgressBar) rootView.findViewById(R.id.progress);
bar.setIndeterminate(false);
bar.setProgress(0);
final Handler handler = new Handler();
final Runnable progressBarDelayRunner = new Runnable() {
public void run() {
bar.setVisibility(View.VISIBLE);
}
};
handler.postDelayed(progressBarDelayRunner, 500);
ImageView fakeImage = new ImageView(getActivity());
fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
File f = ((Reddit) getActivity().getApplicationContext()).getImageLoader().getDiscCache().get(url);
if (f != null && f.exists()) {
imageShown = true;
try {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
} catch (Exception e) {
// todo i.setImage(ImageSource.bitmap(loadedImage));
}
(rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
previous = i.scale;
final float base = i.scale;
i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {
@Override
public void onZoomLevelChanged(float zoom) {
if (zoom > previous && !hidden && zoom > base) {
hidden = true;
final View base = rootView.findViewById(R.id.base);
ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// hide
} else if (zoom <= previous && hidden) {
hidden = false;
final View base = rootView.findViewById(R.id.base);
ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// unhide
}
previous = zoom;
}
});
} else {
((Reddit) getActivity().getApplicationContext()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {
private View mView;
@Override
public void onLoadingStarted(String imageUri, View view) {
imageShown = true;
mView = view;
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Log.v(LogUtil.getTag(), "LOADING FAILED");
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
imageShown = true;
File f = null;
if (getActivity() != null) {
f = ((Reddit) getActivity().getApplicationContext()).getImageLoader().getDiscCache().get(url);
}
if (f != null && f.exists()) {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
} else {
i.setImage(ImageSource.bitmap(loadedImage));
}
(rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
previous = i.scale;
final float base = i.scale;
i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {
@Override
public void onZoomLevelChanged(float zoom) {
if (zoom > previous && !hidden && zoom > base) {
hidden = true;
final View base = rootView.findViewById(R.id.base);
ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// hide
} else if (zoom <= previous && hidden) {
hidden = false;
final View base = rootView.findViewById(R.id.base);
ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// unhide
}
previous = zoom;
}
});
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
Log.v(LogUtil.getTag(), "LOADING CANCELLED");
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
((ProgressBar) rootView.findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
}
});
}
}
}
use of com.nostra13.universalimageloader.core.assist.ImageLoadingProgressListener in project Slide by ccrama.
the class PeekMediaView method displayImage.
public void displayImage(final String urlB) {
LogUtil.v("Displaying " + urlB);
final String url = StringEscapeUtils.unescapeHtml4(urlB);
if (!imageShown) {
actuallyLoaded = url;
final SubsamplingScaleImageView i = (SubsamplingScaleImageView) findViewById(R.id.submission_image);
i.setMinimumDpi(70);
i.setMinimumTileDpi(240);
progress.setIndeterminate(false);
progress.setProgress(0);
final Handler handler = new Handler();
final Runnable progressBarDelayRunner = new Runnable() {
public void run() {
progress.setVisibility(View.VISIBLE);
}
};
handler.postDelayed(progressBarDelayRunner, 500);
ImageView fakeImage = new ImageView(getContext());
fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
File f = ((Reddit) getContext().getApplicationContext()).getImageLoader().getDiscCache().get(url);
if (f != null && f.exists()) {
imageShown = true;
i.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
public void onReady() {
}
@Override
public void onImageLoaded() {
}
@Override
public void onPreviewLoadError(Exception e) {
}
@Override
public void onImageLoadError(Exception e) {
imageShown = false;
LogUtil.v("No image displayed");
}
@Override
public void onTileLoadError(Exception e) {
}
});
try {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
i.setZoomEnabled(false);
} catch (Exception e) {
imageShown = false;
// todo i.setImage(ImageSource.bitmap(loadedImage));
}
(progress).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
} else {
((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {
private View mView;
@Override
public void onLoadingStarted(String imageUri, View view) {
imageShown = true;
mView = view;
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Log.v(LogUtil.getTag(), "LOADING FAILED");
imageShown = false;
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
imageShown = true;
File f = ((Reddit) getContext().getApplicationContext()).getImageLoader().getDiscCache().get(url);
if (f != null && f.exists()) {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
} else {
i.setImage(ImageSource.bitmap(loadedImage));
}
(progress).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
Log.v(LogUtil.getTag(), "LOADING CANCELLED");
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
progress.setProgress(Math.round(100.0f * current / total));
}
});
}
}
}
use of com.nostra13.universalimageloader.core.assist.ImageLoadingProgressListener in project Slide by ccrama.
the class MediaView method displayImage.
public void displayImage(final String urlB) {
LogUtil.v("Displaying " + urlB);
final String url = StringEscapeUtils.unescapeHtml4(urlB);
if (!imageShown) {
actuallyLoaded = url;
final SubsamplingScaleImageView i = (SubsamplingScaleImageView) findViewById(R.id.submission_image);
i.setMinimumDpi(70);
i.setMinimumTileDpi(240);
final ProgressBar bar = (ProgressBar) findViewById(R.id.progress);
bar.setIndeterminate(false);
bar.setProgress(0);
final Handler handler = new Handler();
final Runnable progressBarDelayRunner = new Runnable() {
public void run() {
bar.setVisibility(View.VISIBLE);
}
};
handler.postDelayed(progressBarDelayRunner, 500);
ImageView fakeImage = new ImageView(MediaView.this);
fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
File f = ((Reddit) getApplicationContext()).getImageLoader().getDiscCache().get(url);
if (f != null && f.exists()) {
imageShown = true;
i.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
public void onReady() {
}
@Override
public void onImageLoaded() {
}
@Override
public void onPreviewLoadError(Exception e) {
}
@Override
public void onImageLoadError(Exception e) {
imageShown = false;
LogUtil.v("No image displayed");
}
@Override
public void onTileLoadError(Exception e) {
}
});
try {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
} catch (Exception e) {
imageShown = false;
// todo i.setImage(ImageSource.bitmap(loadedImage));
}
(findViewById(R.id.progress)).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
previous = i.scale;
final float base = i.scale;
i.postDelayed(new Runnable() {
@Override
public void run() {
i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {
@Override
public void onZoomLevelChanged(float zoom) {
if (zoom > previous && !hidden && zoom > base) {
hidden = true;
final View base = findViewById(R.id.gifheader);
ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// hide
} else if (zoom <= previous && hidden) {
hidden = false;
final View base = findViewById(R.id.gifheader);
ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// unhide
}
previous = zoom;
}
});
}
}, 2000);
} else {
final TextView size = (TextView) findViewById(R.id.size);
((Reddit) getApplication()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {
private View mView;
@Override
public void onLoadingStarted(String imageUri, View view) {
imageShown = true;
size.setVisibility(View.VISIBLE);
mView = view;
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Log.v(LogUtil.getTag(), "LOADING FAILED");
imageShown = false;
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
imageShown = true;
size.setVisibility(View.GONE);
File f = ((Reddit) getApplicationContext()).getImageLoader().getDiscCache().get(url);
if (f != null && f.exists()) {
i.setImage(ImageSource.uri(f.getAbsolutePath()));
} else {
i.setImage(ImageSource.bitmap(loadedImage));
}
(findViewById(R.id.progress)).setVisibility(View.GONE);
handler.removeCallbacks(progressBarDelayRunner);
previous = i.scale;
final float base = i.scale;
i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {
@Override
public void onZoomLevelChanged(float zoom) {
if (zoom > previous && !hidden && zoom > base) {
hidden = true;
final View base = findViewById(R.id.gifheader);
ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// hide
} else if (zoom <= previous && hidden) {
hidden = false;
final View base = findViewById(R.id.gifheader);
ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
// unhide
}
previous = zoom;
}
});
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
Log.v(LogUtil.getTag(), "LOADING CANCELLED");
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
size.setText(readableFileSize(total));
((ProgressBar) findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
}
});
}
}
}
Aggregations