List of usage examples for android.os StatFs getBlockCount
@Deprecated public int getBlockCount()
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
/** * // w w w . j a v a 2 s . c om * 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.github.chenxiaolong.dualbootpatcher.freespace.FreeSpaceFragment.java
private void refreshMounts() { mMounts.clear();/*from w w w . j a va2 s . c o m*/ MountEntry[] entries; try { entries = FileUtils.getMounts(); } catch (IOException e) { Log.e(TAG, "Failed to get mount entries", e); return; } for (MountEntry entry : entries) { MountInfo info = new MountInfo(); info.mountpoint = entry.mnt_dir; info.fsname = entry.mnt_fsname; info.fstype = entry.mnt_type; // Ignore irrelevant filesystems if (SKIPPED_FSTYPES.contains(info.fstype) || SKIPPED_FSNAMES.contains(info.fsname) || info.mountpoint.startsWith("/mnt") || info.mountpoint.startsWith("/dev") || info.mountpoint.startsWith("/proc") || info.mountpoint.startsWith("/data/data")) { continue; } StatFs statFs; try { statFs = new StatFs(info.mountpoint); } catch (IllegalArgumentException e) { // Thrown if Os.statvfs() throws ErrnoException Log.e(TAG, "Exception during statfs of " + info.mountpoint + ": " + e.getMessage()); continue; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { info.totalSpace = statFs.getBlockSizeLong() * statFs.getBlockCountLong(); info.availSpace = statFs.getBlockSizeLong() * statFs.getAvailableBlocksLong(); } else { info.totalSpace = statFs.getBlockSize() * statFs.getBlockCount(); info.availSpace = statFs.getBlockSize() * statFs.getAvailableBlocks(); } mMounts.add(info); } mAdapter.notifyDataSetChanged(); }
From source file:com.p2p.misc.DeviceUtility.java
public String[] memCardDetails() { String[] memDetails = new String[3]; StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize(); double sdtotalSize = (double) stat.getBlockCount() * (double) stat.getBlockSize(); // One binary gigabyte equals 1,073,741,824 bytes. float gigaTotal = (float) (sdtotalSize / 1073741824); float gigaAvailable = (float) (sdAvailSize / 1073741824); float usedSize = gigaTotal - gigaAvailable; memDetails[0] = String.valueOf(gigaTotal); memDetails[1] = String.valueOf(gigaAvailable); memDetails[2] = String.valueOf(usedSize); return memDetails; }
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 {/* www . j a v a 2 s.c o m*/ 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:de.cachebox_test.splash.java
@SuppressWarnings("deprecation") @Override/*from w w w .ja v a 2 s . c o m*/ 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:org.uguess.android.sysinfo.SiragonManager.java
/** * This checks the built-in app2sd storage info supported since Froyo */// w ww.java 2s .co m private String[] getSystemA2SDStorageInfo() { Activity ctx = getActivity(); final PackageManager pm = ctx.getPackageManager(); List<ApplicationInfo> allApps = pm.getInstalledApplications(0); long total = 0; long free = 0; for (int i = 0, size = allApps.size(); i < size; i++) { ApplicationInfo info = allApps.get(i); if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { String src = info.sourceDir; if (src != null) { File srcFile = new File(src); if (srcFile.canRead()) { try { StatFs stat = new StatFs(srcFile.getAbsolutePath()); long blockSize = stat.getBlockSize(); total += stat.getBlockCount() * blockSize; free += stat.getAvailableBlocks() * blockSize; } catch (Exception e) { Log.e(SiragonManager.class.getName(), "Cannot access path: " //$NON-NLS-1$ + srcFile.getAbsolutePath(), e); } } } } } if (total > 0) { String[] info = new String[2]; info[0] = Formatter.formatFileSize(ctx, total); info[1] = Formatter.formatFileSize(ctx, free); return info; } return null; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
private String[] getStorageInfo(File path) { if (path != null) { try {/*from w ww .j av a2 s. c o m*/ Activity ctx = getActivity(); StatFs stat = new StatFs(path.getAbsolutePath()); long blockSize = stat.getBlockSize(); String[] info = new String[2]; info[0] = Formatter.formatFileSize(ctx, stat.getBlockCount() * blockSize); info[1] = Formatter.formatFileSize(ctx, stat.getAvailableBlocks() * blockSize); return info; } catch (Exception e) { Log.e(SiragonManager.class.getName(), "Cannot access path: " //$NON-NLS-1$ + path.getAbsolutePath(), e); } } return null; }
From source file:cm.aptoide.pt.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { AptoideThemePicker.setAptoideTheme(this); super.onCreate(savedInstanceState); serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class); startService(serviceDownloadManagerIntent); mContext = this; File sdcard_file = new File(SDCARD); if (!sdcard_file.exists() || !sdcard_file.canWrite()) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog noSDDialog = dialogBuilder.create(); noSDDialog.setTitle(getText(R.string.remote_in_noSD_title)); noSDDialog.setIcon(android.R.drawable.ic_dialog_alert); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getText(R.string.remote_in_noSD)); noSDDialog.setCancelable(false); noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok), new Dialog.OnClickListener() { @Override//from w w w . ja v a 2 s .co m public void onClick(DialogInterface arg0, int arg1) { finish(); } }); noSDDialog.show(); } else { StatFs stat = new StatFs(sdcard_file.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); long availableBlocks = stat.getAvailableBlocks(); long total = (blockSize * totalBlocks) / 1024 / 1024; long avail = (blockSize * availableBlocks) / 1024 / 1024; Log.d("Aptoide", "* * * * * * * * * *"); Log.d("Aptoide", "Total: " + total + " Mb"); Log.d("Aptoide", "Available: " + avail + " Mb"); if (avail < 10) { Log.d("Aptoide", "No space left on SDCARD..."); Log.d("Aptoide", "* * * * * * * * * *"); View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView); final AlertDialog noSpaceDialog = dialogBuilder.create(); noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getText(R.string.remote_in_noSDspace)); noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); noSpaceDialog.show(); } else { SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext); editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); if (!sPref.contains("matureChkBox")) { editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE); SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE); if (sPrefOld.getString("app_rating", "none").equals("Mature")) { editor.putBoolean("matureChkBox", false); } } if (!sPref.contains("version")) { ApplicationAptoide.setRestartLauncher(true); try { editor.putInt("version", getPackageManager().getPackageInfo(getPackageName(), 0).versionCode); } catch (NameNotFoundException e) { e.printStackTrace(); } } if (sPref.getString("myId", null) == null) { String rand_id = UUID.randomUUID().toString(); editor.putString("myId", rand_id); } if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); editor.putInt("scW", dm.widthPixels); editor.putInt("scH", dm.heightPixels); } editor.commit(); File file = new File(LOCAL_PATH + "/apks"); if (!file.exists()) { file.mkdirs(); } new Thread(new Runnable() { @Override public void run() { // Note the L that tells the compiler to interpret the // number as a Long final long MAXFILEAGE = 2678400000L; // 1 month in // milliseconds // Get file handle to the directory. In this case the // application files dir File dir = new File(LOCAL_PATH + "/apks"); // Optain list of files in the directory. // listFiles() returns a list of File objects to each // file found. File[] files = dir.listFiles(); // Loop through all files for (File f : files) { // Get the last modified date. Miliseconds since // 1970 long lastmodified = f.lastModified(); // Do stuff here to deal with the file.. // For instance delete files older than 1 month if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) { f.delete(); } } } }).start(); db = Database.getInstance(); Intent i = new Intent(mContext, MainService.class); startService(i); bindService(i, conn, Context.BIND_AUTO_CREATE); order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list", 0)]; registerReceiver(updatesReceiver, new IntentFilter("update")); registerReceiver(statusReceiver, new IntentFilter("status")); registerReceiver(loginReceiver, new IntentFilter("login")); registerReceiver(storePasswordReceiver, new IntentFilter("401")); registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW")); if (!ApplicationAptoide.MULTIPLESTORES) { registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED")); } registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO")); registered = true; categoriesStrings = new HashMap<String, Integer>(); // categoriesStrings.put("Applications", R.string.applications); boolean serversFileIsEmpty = true; if (sPref.getBoolean("firstrun", true)) { // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); // shortcutIntent.setClassName("cm.aptoide.pt", // "cm.aptoide.pt.Start"); // final Intent intent = new Intent(); // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, // shortcutIntent); // // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, // getString(R.string.app_name)); // Parcelable iconResource = // Intent.ShortcutIconResource.fromContext(this, // R.drawable.ic_launcher); // // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, // iconResource); // intent.putExtra("duplicate", false); // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); // sendBroadcast(intent); if (new File(LOCAL_PATH + "/servers.xml").exists() && ApplicationAptoide.DEFAULTSTORENAME == null) { try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); MyappHandler handler = new MyappHandler(); sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler); ArrayList<String> server = handler.getServers(); if (server.isEmpty()) { serversFileIsEmpty = true; } else { getIntent().putExtra("newrepo", server); } } catch (Exception e) { e.printStackTrace(); } } editor.putBoolean("firstrun", false); editor.putBoolean("orderByCategory", true); editor.commit(); } if (getIntent().hasExtra("newrepo")) { ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo"); for (final String uri2 : repos) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog addNewRepoDialog = dialogBuilder.create(); addNewRepoDialog.setTitle(getString(R.string.add_store)); addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?")); addNewRepoDialog.setCancelable(false); addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialogAddStore(uri2, null, null); } }); addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }); addNewRepoDialog.show(); } } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null && serversFileIsEmpty) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog addAppsRepoDialog = dialogBuilder.create(); addAppsRepoDialog.setTitle(getString(R.string.add_store)); addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/"); addAppsRepoDialog.setCancelable(false); addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialogAddStore("http://apps.store.aptoide.com", null, null); } }); addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }); addAppsRepoDialog.show(); } new Thread(new Runnable() { @Override public void run() { try { getUpdateParameters(); if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer .parseInt(updateParams.get("versionCode"))) { runOnUiThread(new Runnable() { @Override public void run() { requestUpdateSelf(); } }); } } catch (Exception e) { e.printStackTrace(); } } }).start(); } featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null); availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null); updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null); banner = (LinearLayout) availableView.findViewById(R.id.banner); breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null); installedView = new ListView(mContext); updatesListView = (ListView) updateView.findViewById(R.id.updates_list); availableListView = (ListView) availableView.findViewById(R.id.available_list); joinStores = (CheckBox) availableView.findViewById(R.id.join_stores); availableAdapter = new AvailableListAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER, db); updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); pb = (TextView) availableView.findViewById(R.id.loading_pb); addStoreButton = availableView.findViewById(R.id.add_store); bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar); bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name); bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description); } }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String GetDiskInfo(String sPath) { String sRet = ""; StatFs statFS = new StatFs(sPath); long nBlockCount = statFS.getBlockCount(); long nBlockSize = statFS.getBlockSize(); long nBlocksAvail = statFS.getAvailableBlocks(); // Free is often the same as Available, but can include reserved // blocks that are not available to normal applications. // long nBlocksFree = statFS.getFreeBlocks(); sRet = sPath + ": " + (nBlockCount * nBlockSize) + " total, " + (nBlocksAvail * nBlockSize) + " available"; return (sRet); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
public void handleRefreshMedia(final String path, boolean keepChecking, final int retries) { if (!keepChecking || retries <= 0) { refreshBookmarks();// w w w. ja va 2s . c o m return; } final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { Logger.LogDebug("Check " + retries + " for " + path); try { StatFs sf = new StatFs(path); if (sf.getBlockCount() == 0) throw new Exception("No blocks"); showToast(getResources().getString(R.string.s_alert_new_media) + " " + getVolumeName(path) + " @ " + DialogHandler.formatSize((long) sf.getBlockSize() * (long) sf.getAvailableBlocks())); refreshBookmarks(); if (mLastPath.getPath().equals(path)) goHome(); } catch (Throwable e) { Logger.LogWarning("Couldn't read " + path); handleRefreshMedia(path, true, retries - 1); // retry again in 1/2 second } } }, 1000); }