Example usage for android.app ProgressDialog isShowing

List of usage examples for android.app ProgressDialog isShowing

Introduction

In this page you can find the example usage for android.app ProgressDialog isShowing.

Prototype

public boolean isShowing() 

Source Link

Usage

From source file:com.lostad.app.base.util.DownloadUtil.java

public static void downFileAsyn(final Activity ctx, final String upgradeUrl, final String savedPath,
        final MyCallback<Boolean> callback) {
    final ProgressDialog xh_pDialog = new ProgressDialog(ctx);
    // ?//from w ww. ja  v a  2 s.  c  om
    xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // ProgressDialog 
    xh_pDialog.setTitle("???");
    // ProgressDialog???
    xh_pDialog.setMessage("...");
    // ProgressDialog
    // xh_pDialog.setIcon(R.drawable.img2);
    // ProgressDialog ??? false ??
    xh_pDialog.setIndeterminate(false);
    // ProgressDialog ?
    // xh_pDialog.setProgress(100);
    // ProgressDialog ???
    xh_pDialog.setCancelable(true);
    // ProgressDialog
    xh_pDialog.show();

    new Thread() {
        public void run() {

            boolean downloadSuccess = true;
            FileOutputStream fileOutputStream = null;
            try {
                Looper.prepare();
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(upgradeUrl);

                File f = new File(savedPath);
                if (!f.exists()) {
                    f.createNewFile();
                }

                HttpResponse response = client.execute(get);
                HttpEntity entity = response.getEntity();
                // ?
                Long length = entity.getContentLength();
                xh_pDialog.setMax(length.intValue());
                //
                InputStream is = entity.getContent();
                fileOutputStream = null;

                if (is != null && length > 0) {

                    fileOutputStream = new FileOutputStream(f);

                    byte[] buf = new byte[1024];
                    int ch = -1;
                    int count = 0;
                    while ((ch = is.read(buf)) != -1) {

                        if (xh_pDialog.isShowing()) {
                            fileOutputStream.write(buf, 0, ch);
                            // ?
                            count += ch;
                            xh_pDialog.setProgress(count);
                        } else {
                            downloadSuccess = false;
                            break;// ?
                        }
                    }

                } else {
                    callback.onCallback(false);
                }

                if (downloadSuccess && fileOutputStream != null) {
                    xh_pDialog.dismiss();
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    callback.onCallback(true);// ?
                }
                Looper.loop();
            } catch (FileNotFoundException e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
                xh_pDialog.dismiss();
            } catch (Exception e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
            } finally {
                try {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }.start();

}

From source file:org.sickstache.fragments.ShowsFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    if (actionMode == null) {
        actionMode = getSherlockActivity().startActionMode(new ActionMode.Callback() {

            @Override//from w ww.j  av a 2  s.c  om
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                showAdapter.notifyDataSetChanged();
                selected.clear();
                actionMode = null;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflate = getSherlockActivity().getSupportMenuInflater();
                inflate.inflate(R.menu.shows_cab_menu, menu);
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch (item.getItemId()) {
                case R.id.pauseMenuItem:
                    final PauseDialog pDialog = new PauseDialog();
                    pDialog.setTitle("Set Pause");
                    pDialog.setOnOkClick(new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            final ProgressDialog dialog = ProgressDialog.show(
                                    ShowsFragment.this.getSherlockActivity(), "",
                                    "Pausing Shows. Please wait...", true);
                            dialog.setCancelable(true);
                            dialog.show();
                            String[] tvdbids = new String[selected.size()];
                            for (int i = 0; i < selected.size(); i++) {
                                tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                            }
                            Preferences pref = Preferences
                                    .getSingleton(ShowsFragment.this.getSherlockActivity());
                            PauseTask pause = new PauseTask(pref, tvdbids, pDialog.getPause()) {
                                @Override
                                protected void onPostExecute(Boolean result) {
                                    if (dialog != null && dialog.isShowing())
                                        dialog.dismiss();
                                    if (error != null && getFragmentManager() != null) {
                                        ErrorDialog dialog = new ErrorDialog();
                                        dialog.setMessage("Error pausing show.\nERROR: " + error.getMessage());
                                        dialog.show(getFragmentManager(), "pauseError");
                                    }
                                }
                            };
                            pause.execute();
                        }
                    });
                    pDialog.show(getFragmentManager(), "update");
                    return true;
                case R.id.refreshMenuItem: {
                    final ProgressDialog dialog = ProgressDialog.show(ShowsFragment.this.getSherlockActivity(),
                            "", "Refreshing Shows. Please wait...", true);
                    dialog.setCancelable(true);
                    dialog.show();
                    String[] tvdbids = new String[selected.size()];
                    for (int i = 0; i < selected.size(); i++) {
                        tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                    }
                    Preferences pref = Preferences.getSingleton(ShowsFragment.this.getSherlockActivity());
                    RefreshTask refresh = new RefreshTask(pref, tvdbids) {
                        @Override
                        protected void onPostExecute(Boolean result) {
                            if (dialog != null && dialog.isShowing())
                                dialog.dismiss();
                            if (error != null && getFragmentManager() != null) {
                                ErrorDialog dialog = new ErrorDialog();
                                dialog.setMessage("Error refreshing show.\nERROR: " + error.getMessage());
                                dialog.show(getFragmentManager(), "refreshError");
                            }
                        }
                    };
                    refresh.execute();
                }
                    return true;
                case R.id.updateMenuItem: {
                    final ProgressDialog dialog = ProgressDialog.show(ShowsFragment.this.getSherlockActivity(),
                            "", "Updating Shows. Please wait...", true);
                    dialog.setCancelable(true);
                    dialog.show();
                    String[] tvdbids = new String[selected.size()];
                    for (int i = 0; i < selected.size(); i++) {
                        tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                    }
                    Preferences pref = Preferences.getSingleton(ShowsFragment.this.getSherlockActivity());
                    UpdateTask update = new UpdateTask(pref, tvdbids) {
                        @Override
                        protected void onPostExecute(Boolean result) {
                            if (dialog != null && dialog.isShowing())
                                dialog.dismiss();
                            if (error != null && getFragmentManager() != null) {
                                ErrorDialog dialog = new ErrorDialog();
                                dialog.setMessage("Error updating show.\nERROR: " + error.getMessage());
                                dialog.show(getFragmentManager(), "updateError");
                            }
                        }
                    };
                    update.execute();
                }
                    return true;
                //               case R.id.editMenuItem:
                //                  // get all selected items and create the edit show activity passing all of them
                //                  actionMode.finish();
                //                  return true;
                }
                return false;
            }
        });
    }
    ImageView overlay = (ImageView) arg1.findViewById(R.id.showSelectedOverlay);
    int i = selected.indexOf(arg2);
    if (i >= 0) {
        selected.remove(i);
        overlay.setVisibility(View.INVISIBLE);
    } else {
        selected.add(arg2);
        overlay.setVisibility(View.VISIBLE);
    }
    actionMode.setTitle(selected.size() + " Items Selected");
    if (selected.size() == 0) {
        actionMode.finish();
    }
    return true;
}

From source file:com.ubikod.urbantag.ContentViewerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();

    /* If we are coming from Notification delete notification */
    if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_CONTENT_NOTIF) {
        NotificationHelper notificationHelper = new NotificationHelper(this);
        notificationHelper.closeContentNotif();
    } else if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_PLACE_NOTIF) {
        NotificationHelper notificationHelper = new NotificationHelper(this);
        notificationHelper.closePlaceNotif();
    }//  w  w  w.ja  v a2s  . c  om

    /* Fetch content info */
    ContentManager contentManager = new ContentManager(new DatabaseHelper(this, null));
    Log.i(UrbanTag.TAG, "View content : " + extras.getInt(CONTENT_ID));
    this.content = contentManager.get(extras.getInt(CONTENT_ID));
    if (this.content == null) {
        Toast.makeText(this, R.string.error_occured, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    setTitle(content.getName());
    com.actionbarsherlock.app.ActionBar actionBar = this.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.content_viewer);

    /* Find webview and create url for content */
    final WebView webView = (WebView) findViewById(R.id.webview);
    final String URL = UrbanTag.API_URL + ACTION_GET_CONTENT.replaceAll("%", "" + this.content.getId());

    /* Display progress animation */
    final ProgressDialog progress = ProgressDialog.show(this, "",
            this.getResources().getString(R.string.loading_content), false, true,
            new DialogInterface.OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    timeOutHandler.interrupt();
                    webView.stopLoading();
                    ContentViewerActivity.this.finish();
                }

            });

    /* Go fetch content */
    contentFetcher = new Thread(new Runnable() {

        DefaultHttpClient httpClient;

        @Override
        public void run() {
            Looper.prepare();
            Log.i(UrbanTag.TAG, "Fetching content...");
            httpClient = new DefaultHttpClient();
            try {
                String responseBody = httpClient.execute(new HttpGet(URL), new BasicResponseHandler());
                webView.loadDataWithBaseURL("fake://url/for/encoding/hack...", responseBody, mimeType, encoding,
                        "");
                timeOutHandler.interrupt();
                if (progress.isShowing())
                    progress.dismiss();
            } catch (ClientProtocolException cpe) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });
                timeOutHandler.interrupt();
                progress.cancel();
            } catch (IOException ioe) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });
                timeOutHandler.interrupt();
                progress.cancel();
            }

            Looper.loop();
        }

    });
    contentFetcher.start();

    /* TimeOut Handler */
    timeOutHandler = new Thread(new Runnable() {
        private int INCREMENT = 1000;

        @Override
        public void run() {
            Looper.prepare();
            try {
                for (int time = 0; time < TIMEOUT; time += INCREMENT) {
                    Thread.sleep(INCREMENT);
                }

                Log.w(UrbanTag.TAG, "TimeOut !");
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });

                contentFetcher.interrupt();
                progress.cancel();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Looper.loop();

        }

    });
    timeOutHandler.start();

}

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  w w.j a  va  2  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:id.ridon.keude.AppDetailsData.java

private void updateProgressDialog(int progress, int total) {
    if (downloadHandler != null) {
        ProgressDialog pd = getProgressDialog(downloadHandler.getRemoteAddress());
        if (total > 0) {
            pd.setIndeterminate(false);//from w ww.  j  a va 2 s  .  c o  m
            pd.setProgress(progress);
            pd.setMax(total);
        } else {
            pd.setIndeterminate(true);
            pd.setProgress(progress);
            pd.setMax(0);
        }
        if (!pd.isShowing()) {
            Log.d(TAG, "Showing progress dialog for download.");
            pd.show();
        }
    }
}

From source file:com.wpi.assistments.HomeTabbedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_webview);

    final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true);

    isTeacher = false;//from w w  w  .  ja  va  2 s  .c  o m
    toggle = true;
    logoutFlag = false;

    homeWebView = (WebView) findViewById(R.id.homeWebView);
    homeWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            Log.i("test", view.getUrl());
            if (view.getUrl().equals("https://www.assistments.org/account/login") && !logoutFlag) {

                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                intent.putExtra("showPopup", "true");
                startActivity(intent);
                finish();
            } else if (view.getUrl().equals("https://www.assistments.org/teacher")) {
                isTeacher = true;
            } else if (view.getUrl().equals("https://www.assistments.org/account/login") && logoutFlag) {
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }

            if (!homeWebView.canGoBack()) {
                btnBack.setEnabled(false);
            } else {
                btnBack.setEnabled(true);
            }

            if (!homeWebView.canGoForward()) {
                btnForward.setEnabled(false);
            } else {
                btnForward.setEnabled(true);
            }

            if (pd.isShowing() && pd != null) {
                pd.dismiss();
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            pd.show();
            view.loadUrl(url);
            return true;
        }
    });
    homeWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
            new AlertDialog.Builder(webviewContext).setTitle("ASSISTments").setMessage(message)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            logoutFlag = true;
                            result.confirm();
                        }
                    }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            result.cancel();
                        }
                    }).create().show();

            return true;
        }
    });

    if (savedInstanceState != null) {
        homeWebView.restoreState(savedInstanceState);
    } else {
        /** Scaling, replaced by overview mode and wide view port
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        if (size.x <= 780) {
           int scaleRate = (int) ((size.x) / 7.8);
           Log.i("test", Integer.toString(size.x));
           homeWebView.setInitialScale(scaleRate);
        }
        */

        Intent intent = getIntent();

        if (intent.getStringExtra("username").equals("") && intent.getStringExtra("password").equals("")) {
            homeWebView.loadUrl("https://www.assistments.org/signup");

        } else {
            String username = intent.getStringExtra("username");
            String password = intent.getStringExtra("password");

            String postData = "login=" + username + "&password=" + password + "&commit=Log in";
            homeWebView.postUrl("https://www.assistments.org/account/login",
                    EncodingUtils.getBytes(postData, "BASE64"));
        }

    }

    WebSettings settings = homeWebView.getSettings();
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setSupportMultipleWindows(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setAppCacheEnabled(false);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setUseWideViewPort(false);
    settings.setLoadWithOverviewMode(true);
    homeWebView.clearCache(true);
    homeWebView.setPadding(0, 0, 0, 0);
    homeWebView.setInitialScale(getScale());

    btnBack = (Button) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            homeWebView.goBack();
        }
    });

    btnRefresh = (Button) findViewById(R.id.btnRefresh);
    btnRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //homeWebView.zoomOut();
            homeWebView.scrollTo(1000, 0);
            Log.i("test", "111");
            //homeWebView.reload();
        }
    });

    btnForward = (Button) findViewById(R.id.btnForward);
    btnForward.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            homeWebView.goForward();
        }
    });

    btnOffline = (Button) findViewById(R.id.btnOffline);
    btnOffline.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (toggle) {
                homeWebView.loadUrl(
                        "https://www.assistments.org/assistments/student/index.html#offlineUserAssignmentList/");
                btnOffline.setText("Home");
                toggle = false;
            } else {
                if (isTeacher) {
                    homeWebView.loadUrl("https://www.assistments.org/teacher");
                } else {
                    homeWebView.loadUrl("https://www.assistments.org/tutor");
                }
                btnOffline.setText("Offline");
                toggle = true;
            }

        }
    });
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

