List of usage examples for android.widget ProgressBar setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:carnero.cgeo.cgBase.java
public void showProgress(Activity activity, boolean status) { if (activity == null) { return;// www. j a va2s .c o m } final ProgressBar progress = (ProgressBar) activity.findViewById(R.id.actionbar_progress); if (status == true) { progress.setVisibility(View.VISIBLE); } else { progress.setVisibility(View.GONE); } }
From source file:org.anurag.compress.ExtractTarFile.java
public ExtractTarFile(final Context ctx, final Item zFile, final int width, String extractDir, final File file, final int mode) { // TODO Auto-generated constructor stub running = false;/*from ww w. java2 s.c o m*/ errors = false; prog = 0; read = 0; final Dialog dialog = new Dialog(ctx, Constants.DIALOG_STYLE); dialog.setCancelable(true); dialog.setContentView(R.layout.extract_file); dialog.getWindow().getAttributes().width = width; DEST = extractDir; final ProgressBar progress = (ProgressBar) dialog.findViewById(R.id.zipProgressBar); final TextView to = (TextView) dialog.findViewById(R.id.zipFileName); final TextView from = (TextView) dialog.findViewById(R.id.zipLoc); final TextView cfile = (TextView) dialog.findViewById(R.id.zipSize); final TextView zsize = (TextView) dialog.findViewById(R.id.zipNoOfFiles); final TextView status = (TextView) dialog.findViewById(R.id.zipFileLocation); if (extractDir == null) to.setText(ctx.getString(R.string.extractingto) + " Cache directory"); else to.setText(ctx.getString(R.string.extractingto) + " " + DEST); from.setText(ctx.getString(R.string.extractingfrom) + " " + file.getName()); if (mode == 2) { //TAR ENTRY HAS TO BE SHARED VIA BLUETOOTH,ETC... TextView t = null;//= (TextView)dialog.findViewById(R.id.preparing); t.setText(ctx.getString(R.string.preparingtoshare)); } try { if (file.getName().endsWith(".tar.gz")) tar = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(file))); else tar = new TarArchiveInputStream(new BufferedInputStream(new FileInputStream(file))); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); tar = null; } final Handler handle = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: progress.setProgress(0); cfile.setText(ctx.getString(R.string.extractingfile) + " " + name); break; case 1: status.setText(name); progress.setProgress((int) prog); break; case 2: try { tar.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (running) { dialog.dismiss(); if (mode == 0) { //after extracting file ,it has to be opened.... new OpenFileDialog(ctx, Uri.parse(dest)); } else if (mode == 2) { //FILE HAS TO BE SHARED.... new BluetoothChooser(ctx, new File(dest).getAbsolutePath(), null); } else { if (errors) Toast.makeText(ctx, ctx.getString(R.string.errorinext), Toast.LENGTH_SHORT).show(); Toast.makeText(ctx, ctx.getString(R.string.fileextracted), Toast.LENGTH_SHORT).show(); } } break; case 3: zsize.setText(size); progress.setMax((int) max); break; case 4: status.setText(ctx.getString(R.string.preparing)); break; case 5: running = false; Toast.makeText(ctx, ctx.getString(R.string.extaborted), Toast.LENGTH_SHORT).show(); } } }; final Thread thread = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (running) { if (DEST == null) { DEST = Environment.getExternalStorageDirectory() + "/Android/data/org.anurag.file.quest"; new File(DEST).mkdirs(); } TarArchiveEntry ze; try { while ((ze = tar.getNextTarEntry()) != null) { if (ze.isDirectory()) continue; handle.sendEmptyMessage(4); if (!zFile.isDirectory()) { //EXTRACTING A SINGLE FILE FROM AN ARCHIVE.... if (ze.getName().equalsIgnoreCase(zFile.t_getEntryName())) { try { //SENDING CURRENT FILE NAME.... try { name = zFile.getName(); } catch (Exception e) { name = zFile.t_getEntryName(); } handle.sendEmptyMessage(0); dest = DEST; dest = dest + "/" + name; FileOutputStream out = new FileOutputStream((dest)); max = ze.getSize(); size = AppBackup.size(max, ctx); handle.sendEmptyMessage(3); InputStream fin = tar; while ((read = fin.read(data)) != -1 && running) { out.write(data, 0, read); prog += read; name = AppBackup.status(prog, ctx); handle.sendEmptyMessage(1); } out.flush(); out.close(); fin.close(); break; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); //errors = true; } catch (IOException e) { errors = true; } } } else { //EXTRACTING A DIRECTORY FROM TAR ARCHIVE.... String p = zFile.getPath(); if (p.startsWith("/")) p = p.substring(1, p.length()); if (ze.getName().startsWith(p)) { prog = 0; dest = DEST; name = ze.getName(); String path = name; name = name.substring(name.lastIndexOf("/") + 1, name.length()); handle.sendEmptyMessage(0); String foname = zFile.getPath(); if (!foname.startsWith("/")) foname = "/" + foname; if (!path.startsWith("/")) path = "/" + path; path = path.substring(foname.lastIndexOf("/"), path.lastIndexOf("/")); if (!path.startsWith("/")) path = "/" + path; dest = dest + path; new File(dest).mkdirs(); dest = dest + "/" + name; FileOutputStream out; try { max = ze.getSize(); out = new FileOutputStream((dest)); size = AppBackup.size(max, ctx); handle.sendEmptyMessage(3); // InputStream fin = tar; while ((read = tar.read(data)) != -1 && running) { out.write(data, 0, read); prog += read; name = AppBackup.status(prog, ctx); handle.sendEmptyMessage(1); } out.flush(); out.close(); //fin.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); // errors = true; } catch (IOException e) { errors = true; } catch (Exception e) { //errors = true; } } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); errors = true; } handle.sendEmptyMessage(2); } } }); /* Button cancel = (Button)dialog.findViewById(R.id.calcelButton); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub dialog.dismiss(); handle.sendEmptyMessage(5); } }); Button st = (Button)dialog.findViewById(R.id.extractButton); st.setVisibility(View.GONE);*/ dialog.show(); running = true; thread.start(); dialog.setCancelable(false); progress.setVisibility(View.VISIBLE); }