use of me.ccrama.redditslide.Views.SubsamplingScaleImageView in project Slide by ccrama.
the class MediaFragmentComment method displayImage.
public void displayImage(final String url) {
if (!imageShown) {
actuallyLoaded = url;
final SubsamplingScaleImageView i = rootView.findViewById(R.id.submission_image);
i.setMinimumDpi(70);
i.setMinimumTileDpi(240);
final ProgressBar bar = 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().getDiskCache().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.setOnStateChangedListener(new SubsamplingScaleImageView.DefaultOnStateChangedListener() {
@Override
public void onScaleChanged(float newScale, int origin) {
if (newScale > previous && !hidden && newScale > 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 (newScale <= 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 = newScale;
}
});
} 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() {
@Override
public void onLoadingStarted(String imageUri, View view) {
imageShown = true;
}
@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().getDiskCache().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.setOnStateChangedListener(new SubsamplingScaleImageView.DefaultOnStateChangedListener() {
@Override
public void onScaleChanged(float newScale, int origin) {
if (newScale > previous && !hidden && newScale > 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 (newScale <= 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 = newScale;
}
});
}
@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 me.ccrama.redditslide.Views.SubsamplingScaleImageView in project Slide by ccrama.
the class TumblrPager method loadImage.
private static void loadImage(final View rootView, Fragment f, String url) {
final SubsamplingScaleImageView image = rootView.findViewById(R.id.image);
image.setMinimumDpi(70);
image.setMinimumTileDpi(240);
ImageView fakeImage = new ImageView(f.getActivity());
final TextView size = 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() {
@Override
public void onLoadingStarted(String imageUri, View 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(FileUtil.readableFileSize(total));
((ProgressBar) rootView.findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
}
});
}
use of me.ccrama.redditslide.Views.SubsamplingScaleImageView in project Slide by ccrama.
the class MediaFragment method displayImage.
public void displayImage(final String urlB) {
final String url = StringEscapeUtils.unescapeHtml4(urlB);
if (!imageShown) {
actuallyLoaded = url;
final SubsamplingScaleImageView i = rootView.findViewById(R.id.submission_image);
i.setMinimumDpi(70);
i.setMinimumTileDpi(240);
final ProgressBar bar = rootView.findViewById(R.id.progress);
bar.setIndeterminate(false);
LogUtil.v("Displaying image " + url);
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().getDiskCache().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.setOnStateChangedListener(new SubsamplingScaleImageView.DefaultOnStateChangedListener() {
@Override
public void onScaleChanged(float newScale, int origin) {
if (newScale > previous && !hidden && newScale > 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 (newScale <= 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 = newScale;
}
});
} 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() {
@Override
public void onLoadingStarted(String imageUri, View view) {
imageShown = true;
}
@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().getDiskCache().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.setOnStateChangedListener(new SubsamplingScaleImageView.DefaultOnStateChangedListener() {
@Override
public void onScaleChanged(float newScale, int origin) {
if (newScale > previous && !hidden && newScale > 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 (newScale <= 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 = newScale;
}
});
}
@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 me.ccrama.redditslide.Views.SubsamplingScaleImageView in project Slide by ccrama.
the class MediaFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = (ViewGroup) inflater.inflate(R.layout.submission_mediacard, container, false);
if (savedInstanceState != null && savedInstanceState.containsKey("position")) {
stopPosition = savedInstanceState.getLong("position");
}
PopulateShadowboxInfo.doActionbar(s, rootView, getActivity(), true);
View thumbnailView = (rootView.findViewById(R.id.thumbimage2));
thumbnailView.setVisibility(View.GONE);
ImageView typeImage = rootView.findViewById(R.id.type);
typeImage.setVisibility(View.VISIBLE);
SubsamplingScaleImageView img = rootView.findViewById(R.id.submission_image);
final SlidingUpPanelLayout slideLayout = rootView.findViewById(R.id.sliding_layout);
ContentType.Type type = ContentType.getContentType(s);
if (type == ContentType.Type.VREDDIT_REDIRECT || type == ContentType.Type.VREDDIT_DIRECT) {
if ((!s.getDataNode().has("media") || !s.getDataNode().get("media").has("reddit_video")) && !s.getDataNode().has("crosspost_parent_list")) {
type = ContentType.Type.LINK;
}
}
img.setAlpha(1f);
if (Strings.isNullOrEmpty(s.getThumbnail()) || Strings.isNullOrEmpty(firstUrl) || (s.isNsfw() && SettingValues.getIsNSFWEnabled())) {
thumbnailView.setVisibility(View.VISIBLE);
((ImageView) thumbnailView).setImageResource(R.drawable.web);
addClickFunctions(thumbnailView, slideLayout, rootView, type, getActivity(), s);
addClickFunctions(typeImage, slideLayout, rootView, type, getActivity(), s);
(rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
if ((s.isNsfw() && SettingValues.getIsNSFWEnabled())) {
((ImageView) thumbnailView).setImageResource(R.drawable.nsfw);
} else {
if (Strings.isNullOrEmpty(firstUrl) && !Strings.isNullOrEmpty(s.getThumbnail())) {
((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(s.getThumbnail(), ((ImageView) thumbnailView));
}
}
} else {
thumbnailView.setVisibility(View.GONE);
addClickFunctions(img, slideLayout, rootView, type, getActivity(), s);
}
if (!s.isNsfw() || !SettingValues.getIsNSFWEnabled()) {
if (type == ContentType.Type.EXTERNAL || type == ContentType.Type.LINK || type == ContentType.Type.VIDEO) {
doLoad(firstUrl, type);
} else {
doLoad(contentUrl, type);
}
}
switch(type) {
case ALBUM:
case REDDIT_GALLERY:
typeImage.setImageResource(R.drawable.ic_photo_library);
break;
case EXTERNAL:
case LINK:
case REDDIT:
typeImage.setImageResource(R.drawable.ic_public);
rootView.findViewById(R.id.submission_image).setAlpha(0.5f);
break;
case SELF:
typeImage.setImageResource(R.drawable.ic_text_fields);
break;
case EMBEDDED:
case VIDEO:
typeImage.setImageResource(R.drawable.ic_play_arrow);
rootView.findViewById(R.id.submission_image).setAlpha(0.5f);
break;
default:
typeImage.setVisibility(View.GONE);
break;
}
rootView.findViewById(R.id.base).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i2 = new Intent(getActivity(), CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
getActivity().startActivity(i2);
}
});
final View.OnClickListener openClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
};
rootView.findViewById(R.id.base).setOnClickListener(openClick);
final View title = rootView.findViewById(R.id.title);
title.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
slideLayout.setPanelHeight(title.getMeasuredHeight());
title.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
slideLayout.addPanelSlideListener(new SlidingUpPanelLayout.SimplePanelSlideListener() {
@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
rootView.findViewById(R.id.base).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i2 = new Intent(getActivity(), CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
getActivity().startActivity(i2);
}
});
} else {
rootView.findViewById(R.id.base).setOnClickListener(openClick);
}
}
});
return rootView;
}
use of me.ccrama.redditslide.Views.SubsamplingScaleImageView in project Slide by ccrama.
the class MediaView method onDestroy.
@Override
public void onDestroy() {
super.onDestroy();
((SubsamplingScaleImageView) findViewById(R.id.submission_image)).recycle();
if (gif != null) {
gif.cancel();
gif.cancel(true);
}
doOnClick = null;
if (!didLoadGif && fileLoc != null && !fileLoc.isEmpty()) {
new File(fileLoc).delete();
}
}
Aggregations