List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:de.s2hmobile.bitmaps.ImageCache.java
@SuppressWarnings("deprecation") private static int getUsableSpaceFroyo(final File path) { final StatFs stats = new StatFs(path.getPath()); return stats.getBlockSize() * stats.getAvailableBlocks(); }
From source file:cz.muni.fi.japanesedictionary.parser.ParserService.java
/** * Downloads dictionaries.//from w w w . j av a2 s .c om */ protected void onHandleIntent() { Log.i(LOG_TAG, "Creating parser service"); Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this).setAutoCancel(false).setOngoing(true) .setContentTitle(getString(R.string.dictionary_download_title)) .setContentText(getString(R.string.dictionary_download_in_progress) + " (1/5)") .setSmallIcon(R.drawable.ic_notification).setProgress(100, 0, false).setContentInfo("0%") .setContentIntent(resultPendingIntent); startForeground(0, mNotification); mNotifyManager.notify(0, mBuilder.build()); File storage; if (MainActivity.canWriteExternalStorage()) { // external storage available storage = getExternalCacheDir(); } else { storage = getCacheDir(); } if (storage == null) { throw new IllegalStateException("External storage isn't accessible"); } // free sapce controll StatFs stat = new StatFs(storage.getPath()); long bytesAvailable; if (Build.VERSION.SDK_INT < 18) { bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks(); } else { bytesAvailable = stat.getAvailableBytes(); } long megAvailable = bytesAvailable / 1048576; Log.d(LOG_TAG, "Megs free :" + megAvailable); if (megAvailable < 140) { mInternetReceiver = null; mNotEnoughSpace = true; stopSelf(mStartId); return; } this.registerReceiver(mInternetReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean english = sharedPrefs.getBoolean("language_english", false); boolean french = sharedPrefs.getBoolean("language_french", false); boolean dutch = sharedPrefs.getBoolean("language_dutch", false); boolean german = sharedPrefs.getBoolean("language_german", false); boolean russian = sharedPrefs.getBoolean("language_russian", false); if (!english && !french && !dutch && !german && !russian) { Log.i(LOG_TAG, "Setting english as only translation language"); SharedPreferences.Editor editor_lang = sharedPrefs.edit(); editor_lang.putBoolean("language_english", true); editor_lang.commit(); } String dictionaryPath; String kanjiDictPath; URL url; try { url = new URL(ParserService.DICTIONARY_PATH); } catch (MalformedURLException ex) { Log.e(LOG_TAG, "Error: creating url for downloading dictionary"); return; } try { dictionaryPath = storage.getPath() + File.separator + "dictionary.zip"; File outputFile = new File(dictionaryPath); if (outputFile.exists()) { outputFile.delete(); } mDownloadJMDictFrom = url; mDownloadJMDictTo = outputFile; mDownloadingJMDict = true; mDownloadInProgress = true; // downloading kanjidict url = null; try { url = new URL(ParserService.KANJIDICT_PATH); } catch (MalformedURLException ex) { Log.e(LOG_TAG, "Error: creating url for downloading kanjidict2"); } if (url != null) { kanjiDictPath = storage.getPath() + File.separator + "kanjidict.zip"; File fileKanjidict = new File(kanjiDictPath); if (fileKanjidict.exists()) { fileKanjidict.delete(); } mDownloadingKanjidic = false; mDownloadKanjidicFrom = url; mDownloadKanjidicTo = fileKanjidict; } mDownloadTatoebaIndicesFrom = new URL(ParserService.TATOEBA_INDICES_PATH); mDownloadTatoebaIndicesTo = new File(storage, "tatoeba-japanese.zip"); if (mDownloadTatoebaIndicesTo.exists()) { mDownloadTatoebaIndicesTo.delete(); } mDownloadTatoebaSentencesFrom = new URL(ParserService.TATOEBA_SENTENCES_PATH); mDownloadTatoebaSentencesTo = new File(storage, "tatoeba-translation.zip"); if (mDownloadTatoebaSentencesTo.exists()) { mDownloadTatoebaSentencesTo.delete(); } mDownloadKanjiVGFrom = new URL(ParserService.KANJIVG_PATH); mDownloadKanjiVGTo = new File(storage, "kanjivg.zip"); if (mDownloadKanjiVGTo.exists()) { mDownloadKanjiVGTo.delete(); } downloadDictionaries(); } catch (MalformedURLException e) { Log.e(LOG_TAG, "MalformedURLException wrong format of URL: " + e.toString()); stopSelf(mStartId); } catch (IOException e) { Log.e(LOG_TAG, "IOException downloading interrupted: " + e.toString()); stopSelf(mStartId); } catch (Exception e) { e.printStackTrace(); Log.e(LOG_TAG, "Exception: " + e.toString()); stopSelf(mStartId); } }
From source file:com.codingPower.framework.worker.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/*from w w w . j a v a 2 s . c o m*/ * @return The space available in bytes */ public static long getUsableSpace(File path) { final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:net.iaf.framework.imgload.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check// www.java 2 s . c o m * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { if (SDKVersionUtil.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.shine.hotels.util.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check//from w w w. ja v a 2s . c o m * @return The space available in bytes */ //@TargetApi(9) public static long getUsableSpace(File path) { // if (UIUtils.hasGingerbread()) { // return path.getUsableSpace(); // } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.fivehundredpxdemo.android.storage.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check//from w w w . ja v a 2s. c o m * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.example.image.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/*from w ww. j a v a2s. c o m*/ * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { if (VersionUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:android.support.asy.image.ImageCache.java
/** * Check how much usable space is available at a given path. * /*from w ww. j a v a 2 s . c o m*/ * @param path * The path to check * @return The space available in bytes */ public static long getUsableSpace(File path) { // if (Utils.hasGingerbread()) { // return path.getUsableSpace(); // } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.wowcow.chat10.imagecache.ImageCache.java
/** * Check how much usable space is available at a given path. * /*from w ww . j av a 2 s . c o m*/ * @param path * The path to check * @return The space available in bytes */ @SuppressWarnings("deprecation") @TargetApi(9) public static long getUsableSpace(File path) { if (VersionUtil.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.andreaszeiser.bob.ImageCache.java
/** * Check how much usable space is available at a given path. * //from ww w. j av a2s . c o m * @param path * The path to check * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { if (UIUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }