android-workmanager-codelab_start/app/src/main/java/com/example/background/BlurViewModel.java
/**
     * Create the WorkRequest to apply the blur and save the resulting image
     * @param blurLevel The amount to blur the image
     */
Create the WorkRequest to apply the blur and save the resulting image
@param blurLevel The amount to blur the image
Create the WorkRequest to apply the blur and save the resulting image @param blurLevel The amount to blur the image
void applyBlur(int blurLevel) {
    /**
     * WorkRequest: This represents a request to do some work.
     * You'll pass in your Worker as part of creating your WorkRequest.
     * When making the WorkRequest you can also specify things like
     * Constraints on when the Worker should run.
     */
        /**
         * UNIQUE SEQUESCE For example, if your app needs to sync its data to the network,
         * you might enqueue a sequence named "sync",
         * and specify that your new task should be ignored if there's already a sequence with that name.
         * Unique work sequences can also be useful if you need to gradually build up a long chain of tasks.
         * For example, a photo editing app might let users undo a long chain of actions.
         * Each of those undo operations might take a while, but they have to be performed in the correct order.
         * In this case, the app could create an "undo" chain and append each undo operation to the chain as needed.
         */
        /**
         * Ensure that your chain of work to blur your file is unique by using beginUniqueWork.
         * Pass in IMAGE_MANIPULATION_WORK_NAME as the key.
         * You'll also need to pass in a ExistingWorkPolicy.
         * Your options are REPLACE, KEEP or APPEND.
         */
        WorkContinuation continuation = mWorkManager
                .beginUniqueWork(IMAGE_MANIPULATION_WORK_NAME,
                        /**
                         * You'll use REPLACE because if the user decides to blur
                         * another image before the current one is finished,
                         * we want to stop the current one and start blurring the new image.
                         * Blur-O-Matic will now only ever blur one picture at a time.
                         */
                        ExistingWorkPolicy.REPLACE,
                        OneTimeWorkRequest.from(CleanupWorker.class));
        for (int i = 0; i < blurLevel; i++) {
            OneTimeWorkRequest.Builder blurBuilder =
                    new OneTimeWorkRequest.Builder(BlurWorker.class);
            if ( i == 0 ) {
                blurBuilder.setInputData(createInputDataForUri());
            }
            continuation = continuation.then(blurBuilder.build());
        }
        Constraints constraints = new Constraints.Builder()
                .setRequiresCharging(true)
                .build();
        OneTimeWorkRequest save = new OneTimeWorkRequest.Builder(SaveImageToFileWorker.class)
                .setConstraints(constraints) 
                .addTag(TAG_OUTPUT) 
                .build();
        continuation = continuation.then(save);
        continuation.enqueue();
    }
void applyBlur ( int blurLevel ) { /**
     * WorkRequest: This represents a request to do some work.
     * You'll pass in your Worker as part of creating your WorkRequest.
     * When making the WorkRequest you can also specify things like
     * Constraints on when the Worker should run.
     */ /**
         * UNIQUE SEQUESCE For example, if your app needs to sync its data to the network,
         * you might enqueue a sequence named "sync",
         * and specify that your new task should be ignored if there's already a sequence with that name.
         * Unique work sequences can also be useful if you need to gradually build up a long chain of tasks.
         * For example, a photo editing app might let users undo a long chain of actions.
         * Each of those undo operations might take a while, but they have to be performed in the correct order.
         * In this case, the app could create an "undo" chain and append each undo operation to the chain as needed.
         */ /**
         * Ensure that your chain of work to blur your file is unique by using beginUniqueWork.
         * Pass in IMAGE_MANIPULATION_WORK_NAME as the key.
         * You'll also need to pass in a ExistingWorkPolicy.
         * Your options are REPLACE, KEEP or APPEND.
         */ WorkContinuation continuation = mWorkManager . beginUniqueWork ( IMAGE_MANIPULATION_WORK_NAME , /**
                         * You'll use REPLACE because if the user decides to blur
                         * another image before the current one is finished,
                         * we want to stop the current one and start blurring the new image.
                         * Blur-O-Matic will now only ever blur one picture at a time.
                         */ ExistingWorkPolicy . REPLACE , OneTimeWorkRequest . from ( CleanupWorker . class ) ) ; for ( int i = 0 ; i < blurLevel ; i ++ ) { OneTimeWorkRequest . Builder blurBuilder = new OneTimeWorkRequest . Builder ( BlurWorker . class ) ; if ( i == 0 ) { blurBuilder . setInputData ( createInputDataForUri ( ) ) ; } continuation = continuation . then ( blurBuilder . build ( ) ) ; } Constraints constraints = new Constraints . Builder ( ) . setRequiresCharging ( true ) . build ( ) ; OneTimeWorkRequest save = new OneTimeWorkRequest . Builder ( SaveImageToFileWorker . class ) . setConstraints ( constraints ) . addTag ( TAG_OUTPUT ) . build ( ) ; continuation = continuation . then ( save ) ; continuation . enqueue ( ) ; }
Create the WorkRequest to apply the blur and save the resulting image
 @param blurLevel The amount to blur the image
Create the WorkRequest to apply the blur and save the resulting image @param blurLevel The amount to blur the image
// Add WorkRequest to Cleanup temporary images // Add WorkRequests to blur the image the number of times requested // Input the Uri if this is the first blur operation // After the first blur operation the input will be the output of previous // blur operations. // Create charging constraint // Add WorkRequest to save the image to the filesystem // This adds the Constraints // This adds the tag // Actually start the work