com.davemorrissey.labs.subscaleview.ImageSource Java Examples

The following examples show how to use com.davemorrissey.labs.subscaleview.ImageSource. 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: ViewPagerFragment.java    From subsampling-scale-image-view with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(layout.view_pager_page, container, false);

    if (savedInstanceState != null) {
        if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
            asset = savedInstanceState.getString(BUNDLE_ASSET);
        }
    }
    if (asset != null) {
        SubsamplingScaleImageView imageView = rootView.findViewById(id.imageView);
        imageView.setImage(ImageSource.asset(asset));
    }

    return rootView;
}
 
Example #2
Source File: NotePreviewActivity.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
private void handlePreViewImageItem(int index, List<String> data, List<ImagePreViewAdapter.ImagePreViewEntity> imageData, OnCompleteListener listener) {
    String original = data.get(index);
    ImageLoader.download(this, original, file -> {
        if (file == null) {
            listener.onComplete(null);
            return;
        }
        String absolutePath = file.getAbsolutePath();
        float imageScale = getImageScale(absolutePath);
        imageData.add(new ImagePreViewAdapter.ImagePreViewEntity(original, absolutePath, imageScale + 3.0f,
                ImageSource.uri(Uri.fromFile(file)), new ImageViewState(imageScale, new PointF(0, 0), 0)));
        final int nextIndex = index + 1;
        if (nextIndex == data.size()) {
            listener.onComplete(imageData);
        } else {
            handlePreViewImageItem(nextIndex, data, imageData, listener);
        }
    });
}
 
Example #3
Source File: PhotoViewFragment.java    From AndroidUiKit with Apache License 2.0 6 votes vote down vote up
private void loadImageView() {
    final String url = getArguments().getString(ARGUMENTS_IMAGE);
    Glide.with(this).downloadOnly().load(url)
            /* todo replace error icon */
            .apply(new RequestOptions().error(R.mipmap.qq_refresh_success))
            .into(new SimpleTarget<File>() {
                @Override
                public void onResourceReady(File resource, Transition<? super File> transition) {
                    mImageView.setImage(ImageSource.uri(Uri.fromFile(resource)));
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                }
            });

}
 
Example #4
Source File: CropImageView.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
/**
 * Load an image into the imageView.
 *
 * @param uri   for the image to be loaded
 * @param state the state for the imageView (might be null)
 **/
public void loadImage(Uri uri, State state) {
    setProgressBarVisibility(VISIBLE);

    imageUri = uri;

    String mimeType = MediaType.getMimeType(getContext(), imageUri);
    if (MediaType.checkRAWMimeType(mimeType)) {
        setRegionDecoderClass(RAWImageBitmapRegionDecoder.class);
    } else {
        setRegionDecoderClass(CustomRegionDecoder.class);
    }

    if (state != null) {
        cropRect = state.getCropRect();
        setAspectRatio(state.getAspectRatio());
    }
    setImage(ImageSource.uri(uri), state);
}
 
Example #5
Source File: PictureActivity.java    From Panoramic-Screenshot with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	mImageView = $(this, R.id.picture);
	mImageView.setMaxScale(3.0f);
	mImageView.setImage(ImageSource.uri(getIntent().getStringExtra(EXTRA_FILE)));
	mImageView.setZoomEnabled(true);
	mImageView.setScaleAndCenter(1.0f, new PointF(0, 0));
	
	setAppBarAlpha(0.7f);
	
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setDisplayShowTitleEnabled(false);
	
	ViewCompat.setTransitionName(mImageView, TRANSIT_PIC);
	
	mImageView.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			hideOrShowToolbar();
		}
	});
}
 
Example #6
Source File: ImagePreviewFragment.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
private void displayCachedImageFromBackgroundThread(ImageRequest request){
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(request.getSourceUri()));

    if(cacheKey != null){
        BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
        if(resource != null){
            File localFile = ((FileBinaryResource) resource).getFile();
            if(localFile != null){
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        imagePreview.setImage(ImageSource.uri(localFile.getPath()));
                    }
                });
            }
        }

    }
}
 
Example #7
Source File: ImageFragment.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Uri mediaUri = media.getUri();

    imageView.setOrientation(BitmapUtils.getOrientation(mediaUri, getContext()));
    imageView.setImage(ImageSource.uri(mediaUri));
    setTapListener(imageView);

}
 
Example #8
Source File: ImageDisplayLargeFragment.java    From subsampling-scale-image-view with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(layout.imagedisplay_large_fragment, container, false);
    final ImageDisplayActivity activity = (ImageDisplayActivity)getActivity();
    if (activity != null) {
        rootView.findViewById(id.next).setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) { activity.next(); }
        });
    }
    SubsamplingScaleImageView imageView = rootView.findViewById(id.imageView);
    imageView.setImage(ImageSource.asset("card.png"));
    return rootView;
}
 
Example #9
Source File: AnimationActivity.java    From subsampling-scale-image-view with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    findViewById(id.play).setOnClickListener(new OnClickListener() {
        @Override public void onClick(View v) { AnimationActivity.this.play(); }
    });
    view = findViewById(id.imageView);
    view.setImage(ImageSource.asset("sanmartino.jpg"));
}
 
Example #10
Source File: ExtensionPinFragment.java    From subsampling-scale-image-view with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(layout.extension_pin_fragment, container, false);
    final ExtensionActivity activity = (ExtensionActivity)getActivity();
    if (activity != null) {
        rootView.findViewById(id.next).setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) { activity.next(); }
        });
    }
    PinView imageView = rootView.findViewById(id.imageView);
    imageView.setImage(ImageSource.asset("sanmartino.jpg"));
    imageView.setPin(new PointF(1602f, 405f));
    return rootView;
}
 
Example #11
Source File: Image.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(
            R.layout.submission_imagecard, container, false);

    final SubsamplingScaleImageView image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
    TextView title = (TextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);

    title.setVisibility(View.GONE);
    desc.setVisibility(View.GONE);


    ((Reddit) getContext().getApplicationContext()).getImageLoader()
            .loadImage(url,
                    new SimpleImageLoadingListener() {

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            image.setImage(ImageSource.bitmap(loadedImage));
                        }
                    });


    return rootView;
}
 
Example #12
Source File: ImageViewerLayout.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
protected void displayScaleImage() {
    ImageInfo imageInfo = ImageContainer.getImageInfo(mUrl);
    mScaleImageView.setMinimumDpi(36);
    mScaleImageView.setMinimumTileDpi(160);
    mScaleImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
    mScaleImageView.setImage(ImageSource.uri(imageInfo.getPath()));
    mScaleImageView.setBitmapDecoderFactory(new CompatDecoderFactory<ImageDecoder>(SkiaImageDecoder.class, Utils.getBitmapConfig()));
    mScaleImageView.setRegionDecoderFactory(new CompatDecoderFactory<ImageRegionDecoder>(SkiaImageRegionDecoder.class, Utils.getBitmapConfig()));
    mScaleImageView.setOnClickListener(getOnClickListener());

    mScaleImageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
        @Override
        public void onImageLoaded() {
            if (mImageView.getVisibility() == VISIBLE) {
                mRequestManager.clear(mImageView);
                mImageView.setVisibility(View.GONE);
            }
            mScaleImageView.setVisibility(View.VISIBLE);
            if (imageInfo.isLongImage()) {
                float scale = (float) mScaleImageView.getWidth() / imageInfo.getWidth();
                mScaleImageView.animateScaleAndCenter(scale, new PointF(mScaleImageView.getWidth() / 2, 0))
                        .withDuration(500)
                        .withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD)
                        .withInterruptible(false)
                        .start();
                mScaleImageView.setDoubleTapZoomScale(scale);
            }
        }

        @Override
        public void onImageLoadError(Exception e) {
            mRequestManager.clear(mImageView);
            mImageView.setVisibility(View.GONE);
            mProgressBar.setError();
        }
    });
}
 
