當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。