List of usage examples for android.app ProgressDialog STYLE_HORIZONTAL
int STYLE_HORIZONTAL
To view the source code for android.app ProgressDialog STYLE_HORIZONTAL.
Click Source Link
From source file:nf.frex.android.FrexActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_OK) { return;//w w w .j a v a2 s . com } if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) { final Uri imageUri = data.getData(); if (imageUri != null) { File imageFile = new File(imageUri.getPath()); String configName = FrexIO.getFilenameWithoutExt(imageFile); File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT); try { FileInputStream fis = new FileInputStream(paramFile); try { readFrexDoc(fis, configName); } finally { fis.close(); } } catch (IOException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); } } } else if (requestCode == R.id.settings) { view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this)); } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) { final Uri imageUri = data.getData(); final ColorQuantizer colorQuantizer = new ColorQuantizer(); final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } colorQuantizer.cancel(); } }; final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() { @Override public void progress(final String msg, final int iter, final int maxIter) { runOnUiThread(new Runnable() { @Override public void run() { progressDialog.setMessage(msg); progressDialog.setProgress(iter); } }); } }; progressDialog.setTitle(getString(R.string.get_pal_from_img_title)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(cancelListener); progressDialog.setMax(colorQuantizer.getMaxIterCount()); progressDialog.show(); Thread thread = new Thread(new Runnable() { @Override public void run() { Bitmap bitmap; try { bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256); } catch (IOException e) { alert("I/O error: " + e.getLocalizedMessage()); return; } ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener); progressDialog.dismiss(); if (colorScheme != null) { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme"); String colorSchemeId = "$" + imageUri.toString(); colorSchemes.add(colorSchemeId, colorScheme); view.setColorSchemeId(colorSchemeId); view.setColorScheme(colorScheme); view.recomputeColors(); runOnUiThread(new Runnable() { @Override public void run() { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)"); showDialog(R.id.colors); } }); } } }); thread.start(); } }
From source file:com.nextgis.mobile.map.LocalTMSLayer.java
protected static void create(final MapBase map, String layerName, int tmsType, Uri uri) { String sErr = map.getContext().getString(R.string.error_occurred); try {//from w ww . j a v a2 s . c o m InputStream inputStream = map.getContext().getContentResolver().openInputStream(uri); if (inputStream != null) { ProgressDialog progressDialog = new ProgressDialog(map.getContext()); progressDialog.setMessage(map.getContext().getString(R.string.message_zip_extract_progress)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.show(); File outputPath = map.cretateLayerStorage(); //create layer description file JSONObject oJSONRoot = new JSONObject(); oJSONRoot.put(JSON_NAME_KEY, layerName); oJSONRoot.put(JSON_VISIBILITY_KEY, true); oJSONRoot.put(JSON_TYPE_KEY, LAYERTYPE_LOCAL_TMS); oJSONRoot.put(JSON_TMSTYPE_KEY, tmsType); new UnZipTask(map.getMapEventsHandler(), inputStream, outputPath, oJSONRoot, progressDialog) .execute(); return; } } catch (FileNotFoundException e) { Log.d(TAG, "Exception: " + e.getLocalizedMessage()); sErr += ": " + e.getLocalizedMessage(); } catch (JSONException e) { Log.d(TAG, "Exception: " + e.getLocalizedMessage()); sErr += ": " + e.getLocalizedMessage(); } //if we here something wrong occurred Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show(); }
From source file:com.dsi.ant.antplus.pluginsampler.bloodpressure.Activity_BloodPressureSampler.java
/** Called when the activity is first created. */ @Override/*from w w w . j a v a 2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bloodpressure); layoutControllerList = new ArrayList<Closeable>(); button_getAntFsMfgID = (Button) findViewById(R.id.button_getMfgId); button_requestResetData = (Button) findViewById(R.id.button_requestResetDataAndSetTime); checkBox_setTimeOnReset = (CheckBox) findViewById(R.id.checkbox_setTime); button_requestDownloadAllHistory = (Button) findViewById(R.id.button_requestDownloadAllHistory); checkBox_downloadNewOnly = (CheckBox) findViewById(R.id.checkbox_newdataonly); checkBox_enableMonitoring = (CheckBox) findViewById(R.id.checkbox_monitor); button_stopDataMonitor = (Button) findViewById(R.id.button_StopBloodPressureDataMonitor); linearLayout_FitDataView = (LinearLayout) findViewById(R.id.linearLayout_BloodPressureCards); tv_status = (TextView) findViewById(R.id.textView_Status); tv_mfgID = (TextView) findViewById(R.id.textView_AntFsMfgId); button_stopDataMonitor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (bpPcc == null) return; bpPcc.cancelDownloadMeasurementsMonitor(); button_stopDataMonitor.setVisibility(View.GONE); } }); button_requestDownloadAllHistory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (bpPcc == null) return; antFsProgressDialog = new ProgressDialog(Activity_BloodPressureSampler.this); antFsProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); antFsProgressDialog.setMessage("Sending Request..."); antFsProgressDialog.setCancelable(false); antFsProgressDialog.setIndeterminate(false); boolean onlyNew = checkBox_downloadNewOnly.isChecked(); boolean monitor = checkBox_enableMonitoring.isChecked(); boolean submitted = bpPcc.requestDownloadMeasurements(onlyNew, monitor, new IDownloadMeasurementsStatusReceiver() { @Override public void onDownloadMeasurementsStatus( final DownloadMeasurementsStatusCode statusCode, final AntFsRequestStatus finishedCode) { runOnUiThread(new Runnable() { @Override public void run() { handleDownloadMeasurementsState(statusCode, finishedCode); } }); } private void handleDownloadMeasurementsState(DownloadMeasurementsStatusCode statusCode, AntFsRequestStatus finishedCode) { switch (statusCode) { case FINISHED: handleFinishedCode(finishedCode); setRequestUiEnabled(true); break; case PROGRESS_MONITORING: Toast.makeText(Activity_BloodPressureSampler.this, "Monitoring for new downloads.", Toast.LENGTH_SHORT).show(); antFsProgressDialog.dismiss(); button_stopDataMonitor.setVisibility(View.VISIBLE); break; case PROGRESS_SYNCING_WITH_DEVICE: Toast.makeText(Activity_BloodPressureSampler.this, "Synchronizing with device.", Toast.LENGTH_SHORT).show(); break; case UNRECOGNIZED: Toast.makeText(Activity_BloodPressureSampler.this, "Failed: UNRECOGNIZED. PluginLib Upgrade Required?", Toast.LENGTH_SHORT) .show(); setRequestUiEnabled(true); break; default: setRequestUiEnabled(true); break; } } private void handleFinishedCode(AntFsRequestStatus finishedCode) { antFsProgressDialog.dismiss(); switch (finishedCode) { case SUCCESS: Toast.makeText(Activity_BloodPressureSampler.this, "DownloadAllHistory finished successfully.", Toast.LENGTH_SHORT).show(); break; case FAIL_ALREADY_BUSY_EXTERNAL: Toast.makeText(Activity_BloodPressureSampler.this, "DownloadAllHistory failed, device busy.", Toast.LENGTH_SHORT).show(); break; case FAIL_DEVICE_COMMUNICATION_FAILURE: Toast.makeText(Activity_BloodPressureSampler.this, "DownloadAllHistory failed, communication error.", Toast.LENGTH_SHORT) .show(); break; case FAIL_AUTHENTICATION_REJECTED: //NOTE: This is thrown when authentication has failed, most likely when user action is required to enable pairing Toast.makeText(Activity_BloodPressureSampler.this, "DownloadAllHistory failed, authentication rejected.", Toast.LENGTH_LONG).show(); break; case FAIL_DEVICE_TRANSMISSION_LOST: Toast.makeText(Activity_BloodPressureSampler.this, "DownloadAllHistory failed, transmission lost.", Toast.LENGTH_SHORT) .show(); break; case FAIL_PLUGINS_SERVICE_VERSION: Toast.makeText(Activity_BloodPressureSampler.this, "Failed: Plugin Service Upgrade Required?", Toast.LENGTH_SHORT).show(); setRequestUiEnabled(true); break; case UNRECOGNIZED: Toast.makeText(Activity_BloodPressureSampler.this, "Failed: UNRECOGNIZED. PluginLib Upgrade Required?", Toast.LENGTH_SHORT) .show(); break; default: break; } } }, new IMeasurementDownloadedReceiver() { @Override public void onMeasurementDownloaded(final BloodPressureMeasurement measurement) { //Add Blood Pressure Layout to the list of layouts displayed to the user runOnUiThread(new Runnable() { @Override public void run() { layoutControllerList.add(0, new LayoutController_BloodPressure(getLayoutInflater(), linearLayout_FitDataView, measurement.asBloodPressureFitMesg())); } }); } }, new IAntFsProgressUpdateReceiver() { @Override public void onNewAntFsProgressUpdate(final AntFsState stateCode, final long transferredBytes, final long totalBytes) { runOnUiThread(new Runnable() { @Override public void run() { switch (stateCode) { //In Link state and requesting to link with the device in order to pass to Auth state case LINK_REQUESTING_LINK: antFsProgressDialog.setMax(4); antFsProgressDialog.setProgress(1); antFsProgressDialog.setMessage("In Link State: Requesting Link."); break; //In Authentication state, processing authentication commands case AUTHENTICATION: antFsProgressDialog.setMax(4); antFsProgressDialog.setProgress(2); antFsProgressDialog.setMessage("In Authentication State."); break; //In Authentication state, currently attempting to pair with the device //NOTE: Feedback SHOULD be given to the user here as pairing typically requires user interaction with the device case AUTHENTICATION_REQUESTING_PAIRING: antFsProgressDialog.setMax(4); antFsProgressDialog.setProgress(2); antFsProgressDialog .setMessage("In Authentication State: User Pairing Requested."); break; //In Transport state, no requests are currently being processed case TRANSPORT_IDLE: antFsProgressDialog.setMax(4); antFsProgressDialog.setProgress(3); antFsProgressDialog.setMessage( "Requesting download (In Transport State: Idle)..."); break; //In Transport state, files are currently being downloaded case TRANSPORT_DOWNLOADING: antFsProgressDialog.setMessage("In Transport State: Downloading."); antFsProgressDialog.setMax(100); if (transferredBytes >= 0 && totalBytes > 0) { int progress = (int) (transferredBytes * 100 / totalBytes); antFsProgressDialog.setProgress(progress); } break; case UNRECOGNIZED: //This flag indicates that an unrecognized value was sent by the service, an upgrade of your PCC may be required to handle this new value. Toast.makeText(Activity_BloodPressureSampler.this, "Failed: UNRECOGNIZED. PluginLib or Plugin Service Upgrade Required?", Toast.LENGTH_SHORT).show(); break; default: Log.w("BloodPressureSampler", "Unknown ANT-FS State Code Received: " + stateCode); break; } } }); } }); if (submitted) { clearLayoutList(); setRequestUiEnabled(false); antFsProgressDialog.show(); } else { Toast.makeText(Activity_BloodPressureSampler.this, "Error Downloading Measurements: PCC already busy or dead", Toast.LENGTH_SHORT).show(); } } }); button_getAntFsMfgID.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (bpPcc != null) tv_mfgID.setText(Integer.toString(bpPcc.getAntFsManufacturerID())); } }); button_requestResetData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (bpPcc == null) return; final Dialog_ProgressWaiter progressDialog = new Dialog_ProgressWaiter("Resetting Device..."); boolean doSetTime = checkBox_setTimeOnReset.isChecked(); boolean submitted = bpPcc.requestResetDataAndSetTime(doSetTime, new IResetDataAndSetTimeFinishedReceiver() { @Override public void onNewResetDataAndSetTimeFinished(final AntFsRequestStatus statusCode) { //Unrecognized or fail plugins service version indicates the progress dialog would never have started if (statusCode == AntFsRequestStatus.UNRECOGNIZED) { Toast.makeText(Activity_BloodPressureSampler.this, "Reset Failed - " + statusCode + ". Plugin Lib needs upgrade.", Toast.LENGTH_LONG).show(); return; } else if (statusCode == AntFsRequestStatus.FAIL_PLUGINS_SERVICE_VERSION) { Toast.makeText(Activity_BloodPressureSampler.this, "Reset Failed - " + statusCode + ". Plugin Service needs upgrade.", Toast.LENGTH_LONG).show(); return; } progressDialog.dismiss(); runOnUiThread(new Runnable() { @Override public void run() { if (statusCode == AntFsRequestStatus.SUCCESS) Toast.makeText(Activity_BloodPressureSampler.this, "Reset Complete", Toast.LENGTH_SHORT).show(); else Toast.makeText(Activity_BloodPressureSampler.this, "Reset Failed - " + statusCode, Toast.LENGTH_LONG).show(); } }); } }, null); //TODO use AntFsProgressReceiver if (submitted) progressDialog.show(getSupportFragmentManager(), "ResetProgressDialog"); else Toast.makeText(Activity_BloodPressureSampler.this, "Error Resetting Device: PCC likely busy or dead", Toast.LENGTH_SHORT).show(); } }); resetPcc(); }
From source file:com.googlecode.android_scripting.facade.ui.UiFacade.java
@Rpc(description = "Create a horizontal progress dialog.") public void dialogCreateHorizontalProgress(@RpcParameter(name = "title") @RpcOptional String title, @RpcParameter(name = "message") @RpcOptional String message, @RpcParameter(name = "maximum progress") @RpcDefault("100") Integer max) { dialogDismiss(); // Dismiss any existing dialog. mDialogTask = new ProgressDialogTask(ProgressDialog.STYLE_HORIZONTAL, max, title, message, true); }
From source file:edu.polyu.screamalert.SoundProcessing.java
public static void setupVAD() { calibrateProgress = 0;/*from w w w .j ava 2s .c o m*/ calibrateDialog.setMessage(thisContext.getString(R.string.calibrateMsg)); calibrateDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); calibrateDialog.setCancelable(false); calibrateDialog.setMax(100); calibrateDialog.setProgress(calibrateProgress); vadShortData = new short[recordBufferSize / 2]; vadBufferedShortData = new ArrayList<short[]>(); vadBufEnergy = new ArrayList<Double>(); // Storing energy profile isPreparingVAD = true; vadThreshold = Config.VAD_DEFAULT_TH; // Default VAD threshold Exchanger.vadThUpdated = false; // Will be set to true after the vadThreshold has been updated. vadThread = new Thread(new Runnable() { // Execute if vadThread == 0, see below @Override public void run() { int vadCounter = 0; // Count how many times the following loop runs so that we can ignore the first K frames while (isPreparingVAD) { // Will become false when computeVadThreshold thread is run if (recorder == null) { System.out.println("Recorder: recorder is null"); } else { recorder.read(vadShortData, 0, recordBufferSize / 2); // Fill vadShortData[] SoundProcessingActivity.waveformView.updateAudioData(vadShortData); // Display current waveform } vadBufferedShortData.add(vadShortData); numFrames = vadBufferedShortData.get(0).length / samplePerFrm; // No. of frames in vadShortData (no frame overlapping) for (int n = 0; n < numFrames; n++) { int k = 0; float[] x = new float[samplePerFrm]; for (int i = (n * samplePerFrm); i < (n + 1) * samplePerFrm; i++) { // Copy one frame to x[] x[k] = (float) vadBufferedShortData.get(0)[i]; k++; } if (vadCounter > K) { // Ignore the first K frames double currEnergy = MFCC.compLogEnergy(x); vadBufEnergy.add(currEnergy); System.out.println("VadCounter: " + vadCounter + "; currEnergy: " + currEnergy); } vadCounter++; } vadBufferedShortData.remove(0); } System.out.println("VAD: Finish preparing VAD."); } }); if (vadThreshold == Config.VAD_DEFAULT_TH) { // We need to estimate threshold calibrateDialog.show(); // Note: this is always true in this version of the app, see code above handler.post(updateCalibrateDialog); // Execute run() of updateCalibrateDialog } else { vad = new VAD(vadThreshold, Config.endEventTh); // Create VAD object for detecting start and end of events handler.post(startDetection); // A VAD threshold has been defined, start detection right away. } }
From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java
/** * Launch the download of the courses list and store them in the database. * //from w w w. j av a 2 s .c o m * @param context * Application context. * @param username * UCL global user identifier. * @param password * UCL password. * @param end * Runnable to be executed at the end of the download. * @param mHandler * Handler to manage messages and threads. * */ public static void downloadCoursesFromUCLouvain(final LLNCampusActivity context, final String username, final String password, final Runnable end, final Handler mHandler) { Time t = new Time(); t.setToNow(); int year = t.year; // A new academic year begin in September (8th month on 0-based count). if (t.month < 8) { year--; } final int academicYear = year; mHandler.post(new Runnable() { public void run() { final ProgressDialog mProgress = new ProgressDialog(context); mProgress.setCancelable(false); mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgress.setMax(100); mProgress.setMessage(context.getString(R.string.connection)); mProgress.show(); new Thread(new Runnable() { /** * Set the progress to the value n and show the message nextStep * @param n * The progress value. * @param nextStep * The message to show (indicate the next step to be processed). */ public void progress(final int n, final String nextStep) { mHandler.post(new Runnable() { public void run() { mProgress.setProgress(n); mProgress.setMessage(nextStep); } }); Log.d("UCLouvain", nextStep); } /** * Notify to the user an error. * * @param msg * The message to show to the user. */ public void sendError(String msg) { notify(context.getString(R.string.error) + " :" + msg); mProgress.cancel(); } /** * Notify to the user a message. * * @param msg * The message to show to the user. */ public void notify(final String msg) { mHandler.post(new Runnable() { public void run() { context.notify(msg); } }); } public void run() { progress(0, context.getString(R.string.connection_ucl)); UCLouvain uclouvain = new UCLouvain(username, password); progress(20, context.getString(R.string.fetch_info)); ArrayList<Offer> offers = uclouvain.getOffers(academicYear); if (offers == null || offers.isEmpty()) { sendError(context.getString(R.string.error_academic_year) + academicYear); return; } int i = 40; ArrayList<Course> courses = new ArrayList<Course>(); for (Offer o : offers) { progress(i, context.getString(R.string.get_courses) + o.getOfferName()); ArrayList<Course> offerCourses = uclouvain.getCourses(o); if (offerCourses != null && !offerCourses.isEmpty()) { courses.addAll(offerCourses); } else { Log.e("CoursListEditActivity", "Error : No course for offer [" + o.getOfferCode() + "] " + o.getOfferName()); } i += (int) (30. / offers.size()); } if (courses.isEmpty()) { sendError(context.getString(R.string.courses_empty)); return; } // Remove old courses. progress(70, context.getString(R.string.cleaning_db)); LLNCampus.getDatabase().delete("Courses", "", null); LLNCampus.getDatabase().delete("Horaire", "", null); // Add new data. i = 80; for (Course c : courses) { progress(i, context.getString(R.string.add_courses_db)); ContentValues cv = new ContentValues(); cv.put("CODE", c.getCourseCode()); cv.put("NAME", c.getCoursName()); LLNCampus.getDatabase().insert("Courses", cv); i += (int) (20. / courses.size()); } progress(100, context.getString(R.string.end)); mProgress.cancel(); mHandler.post(end); } }).start(); } }); }
From source file:com.phonegap.Notification.java
/** * Show the progress dialog./*from w ww .ja v a 2 s.c om*/ * * @param title Title of the dialog * @param message The message of the dialog */ public synchronized void progressStart(final String title, final String message) { if (this.progressDialog != null) { this.progressDialog.dismiss(); this.progressDialog = null; } final Notification notification = this; final PhonegapActivity ctx = this.ctx; Runnable runnable = new Runnable() { public void run() { notification.progressDialog = new ProgressDialog(ctx); notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); notification.progressDialog.setTitle(title); notification.progressDialog.setMessage(message); notification.progressDialog.setCancelable(true); notification.progressDialog.setMax(100); notification.progressDialog.setProgress(0); notification.progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { notification.progressDialog = null; } }); notification.progressDialog.show(); } }; this.ctx.runOnUiThread(runnable); }
From source file:com.google.ytd.SubmitActivity.java
public void upload(Uri videoUri) { this.dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setMessage("uploading ..."); dialog.setCancelable(false);//from www .ja v a2s . c o m dialog.show(); Handler handler = new Handler() { @Override public void handleMessage(Message msg) { dialog.dismiss(); String videoId = msg.getData().getString("videoId"); if (!Util.isNullOrEmpty(videoId)) { currentFileSize = 0; totalBytesUploaded = 0; Intent result = new Intent(); result.putExtra("videoId", videoId); setResult(RESULT_OK, result); finish(); } else { String error = msg.getData().getString("error"); if (!Util.isNullOrEmpty(error)) { Toast.makeText(SubmitActivity.this, error, Toast.LENGTH_LONG).show(); } } } }; asyncUpload(videoUri, handler); }
From source file:org.liberty.android.fantastischmemo.downloader.DownloaderAnyMemo.java
private void downloadDatabase(final DownloadItem di) throws Exception { String filename = di.getExtras("filename"); if (filename == null) { throw new Exception("Could not get filename"); }//w ww . ja v a2 s. c o m String sdpath = AMEnv.DEFAULT_ROOT_PATH; File outFile = new File(sdpath + filename); mHandler.post(new Runnable() { public void run() { mProgressDialog = new ProgressDialog(DownloaderAnyMemo.this); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.setMessage(getString(R.string.loading_downloading)); mProgressDialog.show(); } }); try { OutputStream out; if (outFile.exists()) { throw new IOException("Database already exist!"); } try { outFile.createNewFile(); out = new FileOutputStream(outFile); URL myURL = new URL(di.getAddress()); Log.v(TAG, "URL IS: " + myURL); URLConnection ucon = myURL.openConnection(); final int fileSize = ucon.getContentLength(); mHandler.post(new Runnable() { public void run() { mProgressDialog.setMax(fileSize); } }); byte[] buf = new byte[BUFFER_SIZE]; InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, BUFFER_SIZE); Runnable increaseProgress = new Runnable() { public void run() { mProgressDialog.setProgress(mDownloadProgress); } }; int len = 0; int lenSum = 0; while ((len = bis.read(buf)) != -1) { out.write(buf, 0, len); lenSum += len; if (lenSum > fileSize / 50) { /* This is tricky. * The UI thread can not be updated too often. * So we update it only 50 times */ mDownloadProgress += lenSum; lenSum = 0; mHandler.post(increaseProgress); } } out.close(); is.close(); /* Uncompress the zip file that contains images */ if (filename.endsWith(".zip")) { mHandler.post(new Runnable() { public void run() { mProgressDialog.setProgress(fileSize); mProgressDialog.setMessage(getString(R.string.downloader_extract_zip)); } }); AMZipUtils.unZipFile(outFile, new File(AMEnv.DEFAULT_ROOT_PATH)); /* Delete the zip file if it is successfully decompressed */ outFile.delete(); } /* We do not check ttf file as db */ if (!filename.toLowerCase().endsWith(".ttf")) { /* Check if the db is correct */ filename = filename.replace(".zip", ".db"); String fullpath = sdpath + filename; AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(DownloaderAnyMemo.this, fullpath); try { long count = helper.getCardDao().getTotalCount(null); if (count <= 0L) { throw new RuntimeException("Downloaded empty db."); } } finally { AnyMemoDBOpenHelperManager.releaseHelper(helper); } /* Add downloaded item to file list */ recentListUtil.addToRecentList(fullpath); } } catch (Exception e) { if (outFile.exists()) { outFile.delete(); } throw new Exception(e); } } catch (Exception e) { Log.e(TAG, "Error downloading", e); throw new Exception(e); } finally { mHandler.post(new Runnable() { public void run() { mProgressDialog.dismiss(); } }); } }