Example usage for android.app Dialog setOnCancelListener

List of usage examples for android.app Dialog setOnCancelListener

Introduction

In this page you can find the example usage for android.app Dialog setOnCancelListener.

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:jp.sonymusicstudio.cast.castcompanionlibrary.utils.Utils.java

/**
 * A utility method to validate that the appropriate version of the Google Play Services is
 * available on the device. If not, it will open a dialog to address the issue. The dialog
 * displays a localized message about the error and upon user confirmation (by tapping on
 * dialog) will direct them to the Play Store if Google Play services is out of date or
 * missing, or to system settings if Google Play services is disabled on the device.
 *//*from   w w w . java 2  s  .  c  o  m*/
public static boolean checkGooglePlayServices(final Activity activity) {
    final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    switch (googlePlayServicesCheck) {
    case ConnectionResult.SUCCESS:
        return true;
    default:
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                activity.finish();
            }
        });
        dialog.show();
    }
    return false;
}

From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java

/**
 * A utility method to validate that the appropriate version of the Google Play Services is
 * available on the device. If not, it will open a dialog to address the issue. The dialog
 * displays a localized message about the error and upon user confirmation (by tapping on
 * dialog) will direct them to the Play Store if Google Play services is out of date or
 * missing, or to system settings if Google Play services is disabled on the device.
 *//*from  w  w  w  . j a va2 s  .com*/
public static boolean checkGooglePlayServices(final Activity activity) {
    final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    switch (googlePlayServicesCheck) {
    case ConnectionResult.SUCCESS:
        return true;
    default:
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                activity.finish();
            }
        });
        dialog.show();
    }
    return false;
}

From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java

/**
 * A utility method to validate that the appropriate version of the Google
 * Play Services is available on the device. If not, it will open a dialog
 * to address the issue. The dialog displays a localized message about the
 * error and upon user confirmation (by tapping on dialog) will direct them
 * to the Play Store if Google Play services is out of date or missing, or
 * to system settings if Google Play services is disabled on the device.
 * //  w w  w. j  a  v  a 2 s.  c o  m
 * @param activity
 * @return
 */
public static boolean checkGooglePlaySevices(final Activity activity) {
    final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    switch (googlePlayServicesCheck) {
    case ConnectionResult.SUCCESS:
        return true;
    default:
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                activity.finish();
            }
        });
        dialog.show();
    }
    return false;
}

From source file:com.ze.client.projecto.dialog.ProjectorDialog.java

@NonNull
@Override//ww w.  java  2  s.c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setOnCancelListener(dialog1 -> dismiss());
    return dialog;
}

From source file:org.dmfs.android.colorpicker.ColorPickerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog result = super.onCreateDialog(savedInstanceState);
    result.requestWindowFeature(Window.FEATURE_NO_TITLE);
    result.setOnCancelListener(this);
    return result;
}

From source file:com.example.google.touroflondon.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    // Verify that Google Play Services is available
    int playStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    if (playStatus != ConnectionResult.SUCCESS) {
        // Google Play services is not available, prompt user and close
        // application when dialog is dismissed
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(playStatus, this, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override/*from w w w  .  ja v a2  s  . c  om*/
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog.show();

        // Hide all active fragments
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mMapFragment);
        if (mPoiListFragment != null) {
            ft.hide(mPoiListFragment);
        }
        ft.commit();

    } else {

        // Make sure active fragments are shown when returning from Play
        // Services dialog interaction
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(mMapFragment);
        if (mPoiListFragment != null) {
            ft.show(mPoiListFragment);
        }
        ft.commit();
    }
}

From source file:com.example.android.touroflondon.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //Verify that Google Play Services is available
    int playStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    if (playStatus != ConnectionResult.SUCCESS) {
        // Google Play services is not available, prompt user and close application when dialog is dismissed
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(playStatus, this, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override//from   w  ww .j a va2s .  co m
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog.show();

        // Hide all active fragments
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mMapFragment);
        if (mPoiListFragment != null) {
            ft.hide(mPoiListFragment);
        }
        ft.commit();

    } else {

        // Getting reference to the SupportMapFragment of activity_main.xml
        TourMapFragment fm = (TourMapFragment) getFragmentManager().findFragmentById(R.id.fragment_map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 0, mMapFragment);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 0, mMapFragment);
        //            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        // Make sure active fragments are shown when returning from Play Services dialog interaction
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(mMapFragment);
        if (mPoiListFragment != null) {
            ft.show(mPoiListFragment);
        }
        ft.commit();

    }

}

From source file:com.dustinmreed.openwifi.DetailFragment.java

private void checkGooglePlayServicesAvailable() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
    if (status != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), 0);
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override/*from w  w  w . j  a v a2s  .  c  om*/
                public void onCancel(DialogInterface dialogInterface) {
                    getActivity().finish();
                }
            });
            dialog.show();
        } else {
            Toast.makeText(getActivity().getApplicationContext(), "This device is not supported.",
                    Toast.LENGTH_LONG).show();
            getActivity().finish();
        }
    }
}

From source file:org.mythdroid.activities.MDActivity.java

@Override
public Dialog onCreateDialog(int id) {

    switch (id) {

    case FRONTEND_CHOOSER:
        final Dialog d = createFrontendDialog();
        d.setOnDismissListener(dismissListener);
        d.setOnCancelListener(cancelListener);
        return d;

    case DIALOG_LOAD:
        final ProgressDialog prog = new ProgressDialog(this);
        prog.setIndeterminate(true);/*  ww  w .  j a v  a 2 s. c om*/
        prog.setMessage(getResources().getText(R.string.loading));
        prog.setCanceledOnTouchOutside(false);
        prog.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                finish();
            }
        });
        return prog;

    }

    return null;

}

From source file:at.wada811.android.dialogfragments.AbstractDialogFragment.java

protected void setOnCancelListener(Dialog dialog) {
    useOnCancelListener = true;/*from   w w  w.j av a2  s  . c  o m*/
    dialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            bindCancelListener();
        }
    });
}