@Override public void onClick(View inButton) { boolean isErr = false; if (mTitle.getText().toString().length() == 0) { mTitle.setError("Required"); mTitle.setEms(10); isErr = true; } if (mDesc.getText().toString().length() == 0) { mDesc.setActivated(true); mDesc.setError("Required"); isErr = true; } if (inButton.getId() == openWeb.getId()) web.setVisibility(View.VISIBLE); else if (inButton.getId() == mAvail.getId()) startActivity(new Intent(this, CheckActivity.class)); else if (inButton.getId() == mBack.getId()) finish(); else if (inButton.getId() == mSub.getId()) { AlertDialog.Builder al = new AlertDialog.Builder(this); if (isErr) return; else al.setTitle("Continue?") .setIcon(R.drawable.ornament) .setMessage("Your listing is going to be submitted to your chosen category.") .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int x) { payment = new ArrayList<String>(); if (mCard.isChecked()) payment.add("Card"); if (mCheck.isChecked()) payment.add("Check"); if (mOnline.isChecked()) payment.add("Online"); if (mCash.isChecked()) payment.add("Cash"); // Toast.makeText(getApplicationContext(), payment.toString(), // Toast.LENGTH_LONG).show(); Intent intent = new Intent(getApplicationContext(), StartActivity.class); intent.putExtra("Payment", payment); intent.putExtra("Category", mChosenCategory); intent.putExtra("Title", mTitle.getText().toString()); intent.putExtra("Price", mPrice.getText().toString()); intent.putExtra("Description", mDesc.getText().toString()); intent.putExtra("Location", mLocation.getText().toString()); intent.putExtra("Photo", jpegData); startActivity(intent); } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int x) {} }) .show(); } else startActivityForResult( new Intent(this, com.lightbox.android.camera.activities.Camera.class), REQ); }
private void build_scroll_view(RaceDetails rd) { // Erase the content of the scroll view LinearLayout pilot_list = (LinearLayout) findViewById(R.id.pilot_list); pilot_list.removeAllViews(); for (int index = 0; index < main_application.nb_of_pilots; index++) { if (rd.isTherePilot(index)) { LinearLayout new_horiz_layout = new LinearLayout(this); new_horiz_layout.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); new_horiz_layout.setOrientation(LinearLayout.HORIZONTAL); EditText new_text_view = new EditText(this); new_text_view.setText(main_application.getPilotName(index)); new_text_view.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); new_text_view.setInputType( InputType.TYPE_NULL); // The text cannot be edited with the soft keypad new_text_view.setFocusable(false); // The text cannot be edited new_horiz_layout.addView(new_text_view); ImageView new_image_view = new ImageView(this); new_image_view.setImageResource(R.drawable.kart); new_horiz_layout.addView(new_image_view); EditText new_text_view_car_id = new EditText(this); if (rd.pilot_to_car_mapping.matching.indexOfKey(index) >= 0) { new_text_view_car_id.setText( Integer.toString(rd.pilot_to_car_mapping.matching.get(index))); } else { // This pilot wasn't in the maximum matching, he therefore is assigned to a car number he // already got // Signal that by writing the car number red. new_text_view_car_id.setText( Integer.toString(rd.pilot_to_car_mapping.unmatched.get(index))); new_text_view_car_id.setTextColor(getResources().getColor(R.color.dark_red)); } new_text_view_car_id.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); new_text_view_car_id.setInputType( InputType.TYPE_NULL); // The text cannot be edited with the soft keypad new_text_view_car_id.setFocusable(false); // The text cannot be edited new_text_view_car_id.setEms(3); new_text_view_car_id.setGravity(Gravity.RIGHT); new_horiz_layout.addView(new_text_view_car_id); pilot_list.addView(new_horiz_layout); } } // Redraw the scroll view pilot_list.invalidate(); }
/** * Creates a row in signals table to store the signal sources checkboxs. Returns the signal * sources checkboxs container. * * @param signalTypeId * @return */ public LinearLayout getSourcesCheckboxsContainer(String signalTypeId) { // Is there already a row for this signal type? LinearLayout checkboxContainer; ArrayList<View> containers = AndroidUtil.getViewsByTag(this, signalTypeId + "-checkboxContainer"); if (containers.size() == 0) { // There is NO row TableRow row = new TableRow(this); TableRow.LayoutParams lp = new TableRow.LayoutParams( TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); row.setLayoutParams(lp); row.setTag(signalTypeId + "-row"); // Signal name. TextView signalType = new TextView(this); signalType.setText(signalTypeId); signalType.setTextColor(Color.BLACK); signalType.setBackgroundResource(R.drawable.table_border); signalType.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f)); signalType.setGravity(Gravity.CENTER); // Signal samples (of each source). EditText signalSamples = new EditText(this); signalSamples.setInputType(InputType.TYPE_CLASS_NUMBER); signalSamples.setBackgroundResource(R.drawable.table_border); signalSamples.setTag(signalTypeId + "-samples"); signalSamples.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f)); signalSamples.setText( Preferences.readString( this.getClass().getSimpleName(), "Signal_" + signalTypeId, DEFAULT_SAMPLES_COUNT + "")); signalSamples.setTextColor(Color.BLACK); signalSamples.setEms(10); // Container for sources checkboxs. checkboxContainer = new LinearLayout(this); checkboxContainer.setOrientation(LinearLayout.HORIZONTAL); checkboxContainer.setTag(signalTypeId + "-checkboxContainer"); // checkboxContainer.setLayoutParams(new TableRow.LayoutParams(0, // TableRow.LayoutParams.MATCH_PARENT, 60f)); LinearLayout left = new LinearLayout(this); left.setOrientation(LinearLayout.VERTICAL); LinearLayout right = new LinearLayout(this); right.setOrientation(LinearLayout.VERTICAL); checkboxContainer.addView(left); checkboxContainer.addView(right); row.addView(signalType); row.addView(signalSamples); ScrollViewWithMaxHeight scrollView = new ScrollViewWithMaxHeight(this); scrollView.setMaxHeight(500); // ScrollView scrollView = new ScrollView(this); scrollView.setLayoutParams( new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 66f)); scrollView.addView(checkboxContainer); row.addView(scrollView); // row.addView(checkboxContainer); TableLayout table = (TableLayout) findViewById(R.id.signalsTable); table.addView(row); } else // There is a row { checkboxContainer = (LinearLayout) containers.get(0); } return checkboxContainer; }
private void createNewContactObject(String type, View my_contact_view) { if (my_contact_view == null) { my_contact_view = fragment_mycontact.getView(); } if (my_contact_view == null) return; LinearLayout ll_data; List<String> list = new ArrayList<String>(); int it = android.text.InputType.TYPE_CLASS_TEXT; int hint = 0; // Typen setzen: List<Integer> list_number = new ArrayList<Integer>(); for (int i = 0; i < array_en_type.length; i++) { if (array_en_type[i].equals(type)) { list_number.add(i); } } for (int i = 0; i < list_number.size(); i++) { list.add((array_en_name[list_number.get(i)])); } final String[] spinnerArray = list.toArray(new String[list.size()]); // ----------- LinearLayout ll_telephone = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_telephone); LinearLayout ll_email = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_email); LinearLayout ll_other = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_other); // new row LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); DisplayMetrics tmp_metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(tmp_metrics); int resolution_width = tmp_metrics.widthPixels; final boolean large_screen = (resolution_width >= 720); final EditText et = new EditText(this); LayoutParams lp_et; lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1); if (type.equals("number")) { ll_data = ll_telephone; it = InputType.TYPE_CLASS_PHONE; hint = R.string.telephone; } else if (type.equals("email")) { ll_data = ll_email; it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; hint = R.string.email; } else { ll_data = ll_other; if (type.equals("address")) { et.setMinLines(1); et.setMaxLines(3); et.setLines(2); hint = R.string.address; it = InputType.TYPE_CLASS_TEXT | InputType .TYPE_TEXT_FLAG_MULTI_LINE; // android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS; lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, large_screen ? 130 : 90, 1); row.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, (large_screen ? 130 : 90) + 20)); et.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); // et.setGravity(Gravity.LEFT | Gravity.TOP ); } else if (type.equals("website")) { hint = R.string.website; it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; } } ((LinearLayout) ll_data.getParent()).setVisibility(LinearLayout.VISIBLE); et.setTextSize(large_screen ? 16 : 14); // EditText-Textgr��e et.setEms(10); et.setHint(hint); et.setInputType(it); lp_et.setMargins(0, 3, 0, 0); et.setLayoutParams(lp_et); Spinner spinner = new Spinner(this); LayoutParams lp_spinner = new LayoutParams( large_screen ? Functions.dpsToPx(this, 100) : Functions.dpsToPx(this, 80), /*300 : 200*/ LayoutParams.MATCH_PARENT); lp_spinner.setMargins(0, 3, 0, 0); MySpinnerArrayAdapter dataAdapter = new MySpinnerArrayAdapter(this, list, large_screen); dataAdapter.setDropDownViewResource( android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setLayoutParams(lp_spinner); spinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected( final AdapterView<?> adapterView, final View view, int arg2, long arg3) { final Spinner spinner = (Spinner) adapterView; MySpinnerArrayAdapter adapter = (MySpinnerArrayAdapter) spinner.getAdapter(); if (adapter .getItem(arg2) .toLowerCase(new Locale("en")) .equals(getString(R.string.en_custom).toLowerCase(new Locale("en")))) { LinearLayout ll = new LinearLayout(MainActivity.this); final EditText et = new EditText(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(0, 20, 0, 0); et.setTextColor(Color.BLACK); et.requestFocus(); // et.setHint(R.string.place); ll.addView(et, layoutParams); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder .setView(ll) .setTitle(R.string.message_custom_en) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String[] newItems = new String[spinnerArray.length + 1]; System.arraycopy(spinnerArray, 0, newItems, 0, spinnerArray.length); newItems[newItems.length - 1] = et.getText().toString(); MySpinnerArrayAdapter adapter = new MySpinnerArrayAdapter( getApplicationContext(), newItems, ((MySpinnerArrayAdapter) spinner.getAdapter()).getLargeScreen()); spinner.setAdapter(adapter); spinner.setSelection(newItems.length - 1); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) {} }) .create() .show(); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); Button btn = new Button(this); btn.setText("x"); LayoutParams lp_btn = new LayoutParams(Functions.dpsToPx(this, 32), LayoutParams.WRAP_CONTENT); lp_btn.setMargins(-10, 0, -10, 0); btn.setLayoutParams(lp_btn); btn.setBackgroundColor(Color.TRANSPARENT); btn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (((LinearLayout) v.getParent().getParent()).getChildCount() == 1) { ((LinearLayout) v.getParent().getParent().getParent()).setVisibility(View.GONE); } ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent()); } }); row.addView(et); row.addView(spinner); row.addView(btn); row.setTag(type); ll_data.addView(row); }