Search in sources :

Example 1 with ImageLoadException

use of im.actor.sdk.util.images.common.ImageLoadException in project actor-platform by actorapp.

the class DocHolder method bindData.

@Override
protected void bindData(Message message, long readDate, long receiveDate, boolean isUpdated, PreprocessedData preprocessedData) {
    document = (DocumentContent) message.getContent();
    // Update state
    if (message.getSenderId() == myUid()) {
        stateIcon.setVisibility(View.VISIBLE);
        switch(message.getMessageState()) {
            case ERROR:
                stateIcon.setResource(R.drawable.msg_error);
                stateIcon.setTint(errorColor);
                break;
            default:
            case PENDING:
                stateIcon.setResource(R.drawable.msg_clock);
                stateIcon.setTint(waitColor);
                break;
            case SENT:
                if (message.getSortDate() <= readDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(readColor);
                } else if (message.getSortDate() <= receiveDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(deliveredColor);
                } else {
                    stateIcon.setResource(R.drawable.msg_check_1);
                    stateIcon.setTint(sentColor);
                }
                break;
        }
    } else {
        stateIcon.setVisibility(View.GONE);
    }
    // Update time
    setTimeAndReactions(time);
    // Content data
    fileName.setText(document.getName());
    fileSize.setText(messenger().getFormatter().formatFileSize(document.getSource().getSize()) + " " + document.getExt().toUpperCase());
    //region File icon
    if (isUpdated) {
        boolean isAppliedThumb = false;
        if (document.getFastThumb() != null) {
            try {
                Bitmap img = ImageLoading.loadBitmap(document.getFastThumb().getImage());
                fileIcon.setImageBitmap(img);
                fileIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
                isAppliedThumb = true;
            } catch (ImageLoadException e) {
                e.printStackTrace();
            }
        }
        if (!isAppliedThumb) {
            int type = FileTypes.getType(document.getExt());
            switch(type) {
                default:
                case FileTypes.TYPE_UNKNOWN:
                    fileIcon.setImageResource(R.drawable.picker_unknown);
                    break;
                case FileTypes.TYPE_APK:
                    fileIcon.setImageResource(R.drawable.picker_apk);
                    break;
                case FileTypes.TYPE_MUSIC:
                    fileIcon.setImageResource(R.drawable.picker_music);
                    break;
                case FileTypes.TYPE_PICTURE:
                    fileIcon.setImageResource(R.drawable.picker_unknown);
                    break;
                case FileTypes.TYPE_DOC:
                    fileIcon.setImageResource(R.drawable.picker_doc);
                    break;
                case FileTypes.TYPE_RAR:
                    fileIcon.setImageResource(R.drawable.picker_rar);
                    break;
                case FileTypes.TYPE_VIDEO:
                    fileIcon.setImageResource(R.drawable.picker_video);
                    break;
                case FileTypes.TYPE_ZIP:
                    fileIcon.setImageResource(R.drawable.picker_zip);
                    break;
                case FileTypes.TYPE_XLS:
                    fileIcon.setImageResource(R.drawable.picker_xls);
                    break;
                case FileTypes.TYPE_PPT:
                    fileIcon.setImageResource(R.drawable.picker_ppt);
                    break;
                case FileTypes.TYPE_CSV:
                    fileIcon.setImageResource(R.drawable.picker_csv);
                    break;
                case FileTypes.TYPE_HTM:
                    fileIcon.setImageResource(R.drawable.picker_htm);
                    break;
                case FileTypes.TYPE_HTML:
                    fileIcon.setImageResource(R.drawable.picker_html);
                    break;
                case FileTypes.TYPE_PDF:
                    fileIcon.setImageResource(R.drawable.picker_pdf);
                    break;
            }
            fileIcon.setScaleType(ImageView.ScaleType.CENTER);
        }
    }
    //endregion
    // Update view
    boolean needRebind = false;
    if (isUpdated) {
        // Resetting binding
        if (downloadFileVM != null) {
            downloadFileVM.detach();
            downloadFileVM = null;
        }
        if (uploadFileVM != null) {
            uploadFileVM.detach();
            uploadFileVM = null;
        }
        needRebind = true;
    } else {
        if (document.getSource() instanceof FileLocalSource) {
            if (uploadFileVM == null && downloadFileVM != null) {
                downloadFileVM.detach();
                downloadFileVM = null;
                needRebind = true;
            }
        } else if (document.getSource() instanceof FileRemoteSource) {
            if (uploadFileVM != null && downloadFileVM == null) {
                uploadFileVM.detach();
                uploadFileVM = null;
                needRebind = true;
            }
        }
    }
    if (downloadFileVM == null && uploadFileVM == null) {
        needRebind = true;
    }
    if (needRebind) {
        downloadIcon.setVisibility(View.GONE);
        progressView.setVisibility(View.GONE);
        progressValue.setVisibility(View.GONE);
        fileIcon.setVisibility(View.GONE);
        menu.setVisibility(View.GONE);
        status.setVisibility(View.GONE);
        if (document.getSource() instanceof FileRemoteSource) {
            FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
            // < 1MB
            boolean autoDownload = remoteSource.getFileReference().getFileSize() <= 1024 * 1024 && messenger().isDocAutoDownloadEnabled();
            downloadFileVM = messenger().bindFile(remoteSource.getFileReference(), autoDownload, new DownloadVMCallback());
        } else if (document.getSource() instanceof FileLocalSource) {
            uploadFileVM = messenger().bindUpload(message.getRid(), new UploadVMCallback());
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) FileLocalSource(im.actor.core.entity.content.FileLocalSource) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException)

Example 2 with ImageLoadException

use of im.actor.sdk.util.images.common.ImageLoadException in project actor-platform by actorapp.

the class BlurActor method onNeedBlur.

private void onNeedBlur(String path, int blurRadius, BluredListener bl) {
    File blured = new File(path + "_blured");
    if (!blured.exists() || blured.length() == 0) {
        try {
            Bitmap blurdBitmap = BitmapUtil.fastBlur(ImageLoading.loadBitmap(path), blurRadius);
            BitmapUtil.save(blurdBitmap, blured.getPath());
            bl.onBlured(blured);
        } catch (ImageLoadException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        bl.onBlured(blured);
    }
}
Also used : Bitmap(android.graphics.Bitmap) IOException(java.io.IOException) File(java.io.File) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException)

Example 3 with ImageLoadException

use of im.actor.sdk.util.images.common.ImageLoadException in project actor-platform by actorapp.

the class PictureActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setTitle(R.string.media_picture);
    int statbarHeight = Screen.getStatusBarHeight();
    if (Build.VERSION.SDK_INT >= 19) {
        toolbar.setPadding(0, statbarHeight, 0, 0);
    }
    final Bundle bundle = getIntent().getExtras();
    path = bundle.getString(ARG_FILE_PATH);
    int sender = bundle.getInt(ARG_OWNER, 0);
    toolbar.setVisibility(View.GONE);
    transitionTop = bundle.getInt(ARG_IMAGE_TOP, 0);
    transitionLeft = bundle.getInt(ARG_IMAGE_LEFT, 0);
    transitionWidth = bundle.getInt(ARG_IMAGE_WIDTH, 0);
    transitionHeight = bundle.getInt(ARG_IMAGE_HEIGHT, 0);
    transitionView = (ImageView) findViewById(R.id.transition);
    backgroundView = findViewById(R.id.background);
    containerView = findViewById(R.id.container);
    containerView.setAlpha(0);
    fragment = new PictureFragment();
    fragment.setArguments(bundle);
    getSupportFragmentManager().beginTransaction().add(R.id.container, fragment).commit();
    Bitmap bitmap = null;
    try {
        bitmap = ImageLoading.loadBitmapOptimized(path);
        bitmapWidth = bitmap.getWidth();
        bitmapHeight = bitmap.getHeight();
    } catch (ImageLoadException e) {
        e.printStackTrace();
        return;
    }
    transitionView.setImageBitmap(bitmap);
    if (bitmap != null)
        bitmap = null;
    MediaFullscreenAnimationUtils.animateForward(transitionView, bitmapWidth, bitmapHeight, transitionLeft, transitionTop, transitionWidth, transitionHeight, new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.setAlpha(1);
            transitionView.setAlpha(0f);
        }
    });
    MediaFullscreenAnimationUtils.animateBackgroundForward(backgroundView, null);
}
Also used : Bitmap(android.graphics.Bitmap) Animator(android.animation.Animator) Bundle(android.os.Bundle) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ActionBar(android.support.v7.app.ActionBar) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException)

Example 4 with ImageLoadException

use of im.actor.sdk.util.images.common.ImageLoadException in project actor-platform by actorapp.

the class ViewAvatarActivity method performBind.

private void performBind(Avatar avatar, AvatarUploadState uploadState) {
    unbind();
    if (uploadState != null && uploadState.isUploading()) {
        if (uploadState.getDescriptor() != null) {
            photoView.setImageURI(Uri.fromFile(new File(uploadState.getDescriptor())));
        } else {
            photoView.setImageURI(null);
        }
        showView(progress);
        goneView(noPhoto);
        return;
    }
    if (avatar == null || avatar.getFullImage() == null) {
        photoView.setImageBitmap(null);
        showView(noPhoto);
        goneView(progress);
    } else {
        goneView(noPhoto);
        // Large image
        String file = messenger().findDownloadedDescriptor(avatar.getFullImage().getFileReference().getFileId());
        if (file != null) {
            try {
                Bitmap bitmap = ImageLoading.loadBitmapOptimized(file);
                photoView.setImageBitmap(bitmap);
                photoView.setZoomable(true);
                goneView(progress);
                return;
            } catch (ImageLoadException e) {
                e.printStackTrace();
            }
        }
        // Full image not available: showing progress
        showView(progress);
        // Trying to show preview first
        boolean isAppliedPreview = false;
        String largeFile = messenger().findDownloadedDescriptor(avatar.getLargeImage().getFileReference().getFileId());
        if (largeFile != null) {
            try {
                Bitmap bitmap = ImageLoading.loadBitmapOptimized(largeFile);
                photoView.setImageBitmap(bitmap);
                photoView.setZoomable(false);
                isAppliedPreview = true;
            } catch (ImageLoadException e) {
                e.printStackTrace();
            }
        }
        if (!isAppliedPreview) {
            String smallFile = messenger().findDownloadedDescriptor(avatar.getSmallImage().getFileReference().getFileId());
            if (smallFile != null) {
                try {
                    Bitmap bitmap = ImageLoading.loadBitmapOptimized(smallFile);
                    photoView.setImageBitmap(bitmap);
                    photoView.setZoomable(false);
                } catch (ImageLoadException e) {
                    e.printStackTrace();
                }
            }
        }
        bindedDownloadFile = messenger().bindFile(avatar.getFullImage().getFileReference(), true, new FileVMCallback() {

            @Override
            public void onNotDownloaded() {
            }

            @Override
            public void onDownloading(float progressV) {
            }

            @Override
            public void onDownloaded(FileSystemReference reference) {
                try {
                    Bitmap bitmap = ImageLoading.loadBitmapOptimized(reference.getDescriptor());
                    photoView.setImageBitmap(bitmap);
                    photoView.setZoomable(true);
                    showView(photoView);
                    goneView(progress);
                } catch (ImageLoadException e) {
                    e.printStackTrace();
                }
            }
        });
    // receiver.request(new FullAvatarTask(avatar));
    }
}
Also used : Bitmap(android.graphics.Bitmap) FileSystemReference(im.actor.runtime.files.FileSystemReference) File(java.io.File) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Aggregations

Bitmap (android.graphics.Bitmap)4 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)4 File (java.io.File)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 Bundle (android.os.Bundle)1 ActionBar (android.support.v7.app.ActionBar)1 FileLocalSource (im.actor.core.entity.content.FileLocalSource)1 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)1 FileVMCallback (im.actor.core.viewmodel.FileVMCallback)1 FileSystemReference (im.actor.runtime.files.FileSystemReference)1 IOException (java.io.IOException)1