Search in sources :

Example 61 with ProgressDialog

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();
}
Also used : ProgressDialog(android.app.ProgressDialog)

Example 62 with ProgressDialog

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();
            }
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) TextView(android.widget.TextView) IOException(java.io.IOException) ProgressDialog(android.app.ProgressDialog) TextView(android.widget.TextView) View(android.view.View) File(java.io.File)

Example 63 with ProgressDialog

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();
}
Also used : ProgressDialog(android.app.ProgressDialog)

Example 64 with ProgressDialog

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);
}
Also used : GamesBackupSummary(com.nolanlawson.keepscore.serialization.GamesBackupSummary) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) Comparator(java.util.Comparator) Format(com.nolanlawson.keepscore.helper.SdcardHelper.Format) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Example 65 with ProgressDialog

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);
}
Also used : Game(com.nolanlawson.keepscore.db.Game) GameDBHelper(com.nolanlawson.keepscore.db.GameDBHelper) List(java.util.List) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog) GamesBackup(com.nolanlawson.keepscore.serialization.GamesBackup)

Aggregations

ProgressDialog (android.app.ProgressDialog)266 DialogInterface (android.content.DialogInterface)47 Intent (android.content.Intent)23 View (android.view.View)21 File (java.io.File)19 TextView (android.widget.TextView)13 SuppressLint (android.annotation.SuppressLint)12 Handler (android.os.Handler)12 FrameLayout (android.widget.FrameLayout)12 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 JSONObject (org.json.JSONObject)10 Uri (android.net.Uri)9 LinearLayout (android.widget.LinearLayout)9 OnCancelListener (android.content.DialogInterface.OnCancelListener)8 Display (android.view.Display)8 Activity (android.app.Activity)7 Dialog (android.app.Dialog)7 ImageView (android.widget.ImageView)7 List (java.util.List)7