Example usage for com.amazonaws.services.s3.model ProgressEvent getEventCode

List of usage examples for com.amazonaws.services.s3.model ProgressEvent getEventCode

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ProgressEvent getEventCode.

Prototype

@Deprecated
public int getEventCode() 

Source Link

Document

Returns the unique event code identifying the type of event this object represents.

Usage

From source file:br.org.fiscal65.amazonaws.AWSPictureUpload.java

License:Open Source License

public AWSPictureUpload(Context context, OnPictureUploadS3PostExecuteListener uploadListener,
        String picturePath, String slugFiscalizacao, String zonaFiscalizacao, Long idFiscalizacao,
        Integer posicaoFoto, Integer podeEnviarRedeDados, Integer sleep) {
    super(context);

    this.uploadListener = uploadListener;

    this.picturePath = picturePath;

    this.slugFiscalizacao = slugFiscalizacao;

    this.zonaFiscalizacao = zonaFiscalizacao;

    this.idFiscalizacao = idFiscalizacao;

    this.posicaoFoto = posicaoFoto;

    this.podeEnviarRedeDados = podeEnviarRedeDados;

    this.sleep = sleep;

    mStatus = Status.IN_PROGRESS;/*from w  ww. j  ava2 s . com*/

    progressListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                boolean hasInternet = CommunicationUtils.verifyConnectivity(getContext());

                if (hasInternet) {
                    boolean isOnWiFi = CommunicationUtils.isWifi(getContext());

                    if (isOnWiFi || (AWSPictureUpload.this.podeEnviarRedeDados != null
                            && AWSPictureUpload.this.podeEnviarRedeDados.equals(1))) {
                        try {
                            ResponseHeaderOverrides override = new ResponseHeaderOverrides();
                            override.setContentType("image/jpeg");

                            GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(
                                    CommunicationConstants.PICTURE_BUCKET_NAME,
                                    AWSUtil.getPrefix(getContext()) + AWSPictureUpload.this.slugFiscalizacao
                                            + "/zona-" + AWSPictureUpload.this.zonaFiscalizacao + "/"
                                            + pictureName);
                            urlRequest.setResponseHeaders(override);

                            URL urlDaFoto = AWSUtil.getS3Client(getContext()).generatePresignedUrl(urlRequest);

                            if (urlDaFoto != null) {
                                String string = urlDaFoto.toString();
                                String[] parts = string.split("\\?");
                                String url = parts[0];

                                S3UploadPictureResult result = new S3UploadPictureResult();
                                result.setUrlDaFoto(url);
                                result.setPosicaoFoto(AWSPictureUpload.this.posicaoFoto);
                                result.setIdFiscalizacao(AWSPictureUpload.this.idFiscalizacao);
                                result.setSlugFiscalizacao(AWSPictureUpload.this.slugFiscalizacao);
                                result.setZonaFiscalizacao(AWSPictureUpload.this.zonaFiscalizacao);

                                mStatus = Status.COMPLETED;
                                AWSPictureUpload.this.uploadListener
                                        .finishedPictureUploadS3ComResultado(result);
                            } else {
                                mStatus = Status.CANCELED;

                                if (mUpload != null) {
                                    mUpload.abort();
                                }

                                AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                        AWSPictureUpload.this.slugFiscalizacao,
                                        AWSPictureUpload.this.zonaFiscalizacao,
                                        AWSPictureUpload.this.idFiscalizacao,
                                        AWSPictureUpload.this.posicaoFoto);
                            }
                        } catch (Exception e) {
                            mStatus = Status.CANCELED;

                            if (mUpload != null) {
                                mUpload.abort();
                            }

                            AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                    AWSPictureUpload.this.slugFiscalizacao,
                                    AWSPictureUpload.this.zonaFiscalizacao,
                                    AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                        }
                    } else {
                        mStatus = Status.CANCELED;

                        if (mUpload != null) {
                            mUpload.abort();
                        }

                        AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                                AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                                AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                    }
                } else {
                    mStatus = Status.CANCELED;

                    if (mUpload != null) {
                        mUpload.abort();
                    }

                    AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                            AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                            AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
                }
            } else if (event.getEventCode() == ProgressEvent.FAILED_EVENT_CODE) {
                mStatus = Status.CANCELED;

                if (mUpload != null) {
                    mUpload.abort();
                }

                AWSPictureUpload.this.uploadListener.finishedPictureUploadS3ComError(
                        AWSPictureUpload.this.slugFiscalizacao, AWSPictureUpload.this.zonaFiscalizacao,
                        AWSPictureUpload.this.idFiscalizacao, AWSPictureUpload.this.posicaoFoto);
            }
        }
    };
}

From source file:com.android.demo.notepad3.DownloadModel.java

License:Open Source License

public DownloadModel(Context context, String key, TransferManager manager) {
    super(context, Uri.parse(key), manager);
    mKey = key;//from   w ww. j  av a  2s  . c  o  m
    mStatus = Status.IN_PROGRESS;
    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {

                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                mediaScanIntent.setData(mUri);
                getContext().sendBroadcast(mediaScanIntent);

                mStatus = Status.COMPLETED;

            }
        }
    };
}

From source file:com.android.demo.notepad3.UploadModel.java

License:Open Source License

public UploadModel(Context context, Uri uri, TransferManager manager) {
    super(context, uri, manager);
    mStatus = Status.IN_PROGRESS;//from   www .  jav  a  2 s  .co m
    mExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    ;
    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                mStatus = Status.COMPLETED;
                if (mFile != null) {
                    mFile.delete();
                }
            }
        }
    };
}

From source file:com.dss.sframework.tools.amazon.models.UploadModel.java

License:Open Source License

public UploadModel(Context context, TransferManager manager, Enums.MEDIA_TYPE mediaType, File file,
        String extension, final String callerFragmentTag) {
    //        super(context, uri, manager);
    super(context, manager, file);

    try {//w  w w  . j  av  a2  s.c  o m
        mCallbacks = (UploadFileCallbacks) context;
    } catch (ClassCastException e) {
        throw new ClassCastException(context.toString() + " must implement UploadFileCallbacks");
    }

    mStatus = Status.IN_PROGRESS;
    mExtension = extension;
    mFile = file;
    mMediaType = mediaType;
    //        mExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(
    //                context.getContentResolver().getType(uri));
    mCallerFragmentTag = callerFragmentTag;

    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                mStatus = Status.COMPLETED;
                if (mFile != null) {
                    mFile.delete();
                }

                mCallbacks.onSuccessListenerUploadFile(mMediaType, mediaURL, mCallerFragmentTag);
            }
        }
    };
}

From source file:com.example.ytlin.gpsandupload.models.DownloadModel.java

License:Open Source License

public DownloadModel(Context context, String key, TransferManager manager) {
    super(context, Uri.parse(key), manager);
    mKey = key;//  w w  w.  j a  v  a  2  s .  co m
    mStatus = Status.IN_PROGRESS;
    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {

                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

                mediaScanIntent.setData(mUri);
                getContext().sendBroadcast(mediaScanIntent);

                mStatus = Status.COMPLETED;
            }

        }

    };
}

From source file:com.fylm.aws.models.UploadModel.java

License:Open Source License

public UploadModel(Context context, Uri uri, TransferManager manager, Double lat, Double log) {
    super(context, uri, manager);
    mStatus = Status.IN_PROGRESS;/*from w ww .  j  a  va 2  s .  co  m*/
    Log.i("Inside upload model definition", "Lat: " + lat);
    latitude = lat;
    longitude = log;
    mExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    ;
    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                mStatus = Status.COMPLETED;
                if (mFile != null) {
                    mFile.delete();
                }
            }
        }
    };
}

From source file:com.proofpoint.event.collector.combiner.S3StorageSystem.java

License:Apache License

@Override
public StoredObject putObject(final URI location, File source) {
    try {/*from w w w.j ava 2  s .com*/
        log.info("starting upload: %s", location);
        final AtomicLong totalTransferred = new AtomicLong();
        Upload upload = s3TransferManager.upload(getS3Bucket(location), getS3ObjectKey(location), source);
        upload.addProgressListener(new ProgressListener() {
            @Override
            public void progressChanged(ProgressEvent progressEvent) {
                // NOTE: This may be invoked by multiple threads.
                long transferred = totalTransferred.addAndGet(progressEvent.getBytesTransferred());
                log.debug("upload progress: %s: transferred=%d code=%d", location, transferred,
                        progressEvent.getEventCode());
            }
        });
        UploadResult uploadResult = upload.waitForUploadResult();
        ObjectMetadata metadata = s3Service.getObjectMetadata(getS3Bucket(location), getS3ObjectKey(location));
        if (!uploadResult.getETag().equals(metadata.getETag())) {
            // this might happen in rare cases due to S3's eventual consistency
            throw new IllegalStateException("uploaded etag is different from retrieved object etag");
        }
        log.info("completed upload: %s (size=%d bytes)", location, totalTransferred.get());
        return updateStoredObject(location, metadata);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.taxi.UploadModel.java

License:Open Source License

public UploadModel(Context context, Uri uri, TransferManager manager) {
    super(context, uri, manager);
    my_context = context;//  w w w.j  av  a 2s  . com
    mStatus = Status.IN_PROGRESS;
    mExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    ;
    mListener = new ProgressListener() {
        @Override
        public void progressChanged(ProgressEvent event) {
            if (event.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                mStatus = Status.COMPLETED;
                if (mFile != null) {
                    mFile.delete();
                }
            }
        }
    };
}