Search in sources :

Example 51 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project physical-web by google.

the class WifiDirectConnect method connect.

public void connect(UrlDevice urlDevice, String title) {
    String progressTitle = mContext.getString(R.string.page_loading_title) + " " + title;
    mProgress = new ProgressDialog(mContext);
    mProgress.setCancelable(true);
    mProgress.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            Log.i(TAG, "Dialog box canceled");
            mDevice = null;
            mManager.cancelConnect(mChannel, new ActionListener() {

                @Override
                public void onSuccess() {
                    Log.d(TAG, "cancel connect call success");
                }

                @Override
                public void onFailure(int reason) {
                    Log.d(TAG, "cancel connect call fail " + reason);
                }
            });
        }
    });
    mProgress.setTitle(progressTitle);
    mProgress.setMessage(mContext.getString(R.string.page_loading_message));
    mProgress.show();
    mDevice = urlDevice;
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = Utils.getWifiAddress(mDevice);
    config.groupOwnerIntent = 0;
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mContext.registerReceiver(mReceiver, intentFilter);
    mManager.requestGroupInfo(mChannel, new WifiP2pManager.GroupInfoListener() {

        public void onGroupInfoAvailable(final WifiP2pGroup group) {
            if (group != null) {
                Log.d(TAG, "group not null");
                if (group.getOwner().deviceAddress.equals(Utils.getWifiAddress(mDevice))) {
                    Log.i(TAG, "Already connected");
                    mManager.requestConnectionInfo(mChannel, new WifiP2pManager.ConnectionInfoListener() {

                        public void onConnectionInfoAvailable(final WifiP2pInfo info) {
                            if (mDevice != null && info.groupOwnerAddress != null) {
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse("http:/" + info.groupOwnerAddress + ":" + Integer.toString(Utils.getWifiPort(mDevice))));
                                mContext.startActivity(intent);
                            }
                        }
                    });
                } else {
                    mManager.removeGroup(mChannel, new ActionListener() {

                        @Override
                        public void onSuccess() {
                            Log.d(TAG, "remove call success");
                            connectHelper(true, config);
                        }

                        @Override
                        public void onFailure(int reason) {
                            Log.d(TAG, "remove call fail " + reason);
                        }
                    });
                }
            } else {
                Log.d(TAG, "group null");
                connectHelper(true, config);
            }
        }
    });
}
Also used : IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) WifiP2pConfig(android.net.wifi.p2p.WifiP2pConfig) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) WifiP2pInfo(android.net.wifi.p2p.WifiP2pInfo) ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener) WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup) WifiP2pManager(android.net.wifi.p2p.WifiP2pManager) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 52 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project AndEngine by nicolasgramlich.

the class ActivityUtils method doAsync.

public static <T> void doAsync(final Context pContext, final CharSequence pTitle, final CharSequence pMessage, final Callable<T> pCallable, final Callback<T> pCallback, final Callback<Exception> pExceptionCallback, final boolean pCancelable) {
    new AsyncTask<Void, Void, T>() {

        private ProgressDialog mPD;

        private Exception mException = null;

        @Override
        public void onPreExecute() {
            this.mPD = ProgressDialog.show(pContext, pTitle, pMessage, true, pCancelable);
            if (pCancelable) {
                this.mPD.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(final DialogInterface pDialogInterface) {
                        pExceptionCallback.onCallback(new CancelledException());
                        pDialogInterface.dismiss();
                    }
                });
            }
            super.onPreExecute();
        }

        @Override
        public T doInBackground(final Void... params) {
            try {
                return pCallable.call();
            } catch (final Exception e) {
                this.mException = e;
            }
            return null;
        }

        @Override
        public void onPostExecute(final T result) {
            try {
                this.mPD.dismiss();
            } catch (final Exception e) {
                Debug.e("Error", e);
            }
            if (this.isCancelled()) {
                this.mException = new CancelledException();
            }
            if (this.mException == null) {
                pCallback.onCallback(result);
            } else {
                if (pExceptionCallback == null) {
                    Debug.e("Error", this.mException);
                } else {
                    pExceptionCallback.onCallback(this.mException);
                }
            }
            super.onPostExecute(result);
        }
    }.execute((Void[]) null);
}
Also used : DialogInterface(android.content.DialogInterface) CancelledException(org.anddev.andengine.ui.activity.BaseActivity.CancelledException) ProgressDialog(android.app.ProgressDialog) CancelledException(org.anddev.andengine.ui.activity.BaseActivity.CancelledException) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 53 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project network-monitor by caarmen.

the class ChoiceDialogFragment method onCreateDialog.

/**
 * @return a Dialog with a list of items, one of them possibly pre-selected.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    Context context = getActivity();
    Bundle arguments = getArguments();
    if (context == null || arguments == null)
        return super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE));
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    int selectedItem = arguments.getInt(DialogFragmentFactory.EXTRA_SELECTED_ITEM);
    final CharSequence[] choices = arguments.getCharSequenceArray(DialogFragmentFactory.EXTRA_CHOICES);
    OnClickListener listener = null;
    final AtomicBoolean hasClicked = new AtomicBoolean(false);
    if (getActivity() instanceof DialogItemListener) {
        listener = (dialog, which) -> {
            FragmentActivity activity = getActivity();
            if (activity == null) {
                Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
            } else if (hasClicked.get()) {
                Log.w(TAG, "User already clicked once on this dialog! Monkey?");
            } else {
                hasClicked.set(true);
                ((DialogItemListener) activity).onItemSelected(actionId, which);
            }
        };
    }
    // If one item is to be pre-selected, use the single choice items layout.
    if (selectedItem >= 0)
        builder.setSingleChoiceItems(choices, selectedItem, listener);
    else
        // If no particular item is to be pre-selected, use the default list item layout.
        builder.setItems(choices, listener);
    if (getActivity() instanceof OnCancelListener)
        builder.setOnCancelListener((OnCancelListener) getActivity());
    final Dialog dialog = builder.create();
    if (getActivity() instanceof OnDismissListener)
        dialog.setOnDismissListener((OnDismissListener) getActivity());
    return dialog;
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) OnDismissListener(android.content.DialogInterface.OnDismissListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FragmentActivity(android.support.v4.app.FragmentActivity) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) OnCancelListener(android.content.DialogInterface.OnCancelListener) NonNull(android.support.annotation.NonNull)

Example 54 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project android_packages_apps_Gallery2 by LineageOS.

the class BookmarkerInfo method showResumeDialog.

private void showResumeDialog(Context context, final BookmarkerInfo bookmark) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.resume_playing_title);
    builder.setMessage(String.format(context.getString(R.string.resume_playing_message), GalleryUtils.formatDuration(context, bookmark.mBookmark / 1000)));
    builder.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            onCompletion();
        }
    });
    builder.setPositiveButton(R.string.resume_playing_resume, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // here try to seek for bookmark
            mVideoCanSeek = true;
            doStartVideo(true, bookmark.mBookmark, bookmark.mDuration);
        }
    });
    builder.setNegativeButton(R.string.resume_playing_restart, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            doStartVideo(true, 0, bookmark.mDuration);
        }
    });
    AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface arg0) {
            mIsShowResumingDialog = true;
        }
    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface arg0) {
            mIsShowResumingDialog = false;
        }
    });
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) OnClickListener(android.content.DialogInterface.OnClickListener) OnShowListener(android.content.DialogInterface.OnShowListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 55 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project Anki-Android by Ramblurr.

the class CardEditor method reloadCollection.

private void reloadCollection(Bundle savedInstanceState) {
    mSavedInstanceState = savedInstanceState;
    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_OPEN_COLLECTION, new DeckTask.TaskListener() {

        @Override
        public void onPostExecute(DeckTask.TaskData result) {
            if (mOpenCollectionDialog.isShowing()) {
                try {
                    mOpenCollectionDialog.dismiss();
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                }
            }
            mCol = result.getCollection();
            if (mCol == null) {
                finish();
            } else {
                onCreate(mSavedInstanceState);
            }
        }

        @Override
        public void onPreExecute() {
            mOpenCollectionDialog = StyledOpenCollectionDialog.show(CardEditor.this, getResources().getString(R.string.open_collection), new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface arg0) {
                    finish();
                }
            });
        }

        @Override
        public void onProgressUpdate(DeckTask.TaskData... values) {
        }
    }, new DeckTask.TaskData(AnkiDroidApp.getCurrentAnkiDroidDirectory() + AnkiDroidApp.COLLECTION_PATH));
}
Also used : DialogInterface(android.content.DialogInterface) DeckTask(com.ichi2.async.DeckTask) JSONException(org.json.JSONException) NotFoundException(android.content.res.Resources.NotFoundException) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OnCancelListener (android.content.DialogInterface.OnCancelListener)60 DialogInterface (android.content.DialogInterface)56 AlertDialog (android.app.AlertDialog)24 OnClickListener (android.content.DialogInterface.OnClickListener)18 View (android.view.View)14 Context (android.content.Context)12 ProgressDialog (android.app.ProgressDialog)11 TextView (android.widget.TextView)11 Intent (android.content.Intent)10 OnDismissListener (android.content.DialogInterface.OnDismissListener)7 Dialog (android.app.Dialog)6 SharedPreferences (android.content.SharedPreferences)6 TypedArray (android.content.res.TypedArray)6 ArrayList (java.util.ArrayList)6 Drawable (android.graphics.drawable.Drawable)5 LocaleList (android.os.LocaleList)5 NonNull (android.support.annotation.NonNull)5 LayoutInflater (android.view.LayoutInflater)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)5