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:org.tigase.mobile.TigaseMobileMessengerActivity.java

@Override
protected Dialog onCreateDialog(int id, Bundle bundle) {
    switch (id) {
    case NEWS_DIALOG: {

        String str = bundle.getString("news_html");

        Builder bldr = new AlertDialog.Builder(this);
        bldr.setTitle("News");
        bldr.setCancelable(true);//from ww w  . j  a  va  2 s.c  o m
        bldr.setMessage(Html.fromHtml(str));
        return bldr.create();
    }

    case CONTACT_REMOVE_DIALOG:
        return null;
    case ABOUT_DIALOG: {

        final Dialog dialog = new Dialog(this);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);

        dialog.setContentView(R.layout.about_dialog);
        dialog.setTitle(getString(R.string.aboutButton));

        TextView tos = (TextView) dialog.findViewById(R.id.aboutTermsOfService);
        tos.setText(Html.fromHtml("<a href='" + getResources().getString(R.string.termsOfServiceURL) + "'>"
                + getResources().getString(R.string.termsOfService) + "</a>"));
        tos.setMovementMethod(LinkMovementMethod.getInstance());

        TextView pp = (TextView) dialog.findViewById(R.id.aboutPrivacyPolicy);
        pp.setText(Html.fromHtml("<a href='" + getResources().getString(R.string.privacyPolicyURL) + "'>"
                + getResources().getString(R.string.privacyPolicy) + "</a>"));
        pp.setMovementMethod(LinkMovementMethod.getInstance());

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

            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        return dialog;
    }
    default:
        return null;
    }
}

From source file:com.woofy.haifa.MapActivity.java

private boolean initMap() {
    if (mMap == null) {
        SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mMap = mapFrag.getMap();/*from   ww  w.  j  a  va2  s .  c  o m*/

        if (mMap != null) {
            mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker marker) {

                    // Getting view from the layout file
                    LayoutInflater inflater = LayoutInflater.from(MapActivity.this);
                    View v = inflater.inflate(R.layout.info_window, null);

                    TextView locality = (TextView) v.findViewById(R.id.tv_locality);
                    locality.setText(marker.getTitle());

                    //                   TextView title = (TextView) v.findViewById(R.id.tv_lat);
                    //                   title.setText(marker.getTitle());

                    TextView address = (TextView) v.findViewById(R.id.tv_lng);
                    address.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                    }
                    if (pic_map.containsKey(marker.getTitle())) {
                        img.setImageBitmap(pic_map.get(marker.getTitle()));
                    }
                    if (marker.getTitle().equals("You")) {
                        img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.you_marker));
                    }

                    if (marker.getSnippet().length() < 30) {

                        //                   img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                        //                   HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                   task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                   
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;
                    //                  return null;
                }

                @Override
                public View getInfoContents(Marker marker) {

                    View v = getLayoutInflater().inflate(R.layout.info_window, null);
                    TextView tvLocality = (TextView) v.findViewById(R.id.tv_locality);
                    TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);
                    TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
                    TextView tvSnippet = (TextView) v.findViewById(R.id.tv_snippet);
                    //                  ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    LatLng ll = marker.getPosition();

                    tvLocality.setText(marker.getTitle());
                    //                  tvLat.setText("Dogs: " + "Woofy, Goofy");
                    //                  tvLng.setText("Click for more info");
                    //                  tvSnippet.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);

                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                        Log.d("Set bitmap", "Set bitmap");
                    } else {
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                    }
                    if (marker.getSnippet().length() < 30) {

                        //                      img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));

                        //                      HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                      task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                      
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;

                }
            });

            mMap.setOnMapLongClickListener(new OnMapLongClickListener() {

                @Override
                public void onMapLongClick(final LatLng point) {

                    final Dialog dialog = new Dialog(MapActivity.this);
                    dialog.setContentView(R.layout.alert_layout);
                    dialog.setCancelable(true);
                    dialog.show();

                    //                       .setMessage(R.string.really_quit)
                    Button b = (Button) dialog.findViewById(R.id.yesmeet);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            String t1 = ((EditText) dialog.findViewById(R.id.meet_name)).getText().toString();
                            //                               String t2 = ((EditText)dialog.findViewById(R.id.editText1111)).getText().toString();

                            if (meet != null)
                                meet.remove();
                            MarkerOptions options;
                            options = new MarkerOptions().title(t1).position(point)
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
                                    .anchor(.5f, .5f) //center the icon
                                    .draggable(true);

                            Marker mar = mMap.addMarker(options);

                            //                           MeetingMarkers.add(mar);
                            meet = mar;

                            dialog.dismiss();

                        }

                    });

                    Button b1 = (Button) dialog.findViewById(R.id.nomeet);
                    b1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            dialog.dismiss();

                        }
                    });

                }
            });

            mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
                @Override
                public void onCameraChange(CameraPosition position) {
                    if (SystemClock.uptimeMillis() - show_people_last_updated > 1000) {
                        show_people_last_updated = SystemClock.uptimeMillis();
                        showPeople();
                    }
                }
            });

            mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

                @Override
                public boolean onMarkerClick(final Marker marker) {

                    lastbitmap = null;
                    marker.hideInfoWindow();
                    marker.showInfoWindow();

                    return false;
                }
            });

            mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                @Override
                public void onInfoWindowClick(Marker marker) {
                    Log.d("Open profile page", marker.getTitle());
                    Intent intent = new Intent(MapActivity.this, Profile.class);
                    intent.putExtra("name", marker.getTitle());
                    startActivity(intent);

                }
            });

            mMap.setOnMarkerDragListener(new OnMarkerDragListener() {

                @Override
                public void onMarkerDragStart(Marker marker) {
                    marker.remove();
                    MarkerOptions options;
                    options = new MarkerOptions().title(marker.getTitle()).position(marker.getPosition())
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
                            .anchor(.5f, .5f) //center the icon
                            .draggable(true);

                    String name = marker.getTitle();
                    if (selected_markers.contains(name)) {
                        selected_markers.remove(name);
                    } else {
                        selected_markers.add(name);
                        options.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_checked));
                    }

                    Marker addmarker = mMap.addMarker(options);
                    PersonMarkers.add(addmarker);
                }

                @Override
                public void onMarkerDragEnd(Marker marker) {

                }

                @Override
                public void onMarkerDrag(Marker arg0) {

                }
            });
        }
    }
    return (mMap != null);
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

