List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:cgeo.geocaching.cgBase.java
/** * insert text into the EditText at the current cursor position * * @param editText//from w ww .j a v a 2 s . c om * @param insertText * @param addSpace * add a space character, if there is no whitespace before the current cursor position * @param moveCursor * place the cursor after the inserted text */ static void insertAtPosition(final EditText editText, String insertText, final boolean addSpace, final boolean moveCursor) { int selectionStart = editText.getSelectionStart(); int selectionEnd = editText.getSelectionEnd(); int start = Math.min(selectionStart, selectionEnd); int end = Math.max(selectionStart, selectionEnd); String content = editText.getText().toString(); if (start > 0 && !Character.isWhitespace(content.charAt(start - 1))) { insertText = " " + insertText; } editText.getText().replace(start, end, insertText); int newCursor = moveCursor ? start + insertText.length() : start; editText.setSelection(newCursor, newCursor); }
From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java
private void createProximityAlertSetupDialog() { final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_proximity_alert_create, R.string.create_proximity_alert); Button setProximityAlertWatcherButton = (Button) dialog .findViewById(R.id.create_proximity_alert_create_alert_watcher_button); Button stopCurrentProximityAlertWatcherButton = (Button) dialog .findViewById(R.id.create_proximity_alert_stop_existing_alert_button); Button cancelButton = (Button) dialog.findViewById(R.id.create_proximity_alert_cancel_button); SeekBar seekbar = (SeekBar) dialog.findViewById(R.id.create_proximity_alert_seekBar); final EditText radiusEditText = (EditText) dialog.findViewById(R.id.create_proximity_alert_range_edit_text); final Switch formatSwitch = (Switch) dialog.findViewById(R.id.create_proximity_alert_format_switch); final double seekBarStepSize = (double) (getResources() .getInteger(R.integer.proximity_alert_maximum_warning_range_meters) - getResources().getInteger(R.integer.proximity_alert_minimum_warning_range_meters)) / 100; radiusEditText.setText(//from w ww. j a va 2 s . com String.valueOf(getResources().getInteger(R.integer.proximity_alert_minimum_warning_range_meters))); formatSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { buttonView.setText(getString(R.string.range_format_nautical_miles)); } else { buttonView.setText(getString(R.string.range_format_meters)); } } }); seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { String range = String.valueOf( (int) (getResources().getInteger(R.integer.proximity_alert_minimum_warning_range_meters) + (seekBarStepSize * progress))); radiusEditText.setText(range); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); setProximityAlertWatcherButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String toastText; if (proximityAlertWatcher == null) { toastText = getString(R.string.proximity_alert_set); } else { toastText = getString(R.string.proximity_alert_replace); } if (proximityAlertWatcher != null) { proximityAlertWatcher.cancel(true); } mGpsLocationTracker = new GpsLocationTracker(getActivity()); double latitude, longitude; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); cachedLat = latitude; longitude = mGpsLocationTracker.getLongitude(); cachedLon = longitude; } else { mGpsLocationTracker.showSettingsAlert(); return; } if (formatSwitch.isChecked()) { cachedDistance = Double.valueOf(radiusEditText.getText().toString()) * getResources().getInteger(R.integer.meters_per_nautical_mile); } else { cachedDistance = Double.valueOf(radiusEditText.getText().toString()); } dialog.dismiss(); Response response; try { String apiName = "fishingfacility"; String format = "OLEX"; String filePath; String fileName = "collisionCheckToolsFile"; response = barentswatchApi.getApi().geoDataDownload(apiName, format); if (response == null) { Log.d(TAG, "RESPONSE == NULL"); throw new InternalError(); } if (fiskInfoUtility.isExternalStorageWritable()) { String directoryPath = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(); String directoryName = "FiskInfo"; filePath = directoryPath + "/" + directoryName + "/"; InputStream zippedInputStream = null; try { TypedInput responseInput = response.getBody(); zippedInputStream = responseInput.in(); zippedInputStream = new GZIPInputStream(zippedInputStream); InputSource inputSource = new InputSource(zippedInputStream); InputStream input = new BufferedInputStream(inputSource.getByteStream()); byte data[]; data = FiskInfoUtility.toByteArray(input); InputStream inputStream = new ByteArrayInputStream(data); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); FiskInfoPolygon2D serializablePolygon2D = new FiskInfoPolygon2D(); String line; boolean startSet = false; String[] convertedLine; List<Point> shape = new ArrayList<>(); while ((line = reader.readLine()) != null) { Point currPoint = new Point(); if (line.length() == 0 || line.equals("")) { continue; } if (Character.isLetter(line.charAt(0))) { continue; } convertedLine = line.split("\\s+"); if (line.length() > 150) { Log.d(TAG, "line " + line); } if (convertedLine[0].startsWith("3sl")) { continue; } if (convertedLine[3].equalsIgnoreCase("Garnstart") && startSet) { if (shape.size() == 1) { // Point serializablePolygon2D.addPoint(shape.get(0)); shape = new ArrayList<>(); } else if (shape.size() == 2) { // line serializablePolygon2D.addLine(new Line(shape.get(0), shape.get(1))); shape = new ArrayList<>(); } else { serializablePolygon2D.addPolygon(new Polygon(shape)); shape = new ArrayList<>(); } startSet = false; } if (convertedLine[3].equalsIgnoreCase("Garnstart") && !startSet) { double lat = Double.parseDouble(convertedLine[0]) / 60; double lon = Double.parseDouble(convertedLine[1]) / 60; currPoint.setNewPointValues(lat, lon); shape.add(currPoint); startSet = true; } else if (convertedLine[3].equalsIgnoreCase("Brunsirkel")) { double lat = Double.parseDouble(convertedLine[0]) / 60; double lon = Double.parseDouble(convertedLine[1]) / 60; currPoint.setNewPointValues(lat, lon); shape.add(currPoint); } } reader.close(); new FiskInfoUtility().serializeFiskInfoPolygon2D(filePath + fileName + "." + format, serializablePolygon2D); tools = serializablePolygon2D; } catch (IOException e) { e.printStackTrace(); } catch (ArrayIndexOutOfBoundsException e) { Log.e(TAG, "Error when trying to serialize file."); Toast error = Toast.makeText(getActivity(), "Ingen redskaper i omrdet du definerte", Toast.LENGTH_LONG); e.printStackTrace(); error.show(); return; } finally { try { if (zippedInputStream != null) { zippedInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } } else { Toast.makeText(v.getContext(), R.string.download_failed, Toast.LENGTH_LONG).show(); dialog.dismiss(); return; } } catch (Exception e) { Log.d(TAG, "Could not download tools file"); Toast.makeText(getActivity(), R.string.download_failed, Toast.LENGTH_LONG).show(); } runScheduledAlarm(getResources().getInteger(R.integer.zero), getResources().getInteger(R.integer.proximity_alert_interval_time_seconds)); Toast.makeText(getActivity(), toastText, Toast.LENGTH_LONG).show(); } }); if (proximityAlertWatcher != null) { TypedValue outValue = new TypedValue(); stopCurrentProximityAlertWatcherButton.setVisibility(View.VISIBLE); getResources().getValue(R.dimen.proximity_alert_dialog_button_text_size_small, outValue, true); float textSize = outValue.getFloat(); setProximityAlertWatcherButton.setTextSize(textSize); stopCurrentProximityAlertWatcherButton.setTextSize(textSize); cancelButton.setTextSize(textSize); stopCurrentProximityAlertWatcherButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { proximityAlertWatcher.cancel(true); proximityAlertWatcher = null; dialog.dismiss(); } }); } cancelButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog)); dialog.show(); }
From source file:org.csp.everyaware.offline.Map.java
private void insertAnnDialog(final ExtendedLatLng annLatLng) { final Dialog insertDialog = new Dialog(Map.this); insertDialog.setContentView(R.layout.insert_dialog); insertDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); insertDialog.setTitle(R.string.annotation_insertion); insertDialog.setCancelable(false);/*ww w . ja va 2 s . co m*/ //get reference to send button final Button sendButton = (Button) insertDialog.findViewById(R.id.send_button); sendButton.setEnabled(false); //active only if there's text //get reference to cancel/close window button final Button cancelButton = (Button) insertDialog.findViewById(R.id.cancel_button); cancelButton.setEnabled(true); //active all time cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { insertDialog.dismiss(); } }); //get reference to edittext in which user writes annotation final EditText editText = (EditText) insertDialog.findViewById(R.id.annotation_editText); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //if modified text length is more than 0, activate send button if (s.length() > 0) sendButton.setEnabled(true); else sendButton.setEnabled(false); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); //get checkbox references CheckBox facebookChBox = (CheckBox) insertDialog.findViewById(R.id.facebook_checkBox); CheckBox twitterChBox = (CheckBox) insertDialog.findViewById(R.id.twitter_checkBox); //activate check boxes depends from log in facebook/twitter boolean[] logs = new boolean[2]; logs[0] = Utils.getValidFbSession(getApplicationContext()); logs[1] = Utils.getValidTwSession(getApplicationContext()); facebookChBox.setEnabled(logs[0]); twitterChBox.setEnabled(logs[1]); //checked on check boxes final boolean[] checkeds = Utils.getShareCheckedOn(getApplicationContext()); if (checkeds[0] == true) facebookChBox.setChecked(true); else facebookChBox.setChecked(false); if (checkeds[1] == true) twitterChBox.setChecked(true); else twitterChBox.setChecked(false); facebookChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { Utils.setShareCheckedOn(checked, checkeds[1], getApplicationContext()); checkeds[0] = checked; } }); twitterChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { Utils.setShareCheckedOn(checkeds[0], checked, getApplicationContext()); checkeds[1] = checked; } }); //send annotation to server and on facebook/twitter if user is logged on sendButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //1 - read inserted annotation String annotation = editText.getText().toString(); //2 - update record on db with annotation and save recordId double recordId = annLatLng.mRecordId; int result = mDbManager.updateRecordAnnotation(recordId, annotation); if (result == 1) Toast.makeText(getApplicationContext(), "Updated record", Toast.LENGTH_LONG).show(); else Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show(); boolean[] checks = Utils.getShareCheckedOn(getApplicationContext()); //3 - share on facebook is user wants and internet is active now if (checks[0] == true) { Record annotatedRecord = mDbManager.loadRecordById(recordId); try { FacebookManager fb = FacebookManager.getInstance(null, null); if (fb != null) fb.postMessageOnWall(annotatedRecord); } catch (Exception e) { e.printStackTrace(); } } //4 - share on twitter is user wants and internet is active now if (checks[1] == true) { Record annotatedRecord = mDbManager.loadRecordById(recordId); try { TwitterManager twManager = TwitterManager.getInstance(null); twManager.postMessage(annotatedRecord); } catch (Exception e) { e.printStackTrace(); } } //5 - show marker for annotated record Record annotatedRecord = mDbManager.loadRecordById(recordId); String userAnn = annotatedRecord.mUserData1; if (!userAnn.equals("") && (annotatedRecord.mValues[0] != 0)) { BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.annotation_marker); Marker marker = mGoogleMap.addMarker(new MarkerOptions() .position(new LatLng(annotatedRecord.mValues[0], annotatedRecord.mValues[1])) .title("BC: " + String.valueOf(annotatedRecord.mBcMobile) + " " + getResources().getString(R.string.micrograms)) .snippet("Annotation: " + userAnn).icon(icon).anchor(0f, 1f)); } insertDialog.dismiss(); } }); insertDialog.show(); }
From source file:com.max2idea.android.limbo.main.LimboActivity.java
public void promptImageName(final Activity activity, String hd) { final String hd_string = hd; final AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(activity).create(); alertDialog.setTitle("Image Name"); RelativeLayout mLayout = new RelativeLayout(this); mLayout.setId(12222);// www . j a v a2s. c o m EditText imageNameView = new EditText(activity); imageNameView.setEnabled(true); imageNameView.setVisibility(View.VISIBLE); imageNameView.setId(201012010); imageNameView.setSingleLine(); RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); mLayout.addView(imageNameView, searchViewParams); final Spinner size = new Spinner(this); RelativeLayout.LayoutParams setPlusParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); size.setId(201012044); String[] arraySpinner = new String[7]; for (int i = 0; i < arraySpinner.length; i++) { if (i < 5) { arraySpinner[i] = (i + 1) + " GB"; } } arraySpinner[5] = "10 GB"; arraySpinner[6] = "20 GB"; ArrayAdapter sizeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner); sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); size.setAdapter(sizeAdapter); setPlusParams.addRule(RelativeLayout.BELOW, imageNameView.getId()); mLayout.addView(size, setPlusParams); // TODO: Not working for now // final TextView preallocText = new TextView(this); // preallocText.setText("Preallocate? "); // preallocText.setTextSize(15); // RelativeLayout.LayoutParams preallocTParams = new // RelativeLayout.LayoutParams( // RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.WRAP_CONTENT); // preallocTParams.addRule(RelativeLayout.BELOW, size.getId()); // mLayout.addView(preallocText, preallocTParams); // preallocText.setId(64512044); // // final CheckBox prealloc = new CheckBox(this); // RelativeLayout.LayoutParams preallocParams = new // RelativeLayout.LayoutParams( // RelativeLayout.LayoutParams.WRAP_CONTENT, // RelativeLayout.LayoutParams.WRAP_CONTENT); // preallocParams.addRule(RelativeLayout.BELOW, size.getId()); // preallocParams.addRule(RelativeLayout.RIGHT_OF, // preallocText.getId()); // preallocParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, // preallocText.getId()); // mLayout.addView(prealloc, preallocParams); // prealloc.setId(64512344); alertDialog.setView(mLayout); final Handler handler = this.handler; // alertDialog.setMessage(body); alertDialog.setButton("Create", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int sizeSel = size.getSelectedItemPosition(); String templateImage = "hd1g.qcow2"; if (sizeSel < 5) { templateImage = "hd" + (sizeSel + 1) + "g.qcow2"; } else if (sizeSel == 5) { templateImage = "hd10g.qcow2"; } else if (sizeSel == 6) { templateImage = "hd20g.qcow2"; } // UIUtils.log("Searching..."); EditText a = (EditText) alertDialog.findViewById(201012010); progDialog = ProgressDialog.show(activity, "Please Wait", "Creating HD Image...", true); // CreateImage createImg = new // CreateImage(a.getText().toString(), // hd_string, sizeInt, prealloc.isChecked()); // CreateImage createImg = new CreateImage(a.getText().toString(), // hd_string, sizeInt, false); // createImg.execute(); String image = a.getText().toString(); if (!image.endsWith(".qcow2")) { image += ".qcow2"; } createImg(templateImage, image, hd_string); } }); alertDialog.show(); }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog selectPgnSaveNewFileDialog() { View content = View.inflate(this, R.layout.create_pgn_file, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);/*from ww w . j ava2 s. c o m*/ builder.setTitle(R.string.select_pgn_file_save); final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename); fileNameView.setText(""); final Runnable savePGN = new Runnable() { public void run() { String pgnFile = fileNameView.getText().toString(); if ((pgnFile.length() > 0) && !pgnFile.contains(".")) pgnFile += ".pgn"; String sep = File.separator; String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile; savePGNToFile(pathName, false); } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { savePGN.run(); } }); builder.setNegativeButton(R.string.cancel, null); final Dialog dialog = builder.create(); fileNameView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { savePGN.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog selectMoveDialog() { View content = View.inflate(this, R.layout.select_move_number, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);/*from ww w .j ava 2 s. c o m*/ builder.setTitle(R.string.goto_move); final EditText moveNrView = (EditText) content.findViewById(R.id.selmove_number); moveNrView.setText("1"); final Runnable gotoMove = new Runnable() { public void run() { try { int moveNr = Integer.parseInt(moveNrView.getText().toString()); ctrl.gotoMove(moveNr); } catch (NumberFormatException nfe) { Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT) .show(); } } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { gotoMove.run(); } }); builder.setNegativeButton(R.string.cancel, null); final AlertDialog dialog = builder.create(); moveNrView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { gotoMove.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog newNetworkEngineDialog() { View content = View.inflate(this, R.layout.create_network_engine, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);//from w ww . j a v a 2 s. c om builder.setTitle(R.string.create_network_engine); final EditText engineNameView = (EditText) content.findViewById(R.id.create_network_engine); engineNameView.setText(""); final Runnable createEngine = new Runnable() { public void run() { String engineName = engineNameView.getText().toString(); String sep = File.separator; String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName; File file = new File(pathName); boolean nameOk = true; int errMsg = -1; if (engineName.contains("/")) { nameOk = false; errMsg = R.string.slash_not_allowed; } else if (internalEngine(engineName) || file.exists()) { nameOk = false; errMsg = R.string.engine_name_in_use; } if (!nameOk) { Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); return; } networkEngineToConfig = pathName; removeDialog(NETWORK_ENGINE_CONFIG_DIALOG); showDialog(NETWORK_ENGINE_CONFIG_DIALOG); } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { createEngine.run(); } }); builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); final Dialog dialog = builder.create(); engineNameView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { createEngine.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public static AlertDialog getaddtextdialog(String title, final int itemnumber, Context ctx) { AlertDialog.Builder getaddtext = new AlertDialog.Builder(ctx); final LinearLayout linearlayout = new LinearLayout(ctx); linearlayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linearlayout.setOrientation(LinearLayout.VERTICAL); final EditText nameet = new EditText(ctx); nameet.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView fontname = new TextView(ctx); fontname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView colorname = new TextView(ctx); colorname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner fontsizespinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner colorspinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); List<String> fontsizelist = new ArrayList<String>(); for (int t = 1; t < 200; t++) { fontsizelist.add(u.s(t));/*from www . j av a 2s . c o m*/ } ArrayAdapter<String> fontsizearrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, fontsizelist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); List<String> colorlist = new ArrayList<String>(); { colorlist.add("RED"); colorlist.add("BLACK"); colorlist.add("BLUE"); colorlist.add("GREEN"); colorlist.add("WHITE"); colorlist.add("GRAY"); } ArrayAdapter<String> colorlistarrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, colorlist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); colorspinner.setAdapter(colorlistarrayadapter); fontsizespinner.setAdapter(fontsizearrayadapter); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, "25")); fontname.setText("Select Font Size"); fontname.setTextSize(20f); colorname.setText("Select Color"); colorname.setTextSize(20f); linearlayout.addView(nameet); linearlayout.addView(fontname); linearlayout.addView(fontsizespinner); linearlayout.addView(colorname); linearlayout.addView(colorspinner); if (!(itemnumber == view.i)) { nameet.setText(view.ITEMstring[itemnumber]); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, u.s(view.ITEMfontsize[itemnumber]))); colorspinner.setSelection(getIndexofSpinner(colorspinner, u.s(view.ITEMfontcolor[itemnumber]))); } getaddtext.setView(linearlayout); getaddtext.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); getaddtext.setTitle(title); getaddtext.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String string = nameet.getText().toString(); float fontsize = fontsizespinner.getSelectedItemPosition() + 1; //ITEMelcnumber[itemselectednumber]=u.i(string); int colpos = colorspinner.getSelectedItemPosition(); int[] col = new int[] { Color.RED, Color.BLACK, Color.BLUE, Color.GREEN, Color.WHITE, Color.GRAY }; int color = col[colpos]; Log.d("addtext", u.s((int) fontsize) + colpos + color); view.ITEMstring[itemnumber] = string; view.ITEMfontsize[itemnumber] = (int) fontsize; view.ITEMfontcolor[itemnumber] = color; view.itemname = string; view.fontsize = (int) fontsize; view.color = color; view.invalidate(); dialog.dismiss(); FloorPlanActivity.writeonedbitem(itemnumber); } }); return getaddtext.create(); }
From source file:nf.frex.android.FrexActivity.java
private void preparePropertiesDialog(final Dialog dialog) { final Registry<Fractal> fractals = Registries.fractals; int fractalTypeIndex = fractals.getIndex(view.getFractalId()); final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner); final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar); final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text); final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box); final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box); final Button okButton = (Button) dialog.findViewById(R.id.ok_button); final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); juliaModeCheckBox.setEnabled(true);//from w ww.ja v a 2 s . c o m ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, fractals.getIds()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fractalTypeSpinner.setAdapter(arrayAdapter); fractalTypeSpinner.setSelection(fractalTypeIndex, true); fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { Fractal fractal = fractals.getValue(position); iterationsEditText.setText(fractal.getDefaultIterMax() + ""); boolean sameFractal = view.getFractalId().equals(fractals.getId(position)); if (!sameFractal) { juliaModeCheckBox.setChecked(false); } juliaModeCheckBox.setEnabled(sameFractal); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL); final double iterationsMin = 1; final double iterationsMax = 3; final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar, iterationsMin, iterationsMax, true, view.getIterMax()); iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { int iterMax = iterationsSeekBarConfigurer.getValueInt(); iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { try { int iterMax = Integer.parseInt(v.getText().toString()); iterationsSeekBarConfigurer.setValue(iterMax); return true; } catch (NumberFormatException e) { return false; } } }); decoratedFractal.setChecked(view.isDecoratedFractal()); juliaModeCheckBox.setChecked(view.isJuliaModeFractal()); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int iterMax; try { iterMax = Integer.parseInt(iterationsEditText.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); return; } dialog.dismiss(); String oldConfigName = view.getConfigName(); String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition()); Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition()); String oldFractalId = view.getFractalId(); boolean newJuliaModeFractal = juliaModeCheckBox.isChecked(); boolean oldJuliaModeFractal = view.isJuliaModeFractal(); view.setFractalId(newFractalId); view.setIterMax(iterMax); view.setDecoratedFractal(decoratedFractal.isChecked()); view.setJuliaModeFractal(newJuliaModeFractal); boolean fractalTypeChanged = !oldFractalId.equals(newFractalId); if (fractalTypeChanged) { if (oldConfigName.contains(oldFractalId.toLowerCase())) { view.setConfigName(newFractalId.toLowerCase()); } view.setRegion(fractal.getDefaultRegion()); view.setBailOut(fractal.getDefaultBailOut()); } boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal; if (fractalTypeChanged || juliaModeChanged) { view.getRegionHistory().clear(); view.getRegionHistory().add(fractal.getDefaultRegion().clone()); } view.recomputeAll(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }