Java Code Examples for android.app.ProgressDialog#setOnCancelListener()

The following examples show how to use android.app.ProgressDialog#setOnCancelListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadCartridgeActivity.java    From WhereYouGo with GNU General Public License v3.0 6 votes vote down vote up
public DownloadTask(final Context context, String username, String password) {
    super(context, username, password);
    progressDialog = new ProgressDialog(context);
    progressDialog.setMessage("");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMax(1);
    progressDialog.setIndeterminate(true);
    progressDialog.setCanceledOnTouchOutside(false);

    progressDialog.setCancelable(true);
    progressDialog.setOnCancelListener(arg0 -> {
        if (downloadTask != null && downloadTask.getStatus() != Status.FINISHED) {
            downloadTask.cancel(false);
            downloadTask = null;
            Log.i("down", "cancel");
            ManagerNotify.toastShortMessage(context, getString(R.string.cancelled));
        }
    });
}
 
Example 2
Source File: DialogUtils.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a progress dialog.
 *
 * @param spinner true to use the spinner style
 * @param context the context
 * @param messageId the progress message id
 * @param onCancelListener the cancel listener
 * @param formatArgs the format arguments for the message id
 */
private static ProgressDialog createProgressDialog(boolean spinner, final Context context,
    int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
  final ProgressDialog progressDialog = new ProgressDialog(context);
  progressDialog.setCancelable(true);
  progressDialog.setCanceledOnTouchOutside(false);
  progressDialog.setIcon(android.R.drawable.ic_dialog_info);
  progressDialog.setIndeterminate(true);
  progressDialog.setMessage(context.getString(messageId, formatArgs));
  progressDialog.setOnCancelListener(onCancelListener);
  progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER
      : ProgressDialog.STYLE_HORIZONTAL);
  progressDialog.setTitle(R.string.generic_progress_title);
  progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {

      @Override
    public void onShow(DialogInterface dialog) {
      setDialogTitleDivider(context, progressDialog);
    }
  });
  return progressDialog;
}
 
Example 3
Source File: Search.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    mCancelled=false;
    mProgressDialog = new ProgressDialog(mParent);
    mProgressDialog.setTitle(R.string.spinner_message);
    mProgressDialog.setMessage(mQuery);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        public void onCancel(DialogInterface dialog)
        {
            mCancelled=true;
            cancel(false);
        }
    });
    mProgressDialog.show();
    mParent = null;
}
 
Example 4
Source File: WebServiceClient.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
public WebServiceClient(Context context, WebServiceTaskListener<T> listener) {
    mContext = context;
    mListener = listener;
    if (mContext == null || mListener == null) { 
        throw new IllegalArgumentException();
    }

    mProgressDialog = new ProgressDialog(mContext);
    mProgressDialog.setMessage(mContext.getString(R.string.wsc_please_wait));
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dlgInterface) {
            abortTaskIfRunning();
        }
    });

    mHash = getAppSignatureHash(mContext);
}
 
Example 5
Source File: TextFrag.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    mProgressDialog = new ProgressDialog(mParent);
    mProgressDialog.setTitle(R.string.spinner_message);
    // mProgressDialog.setMessage(R.string.spinner_message);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setCancelable(false);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
        }
    });
    mProgressDialog.show();
    mChangeCancel = true;
    mParent = null;
}
 
Example 6
Source File: LoadingDialog.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new instance.
 * 
 * @param context
 *            the context.
 * @param cancelable
 *            whether the user can cancel the dialog by tapping outside of
 *            it, or by pressing Back button.
 * @param msg
 *            the message to display.
 */
public LoadingDialog(Context context, boolean cancelable, CharSequence msg) {
    mDialog = new ProgressDialog(context);
    mDialog.setCancelable(cancelable);
    mDialog.setMessage(msg);
    mDialog.setIndeterminate(true);

    if (cancelable) {
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                cancel(true);
            }// onCancel()

        });
    }
}
 
Example 7
Source File: Main.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    mProgressDialog = new ProgressDialog(mParent);
    mProgressDialog.setTitle(R.string.spinner_message);
    // mProgressDialog.setMessage(R.string.spinner_message);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setCancelable(false);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
        }
    });
    mProgressDialog.show();
    mChangeCancel = true;
    mParent = null;
}
 
Example 8
Source File: DecompressionActivity.java    From Dainty with Apache License 2.0 6 votes vote down vote up
private void initData() {
    mDialog=new ProgressDialog(this);
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mDialog.setTitle("正在解析压缩包");
    mDialog.setMessage("请稍等...");
    mDialog.show();
    adapter = new CompressionListAdapter(this, data);
    switch (FileUtil.getExtensionName(handleFilePath)) {
        case "zip":
            type = "zip";
            presenter.resolveZip(handleFilePath);
            break;
        case "rar":
            type = "rar";
            presenter.resolveRar(handleFilePath);
            break;
    }
}
 
