Tasks/src/main/java/com/dummies/tasks/fragment/TaskEditFragment.java
@Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor task) {
        // Sanity check.  If we weren't able to load anything,
        // then just close this activity.
        if (task.getCount() == 0) {
            // onLoadFinished is called from a background thread.  Many
            // operations that affect the UI aren't allowed from
            // background threads.  So make sure that we call
            // finishEditingTask from the UI thread instead of from a
            // background thread.
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ((OnEditFinished) getActivity()).finishEditingTask();
                }
            });
            return;
        }

        // Set our title and notes from the DB
        titleText.setText(task.getString(task
                .getColumnIndexOrThrow(TaskProvider.COLUMN_TITLE)));
        notesText.setText(task.getString(task
                .getColumnIndexOrThrow(TaskProvider.COLUMN_NOTES)));

        // The task date from the database
        Long dateInMillis = task.getLong(task
                .getColumnIndexOrThrow(
                        TaskProvider.COLUMN_DATE_TIME));
        Date date = new Date(dateInMillis);
        taskDateAndTime.setTime(date);

        // Set the thumbnail image
        Picasso.with(getActivity())
                .load(TaskProvider.getImageUrlForTask(taskId))
                .into(imageView, new Callback() {
                    @SuppressWarnings({"PointlessBooleanExpression",
                        "ConstantConditions"})
                    @Override
                    public void onSuccess() {
                        Activity activity = getActivity();

                        // Because Picasso downloads images in the
                        // background, we can't be sure that the user
                        // didn't close the activity while the image
                        // was being loaded.  If they did,
                        // we will bomb out, so check do a sanity check
                        // to be sure.
                        if( activity==null )
                            return;

                        // Don't do this for tablets, only phones,
                        // since it doesn't really work with a split
                        // screen view.
                        if( !BuildConfig.SHOULD_USE_PALETTE )
                            return;

                        // Set the colors of the activity based on the
                        // colors of the image, if available
                        Bitmap bitmap = ((BitmapDrawable) imageView
                                .getDrawable())
                                .getBitmap();
                        Palette palette = Palette.generate(bitmap, 32);
                        int bgColor = palette.getLightMutedColor(0);

                        if( bgColor!=0 ) {
                            rootView.setBackgroundColor(bgColor);
                        }
                    }

                    @Override
                    public void onError() {
                        // do nothing, we'll use the default colors
                    }
                });

        // We updated our task info, so update the date and time buttons
        updateDateAndTimeButtons();
    }
/**
     * This methid is called when the loader has finished loading its
     * data
     */
This methid is called when the loader has finished loading its
data
This methid is called when the loader has finished loading its data
@Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor task) {
        if (task.getCount() == 0) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ((OnEditFinished) getActivity()).finishEditingTask();
                }
            });
            return;
        }
        titleText.setText(task.getString(task
                .getColumnIndexOrThrow(TaskProvider.COLUMN_TITLE)));
        notesText.setText(task.getString(task
                .getColumnIndexOrThrow(TaskProvider.COLUMN_NOTES)));
        Long dateInMillis = task.getLong(task
                .getColumnIndexOrThrow(
                        TaskProvider.COLUMN_DATE_TIME));
        Date date = new Date(dateInMillis);
        taskDateAndTime.setTime(date);
        Picasso.with(getActivity())
                .load(TaskProvider.getImageUrlForTask(taskId))
                .into(imageView, new Callback() {
                    @SuppressWarnings({"PointlessBooleanExpression",
                        "ConstantConditions"})
                    @Override
                    public void onSuccess() {
                        Activity activity = getActivity();
                        if( activity==null )
                            return;
                        if( !BuildConfig.SHOULD_USE_PALETTE )
                            return;
                        Bitmap bitmap = ((BitmapDrawable) imageView
                                .getDrawable())
                                .getBitmap();
                        Palette palette = Palette.generate(bitmap, 32);
                        int bgColor = palette.getLightMutedColor(0);
                        if( bgColor!=0 ) {
                            rootView.setBackgroundColor(bgColor);
                        }
                    }
                    @Override
                    public void onError() {
                    }
                });
        updateDateAndTimeButtons();
    }
@ Override public void onLoadFinished ( Loader < Cursor > loader , Cursor task ) { if ( task . getCount ( ) == 0 ) { getActivity ( ) . runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { ( ( OnEditFinished ) getActivity ( ) ) . finishEditingTask ( ) ; } } ) ; return ; } titleText . setText ( task . getString ( task . getColumnIndexOrThrow ( TaskProvider . COLUMN_TITLE ) ) ) ; notesText . setText ( task . getString ( task . getColumnIndexOrThrow ( TaskProvider . COLUMN_NOTES ) ) ) ; Long dateInMillis = task . getLong ( task . getColumnIndexOrThrow ( TaskProvider . COLUMN_DATE_TIME ) ) ; Date date = new Date ( dateInMillis ) ; taskDateAndTime . setTime ( date ) ; Picasso . with ( getActivity ( ) ) . load ( TaskProvider . getImageUrlForTask ( taskId ) ) . into ( imageView , new Callback ( ) { @ SuppressWarnings ( { "PointlessBooleanExpression" , "ConstantConditions" } ) @ Override public void onSuccess ( ) { Activity activity = getActivity ( ) ; if ( activity == null ) return ; if ( ! BuildConfig . SHOULD_USE_PALETTE ) return ; Bitmap bitmap = ( ( BitmapDrawable ) imageView . getDrawable ( ) ) . getBitmap ( ) ; Palette palette = Palette . generate ( bitmap , 32 ) ; int bgColor = palette . getLightMutedColor ( 0 ) ; if ( bgColor != 0 ) { rootView . setBackgroundColor ( bgColor ) ; } } @ Override public void onError ( ) { } } ) ; updateDateAndTimeButtons ( ) ; }
This methid is called when the loader has finished loading its
 data
This methid is called when the loader has finished loading its data
// Sanity check.  If we weren't able to load anything, // then just close this activity. // onLoadFinished is called from a background thread.  Many // operations that affect the UI aren't allowed from // background threads.  So make sure that we call // finishEditingTask from the UI thread instead of from a // background thread. // Set our title and notes from the DB // The task date from the database // Set the thumbnail image // Because Picasso downloads images in the // background, we can't be sure that the user // didn't close the activity while the image // was being loaded.  If they did, // we will bomb out, so check do a sanity check // to be sure. // Don't do this for tablets, only phones, // since it doesn't really work with a split // screen view. // Set the colors of the activity based on the // colors of the image, if available // do nothing, we'll use the default colors // We updated our task info, so update the date and time buttons