@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = (ViewGroup) inflater.inflate(R.layout.submission_imagecard, container, false); image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image); PopulateShadowboxInfo.doActionbar(s, rootView, getActivity()); (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE); type = ContentType.getImageType(s); if (type.toString().toLowerCase().contains("image") && type != ContentType.ImageType.IMAGE_LINK) { addClickFunctions(image, rootView, type, getActivity(), s); loadImage(s.getUrl()); } else if (s.getDataNode().has("preview") && s.getDataNode().get("preview").get("images").get(0).get("source").has("height") && s.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt() > 200) { loadImage( s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText()); } else { image.recycle(); (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.VISIBLE); ((ImageView) rootView.findViewById(R.id.thumbimage2)).setImageResource(R.drawable.web); addClickFunctions( (rootView.findViewById(R.id.thumbimage2)), rootView, type, getActivity(), s); (rootView.findViewById(R.id.progress)).setVisibility(View.GONE); } 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); } }); return rootView; }
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); int mDuration = 250; // in millis 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); int mDuration = 250; // in millis 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); int mDuration = 250; // in millis 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); int mDuration = 250; // in millis 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)); } }); } rootView .findViewById(R.id.submission_image) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v2) { getActivity().finish(); } }); } }
private void loadImage(String url) { final ProgressBar bar = (ProgressBar) rootView.findViewById(R.id.progress); bar.setIndeterminate(false); bar.setProgress(0); if (url != null && ContentType.isImgurLink(url)) { url = url + ".png"; } ImageView fakeImage = new ImageView(getActivity()); fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight())); fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP); ((Reddit) getActivity().getApplication()) .getImageLoader() .displayImage( url, new ImageViewAware(fakeImage), ImageLoaderUtils.options, new ImageLoadingListener() { private View mView; @Override public void onLoadingStarted(String imageUri, View view) { 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) { image.setImage(ImageSource.bitmap(loadedImage)); (rootView.findViewById(R.id.progress)).setVisibility(View.GONE); if (type == ContentType.ImageType.IMAGE || type == ContentType.ImageType.IMGUR) { image.setMinimumDpi(30); previous = image.scale; final float base = image.scale; image.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); int mDuration = 250; // in millis 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); int mDuration = 250; // in millis 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)); } }); }