本文整理汇总了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();
}
示例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");
}
示例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");
}
示例4: getDir
import android.app.Application; //导入方法依赖的package包/类
private File getDir(){
Application app = getApplication();
if(app.getExternalCacheDir()==null){
return app.getCacheDir();
}else{
return app.getExternalCacheDir();
}
}
示例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);
}
示例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;
}
示例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
}
}
示例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();
}
示例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);
}
示例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);
}
示例11: provideOkhttpCache
import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
static Cache provideOkhttpCache(Application application) {
return new Cache(application.getCacheDir(), CACHE_SIZE);
}
示例12: getFaviconFile
import android.app.Application; //导入方法依赖的package包/类
@NonNull
private static File getFaviconFile(@NonNull Application application) {
return new File(application.getCacheDir(), FOLDER_ICON);
}
示例13: getDefaultIconFile
import android.app.Application; //导入方法依赖的package包/类
@NonNull
private static File getDefaultIconFile(@NonNull Application application) {
return new File(application.getCacheDir(), DEFAULT_ICON);
}
示例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);
}
示例15: provideHttpCache
import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
Cache provideHttpCache(Application application) {
return new Cache(application.getCacheDir(), CACHE_SIZE);
}