예제 #1
0
 @Override
 protected void onStop() {
   HttpResponseCache cache = HttpResponseCache.getInstalled();
   if (cache != null) {
     cache.flush();
   }
   super.onStop();
 }
예제 #2
0
 static Object install(Context context) throws IOException {
   File cacheDir = Utils.createDefaultCacheDir(context);
   HttpResponseCache cache = HttpResponseCache.getInstalled();
   if (cache == null) {
     int maxSize = Utils.calculateDiskCacheSize(cacheDir);
     cache = HttpResponseCache.install(cacheDir, maxSize);
   }
   return cache;
 }
 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
 @Override
 protected void onStop() {
   super.onStop();
   HttpResponseCache cache = HttpResponseCache.getInstalled();
   if (cache != null) {
     cache.flush();
   }
 }
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lista);

    try {
      File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http");
      long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
      HttpResponseCache.install(httpCacheDir, httpCacheSize);
    } catch (IOException e) {
      Log.i("TAG", "HTTP response cache installation failed:" + e);
    }

    produtosBD = new ArrayList<>();

    lista = (ListView) findViewById(R.id.listView);
    autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);

    baseProgressBar = (LinearLayout) findViewById(R.id.baseProgressBar);

    ctx = this;

    minhaLista = new ArrayList<>();

    bundle = getIntent().getExtras();

    new GetListaWS().execute();
  }
예제 #5
0
 @Override
 public void close() throws IOException {
   if (ResponseCache.getDefault() == this.delegate) {
     ResponseCache.setDefault(null);
   }
   delegate.close();
 }
예제 #6
0
 /*
  * enable caching for HttpUrlConnection
  * http://developer.android.com/training/efficient-downloads/redundant_redundant.html
  */
 private static void enableHttpResponseCache(Context context) {
   try {
     long httpCacheSize = 5 * 1024 * 1024; // 5MB
     File httpCacheDir = new File(context.getCacheDir(), "http");
     HttpResponseCache.install(httpCacheDir, httpCacheSize);
   } catch (IOException e) {
     AppLog.w(T.UTILS, "Failed to enable http response cache");
   }
 }
예제 #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
      File httpCacheDir = new File(getCacheDir(), "http");
      long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
      HttpResponseCache.install(httpCacheDir, httpCacheSize);
    } catch (IOException e) {
      Log.i(TAG, "HTTP response cache installation failed:" + e);
    }

    dh1 = (Button) findViewById(R.id.dh1);
    dh2 = (Button) findViewById(R.id.dh2);
    about = (Button) findViewById(R.id.about);
    dh1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            flg = 0;
            if (isConnected()) {

              new fetchMenu().execute("dh1");

            } else {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.NoInternet), Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
    dh2.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            flg = 1;
            if (isConnected()) {

              new fetchMenu().execute("dh2");

            } else {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.NoInternet), Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
    about.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent in = new Intent(MainActivity.this, info.class);
            startActivity(in);
          }
        });
  }
예제 #8
0
 private void installHtppCache() {
   try {
     File dir = getCacheDir();
     File httpCacheDir = new File(dir, "logoCache");
     long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
     HttpResponseCache.install(httpCacheDir, httpCacheSize);
   } catch (IOException e) {
     Log.i(getClass().getSimpleName(), "HTTP response cache installation failed:" + e);
   }
 }
예제 #9
0
  public static HttpResponseCache install(Context context) throws IOException {
    ResponseCache installed = ResponseCache.getDefault();
    if (installed instanceof Closeable) {
      ((Closeable) installed).close();
    }

    File directory = SystemUtils.getCacheDir(context, "http");
    long maxSize =
        SystemUtils.calculateDiskCacheSize(directory, MIN_DISK_CACHE_SIZE, MAX_DISK_CACHE_SIZE);

    return new HttpResponseCache(android.net.http.HttpResponseCache.install(directory, maxSize));
  }
예제 #10
0
 private static void flushHttpCache() {
   HttpResponseCache cache = HttpResponseCache.getInstalled();
   if (cache != null) {
     cache.flush();
   }
 }
예제 #11
0
 @Override
 public CacheRequest put(URI uri, URLConnection connection) throws IOException {
   return delegate.put(uri, connection);
 }
예제 #12
0
 @Override
 public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders)
     throws IOException {
   return delegate.get(uri, requestMethod, requestHeaders);
 }