Example #13
Source File: ImagePreviewFragment.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void refreshPreview(Bundle bundle) {

    if(bundle.containsKey(getLocalCacheKey())){

        String path = bundle.getString(getLocalCacheKey());
        if(!path.equalsIgnoreCase(filePath)){
            ImageSource imageSource = ImageSource.uri(path);
            imagePreview.setImage(imageSource);
            filePath = path;
        }

    }

    if(bundle.containsKey(getMainKey())){
        String data = bundle.getString(getMainKey());
        postItem = new Gson().fromJson(data, PostItem.class);
        if(!topBannerTitle.getText().toString().equalsIgnoreCase(postItem.getTitle()))
            topBannerTitle.setText(postItem.getTitle());
    }


    if(imagePreview.getVisibility() == View.GONE){
        imagePreview.setVisibility(View.VISIBLE);
    }

}
 
Example #14
Source File: ImagePreviewFragment.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.preview_image_fragment, container, false);
    ButterKnife.inject(this, view);

    if(getArguments().containsKey(getMainKey())){
        String data = getArguments().getString(getMainKey());
        postItem = new Gson().fromJson(data, PostItem.class);
        topBannerTitle.setText(postItem.getTitle());
    }

    if(getArguments().containsKey(getLocalCacheKey())){
        String path = getArguments().getString(getLocalCacheKey());
        imagePreview.setImage(ImageSource.uri(path));
        imagePreview.setVisibility(View.VISIBLE);
        filePath = path;
    }else{
        preFetchToDiskCacheAndDisplay();
    }

    if(getContext() instanceof MainActivity){
        MainActivity mainActivity = (MainActivity)getContext();
        mainActivity.setDraggable(topBanner);
    }

    if(getContext() instanceof ThreadActivity){
        topBanner.setVisibility(View.GONE);
    }

    return view;
}
 
Example #15
Source File: MediaViewerActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void DisplayImage(final File file, final Uri uri) {
    final boolean gif = "image/gif".equalsIgnoreCase(getMimeType(file.toString()));
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(new File(file.getPath()).getAbsolutePath(), options);
    height = options.outHeight;
    width = options.outWidth;
    rotation = getRotation(Uri.parse("file://" + file.getAbsolutePath()));
    Log.d(Config.LOGTAG, "Image height: " + height + ", width: " + width + ", rotation: " + rotation);
    if (useAutoRotateScreen()) {
        rotateScreen(width, height, rotation);
    }
    try {
        if (gif) {
            binding.messageGifView.setVisibility(View.VISIBLE);
            binding.messageGifView.setImageURI(uri);
            binding.messageGifView.setOnTouchListener((view, motionEvent) -> gestureDetector.onTouchEvent(motionEvent));
        } else {
            binding.messageImageView.setVisibility(View.VISIBLE);
            binding.messageImageView.setImage(ImageSource.uri(uri));
            binding.messageImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
            binding.messageImageView.setOnTouchListener((view, motionEvent) -> gestureDetector.onTouchEvent(motionEvent));
        }
    } catch (Exception e) {
        ToastCompat.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
 
Example #16
Source File: ZoomingImageView.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void setSubsamplingImageViewUri(@NonNull Uri uri) {
  subsamplingImageView.setBitmapDecoderFactory(new AttachmentBitmapDecoderFactory());
  subsamplingImageView.setRegionDecoderFactory(new AttachmentRegionDecoderFactory());

  subsamplingImageView.setVisibility(View.VISIBLE);
  photoView.setVisibility(View.GONE);

  subsamplingImageView.setImage(ImageSource.uri(uri));
}
 
Example #17
Source File: PhotoPreviewActivity.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
@Override
protected final void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.product_photo_preview_activity);

    Bundle extras = getIntent().getExtras();
    productId = (String) extras.get(ProductsActivity.PRODUCT_ID_KEY);
    productName = (String) extras.get(ProductsActivity.PRODUCT_NAME);
    calledFromDialog = (boolean) extras.get(ProductsActivity.FROM_DIALOG);
    setTitle(productName);

    SubsamplingScaleImageView productImage = (SubsamplingScaleImageView) findViewById(R.id.product_image_in_viewer);
    ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);

    AbstractInstanceFactory instanceFactory = new InstanceFactory(this);
    productService = (ProductService) instanceFactory.createInstance(ProductService.class);

    String listDialogTitle = getResources().getString(R.string.product_as_title, productName);
    setTitle(listDialogTitle);

    loadImageFromStorage(productId)
            .doOnNext(result -> fullSizeBitmap = result)
            .doOnCompleted(() ->
            {
                progressBar.setVisibility(View.GONE);
                productImage.setImage(ImageSource.bitmap(fullSizeBitmap));
            })
            .doOnError(Throwable::printStackTrace)
            .subscribe();
}
 
