List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java
public void connectToPublicServer(final PublicServer server) { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); final Settings settings = Settings.getInstance(this); // Allow username entry final EditText usernameField = new EditText(this); usernameField.setHint(settings.getDefaultUsername()); alertBuilder.setView(usernameField); alertBuilder.setTitle(R.string.connectToServer); alertBuilder.setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() { @Override//from w w w. j av a 2 s .c o m public void onClick(DialogInterface dialog, int which) { PublicServer newServer = server; if (!usernameField.getText().toString().equals("")) newServer.setUsername(usernameField.getText().toString()); else newServer.setUsername(settings.getDefaultUsername()); connectToServer(newServer); } }); alertBuilder.show(); }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject// w w w . j ava 2s . c o 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(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.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 InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); 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("<"); */ Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } 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(">"); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } 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); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } 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); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } 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.googlecode.android_scripting.facade.AndroidFacade.java
private String getInputFromAlertDialog(final String title, final String message, final boolean password) { final FutureActivityTask<String> task = new FutureActivityTask<String>() { @Override//w w w. ja va 2 s . co m public void onCreate() { super.onCreate(); final EditText input = new EditText(getActivity()); if (password) { input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); input.setTransformationMethod(new PasswordTransformationMethod()); } AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(title); alert.setMessage(message); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); setResult(input.getText().toString()); finish(); } }); alert.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); setResult(null); finish(); } }); alert.show(); } }; mTaskQueue.execute(task); try { return task.getResult(); } catch (Exception e) { Log.e("Failed to display dialog.", e); throw new RuntimeException(e); } }
From source file:kuzki.net.exercisetracker.MainActivity.java
private void getRouteName() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.name_your_route_prompt); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input);/* w ww . java 2 s .c o m*/ alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mRecordRoute.name = input.getText().toString(); addRecordedRouteToDb(); finish(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mRecordRoute = null; mMap.clear(); } }); alert.show(); }
From source file:com.example.innf.newchangtu.Map.view.activity.MainActivity.java
private void fastSend() { Log.d(TAG, "fastSend: is called"); String[] remark = { "?", "", "" }; ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, remark);/* www.java 2 s. c om*/ View view1 = View.inflate(MainActivity.this, R.layout.show_dialog, null); final ListView listView = (ListView) view1.findViewById(R.id.dialog_list_view); listView.setAdapter(adapter); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog dialog = builder.setTitle("?").setView(view1) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { sendSMS(); } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).show(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (i == 2) { final EditText editText = new EditText(MainActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); AlertDialog dialog = builder.setTitle("").setView(editText) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setRemark(editText.getText().toString()); sendSMS(); Log.d(TAG, editText.getText().toString()); } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).show(); } else { setRemark(listView.getItemAtPosition(i).toString()); sendSMS(); } dialog.dismiss(); } }); }
From source file:com.googlecode.CallerLookup.Main.java
public void doSave() { final Context context = this; final EditText input = new EditText(context); input.setHint(R.string.Name); AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle(R.string.SaveTitle);/*from w w w. j a v a2 s. c o m*/ alert.setMessage(R.string.SaveMessage); alert.setView(input); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialog, int which) { final String name = SAVED_PREFIX + input.getText().toString().trim(); if (name.length() <= SAVED_PREFIX.length()) { AlertDialog.Builder error = new AlertDialog.Builder(context); error.setTitle(R.string.NameMissingTitle); error.setMessage(R.string.NameMissingMessage); error.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doSave(); } }); error.show(); return; } if (mLookupEntries.containsKey(name)) { AlertDialog.Builder confirm = new AlertDialog.Builder(context); confirm.setTitle(R.string.NameConfirmTitle); confirm.setMessage(R.string.NameConfirmMessage); confirm.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mLookupEntries.remove(name); mUserLookupEntries.remove(name); addUserLookupEntry(name); int count = mLookup.getCount(); for (int i = 1; i < count; i++) { if (mLookup.getItemAtPosition(i).toString().equals(name)) { mLookup.setSelection(i); break; } } } }); confirm.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doSave(); } }); confirm.show(); return; } addUserLookupEntry(name); ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); adapter.add(name); mLookup.setSelection(mLookup.getCount() - 1); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert.show(); }
From source file:info.papdt.blacklight.ui.main.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.switch_theme) { Utility.switchTheme(this); // This will re-create the whole activity recreate();//from w w w. j av a2s .c om return true; } else if (item.getItemId() == R.id.group_destroy) { new AlertDialog.Builder(this).setMessage(R.string.confirm_delete).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new GroupDeleteTask().execute(); } }).show(); return true; } else if (item.getItemId() == R.id.group_create) { final EditText text = new EditText(this); new AlertDialog.Builder(this).setTitle(R.string.group_create).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new GroupCreateTask().execute(text.getText().toString().trim()); } }).setView(text).show(); return true; } else if (item.getItemId() == R.id.search) { mSearchBox.clearSearchable(); List<String> history = mSearchHistory.getHistory(); for (String keyword : history) { mSearchBox.addSearchable( new SearchResult(keyword, getResources().getDrawable(R.drawable.ic_history))); } updateSplashes(); mSearchBox.revealFromMenuItem(R.id.search, this); return true; } else { return super.onOptionsItemSelected(item); } }
From source file:com.sonetel.ui.SipHome.java
private void postStartSipService() { // If we have never set fast settings //DBAdapter db = new DBAdapter(this); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (CustomDistribution.showFirstSettingScreen()) { if (!prefProviderWrapper.getPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, false)) { //ContentValues initialValues = new ContentValues(); for (int i = 1; i <= 52; i++) { //initialValues = AccessNumbers.getContentValues(i); getContentResolver().insert(SipProfile.ACCESS_URI, AccessNumbers.getContentValues(i)); //db1.insert(db.databaseHelper.ACCESS_NUMS_TABLE_NAME, null, initialValues); }/* w w w . j a v a2 s . co m*/ } prefProviderWrapper.setPreferenceBooleanValue(prefWrapper.ACCESS_NUM_ALREADY_FETCHED, true);// yuva should be true prefWrapper.setSimId(tm.getSubscriberId()); Location_Finder locFinder = new Location_Finder(getBaseContext()); prefWrapper.setTelCountryCode(locFinder.getTelContryCode()); prefWrapper.setCurrentLocation(tm.getNetworkCountryIso()); //PrefsLogic.setCallthruNumber(getBaseContext()); } else { boolean doFirstParams = !prefProviderWrapper .getPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, false); prefProviderWrapper.setPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, true); if (!tm.getSubscriberId().equalsIgnoreCase(prefWrapper.getSimId())) { //final DBAdapter db = new DBAdapter(this); final EditText input = new EditText(this); new AlertDialog.Builder(this) .setTitle("New SIM: Please enter new mobile number") //.setMessage("Please enter your new mobile number in Sign in screen") .setIcon(R.drawable.ic_wizard_sonetel) .setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String mobile = input.getText().toString(); int nbrOfAccount = doWeHaveAccount(); SipProfile account = new SipProfile(); if (nbrOfAccount != 0) { account = SipProfile.getProfileFromDbId(getActivity(), 1, DBProvider.ACCOUNT_FULL_PROJECTION); account.mobile_nbr = mobile; getContentResolver().update( ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, 1), account.getDbContentValues(), null, null); } TelephonyManager tm = (TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE); prefWrapper.setSimId(tm.getSubscriberId()); if (mobile.length() < 8 && !mobile.startsWith("+")) { Toast.makeText(getBaseContext(), "Invalid mobile number. Please enter +MOBILENUMBER in the international format", Toast.LENGTH_LONG).show(); } } private Context getActivity() { // TODO Auto-generated method stub return null; } }) .show(); } if (doFirstParams) { prefProviderWrapper.resetAllDefaultValues(); } } // If we have no account yet, open account panel, if (!hasTriedOnceActivateAcc && isInternetAvail) { int accountCount = 0; accountCount = doWeHaveAccount(); if (accountCount == 0) { Intent accountIntent = null; WizardInfo distribWizard = CustomDistribution.getCustomDistributionWizard(); if (distribWizard != null) { accountIntent = new Intent(this, BasePrefsWizard.class); accountIntent.putExtra(SipProfile.FIELD_WIZARD, distribWizard.id); } // else { // accountIntent = new Intent(this, AccountsEditList.class); // } if (accountIntent != null) { accountIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(accountIntent); hasTriedOnceActivateAcc = true; return; } } hasTriedOnceActivateAcc = false; } }
From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java
/** * Renames a sourceItem// w w w. ja v a 2 s .co m * @param sourceItem The sourceItem to rename */ private void renameItem(final Item sourceItem) { final Activity activity = getActivity(); final EditText newName = new EditText(activity); newName.setInputType(InputType.TYPE_CLASS_TEXT); newName.setHint(sourceItem.name); final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.rename) .setIcon(android.R.drawable.ic_menu_edit).setView(newName) .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final ICallback<Item> callback = new DefaultCallback<Item>(getActivity()) { @Override public void success(final Item item) { Toast.makeText(activity, activity.getString(R.string.renamed_item, sourceItem.name, item.name), Toast.LENGTH_LONG).show(); refresh(); dialog.dismiss(); } @Override public void failure(final ClientException error) { Toast.makeText(activity, activity.getString(R.string.rename_error, sourceItem.name), Toast.LENGTH_LONG).show(); dialog.dismiss(); } }; Item updatedItem = new Item(); updatedItem.id = sourceItem.id; updatedItem.name = newName.getText().toString(); ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive() .getItems(updatedItem.id).buildRequest().update(updatedItem, callback); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.cancel(); } }).create(); alertDialog.show(); }
From source file:com.github.irshulx.Components.InputExtensions.java
public void insertLink() { final AlertDialog.Builder inputAlert = new AlertDialog.Builder(this.editorCore.getContext()); inputAlert.setTitle("Add a Link"); final EditText userInput = new EditText(this.editorCore.getContext()); //dont forget to add some margins on the left and right to match the title userInput.setHint("type the URL here"); userInput.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT); inputAlert.setView(userInput);//from ww w. j a va 2 s . c o m inputAlert.setPositiveButton("Insert", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String userInputValue = userInput.getText().toString(); insertLink(userInputValue); } }); inputAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alertDialog = inputAlert.create(); alertDialog.show(); }