本文整理匯總了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);
}