Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:org.apache.cordova.core.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//  w  w  w  .jav  a  2s.  co  m
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", EXIT_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setText("<");
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setText(">");
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setText(buttonLabel);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Create a alert dialog for entering Destination values 
 * //from w  w  w.ja v  a2s.  c o  m
 */
private void showDestinationAlert(final String dlocation, final String dreason) {
    final EditText enterLocation = new EditText(this);
    final EditText enterReason = new EditText(this);

    if (!dlocation.equals("")) {
        enterLocation.setText(dlocation);
    }
    if (!dreason.equals("")) {
        enterReason.setText(dreason);
    }
    enterLocation.setHint("Enter location");
    enterReason.setHint("Enter reason");

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(enterLocation);
    linearLayout.addView(enterReason);

    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setView(linearLayout);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Destination dest = new Destination(enterLocation.getText().toString(),
                    enterReason.getText().toString());
            ClaimListController.addDestination(dest, theClaim);

            //open Map activity and make user pick a geolocation
            Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this);
            startActivityForResult(intent, GET_GEOLOCATION_CODE);

            destAdaptor.notifyDataSetChanged();

        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    alert.show();
}

From source file:edu.oakland.festinfo.activities.MapPageActivity.java

@AfterViews
void init() {//from   www. ja v  a2s . c  om
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Map");
    colorUpArrow();

    mapKeySpinner = (Spinner) findViewById(R.id.mapkey_spinner);
    mapKeySpinner.setAdapter(new MyAdapter(MapPageActivity.this, R.layout.row, strings));
    ParseInstallation.getCurrentInstallation().saveInBackground();
    FragmentManager fragmentManager = getFragmentManager();
    mapFragment = (MapFragment) fragmentManager.findFragmentById(R.id.map);
    map = mapFragment.getMap();

    map.setMyLocationEnabled(true);

    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    map.setOnMapClickListener(this);
    map.setOnMapLongClickListener(this);
    map.setOnMarkerDragListener(this);
    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(final Marker marker) {
            //tvLocInfo.setText("Info Window Selected");
            if (marker.getTitle().equals("Ranch Area") || marker.getTitle().equals("Sherwood Court")
                    || marker.getTitle().equals("Tripolee") || marker.getTitle().equals("The Observatory")
                    || marker.getTitle().equals("The Hangar") || marker.getTitle().equals("Jubilee")
                    || marker.getTitle().equals("Forest Stage")) {
                AlertDialog.Builder infowindowBuilderGeofence = new AlertDialog.Builder(MapPageActivity.this);
                infowindowBuilderGeofence.setTitle(R.string.infowindow_geofence_click_options).setItems(
                        R.array.infowindow_geofence_choices_array, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                switch (which) {

                                case 0:
                                    //tvLocInfo.setText("Favorite Stage Selected");
                                    ParseInstallation installationFavorite = ParseInstallation
                                            .getCurrentInstallation();
                                    ParsePush push = new ParsePush();
                                    if (marker.getTitle().equals("Ranch Area")) {
                                        installationFavorite.put("RanchAreaFavorited", true);
                                        push.subscribeInBackground("RanchArea");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Sherwood Court")) {
                                        installationFavorite.put("SherwoodCourtFavorited", true);
                                        push.subscribeInBackground("SherwoodCourt");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Tripolee")) {
                                        installationFavorite.put("TripoleeFavorited", true);
                                        push.subscribeInBackground("Tripolee");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("The Hangar")) {
                                        installationFavorite.put("TheHangarFavorited", true);
                                        push.subscribeInBackground("TheHanagar");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Jubilee")) {
                                        installationFavorite.put("JubileeFavorited", true);
                                        push.subscribeInBackground("Jubilee");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Forest Stage")) {
                                        installationFavorite.put("ForestStageFavorited", true);
                                        push.subscribeInBackground("ForestStage");
                                        installationFavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("The Observatory")) {
                                        installationFavorite.put("TheObservatoryFavorited", true);
                                        push.subscribeInBackground("TheObservatory");
                                        installationFavorite.saveInBackground();
                                    }
                                    break;

                                case 1:
                                    //tvLocInfo.setText("Unfavorite Stage Selected");
                                    ParseInstallation installationUnfavorite = ParseInstallation
                                            .getCurrentInstallation();
                                    ParsePush pushRemove = new ParsePush();
                                    if (marker.getTitle().equals("Ranch Area")) {
                                        installationUnfavorite.put("RanchAreaFavorited", false);
                                        pushRemove.unsubscribeInBackground("RanchArea");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Sherwood Court")) {
                                        installationUnfavorite.put("SherwoodCourtFavorited", false);
                                        pushRemove.unsubscribeInBackground("SherwoodCourt");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Tripolee")) {
                                        installationUnfavorite.put("TripoleeFavorited", false);
                                        pushRemove.unsubscribeInBackground("Tripolee");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("The Hangar")) {
                                        installationUnfavorite.put("TheHangar", false);
                                        pushRemove.unsubscribeInBackground("TheHanagar");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Jubilee")) {
                                        installationUnfavorite.put("JubileeFavorited", false);
                                        pushRemove.unsubscribeInBackground("Jubilee");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("Forest Stage")) {
                                        installationUnfavorite.put("ForestStageFavorited", false);
                                        pushRemove.unsubscribeInBackground("ForestStage");
                                        installationUnfavorite.saveInBackground();
                                    } else if (marker.getTitle().equals("The Observatory")) {
                                        installationUnfavorite.put("TheObservatoryFavorited", false);
                                        pushRemove.unsubscribeInBackground("TheObservatory");
                                        installationUnfavorite.saveInBackground();
                                    }
                                    break;

                                }
                            }

                        }

                );
                infowindowBuilderGeofence.show();
            } else {
                AlertDialog.Builder infowindowBuilderNoGeofence = new AlertDialog.Builder(MapPageActivity.this);
                infowindowBuilderNoGeofence.setTitle(R.string.infowindow_nogeofence_click_options).setItems(
                        R.array.infowindow_nogeofence_choices_array, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                switch (which) {
                                case 0:
                                    AlertDialog.Builder deleteConfirmation = new AlertDialog.Builder(
                                            MapPageActivity.this);
                                    deleteConfirmation.setTitle("Warning");
                                    deleteConfirmation
                                            .setMessage("Are you sure you want to delete this marker?");
                                    deleteConfirmation.setPositiveButton("Yes",
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    ParseGeoPoint geoPoint = new ParseGeoPoint(
                                                            marker.getPosition().latitude,
                                                            marker.getPosition().longitude);
                                                    currentMarkerTitle = marker.getTitle();

                                                    ParseQuery<ParseObject> query = ParseQuery
                                                            .getQuery("MapMarkers");
                                                    query.whereEqualTo("Title", currentMarkerTitle);
                                                    query.getFirstInBackground(new GetCallback<ParseObject>() {
                                                        @Override
                                                        public void done(ParseObject object, ParseException e) {

                                                            try {
                                                                for (int i = 0; i < combinedArray.size(); i++) {
                                                                    if (combinedArray.get(i).getIdentification()
                                                                            .equals(object
                                                                                    .getString("GeofenceID"))) {
                                                                        combinedArray.get(i).getCircle()
                                                                                .setRadius(0);
                                                                        combinedArray.get(i).getCircle()
                                                                                .remove();
                                                                        combinedArray.get(i).getMarker()
                                                                                .remove();
                                                                        combinedArray.remove(i);
                                                                        object.delete();
                                                                    }

                                                                }
                                                            } catch (ParseException e1) {
                                                                e1.printStackTrace();
                                                            }
                                                            object.saveInBackground();

                                                        }
                                                    });
                                                }
                                            });
                                    deleteConfirmation.setNegativeButton("Cancel",
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.cancel();
                                                }
                                            });
                                    deleteConfirmation.show();
                                    break;

                                case 1:
                                    //tvLocInfo.setText("Change title selected");
                                    AlertDialog.Builder changeTitleInput = new AlertDialog.Builder(
                                            MapPageActivity.this);
                                    changeTitleInput.setTitle("Enter new Title: ");
                                    final EditText changeInput = new EditText(MapPageActivity.this);
                                    changeInput.setInputType(InputType.TYPE_CLASS_TEXT);
                                    changeTitleInput.setView(changeInput);
                                    changeTitleInput.setPositiveButton("Ok",
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (changeInput.getText().toString().matches("")) {
                                                        Toast.makeText(getApplicationContext(),
                                                                "No Input Entered!", Toast.LENGTH_SHORT).show();
                                                    } else {
                                                        ParseQuery<ParseObject> query = ParseQuery
                                                                .getQuery("MapMarkers");
                                                        query.findInBackground(new FindCallback<ParseObject>() {
                                                            @Override
                                                            public void done(List<ParseObject> objects,
                                                                    ParseException e) {
                                                                if (e == null) {
                                                                    for (int i = 0; i < objects.size(); i++) {
                                                                        if (objects.get(i).getString("Title")
                                                                                .equals(marker.getTitle())) {
                                                                            objects.get(i)
                                                                                    .put("Title", changeInput
                                                                                            .getText()
                                                                                            .toString());
                                                                            objects.get(i).saveInBackground();
                                                                        }
                                                                    }
                                                                } else {
                                                                    Toast.makeText(getApplicationContext(),
                                                                            "Error!", Toast.LENGTH_SHORT)
                                                                            .show();
                                                                }
                                                            }
                                                        });
                                                        for (int i = 0; i < combinedArray.size(); i++) {
                                                            if (combinedArray.get(i).getIdentification()
                                                                    .equals(marker.getId())) {
                                                                combinedArray.get(i).getMarker().setTitle(
                                                                        changeInput.getText().toString());
                                                            }
                                                        }

                                                    }
                                                }
                                            });
                                    changeTitleInput.setNegativeButton("Cancel",
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.cancel();
                                                }
                                            });
                                    changeTitleInput.show();
                                    break;

                                }
                            }

                        }

                );
                infowindowBuilderNoGeofence.show();
            }
        }
    });

    focusCamera();
    buildGoogleApiClient();
}

From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from   www . j a  va2s  .c o  m
    switch (id) {
    case DIALOG_ID_NO_WORDS: {
        final DialogNoWordsListener DIALOG_LISTENER_NO_WORDS = new DialogNoWordsListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.no_words);
        builder.setNegativeButton(R.string.category, DIALOG_LISTENER_NO_WORDS);
        builder.setPositiveButton(R.string.new_game, DIALOG_LISTENER_NO_WORDS);
        builder.setNeutralButton(R.string.size, DIALOG_LISTENER_NO_WORDS);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_NO_WORDS_CUSTOM: {
        final DialogNoWordsCustomListener DIALOG_LISTENER_NO_WORDS_CUSTOM = new DialogNoWordsCustomListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.no_words_custom);
        builder.setNegativeButton(R.string.category, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        builder.setPositiveButton(R.string.custom_editor, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_OVER: {
        final DialogGameOverListener DIALOG_LISTENER_GAME_OVER = new DialogGameOverListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        EditText text = new EditText(this);
        text.setSingleLine();
        text.setId(android.R.id.input);
        builder.setView(text);
        builder.setPositiveButton(R.string.SAVE_SUBMIT, DIALOG_LISTENER_GAME_OVER);
        builder.setNeutralButton(R.string.SAVE, DIALOG_LISTENER_GAME_OVER);
        builder.setOnCancelListener(DIALOG_LISTENER_GAME_OVER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_HIGH_SCORES_LOCAL_SHOW: {
        final DialogHighScoresLocalShowListener DIALOG_LISTENER_HIGH_SCORES_SHOW = new DialogHighScoresLocalShowListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        builder.setTitle(R.string.LOCAL_HIGH_SCORES);
        builder.setNegativeButton(R.string.reset, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setNeutralButton(android.R.string.ok, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setPositiveButton(R.string.GLOBAL, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_NEW: {
        final DialogGameNewListener DIALOG_LISTENER_GAME_NEW = new DialogGameNewListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(this.getString(R.string.game_over));
        builder.setPositiveButton(R.string.new_game, DIALOG_LISTENER_GAME_NEW);
        builder.setNeutralButton(R.string.REPLAY, DIALOG_LISTENER_GAME_NEW);
        builder.setNegativeButton(android.R.string.cancel, DIALOG_LISTENER_GAME_NEW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_INPUT_TYPE: {
        final DialogIntroListener DIALOG_LISTENER_INTRO = new DialogIntroListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.INTRO);
        builder.setPositiveButton(R.string.tap, DIALOG_LISTENER_INTRO);
        builder.setNeutralButton(android.R.string.cancel, DIALOG_LISTENER_INTRO);
        builder.setNegativeButton(R.string.drag, DIALOG_LISTENER_INTRO);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogIntroDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.INTRO_DONATE_MSG);
        builder.setPositiveButton(R.string.DONATE, LISTENER);
        builder.setNegativeButton(R.string.DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.DONATE_MSG);
        builder.setPositiveButton(R.string.DONATE_MARKET, LISTENER);
        builder.setNeutralButton(R.string.DONATE_WEB, LISTENER);
        builder.setNegativeButton(R.string.DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    default:
        dialog = super.onCreateDialog(id);
        break;
    }
    return dialog;
}

From source file:io.v.moments.ux.MainActivity.java

@Override
public void onSensorChanged(SensorEvent event) {
    float gX = event.values[0] / SensorManager.GRAVITY_EARTH;
    float gY = event.values[1] / SensorManager.GRAVITY_EARTH;
    float gZ = event.values[2] / SensorManager.GRAVITY_EARTH;
    double gForce = Math.sqrt(gX * gX + gY * gY + gZ * gZ);
    if (gForce < SHAKE_THRESHOLD) {
        return;//from   www. java 2s  .  c  o  m
    }
    final long now = System.currentTimeMillis();
    if (now - mShakeTimestamp < SHAKE_EVENT_MS) {
        return;
    }
    mShakeTimestamp = now;

    final EditText invitee = new EditText(this);
    invitee.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

    AlertDialog.Builder builder = new AlertDialog.Builder(this)
            .setTitle(getString(R.string.invite_remote_inspector)).setView(invitee)
            .setPositiveButton(getString(R.string.invite_remote_inspector_positive_button),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            String to = invitee.getText().toString();
                            intent.setType("message/rfc822");
                            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
                            intent.putExtra(Intent.EXTRA_SUBJECT, "Please help me debug");
                            try {
                                intent.putExtra(Intent.EXTRA_TEXT,
                                        mV23Manager.inviteInspector(to, Duration.standardDays(1)));
                                mRemoteInspectionEnabled = true;
                            } catch (Exception e) {
                                toast(e.toString());
                                return;
                            }
                            if (intent.resolveActivity(getPackageManager()) != null) {
                                startActivity(intent);
                            } else {
                                toast(getString(R.string.invite_remote_inspector_failed));
                            }
                        }
                    })
            .setNegativeButton(getString(R.string.invite_remote_inspector_negative_button),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
    if (mRemoteInspectionEnabled) {
        builder.setNeutralButton(getString(R.string.invite_remote_inspector_neutral_button),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // This doesn't take effect till the next time the activity is created
                        // (invited users will still be able to connect till then).
                        mRemoteInspectionEnabled = false;
                    }
                });
    }
    builder.show();
}

From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from w  ww .  ja  v a 2 s .  c  o m
    switch (id) {
    case DIALOG_ID_NO_WORDS: {
        final DialogNoWordsListener DIALOG_LISTENER_NO_WORDS = new DialogNoWordsListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_no_words);
        builder.setNegativeButton(R.string.ws_category, DIALOG_LISTENER_NO_WORDS);
        builder.setPositiveButton(R.string.ws_new_game, DIALOG_LISTENER_NO_WORDS);
        builder.setNeutralButton(R.string.ws_size, DIALOG_LISTENER_NO_WORDS);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_NO_WORDS_CUSTOM: {
        final DialogNoWordsCustomListener DIALOG_LISTENER_NO_WORDS_CUSTOM = new DialogNoWordsCustomListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_no_words_custom);
        builder.setNegativeButton(R.string.ws_category, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        builder.setPositiveButton(R.string.ws_custom_editor, DIALOG_LISTENER_NO_WORDS_CUSTOM);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_OVER: {
        final DialogGameOverListener DIALOG_LISTENER_GAME_OVER = new DialogGameOverListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        EditText text = new EditText(this);
        text.setSingleLine();
        text.setId(android.R.id.input);
        builder.setView(text);
        builder.setPositiveButton(R.string.ws_SAVE_SUBMIT, DIALOG_LISTENER_GAME_OVER);
        builder.setNeutralButton(R.string.ws_SAVE, DIALOG_LISTENER_GAME_OVER);
        builder.setOnCancelListener(DIALOG_LISTENER_GAME_OVER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_HIGH_SCORES_LOCAL_SHOW: {
        final DialogHighScoresLocalShowListener DIALOG_LISTENER_HIGH_SCORES_SHOW = new DialogHighScoresLocalShowListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("blank");
        builder.setTitle(R.string.ws_LOCAL_HIGH_SCORES);
        builder.setNegativeButton(R.string.ws_reset, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setNeutralButton(android.R.string.ok, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        builder.setPositiveButton(R.string.ws_GLOBAL, DIALOG_LISTENER_HIGH_SCORES_SHOW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_GAME_NEW: {
        final DialogGameNewListener DIALOG_LISTENER_GAME_NEW = new DialogGameNewListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(this.getString(R.string.ws_game_over));
        builder.setPositiveButton(R.string.ws_new_game, DIALOG_LISTENER_GAME_NEW);
        builder.setNeutralButton(R.string.ws_REPLAY, DIALOG_LISTENER_GAME_NEW);
        builder.setNegativeButton(android.R.string.cancel, DIALOG_LISTENER_GAME_NEW);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_INPUT_TYPE: {
        final DialogIntroListener DIALOG_LISTENER_INTRO = new DialogIntroListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_INTRO);
        builder.setPositiveButton(R.string.ws_tap, DIALOG_LISTENER_INTRO);
        builder.setNeutralButton(android.R.string.cancel, DIALOG_LISTENER_INTRO);
        builder.setNegativeButton(R.string.ws_drag, DIALOG_LISTENER_INTRO);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_INTRO_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogIntroDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_INTRO_DONATE_MSG);
        builder.setPositiveButton(R.string.ws_DONATE, LISTENER);
        builder.setNegativeButton(R.string.ws_DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    case DIALOG_ID_DONATE: {
        final DialogInterface.OnClickListener LISTENER = new DialogDonateListener();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ws_DONATE_MSG);
        builder.setPositiveButton(R.string.ws_DONATE_MARKET, LISTENER);
        builder.setNeutralButton(R.string.ws_DONATE_WEB, LISTENER);
        builder.setNegativeButton(R.string.ws_DONATE_NO, LISTENER);
        dialog = builder.create();
        break;
    }
    default:
        dialog = super.onCreateDialog(id);
        break;
    }
    return dialog;
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showSendMoneyPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    final String message = "Send Money to Friend In A Flash";
    String positiveButtonText = "Send";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelMobileNo = new TextView(getActivity());
    final EditText editMobileNo = new EditText(getActivity());
    final TextView labelMessage = new TextView(getActivity());
    final EditText editMessage = new EditText(getActivity());
    editAmount.setSingleLine(true);/*from  w  w  w.j  av  a  2s. c  o  m*/
    editMobileNo.setSingleLine(true);
    editMessage.setSingleLine(true);

    labelAmount.setText("Amount");
    labelMobileNo.setText("Enter Mobile No of Friend");
    labelMessage.setText("Enter Message (Optional)");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelMobileNo.setLayoutParams(layoutParams);
    labelMessage.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editMobileNo.setLayoutParams(layoutParams);
    editMessage.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelMobileNo);
    linearLayout.addView(editMobileNo);
    linearLayout.addView(labelMessage);
    linearLayout.addView(editMessage);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editMobileNo.setInputType(InputType.TYPE_CLASS_NUMBER);
    alert.setTitle("Send Money In A Flash");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String mobileNo = editMobileNo.getText().toString();
            String message = editMessage.getText().toString();

            mCitrusClient.sendMoneyToMoblieNo(new Amount(amount), mobileNo, message,
                    new Callback<PaymentResponse>() {
                        @Override
                        public void success(PaymentResponse paymentResponse) {
                            //                        Utils.showToast(getActivity(), paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL ? "Sent Money Successfully." : "Failed To Send the Money");
                            ((UIActivity) getActivity()).showSnackBar(
                                    paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL
                                            ? "Sent Money Successfully."
                                            : "Failed To Send the Money");
                        }

                        @Override
                        public void error(CitrusError error) {
                            //                        Utils.showToast(getActivity(), error.getMessage());
                            ((UIActivity) getActivity()).showSnackBar(error.getMessage());
                        }
                    });
            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}

From source file:org.apache.cordova.plugins.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//from ww w .  jav  a2s .  com
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", EXIT_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setText("<");
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setText(">");
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setText(buttonLabel);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            /*cemerson*/ if (arrowButtonsAllowed) {
                actionButtonContainer.addView(back);
                actionButtonContainer.addView(forward);
            }

            // ================================================
            // CHANGING per:
            // http://stackoverflow.com/a/16596554/826308

            // *** ORIG CODE ***
            // // Add the views to our toolbar
            // toolbar.addView(actionButtonContainer);
            // toolbar.addView(edittext);
            // toolbar.addView(close);

            // // Don't add the toolbar if its been disabled
            // if (getShowLocationBar()) {
            //     // Add our toolbar to our main view/layout
            //     main.addView(toolbar);
            // }

            // *** CHANGED CODE ***
            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            if (getShowLocationBar()) {
                toolbar.addView(edittext);
            }
            toolbar.addView(close);

            // Add our toolbar to our main view/layout
            main.addView(toolbar);
            // ================================================

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.fastbootmobile.encore.app.fragments.PlaylistViewFragment.java

private void renamePlaylistDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

    // Set an EditText view to get user input
    final EditText input = new EditText(getActivity());
    input.setText(mPlaylist.getName());//from ww w  . ja v a2  s.  com
    alert.setView(input);

    alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();
            ProviderConnection conn = PluginsLookup.getDefault().getProvider(mPlaylist.getProvider());
            if (conn != null) {
                IMusicProvider provider = conn.getBinder();
                if (provider != null) {
                    try {
                        provider.renamePlaylist(mPlaylist.getRef(), value);
                    } catch (RemoteException e) {
                        Log.e(TAG, "Cannot rename playlist", e);
                    } catch (Exception e) {
                        Sentry.captureException(new Exception("Rename playlist: Plugin error", e));
                    }
                }
            }
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

    alert.show();
}