List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:com.egoists.coco_nut.android.cache.ImageCache.java
/** * Check how much usable space is available at a given path. * /*from w ww.jav a 2 s . c o m*/ * @param path The path to check * @return The space available in bytes */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static long getUsableSpace(File path) { if (EtcUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:id.wibisana.priadimulia.imagecaching.cache.ImageCache.java
@SuppressWarnings("deprecation") @TargetApi(9)/*from ww w . j a va2s . c om*/ 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.colorchen.qbase.utils.FileUtil.java
/** * ????.//from w ww . ja v a 2 s . c o m */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static long getDirSize(String path) { StatFs stat = new StatFs(path); long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= 18) { blockSize = stat.getBlockSizeLong(); availableBlocks = stat.getAvailableBlocksLong(); } else { blockSize = stat.getBlockSize(); availableBlocks = stat.getAvailableBlocks(); } return availableBlocks * blockSize; }
From source file:org.brandroid.openmanager.util.FileManager.java
public static boolean checkForNoMedia(OpenPath defPath) { if (defPath == null) return true; if (defPath instanceof OpenFile) { StatFs sf = new StatFs(defPath.getPath()); if (sf.getBlockCount() == 0) return true; else//from w w w . j a va 2s . co m return false; } else { try { return defPath.list() == null || defPath.list().length == 0; } catch (IOException e) { Logger.LogError("Error Checking for Media.", e); return true; } } }
From source file:uk.ac.horizon.ubihelper.service.LogManager.java
public synchronized void logValue(String channelName, JSONObject value) { if (!logging) { Log.d(TAG, "ignore logValue (not logging) " + channelName + "=" + value); return;//ww w . j ava2s .c o m } Log.d(TAG, "logValue " + channelName + "=" + value); // marshall long time = System.currentTimeMillis(); JSONObject lval = new JSONObject(); byte data[]; try { lval.put("time", time); lval.put("name", channelName); lval.put("value", value); data = lval.toString().getBytes("UTF-8"); } catch (Exception e) { Log.e(TAG, "marshalling log value: " + e); return; } try { // quick write? if (writeValue(data)) return; } catch (Exception e) { Log.w(TAG, "problem writing value: " + e); } // ensure no open file closeCurrentFile(); // fix up... File dir = getLogDirectory(service); if (dir == null || !dir.exists() || !dir.canWrite()) { signalError("External storage not accessible/present"); return; } if (currentLogDir == null && !dir.equals(currentLogDir)) { // initialise log dir, i.e. current size currentLogDir = dir; currentLogDir.mkdirs(); try { cacheFiles = new ArrayList<File>(); File files[] = currentLogDir.listFiles(); for (int fi = 0; fi < files.length; fi++) cacheFiles.add(files[fi]); currentCacheUsage = 0; for (File f : cacheFiles) currentCacheUsage += f.length(); Collections.sort(cacheFiles, new Comparator<File>() { public int compare(File f1, File f2) { return new Long(f1.lastModified()).compareTo(f2.lastModified()); } }); } catch (Exception e) { signalError("External storage not accessible/present (on check cache size)"); return; } } // current log configuration SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(service); // is there space StatFs fs = new StatFs(currentLogDir.getAbsolutePath()); long availableFs = fs.getAvailableBlocks() * fs.getBlockSize(); long availableCache = (maxCacheSize > 0) ? maxCacheSize - currentCacheUsage : availableFs; if (availableCache < MIN_NEW_FILE_SIZE) { boolean deleteOldFiles = prefs.getBoolean(LOG_DELETE_OLD_FILES, false); if (!deleteOldFiles) { if (availableCache < availableFs) signalError("Log cache full (cannot delete old files)"); else signalError("Log storage device full (cannot delete old files)"); return; } // try deleting oldest file first while (cacheFiles.size() > 0 && availableCache < MIN_NEW_FILE_SIZE) { File f = cacheFiles.remove(0); Log.i(TAG, "Deleting old cache file " + f + " (modified " + logDateFormat.format(new Date(f.lastModified())) + ", length " + f.length() + ")"); long len = f.length(); currentCacheUsage -= len; availableCache += len; if (!f.delete()) { signalError("Log cache full (failed to delete old file(s))"); return; } } if (availableCache < MIN_NEW_FILE_SIZE) { signalError("Log cache full (no old files)"); return; } } // new log file String filePrefix = prefs.getString(LOG_FILE_PREFIX, "log"); int i = 1; String filename = filePrefix + "_" + logDateFormat.format(new Date(time)); currentLogFile = new File(currentLogDir, filename + ".log"); while (currentLogFile.exists()) { i++; currentLogFile = new File(currentLogDir, filename + "_" + i + ".log"); } try { OutputStream os = new FileOutputStream(currentLogFile); currentLogStream = new BufferedOutputStream(os, BUFFER_SIZE); cacheFiles.add(currentLogFile); currentFileLength = 0; } catch (Exception e) { Log.w(TAG, "Error opening log file " + currentLogFile + ": " + e); signalError("Cannot create log file"); closeCurrentFile(); return; } // try again! try { // quick write? if (writeValue(data)) return; } catch (Exception e) { Log.w(TAG, "problem writing value: " + e); } signalError("Cannot write to new log file"); return; }
From source file:com.cellbots.logger.LoggerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); application = (LoggerApplication) getApplication(); // Keep the screen on to make sure the phone stays awake. getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mIsRecording = false;/*from w ww. j a va2 s . com*/ useZip = getIntent().getBooleanExtra(EXTRA_USE_ZIP, true); final int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_VIDEO_FRONT); if ((mode == MODE_VIDEO_FRONT) || (mode == MODE_VIDEO_BACK)) { if (mode == MODE_VIDEO_FRONT) { setContentView(R.layout.video_front_mode); } else { setContentView(R.layout.video_back_mode); } mCamcorderView = (AbstractCamcorderPreview) findViewById(R.id.surface); final SurfaceHolder previewHolder = mCamcorderView.getHolder(); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } else { mDelay = getIntent().getIntExtra(EXTRA_PICTURE_DELAY, 30) * 1000; if (mDelay < 0) { mDelay = 0; } setContentView(R.layout.pictures_mode); mCameraView = (CameraPreview) findViewById(R.id.surface); } // Setup the initial available space mStatFs = new StatFs(Environment.getExternalStorageDirectory().toString()); float percentage = (float) (mStatFs.getBlockCount() - mStatFs.getAvailableBlocks()) / (float) mStatFs.getBlockCount(); mFreeSpacePct = (int) (percentage * 100); mStorageBarImageView = (BarImageView) findViewById(R.id.storage_barImageView); mStorageBarImageView.setPercentage(percentage); mStorageTextView = (TextView) findViewById(R.id.storage_text); mStorageSpacerTextView = (TextView) findViewById(R.id.storage_text_spacer); mStorageTextView.setText(mFreeSpacePct + "%"); mStorageSpacerTextView.setPadding(mStorageSpacerTextView.getPaddingLeft(), (int) ((1 - percentage) * UI_BAR_MAX_TOP_PADDING), mStorageSpacerTextView.getPaddingRight(), mStorageSpacerTextView.getPaddingBottom()); mFlashingRecGroup = (LinearLayout) findViewById(R.id.flashingRecGroup); mRecTimeTextView = (TextView) findViewById(R.id.recTime); mGpsLocationView = (TextView) findViewById(R.id.gpsLocation); mPictureCountView = (TextView) findViewById(R.id.pictureCount); mDataDrawer = (SlidingDrawer) findViewById(R.id.dataDrawer); mDiagnosticsDrawer = (SlidingDrawer) findViewById(R.id.diagnosticsDrawer); final ImageButton recordButton = (ImageButton) findViewById(R.id.button_record); recordButton.setOnClickListener(new View.OnClickListener() { // @Override @Override public void onClick(View v) { synchronized (mIsRecording) { if ((mode == MODE_VIDEO_FRONT) || (mode == MODE_VIDEO_BACK)) { if (!mIsRecording) { try { mIsRecording = true; recordButton.setImageResource(R.drawable.rec_button_pressed); // initializes recording mCamcorderView.initializeRecording(); // starts recording mCamcorderView.startRecording(); startRecTime = System.currentTimeMillis(); new Thread(updateRecTimeDisplay).start(); if (mRemoteControl != null) mRemoteControl.broadcastMessage("*** Recording Started ***\n"); } catch (Exception e) { Log.e("ls", "Recording has failed...", e); Toast.makeText(getApplicationContext(), "Camera hardware error. Please restart the application.", Toast.LENGTH_LONG) .show(); finish(); return; } } else { cleanup(); } } else { if (!mIsRecording) { try { mIsRecording = true; recordButton.setImageResource(R.drawable.rec_button_pressed); mCameraView.takePictures(mDelay); new Thread(updateRecTimeDisplay).start(); } catch (Exception e) { Log.e("ls", "Taking pictures has failed...", e); Toast.makeText(getApplicationContext(), "Taking pictures is not possible at the moment: " + e.toString(), Toast.LENGTH_SHORT).show(); } } else { cleanup(); } } } } }); final ImageButton dataButton = (ImageButton) findViewById(R.id.button_data); dataButton.setOnClickListener(new View.OnClickListener() { // @Override @Override public void onClick(View v) { if (mDataDrawer.isOpened()) { dataButton.setImageResource(R.drawable.data_button_up); mDataDrawer.animateClose(); } else { dataButton.setImageResource(R.drawable.data_button_pressed); mDataDrawer.animateOpen(); } } }); final ImageButton diagnosticsButton = (ImageButton) findViewById(R.id.button_diagnostics); diagnosticsButton.setOnClickListener(new View.OnClickListener() { // @Override @Override public void onClick(View v) { if (mDiagnosticsDrawer.isOpened()) { diagnosticsButton.setImageResource(R.drawable.diagnostics_button_up); mDiagnosticsDrawer.animateClose(); } else { diagnosticsButton.setImageResource(R.drawable.diagnostics_button_pressed); mDiagnosticsDrawer.animateOpen(); } } }); // setupSensors(); initSensorUi(); }
From source file:com.adobe.phonegap.contentsync.Sync.java
private long getFreeSpace() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:com.secbro.qark.filebrowser.FileBrowserFragment.java
public static long getFreeSpace(String path) { StatFs stat = new StatFs(path); long availSize = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); return availSize; }
From source file:com.airad.zhonghan.ui.components.ImageCache.java
/** * Check how much usable space is available at a given path. * // w w w . ja v a2 s .co m * @param path * The path to check * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.tack.android.image.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check// w w w . j a v a2 s. c om * @return The space available in bytes */ @TargetApi(9) public static long getUsableSpace(File path) { if (ConfigUtil.hasV09()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }