Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:in.shick.diode.common.Common.java

/**
 * Helper function to display a list of URLs.
 * @param theContext The current application context.
 * @param settings The settings to use regarding the browser component.
 * @param theItem The ThingInfo item to get URLs from.
 *//*w  w w  . j  ava 2 s.c om*/
public static void showLinksDialog(final Context theContext, final RedditSettings settings,
        final ThingInfo theItem) {
    assert (theContext != null);
    assert (theItem != null);
    assert (settings != null);
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = theItem.getUrls();
    for (MarkdownURL vtUrl : vtUrls) {
        urls.add(vtUrl.url);
    }
    ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext,
            android.R.layout.select_dialog_item, vtUrls) {
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv;
            if (convertView == null) {
                tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                        .inflate(android.R.layout.select_dialog_item, null);
            } else {
                tv = (TextView) convertView;
            }

            String url = getItem(position).url;
            String anchorText = getItem(position).anchorText;
            //                        if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText);

            Drawable d = null;
            try {
                d = theContext.getPackageManager()
                        .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            } catch (PackageManager.NameNotFoundException ignore) {
            }
            if (d != null) {
                d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                tv.setCompoundDrawablePadding(10);
                tv.setCompoundDrawables(d, null, null, null);
            }

            final String telPrefix = "tel:";
            if (url.startsWith(telPrefix)) {
                url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
            }

            if (anchorText != null)
                tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
            else
                tv.setText(Html.fromHtml(url));

            return tv;
        }
    };

    AlertDialog.Builder b = new AlertDialog.Builder(
            new ContextThemeWrapper(theContext, settings.getDialogTheme()));

    DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            if (which >= 0) {
                Common.launchBrowser(settings, theContext, urls.get(which),
                        Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(),
                        settings.isSaveHistory());
            }
        }
    };

    b.setTitle(R.string.select_link_title);
    b.setCancelable(true);
    b.setAdapter(adapter, click);

    b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    b.show();
}

From source file:com.example.amapapplicationtest.MainActivity.java

/** Called when the activity is first created. */
@Override// w  w w  .  j  av a 2  s . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initMap();

    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    String provider = lm.getBestProvider(new Criteria(), true);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();

    Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
    if (location != null) {
        googlemap.animateCamera(CameraUpdateFactory
                .newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));

        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
                .zoom(17) // Sets the zoom
                .bearing(90) // Sets the orientation of the camera to east
                .tilt(40) // Sets the tilt of the camera to 30 degrees
                .build(); // Creates a CameraPosition from the builder
        googlemap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    }

    if (provider == null) {
        onProviderDisabled(provider);
    }
    data = new MarkerDataSource(context);
    try {
        data.open();

    } catch (Exception e) {
        Log.i("hello", "hello");
    }

    List<MyMarkerObj> m = data.getMyMarkers();
    for (int i = 0; i < m.size(); i++) {
        String[] slatlng = m.get(i).getPosition().split(" ");
        LatLng lat = new LatLng(Double.valueOf(slatlng[0]), Double.valueOf(slatlng[1]));
        googlemap.addMarker(
                new MarkerOptions().title(m.get(i).getTitle()).snippet(m.get(i).getSnippet()).position(lat));

        googlemap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

            public void onInfoWindowClick(Marker marker) {
                Toast.makeText(getBaseContext(), "Info Window clicked@" + marker.getId(), Toast.LENGTH_SHORT)
                        .show();
            }
        });

        //  marker.view();
        //    data.getMarker(new MyMarkerObj(marker.getTitle(), marker.getSnippet(), marker.getPosition().latitude + " " + marker.getPosition().longitude));
    }

    googlemap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        public void onMapLongClick(final LatLng latlng) {
            LayoutInflater li = LayoutInflater.from(context);
            final View v = li.inflate(R.layout.alertlayout, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setView(v);
            builder.setCancelable(false);

            builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    EditText title = (EditText) v.findViewById(R.id.ettitle);
                    EditText snippet = (EditText) v.findViewById(R.id.etsnippet);
                    googlemap.addMarker(new MarkerOptions().title(title.getText().toString())
                            .snippet(snippet.getText().toString())
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
                            .position(latlng));
                    String sll = latlng.latitude + " " + latlng.longitude;
                    data.addMarker(
                            new MyMarkerObj(title.getText().toString(), snippet.getText().toString(), sll));
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            AlertDialog alert = builder.create();
            alert.show();

        }
    });
}

From source file:com.zerobyte.lifesync.EventDisplayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.editEvent_option:
        // LOGIC TO EDIT EVENT
        Intent EditEventIntent = new Intent(EventDisplayActivity.this, EventInputActivity.class);
        int currentPage = mPager.getCurrentItem();
        ScheduleEvent se = schedule_data.get(schedule_id_list.get(currentPage));

        HashMap<String, String> event_data = new HashMap<String, String>();
        event_data.put("event_id", "" + se.getEvent_id());
        event_data.put("event_name", se.getEvent_name());
        event_data.put("event_start_time", se.getEvent_start_time());
        event_data.put("event_end_time", se.getEvent_end_time());
        event_data.put("event_location", se.getEvent_location());
        event_data.put("event_description", se.getEvent_description());
        EditEventIntent.putExtra("event_data", event_data);
        startActivityForResult(EditEventIntent, EDIT_EVENT);

        return true;

    case R.id.deleteEvent_option:
        // LOGIC TO DELETE EVENT
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage("Delete Event?");
        builder.setInverseBackgroundForced(true);
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();/*from  ww w. j av a2s .  c om*/
            }
        });
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                final LifeSyncHttpClient httpClient = new LifeSyncHttpClient();
                ParameterMap params = httpClient.newParams();
                final int currentPage = mPager.getCurrentItem();
                ScheduleEvent se = schedule_data.get(schedule_id_list.get(currentPage));
                int eventID = se.getEvent_id();

                params.add("event_id", "" + eventID);

                httpClient.post("/removeEvent", params, new AsyncCallback() {
                    @Override
                    public void onComplete(HttpResponse httpResponse) {
                        int status = httpResponse.getStatus();

                        if (status == httpClient.HTTP_OK) {
                            showToast("Event successfully removed!");
                            schedule_data.remove(schedule_id_list.get(currentPage));
                            lfapp.saveSchedule(schedule_data);
                            onBackPressed();
                        } else {
                            showToast("Error removing event.");
                        }
                    }

                    @Override
                    public void onError(Exception e) {
                        showToast("Sorry, a server error occurred. Please try again. ");
                        showToast(e.getMessage());
                        e.printStackTrace();
                    }
                });

                // schedule_id_list.remove(currentPage);
                //mPager.removeViewAt(currentPage);

            }
        });
        AlertDialog alert = builder.create();
        alert.show();

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.microsoft.azure.engagement.engagement.AzmeNotifier.java

@Override
protected void prepareInAppArea(final EngagementReachInteractiveContent content, final View notifAreaView)
        throws RuntimeException {
    // Checks whether it is an in-app notifications with POP-UP category.
    if (content.isSystemNotification() == false
            && AzmeNotifier.IN_APP_POP_UP_CATEGORY.equals(content.getCategory()) == true) {
        // We create an in-app notifications with POP-UP category in order to display a dialog.

        // Gets the context from the view in order to display a dialog
        final Context context = notifAreaView.getContext();
        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
        dialogBuilder.setTitle(content.getNotificationTitle());
        dialogBuilder.setMessage(content.getNotificationMessage());
        dialogBuilder.setCancelable(false);
        // Sets the positive action to perform the Engagement 'open notification' action.
        dialogBuilder.setPositiveButton(R.string.positive_button, new OnClickListener() {
            @Override//from   ww w.ja va 2  s. com
            public void onClick(DialogInterface dialog, int which) {
                content.actionNotification(context, true);
            }
        });
        if (content.isNotificationCloseable() == true) {
            // Sets the negative action to perform the Engagement 'exit/cancel' action.
            dialogBuilder.setNegativeButton(R.string.negative_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    content.exitNotification(context);
                }
            });
        }
        notifAreaView.setVisibility(View.GONE);
        dialogBuilder.show();
    }
    // Checks whether it is an in-app notifications with INTERSTITIAL category.
    else if (content.isSystemNotification() == false
            && AzmeNotifier.INTERSTITIAL_CATEGORY.equals(content.getCategory()) == true) {
        // We display directly the notification content
        notifAreaView.setVisibility(View.GONE);
        content.actionNotification(mContext, true);
    } else {
        // We show the default in-app area.
        super.prepareInAppArea(content, notifAreaView);
    }
}

From source file:com.muzima.view.forms.FormWebViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        AlertDialog.Builder builder = new AlertDialog.Builder(FormWebViewActivity.this);
        builder.setCancelable(true).setIcon(getResources().getDrawable(R.drawable.ic_warning))
                .setTitle(getResources().getString(R.string.caution))
                .setMessage(getResources().getString(R.string.exit_form_message))
                .setPositiveButton("Yes", positiveClickListener()).setNegativeButton("No", null).create()
                .show();/*from   w  ww . j  a va2  s . co m*/
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.yahoo.mobile.client.android.yodel.ui.PostListFragment.java

