Search in sources :

Example 1 with ImageAttachment

use of ve.com.abicelis.remindy.model.attachment.ImageAttachment in project Remindy by abicelis.

the class EditImageAttachmentActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_image_attachment);
    mContainer = (RelativeLayout) findViewById(R.id.activity_edit_image_attachment_container);
    mImage = (ImageView) findViewById(R.id.activity_edit_image_attachment_image);
    mCrop = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_crop);
    mRotate = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_rotate);
    mCamera = (FloatingActionButton) findViewById(R.id.activity_edit_image_attachment_camera);
    mOk = (Button) findViewById(R.id.activity_edit_image_attachment_ok);
    mCancel = (Button) findViewById(R.id.activity_edit_image_attachment_cancel);
    if (savedInstanceState != null) {
        //Rotated screen!
        mImageAttachment = (ImageAttachment) savedInstanceState.getSerializable(IMAGE_ATTACHMENT_EXTRA);
        mHolderPosition = savedInstanceState.getInt(HOLDER_POSITION_EXTRA);
        mEditingExistingImageAttachment = savedInstanceState.getBoolean(EDITING_ATTACHMENT_EXTRA);
        mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
        if (mImageBackup == null) {
            //IF image was deleted from device
            mImageBackup = ImageUtil.getBitmap(mImageAttachment.getThumbnail());
            saveThumbnailAsImageFile(mImageBackup);
        }
        mImage.setImageBitmap(mImageBackup);
    } else {
        if (getIntent().hasExtra(HOLDER_POSITION_EXTRA) && getIntent().hasExtra(IMAGE_ATTACHMENT_EXTRA)) {
            mHolderPosition = getIntent().getIntExtra(HOLDER_POSITION_EXTRA, -1);
            mImageAttachment = (ImageAttachment) getIntent().getSerializableExtra(IMAGE_ATTACHMENT_EXTRA);
            if (mImageAttachment.getImageFilename() != null && !mImageAttachment.getImageFilename().isEmpty()) {
                mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
                if (mImageBackup == null) {
                    //IF image was deleted from device
                    mImageBackup = ImageUtil.getBitmap(mImageAttachment.getThumbnail());
                    saveThumbnailAsImageFile(mImageBackup);
                }
                mEditingExistingImageAttachment = true;
                mImage.setImageBitmap(mImageBackup);
            } else {
                mImageAttachment = new ImageAttachment();
                mImageAttachment.setImageFilename(UUID.randomUUID().toString() + IMAGE_FILE_EXTENSION);
                handleShowCameraGalleryDialog();
            }
        } else {
            BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {

                @Override
                public void onDismissed(Snackbar transientBottomBar, int event) {
                    super.onDismissed(transientBottomBar, event);
                    setResult(RESULT_CANCELED);
                    finish();
                }
            };
            Log.e(TAG, "Missing HOLDER_POSITION_EXTRA and/or IMAGE_ATTACHMENT_EXTRA parameters in EditImageAttachmentActivity.");
            SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.error_unexpected, SnackbarUtil.SnackbarDuration.LONG, callback);
            finish();
        }
    //            mImageAttachment = new ImageAttachment(new byte[0], "09ce7135-86d6-4d93-bcc5-1fbff5651d0f.jpg");
    //            mImageBackup = ImageUtil.getBitmap(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()));
    //            mEditingExistingImageAttachment = true;
    //            mImage.setImageBitmap(mImageBackup);
    }
    mRotation = 0;
    mCrop.setOnClickListener(this);
    mRotate.setOnClickListener(this);
    mCamera.setOnClickListener(this);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);
}
Also used : BaseTransientBottomBar(android.support.design.widget.BaseTransientBottomBar) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) File(java.io.File) Snackbar(android.support.design.widget.Snackbar)

Example 2 with ImageAttachment

use of ve.com.abicelis.remindy.model.attachment.ImageAttachment in project Remindy by abicelis.

the class RemindyDAO method getAttachmentFromCursor.

private Attachment getAttachmentFromCursor(Cursor cursor) {
    int id = cursor.getInt(cursor.getColumnIndex(RemindyContract.AttachmentTable._ID));
    int reminderId = cursor.getInt(cursor.getColumnIndex(RemindyContract.AttachmentTable.COLUMN_NAME_TASK_FK.getName()));
    AttachmentType attachmentType = AttachmentType.valueOf(cursor.getString(cursor.getColumnIndex(RemindyContract.AttachmentTable.COLUMN_NAME_TYPE.getName())));
    String textContent = cursor.getString(cursor.getColumnIndex(RemindyContract.AttachmentTable.COLUMN_NAME_CONTENT_TEXT.getName()));
    byte[] blobContent = cursor.getBlob(cursor.getColumnIndex(RemindyContract.AttachmentTable.COLUMN_NAME_CONTENT_BLOB.getName()));
    switch(attachmentType) {
        case AUDIO:
            return new AudioAttachment(id, reminderId, textContent);
        case IMAGE:
            return new ImageAttachment(id, reminderId, blobContent, textContent);
        case TEXT:
            return new TextAttachment(id, reminderId, textContent);
        case LINK:
            return new LinkAttachment(id, reminderId, textContent);
        case LIST:
            return new ListAttachment(id, reminderId, textContent);
        default:
            throw new InvalidParameterException("AttachmentType is invalid. Value = " + attachmentType);
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) AttachmentType(ve.com.abicelis.remindy.enums.AttachmentType) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment)

Example 3 with ImageAttachment

use of ve.com.abicelis.remindy.model.attachment.ImageAttachment in project Remindy by abicelis.

the class TaskActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //This request comes from ImageAttachmentViewHolder calling startActivityForResult() on EditImageAttachmentActivity
    if (requestCode == EditImageAttachmentActivity.EDIT_IMAGE_ATTACHMENT_REQUEST_CODE && resultCode == RESULT_OK) {
        int position = data.getIntExtra(EditImageAttachmentActivity.HOLDER_POSITION_EXTRA, -1);
        ImageAttachment imageAttachment = (ImageAttachment) data.getSerializableExtra(EditImageAttachmentActivity.IMAGE_ATTACHMENT_EXTRA);
        if (position != -1) {
            TaskFragment taskFragment = (TaskFragment) mTaskViewPagerAdapter.getRegisteredFragment(0);
            ImageAttachmentViewHolder holder = (ImageAttachmentViewHolder) taskFragment.mRecyclerView.findViewHolderForAdapterPosition(position);
            holder.updateImageAttachment(imageAttachment);
        }
    }
    //This request comes from ImageAttachmentViewHolder calling startActivityForResult() on ViewImageAttachmentActivity
    if (requestCode == ViewImageAttachmentActivity.VIEW_IMAGE_ATTACHMENT_REQUEST_CODE && resultCode == RESULT_OK) {
        int position = data.getIntExtra(ViewImageAttachmentActivity.HOLDER_POSITION_EXTRA, -1);
        ImageAttachment imageAttachment = (ImageAttachment) data.getSerializableExtra(ViewImageAttachmentActivity.IMAGE_ATTACHMENT_EXTRA);
        if (position != -1) {
            TaskFragment taskFragment = (TaskFragment) mTaskViewPagerAdapter.getRegisteredFragment(0);
            ImageAttachmentViewHolder holder = (ImageAttachmentViewHolder) taskFragment.mRecyclerView.findViewHolderForAdapterPosition(position);
            holder.updateImageAttachment(imageAttachment);
        }
    }
}
Also used : TaskFragment(ve.com.abicelis.remindy.app.fragments.TaskFragment) ImageAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.ImageAttachmentViewHolder) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 4 with ImageAttachment

use of ve.com.abicelis.remindy.model.attachment.ImageAttachment in project Remindy by abicelis.

