com.squareup.picasso.OkHttpDownloader Java Examples

The following examples show how to use com.squareup.picasso.OkHttpDownloader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Capabilities.java    From ChatApp with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate()
{
    super.onCreate();

    // For offline use

    FirebaseDatabase.getInstance().setPersistenceEnabled(true);

    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));

    Picasso build = builder.build();
    build.setLoggingEnabled(true);
    Picasso.setSingletonInstance(build);

    // If user disconnect

    if(FirebaseAuth.getInstance().getCurrentUser() != null)
    {
        final DatabaseReference userDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
        userDatabase.addValueEventListener(new ValueEventListener()
        {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot)
            {
                if(dataSnapshot != null)
                {
                    userDatabase.child("online").onDisconnect().setValue(ServerValue.TIMESTAMP);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError)
            {
                Log.d(TAG, "usersDatabase failed: " + databaseError.getMessage());
            }
        });
    }
}
 
Example #2
Source File: SimpleBlog.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (!FirebaseApp.getApps(this).isEmpty()) {
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);//offlinecapability
    }
    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));
    Picasso built = builder.build();
    built.setIndicatorsEnabled(false);
    built.setLoggingEnabled(true);
    Picasso.setSingletonInstance(built);
}
 
Example #3
Source File: App.java    From PhotoDiscovery with Apache License 2.0 5 votes vote down vote up
private void initPicasso() {
  File cacheDirectory = new File(getCacheDir().getAbsolutePath(), "OKHttpCache");

  OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setCache(new Cache(cacheDirectory, Integer.MAX_VALUE));

  /** Dangerous interceptor that rewrites the server's cache-control header. */
  okHttpClient.networkInterceptors().add(new Interceptor() {
    @Override public Response intercept(Chain chain) throws IOException {
      Response originalResponse = chain.proceed(chain.request());
      return originalResponse.newBuilder()
          .header("Cache-Control", "public, max-age=432000")
          .header("Pragma", "")
          .build();
    }
  });

  OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient);

  Picasso.Builder builder = new Picasso.Builder(this);
  builder.downloader(okHttpDownloader);

  Picasso picasso = builder.build();
  //picasso.setIndicatorsEnabled(true);
  //picasso.setLoggingEnabled(true);
  Picasso.setSingletonInstance(picasso);
}
 
Example #4
Source File: MyApplication.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
private void initPicasso() {
        Picasso.Builder builder = new Picasso.Builder(this);
        builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));
        Picasso built = builder.build();
//        built.setIndicatorsEnabled(true);
//        built.setLoggingEnabled(true);
        Picasso.setSingletonInstance(built);
    }
 
Example #5
Source File: PicassoConfigFactory.java    From ImageLoadPK with Apache License 2.0 5 votes vote down vote up
public static Picasso getPicasso(Context context) {
        if (sPicasso == null) {
            sPicasso = new Picasso.Builder(context)
                    //硬盘缓存池大小
                    .downloader(new OkHttpDownloader(context, ConfigConstants.MAX_CACHE_DISK_SIZE))
                    //内存缓存池大小
                    .memoryCache(new LruCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE))
//                    .defaultBitmapConfig(Bitmap.Config.ARGB_4444)
                    .build();
        }
        return sPicasso;
    }
 
Example #6
Source File: DataModule.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app)
            .downloader(new OkHttpDownloader(client))
            .listener(new Picasso.Listener() {
                @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
                    Timber.e(e, "Failed to load image: %s", uri);
                }
            })
            .build();
}
 
Example #7
Source File: PicassoProvider.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Picasso getInstance(Context context, boolean changeCredentials) {
    if (mPicasso == null || changeCredentials) {
        OkHttpClient client = RepoManager.provideOkHttpClient(
                DhisController.getInstance().getUserCredentials(), context);
        mPicasso = new Picasso.Builder(context)
                .downloader(new OkHttpDownloader(client))
                .build();
        mPicasso.setIndicatorsEnabled(false);
        mPicasso.setLoggingEnabled(false);
    }

    return mPicasso;
}
 
Example #8
Source File: DataModule.java    From githot with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Picasso providePicasso(OkHttpClient okHttpClient, Context ctx) {
    Picasso.Builder builder = new Picasso.Builder(ctx);
    builder.downloader(new OkHttpDownloader(okHttpClient))
            .listener(new Picasso.Listener() {
                public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                    L.e(exception + "Picasso load image failed: " + uri.toString());
                }
            })
            .indicatorsEnabled(false)
            .loggingEnabled(false);
    return builder.build();
}
 
Example #9
Source File: DataModule.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Picasso providePicasso(OkHttpClient okHttpClient, Context ctx) {
    Picasso.Builder builder = new Picasso.Builder(ctx);
    builder.downloader(new OkHttpDownloader(okHttpClient))
            .listener(new Picasso.Listener() {
                public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                    Timber.e(exception, "Picasso load image failed: " + uri.toString());
                }
            })
            .indicatorsEnabled(false)
            .loggingEnabled(false);
    return builder.build();
}
 
Example #10
Source File: ImageFragment.java    From SteamGifts with MIT License 5 votes vote down vote up
@Override
protected byte[] doInBackground(Void... params) {
    try {
        // Grab an input stream to the image
        OkHttpDownloader downloader = new OkHttpDownloader(getContext());
        Downloader.Response response = downloader.load(Uri.parse(url), 0);

        // Read the image into a byte array
        return Okio.buffer(Okio.source(response.getInputStream())).readByteArray();
    } catch (Exception e) {
        Log.d(ImageFragment.class.getSimpleName(), "Error fetching image", e);
        return null;
    }
}
 
Example #11
Source File: DataModule.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app)
            .downloader(new OkHttpDownloader(client))
            .listener(new Picasso.Listener() {
                @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
                    Timber.e(e, "Failed to load image: %s", uri);
                }
            })
            .build();
}
 
Example #12
Source File: DebugDataSourceModule.java    From Qiitanium with MIT License 5 votes vote down vote up
@Override
public Picasso providePicasso(Application app, OkHttpClient client) {
  return new Picasso.Builder(app)
      .indicatorsEnabled(false)
      .downloader(new OkHttpDownloader(client))
      .listener(new Picasso.Listener() {
        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
          Timber.w(e, "Failed to load image: %s", uri);
        }
      })
      .build();
}
 
Example #13
Source File: HostManager.java    From Kore with Apache License 2.0 4 votes vote down vote up
/**
     * Returns the current host {@link Picasso} image downloader
     * @return {@link Picasso} instance suitable to download images from the current xbmc
     */
    public Picasso getPicasso() {
        if (currentPicasso == null) {
            currentHostInfo = getHostInfo();
            if (currentHostInfo != null) {
//                currentPicasso = new Picasso.Builder(context)
//                        .downloader(new BasicAuthUrlConnectionDownloader(context,
//                                currentHostInfo.getUsername(), currentHostInfo.getPassword()))
//                        .indicatorsEnabled(BuildConfig.DEBUG)
//                        .build();

                // Http client should already handle authentication
                OkHttpClient picassoClient = getConnection().getOkHttpClient().clone();

//                OkHttpClient picassoClient = new OkHttpClient();
//                // Set authentication on the client
//                if (!TextUtils.isEmpty(currentHostInfo.getUsername())) {
//                    picassoClient.interceptors().add(new Interceptor() {
//                        @Override
//                        public Response intercept(Chain chain) throws IOException {
//
//                            String creds = currentHostInfo.getUsername() + ":" + currentHostInfo.getPassword();
//                            Request newRequest = chain.request().newBuilder()
//                                    .addHeader("Authorization",
//                                            "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP))
//                                    .build();
//                            return chain.proceed(newRequest);
//                        }
//                    });
//                }

                // Set cache
                File cacheDir = NetUtils.createDefaultCacheDir(context);
                long cacheSize = NetUtils.calculateDiskCacheSize(cacheDir);
                picassoClient.setCache(new com.squareup.okhttp.Cache(cacheDir,cacheSize));

                currentPicasso = new Picasso.Builder(context)
                        .downloader(new OkHttpDownloader(picassoClient))
//                        .indicatorsEnabled(BuildConfig.DEBUG)
                        .build();
            }
        }

        return currentPicasso;
    }
 
Example #14
Source File: DataSourceModule.java    From Qiitanium with MIT License 4 votes vote down vote up
@Provides
public Picasso providePicasso(Application app, OkHttpClient client) {
  return new Picasso.Builder(app)
      .downloader(new OkHttpDownloader(client))
      .build();
}