use of android.app.ProgressDialog in project android-app-common-tasks by multidots.
the class Util method startBackgroundJob.
public static void startBackgroundJob(MonitoredActivity activity, @SuppressWarnings("SameParameterValue") String title, String message, Runnable job, Handler handler) {
// Make the progress dialog uncancelable, so that we can gurantee
// the thread will be done before the activity getting destroyed.
ProgressDialog dialog = ProgressDialog.show(activity, title, message, true, false);
new Thread(new BackgroundJob(activity, job, dialog, handler)).start();
}
use of android.app.ProgressDialog in project android-app-common-tasks by multidots.
the class EmailContactsScreenShotActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_contacts_screen_shot);
final TextView tvEmails = (TextView) findViewById(R.id.email_list_tv);
ArrayList<String> nameEmailDetails = Common.getNameEmailDetails(this);
String strNameEmail = "";
for (int i = 0; i < nameEmailDetails.size(); i++) {
strNameEmail += "\n\n " + nameEmailDetails.get(i);
}
tvEmails.setText(strNameEmail);
findViewById(R.id.screenshot).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog progressDialog = new ProgressDialog(EmailContactsScreenShotActivity.this);
progressDialog.setMessage("Please wait");
progressDialog.show();
Bitmap b = Common.captureView(tvEmails);
// ImageView ivEmail = (ImageView) findViewById(R.id.email_iv_screen);
// ivEmail.setImageBitmap(b);
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/UtilsExample";
File dir = new File(file_path);
if (!dir.exists())
//noinspection ResultOfMethodCallIgnored
dir.mkdirs();
File file = new File(dir, "ScreenShot" + Calendar.getInstance().getTime() + ".png");
FileOutputStream fOut;
progressDialog.dismiss();
try {
fOut = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
Common.showAlertDialog(EmailContactsScreenShotActivity.this, getString(R.string.app_name), "Screenshot saved in " + file.getPath(), false);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
use of android.app.ProgressDialog in project android-app-common-tasks by multidots.
the class Util method startBackgroundJob.
public static void startBackgroundJob(MonitoredActivity activity, @SuppressWarnings("SameParameterValue") String title, String message, Runnable job, Handler handler) {
// Make the progress dialog uncancelable, so that we can gurantee
// the thread will be done before the activity getting destroyed.
ProgressDialog dialog = ProgressDialog.show(activity, title, message, true, false);
new Thread(new BackgroundJob(activity, job, dialog, handler)).start();
}
use of android.app.ProgressDialog in project KeepScore by nolanlawson.
the class MainActivity method showLoadBackupDialog.
private void showLoadBackupDialog() {
if (!SdcardHelper.isAvailable()) {
ToastHelper.showLong(this, R.string.toast_no_sdcard);
return;
}
final List<String> backups = SdcardHelper.list(Location.Backups);
if (backups.isEmpty()) {
ToastHelper.showShort(this, R.string.toast_no_backups);
return;
}
final ProgressDialog progressDialog = showProgressDialog(R.string.text_loading_generic, backups.size());
// show progress dialog to avoid jankiness
new AsyncTask<Void, Void, List<GamesBackupSummary>>() {
@Override
protected List<GamesBackupSummary> doInBackground(Void... params) {
List<GamesBackupSummary> summaries = new ArrayList<GamesBackupSummary>();
// fetch the summaries only, so that we don't have to read the entire XML file for each one
for (String backup : backups) {
File file = SdcardHelper.getFile(backup, Location.Backups);
Uri uri = Uri.fromFile(file);
Format format = file.getName().endsWith(".gz") ? Format.GZIP : Format.XML;
GamesBackupSummary summary = GamesBackupSerializer.readGamesBackupSummary(uri, format, getContentResolver());
summaries.add(summary);
publishProgress((Void) null);
}
// show most recent ones first
Collections.sort(summaries, new Comparator<GamesBackupSummary>() {
public int compare(GamesBackupSummary lhs, GamesBackupSummary rhs) {
return Long.valueOf(rhs.getDateSaved()).compareTo(lhs.getDateSaved());
}
});
return summaries;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
progressDialog.incrementProgressBy(1);
}
@Override
protected void onPostExecute(List<GamesBackupSummary> result) {
super.onPostExecute(result);
progressDialog.dismiss();
showLoadBackupDialogFinished(result);
}
}.execute((Void) null);
}
use of android.app.ProgressDialog in project KeepScore by nolanlawson.
the class MainActivity method saveBackup.
private void saveBackup(final Format format, final Location location, final List<Integer> gameIds, final Callback<String> onSuccessWithFilename) {
if (!SdcardHelper.isAvailable()) {
ToastHelper.showLong(this, R.string.toast_no_sdcard);
return;
}
final String filename = SdcardHelper.createBackupFilename(format);
final ProgressDialog progressDialog = showProgressDialog(R.string.text_saving, gameIds.size());
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
List<Game> games = new ArrayList<Game>();
GameDBHelper dbHelper = null;
try {
dbHelper = new GameDBHelper(MainActivity.this);
for (Integer gameId : gameIds) {
Game game = dbHelper.findGameById(gameId);
games.add(game);
publishProgress((Void) null);
}
} finally {
if (dbHelper != null) {
dbHelper.close();
}
}
GamesBackup gamesBackup = new GamesBackup();
gamesBackup.setVersion(GamesBackupSerializer.CURRENT_VERSION);
gamesBackup.setDateSaved(System.currentTimeMillis());
gamesBackup.setAutomatic(false);
gamesBackup.setGameCount(games.size());
gamesBackup.setGames(games);
gamesBackup.setFilename(filename);
String xmlData = GamesBackupSerializer.serialize(gamesBackup);
return SdcardHelper.save(filename, format, location, xmlData);
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
onSuccessWithFilename.onCallback(filename);
} else {
ToastHelper.showLong(MainActivity.this, R.string.toast_save_backup_failed);
}
progressDialog.dismiss();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
progressDialog.incrementProgressBy(1);
}
}.execute((Void) null);
}
Aggregations