Example 9
Source File: BluetoothSite.java    From physical-web with Apache License 2.0 6 votes vote down vote up
/**
 * Connects to the Gatt service of the device to download a web page and displays a progress bar
 * for the title.
 * @param deviceAddress The mac address of the bar
 * @param title The title of the web page being downloaded
 */
public void connect(String deviceAddress, String title) {
  running = true;
  String progressTitle = activity.getString(R.string.page_loading_title) + " " + title;
  progress = new ProgressDialog(activity);
  progress.setCancelable(true);
  progress.setOnCancelListener(new OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialogInterface) {
      Log.i(TAG, "Dialog box canceled");
      close();
    }
  });
  progress.setTitle(progressTitle);
  progress.setMessage(activity.getString(R.string.page_loading_message));
  progress.show();
  activity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      mBluetoothGatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress)
          .connectGatt(activity, false, BluetoothSite.this);
    }
  });
}
 
Example 10
Source File: Search.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    mCancelled=false;
    mProgressDialog = new ProgressDialog(mParent);
    mProgressDialog.setTitle(R.string.spinner_message);
    mProgressDialog.setMessage(mQuery);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setCancelable(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        public void onCancel(DialogInterface dialog)
        {
            mCancelled=true;
            cancel(false);
        }
    });
    mProgressDialog.show();
    mParent = null;
}
 
Example 11
Source File: WeixinUtil.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
private static ProgressDialog show(Context context, CharSequence title,
                                  CharSequence message, boolean indeterminate,
                                  boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(context,ProgressDialog.THEME_HOLO_LIGHT);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    dialog.show();
    return dialog;
}
 
Example 12
Source File: NovelReaderActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
private void getNC() {
	List<NameValuePair> targVar = new ArrayList<NameValuePair>();
	targVar.add(Wenku8Interface.getNovelContent(currentAid, currentCid,
			GlobalConfig.getFetchLanguage()));

	final asyncNovelContentTask ast = new asyncNovelContentTask();
	ast.execute(targVar);

	pDialog = new ProgressDialog(parentActivity);
	pDialog.setTitle(getResources().getString(R.string.load_status));
	pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
	pDialog.setCancelable(true);
	pDialog.setOnCancelListener(new OnCancelListener() {
		@Override
		public void onCancel(DialogInterface dialog) {
			// TODO Auto-generated method stub
			ast.cancel(true);
			pDialog.dismiss();
			pDialog = null;
		}

	});
	pDialog.setMessage(getResources().getString(R.string.load_loading));
	pDialog.setProgress(0);
	pDialog.setMax(1);
	pDialog.show();

	return;
}
 
Example 13
Source File: BluetoothLEStack.java    From awesomesauce-rfduino with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Connect to a chosen Bluetooth Device using whatever BLE Stack is available. **/
public static BluetoothLEStack connectToBluetoothLEStack(BluetoothDevice device, Activity hostActivity, String uuidStringRepresentation, OnCancelListener onCancelConnectionAttempt){
	bluetoothConnectionWaitWindow = new ProgressDialog(hostActivity);
	bluetoothConnectionWaitWindow.setTitle("Connecting to Bluetooth Radio " + device.getAddress());
	bluetoothConnectionWaitWindow.setMessage("Please wait...");
	bluetoothConnectionWaitWindow.setCancelable(false);
	
	if (onCancelConnectionAttempt != null){
		bluetoothConnectionWaitWindow.setCancelable(true);
		bluetoothConnectionWaitWindow.setOnCancelListener(onCancelConnectionAttempt);
	}
	bluetoothConnectionWaitWindow.setIndeterminate(true);
	bluetoothConnectionWaitWindow.show();
	
	
	if (singleton != null){
		singleton.disconnect();
		singleton.connect(device, hostActivity);
		
	} else {
	
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
		singleton =  new AndroidBleStack(device, null, hostActivity);
		
	} else {
		//See if Samsung (Broadcom-based) Bluetooth Low Energy stack will work- works on Android 4.1 and 4.2
		singleton = new SamsungBleStack(device, hostActivity);
	}
	}
	return singleton;
}
 
Example 14
Source File: DialogAsyncTask.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPreExecute() {
    ProgressDialog dialog = new ProgressDialog(mContext);
    dialog.setMessage(mContext.getString(mProgressMessageId));
    dialog.setIndeterminate(true);
    dialog.setCancelable(mCancelable);
    if (mCancelable) {
        dialog.setOnCancelListener(this);
    }
    dialog.show();
    mDialog = dialog;
}
 
