Search in sources :

Example 6 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project remusic by aa112901.

the class SimpleWidgetProvider method pushUpdate.

// 更新所有的 widget
private synchronized void pushUpdate(final Context context, AppWidgetManager appWidgetManager, boolean updateProgress) {
    pushAction(context, MediaService.SEND_PROGRESS);
    RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.simple_control_widget_layout);
    //将按钮与点击事件绑定
    remoteView.setOnClickPendingIntent(R.id.widget_play, getPendingIntent(context, R.id.widget_play));
    remoteView.setOnClickPendingIntent(R.id.widget_pre, getPendingIntent(context, R.id.widget_pre));
    remoteView.setOnClickPendingIntent(R.id.widget_next, getPendingIntent(context, R.id.widget_next));
    remoteView.setOnClickPendingIntent(R.id.widget_love, getPendingIntent(context, R.id.widget_love));
    remoteView.setTextViewText(R.id.widget_content, trackname == null && art == null ? "" : trackname + "-" + art);
    remoteView.setProgressBar(R.id.widget_progress, (int) duration, (int) position, false);
    isFav = false;
    long[] favlists = PlaylistsManager.getInstance(context).getPlaylistIds(IConstants.FAV_PLAYLIST);
    for (long i : favlists) {
        if (currentId == i) {
            isFav = true;
            break;
        }
    }
    if (isFav) {
        remoteView.setImageViewResource(R.id.widget_love, R.drawable.widget_unstar_selector);
    } else {
        remoteView.setImageViewResource(R.id.widget_love, R.drawable.widget_star_selector);
    }
    if (isPlaying) {
        remoteView.setImageViewResource(R.id.widget_play, R.drawable.widget_pause_selector);
    } else {
        remoteView.setImageViewResource(R.id.widget_play, R.drawable.widget_play_selector);
    }
    if (updateProgress) {
        if (albumuri == null) {
            remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
        } else {
            if (isTrackLocal) {
                Bitmap bitmap = ImageUtils.getArtworkQuick(context, Uri.parse(albumuri), 160, 160);
                if (bitmap != null) {
                    remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
                } else {
                    remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
                }
            } else {
                Bitmap bitmap = albumMap.get(albumuri);
                if (bitmap != null)
                    remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
            }
        }
    } else {
        if (albumuri == null) {
            remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
        } else {
            if (isTrackLocal) {
                final Bitmap bitmap = ImageUtils.getArtworkQuick(context, Uri.parse(albumuri), 160, 160);
                if (bitmap != null) {
                    remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
                } else {
                    remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
                }
                albumMap.clear();
            } else {
                if (albumMap.get(albumuri) != null) {
                    remoteView.setImageViewBitmap(R.id.widget_image, albumMap.get(albumuri));
                //noBit = null;
                } else {
                    Uri uri = Uri.parse(albumuri);
                    if (uri == null) {
                        noBit = BitmapFactory.decodeResource(context.getResources(), R.drawable.placeholder_disk_210);
                        albumMap.put(albumuri, noBit);
                        pushUpdate(context, AppWidgetManager.getInstance(context), false);
                    } else {
                        ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setProgressiveRenderingEnabled(true).build();
                        ImagePipeline imagePipeline = Fresco.getImagePipeline();
                        DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
                        dataSource.subscribe(new BaseBitmapDataSubscriber() {

                            @Override
                            public void onNewResultImpl(@Nullable Bitmap bitmap) {
                                // No need to do any cleanup.
                                if (bitmap != null) {
                                    noBit = bitmap.copy(bitmap.getConfig(), true);
                                    albumMap.put(albumuri, noBit);
                                }
                                pushUpdate(context, AppWidgetManager.getInstance(context), false);
                            }

                            @Override
                            public void onFailureImpl(DataSource dataSource) {
                                // No cleanup required here.
                                noBit = BitmapFactory.decodeResource(context.getResources(), R.drawable.placeholder_disk_210);
                                albumMap.put(albumuri, noBit);
                                pushUpdate(context, AppWidgetManager.getInstance(context), false);
                            }
                        }, CallerThreadExecutor.getInstance());
                    }
                }
            }
        }
    }
    // 相当于获得所有本程序创建的appwidget
    ComponentName componentName = new ComponentName(context, SimpleWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteView);
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) Uri(android.net.Uri) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ComponentName(android.content.ComponentName) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline)

Example 7 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project remusic by aa112901.

the class LoodView method initUI.

/**
     * 初始化UI
     *
     * @param context
     */