public void openDialog() {
    //      Dialog dialog = null;
    //      Builder builder = new Dialog.Builder(this).setTitle("?").setMessage("??");
    //      dialog = builder.create();
    //      dialog.show();

    Dialog dialog = new Dialog(this, R.style.CustomDialog);
    dialog.setContentView(R.layout.launcher_fail);
    dialog.setOnKeyListener(keylistener);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);
    dialog.show();/*from   w w  w.j a  va  2s.co  m*/
}

From source file:com.birdeye.MainActivity.java

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

    switch (item.getItemId()) {
    case R.id.logout:

        fullReset();//w ww . jav a 2 s . com
        startActivity(LoginActivity.create(this));
        finish();

        return true;

    case R.id.About:

        final Dialog dialog2 = new Dialog(MainActivity.this);
        dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog2.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog2.setContentView(R.layout.about);
        dialog2.setCancelable(false);

        dialog2.show();

        return true;

    case R.id.ShareApp:

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/html");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(
                "<p>Hey, am using this really cool hashtag activated camera app. Get it here #birdeyecamera.</p>"));
        startActivity(Intent.createChooser(sharingIntent, "Share using"));

        return true;

    case R.id.Recommend:

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("BirdEyeCamera", "birdeyecamera@digitalbabi.es", null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feature Recommendation");
        startActivity(Intent.createChooser(emailIntent, "Send email..."));

        return true;

    case R.id.rateApp:

        final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
        final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

        if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0) {
            startActivity(rateAppIntent);
        } else {
            /* handle your error case: the device has no way to handle market urls */
        }

        return true;

    case R.id.RemoveAds:

        if (Globals.hasPaid) {
            Toast.makeText(MainActivity.this, "You already are in a premium account", Toast.LENGTH_SHORT)
                    .show();

        } else {

            removeAdsDialog();

        }

        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.thingsee.tracker.MainActivity.java