public void showAlertDialog() {
    MainActivity activity = ((MainActivity) getActivity());
    if (activity == null) {
        return;/*w  ww .j  a v  a2  s  . c  om*/
    }
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setMessage(R.string.network_not_available);
    alertDialog.setCancelable(true);
    alertDialog.setPositiveButton(R.string.retry_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            refreshPosts();
            dialog.dismiss();
        }
    });
    alertDialog.setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    mAlertDialog = alertDialog.create();
    mAlertDialog.show();
}

From source file:com.example.angel.parkpanda.create_new_account.java

public void sendDataToDataBase() {

    LOGININFO.carlicensenumber = txt_carno.getText().toString();
    LOGININFO.email = txt_email.getText().toString();
    LOGININFO.firstname = txt_firstname.getText().toString();
    LOGININFO.lastname = txt_lastname.getText().toString();
    String strPass = txt_pasword.getText().toString();

    firebaseAuth.createUserWithEmailAndPassword(LOGININFO.email, strPass)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override/*ww  w . ja v a  2  s.com*/
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        FIRE_USER account = new FIRE_USER();
                        String strr = task.getResult().getUser().getUid().toString();
                        account.setcarlicensenumber(LOGININFO.carlicensenumber);
                        account.setFirstname(LOGININFO.firstname);
                        account.setLastname(LOGININFO.lastname);
                        account.setUid(strr);

                        DatabaseReference mDatabase;
                        mDatabase = FirebaseDatabase.getInstance().getReference();
                        mDatabase.child("profiles").child(strr).setValue(account);
                        LOGININFO.flag = 10;
                        Fragment fragment = new my_account();
                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction FT = fragmentManager.beginTransaction();
                        FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
                        FT.replace(R.id.flContent, fragment).commit();
                    } else {

                        LOGININFO.flag = 0;
                        LOGININFO.carlicensenumber = "";
                        LOGININFO.email = "";
                        LOGININFO.firstname = "";
                        LOGININFO.lastname = "";
                        String strPass = "";
                        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(getContext());
                        dlgAlert.setTitle("Email already exist.");
                        dlgAlert.setPositiveButton("OK", null);
                        dlgAlert.setCancelable(true);
                        dlgAlert.create().show();
                    }
                }
            });
}

From source file:com.phonegap.Notification.java

/**
 * Builds and shows a native Android alert with given Strings
 * @param message       The message the alert should display
 * @param title       The title of the alert
 * @param buttonLabel    The label of the button 
 * @param callbackId   The callback id/* ww  w  . jav a 2  s . co  m*/
 */
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final String callbackId) {

    final PhonegapActivity ctx = this.ctx;
    final Notification notification = this;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    notification.success(new PluginResult(PluginResult.Status.OK, 0), callbackId);
                }
            });
            dlg.create();
            dlg.show();
        };
    };
    this.ctx.runOnUiThread(runnable);
}

From source file:com.ota.updates.activities.MainActivity.java

private Boolean checkRomIsCompatible() {
    boolean doesRomSupportApp = Utils.doesPropExist(PROP_MANIFEST);
    if (!doesRomSupportApp) {
        final Activity activity = this;
        final Resources resources = getResources();
        String title = resources.getString(R.string.no_support_title);
        String message = resources.getString(R.string.no_support_message);
        String findOutMore = resources.getString(R.string.no_support_find_out_more);

        AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
        alert.setTitle(title);//w  w  w  .j  av a  2s.  c  o m
        alert.setMessage(message);
        alert.setCancelable(false);
        alert.setPositiveButton(findOutMore, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String findOutMoreLink = resources.getString(R.string.no_support_find_out_more_link);
                Utils.openWebsite(mContext, findOutMoreLink);
                activity.finish(); // This is very bad. But I need to end the app here
            }
        });
        alert.show();
    }
    return doesRomSupportApp;
}

From source file:com.orangelabs.rcs.ri.messaging.chat.ChatView.java

/**
 * Add quick text/* w ww .  j  a v  a 2 s.c  o m*/
 */
protected void addQuickText() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.label_select_quicktext);
    builder.setCancelable(true);
    builder.setItems(R.array.select_quicktext, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String[] items = getResources().getStringArray(R.array.select_quicktext);
            mComposeText.append(items[which]);
        }
    });
    registerDialog(builder.show());
}