Example #18
Source File: GalleryPagerFragment.java    From DelegateAdapter with Apache License 2.0 5 votes vote down vote up
private void loadPhoto(Photo photo) {
    if (photo != null && getUserVisibleHint() && isAdded() && !mScaleImageView.isImageLoaded()) {
        mPb.setVisibility(View.VISIBLE);
        Glide.with(this).asFile().load(photo.urls.full).into(new SimpleTarget<File>() {
            @Override
            public void onResourceReady(File resource, Transition<? super File> transition) {
                ImageSource source = ImageSource.uri(Uri.fromFile(resource));
                mScaleImageView.setImage(source);
            }
        });
    }
}
 
Example #19
Source File: FourFragment.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    Log.e(TAG, "onCreateView: ");

    if (null != rootView) {
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (null != parent) {
            parent.removeView(rootView);
        }
    } else {
        rootView = inflater.inflate(R.layout.fragment_four, container, false);
        loadData();
    }
    final SubsamplingScaleImageView imageView = rootView.findViewById(R.id.image);
    imageView.setImage(ImageSource.resource(R.drawable.cat));

    rootView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(a){
                imageView.setImage(ImageSource.resource(R.drawable.a5));
            }else {
                imageView.setImage(ImageSource.resource(R.drawable.cat));
            }
            a=!a;
        }
    });

    return rootView;
}
 
Example #20
Source File: BigImageView.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void showContent(File image) {

    if ("gif".equals(MyUtil.getRealType(image))) {
        try {
            GifDrawable gif = new GifDrawable(image.getAbsolutePath());
            placeHolder.setVisibility(VISIBLE);
            gifView.setVisibility(VISIBLE);
            llLoading.setVisibility(GONE);
            gifView.setImageDrawable(gif);
        } catch (IOException e) {
            e.printStackTrace();
            showError();
        }
    } else {
        mImageView.setVisibility(VISIBLE);
        if (image != null)
            mImageView.setImage(ImageSource.uri(Uri.fromFile(image)));
        Log.d("BigImageView", "mImageView.setImage: " + image.getAbsolutePath());
        if (placeHolder != null) {
            placeHolder.setVisibility(GONE);
        }
    }
    currentState = STATE_CONTENT;
    if (progressView != null)
        progressView.setVisibility(GONE);
    if (mThumbnailView != null)
        mThumbnailView.setVisibility(GONE);
    if (errorView != null)
        errorView.setVisibility(GONE);

}
 
Example #21
Source File: BigImageView.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCacheHitEvent(CacheHitEvent2 event) {
    if (this.url.equals(event.url)) {
        Log.d("BigImageView", "onCacheHitEvent2---event url: " + event.url);
        mImageView.setImage(ImageSource.uri(event.uri));
        showContent(null);

    }
}
 
