List of usage examples for android.app ProgressDialog setMessage
@Override public void setMessage(CharSequence message)
From source file:com.owncloud.android.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 av a 2 s .com 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(android.R.drawable.ic_dialog_alert); 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 // constatn is not defined // in API7 < this constatant 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(android.R.drawable.ic_dialog_alert); 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:fm.smart.r1.activity.ItemActivity.java
public void addToList(final String item_id) { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Adding item to study list ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add = new Thread() { public void run() { ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, item_id, ItemActivity.this); myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(ItemActivity.add_item_result.getTitle()); dialog.setMessage(ItemActivity.add_item_result.getMessage()); ItemActivity.add_item_result = null; dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }//from ww w . j a va 2 s . c om }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add.start(); }
From source file:com.doplgangr.secrecy.views.FilesListFragment.java
void changePassphrase() { final View dialogView = View.inflate(context, R.layout.change_passphrase, null); new AlertDialog.Builder(context).setTitle(getString(R.string.Vault__change_password)).setView(dialogView) .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String oldPassphrase = ((EditText) dialogView.findViewById(R.id.oldPassphrase)).getText() .toString(); String newPassphrase = ((EditText) dialogView.findViewById(R.id.newPassphrase)).getText() .toString(); String confirmNewPassphrase = ((EditText) dialogView.findViewById(R.id.confirmPassphrase)) .getText().toString(); ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setMessage(CustomApp.context.getString(R.string.Vault__changing_password)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.show(); changePassphraseInBackground(oldPassphrase, newPassphrase, confirmNewPassphrase, progressDialog); }/*from ww w. j av a 2s .c o m*/ }).setNegativeButton(R.string.CANCEL, Util.emptyClickListener).show(); }
From source file:org.ohmage.authenticator.AuthenticatorActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog = super.onCreateDialog(id); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); switch (id) { case DIALOG_LOGIN_ERROR: dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_auth_error).setCancelable(true) .setPositiveButton(R.string.ok, null) /*/* ww w. ja va 2 s . co m*/ * .setNeutralButton("Help", new * DialogInterface.OnClickListener() { * @Override public void onClick(DialogInterface dialog, int * which) { startActivity(new Intent(LoginActivity.this, * HelpActivity.class)); //put extras for specific help on login * error } }) */; // add button for contact dialog = dialogBuilder.create(); break; case DIALOG_USER_DISABLED: dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_account_disabled) .setCancelable(true).setPositiveButton(R.string.ok, null) /* * .setNeutralButton("Help", new * DialogInterface.OnClickListener() { * @Override public void onClick(DialogInterface dialog, int * which) { startActivity(new Intent(LoginActivity.this, * HelpActivity.class)); //put extras for specific help on login * error } }) */; // add button for contact dialog = dialogBuilder.create(); break; case DIALOG_NETWORK_ERROR: dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_network_error) .setCancelable(true).setPositiveButton(R.string.ok, null) /* * .setNeutralButton("Help", new * DialogInterface.OnClickListener() { * @Override public void onClick(DialogInterface dialog, int * which) { startActivity(new Intent(LoginActivity.this, * HelpActivity.class)); //put extras for specific help on http * error } }) */; // add button for contact dialog = dialogBuilder.create(); break; case DIALOG_INTERNAL_ERROR: dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_server_error).setCancelable(true) .setPositiveButton(R.string.ok, null) /* * .setNeutralButton("Help", new * DialogInterface.OnClickListener() { * @Override public void onClick(DialogInterface dialog, int * which) { startActivity(new Intent(LoginActivity.this, * HelpActivity.class)); //put extras for specific help on http * error } }) */; // add button for contact dialog = dialogBuilder.create(); break; case DIALOG_LOGIN_PROGRESS: { pDialog = new ProgressDialog(this); pDialog.setMessage(getString(R.string.login_authenticating, getString(R.string.server_name))); pDialog.setIndeterminate(true); pDialog.setCancelable(false); dialog = pDialog; break; } case DIALOG_DOWNLOADING_CAMPAIGNS: { ProgressDialog pDialog = new ProgressDialog(this); pDialog.setMessage(getString(R.string.login_download_campaign)); pDialog.setCancelable(false); // pDialog.setIndeterminate(true); dialog = pDialog; break; } case DIALOG_SERVER_LIST: { AlertDialog.Builder builder = new AlertDialog.Builder(this); ArrayList<String> servers = Lists.newArrayList(getResources().getStringArray(R.array.servers)); if (OhmageApplication.DEBUG_BUILD) { servers.add("https://test.ohmage.org/"); } final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, servers); builder.setTitle(R.string.login_choose_server); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mServerEdit .setText(((AlertDialog) dialog).getListView().getAdapter().getItem(which).toString()); } }); dialog = builder.create(); break; } } return dialog; }
From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java
/** * Display the UI defined in activity_photographs.xml upon activity start. *///from w w w.ja va 2 s . co m @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_photographs); /* * Add "up" button functionality in the left of application icon in * top-left corner, allowing user to return to "welcome" screen */ final ActionBar ab = this.getSupportActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); /* * Create "navigation spinner" in activity action bar that allows user to * view a different content screen */ final ArrayAdapter<CharSequence> navDropDownAdapter = ArrayAdapter.createFromResource(this, R.array.ab_content_activities_names, R.layout.ab_navigation_dropdown_item); ab.setListNavigationCallbacks(navDropDownAdapter, this); ab.setSelectedNavigationItem(ContentActivity.PHOTOGRAPHS.getABDropDownListIndex()); // Retrieve name of lighthouse that user is viewing final Bundle extras = this.getIntent().getExtras(); final String lighthouseNameSelected = extras.getString("lighthousename"); // Lighthouse data guaranteed to exist ("Welcome" activity performs data // existence validation) final LighthouseDataParser lighthouseInformationParser = new LighthouseDataParser( this.getApplicationContext(), lighthouseNameSelected); lighthouseInformationParser.parseLighthouseData(); this.currentLighthouse = lighthouseInformationParser.getLighthouse(); /* * Complete Flickr downloading task only if a network connection exists * _and_ the cache is empty or contains information about a lighthouse * other than the "desired" one */ this.userConnectedToInternet = this.networkConnectionExists(); FlickrDownloadHandler downloadHandler = null; if (this.userConnectedToInternet) { if (!this.photoCacheExists()) { if (!PhotographsActivity.downloadingThreadStarted) { Log.d("LIGHTNAVDEBUG", "Creating dialog..."); // Display dialog informing user about download progress final ProgressDialog flickrPhotoDownloadDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER); flickrPhotoDownloadDialog.setTitle("Downloading Flickr photos"); flickrPhotoDownloadDialog.setMessage("Downloading photographs from Flickr..."); flickrPhotoDownloadDialog.setCancelable(true); flickrPhotoDownloadDialog.show(); final HashSet<Photograph> flickrPhotos = new HashSet<Photograph>(); /* * Start background thread that will complete actual downloading * process */ PhotographsActivity.downloadingThreadStarted = true; downloadHandler = new FlickrDownloadHandler(this, this.currentLighthouse, flickrPhotos, flickrPhotoDownloadDialog); final FlickrPhotoDownloadThread downloadThread = new FlickrPhotoDownloadThread( this.getApplicationContext(), this.currentLighthouse, downloadHandler, PhotographsActivity.XML_DOWNLOAD_COMPLETE, PhotographsActivity.INTERRUPT); Log.d("LIGHTNAVDEBUG", "Flickr download XML thread started"); downloadThread.start(); /* * Interrupt (stop) currently-running thread if user cancels * downloading operation explicitly */ flickrPhotoDownloadDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface di) { if (downloadThread.isAlive()) { downloadThread.interrupt(); } else if (PhotographsActivity.this.parseOutputThread != null && PhotographsActivity.this.parseOutputThread.isAlive()) { PhotographsActivity.this.parseOutputThread.interrupt(); } else { // Do nothing } } }); } } else { final ArrayList<Photograph> lighthousePhotos = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); lighthousePhotos.clear(); final File downloadCacheDir = new File(this.getFilesDir() + "/download-cache/"); final File[] downloadCacheDirContents = downloadCacheDir.listFiles(); for (int i = 0; i < downloadCacheDirContents.length; i++) { final String downloadCacheDirContentName = downloadCacheDirContents[i].getName(); final String[] downloadCacheDirContentPieces = downloadCacheDirContentName.split("_"); final Long photoID = Long.parseLong(downloadCacheDirContentPieces[2]); final String ownerName = downloadCacheDirContentPieces[3].replace("~", " "); final String creativeCommonsLicenseIDString = downloadCacheDirContentPieces[4].substring(0, 1); final int creativeCommonsLicenseID = Integer.parseInt(creativeCommonsLicenseIDString); final CreativeCommonsLicenseType licenseType = CreativeCommonsLicenseType .convertToLicenseEnum(creativeCommonsLicenseID); lighthousePhotos.add(new Photograph(photoID, ownerName, licenseType, "/download-cache/" + downloadCacheDirContentName)); } this.currentLighthouse.getAlbum().put(ActivityVisible.PHOTOGRAPHS, lighthousePhotos); } } if (!this.userConnectedToInternet || this.userConnectedToInternet && this.photoCacheExists() || downloadHandler != null && downloadHandler.getFlickrOperationsComplete()) { // Display first photograph as "selected" photograph in top-left corner // by default final ArrayList<Photograph> photoSet = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); final Photograph currentPhotoOnLeftSide = photoSet.get(0); final ImageView currentPhotoView = (ImageView) this.findViewById(R.id.iv_photographs_current_image); if (this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + currentPhotoOnLeftSide.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(currentPhotoOnLeftSide.getResID()); } // Add credits for "default" main photograph final TextView owner = (TextView) this.findViewById(R.id.tv_photographs_photographer); final TextView licenseType = (TextView) this.findViewById(R.id.tv_photographs_license); owner.setText("Uploaded by: " + currentPhotoOnLeftSide.getOwner()); licenseType.setText("License: " + currentPhotoOnLeftSide.getLicenseTypeAbbreviation()); /* * Display Google Map as a SupportMapFragment (instead of MapFragment * for compatibility with Android 2.x) */ /* * BIG thanks to http://www.truiton.com/2013/05/ * android-supportmapfragment-example/ for getting this part of the app * working */ final FragmentManager fm = this.getSupportFragmentManager(); final Fragment mapFragment = fm.findFragmentById(R.id.frag_photographs_map); final SupportMapFragment smf = (SupportMapFragment) mapFragment; smf.getMap(); final GoogleMap supportMap = smf.getMap(); /* * Center map at lighthouse location, at a zoom level of 12 with no * tilt, facing due north */ final LatLng lighthouseLocation = new LatLng(this.currentLighthouse.getCoordinates().getLatitude(), this.currentLighthouse.getCoordinates().getLongitude()); final float zoomLevel = 12.0f; final float tiltAngle = 0.0f; final float bearing = 0.0f; final CameraPosition cameraPos = new CameraPosition(lighthouseLocation, zoomLevel, tiltAngle, bearing); supportMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos)); /* * Allows user to open a maps application (such as Google Maps) upon * selecting the map fragment */ /* * Courtesy of: * http://stackoverflow.com/questions/6205827/how-to-open-standard * -google-map-application-from-my-application */ supportMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng lighthouseCoordinates) { final String uri = String.format(Locale.US, "geo:%f,%f", lighthouseCoordinates.latitude, lighthouseCoordinates.longitude); final Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PhotographsActivity.this.startActivity(googleMapsIntent); } }); this.gv = (GridView) this.findViewById(R.id.gv_photographs_thumbnails); /* * Photographs in the "current lighthouse album" are from Flickr if the * album is empty or if the first (or _any_) of the elements in the * album do not have a "proper" static resource ID */ this.photosFromFlickr = this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).isEmpty() || this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).iterator().next() .getResID() == 0; final LighthouseImageAdapter thumbnailAdapter = new LighthouseImageAdapter(this, this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS), this.photosFromFlickr); this.gv.setAdapter(thumbnailAdapter); this.gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Determine which photograph from the list was selected... final Photograph photoClicked = (Photograph) thumbnailAdapter.getItem(position); final int photoClickedResID = photoClicked.getResID(); // ...and change the information in the top-left corner // accordingly if (PhotographsActivity.this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + photoClicked.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(photoClickedResID); } owner.setText("Uploaded by: " + photoClicked.getOwner()); licenseType.setText("License: " + photoClicked.getLicenseTypeAbbreviation()); } }); } }
From source file:com.sxt.superqq.activity.LoginActivity.java
/** * ?//from w w w .ja v a2s. c o m */ private void setLoginClickListener() { findViewById(R.id.btnLogin).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!CommonUtils.isNetWorkConnected(LoginActivity.this)) { Toast.makeText(LoginActivity.this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show(); return; } currentUsername = usernameEditText.getText().toString().trim(); currentPassword = passwordEditText.getText().toString().trim(); /* * ???? */ if (TextUtils.isEmpty(currentUsername)) { Toast.makeText(LoginActivity.this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(currentPassword)) { Toast.makeText(LoginActivity.this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT) .show(); return; } //? progressShow = true; final ProgressDialog pd = new ProgressDialog(LoginActivity.this); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { progressShow = false; } }); pd.setMessage(getString(R.string.Is_landing)); pd.show(); final long start = System.currentTimeMillis(); // sdk?? EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() { @Override public void onSuccess() { if (!progressShow) { return; } runOnUiThread(new Runnable() { public void run() { pd.setMessage(getString(R.string.list_is_for)); } }); try { //? boolean isSuccess = loginAppServer(currentUsername, currentPassword); if (!isSuccess) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(LoginActivity.this, "", 2000).show(); return; } }); } final String userName = SuperQQApplication.getInstance().getUserName(); //? isSuccess = NetUtils.downloadAvatar(LoginActivity.this, userName); if (SuperQQApplication.getInstance().getContacts().size() == 0) { //,20userName?? new DownloadContactsTask(LoginActivity.this, userName, 0, 20) .execute(I.SERVER_ROOT); } if (!isSuccess) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(LoginActivity.this, userName + "?", 3000) .show(); } }); } // ** ?logout??? // ** manually load all local groups and // conversations in case we are auto login EMGroupManager.getInstance().loadAllGroups(); EMChatManager.getInstance().loadAllConversations(); //?? processContactsAndGroups(); } catch (Exception e) { e.printStackTrace(); //????? runOnUiThread(new Runnable() { public void run() { pd.dismiss(); SuperQQApplication.getInstance().logout(null); Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1) .show(); } }); return; } //?nickname ios?nick boolean updatenick = EMChatManager.getInstance() .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim()); if (!updatenick) { Log.e("LoginActivity", "update current user nick fail"); } if (!LoginActivity.this.isFinishing()) pd.dismiss(); // ? startActivity(new Intent(LoginActivity.this, MainActivity.class)); finish(); } @Override public void onProgress(int progress, String status) { } @Override public void onError(final int code, final String message) { if (!progressShow) { return; } runOnUiThread(new Runnable() { public void run() { pd.dismiss(); Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message, Toast.LENGTH_SHORT).show(); } }); } }); // Intent intent = new Intent(LoginActivity.this, com.sxt.superqq.activity.AlertDialogActivity.class); // intent.putExtra("editTextShow", true); // intent.putExtra("titleIsCancel", true); // intent.putExtra("msg", getResources().getString(R.string.please_set_the_current)); // intent.putExtra("edit_text", currentUsername); // startActivityForResult(intent, REQUEST_CODE_SETNICK); } }); }
From source file:com.yeldi.yeldibazaar.AppDetails.java
private ProgressDialog createProgressDialog(String file, int p, int max) { final ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMessage(getString(R.string.download_server) + ":\n " + file); pd.setMax(max);//from www. ja v a 2 s . c om pd.setProgress(p); pd.setCancelable(true); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { downloadHandler.cancel(); } }); pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { pd.cancel(); } }); pd.show(); return pd; }
From source file:com.fabernovel.alertevoirie.HomeActivity.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 a v a2s. c o m pd.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (dialog_shown) removeDialog(DIALOG_PROGRESS); } }); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AVService.getInstance(HomeActivity.this).cancelTask(); finish(); } }); pd.setMessage(getString(R.string.ui_message_loading)); return pd; default: return super.onCreateDialog(id); } }
From source file:com.money.manager.ex.sync.SyncManager.java
public void invokeSyncService(String action) { // Validation. String remoteFile = getRemotePath(); // We need a value in remote file name preferences. if (TextUtils.isEmpty(remoteFile)) return;/*from w w w .j a va 2 s . c o m*/ // Action ProgressDialog progressDialog = null; // Create progress dialog only if called from the UI. if ((getContext() instanceof Activity)) { //progress dialog shown only when downloading an updated db file. progressDialog = new ProgressDialog(getContext()); progressDialog.setCancelable(false); progressDialog.setMessage(getContext().getString(R.string.syncProgress)); progressDialog.setIndeterminate(true); // progressDialog.show(); } Messenger messenger = null; if (getContext() instanceof Activity) { // Messenger handles received messages from the sync service. Can run only in a looper thread. messenger = new Messenger(new SyncServiceMessageHandler(getContext(), progressDialog, remoteFile)); } String localFile = getDatabases().getCurrent().localPath; Intent syncServiceIntent = IntentFactory.getSyncServiceIntent(getContext(), action, localFile, remoteFile, messenger); // start service getContext().startService(syncServiceIntent); // Reset any other scheduled uploads as the current operation will modify the files. abortScheduledUpload(); // The messages from the service are received via messenger. }
From source file:fm.smart.r1.ItemActivity.java
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/*from w w w .j av a2 s. c o m*/ // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in if (LoginActivity.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.getId()); 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 = new AddItemResult(Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item.getId(), null)); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default goal ItemActivity.add_sentence_goal_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item.getId(), sentence_id, null)); result = ItemActivity.add_sentence_goal_result; if (ItemActivity.add_sentence_goal_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.getId(), Main.default_study_goal_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.getId().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(); } } }