protected void getPhoto(Uri uri) {
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Uri, Void, String> asyncTask = new AsyncTask<Uri, Void, String>() {
        @Override/*  w  w  w.ja v  a2 s  . co m*/
        protected String doInBackground(Uri... imgUri) {
            String[] projection = new String[] { MediaStore.Images.Media.DATA };
            String path = null;
            Cursor c = getContentResolver().query(imgUri[0], projection, null, null, null);
            if ((c != null) && c.moveToFirst()) {
                path = c.getString(c.getColumnIndex(projection[0]));
            } else {
                // some file manages send the path through the uri
                path = imgUri[0].getPath();
            }
            c.close();
            return path;
        }

        @Override
        protected void onPostExecute(String path) {
            if (loadingDialog.isShowing())
                loadingDialog.dismiss();
            if (path != null)
                setPhoto(path);
            else
                (Toast.makeText(SonetCreatePost.this, "error retrieving the photo path", Toast.LENGTH_LONG))
                        .show();
        }
    };
    loadingDialog.setMessage(getString(R.string.loading));
    loadingDialog.setCancelable(true);
    loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            if (!asyncTask.isCancelled())
                asyncTask.cancel(true);
        }
    });
    loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    loadingDialog.show();
    asyncTask.execute(uri);
}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

protected void getPhoto(Uri uri) {
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Uri, Void, String> asyncTask = new AsyncTask<Uri, Void, String>() {
        @Override/*from  w  w  w  . j av a2 s  . c  o m*/
        protected String doInBackground(Uri... imgUri) {
            String[] projection = new String[] { MediaStore.Images.Media.DATA };
            String path = null;
            Cursor c = getContentResolver().query(imgUri[0], projection, null, null, null);
            if ((c != null) && c.moveToFirst()) {
                path = c.getString(c.getColumnIndex(projection[0]));
            } else {
                // some file manages send the path through the uri
                path = imgUri[0].getPath();
            }
            c.close();
            return path;
        }

        @Override
        protected void onPostExecute(String path) {
            if (loadingDialog.isShowing())
                loadingDialog.dismiss();
            if (path != null)
                setPhoto(path);
            else
                (Toast.makeText(MyfeedleCreatePost.this, "error retrieving the photo path", Toast.LENGTH_LONG))
                        .show();
        }
    };
    loadingDialog.setMessage(getString(R.string.loading));
    loadingDialog.setCancelable(true);
    loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            if (!asyncTask.isCancelled())
                asyncTask.cancel(true);
        }
    });
    loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    loadingDialog.show();
    asyncTask.execute(uri);
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveCfgPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//from  w  w  w.  ja  v  a  2  s . com
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    });
    prog.setTitle("Saving CFG");
    prog.setMessage("Saving...");
    prog.setIndeterminate(true);
    prog.setCancelable(false);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {
                try {

                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }

            TimidityActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    String trueName = finalval;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null
                            && needToRename != null) {
                        if (Globals.renameDocumentFile(TimidityActivity.this, finalval, needToRename)) {
                            trueName = needToRename;
                        } else {
                            trueName = "Error";
                        }
                    }
                    Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                    prog.dismiss();
                    fileFrag.getDir(fileFrag.currPath);
                }
            });

        }
    }).start();
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveWavPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override/*w w  w .j a va2 s  .co  m*/
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    });
    prog.setTitle("Converting to WAV");
    prog.setMessage("Converting...");
    prog.setIndeterminate(false);
    prog.setCancelable(false);
    prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {
                prog.setMax(JNIHandler.maxTime);
                prog.setProgress(JNIHandler.currTime);
                try {

                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }
            if (!localfinished) {
                JNIHandler.stop();
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            fileFrag.getDir(fileFrag.currPath);
                        }
                    }
                });

            } else {
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        String trueName = finalval;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null
                                && needToRename != null) {
                            if (Globals.renameDocumentFile(TimidityActivity.this, finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        fileFrag.getDir(fileFrag.currPath);
                    }
                });
            }
        }
    }).start();
}