@Override
public void onBackPressed() {
    if (touchActive) {
        if (onChildOnMapView) {
            if ((trackerModelWithMarker != null) && (trackerModelWithMarker.getMarker().isInfoWindowShown())) {
                trackerModelWithMarker.getMarker().hideInfoWindow();
            }/*from w w w.  j ava  2  s  . c  o  m*/
            displayTrackers();
            trackerList.setVisibility(View.VISIBLE);
            onChildOnMapView = false;
            userZoomAndPanOnMap = false;
            zoomToBoundingBox();
        } else {
            final Dialog exitQuery = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
            exitQuery.requestWindowFeature(Window.FEATURE_NO_TITLE);
            exitQuery.setCancelable(true);
            exitQuery.setContentView(R.layout.exit_app_query);
            ClearTextView cancel = (ClearTextView) exitQuery.findViewById(R.id.cancel);
            cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    exitQuery.cancel();
                }
            });
            ClearTextView exit = (ClearTextView) exitQuery.findViewById(R.id.exit);
            exit.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    exitApplication();
                    startupDone = false;
                    exitQuery.cancel();
                }
            });
            exitQuery.show();
            exitQuery.getWindow().setDimAmount(0.5f);
            exitQuery.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void showSettings() {
    final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    int selfReportIntervalSpinnerPosition = sharedPref.getInt("selfReportIntervalSpinnerPosition", 2);
    int selfReportVarianceSpinnerPosition = sharedPref.getInt("selfReportVarianceSpinnerPosition", 0);
    int questionnaireSpinnerPosition = sharedPref.getInt("questionnaireSpinnerPosition", 0);
    //int baselineQuestionnaireSpinnerPosition = sharedPref.getInt("baselineQuestionnaireSpinnerPosition", 0);
    String activityName = sharedPref.getString("activityName", "");
    String participantFirstName = sharedPref.getString("participantFirstName", "");
    String participantLastName = sharedPref.getString("participantLastName", "");
    boolean configureInterval = sharedPref.getBoolean("configureInterval", false);
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.settings);
    dialog.setTitle(getString(R.string.action_settings));
    dialog.setCancelable(true);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setAttributes(lp);
    selfReportIntervalSpinner = (Spinner) dialog.findViewById(R.id.self_report_interval_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_interval_values, android.R.layout.simple_spinner_item);
    selfReportIntervalSpinner.setAdapter(adapter);
    selfReportIntervalSpinner.setSelection(selfReportIntervalSpinnerPosition);
    selfReportVarianceSpinner = (Spinner) dialog.findViewById(R.id.self_report_variance_spinner);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_variance_values, android.R.layout.simple_spinner_item);
    selfReportVarianceSpinner.setAdapter(adapter2);
    selfReportVarianceSpinner.setSelection(selfReportVarianceSpinnerPosition);

    questionnaireSpinner = (Spinner) dialog.findViewById(R.id.questionnaireSpinner);
    //baselineQuestionnaireSpinner = (Spinner) dialog.findViewById(R.id.baseline_questionnaireSpinner);

    String[] questionnaireTitles = new String[0];
    try {//from   w w w.j av a2 s. c om
        questionnaireTitles = new String[questionnaireCount];
        for (int i = 0; i < questionnaireCount; i++) {
            String questionnaireFilename = questionnaireFilenames[i];
            String questionnairePath = "questionnaires/" + localeString + "/" + questionnaireFilename;
            try {
                JSONObject questionnaire = Utils
                        .getJSONObjectFromInputStream(getAssets().open(questionnairePath));
                String questionnaireTitle = questionnaire.getJSONObject("questionnaire").getString("title");
                questionnaireTitles[i] = questionnaireTitle;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    ArrayAdapter<String> qSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            questionnaireTitles);
    questionnaireSpinner.setAdapter(qSpinnerAdapter);
    questionnaireSpinner.setSelection(questionnaireSpinnerPosition);
    //baselineQuestionnaireSpinner.setAdapter(qSpinnerAdapter);
    //baselineQuestionnaireSpinner.setSelection(baselineQuestionnaireSpinnerPosition);

    final EditText participantFirstNameEditText = (EditText) dialog
            .findViewById(R.id.participant_first_name_edit_text);
    final EditText participantLastNameEditText = (EditText) dialog
            .findViewById(R.id.participant_last_name_edit_text);
    final EditText activityNameEditText = (EditText) dialog.findViewById(R.id.activity_name_edit_text);
    participantFirstNameEditText.setText(participantFirstName);
    participantLastNameEditText.setText(participantLastName);
    activityNameEditText.setText(activityName);

    final Switch configureIntervalSwitch = (Switch) dialog.findViewById(R.id.configure_interval_switch);
    configureIntervalSwitch.setChecked(configureInterval);
    if (configureInterval) {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
    } else {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
    }

    Button saveButton = (Button) dialog.findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selfReportInterval = Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString());
            selfReportVariance = Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString());

            MainActivity.this.participantFirstName = participantFirstNameEditText.getText().toString().trim();
            MainActivity.this.participantLastName = participantLastNameEditText.getText().toString().trim();
            MainActivity.this.activityName = activityNameEditText.getText().toString().trim();
            MainActivity.this.intervalConfigured = configureIntervalSwitch.isChecked();

            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("selfReportIntervalSpinnerPosition",
                    selfReportIntervalSpinner.getSelectedItemPosition());
            editor.putInt("selfReportVarianceSpinnerPosition",
                    selfReportVarianceSpinner.getSelectedItemPosition());
            editor.putInt("questionnaireSpinnerPosition", questionnaireSpinner.getSelectedItemPosition());
            //editor.putInt("baselineQuestionnaireSpinnerPosition", baselineQuestionnaireSpinner.getSelectedItemPosition());
            editor.putInt("selfReportInterval",
                    Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString()));
            editor.putInt("selfReportVariance",
                    Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString()));

            editor.putString("participantFirstName", participantFirstNameEditText.getText().toString().trim());
            editor.putString("participantLastName", participantLastNameEditText.getText().toString().trim());
            editor.putString("activityName", activityNameEditText.getText().toString().trim());
            editor.putBoolean("configureInterval", configureIntervalSwitch.isChecked());
            editor.apply();

            dialog.dismiss();
        }
    });

    configureIntervalSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
            } else {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
            }
        }
    });
    dialog.show();
}

From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java

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

            WebView webView = (WebView) dialog.findViewById(R.id.webViewLicense);
            webView.loadDataWithBaseURL(null, licenseText, Constants.MIME_TYPE, Constants.ENCODING_METHOD,
                    null);

            TextView textViewTitle = (TextView) dialog.findViewById(R.id.textViewDeviceNameTitle);
            textViewTitle.setText(title);

            Button btnAgree = (Button) dialog.findViewById(R.id.dialogButtonOK);
            Button btnCancel = (Button) dialog.findViewById(R.id.dialogButtonCancel);

            btnAgree.setOnClickListener(new OnClickListener() {
                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onClick(View v) {
                    Preference.putBoolean(context, Constants.PreferenceFlag.IS_AGREED, true);
                    dialog.dismiss();
                    //load the next intent based on ownership type
                    startDeviceAdminPrompt();
                }
            });

            btnCancel.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.DEFAULT_REPEAT_COUNT) {
                        return true;
                    } else if (keyCode == KeyEvent.KEYCODE_BACK
                            && event.getRepeatCount() == Constants.DEFAULT_REPEAT_COUNT) {
                        return true;
                    }
                    return false;
                }
            });

            dialog.show();
        }
    });
}

From source file:org.telegram.ui.TwoStepVerificationActivity.java

private void setNewPassword(final boolean clear) {
    final TLRPC.TL_account_updatePasswordSettings req = new TLRPC.TL_account_updatePasswordSettings();
    req.current_password_hash = currentPasswordHash;
    req.new_settings = new TLRPC.TL_account_passwordInputSettings();
    if (clear) {/*from  ww  w  .  j a  va 2s.  com*/
        if (waitingForEmail && currentPassword instanceof TLRPC.TL_account_noPassword) {
            req.new_settings.flags = 2;
            req.new_settings.email = "";
            req.current_password_hash = new byte[0];
        } else {
            req.new_settings.flags = 3;
            req.new_settings.hint = "";
            req.new_settings.new_password_hash = new byte[0];
            req.new_settings.new_salt = new byte[0];
            req.new_settings.email = "";
        }
    } else {
        if (firstPassword != null && firstPassword.length() > 0) {
            byte[] newPasswordBytes = null;
            try {
                newPasswordBytes = firstPassword.getBytes("UTF-8");
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }

            byte[] new_salt = currentPassword.new_salt;
            byte[] hash = new byte[new_salt.length * 2 + newPasswordBytes.length];
            System.arraycopy(new_salt, 0, hash, 0, new_salt.length);
            System.arraycopy(newPasswordBytes, 0, hash, new_salt.length, newPasswordBytes.length);
            System.arraycopy(new_salt, 0, hash, hash.length - new_salt.length, new_salt.length);
            req.new_settings.flags |= 1;
            req.new_settings.hint = hint;
            req.new_settings.new_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
            req.new_settings.new_salt = new_salt;
        }
        if (email.length() > 0) {
            req.new_settings.flags |= 2;
            req.new_settings.email = email;
        }
    }
    needShowProgress();
    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    needHideProgress();
                    if (error == null && response instanceof TLRPC.TL_boolTrue) {
                        if (clear) {
                            currentPassword = null;
                            currentPasswordHash = new byte[0];
                            loadPasswordInfo(false);
                            updateRows();
                        } else {
                            if (getParentActivity() == null) {
                                return;
                            }
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            NotificationCenter.getInstance().postNotificationName(
                                                    NotificationCenter.didSetTwoStepPassword,
                                                    (Object) req.new_settings.new_password_hash);
                                            finishFragment();
                                        }
                                    });
                            builder.setMessage(LocaleController.getString("YourPasswordSuccessText",
                                    R.string.YourPasswordSuccessText));
                            builder.setTitle(LocaleController.getString("YourPasswordSuccess",
                                    R.string.YourPasswordSuccess));
                            Dialog dialog = showDialog(builder.create());
                            if (dialog != null) {
                                dialog.setCanceledOnTouchOutside(false);
                                dialog.setCancelable(false);
                            }
                        }
                    } else if (error != null) {
                        if (error.text.equals("EMAIL_UNCONFIRMED")) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            NotificationCenter.getInstance().postNotificationName(
                                                    NotificationCenter.didSetTwoStepPassword,
                                                    (Object) req.new_settings.new_password_hash);
                                            finishFragment();
                                        }
                                    });
                            builder.setMessage(LocaleController.getString("YourEmailAlmostThereText",
                                    R.string.YourEmailAlmostThereText));
                            builder.setTitle(LocaleController.getString("YourEmailAlmostThere",
                                    R.string.YourEmailAlmostThere));
                            Dialog dialog = showDialog(builder.create());
                            if (dialog != null) {
                                dialog.setCanceledOnTouchOutside(false);
                                dialog.setCancelable(false);
                            }
                        } else {
                            if (error.text.equals("EMAIL_INVALID")) {
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                        LocaleController.getString("PasswordEmailInvalid",
                                                R.string.PasswordEmailInvalid));
                            } else if (error.text.startsWith("FLOOD_WAIT")) {
                                int time = Utilities.parseInt(error.text);
                                String timeString;
                                if (time < 60) {
                                    timeString = LocaleController.formatPluralString("Seconds", time);
                                } else {
                                    timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                }
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                        LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime,
                                                timeString));
                            } else {
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                        error.text);
                            }
                        }
                    }
                }
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
}

From source file:net.momodalo.app.vimtouch.VimTouch.java

public void showCmdHistory() {

    final Dialog dialog = new Dialog(this, R.style.DialogSlideAnim);

    // Setting dialogview
    Window window = dialog.getWindow();
    window.setGravity(Gravity.BOTTOM);//w w w .j av  a 2s .c o  m

    window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    dialog.setTitle(null);
    dialog.setContentView(R.layout.hist_list);
    dialog.setCancelable(true);

    LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.hist_layout);
    if (AndroidCompat.SDK >= 11) {
        layout.setShowDividers(LinearLayout.SHOW_DIVIDER_BEGINNING | LinearLayout.SHOW_DIVIDER_MIDDLE
                | LinearLayout.SHOW_DIVIDER_END);
    }
    LayoutParams params = layout.getLayoutParams();
    params.width = mScreenWidth;
    layout.setLayoutParams(params);

    LayoutInflater inflater = LayoutInflater.from(this);
    boolean exists = false;

    for (int i = 1; i <= 10; i++) {
        TextView button = (TextView) inflater.inflate(R.layout.histbutton, layout, false);
        String cmd = Exec.getCmdHistory(i);
        if (cmd.length() == 0)
            break;
        exists = true;
        button.setText(":" + cmd);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                TextView text = (TextView) v;
                CharSequence cmd = text.getText();
                Exec.doCommand(cmd.subSequence(1, cmd.length()).toString());
                dialog.dismiss();
            }
        });
        layout.addView((View) button);
    }

    if (exists)
        dialog.show();
}

From source file:org.telegram.ui.TwoStepVerificationActivity.java

