List of usage examples for android.app ProgressDialog setMessage
@Override public void setMessage(CharSequence message)
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java
private void uploadPhoto() { final ProgressDialog progress = new ProgressDialog(DetailsActivity.this); progress.setMessage(getResources().getString(R.string.send)); progress.setTitle(getResources().getString(R.string.app_name)); progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); progress.show();/* w w w . j ava 2 s .c om*/ final File mediaFile = getStoredMediaFile(); RequestBody file = RequestBody .create(MediaType.parse(URLConnection.guessContentTypeFromName(mediaFile.getName())), mediaFile); rsapi.photoUpload(email, token, bahnhof.getId(), countryCode.toLowerCase(), file) .enqueue(new Callback<Void>() { @Override public void onResponse(Call<Void> call, Response<Void> response) { progress.dismiss(); switch (response.code()) { case 202: new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_completed); break; case 400: new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_bad_request); break; case 401: new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_token_invalid); break; case 409: new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_conflict); break; case 413: new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_too_big); break; default: new SimpleDialogs().confirm(DetailsActivity.this, String.format(getText(R.string.upload_failed).toString(), response.code())); } } @Override public void onFailure(Call<Void> call, Throwable t) { Log.e(TAG, "Error uploading photo", t); progress.dismiss(); new SimpleDialogs().confirm(DetailsActivity.this, String.format(getText(R.string.upload_failed).toString(), t.getMessage())); } }); }
From source file:com.money.manager.ex.MainActivity.java
public void startServiceSyncDropbox() { if (mDropboxHelper != null && mDropboxHelper.isLinked()) { Intent service = new Intent(getApplicationContext(), DropboxServiceIntent.class); service.setAction(DropboxServiceIntent.INTENT_ACTION_SYNC); service.putExtra(DropboxServiceIntent.INTENT_EXTRA_LOCAL_FILE, MoneyManagerApplication.getDatabasePath(this.getApplicationContext())); service.putExtra(DropboxServiceIntent.INTENT_EXTRA_REMOTE_FILE, mDropboxHelper.getLinkedRemoteFile()); //progress dialog final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setCancelable(false); progressDialog.setMessage(getString(R.string.dropbox_syncProgress)); progressDialog.setIndeterminate(true); progressDialog.show();/*from w ww . j a v a2 s .c o m*/ //create a messenger Messenger messenger = new Messenger(new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_NOT_CHANGE) { // close dialog if (progressDialog != null && progressDialog.isShowing()) progressDialog.hide(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, R.string.dropbox_database_is_synchronized, Toast.LENGTH_LONG).show(); } }); } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_DOWNLOAD) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, R.string.dropbox_download_is_starting, Toast.LENGTH_LONG).show(); } }); } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_DOWNLOAD) { // close dialog if (progressDialog != null && progressDialog.isShowing()) progressDialog.hide(); // reload fragment reloadAllFragment(); } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_UPLOAD) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, R.string.dropbox_upload_is_starting, Toast.LENGTH_LONG).show(); } }); } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_UPLOAD) { // close dialog if (progressDialog != null && progressDialog.isShowing()) progressDialog.hide(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, R.string.upload_file_to_dropbox_complete, Toast.LENGTH_LONG).show(); } }); } } }); service.putExtra(DropboxServiceIntent.INTENT_EXTRA_MESSENGER, messenger); this.startService(service); } }
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
private void applyRules() { // Get context final Context context = this; // Show progress final ProgressDialog progress = new ProgressDialog(this); // Finish message final Toast completed = Toast.makeText(this, getString(R.string.firewall_rules_complete), Toast.LENGTH_SHORT);/*from w w w.j a va 2s . c om*/ progress.setIndeterminate(true); progress.setProgress(0); progress.show(); // Handler to dismiss progress @SuppressLint("HandlerLeak") final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); progress.dismiss(); completed.show(); } }; // Apply firewall rules new Thread(new Runnable() { @Override public void run() { progress.setMessage(getString(R.string.firewall_rules_create)); Firewall.createRules(context); handler.sendMessage(handler.obtainMessage()); } }).start(); }
From source file:org.runnerup.export.UploadManager.java
private void uploadOK(Uploader uploader, ProgressDialog copySpinner, SQLiteDatabase copyDB, long id) { copySpinner.setMessage(getResources().getString(R.string.saving)); ContentValues tmp = new ContentValues(); tmp.put(DB.EXPORT.ACCOUNT, uploader.getId()); tmp.put(DB.EXPORT.ACTIVITY, id);/*from w w w.j av a 2s . c o m*/ tmp.put(DB.EXPORT.STATUS, 0); copyDB.insert(DB.EXPORT.TABLE, null, tmp); }
From source file:export.UploadManager.java
protected void doListWorkout(final Uploader uploader) { final ProgressDialog copySpinner = mSpinner; copySpinner.setMessage("Listing from " + uploader.getName()); final ArrayList<Pair<String, String>> list = new ArrayList<Pair<String, String>>(); new AsyncTask<Uploader, String, Uploader.Status>() { @Override//from w ww .j a v a2 s . c o m protected Uploader.Status doInBackground(Uploader... params) { try { return params[0].listWorkouts(list); } catch (Exception ex) { ex.printStackTrace(); return Uploader.Status.ERROR; } } @Override protected void onPostExecute(Uploader.Status result) { switch (result) { case CANCEL: case ERROR: case INCORRECT_USAGE: case SKIP: break; case OK: for (Pair<String, String> w : list) { workoutRef.add(new WorkoutRef(uploader.getName(), w.first, w.second)); } break; case NEED_AUTH: handleAuth(new Callback() { @Override public void run(String uploaderName, export.Uploader.Status status) { switch (status) { case CANCEL: case SKIP: case ERROR: case INCORRECT_USAGE: case NEED_AUTH: // should be handled inside // connect "loop" nextListWorkout(); break; case OK: doListWorkout(uploader); break; } } }, uploader, result.authMethod); return; } nextListWorkout(); } }.execute(uploader); }
From source file:com.cerema.cloud2.ui.activity.Uploader.java
@Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_WAITING: final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme); pDialog.setIndeterminate(false); pDialog.setCancelable(false);/* w w w. j a v a 2 s . c om*/ pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading)); pDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress); v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent), android.graphics.PorterDuff.Mode.MULTIPLY); } }); return pDialog; case DIALOG_NO_ACCOUNT: builder.setIcon(R.drawable.ic_warning); builder.setTitle(R.string.uploader_wrn_no_account_title); builder.setMessage( String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name))); builder.setCancelable(false); builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) { // using string value since in API7 this // constant is not defined // in API7 < this constant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() }); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } else { // since in API7 there is no direct call for // account setup, so we need to // show our own AccountSetupAcricity, get // desired results and setup // everything for ourself Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } } }); builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: CharSequence ac[] = new CharSequence[mAccountManager .getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false); } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); onAccountSet(mAccountWasRestored); dialog.dismiss(); mAccountSelected = true; mAccountSelectionShowing = false; } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mAccountSelectionShowing = false; dialog.cancel(); finish(); } }); return builder.create(); case DIALOG_NO_STREAM: builder.setIcon(R.drawable.ic_warning); builder.setTitle(R.string.uploader_wrn_no_content_title); builder.setMessage(R.string.uploader_wrn_no_content_text); builder.setCancelable(false); builder.setNegativeButton(R.string.common_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); default: throw new IllegalArgumentException("Unknown dialog id: " + id); } }
From source file:com.fabernovel.alertevoirie.NewsActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_PROGRESS: ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); pd.setIndeterminate(true);/*w ww . j ava 2 s. c o m*/ pd.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(DIALOG_PROGRESS); } }); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AVService.getInstance(NewsActivity.this).cancelTask(); finish(); } }); pd.setMessage(getString(R.string.ui_message_loading)); return pd; default: return super.onCreateDialog(id); } }
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/*from w ww. j a v a 2 s . c o m*/ 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: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 av a 2s .c o 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.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 w w .java2s .c o 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(); } }