Example usage for android.app Dialog setCancelable

List of usage examples for android.app Dialog setCancelable

Introduction

In this page you can find the example usage for android.app Dialog 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:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java

private void showHelpDialog() {
    Dialog helpDialog = new Dialog(this);
    helpDialog.setCancelable(true);
    helpDialog.setCanceledOnTouchOutside(true);

    helpDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    helpDialog.setContentView(getLayoutInflater().inflate(R.layout.help_dialog_view, null));

    helpDialog.show();//from   w  w w .ja va  2  s.  c  om
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public void showDialog() throws NameNotFoundException {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.about_dialog);
    dialog.setTitle("About Repeater.MY " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    dialog.setCancelable(true);

    // text/*from   w  ww.ja v a 2s  .  com*/
    TextView text = (TextView) dialog.findViewById(R.id.tvAbout);
    text.setText(R.string.txtLicense);

    // icon image
    ImageView img = (ImageView) dialog.findViewById(R.id.ivAbout);
    img.setImageResource(R.drawable.ic_launcher);

    dialog.show();

}

From source file:com.android.cabapp.fragments.MyAccountFragment.java

void showDialog() {

    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.device_id_dialog);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);

    etDeviceName = (EditText) dialog.findViewById(R.id.etDeviceName);
    rlBtnSave = (RelativeLayout) dialog.findViewById(R.id.rlbtnSave);
    rlBtnCancel = (RelativeLayout) dialog.findViewById(R.id.rlbtnCancel);

    if (!Util.getPOSDeviceName(mContext).equals(""))
        etDeviceName.setText(Util.getPOSDeviceName(mContext));
    etDeviceName.setSelection(etDeviceName.getText().length());

    // dialog.setTitle("Please enter Serial number");
    rlBtnSave.setOnClickListener(new View.OnClickListener() {
        @Override//  w ww .j ava2  s.  co m
        public void onClick(View v) {
            String szDeviceName = etDeviceName.getText().toString().trim();
            if (szDeviceName.isEmpty()) {
                Util.showToastMessage(mContext, "Field cannot be left empty!", Toast.LENGTH_LONG);
            } else if (szDeviceName.length() < 11) {
                Util.showToastMessage(mContext, "Serial number cannot be less than 10!", Toast.LENGTH_LONG);
            } else {
                Util.setPOSDeviceName(mContext, szDeviceName);
                tvDeviceID.setVisibility(View.VISIBLE);
                tvDeviceID.setText(Util.getPOSDeviceName(mContext));
                Util.hideSoftKeyBoard(mContext, rlBtnSave);
                dialog.dismiss();

            }

        }
    });

    rlBtnCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Util.hideSoftKeyBoard(mContext, v);
            dialog.dismiss();
        }
    });
    dialog.show();

}

From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java

/**
 * Method to verify google play services on the device
 * *//*from ww w . java 2s  .  co  m*/
private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST);
            dialog.setCancelable(false);
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        } else {
            Toast.makeText(getApplicationContext(), "This device is not supported Play Service.",
                    Toast.LENGTH_LONG).show();
            finish();
        }
        return false;
    }
    return true;
}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *//* w w  w.j  a  v a 2  s .  co  m*/
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    // UI settings for dialog pop-up
    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + name + " created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Close dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 *///from  w  w w.  j a  v  a  2 s.  c  o m
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer position = mListView.getPositionForView(view);
    final Dialog editDialog = new Dialog(this);

    // UI settings for dialog pop-up
    editDialog.setContentView(R.layout.add_edit_dialog);
    editDialog.setTitle("Edit Todo");
    TextView textView = (TextView) editDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    editDialog.setCancelable(true);
    EditText currentText = (EditText) editDialog.findViewById(R.id.todo);

    // Get selected TodoItem values
    final String name = mTodoItemList.get(position).text;
    final boolean isDone = mTodoItemList.get(position).isDone;
    final int id = mTodoItemList.get(position).idNumber;
    currentText.setText(name);

    Button editDone = (Button) editDialog.findViewById(R.id.Add);
    editDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    editDone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) editDialog.findViewById(R.id.todo);

            final String updatedName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!updatedName.isEmpty()) {
                String json = "{\"text\":\"" + updatedName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + updatedName + " updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            editDialog.dismiss();
        }
    });
}

From source file:nf.frex.android.FrexActivity.java

private Dialog createColorsDialog() {
    Dialog dialog = new Dialog(this);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    dialog.setContentView(R.layout.colors_dialog);
    dialog.setTitle(getString(R.string.colors));
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
}

From source file:org.thoughtland.xlocation.ActivityApp.java