private void processDone() {
    if (type == 0) {
        if (!passwordEntered) {
            String oldPassword = passwordEditText.getText().toString();
            if (oldPassword.length() == 0) {
                onPasscodeError(false);/* w ww.ja  v a2s .  c om*/
                return;
            }
            byte[] oldPasswordBytes = null;
            try {
                oldPasswordBytes = oldPassword.getBytes("UTF-8");
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }

            needShowProgress();
            byte[] hash = new byte[currentPassword.current_salt.length * 2 + oldPasswordBytes.length];
            System.arraycopy(currentPassword.current_salt, 0, hash, 0, currentPassword.current_salt.length);
            System.arraycopy(oldPasswordBytes, 0, hash, currentPassword.current_salt.length,
                    oldPasswordBytes.length);
            System.arraycopy(currentPassword.current_salt, 0, hash,
                    hash.length - currentPassword.current_salt.length, currentPassword.current_salt.length);

            final TLRPC.TL_account_getPasswordSettings req = new TLRPC.TL_account_getPasswordSettings();
            req.current_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
            ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                @Override
                public void run(final TLObject response, final TLRPC.TL_error error) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            needHideProgress();
                            if (error == null) {
                                currentPasswordHash = req.current_password_hash;
                                passwordEntered = true;
                                AndroidUtilities.hideKeyboard(passwordEditText);
                                updateRows();
                            } else {
                                if (error.text.equals("PASSWORD_HASH_INVALID")) {
                                    onPasscodeError(true);
                                } else if (error.text.startsWith("FLOOD_WAIT")) {
                                    int time = Utilities.parseInt(error.text);
                                    String timeString;
                                    if (time < 60) {
                                        timeString = LocaleController.formatPluralString("Seconds", time);
                                    } else {
                                        timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                    }
                                    showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                            LocaleController.formatString("FloodWaitTime",
                                                    R.string.FloodWaitTime, timeString));
                                } else {
                                    showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                            error.text);
                                }
                            }
                        }
                    });
                }
            }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
        }
    } else if (type == 1) {
        if (passwordSetState == 0) {
            if (passwordEditText.getText().length() == 0) {
                onPasscodeError(false);
                return;
            }
            titleTextView
                    .setText(LocaleController.getString("ReEnterYourPasscode", R.string.ReEnterYourPasscode));
            firstPassword = passwordEditText.getText().toString();
            setPasswordSetState(1);
        } else if (passwordSetState == 1) {
            if (!firstPassword.equals(passwordEditText.getText().toString())) {
                try {
                    Toast.makeText(getParentActivity(),
                            LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch),
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                onPasscodeError(true);
                return;
            }
            setPasswordSetState(2);
        } else if (passwordSetState == 2) {
            hint = passwordEditText.getText().toString();
            if (hint.toLowerCase().equals(firstPassword.toLowerCase())) {
                try {
                    Toast.makeText(getParentActivity(),
                            LocaleController.getString("PasswordAsHintError", R.string.PasswordAsHintError),
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                onPasscodeError(false);
                return;
            }
            if (!currentPassword.has_recovery) {
                setPasswordSetState(3);
            } else {
                email = "";
                setNewPassword(false);
            }
        } else if (passwordSetState == 3) {
            email = passwordEditText.getText().toString();
            if (!isValidEmail(email)) {
                onPasscodeError(false);
                return;
            }
            setNewPassword(false);
        } else if (passwordSetState == 4) {
            String code = passwordEditText.getText().toString();
            if (code.length() == 0) {
                onPasscodeError(false);
                return;
            }
            TLRPC.TL_auth_recoverPassword req = new TLRPC.TL_auth_recoverPassword();
            req.code = code;
            ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                @Override
                public void run(TLObject response, final TLRPC.TL_error error) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (error == null) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                NotificationCenter.getInstance().postNotificationName(
                                                        NotificationCenter.didSetTwoStepPassword);
                                                finishFragment();
                                            }
                                        });
                                builder.setMessage(
                                        LocaleController.getString("PasswordReset", R.string.PasswordReset));
                                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                Dialog dialog = showDialog(builder.create());
                                if (dialog != null) {
                                    dialog.setCanceledOnTouchOutside(false);
                                    dialog.setCancelable(false);
                                }
                            } else {
                                if (error.text.startsWith("CODE_INVALID")) {
                                    onPasscodeError(true);
                                } else if (error.text.startsWith("FLOOD_WAIT")) {
                                    int time = Utilities.parseInt(error.text);
                                    String timeString;
                                    if (time < 60) {
                                        timeString = LocaleController.formatPluralString("Seconds", time);
                                    } else {
                                        timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                    }
                                    showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                            LocaleController.formatString("FloodWaitTime",
                                                    R.string.FloodWaitTime, timeString));
                                } else {
                                    showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                            error.text);
                                }
                            }
                        }
                    });
                }
            }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
        }
    }
}