如何在Android上将Google云端硬盘与Picasso集成?

如何在Android上将Google云端硬盘与Picasso集成?,第1张

概述我正在编写一个应用程序,将图像存储在Google云端硬盘中,我想显示这些图库(GridView).为了更高效(即异步),我想将其与毕加索结合起来.但是Picasso.load(String)只是一个加载的别名(Uri.parse(path)),我没有Uri,因为图像是这样加载的(简化和未公开的实用程序方法): public static Bitmap getBitmap(DriveId id) { 我正在编写一个应用程序,将图像存储在Google云端硬盘中,我想显示这些图库(GrIDVIEw).为了更高效(即异步),我想将其与毕加索结合起来.但是Picasso.load(String)只是一个加载的别名(Uri.parse(path)),我没有Uri,因为图像是这样加载的(简化和未公开的实用程序方法):
public static Bitmap getBitmap(DriveID ID) {    Googleapiclient clIEnt = apiclientAsyncTask.createConnectedClIEnt(App.getAppContext());    Drivefile file = Drive.DriveAPI.getfile(clIEnt,ID);    Metadata Meta = sync(file.getMetadata(clIEnt));    Contents contents = sync(file.openContents(clIEnt,Drivefile.MODE_READ_ONLY,null));    inputStream imagestream = contents.getinputStream();    try {        return BitmapFactory.decodeStream(imagestream);    } finally {        IOTools.ignorantClose(imagestream);        sync(file.discardContents(clIEnt,contents));    }}

是否有任何其他类似的库可能支持任意输入(String / Object)的集成

当然我想在Picasso中使用缓存(网络(上面的方法),磁盘,内存)的完全支持.

解决方法 当时毕加索的版本不支持我想要的东西所以我去使用了 Glide 3.这就是我设法放在一起的东西.
我还没有测试它,我把它从历史中拼凑起来,因为我从我的应用程序中删除了这个支持,这是一个过度杀伤力;但是当功能仍然存在时,它正在工作.

在ConnectionCallbacks.onConnected中:

GlIDe.get(getContext()).register(DriveID.class,inputStream.class,new DriveIDModelLoader.Factory(mClIEnt));

在ConnectionCallbacks.onConnectionSuspended中:

GlIDe.get(getContext()).unregister(DriveID.class,inputStream.class);

在列表适配器:

String driveString = cursor.getString(cursor.getColumnIndex("image"));DriveID driveID = DriveID.decodeFromString(driveString);GlIDe.with(this)     .from(DriveID.class)     .load(driveID)     .into(imageVIEw);

滑胶:

import java.io.*;import androID.content.Context;import androID.net.Uri;import com.bumptech.glIDe.load.data.DataFetcher;import com.bumptech.glIDe.load.model.*;import com.bumptech.glIDe.load.model.stream.StreamModelLoader;import com.Google.androID.gms.common.API.Googleapiclient;import com.Google.androID.gms.drive.DriveID;public class DriveIDModelLoader implements StreamModelLoader<DriveID> {    private final Googleapiclient clIEnt;    public DriveIDModelLoader(Googleapiclient clIEnt) {        this.clIEnt = clIEnt;    }    public DataFetcher<inputStream> getResourceFetcher(DriveID model,int wIDth,int height) {        return new DriveIDDataFetcher(clIEnt,model);    }    public static class Factory implements ModelLoaderFactory<DriveID,inputStream> {        private final Googleapiclient clIEnt;        public Factory(Googleapiclient clIEnt) {            this.clIEnt = clIEnt;        }        public ModelLoader<DriveID,inputStream> build(Context context,GenericLoaderFactory factorIEs) {            return new DriveIDModelLoader(clIEnt);        }        public voID teardown() {            clIEnt.disconnect();        }    }}

驱动相关的GlIDe逻辑:

import java.io.inputStream;import org.slf4j.*;import com.bumptech.glIDe.Priority;import com.bumptech.glIDe.load.data.DataFetcher;import com.Google.androID.gms.common.API.*;import com.Google.androID.gms.drive.*;public class DriveIDDataFetcher implements DataFetcher<inputStream> {    private static final Logger LOG = LoggerFactory.getLogger(DriveIDDataFetcher.class);    private final Googleapiclient clIEnt;    private final DriveID driveID;    private boolean cancelled = false;    private Drivefile file;    private Contents contents;    public DriveIDDataFetcher(Googleapiclient clIEnt,DriveID driveID) {        this.clIEnt = clIEnt;        this.driveID = driveID;    }    public String getID() {        return driveID.encodetoString();    }    public inputStream loadData(Priority priority) {        if (cancelled) return null;        if (clIEnt == null) {            LOG.warn("No connected clIEnt received,giving custom error image");            return null;        }        file = Drive.DriveAPI.getfile(clIEnt,driveID);        if (cancelled) return null;        contents = sync(file.openContents(clIEnt,null)).getContents();        if (cancelled) return null;        return contents.getinputStream();    }    public voID cancel() {        cancelled = true;        if (contents != null) {            file.discardContents(clIEnt,contents);        }    }    public voID cleanup() {        if (contents != null) {            sync(file.discardContents(clIEnt,contents));        }    }    private static <T extends Result> voID assertSuccess(T result) {        if (!result.getStatus().isSuccess()) {            throw new IllegalStateException(result.getStatus().toString());        }    }    private static <T extends Result> T sync(PendingResult<T> pending) {        T result = pending.await();        assertSuccess(result);        return result;    }}
总结

以上是内存溢出为你收集整理的如何在Android上将Google云端硬盘与Picasso集成?全部内容,希望文章能够帮你解决如何在Android上将Google云端硬盘与Picasso集成?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1131088.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存