Example #22
Source File: ImagePreViewAdapter.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
public ImagePreViewEntity(String original, String path, float maxScale, ImageSource source, ImageViewState state) {
    this.original = original;
    this.path = path;
    this.maxScale = maxScale;
    this.source = source;
    this.state = state;
}
 
Example #23
Source File: ZoomingImageView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void setSubsamplingImageViewUri(@NonNull Uri uri) {
  subsamplingImageView.setBitmapDecoderFactory(new AttachmentBitmapDecoderFactory());
  subsamplingImageView.setRegionDecoderFactory(new AttachmentRegionDecoderFactory());

  subsamplingImageView.setVisibility(View.VISIBLE);
  photoView.setVisibility(View.GONE);

  subsamplingImageView.setImage(ImageSource.uri(uri));
}
 
Example #24
Source File: ZoomingImageView.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
private void setSubsamplingImageViewUri(Uri uri) {
  subsamplingImageView.setVisibility(View.VISIBLE);
  imageView.setVisibility(View.GONE);

  subsamplingImageView.setImage(ImageSource.uri(uri));
}
 
Example #25
Source File: ViewImageActivity.java    From droidddle with Apache License 2.0 4 votes vote down vote up
@Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            super.onReceiveResult(resultCode, resultData);
            if (isFinishing() || isSupportDestroyed()) {
                return;
            }
            if (resultCode == DownloadService.UPDATE_PROGRESS) {
                mProgressBar.setIndeterminate(false);
                mProgressBar.setMax(100);
                int progress = resultData.getInt("progress");
                long total = resultData.getLong("total");
                long current = resultData.getLong("current");
                mProgressPercentage.setText(progress + "%");
                mProgressValues.setText(getProgressValues(current, total));
                mProgressBar.setProgress(progress);
                //                mProgressDialog.setProgress(progress);
                if (progress == 100) {
                    //                    mProgressDialog.dismiss();
                    mProgressLayout.setVisibility(View.GONE);
                    //                    mProgressMenu.setVisible(false);
                    String path = resultData.getString("file");
                    if (path.endsWith("gif")) {
                        FrescoUtils.setShotImage(mImageView, Uri.fromFile(new File(path)));
                    } else {
                        mImageView2.setVisibility(View.VISIBLE);
                        mImageView2.setImage(ImageSource.uri(path));
                        mImageView.setVisibility(View.GONE);
                    }
//                    final BitmapFactory.Options options = new BitmapFactory.Options();
//                    options.inJustDecodeBounds = true;
//                    BitmapFactory.decodeFile(path, options);
//                    final int height = options.outHeight;
//                    final int width = options.outWidth;
//                    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
//                    Display display = wm.getDefaultDisplay();
//                    Point size = new Point();
//                    display.getSize(size);
//                    int max = Math.max(size.x, size.y);
//
//                    if (height >= max || width >= max) {
//                        mImageView2.setImageBitmap(
//                                ImageUtil.decodeSampledBitmapFromFile(path, max, max));
//                    } else {
//                        mImageView2.setImageURI(Uri.fromFile(new File(path)));
//                    }
//                    mImageView.setVisibility(View.GONE);
//                    if (height >= 2048 || width >= 2048) {
//                        mImageView.setImageBitmap(ImageUtil.decodeSampledBitmapFromFile(path, 1000, 1000));
//                    }else{
//                        FrescoUtils.setShotImage(mImageView, Uri.fromFile(new File(path)));
//                    }
//                    mImageView.setImageURI(Uri.fromFile(new File(path)));
                    //                    Glide.with(ViewImageActivity.this).load(path).into(mImageView);
                }
            }
        }
 
Example #26
Source File: ConfigurationActivity.java    From subsampling-scale-image-view with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = findViewById(id.imageView);
    view.setImage(ImageSource.asset("card.png"));
}
 
Example #27
Source File: BasicFeaturesActivity.java    From subsampling-scale-image-view with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SubsamplingScaleImageView view = findViewById(id.imageView);
    view.setImage(ImageSource.asset("sanmartino.jpg"));
}