@SuppressLint("InflateParams")
public static void showHelp(ActivityBase context, View parent, Hook hook) {
    // Build dialog
    Dialog dlgHelp = new Dialog(context);
    dlgHelp.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dlgHelp.setTitle(R.string.app_name);
    dlgHelp.setContentView(R.layout.helpfunc);
    dlgHelp.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, context.getThemed(R.attr.icon_launcher));
    dlgHelp.setCancelable(true);

    // Set title/*  w  w w . j  a  v  a 2  s  .  co  m*/
    TextView tvTitle = (TextView) dlgHelp.findViewById(R.id.tvTitle);
    tvTitle.setText(hook.getName());

    // Set info
    TextView tvInfo = (TextView) dlgHelp.findViewById(R.id.tvInfo);
    tvInfo.setText(Html.fromHtml(hook.getAnnotation()));
    tvInfo.setMovementMethod(LinkMovementMethod.getInstance());

    // Set permissions
    String[] permissions = hook.getPermissions();
    if (permissions != null && permissions.length > 0)
        if (!permissions[0].equals("")) {
            TextView tvPermissions = (TextView) dlgHelp.findViewById(R.id.tvPermissions);
            tvPermissions.setText(Html.fromHtml(TextUtils.join("<br />", permissions)));
        }

    dlgHelp.show();
}

From source file:org.wso2.emm.agent.AuthenticationActivity.java

/**
 * Show the license text retrieved from the server.
 *
 * @param message Message text to be shown as the license.
 * @param title   Title of the license.//from w ww  . j ava 2  s.  c o m
 */
private void showAgreement(final String message, String title) {
    AuthenticationActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom_terms_popup);
            dialog.setTitle(Constants.EULA_TITLE);
            dialog.setCancelable(false);

            WebView webView = (WebView) dialog.findViewById(R.id.webview);

            webView.loadDataWithBaseURL(null, message, Constants.MIME_TYPE, Constants.ENCODING_METHOD, null);

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);

            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Preference.putBoolean(context, Constants.PreferenceFlag.IS_AGREED, true);
                    dialog.dismiss();
                    //load the next intent based on ownership type
                    checkManifestPermissions();
                }
            });

            cancelButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    CommonUtils.clearClientCredentials(context);
                    cancelEntry();
                }
            });

            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_SEARCH
                            && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) {
                        return true;
                    } else if (keyCode == KeyEvent.KEYCODE_BACK
                            && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) {
                        return true;
                    }
                    return false;
                }
            });

            dialog.show();
        }
    });
}

From source file:com.nbplus.vbroadlauncher.fragment.LoadIoTDevicesDialogFragmentStatus.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = new Dialog(
            getActivity()/*new ContextThemeWrapper(getActivity(), R.style.FullScreenDialog)*/);

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    setRetainInstance(true);// ww w.  j  a v  a  2  s. co m
    originalOrientation = getActivity().getRequestedOrientation();
    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    // fullscreen without statusbar
    dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    dialog.setCancelable(false);
    this.setCancelable(false);

    // disable back key
    dialog.setOnKeyListener(this);

    // set content view
    View v = getActivity().getLayoutInflater().inflate(R.layout.fragment_iot_devices, null, false);
    dialog.setContentView(v);

    // grid view
    mGridView = (GridView) v.findViewById(R.id.iot_devices_grid);
    mGridView.setEmptyView(v.findViewById(android.R.id.empty));

    // set button control
    mCloseButton = (ImageButton) v.findViewById(R.id.btn_close);
    mCloseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnClose..");
            ((BaseActivity) getActivity()).dismissProgressDialog();
            Intent sendIntent = new Intent();
            sendIntent.setAction(Constants.ACTION_IOT_DEVICE_LIST);
            sendIntent.putExtra(Constants.EXTRA_IOT_DEVICE_CANCELED, true);
            LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(sendIntent);

            dismiss();
        }
    });

    mRefreshButton = (Button) v.findViewById(R.id.btn_refresh);
    mRefreshButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnRefresh..");
            ((BaseActivity) getActivity()).showProgressDialog();

            IoTInterface.getInstance().getDevicesList(DeviceTypes.ALL, LoadIoTDevicesDialogFragmentStatus.this,
                    true);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    ((BaseActivity) getActivity()).dismissProgressDialog();
                }
            }, 6000);
        }
    });

    mSendButton = (Button) v.findViewById(R.id.btn_send);
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnSend..");
            ((BaseActivity) getActivity()).dismissProgressDialog();
            showSyncAlertDialog();
        }
    });

    mGridView.setOnItemClickListener(this);

    return dialog;
}