private void initUI(Context context) {
    LayoutInflater.from(context).inflate(R.layout.load_view, this, true);
    for (String imagesID : imageNet) {
        final SimpleDraweeView mAlbumArt = new SimpleDraweeView(context);
        ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {

            @Override
            public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
                if (imageInfo == null) {
                    return;
                }
                QualityInfo qualityInfo = imageInfo.getQualityInfo();
                FLog.d("Final image received! " + "Size %d x %d", "Quality level %d, good enough: %s, full quality: %s", imageInfo.getWidth(), imageInfo.getHeight(), qualityInfo.getQuality(), qualityInfo.isOfGoodEnoughQuality(), qualityInfo.isOfFullQuality());
            }

            @Override
            public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
            //FLog.d("Intermediate image received");
            }

            @Override
            public void onFailure(String id, Throwable throwable) {
                mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
            }
        };
        Uri uri = null;
        try {
            uri = Uri.parse(imagesID);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (uri != null) {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(mAlbumArt.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            mAlbumArt.setController(controller);
        } else {
            mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
        }
        //view.setImageURI(Uri.parse(imagesID));
        // view.setImageResource(imagesID);
        // view.setImageResource(imagesID);
        mAlbumArt.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageViewList.add(mAlbumArt);
    }
    dotViewList.add(findViewById(R.id.v_dot1));
    dotViewList.add(findViewById(R.id.v_dot2));
    dotViewList.add(findViewById(R.id.v_dot3));
    dotViewList.add(findViewById(R.id.v_dot4));
    dotViewList.add(findViewById(R.id.v_dot5));
    dotViewList.add(findViewById(R.id.v_dot6));
    dotViewList.add(findViewById(R.id.v_dot7));
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setFocusable(true);
    fPagerAdapter = new FPagerAdapter();
    viewPager.setAdapter(fPagerAdapter);
    viewPager.addOnPageChangeListener(new MyPageChangeListener());
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) DraweeController(com.facebook.drawee.interfaces.DraweeController) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) Uri(android.net.Uri) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Nullable(android.support.annotation.Nullable)

Example 8 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project remusic by aa112901.

the class RoundView method setAlbum.

public void setAlbum(String albumPath) {
    if (albumPath == null) {
        albumView.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_play_song));
    } else {
        try {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(albumView.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            albumView.setController(controller);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    Log.e("roundview", "setalbum = " + albumPath);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 9 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project actor-platform by actorapp.

the class PhotoHolder method bindImage.

public void bindImage(Uri uri) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(previewView.getLayoutParams().width, previewView.getLayoutParams().height)).build();
    PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(previewView.getController()).setImageRequest(request).setControllerListener(animationController).build();
    previewView.setController(controller);
}
Also used : PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 10 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project actor-platform by actorapp.

the class StickerView method bind.

public void bind(FileReference fileReference, int size) {
    if (this.fileReference != null && this.fileReference.equals(fileReference)) {
        return;
    }
    if (bindedFile != null) {
        bindedFile.detach();
        bindedFile = null;
    }
    setImageURI(null);
    this.fileReference = fileReference;
    bindedFile = messenger().bindFile(fileReference, true, new FileVMCallback() {

        private boolean isFastThumbLoaded = false;

        private void checkFastThumb() {
            if (!isFastThumbLoaded) {
                isFastThumbLoaded = true;
            //                    if (sticker.getThumb() != null) {
            //                        fastThumbLoader.request(sticker.getThumb());
            //                    }
            }
        }

        @Override
        public void onNotDownloaded() {
            checkFastThumb();
        }

        @Override
        public void onDownloading(float progress) {
            checkFastThumb();
        }

        @Override
        public void onDownloaded(FileSystemReference reference) {
            imageFile = new File(reference.getDescriptor());
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(imageFile)).setAutoRotateEnabled(true).build();
            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
            setController(controller);
            loaded = true;
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)62 DraweeController (com.facebook.drawee.interfaces.DraweeController)20 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)17 CloseableReference (com.facebook.common.references.CloseableReference)14 Uri (android.net.Uri)10 File (java.io.File)10 Bitmap (android.graphics.Bitmap)9 CacheKey (com.facebook.cache.common.CacheKey)9 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)8 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 DataSource (com.facebook.datasource.DataSource)6 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)5 Animatable (android.graphics.drawable.Animatable)4 Nullable (android.support.annotation.Nullable)4 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)4 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)4 QualityInfo (com.facebook.imagepipeline.image.QualityInfo)4 FileSystemReference (im.actor.runtime.files.FileSystemReference)4 Test (org.junit.Test)4