Example 15
Source File: DialogUnit.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public PerformSendCallback(int localArchiveMax) {
	Context context = uiManager.getContext();
	dialog = new ProgressDialog(context);
	if (localArchiveMax >= 0) {
		dialog.setMessage(context.getString(R.string.message_processing_data));
		dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		dialog.setMax(localArchiveMax);
	} else {
		dialog.setMessage(context.getString(R.string.message_sending));
	}
	dialog.setCanceledOnTouchOutside(false);
	dialog.setOnCancelListener(this);
	dialog.show();
}
 
Example 16
Source File: CustomThemeListActivity.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private ProgressDialog showProgressDialog(final CancellableTask task) {
    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.custom_themes_loading));
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            task.cancel();
        }
    });
    progressDialog.show();
    return progressDialog;
}
 
Example 17
Source File: WebDialog.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    spinner = new ProgressDialog(getContext());
    spinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
    spinner.setMessage(getContext().getString(R.string.com_facebook_loading));
    spinner.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            cancel();
        }
    });

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    contentFrameLayout = new FrameLayout(getContext());

    // First calculate how big the frame layout should be
    resize();
    getWindow().setGravity(Gravity.CENTER);

    // resize the dialog if the soft keyboard comes up
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    /* Create the 'x' image, but don't add to the contentFrameLayout layout yet
     * at this point, we only need to know its drawable width and height
     * to place the webview
     */
    createCrossImage();

    /* Now we know 'x' drawable width and height,
     * layout the webview and add it the contentFrameLayout layout
     */
    int crossWidth = crossImageView.getDrawable().getIntrinsicWidth();

    setUpWebView(crossWidth / 2 + 1);

    /* Finally add the 'x' image to the contentFrameLayout layout and
    * add contentFrameLayout to the Dialog view
    */
    contentFrameLayout.addView(crossImageView, new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    setContentView(contentFrameLayout);
}
 
Example 18
Source File: CommOtherDataObserver.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
public CommOtherDataObserver(LifecycleOwner lifecycleOwner, ProgressDialog progressDialog) {
    this.lifecycleOwner = lifecycleOwner;
    this.progressDialog = progressDialog;
    progressDialog.setOnCancelListener(dialog -> mDisposable.dispose());
}
 
Example 19
Source File: QiscusPhotoViewerActivity.java    From qiscus-sdk-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_qiscus_photo_viewer);

    presenter = new QiscusPhotoViewerPresenter(this);

    toolbar = findViewById(R.id.toolbar);
    tvTitle = findViewById(R.id.tv_title);
    viewPager = findViewById(R.id.view_pager);
    progressBar = findViewById(R.id.progress_bar);
    senderName = findViewById(R.id.sender_name);
    date = findViewById(R.id.date);
    ImageButton shareButton = findViewById(R.id.action_share);
    infoPanel = findViewById(R.id.info_panel);
    fadein = AnimationUtils.loadAnimation(this, R.anim.qiscus_fadein);
    fadeout = AnimationUtils.loadAnimation(this, R.anim.qiscus_fadeout);

    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.qiscus_downloading));
    progressDialog.setMax(100);
    progressDialog.setIndeterminate(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setOnCancelListener(dialog -> {
        presenter.cancelDownloading();
        showError(getString(R.string.qiscus_redownload_canceled));
        if (ongoingDownload != null) {
            ongoingDownload.setDownloadingListener(null);
            ongoingDownload.setProgressListener(null);
        }
    });

    findViewById(R.id.back).setOnClickListener(v -> onBackPressed());
    setSupportActionBar(toolbar);
    viewPager.addOnPageChangeListener(this);

    resolveData(savedInstanceState);

    presenter.loadQiscusPhotos(qiscusComment.getRoomId());

    if (!Qiscus.getChatConfig().isEnableShareMedia()) {
        shareButton.setVisibility(View.GONE);
    }

    shareButton.setOnClickListener(v -> {
        Pair<QiscusComment, File> qiscusPhoto = qiscusPhotos.get(position);
        shareImage(qiscusPhoto.second);
    });
}
 
Example 20
Source File: CommJsonObserver.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
public CommJsonObserver(LifecycleOwner lifecycleOwner, ProgressDialog progressDialog) {
    this.lifecycleOwner = lifecycleOwner;
    this.progressDialog = progressDialog;
    progressDialog.setOnCancelListener(dialog -> mDisposable.dispose());
}