List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:com.doplgangr.secrecy.views.FilesListFragment.java
public void onEventMainThread(Vault vault) { //The vault finishes initializing, is prepared to be populated. secret = vault;/*from w w w .j av a 2s. c o m*/ if (secret.isEcbVault()) { Util.alert(context, getString(R.string.Error__old_vault_format), getString(R.string.Error__old_vault_format_message), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Util.alert(context, getString(R.string.Upgrade__backup_beforehand), getString(R.string.Upgrade__backup_beforehand_message), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { backUp(); finish(); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ProgressDialog progress = new ProgressDialog(context); progress.setMessage(getString(R.string.Vault_updating)); progress.setIndeterminate(true); progress.setCancelable(false); progress.show(); updateVaultInBackground(progress); } }); } }, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { finish(); } }); return; } if (secret.wrongPass) { Util.alert(context, getString(R.string.Error__open_vault), getString(R.string.Error__open_vault_message), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { finish(); } }, null); return; } addFiles(); context.setTitle(secret.getName()); mInitializeDialog.dismiss(); setupViews(); }
From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { final BaseApplication application = (BaseApplication) getActivity().getApplication(); final IOneDriveClient oneDriveClient = application.getOneDriveClient(); if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD && data != null && data.getData() != null && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) { final ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setTitle(R.string.upload_in_progress_title); dialog.setMessage(getString(R.string.upload_in_progress_message)); dialog.setIndeterminate(false);/*from w ww .j a va 2s . co m*/ dialog.setCancelable(false); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format)); dialog.show(); final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(final Void... params) { try { final ContentResolver contentResolver = getActivity().getContentResolver(); final ContentProviderClient contentProvider = contentResolver .acquireContentProviderClient(data.getData()); final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData()); contentProvider.release(); // Fix up the file name (needed for camera roll photos, etc) final String filename = FileContent.getValidFileName(contentResolver, data.getData()); final Option option = new QueryOption("@name.conflictBehavior", "fail"); oneDriveClient.getDrive().getItems(mItemId).getChildren().byId(filename).getContent() .buildRequest(Collections.singletonList(option)) .put(fileInMemory, new IProgressCallback<Item>() { @Override public void success(final Item item) { dialog.dismiss(); Toast.makeText(getActivity(), application.getString(R.string.upload_complete, item.name), Toast.LENGTH_LONG).show(); refresh(); } @Override public void failure(final ClientException error) { dialog.dismiss(); if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) { Toast.makeText(getActivity(), R.string.upload_failed_name_conflict, Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(), application.getString(R.string.upload_failed, filename), Toast.LENGTH_LONG).show(); } } @Override public void progress(final long current, final long max) { dialog.setProgress((int) current); dialog.setMax((int) max); } }); } catch (final Exception e) { Log.e(getClass().getSimpleName(), e.getMessage()); Log.e(getClass().getSimpleName(), e.toString()); } return null; } }; uploadFile.execute(); } }
From source file:de.mkrtchyan.recoverytools.FlashFragment.java
public void showUnifiedBuildsDialog() { final AppCompatDialog UnifiedBuildsDialog = new AppCompatDialog(mContext); UnifiedBuildsDialog.setTitle(R.string.make_choice); final ArrayList<String> DevName = new ArrayList<>(); ArrayList<String> DevNamesCarriers = new ArrayList<>(); UnifiedBuildsDialog.setContentView(R.layout.dialog_unified_build); ListView UnifiedList = (ListView) UnifiedBuildsDialog.findViewById(R.id.lvUnifiedList); ArrayAdapter<String> UnifiedAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1, DevNamesCarriers);//from w ww . jav a 2 s .com UnifiedList.setAdapter(UnifiedAdapter); if (mDevice.getManufacture().equals("samsung")) { String[] unifiedGalaxyS3 = { "d2lte", "d2att", "d2cri", "d2mtr", "d2spr", "d2tmo", "d2usc", "d2vzw" }; String[] unifiedGalaxyNote3 = { "hlte", "hltespr", "hltetmo", "hltevzw", "htlexx" }; String[] unifiedGalaxyS4 = { "jflte", "jflteatt", "jfltecan", "jfltecri", "jfltecsp", "jfltespr", "jfltetmo", "jflteusc", "jfltevzw", "jfltexx", "jgedlte" }; if (Common.stringEndsWithArray(mDevice.getName(), unifiedGalaxyS3)) { DevName.addAll(Arrays.asList(unifiedGalaxyS3)); } else if (Common.stringEndsWithArray(mDevice.getName(), unifiedGalaxyS3)) { DevName.addAll(Arrays.asList(unifiedGalaxyNote3)); } else if (Common.stringEndsWithArray(mDevice.getName(), unifiedGalaxyS4)) { DevName.addAll(Arrays.asList(unifiedGalaxyS4)); } } if (mDevice.getManufacture().equals("motorola")) { String[] unifiedMsm8960 = { "moto_msm8960" }; if (mDevice.getBOARD().equals("msm8960")) { DevName.addAll(Arrays.asList(unifiedMsm8960)); } } for (String i : DevName) { if (i.contains("att")) { DevNamesCarriers.add(i + " (AT&T Mobility)"); } else if (i.contains("can")) { DevNamesCarriers.add(i + " (Canada)"); } else if (i.contains("cri")) { DevNamesCarriers.add(i + " (Cricket Wireless)"); } else if (i.contains("csp")) { DevNamesCarriers.add(i + " (C Spire Wireless)"); } else if (i.contains("mtr")) { DevNamesCarriers.add(i + " (MetroPCS)"); } else if (i.contains("spr")) { DevNamesCarriers.add(i + " (Sprint Corporation)"); } else if (i.contains("tmo")) { DevNamesCarriers.add(i + " (T-Mobile US)"); } else if (i.contains("usc")) { DevNamesCarriers.add(i + " (U.S. Cellular)"); } else if (i.contains("vzw")) { DevNamesCarriers.add(i + " (Verizon Wireless)"); } else if (i.contains("xx")) { DevNamesCarriers.add(i + " (International)"); } else if (i.contains("ged")) { DevNamesCarriers.add(i + " (Google Play Edition)"); } else { DevNamesCarriers.add(i + " (Unified)"); } } UnifiedList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { UnifiedBuildsDialog.dismiss(); final ProgressDialog reloading = new ProgressDialog(mContext); reloading.setMessage(mContext.getString(R.string.reloading)); reloading.setCancelable(false); reloading.show(); new Thread(new Runnable() { @Override public void run() { Common.setBooleanPref(mContext, Constants.PREF_NAME, Constants.PREF_KEY_SHOW_UNIFIED, false); mDevice.setName(DevName.get(position)); mDevice.loadRecoveryList(); mActivity.runOnUiThread(new Runnable() { @Override public void run() { reloading.dismiss(); mActivity.switchTo(FlashFragment.newInstance(mActivity)); } }); } }).start(); } }); AppCompatButton KeepCurrent = (AppCompatButton) UnifiedBuildsDialog.findViewById(R.id.bKeepCurrent); KeepCurrent.setText(String.format(getString(R.string.keep_current_name), mDevice.getName())); KeepCurrent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Common.setBooleanPref(mContext, Constants.PREF_NAME, Constants.PREF_KEY_SHOW_UNIFIED, false); UnifiedBuildsDialog.dismiss(); } }); if (DevName.size() > 0) { UnifiedBuildsDialog.show(); UnifiedBuildsDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Common.setBooleanPref(mContext, Constants.PREF_NAME, Constants.PREF_KEY_SHOW_UNIFIED, false); } }); } }
From source file:com.example.innf.newchangtu.Map.view.activity.MainActivity.java
private void uploadImage() { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setMessage("..."); progressDialog.show();/*from w w w . j a v a2 s . c o m*/ progressDialog.setCancelable(false); final BmobFile photo = new BmobFile(getTrackPhotoFile(mTrack)); photo.upload(new UploadFileListener() { @Override public void done(BmobException e) { if (null == e) { showToast("?"); mTrack.setPhoto(photo); mTrack.update(mTrack.getObjectId(), new UpdateListener() { @Override public void done(BmobException e) { if (null == e) { showToast("??"); } else { showToast("?" + e.getMessage()); } } }); } else { showToast("" + e.getMessage()); } progressDialog.cancel(); } }); }
From source file:fm.smart.r1.activity.ItemActivity.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); // this should be called once image has been chosen by user // using requestCode to pass item id - haven't worked out any other way // to do it/* ww w. j a v a 2 s .co m*/ // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in if (Main.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid navigation back to this? LoginActivity.return_to = ItemActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id")); startActivity(intent); // TODO in this case forcing the user to rechoose the image // seems a little // rude - should probably auto-submit here ... } else { // Bundle extras = data.getExtras(); // String sentence_id = (String) extras.get("sentence_id"); final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Uploading image ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add_image = new Thread() { public void run() { // TODO needs to check for interruptibility String sentence_id = Integer.toString(requestCode); Uri selectedImage = data.getData(); // Bitmap bitmap = Media.getBitmap(getContentResolver(), // selectedImage); // ByteArrayOutputStream bytes = new // ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 40, // bytes); // ByteArrayInputStream fileInputStream = new // ByteArrayInputStream( // bytes.toByteArray()); // TODO Might have to save to file system first to get // this // to work, // argh! // could think of it as saving to cache ... // add image to sentence FileInputStream is = null; FileOutputStream os = null; File file = null; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // ByteArrayInputStream bais = new // ByteArrayInputStream(bytes.toByteArray()); // FileDescriptor fd = // resolver.openFileDescriptor(selectedImage, // "r").getFileDescriptor(); // is = new FileInputStream(fd); String filename = "test.jpg"; File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE); file = new File(dir, filename); os = new FileOutputStream(file); // while (bais.available() > 0) { // / os.write(bais.read()); // } os.write(bytes.toByteArray()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } // File file = new // File(Uri.decode(selectedImage.toString())); // ensure item is in users default list ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, (String) item.item_node.atts.get("id"), ItemActivity.this); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default list ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id, (String) item.item_node.atts.get("id"), Main.default_study_list_id, ItemActivity.this); result = ItemActivity.add_sentence_list_result; if (ItemActivity.add_sentence_list_result.success()) { String media_entity = "http://test.com/test.jpg"; String author = "tansaku"; String author_url = "http://smart.fm/users/tansaku"; Log.d("DEBUG-IMAGE-URI", selectedImage.toString()); ItemActivity.add_image_result = addImage(file, media_entity, author, author_url, "1", sentence_id, (String) item.item_node.atts.get("id"), Main.default_study_list_id); result = ItemActivity.add_image_result; } } final Result display = result; myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(display.getTitle()); dialog.setMessage(display.getMessage()); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (ItemActivity.add_image_result != null && ItemActivity.add_image_result.success()) { ItemListActivity.loadItem(ItemActivity.this, item.item_node.atts.get("id").toString()); } } }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add_image.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add_image.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add_image.start(); } } }
From source file:com.zhenlaidian.ui.InputCarNumberActivity.java
public void getParkInfo(String carnumber) throws UnsupportedEncodingException { if (!IsNetWork.IsHaveInternet(this)) { Toast.makeText(this, "???", Toast.LENGTH_SHORT).show(); return;/*from ww w. ja v a 2 s .co m*/ } String car = URLEncoder.encode(carnumber, "utf-8"); AQuery aQuery = new AQuery(InputCarNumberActivity.this); String path = baseurl; String url = path + "collectorrequest.do?action=getecsorder&token=" + token + "&car_number=" + URLEncoder.encode(car, "utf-8") + "&berthid=" + SharedPreferencesUtils.getIntance(this).getberthid() + "&version=" + CommontUtils.getVersion(this) + "&out=json"; MyLog.w("InputCarNumberActivity-->>", "?URL-->>" + url); final ProgressDialog dialog = ProgressDialog.show(InputCarNumberActivity.this, "...", "???...", true, true); dialog.setCancelable(false); aQuery.ajax(url, String.class, new AjaxCallback<String>() { @Override public void callback(String url, String object, AjaxStatus status) { dialog.dismiss(); if (getIntent().getStringExtra("from").equals("input")) { // if (object != null) { Gson gson = new Gson(); listEntity = gson.fromJson(object, ZhuiJiaoListEntity.class); MyLog.i("ParkingInfoActivity-->>", "??" + listEntity.toString()); ismonthuser = listEntity.getIsmonthuser(); if (listEntity.getResult().equals("0")) { //?? //? putStringToPreference("preorderid", listEntity.getOrderid()); if (getBooleanFromPreference("next")) { //? intent2(); } else { entity = listEntity.getOrders(); Intent i = new Intent(context, ZhuiJiaoListActivity.class); putStringToPreference("carnumber", et_carnumber.getText().toString()); i.putExtra("list", entity); startActivityForResult(i, Constant.BACK_FROM_OWE); } } else if (listEntity.getResult().equals("1")) { //?? putStringToPreference("preorderid", listEntity.getOrderid()); intent2(); } else if (listEntity.getResult().equals("-2")) { new AlertDialog.Builder(InputCarNumberActivity.this).setTitle("??") .setIcon(R.drawable.app_icon_32).setMessage("" + listEntity.getErrmsg()) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { putStringToPreference("preorderid", listEntity.getOrderid()); entity = listEntity.getOrders(); if (getBooleanFromPreference("next")) { //? intent2(); } else if (!(entity != null && entity.size() > 0)) { //? intent2(); } else { Intent i = new Intent(context, ZhuiJiaoListActivity.class); putStringToPreference("carnumber", et_carnumber.getText().toString()); i.putExtra("list", entity); startActivityForResult(i, Constant.BACK_FROM_OWE); } } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).create().show(); } else { // -1 -3 new AlertDialog.Builder(InputCarNumberActivity.this).setTitle("??") .setIcon(R.drawable.app_icon_32).setMessage("" + listEntity.getErrmsg()) .setPositiveButton("", null).create().show(); } } else { putStringToPreference("preorderid", ""); intent2(); } } else { //? if (object != null) { Gson gson = new Gson(); listEntity = gson.fromJson(object, ZhuiJiaoListEntity.class); MyLog.i("ParkingInfoActivity-->>", "??" + listEntity.toString()); if (listEntity.getResult().equals("1")) { //?? CommontUtils.toast(context, ""); finish(); } else { //?? entity = listEntity.getOrders(); if (CommontUtils.checkList(entity)) { Intent i = new Intent(context, ZhuiJiaoListActivity.class); putStringToPreference("carnumber", et_carnumber.getText().toString()); i.putExtra("list", entity); startActivityForResult(i, Constant.BACK_FROM_OWE); } else { CommontUtils.toast(context, ""); finish(); } } } else { CommontUtils.toast(context, ""); finish(); } } } }.timeout(5000)); }
From source file:uk.co.armedpineapple.cth.SDLActivity.java
private void installFiles(final SharedPreferences preferences) { final ProgressDialog dialog = new ProgressDialog(this); final UnzipTask unzipTask = new UnzipTask(app.configuration.getCthPath() + "/scripts/", this) { @Override/*from w ww . j a v a2s . com*/ protected void onPreExecute() { super.onPreExecute(); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setMessage(getString(R.string.preparing_game_files_dialog)); dialog.setIndeterminate(false); dialog.setCancelable(false); dialog.show(); } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); dialog.setProgress(values[0]); dialog.setMax(values[1]); } @Override protected void onPostExecute(AsyncTaskResult<String> result) { super.onPostExecute(result); Exception error; if ((error = result.getError()) != null) { Log.d(LOG_TAG, "Error copying files."); BugSenseHandler.sendException(error); } Editor edit = preferences.edit(); edit.putBoolean("scripts_copied", true); edit.putInt("last_version", currentVersion); edit.commit(); dialog.hide(); loadApplication(); } }; AsyncTask<String, Void, AsyncTaskResult<File>> copyTask = new AsyncTask<String, Void, AsyncTaskResult<File>>() { @Override protected AsyncTaskResult<File> doInBackground(String... params) { try { Files.copyAsset(SDLActivity.this, params[0], params[1]); } catch (IOException e) { return new AsyncTaskResult<File>(e); } return new AsyncTaskResult<File>(new File(params[1] + "/" + params[0])); } @Override protected void onPostExecute(AsyncTaskResult<File> result) { super.onPostExecute(result); File f; if ((f = result.getResult()) != null) { unzipTask.execute(f); } else { BugSenseHandler.sendException(result.getError()); } } }; if (Files.canAccessExternalStorage()) { copyTask.execute(ENGINE_ZIP_FILE, getExternalCacheDir().getAbsolutePath()); } else { DialogFactory.createExternalStorageWarningDialog(this, true).show(); } }
From source file:com.uraroji.garage.android.arrraycopybench.MainActivity.java
private void startBench() { mResultTextView.setText(""); final String arrayTypeStr = mArrayTypeSpinner.getSelectedItem().toString(); final int arrayLength = Integer.parseInt(mArrayLengthSpinner.getSelectedItem().toString()); final int benchTimes = Integer.parseInt(mBenchTimesSpinner.getSelectedItem().toString()); final ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getString(R.string.benchmarking)); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setCancelable(false); dialog.show();//from www .j ava 2 s .co m final Handler handler = new Handler(); if (arrayTypeStr.equals("byte")) { final byte[] src = new byte[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (byte) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("short")) { final short[] src = new short[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (short) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("int")) { final int[] src = new int[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (int) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("long")) { final long[] src = new long[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (long) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("double")) { final double[] src = new double[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (double) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Object")) { final Object[] src = new Object[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Object(); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Byte")) { final Byte[] src = new Byte[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Byte((byte) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Integer")) { final Integer[] src = new Integer[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Integer((int) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Long")) { final Long[] src = new Long[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Long((long) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Double")) { final Double[] src = new Double[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Double((double) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else { dialog.dismiss(); } }
From source file:org.telegram.ui.CacheControlActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("CacheSettings", R.string.CacheSettings)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// www . j a v a 2 s . c om public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ListView listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) { if (getParentActivity() == null) { return; } if (i == keepMediaRow) { BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); builder.setItems( new CharSequence[] { LocaleController.formatPluralString("Weeks", 1), LocaleController.formatPluralString("Months", 1), LocaleController.getString("KeepMediaForever", R.string.KeepMediaForever) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { SharedPreferences.Editor editor = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit(); editor.putInt("keep_media", which).commit(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } PendingIntent pintent = PendingIntent.getService( ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, ClearCacheService.class), 0); AlarmManager alarmManager = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); if (which == 2) { alarmManager.cancel(pintent); } else { alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, pintent); } } }); showDialog(builder.create()); } else if (i == databaseRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setMessage( LocaleController.getString("LocalDatabaseClear", R.string.LocalDatabaseClear)); builder.setPositiveButton(LocaleController.getString("CacheClear", R.string.CacheClear), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); progressDialog .setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { @Override public void run() { try { SQLiteDatabase database = MessagesStorage.getInstance() .getDatabase(); ArrayList<Long> dialogsToCleanup = new ArrayList<>(); SQLiteCursor cursor = database .queryFinalized("SELECT did FROM dialogs WHERE 1"); StringBuilder ids = new StringBuilder(); while (cursor.next()) { long did = cursor.longValue(0); int lower_id = (int) did; int high_id = (int) (did >> 32); if (lower_id != 0 && high_id != 1) { dialogsToCleanup.add(did); } } cursor.dispose(); SQLitePreparedStatement state5 = database .executeFast("REPLACE INTO messages_holes VALUES(?, ?, ?)"); SQLitePreparedStatement state6 = database.executeFast( "REPLACE INTO media_holes_v2 VALUES(?, ?, ?, ?)"); database.beginTransaction(); for (int a = 0; a < dialogsToCleanup.size(); a++) { Long did = dialogsToCleanup.get(a); int messagesCount = 0; cursor = database.queryFinalized( "SELECT COUNT(mid) FROM messages WHERE uid = " + did); if (cursor.next()) { messagesCount = cursor.intValue(0); } cursor.dispose(); if (messagesCount <= 2) { continue; } cursor = database.queryFinalized( "SELECT last_mid_i, last_mid FROM dialogs WHERE did = " + did); int messageId = -1; if (cursor.next()) { long last_mid_i = cursor.longValue(0); long last_mid = cursor.longValue(1); SQLiteCursor cursor2 = database.queryFinalized( "SELECT data FROM messages WHERE uid = " + did + " AND mid IN (" + last_mid_i + "," + last_mid + ")"); try { while (cursor2.next()) { NativeByteBuffer data = cursor2.byteBufferValue(0); if (data != null) { TLRPC.Message message = TLRPC.Message .TLdeserialize(data, data.readInt32(false), false); data.reuse(); if (message != null) { messageId = message.id; } } } } catch (Exception e) { FileLog.e("tmessages", e); } cursor2.dispose(); database.executeFast("DELETE FROM messages WHERE uid = " + did + " AND mid != " + last_mid_i + " AND mid != " + last_mid).stepThis().dispose(); database.executeFast( "DELETE FROM messages_holes WHERE uid = " + did) .stepThis().dispose(); database.executeFast( "DELETE FROM bot_keyboard WHERE uid = " + did) .stepThis().dispose(); database.executeFast( "DELETE FROM media_counts_v2 WHERE uid = " + did) .stepThis().dispose(); database.executeFast( "DELETE FROM media_v2 WHERE uid = " + did) .stepThis().dispose(); database.executeFast( "DELETE FROM media_holes_v2 WHERE uid = " + did) .stepThis().dispose(); BotQuery.clearBotKeyboard(did, null); if (messageId != -1) { MessagesStorage.createFirstHoles(did, state5, state6, messageId); } } cursor.dispose(); } state5.dispose(); state6.dispose(); database.commitTransaction(); database.executeFast("VACUUM").stepThis().dispose(); } catch (Exception e) { FileLog.e("tmessages", e); } finally { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } if (listAdapter != null) { File file = new File( ApplicationLoader.getFilesDirFixed(), "cache4.db"); databaseSize = file.length(); listAdapter.notifyDataSetChanged(); } } }); } } }); } }); showDialog(builder.create()); } else if (i == cacheRow) { if (totalSize <= 0 || getParentActivity() == null) { return; } BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); builder.setApplyTopPadding(false); builder.setApplyBottomPadding(false); LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); for (int a = 0; a < 6; a++) { long size = 0; String name = null; if (a == 0) { size = photoSize; name = LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache); } else if (a == 1) { size = videoSize; name = LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache); } else if (a == 2) { size = documentsSize; name = LocaleController.getString("LocalDocumentCache", R.string.LocalDocumentCache); } else if (a == 3) { size = musicSize; name = LocaleController.getString("LocalMusicCache", R.string.LocalMusicCache); } else if (a == 4) { size = audioSize; name = LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache); } else if (a == 5) { size = cacheSize; name = LocaleController.getString("LocalCache", R.string.LocalCache); } if (size > 0) { clear[a] = true; CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity()); checkBoxCell.setTag(a); checkBoxCell.setBackgroundResource(R.drawable.list_selector); linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); checkBoxCell.setText(name, AndroidUtilities.formatFileSize(size), true, true); checkBoxCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; int num = (Integer) cell.getTag(); clear[num] = !clear[num]; cell.setChecked(clear[num], true); } }); } else { clear[a] = false; } } BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(getParentActivity(), 1); cell.setBackgroundResource(R.drawable.list_selector); cell.setTextAndIcon( LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache).toUpperCase(), 0); cell.setTextColor(Theme.STICKERS_SHEET_REMOVE_TEXT_COLOR); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (visibleDialog != null) { visibleDialog.dismiss(); } } catch (Exception e) { FileLog.e("tmessages", e); } cleanupFolders(); } }); linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); builder.setCustomView(linearLayout); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.almarsoft.GroundhogReader.MessageListActivity.java
@Override protected Dialog onCreateDialog(int id) { ProgressDialog dialog = null; if (id == ID_DIALOG_CATCHUP) { dialog = new ProgressDialog(this); dialog.setMessage(getString(R.string.catchingup_server)); dialog.setIndeterminate(true);// ww w.j a v a 2s .c om dialog.setCancelable(false); return dialog; } return super.onCreateDialog(id); }