当前位置: 首页>>代码示例>>Java>>正文


Java Application.getCacheDir方法代码示例

本文整理汇总了Java中android.app.Application.getCacheDir方法的典型用法代码示例。如果您正苦于以下问题:Java Application.getCacheDir方法的具体用法?Java Application.getCacheDir怎么用?Java Application.getCacheDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Application的用法示例。


在下文中一共展示了Application.getCacheDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: provideOkHttpClient

import android.app.Application; //导入方法依赖的package包/类
/**
 * Provide  okhttpclient
 * interceptors can be used for extension(add user token on the http header for example)
 *
 * @param app                 the Application context
 * @param interceptors        interceptors that implements {@link Interceptor}
 * @param networkInterceptors
 * @return the okhttp client
 */
@Provides
@Singleton
public OkHttpClient provideOkHttpClient(Application app,
                                        @OkHttpInterceptors
                                        @NonNull List<Interceptor> interceptors,
                                        @OkHttpNetworkInterceptors
                                        @NonNull List<Interceptor> networkInterceptors) {
    OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder()
            .connectTimeout(Config.HTTP_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
            .readTimeout(Config.HTTP_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    for (Interceptor interceptor : interceptors) {
        okHttpBuilder.addInterceptor(interceptor);
    }

    for (Interceptor networkInterceptor : networkInterceptors) {
        okHttpBuilder.addNetworkInterceptor(networkInterceptor);
    }
    //Offline mode
    File httpCacheDirectory = new File(app.getCacheDir(), "network_cache");
    okHttpBuilder
            .cache(new Cache(httpCacheDirectory, Config.HTTP_CACHE_FILE_SIZE))
            .addInterceptor(OkHttpUtils.OFFLINE_INTERCEPTOR)
            .addNetworkInterceptor(OkHttpUtils.REWRITE_RESPONSE_INTERCEPTOR);
    return okHttpBuilder.build();
}
 
开发者ID:OHoussein,项目名称:Android-Show-Reader,代码行数:35,代码来源:NetModule.java

示例2: setUp

import android.app.Application; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  Application context = RuntimeEnvironment.application;

  ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class);
  when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
  when(factory.buildParser()).thenReturn(parser);
  when(factory.buildEncoder()).thenReturn(gifEncoder);
  when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class)))
      .thenReturn(frameResource);

  // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
  when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt()))
      .thenReturn(frameResource);

  when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);
  when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0));

  when(resource.get()).thenReturn(gifDrawable);

  encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory);
  options = new Options();
  options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true);

  file = new File(context.getCacheDir(), "test");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:ReEncodingGifResourceEncoderTest.java

示例3: setUp

import android.app.Application; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  Application context = RuntimeEnvironment.application;

  ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class);
  when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
  when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
  when(factory.buildParser()).thenReturn(parser);
  when(factory.buildEncoder()).thenReturn(gifEncoder);
  when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class)))
      .thenReturn(frameResource);

  // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
  when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt()))
      .thenReturn(frameResource);

  when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);
  when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0));

  when(resource.get()).thenReturn(gifDrawable);

  encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory);
  options = new Options();
  options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true);

  file = new File(context.getCacheDir(), "test");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:ReEncodingGifResourceEncoderTest.java

示例4: getDir

import android.app.Application; //导入方法依赖的package包/类
private File getDir(){
    Application app = getApplication();
    if(app.getExternalCacheDir()==null){
        return app.getCacheDir();
    }else{
        return app.getExternalCacheDir();
    }
}
 
开发者ID:moeoverflow,项目名称:PixivForMuzeiPlus,代码行数:9,代码来源:PixivSource.java

示例5: createOkHttpClient

import android.app.Application; //导入方法依赖的package包/类
static OkHttpClient.Builder createOkHttpClient(Application app) {
  // Install an HTTP cache in the application cache directory.
  File cacheDir = new File(app.getCacheDir(), "http");
  Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

  return new OkHttpClient.Builder()
      .cache(cache);
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:9,代码来源:DataModule.java

示例6: provideOkHttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
    int cacheSize = 20 * 1024 * 1024; // 20 MiB
    Cache cache = new Cache(application.getCacheDir(), cacheSize);
    return cache;
}
 
开发者ID:Jusenr,项目名称:androidgithub,代码行数:8,代码来源:NetModule.java

示例7: start

import android.app.Application; //导入方法依赖的package包/类
/**
 * Inicia uma instancia da lib PlainRequest
 * utilizando cache do volley
 *
 * @param app
 * @param sizeCache // tamanho do cache em MB
 */
public void start(Application app, int sizeCache) {
    if(context == null) {
        context = app.getApplicationContext();
        // Cache
        Cache cache = new DiskBasedCache(app.getCacheDir(), (1024 * 1024) * sizeCache);
        Network network = new BasicNetwork(new HurlStack());
        queue = new RequestQueue(cache, network); // Criação do RequestQueue
    }
}
 
开发者ID:giovanimoura,项目名称:plainrequest,代码行数:17,代码来源:PlainRequestQueue.java

示例8: BaseSuggestionsModel

import android.app.Application; //导入方法依赖的package包/类
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
    mEncoding = encoding;
    mLanguage = getLanguage();
    File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
    mHttpClient = new OkHttpClient.Builder()
        .cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
        .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
        .build();
    mCacheControl = new CacheControl.Builder().maxStale(1, TimeUnit.DAYS).build();
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:11,代码来源:BaseSuggestionsModel.java

示例9: provideOkHttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideOkHttpCache(Application application){
    int cacheSize = 10 * 1024 * 1024;  // 10 MB
    return new Cache(application.getCacheDir(),cacheSize);
}
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:7,代码来源:NetModule.java

示例10: provideOkHttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
    int cacheSize = 10 * 1024 * 1024; // 10 MiB
    return new Cache(application.getCacheDir(), cacheSize);
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:7,代码来源:ApiModule.java

示例11: provideOkhttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
static Cache provideOkhttpCache(Application application) {
    return new Cache(application.getCacheDir(), CACHE_SIZE);
}
 
开发者ID:ragdroid,项目名称:Dahaka,代码行数:6,代码来源:ApiModule.java

示例12: getFaviconFile

import android.app.Application; //导入方法依赖的package包/类
@NonNull
private static File getFaviconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), FOLDER_ICON);
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:5,代码来源:BookmarkPage.java

示例13: getDefaultIconFile

import android.app.Application; //导入方法依赖的package包/类
@NonNull
private static File getDefaultIconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), DEFAULT_ICON);
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:5,代码来源:BookmarkPage.java

示例14: provideHttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideHttpCache(Application application) {
    int cacheSize = 10 * 1024 * 1024;        // 10 MB
    return new Cache(application.getCacheDir(), cacheSize);
}
 
开发者ID:bojanb89pa,项目名称:OAuth2Android,代码行数:7,代码来源:APIModule.java

示例15: provideHttpCache

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideHttpCache(Application application) {
    return new Cache(application.getCacheDir(), CACHE_SIZE);
}
 
开发者ID:pabloserranof,项目名称:GuardianReader,代码行数:6,代码来源:NetModule.java


注:本文中的android.app.Application.getCacheDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。