the class TaskDetailActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //This request comes from ImageAttachmentViewHolder calling startActivityForResult() on EditImageAttachmentActivity
    if (requestCode == EditImageAttachmentActivity.EDIT_IMAGE_ATTACHMENT_REQUEST_CODE && resultCode == RESULT_OK) {
        int position = data.getIntExtra(EditImageAttachmentActivity.HOLDER_POSITION_EXTRA, -1);
        ImageAttachment imageAttachment = (ImageAttachment) data.getSerializableExtra(EditImageAttachmentActivity.IMAGE_ATTACHMENT_EXTRA);
        if (position != -1) {
            ImageAttachmentViewHolder holder = (ImageAttachmentViewHolder) mRecyclerView.findViewHolderForAdapterPosition(position);
            if (holder != null)
                holder.updateImageAttachment(imageAttachment);
        }
    }
    //This request comes from ImageAttachmentViewHolder calling startActivityForResult() on ViewImageAttachmentActivity
    if (requestCode == ViewImageAttachmentActivity.VIEW_IMAGE_ATTACHMENT_REQUEST_CODE && resultCode == RESULT_OK) {
        int position = data.getIntExtra(ViewImageAttachmentActivity.HOLDER_POSITION_EXTRA, -1);
        ImageAttachment imageAttachment = (ImageAttachment) data.getSerializableExtra(ViewImageAttachmentActivity.IMAGE_ATTACHMENT_EXTRA);
        if (position != -1) {
            ImageAttachmentViewHolder holder = (ImageAttachmentViewHolder) mRecyclerView.findViewHolderForAdapterPosition(position);
            if (holder != null)
                holder.updateImageAttachment(imageAttachment);
        }
    }
    //This request comes from TaskActivity, which was called from menu edit button
    if (requestCode == TaskActivity.TASK_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
        //Task was edited
        mTaskDataUpdated = true;
        mTask = (Task) data.getSerializableExtra(TaskActivity.TASK_TO_EDIT);
        setUpViews();
        setUpDoneOrOverdue();
        setUpToolbar();
        setUpReminderViews();
        setUpRecyclerView();
    }
}
Also used : ImageAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.ImageAttachmentViewHolder) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 5 with ImageAttachment

use of ve.com.abicelis.remindy.model.attachment.ImageAttachment in project Remindy by abicelis.

the class AttachmentAdapter method deleteAttachment.

public void deleteAttachment(int position) {
    //Called from viewHolders when deleting an attachment
    Attachment attachment = mAttachments.get(position);
    switch(attachment.getType()) {
        case AUDIO:
            String audioFilename = ((AudioAttachment) attachment).getAudioFilename();
            FileUtil.deleteAudioAttachment(mActivity, audioFilename);
            break;
        case IMAGE:
            String imageFilename = ((ImageAttachment) attachment).getImageFilename();
            FileUtil.deleteImageAttachment(mActivity, imageFilename);
    }
    mAttachments.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, getItemCount());
    if (mRealTimeDataPersistence) {
        triggerAttachmentDataUpdatedListener();
    }
}
Also used : AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Aggregations

ImageAttachment (ve.com.abicelis.remindy.model.attachment.ImageAttachment)10 AudioAttachment (ve.com.abicelis.remindy.model.attachment.AudioAttachment)6 LinkAttachment (ve.com.abicelis.remindy.model.attachment.LinkAttachment)5 ListAttachment (ve.com.abicelis.remindy.model.attachment.ListAttachment)5 TextAttachment (ve.com.abicelis.remindy.model.attachment.TextAttachment)5 ImageAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.ImageAttachmentViewHolder)3 Attachment (ve.com.abicelis.remindy.model.attachment.Attachment)3 File (java.io.File)2 InvalidParameterException (java.security.InvalidParameterException)2 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)1 Snackbar (android.support.design.widget.Snackbar)1 TaskFragment (ve.com.abicelis.remindy.app.fragments.TaskFragment)1 AudioAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.AudioAttachmentViewHolder)1 LinkAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.LinkAttachmentViewHolder)1 ListAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.ListAttachmentViewHolder)1 TextAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.TextAttachmentViewHolder)1 AttachmentType (ve.com.abicelis.remindy.enums.AttachmentType)1