List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:com.nf2m.util.ImageCache.java
/** * Check how much usable space is available at UriObserver given path. * * @param path The path to check//from w w w. jav a 2 s . co m * @return The space available in bytes */ @TargetApi(VERSION_CODES.GINGERBREAD) static long getUsableSpace(@NonNull 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:cn.com.wo.bitmap.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 a 2s .co m*/ * @return The space available in bytes */ @TargetApi(9) 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:de.cachebox_test.splash.java
@SuppressWarnings("deprecation") @Override// w ww. ja va2 s .com protected void onStart() { super.onStart(); Log.debug(log, "onStart"); if (android.os.Build.VERSION.SDK_INT >= 23) { PermissionCheck.checkNeededPermissions(this); } // initial GDX Gdx.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath()); // first, try to find stored preferences of workPath androidSetting = this.getSharedPreferences(Global.PREFS_NAME, 0); workPath = androidSetting.getString("WorkPath", Environment.getDataDirectory() + "/cachebox"); boolean askAgain = androidSetting.getBoolean("AskAgain", true); showSandbox = androidSetting.getBoolean("showSandbox", false); Global.initTheme(this); Global.InitIcons(this); CB_Android_FileExplorer fileExplorer = new CB_Android_FileExplorer(this); PlatformConnector.setGetFileListener(fileExplorer); PlatformConnector.setGetFolderListener(fileExplorer); String LangPath = androidSetting.getString("Sel_LanguagePath", ""); if (LangPath.length() == 0) { // set default lang String locale = Locale.getDefault().getLanguage(); if (locale.contains("de")) { LangPath = "data/lang/de/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("fr")) { LangPath = "data/lang/fr/strings.ini"; } else if (locale.contains("nl")) { LangPath = "data/lang/nl/strings.ini"; } else if (locale.contains("pl")) { LangPath = "data/lang/pl/strings.ini"; } else if (locale.contains("pt")) { LangPath = "data/lang/pt/strings.ini"; } else if (locale.contains("hu")) { LangPath = "data/lang/hu/strings.ini"; } else { LangPath = "data/lang/en-GB/strings.ini"; } } new Translation(workPath, FileType.Internal); try { Translation.LoadTranslation(LangPath); } catch (Exception e) { e.printStackTrace(); } // check Write permission if (!askAgain) { if (!FileIO.checkWritePermission(workPath)) { askAgain = true; if (!ToastEx) { ToastEx = true; String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } } if ((askAgain)) { // no saved workPath found -> search sd-cards and if more than 1 is found give the user the possibility to select one String externalSd = getExternalSdPath("/CacheBox"); boolean hasExtSd; final String externalSd2 = externalSd; if (externalSd != null) { hasExtSd = (externalSd.length() > 0) && (!externalSd.equalsIgnoreCase(workPath)); } else { hasExtSd = false; } // externe SD wurde gefunden != internal // oder Tablet Layout mglich // -> Auswahldialog anzeigen try { final Dialog dialog = new Dialog(context) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { splash.this.finish(); } return super.onKeyDown(keyCode, event); } }; dialog.setContentView(R.layout.sdselectdialog); TextView title = (TextView) dialog.findViewById(R.id.select_sd_title); title.setText(Translation.Get("selectWorkSpace") + "\n\n"); /* * TextView tbLayout = (TextView) dialog.findViewById(R.id.select_sd_layout); tbLayout.setText("\nLayout"); final RadioGroup * rgLayout = (RadioGroup) dialog.findViewById(R.id.select_sd_radiogroup); final RadioButton rbHandyLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_handylayout); final RadioButton rbTabletLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_tabletlayout); rbHandyLayout.setText("Handy-Layout"); * rbTabletLayout.setText("Tablet-Layout"); if (!GlobalCore.posibleTabletLayout) { * rgLayout.setVisibility(RadioGroup.INVISIBLE); rbHandyLayout.setChecked(true); } else { if (GlobalCore.isTab) { * rbTabletLayout.setChecked(true); } else { rbHandyLayout.setChecked(true); } } */ final CheckBox cbAskAgain = (CheckBox) dialog.findViewById(R.id.select_sd_askagain); cbAskAgain.setText(Translation.Get("AskAgain")); cbAskAgain.setChecked(askAgain); Button buttonI = (Button) dialog.findViewById(R.id.button1); buttonI.setText("Internal SD\n\n" + workPath); buttonI.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use internal SD -> nothing to change Thread thread = new Thread() { @Override public void run() { boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); dialog.dismiss(); startInitial(); } }; thread.start(); } }); Button buttonE = (Button) dialog.findViewById(R.id.button2); final boolean isSandbox = externalSd == null ? false : externalSd.contains("Android/data/de.cachebox_test"); if (!hasExtSd) { buttonE.setVisibility(Button.INVISIBLE); } else { String extSdText = isSandbox ? "External SD SandBox\n\n" : "External SD\n\n"; buttonE.setText(extSdText + externalSd); } buttonE.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show KitKat Massage? if (isSandbox && !showSandbox) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title alertDialogBuilder.setTitle("KitKat Sandbox"); // set dialog message alertDialogBuilder.setMessage(Translation.Get("Desc_Sandbox")).setCancelable(false) .setPositiveButton(Translation.Get("yes"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, run Sandbox Path showSandbox = true; Config.AcceptChanges(); // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }) .setNegativeButton(Translation.Get("no"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } } }); LinearLayout ll = (LinearLayout) dialog.findViewById(R.id.scrollViewLinearLayout); // add all Buttons for created Workspaces AdditionalWorkPathArray = getAdditionalWorkPathArray(); for (final String AddWorkPath : AdditionalWorkPathArray) { final String Name = FileIO.GetFileNameWithoutExtension(AddWorkPath); if (!FileIO.checkWritePermission(AddWorkPath)) { // delete this Work Path deleteWorkPath(AddWorkPath); continue; } Button buttonW = new Button(context); buttonW.setText(Name + "\n\n" + AddWorkPath); buttonW.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // setting the MassageBox then the UI_sizes are not initial in this moment Resources res = splash.this.getResources(); float scale = res.getDisplayMetrics().density; float calcBase = 533.333f * scale; FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1); int width = frame.getMeasuredWidth(); int height = frame.getMeasuredHeight(); MessageBox.Builder.WindowWidth = width; MessageBox.Builder.WindowHeight = height; MessageBox.Builder.textSize = (calcBase / res.getDimensionPixelSize(R.dimen.BtnTextSize)) * scale; MessageBox.Builder.ButtonHeight = (int) (50 * scale); // Ask before delete msg = (MessageBox) MessageBox.Show(Translation.Get("shuredeleteWorkspace", Name), Translation.Get("deleteWorkspace"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == MessageBox.BUTTON_POSITIVE) { // Delete this Workpath only from Settings don't delete any File deleteWorkPath(AddWorkPath); } // Start again to exclude the old Folder msg.dismiss(); onStart(); } }); dialog.dismiss(); return true; } }); buttonW.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = AddWorkPath; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }); ll.addView(buttonW); } Button buttonC = (Button) dialog.findViewById(R.id.buttonCreateWorkspace); buttonC.setText(Translation.Get("createWorkSpace")); buttonC.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); getFolderReturnListener = new IgetFolderReturnListener() { @Override public void getFolderReturn(String Path) { if (FileIO.checkWritePermission(Path)) { AdditionalWorkPathArray.add(Path); writeAdditionalWorkPathArray(AdditionalWorkPathArray); // Start again to include the new Folder onStart(); } else { String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } }; PlatformConnector.getFolder("", Translation.Get("select_folder"), Translation.Get("select"), getFolderReturnListener); } }); dialog.show(); } catch (Exception ex) { ex.printStackTrace(); } } else { if (GlobalCore.displayType == DisplayType.Large || GlobalCore.displayType == DisplayType.xLarge) GlobalCore.isTab = isLandscape; // restore the saved workPath // test whether workPath is available by checking the free size on the SD String workPathToTest = workPath.substring(0, workPath.lastIndexOf("/")); long bytesAvailable = 0; try { StatFs stat = new StatFs(workPathToTest); bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount(); } catch (Exception ex) { bytesAvailable = 0; } if (bytesAvailable == 0) { // there is a workPath stored but this workPath is not available at the moment (maybe SD is removed) Toast.makeText(splashActivity, "WorkPath " + workPath + " is not available!\nMaybe SD-Card is removed?", Toast.LENGTH_LONG) .show(); finish(); return; } startInitial(); } }
From source file:com.dv.Utils.DvFileUtil.java
/** * sdcard./*from w w w . j a va2s . c o m*/ * * @return the int */ public static int freeSpaceOnSD() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB; return (int) sdFreeMB; }
From source file:cn.org.eshow.framwork.util.AbFileUtil.java
/** * sdcard./*w ww . j ava 2 s. c o m*/ * * @return the int */ public static int freeSpaceOnSD() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024; return (int) sdFreeMB; }
From source file:com.sogrey.sinaweibo.utils.FileUtil.java
/** * sdcard.//from ww w. j a va 2 s . c o m * * @return the int */ @SuppressWarnings("deprecation") public static int freeSpaceOnSD() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024; return (int) sdFreeMB; }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
/** * // w w w . j a va 2 s .c o m * Map returned: * * <pre> * TZ = Timezone * id = Timezone ID * display = Timezone display name * offset = Offset from UTC (in ms) * SDK = SDK Version * download = default download path * appcache = Location of application cache * sdcard = Space on sdcard * availblocks = Available blocks * blockcount = Total Blocks * blocksize = size of block. * </pre> */ @Rpc(description = "A map of various useful environment details") public Map<String, Object> environment() { Map<String, Object> result = new HashMap<String, Object>(); Map<String, Object> zone = new HashMap<String, Object>(); Map<String, Object> space = new HashMap<String, Object>(); TimeZone tz = TimeZone.getDefault(); zone.put("id", tz.getID()); zone.put("display", tz.getDisplayName()); zone.put("offset", tz.getOffset((new Date()).getTime())); result.put("TZ", zone); result.put("SDK", android.os.Build.VERSION.SDK); result.put("download", FileUtils.getExternalDownload().getAbsolutePath()); result.put("appcache", mService.getCacheDir().getAbsolutePath()); try { StatFs fs = new StatFs("/sdcard"); space.put("availblocks", fs.getAvailableBlocks()); space.put("blocksize", fs.getBlockSize()); space.put("blockcount", fs.getBlockCount()); } catch (Exception e) { space.put("exception", e.toString()); } result.put("sdcard", space); return result; }
From source file:com.nd.pad.GreenBrowser.util.ImageDownloader.java
/** * // ww w. j a v a 2s.c o m * @ : freeSpaceOnSd * @ : sdcard * @ * @return * * @ * @2012-10-20 12:18:41 * @ * */ private int freeSpaceOnSd() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()); return (int) sdFreeMB; }
From source file:de.cachebox_test.splash.java
private String testExtSdPath(String extPath) { if (extPath.equalsIgnoreCase(workPath)) return null; // if this extPath is the same than the actual workPath -> this is the // internal SD, not // the external!!! try {/* w ww .j av a2s.c om*/ if (FileIO.FileExists(extPath)) { StatFs stat = new StatFs(extPath); @SuppressWarnings("deprecation") long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount(); if (bytesAvailable == 0) { return null; // ext SD-Card is not plugged in -> do not use it } else { // Check can Read/Write File f = FileFactory.createFile(extPath); if (f.canWrite()) { if (f.canRead()) { return f.getAbsolutePath(); // ext SD-Card is plugged in } } // Check can Read/Write on Application Storage String appPath = this.getApplication().getApplicationContext().getExternalFilesDir(null) .getAbsolutePath(); int Pos = appPath.indexOf("/Android/data/"); String p = appPath.substring(Pos); File fi = FileFactory.createFile(extPath + p);// "/Android/data/de.cachebox_test/files"); fi.mkdirs(); if (fi.canWrite()) { if (fi.canRead()) { return fi.getAbsolutePath(); } } return null; } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.atwal.wakeup.battery.util.Utilities.java
public static long getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); return stat.getAvailableBlocks() * blockSize; }