List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.krayzk9s.imgurholo.ui.MessagingFragment.java
private void buildSendMessage(String username) { ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final EditText newUsername = new EditText(activity); newUsername.setSingleLine();/* w w w . ja va 2s .c o m*/ newUsername.setHint(R.string.body_hint_recipient); if (username != null) newUsername.setText(username); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(5); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newUsername); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_send_message_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { MessagingAsync messagingAsync = new MessagingAsync(newBody.getText().toString(), newUsername.getText().toString()); messagingAsync.execute(); } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); }
From source file:org.codecyprus.android_client.ui.ActivityStartQuiz.java
private void enterCode() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.Enter_code); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input);//from w ww. j a va 2 s.c om alert.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { code = input.getText().toString(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); }
From source file:mobi.monaca.framework.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w w w . j a va 2 s.co m*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // 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", CLOSE_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.FILL_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 ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setImageResource(R.drawable.childbroswer_icon_arrow_left); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setImageResource(R.drawable.childbroswer_icon_arrow_right); 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.FILL_PARENT, LayoutParams.FILL_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 ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); close.setImageResource(R.drawable.childbroswer_icon_close); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.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(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { //TODO check LocalFileBootloader InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.ichi2.anki.ModelFieldEditor.java
private void renameFieldDialog() { mFieldNameInput = new EditText(this); mFieldNameInput.setSingleLine(true); mFieldNameInput.setText(mFieldLabels.get(mCurrentPos)); mFieldNameInput.setSelection(mFieldNameInput.getText().length()); new MaterialDialog.Builder(this).title(R.string.rename_model).positiveText(R.string.dialog_ok) .customView(mFieldNameInput, true).callback(new MaterialDialog.ButtonCallback() { @Override/*from ww w .ja v a 2 s .c o m*/ public void onPositive(MaterialDialog dialog) { String fieldLabel = mFieldNameInput.getText().toString() .replaceAll("[\'\"\\n\\r\\[\\]\\(\\)]", ""); if (fieldLabel.length() == 0) { showToast(getResources().getString(R.string.toast_empty_name)); } else if (containsField(fieldLabel)) { showToast(getResources().getString(R.string.toast_duplicate_field)); } else { //Field is valid, now rename try { renameField(); } catch (ConfirmModSchemaException e) { // Handler mod schema confirmation ConfirmationDialog c = new ConfirmationDialog() { public void confirm() { try { mCol.modSchema(false); renameField(); } catch (ConfirmModSchemaException e) { //This should never be thrown } dismissContextMenu(); } public void cancel() { dismissContextMenu(); } }; c.setArgs(getResources().getString(R.string.full_sync_confirmation)); ModelFieldEditor.this.showDialogFragment(c); } } } }).negativeText(R.string.dialog_cancel).show(); }
From source file:com.lge.helloFriendsCamera.ConnectionActivity.java
/** * Show dialog with EditText to input wifi password *//*from w w w. ja v a 2s.c o m*/ private void showWifiDialog() { AlertDialog.Builder alert = new AlertDialog.Builder(mContext); alert.setTitle(getSsid(selectedDevice)); alert.setMessage("password"); final EditText input = new EditText(mContext); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mProgressDialog = ProgressDialog.show(mContext, "", "Connecting...", true, false); String passwd = input.getText().toString(); mConnectionManager.connect(getSsid(selectedDevice), passwd); } }); alert.show(); }
From source file:org.apache.cordova.dialogs.Notification.java
/** * Builds and shows a native Android prompt dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The following results are returned to the JavaScript callback identified by callbackId: * buttonIndex Index number of the button selected * input1 The text entered in the prompt dialog box * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. */// ww w . ja va2 s . co m public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { final EditText promptInput = new EditText(cordova.getActivity()); promptInput.setHint(defaultText); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); dlg.setView(promptInput); final JSONObject result = new JSONObject(); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 2); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:ca.ualberta.cs.drivr.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); userManager.setConnectivityManager((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)); /**//from ww w.j ava 2s . co m * This calls the login activity a the beginning if there is no local user stored */ if (userManager.getUser().getUsername().isEmpty()) { Intent intent = new Intent(MainActivity.this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); context = getApplicationContext(); PreferenceManager.setDefaultValues(this, R.xml.pref_driver_mode, false); setSupportActionBar(toolbar); // Create an instance of GoogleAPIClient. if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } mFragment = (SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.main_map); mFragment.getMapAsync(this); autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager() .findFragmentById(R.id.place_autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { ConcretePlace concretePlace = new ConcretePlace(place); Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create(); if (userManager.getUserMode().equals(UserMode.RIDER)) { Intent intent = new Intent(MainActivity.this, NewRequestActivity.class); String concretePlaceJson = gson.toJson(concretePlace); intent.putExtra(NewRequestActivity.EXTRA_PLACE, concretePlaceJson); Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng()); startActivity(intent); } else if (userManager.getUserMode().equals(UserMode.DRIVER)) { Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class); String concretePlaceJson = gson.toJson(concretePlace); intent.putExtra(SearchRequestActivity.EXTRA_PLACE, concretePlaceJson); intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, ""); Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng()); startActivity(intent); } } @Override public void onError(Status status) { // Do nothing } }); // Using the floating action button menu system final FloatingActionMenu fabMenu = (FloatingActionMenu) findViewById(R.id.main_fab_menu); FloatingActionButton fabSettings = (FloatingActionButton) findViewById(R.id.fabSettings); FloatingActionButton fabRequests = (FloatingActionButton) findViewById(R.id.main_fab_requests); FloatingActionButton fabProfile = (FloatingActionButton) findViewById(R.id.main_fab_profile); FloatingActionButton fabHistory = (FloatingActionButton) findViewById(R.id.main_fah_history); FloatingActionButton fabLogin = (FloatingActionButton) findViewById(R.id.main_fab_login); final FloatingActionButton fabDriver = (FloatingActionButton) findViewById(R.id.main_driver_mode); final FloatingActionButton fabRider = (FloatingActionButton) findViewById(R.id.main_rider_mode); // Hide the settings FAB fabSettings.setVisibility(View.GONE); /* Change between user and driver mode. Will probably be replaced with an option in settings. For now the visibility of this is set to gone because we should not have too many FABs. Having too many FABs may cause confusion and rendering issues on small screens. */ keywordEditText = (EditText) findViewById(R.id.main_keyword_edit_text); FloatingActionButton fabMode = (FloatingActionButton) findViewById(R.id.main_fab_mode); fabMode.setVisibility(View.GONE); if (userManager.getUserMode().equals(UserMode.RIDER)) { fabRider.setVisibility(View.GONE); keywordEditText.setVisibility(View.GONE); } else { fabDriver.setVisibility(View.GONE); keywordEditText.setVisibility(View.VISIBLE); } keywordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class); intent.putExtra(SearchRequestActivity.EXTRA_PLACE, ""); intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, keywordEditText.getText().toString()); keywordEditText.setText(""); keywordEditText.clearFocus(); startActivity(intent); } return true; } }); fabMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked mode fab"); /* Will be able to implement code below once elasticSearch is up and running UserManager userManager = null; // Once elasticSearch is working will replace with finding a User if (userManager.getUserMode() == UserMode.DRIVER) { userManager.setUserMode(UserMode.RIDER); } else if (userManager.getUserMode() == UserMode.RIDER) { userManager.setUserMode(UserMode.DRIVER); //Will have to implement a method "FindNearbyRequests" to get requests whose source // is nearby and display it on the map //Intent intent = new Intent((MainActivity.this, FindNearbyRequests.class);) //startActivity(intent); }*/ } }); fabDriver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (userManager.getUser().getVehicleDescription().isEmpty()) { /* * From: http://stackoverflow.com/a/29048271 * Author: Syeda Zunairah * Accessed: November 29, 2016 * Creates a dialog box with an edit text to get the vehicle description. */ AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext()); final EditText edittext = new EditText(v.getContext()); edittext.setText("Vechicle Make"); edittext.clearComposingText(); alert.setTitle("Become a Driver!"); alert.setMessage( "Drivers are require to enter vehicle information!\n\nPlease enter your vehicle's make"); alert.setView(edittext); alert.setPositiveButton("Save Description", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String vehicleDescription = edittext.getText().toString(); if (!vehicleDescription.isEmpty()) { userManager.getUser().setVehicleDescription(vehicleDescription); userManager.notifyObservers(); userManager.setUserMode(UserMode.DRIVER); ElasticSearch elasticSearch = new ElasticSearch( userManager.getConnectivityManager()); elasticSearch.updateUser(userManager.getUser()); keywordEditText.setVisibility(View.VISIBLE); fabDriver.setVisibility(View.GONE); fabRider.setVisibility(View.VISIBLE); fabMenu.close(true); } dialog.dismiss(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); AlertDialog newAlert = alert.create(); newAlert.show(); } if (!userManager.getUser().getVehicleDescription().isEmpty()) { userManager.setUserMode(UserMode.DRIVER); keywordEditText.setVisibility(View.VISIBLE); fabDriver.setVisibility(View.GONE); fabRider.setVisibility(View.VISIBLE); fabMenu.close(true); } } }); fabRider.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { userManager.setUserMode(UserMode.RIDER); keywordEditText.setVisibility(View.GONE); fabRider.setVisibility(View.GONE); fabDriver.setVisibility(View.VISIBLE); fabMenu.close(true); } }); fabLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, LoginActivity.class); fabMenu.close(true); startActivity(intent); } }); fabSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked settings fab"); Intent intent = new Intent(MainActivity.this, SettingsActivity.class); fabMenu.close(true); startActivity(intent); } }); fabProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked profile fab"); Intent intent = new Intent(MainActivity.this, ProfileActivity.class); fabMenu.close(true); startActivity(intent); } }); fabHistory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked history fab"); Intent intent = new Intent(MainActivity.this, RequestHistoryActivity.class); fabMenu.close(true); startActivity(intent); } }); fabRequests.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked requests fab"); Intent intent = new Intent(MainActivity.this, RequestsListActivity.class); fabMenu.close(true); startActivity(intent); } }); setNotificationAlarm(context); }
From source file:com.secbro.qark.customintent.CreateCustomIntentActivity.java
private void createExtrasView() { LinearLayout topLayout = (LinearLayout) findViewById(R.id.extras_key_value_container); LinearLayout.LayoutParams llpTextView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llpTextView.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom); LinearLayout.LayoutParams llpEditText = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); llpEditText.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom); //key//from w w w .j a va 2 s . c om LinearLayout keyLinearLayout = new LinearLayout(this); keyLinearLayout.setOrientation(LinearLayout.HORIZONTAL); TextView keyTextView = new TextView(this); keyTextView.setText(getResources().getString(R.string.intent_extras_key)); keyTextView.setLayoutParams(llpTextView); AutoCompleteTextView keyEditText = new AutoCompleteTextView(this); keyEditText.setLayoutParams(llpEditText); ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.intent_extras_array)); keyEditText.setAdapter(adapter3); keyEditText.setSelection(keyEditText.getText().length()); keyEditText.setTag("key_field"); keyLinearLayout.addView(keyTextView); keyLinearLayout.addView(keyEditText); //value LinearLayout valueLinearLayout = new LinearLayout(this); valueLinearLayout.setOrientation(LinearLayout.HORIZONTAL); TextView valueTextView = new TextView(this); valueTextView.setText(getResources().getString(R.string.intent_extras_value)); valueTextView.setLayoutParams(llpTextView); EditText valueEditText = new EditText(this); valueEditText.setTag("value_field"); valueEditText.setLayoutParams(llpEditText); valueLinearLayout.addView(valueTextView); valueLinearLayout.addView(valueEditText); topLayout.addView(keyLinearLayout); topLayout.addView(valueLinearLayout); }
From source file:com.sigilance.CardEdit.MainActivity.java
private void promptForChangePin(final int mode) { AlertDialog.Builder builder = new AlertDialog.Builder(this); if (mode == 0x83) builder.setTitle(R.string.action_change_pw3); else//from ww w . java2 s .c o m builder.setTitle(R.string.action_change_pw1); final String typeString = mode == 0x83 ? "Admin" : "User"; String defaultString = mode == 0x83 ? "12345678" : "123456"; builder.setMessage(String.format("REMINDER: The default %s PIN is %s", typeString, defaultString)); final EditText oldPinInput = new EditText(this); oldPinInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); oldPinInput.setHint(String.format("Old %s PIN", mode == 0x83 ? "Admin" : "User")); final EditText newPinInput = new EditText(this); newPinInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); newPinInput.setHint(String.format("New %s PIN", mode == 0x83 ? "Admin" : "User")); final EditText confirmPinInput = new EditText(this); confirmPinInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); confirmPinInput.setHint("Repeat New PIN"); LinearLayout fields = new LinearLayout(this); fields.setOrientation(LinearLayout.VERTICAL); fields.addView(oldPinInput); fields.addView(newPinInput); fields.addView(confirmPinInput); builder.setView(fields); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Placeholder; we will override this } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (oldPinInput.getText().toString().length() == 0 || newPinInput.getText().toString().length() == 0) { Toast.makeText(MainActivity.this, "Enter a PIN!", Toast.LENGTH_SHORT).show(); return; } if (!(confirmPinInput.getText().toString().equals(newPinInput.getText().toString()))) { newPinInput.setText(""); confirmPinInput.setText(""); Toast.makeText(MainActivity.this, "PINs did not match.", Toast.LENGTH_SHORT).show(); return; } int minPinLength = (mode == 0x83) ? 8 : 6; if (oldPinInput.getText().toString().length() < minPinLength || newPinInput.getText().toString().length() < minPinLength) { newPinInput.setText(""); confirmPinInput.setText(""); Toast.makeText(MainActivity.this, String.format("%s PIN must be at least %d digits.", typeString, minPinLength), Toast.LENGTH_SHORT).show(); return; } // Once we have valid PINs, add the pending operation. mPendingOperations.add(new PendingChangePinOperation(mode, oldPinInput.getText().toString(), newPinInput.getText().toString())); // And prompt the user to change the PIN. hideUi(); findTextViewById(R.id.id_action_reqiured_warning).setText(R.string.warning_tap_card_to_change); dialog.dismiss(); } }); }
From source file:com.phonegap.plugins.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load.//from ww w. ja v a 2 s .c o m * @param jsonObject */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // 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", CLOSE_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.FILL_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); toolbar.setVisibility(View.GONE); // 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); actionButtonContainer.setVisibility(View.GONE); // Back button ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); try { back.setImageBitmap(loadDrawable("www/images/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); try { forward.setImageBitmap(loadDrawable("www/images/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } 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.FILL_PARENT, LayoutParams.FILL_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 ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); try { close.setImageBitmap(loadDrawable("www/images/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.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(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }