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.neighbor.ex.tong.ui.activity.MainActivity2Activity.java

private void showDialogAree() {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    dialog.setContentView(R.layout.dialog_agree); // custom_dialog.xml  ? layout  ?? view .
    WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
    params.width = LinearLayout.LayoutParams.MATCH_PARENT;
    final CheckBox accountLicense = (CheckBox) dialog.findViewById(R.id.checkBoxAgree);
    final Button agreeBtn = (Button) dialog.findViewById(R.id.buttonAgree);
    final Button agreeCancelBtn = (Button) dialog.findViewById(R.id.buttonAgreeCancel);
    agreeBtn.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w  .  ja  v a  2 s .co m*/
        public void onClick(View view) {
            if (accountLicense.isChecked()) {
                SharedPreferenceManager.setValue(MainActivity2Activity.this,
                        SharedPreferenceManager.positionAgree, "true");
                dialog.dismiss();
            }
        }
    });
    agreeCancelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:org.csp.everyaware.offline.Map.java

private void insertAnnDialog(final ExtendedLatLng annLatLng) {
    final Dialog insertDialog = new Dialog(Map.this);
    insertDialog.setContentView(R.layout.insert_dialog);
    insertDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    insertDialog.setTitle(R.string.annotation_insertion);
    insertDialog.setCancelable(false);

    //get reference to send button
    final Button sendButton = (Button) insertDialog.findViewById(R.id.send_button);
    sendButton.setEnabled(false); //active only if there's text

    //get reference to cancel/close window button
    final Button cancelButton = (Button) insertDialog.findViewById(R.id.cancel_button);
    cancelButton.setEnabled(true); //active all time
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override/*from  www .  ja  v  a 2s.  c o m*/
        public void onClick(View v) {
            insertDialog.dismiss();
        }
    });

    //get reference to edittext in which user writes annotation
    final EditText editText = (EditText) insertDialog.findViewById(R.id.annotation_editText);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //if modified text length is more than 0, activate send button
            if (s.length() > 0)
                sendButton.setEnabled(true);
            else
                sendButton.setEnabled(false);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    //get checkbox references
    CheckBox facebookChBox = (CheckBox) insertDialog.findViewById(R.id.facebook_checkBox);
    CheckBox twitterChBox = (CheckBox) insertDialog.findViewById(R.id.twitter_checkBox);

    //activate check boxes depends from log in facebook/twitter
    boolean[] logs = new boolean[2];
    logs[0] = Utils.getValidFbSession(getApplicationContext());
    logs[1] = Utils.getValidTwSession(getApplicationContext());

    facebookChBox.setEnabled(logs[0]);
    twitterChBox.setEnabled(logs[1]);

    //checked on check boxes
    final boolean[] checkeds = Utils.getShareCheckedOn(getApplicationContext());
    if (checkeds[0] == true)
        facebookChBox.setChecked(true);
    else
        facebookChBox.setChecked(false);
    if (checkeds[1] == true)
        twitterChBox.setChecked(true);
    else
        twitterChBox.setChecked(false);

    facebookChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            Utils.setShareCheckedOn(checked, checkeds[1], getApplicationContext());
            checkeds[0] = checked;
        }
    });

    twitterChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            Utils.setShareCheckedOn(checkeds[0], checked, getApplicationContext());
            checkeds[1] = checked;
        }
    });

    //send annotation to server and on facebook/twitter if user is logged on 
    sendButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //1 - read inserted annotation
            String annotation = editText.getText().toString();

            //2 - update record on db with annotation and save recordId            
            double recordId = annLatLng.mRecordId;

            int result = mDbManager.updateRecordAnnotation(recordId, annotation);

            if (result == 1)
                Toast.makeText(getApplicationContext(), "Updated record", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show();

            boolean[] checks = Utils.getShareCheckedOn(getApplicationContext());

            //3 - share on facebook is user wants and internet is active now
            if (checks[0] == true) {
                Record annotatedRecord = mDbManager.loadRecordById(recordId);
                try {
                    FacebookManager fb = FacebookManager.getInstance(null, null);
                    if (fb != null)
                        fb.postMessageOnWall(annotatedRecord);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //4 - share on twitter is user wants and internet is active now
            if (checks[1] == true) {
                Record annotatedRecord = mDbManager.loadRecordById(recordId);

                try {
                    TwitterManager twManager = TwitterManager.getInstance(null);
                    twManager.postMessage(annotatedRecord);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //5 - show marker for annotated record
            Record annotatedRecord = mDbManager.loadRecordById(recordId);

            String userAnn = annotatedRecord.mUserData1;

            if (!userAnn.equals("") && (annotatedRecord.mValues[0] != 0)) {
                BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.annotation_marker);
                Marker marker = mGoogleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(annotatedRecord.mValues[0], annotatedRecord.mValues[1]))
                        .title("BC: " + String.valueOf(annotatedRecord.mBcMobile) + " "
                                + getResources().getString(R.string.micrograms))
                        .snippet("Annotation: " + userAnn).icon(icon).anchor(0f, 1f));
            }

            insertDialog.dismiss();
        }
    });

    insertDialog.show();
}

From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsReceivePaymentMainFragment.java

/**
 * ??/*from   w w w .j  a  va 2  s  .  c om*/
 * @param message
 * @param positive
 * @param negative
 * @param positiveEnable
 * @param negativeEnable
 */
private void showDefaultCardDialog(String message, String positive, String negative, boolean positiveEnable,
        boolean negativeEnable) {
    message = "??????????";

    //newDialog?
    Dialog dialog = new Dialog(getActivity(), R.style.MyDialogStyleBottom);
    //ContentView
    dialog.setContentView(R.layout.sms_default_card_dialog);
    dialog.findViewById(R.id.select_card).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            selectReceiveBankCard();
        }
    });
    dialog.findViewById(R.id.add_card).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            addReceiveBankCard();
        }
    });

    dialog.findViewById(R.id.select_card).setEnabled(positiveEnable);
    dialog.findViewById(R.id.add_card).setEnabled(negativeEnable);
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();
}

From source file:com.orange.datavenue.DatasourceListFragment.java

/**
 *
 *//*from   w  w  w .  j ava2s  . c o  m*/
private void deleteDatasource() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.delete_dialog);
    dialog.setTitle(R.string.delete);

    TextView info = (TextView) dialog.findViewById(R.id.info_label);
    info.setText(
            String.format(getString(R.string.delete_datasource), Model.instance.currentDatasource.getId()));

    Button deleteButton = (Button) dialog.findViewById(R.id.delete_button);
    deleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId());

            DeleteDatasourceOperation deleteDatasourceOperation = new DeleteDatasourceOperation(
                    Model.instance.oapiKey, Model.instance.key, Model.instance.currentDatasource,
                    new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getDatasources(); // reload
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            deleteDatasourceOperation.execute("");

            dialog.dismiss();
        }

    });

    Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelDeleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java

public void oAuthRequest(String hostAndPath, String clientId, String scope) {

    Activity activity = getActivity();/*w  w  w  .j  a  v a2s  .co m*/
    if (activity == null) {
        return;
    }

    byte[] buf = new byte[16];
    new Random().nextBytes(buf);
    mOAuthState = new String(Hex.encode(buf));
    mOAuthCode = null;

    final Dialog auth_dialog = new Dialog(activity);
    auth_dialog.setContentView(R.layout.oauth_webview);
    WebView web = (WebView) auth_dialog.findViewById(R.id.web_view);
    web.getSettings().setSaveFormData(false);
    web.getSettings().setUserAgentString("OpenKeychain " + BuildConfig.VERSION_NAME);
    web.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);
            if ("oauth-openkeychain".equals(uri.getScheme())) {

                if (mOAuthCode != null) {
                    return true;
                }

                if (uri.getQueryParameter("error") != null) {
                    Log.i(Constants.TAG, "got oauth error: " + uri.getQueryParameter("error"));
                    auth_dialog.dismiss();
                    return true;
                }

                // check if mOAuthState == queryParam[state]
                mOAuthCode = uri.getQueryParameter("code");

                auth_dialog.dismiss();
                return true;
            }
            // don't surf away from github!
            if (!"github.com".equals(uri.getHost())) {
                auth_dialog.dismiss();
                return true;
            }
            return false;
        }

    });

    auth_dialog.setTitle(R.string.linked_webview_title_github);
    auth_dialog.setCancelable(true);
    auth_dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            step1GetOAuthToken();
        }
    });
    auth_dialog.show();

    web.loadUrl("https://" + hostAndPath + "?client_id=" + clientId + "&scope=" + scope
            + "&redirect_uri=oauth-openkeychain://linked/" + "&state=" + mOAuthState);

}

From source file:com.mitre.holdshort.MainActivity.java

private void showDisclaimer() {

    final Dialog dialog = new Dialog(MainActivity.this);
    OnClickListener disclaimerBtnClick;//  ww w.  j  a  v  a2s  .c  o  m

    dialog.setContentView(R.layout.legal_stuff_dialog);
    dialog.setTitle("RIPPLE - Informed Consent");
    dialog.setCancelable(false);
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    TextView consent = (TextView) dialog.findViewById(R.id.disclaimerAccept);
    TextView reject = (TextView) dialog.findViewById(R.id.disclaimerReject);

    disclaimerBtnClick = new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (v.getId() == R.id.disclaimerAccept) {
                settings.edit().putBoolean("consent", true).commit();
                dialog.dismiss();
                waiverAccept = true;
                startUp();
            } else {
                finish();
            }

        }

    };

    consent.setOnClickListener(disclaimerBtnClick);
    reject.setOnClickListener(disclaimerBtnClick);
    dialog.show();

}

From source file:biz.bokhorst.xprivacy.ActivityApp.java

private void optionHelp() {
    // Show help/*from w  w w  .  j  a  v  a 2s  . com*/
    Dialog dialog = new Dialog(ActivityApp.this);
    dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dialog.setTitle(R.string.menu_help);
    dialog.setContentView(R.layout.help);
    dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
    ((ImageView) dialog.findViewById(R.id.imgHelpHalf)).setImageBitmap(getHalfCheckBox());
    ((ImageView) dialog.findViewById(R.id.imgHelpOnDemand)).setImageBitmap(getOnDemandCheckBox());
    dialog.setCancelable(true);
    dialog.show();
}

From source file:com.orange.datavenue.StreamListFragment.java

/**
 *
 *//*from ww w  .j av  a 2s .c  om*/
private void deleteStream() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.delete_dialog);
    dialog.setTitle(R.string.delete);

    TextView info = (TextView) dialog.findViewById(R.id.info_label);
    info.setText(String.format(getString(R.string.delete_stream), Model.instance.currentStream.getId()));

    Button deleteButton = (Button) dialog.findViewById(R.id.delete_button);

    deleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId());
            Log.d(TAG_NAME, "stream : " + Model.instance.currentStream.getId());

            DeleteStreamOperation deleteStreamOperation = new DeleteStreamOperation(Model.instance.oapiKey,
                    Model.instance.key, Model.instance.currentDatasource, Model.instance.currentStream,
                    new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getStreams(); // reload
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            deleteStreamOperation.execute("");

            dialog.dismiss();
        }

    });

    Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelDeleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Create a Emoticons {@link Dialog}.//from   w ww.  j a  v a2s .  c om
 *
 * @return Emoticons {@link Dialog}
 */
private Dialog createEmoticonsDialog() {
    final Dialog d = new Dialog(this);
    d.setTitle(R.string.emo_);
    d.setContentView(R.layout.emo);
    d.setCancelable(true);
    final String[] emoticons = this.getResources().getStringArray(R.array.emoticons);
    final GridView gridview = (GridView) d.findViewById(R.id.gridview);
    gridview.setAdapter(new BaseAdapter() {
        // references to our images
        // keep order and count synced with string-array!
        private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool,
                R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy,
                R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed,
                R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised,
                R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking,
                R.drawable.emo_im_wtf, R.drawable.emo_im_yelling };

        @Override
        public long getItemId(final int position) {
            return 0;
        }

        @Override
        public Object getItem(final int position) {
            return null;
        }

        @Override
        public int getCount() {
            return this.mThumbIds.length;
        }

        @Override
        public View getView(final int position, final View convertView, final ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) { // if it's not recycled,
                // initialize some attributes
                imageView = new ImageView(WebSMS.this);
                imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING,
                        EMOTICONS_PADDING);
            } else {
                imageView = (ImageView) convertView;
            }

            imageView.setImageResource(this.mThumbIds[position]);
            return imageView;
        }
    });
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) {
            EditText et = WebSMS.this.etText;
            final String e = emoticons[id];
            int i = et.getSelectionStart();
            int j = et.getSelectionEnd();
            if (i > j) {
                int x = i;
                i = j;
                j = x;
            }
            String t = et.getText().toString();
            et.setText(t.substring(0, i) + e + t.substring(j));
            et.setSelection(i + e.length());
            d.dismiss();
            et.requestFocus();
        }
    });
    return d;
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

private void optionTutorial() {
    ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
    ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    int userId = Util.getUserId(Process.myUid());
    PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.FALSE.toString());

    Dialog dlgUsage = new Dialog(this);
    dlgUsage.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dlgUsage.setTitle(R.string.title_usage_header);
    dlgUsage.setContentView(R.layout.usage);
    dlgUsage.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
    dlgUsage.setCancelable(true);
    dlgUsage.show();//  www.  j  a v  a2  s .c  o m
}