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);
}
}
});
}
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);
}
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;
}
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();
}
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));
}
Aggregations