private void fillData() { newName.setText(intent.getStringExtra(NutrientsDBAdapter.KEY_NAME)); newProteins.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_PROTEINS, 0))); newFats.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_FATS, 0))); newCarbs.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_CARBOHYDRATES, 0))); newCalories.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_CALORIES, 0))); }
public void initializeMainWork() { mContext = getApplicationContext(); // StricMode Thread Policy setting StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .permitDiskReads() .permitDiskWrites() .permitNetwork() .build()); select_icon = (Button) findViewById(R.id.select_icon); select_icon.setOnClickListener(this); mAddress = new MyAddress(); mAddress.getAddressFromText(); if (!mAddress.getIP().equals("") && !mAddress.getPORTDATA().equals("") && !mAddress.getPORTVIDEO().equals("")) { SIP = mAddress.getIP(); DATA_SPORT = mAddress.getPORTDATA(); VIDEO_SPORT = mAddress.getPORTVIDEO(); editText3.setText(SIP); editText4.setText(DATA_SPORT); editText5.setText(VIDEO_SPORT); CONNECTION_READY = true; } mUser = new MyUser(); img_lock = (ImageView) findViewById(R.id.image_lock); img_unlock = (ImageView) findViewById(R.id.image_unlock); img_lock.setOnClickListener(this); img_unlock.setOnClickListener(this); }
private void init() { it = getIntent(); order_id = it.getStringExtra("order_id"); rec_id = it.getStringExtra("rec_id"); goods_num = it.getStringExtra("goods_num"); goods_pay_price = it.getStringExtra("goods_pay_price"); goods_price = it.getStringExtra("goods_price"); goods_name = it.getStringExtra("goods_name"); tv_goods_pay_price = (TextView) findViewById(R.id.tv_goods_pay_price); tv_goods_pay_price.setText(goods_pay_price); tv_pay_price = (TextView) findViewById(R.id.tv_pay_price); tv_pay_price.setText(goods_pay_price); tv_goods_name = (TextView) findViewById(R.id.tv_goods_name); tv_goods_name.setText(goods_name); tv_goods_price = (TextView) findViewById(R.id.tv_goods_price); tv_goods_price.setText(goods_price); tv_goods_num = (TextView) findViewById(R.id.tv_goods_num); tv_goods_num.setText(goods_num); btn_sub = (Button) findViewById(R.id.btn_sub); btn_sub.setOnClickListener(this); check_1 = (CheckBox) findViewById(R.id.check_1); check_2 = (CheckBox) findViewById(R.id.check_2); ll_check_1 = (LinearLayout) findViewById(R.id.ll_check_1); ll_check_2 = (LinearLayout) findViewById(R.id.ll_check_2); ll_check_1.setOnClickListener(this); ll_check_2.setOnClickListener(this); et_pay_price = (EditText) findViewById(R.id.et_pay_price); et_pay_price.setText(goods_pay_price); et_goos_nnum = (EditText) findViewById(R.id.et_goos_nnum); et_goos_nnum.setText(goods_num); et_extend_msg = (EditText) findViewById(R.id.et_extend_msg); }
@Override public void onRefresh(SyncedObject.LocationListSyncedObject locationListSyncedObject) { String location = locationListSyncedObject.getLocationName(); String market = locationListSyncedObject.getLocationMarket(); Resources res = getActivity().getResources(); String titlewed = res.getString(R.string.ua_wedloctitle); String titlehome = res.getString(R.string.ua_homeloctitle); mIsNotifyTextChanged = false; if (!PlannerApplication.isEmptyOrNull(location)) { if (titlewed.equals(mLocationFrom)) { mWeddingLocationEditText.setText(location); mDefaultWeddingLocation = mWeddingLocationEditText.getText().toString(); mWeddingLocationMarketCode = market; } else if (titlehome.equals(mLocationFrom)) { mCityStateEditText.setText(location); mDefaultCityState = mCityStateEditText.getText().toString(); mHomeMarketCode = market; } } else { if (titlewed.equals(mLocationFrom) && mDefaultWeddingLocation != null) { mWeddingLocationEditText.setText(mDefaultWeddingLocation); } else if (titlehome.equals(mLocationFrom) && mDefaultCityState != null) { mCityStateEditText.setText(mDefaultCityState); } } }
void updateServerConfig(String host, int port) { currentHost = host; currentPort = port; Toast.makeText(this, "host" + host + "----port" + port, Toast.LENGTH_SHORT).show(); etHost.setText(currentHost); etPort.setText("" + currentPort); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); preferences = PreferenceManager.getDefaultSharedPreferences(this); addressField = (EditText) findViewById(addressText); portField = (EditText) findViewById(portText); intervalField = (EditText) findViewById(intervalText); addressField.setText(preferences.getString("address", null)); portField.setText(Integer.toString(preferences.getInt("port", 8080))); intervalField.setText(Integer.toString(preferences.getInt("interval", 10))); startButton = (ToggleButton) findViewById(R.id.startButton); service = new Intent(this, LocationService.class); startButton.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { /*service.putExtra("address", addressField.getText().toString()); service.putExtra("port", Integer.parseInt(portField.getText().toString())); service.putExtra("interval", Integer.parseInt(intervalField.getText().toString()));*/ updatePreferences(); System.out.println("Starting service act"); startService(service); } else { stopService(service); } } }); }
private void writeFrequency() { // get the text entered in edit box String text = mUserText.getText().toString(); try { int iFreq = Integer.parseInt(text); Float validFreq = UpdateFrequency(iFreq); if (validFreq != 0) { // reset the text in edit box for the next entry mUserText.setText(null); Bundle bundle = new Bundle(); bundle.putFloat(FREQ_VALUE, validFreq); Intent result = new Intent(); result.putExtras(bundle); setResult(RESULT_OK, result); finish(); } else { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setMessage("Enter valid frequency!!") .setNegativeButton(android.R.string.ok, null) .show(); mUserText.setText(null); } } catch (NumberFormatException nfe) { if (DBG) Log.d(TAG, "NumberFormatException:" + nfe.getMessage()); new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setMessage("Enter valid number!!") .setNegativeButton(android.R.string.ok, null) .show(); mUserText.setText(null); } }
public void cancel(View v) { // settext = '' edtFname.setText(""); edtLname.setText(""); edtEmail.setText(""); edtAge.setText(""); // set button color = blue btnAge.setBackgroundResource(R.drawable.button_custom); btnDob.setBackgroundResource(R.drawable.button_custom); btnUnborn.setBackgroundResource(R.drawable.button_custom); btnMale.setBackgroundResource(R.drawable.maleselector); btnFemale.setBackgroundResource(R.drawable.femaleselector); btnAge.setTextColor(Color.WHITE); btnDob.setTextColor(Color.WHITE); btnUnborn.setTextColor(Color.WHITE); // btnMale.setTextColor(Color.WHITE); // btnFemale.setTextColor(Color.WHITE); // reset visibility spYear.setVisibility(View.INVISIBLE); spMonth.setVisibility(View.INVISIBLE); spDay.setVisibility(View.INVISIBLE); edtAge.setVisibility(View.INVISIBLE); Intent i = new Intent(Profile_Edit.this, Profile_view.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.putExtra("EXIT", true); this.startActivity(i); // finish(); }
public void clear(View v) { eID.setText(""); eName.setText(""); eEmail.setText(""); eAccess.setText(""); eAccessconfirm.setText(""); female.setChecked(false); male.setChecked(false); affirm.setChecked(false); AccessText.setError("", null); AccessText.setTextColor(Color.BLACK); AccessConfirmText.setError("", null); AccessConfirmText.setTextColor(Color.BLACK); GenderText.setError("", null); GenderText.setTextColor(Color.BLACK); EmailText.setError("", null); EmailText.setTextColor(Color.BLACK); IDtext.setError("", null); IDtext.setTextColor(Color.BLACK); NameText.setError("", null); NameText.setTextColor(Color.BLACK); departmentSpinner.setSelection(0); }
@Override public void onValueChanged(BgSeekBar seekBar, int value, boolean fromUser, boolean usingKeys) { if (ignoreChanges) return; hsv.h = barH.getValue() / 360.0; hsv.s = barS.getValue() / 100.0; hsv.v = barV.getValue() / 100.0; currentColor = hsv.toRGB(false); if (seekBar == barH) { updateGS(); updateGV(); } else if (seekBar == barS) { updateGH(); updateGV(); } else if (seekBar == barV) { updateGH(); updateGS(); } ignoreChanges = true; txtH.setText(Integer.toString((int) (hsv.h * 360.0))); txtS.setText(Integer.toString((int) (hsv.s * 100.0))); txtV.setText(Integer.toString((int) (hsv.v * 100.0))); txt.setText(ColorUtils.toHexColor(currentColor)); ignoreChanges = false; barH.invalidate(); barS.invalidate(); barV.invalidate(); bgCurrent.setColor(currentColor); lblCurrent.invalidate(); }
private void calculatePerPersonTotal() { if (billTotal > 0 && finalTotal > 0 && noOfPeopleValue > 0) { perPersonAmountEditText.setText(getFormattedString(finalTotal / noOfPeopleValue)); } else { perPersonAmountEditText.setText(""); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_homework_edit); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); editName = (EditText) findViewById(R.id.homework_edit_name); editDesctription = (EditText) findViewById(R.id.homework_edit_description); Intent i = getIntent(); if (i != null) { id = i.getIntExtra(PARAMETER_ID, -1); if (id == -1) { Intent data = new Intent(); data.putExtra(PARAMETER_ID, id); setResult(RESULT_CANCELED, data); finishAfterTransition(); } else { String name = i.getStringExtra(PARAMETER_NAME); String description = i.getStringExtra(PARAMETER_DESCRIPTION); if (name != null && description != null) { editName.setText(name); editDesctription.setText(description); } } } }
public void onActivityResult(int requestCode, int resultCode, Intent resultData) { Uri currentUri = null; if (resultCode == Activity.RESULT_OK) { if (requestCode == CREATE_REQUEST_CODE) { if (resultData != null) { textView.setText(""); } } else if (requestCode == SAVE_REQUEST_CODE) { if (resultData != null) { currentUri = resultData.getData(); writeFileContent(currentUri); } } else if (requestCode == OPEN_REQUEST_CODE) { if (resultData != null) { currentUri = resultData.getData(); try { String content = readFileContent(currentUri); textView.setText(content); } catch (IOException e) { // 에러가 있을 때 처리하는 코드 } } } } }
// obsługa przycisku zatwierdz public void sendSmsByManager() { try { smsModel.setPhone(phoneNumber.getText().toString()); smsModel.setSms(smsBody.getText().toString() + " "); dateTextView.setText(""); timeTextView.setText(""); phoneNumber.setText(""); smsBody.setText(""); if (Patterns.PHONE.matcher(smsModel.getPhone()).matches()) { Message msg = Message.obtain(null, SMSService.SEND_SMS, 0, 0); Bundle bundle = new Bundle(); bundle.putParcelable("sms", smsModel); msg.setData(bundle); try { messenger.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } else { Toast.makeText(getApplicationContext(), R.string.invalidPhone, Toast.LENGTH_LONG).show(); } } catch (Exception ex) { Toast.makeText(getApplicationContext(), R.string.failedToSendSms, Toast.LENGTH_LONG).show(); ex.printStackTrace(); } }
// If you want location on changing place also than use below method // otherwise remove all below methods and don't implement location listener @Override public void onLocationChanged(Location arg0) { if (!working) return; Log.d("TEST", "LocationChanged"); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } l = lm.getLastKnownLocation(provider); double diff_x = Math.abs(l.getLongitude() - goList.get(active).getLongitude()) * degToM * Math.abs(Math.cos(l.getLatitude())); double diff_y = Math.abs(l.getLatitude() - goList.get(active).getLatitude()) * degToM; double dist = Math.sqrt(Math.pow(diff_x, 2) + Math.pow(diff_y, 2)); x.setText("" + diff_x); y.setText("" + diff_y); if (diff_x > TOLLERANCE || diff_y > TOLLERANCE) { currentDistance.setText( getString(R.string.activityGame_currentDistance_label, getDistance(dist))); } else { goToNextPoint(); } Log.d("ERROR", "Zginąłeś"); }
private void updateViewsBasedOnPromoCodeChange() { Button applyButton = (Button) findViewById(R.id.button_apply_promo); EditText promoText = (EditText) findViewById(R.id.edit_text_promo_code); if (printOrder.getPromoCode() != null) { promoText.setText(printOrder.getPromoCode()); promoText.setEnabled(false); applyButton.setText("Clear"); } else { promoText.setText(""); promoText.setEnabled(true); applyButton.setText("Apply"); } Button payWithCreditCardButton = (Button) findViewById(R.id.button_pay_with_credit_card); if (printOrder.getCost(printOrder.getCurrencyCode()).compareTo(BigDecimal.ZERO) <= 0) { findViewById(R.id.button_pay_with_paypal).setVisibility(View.GONE); payWithCreditCardButton.setText("Checkout for Free!"); payWithCreditCardButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { submitOrderForPrinting(null); } }); } else { findViewById(R.id.button_pay_with_paypal).setVisibility(View.VISIBLE); payWithCreditCardButton.setText("Pay with Credit Card"); } }
@Override public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); serverFields = root.findViewById(R.id.mpp_xmpp_server_fields); serverEditText = (EditText) root.findViewById(R.id.mpp_xmpp_server_edittext); loginEditText = (EditText) root.findViewById(R.id.mpp_xmpp_login_edittext); passwordEditText = (EditText) root.findViewById(R.id.mpp_xmpp_password_edittext); if (!isNewAccount()) { final XmppAccount realm = getEditedAccount(); final XmppAccountConfiguration configuration = realm.getConfiguration(); setupServerInput(root); serverEditText.setText(configuration.getServer()); loginEditText.setText(configuration.getLogin()); loginEditText.setEnabled(false); passwordEditText.setText(configuration.getPassword()); } else { setupServerInput(root); } final int loginHintResId = getLoginHintResId(); if (loginHintResId != NO_ID) { loginEditText.setHint(loginHintResId); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (searchMode == Var.SEARCH_YOUTUBE) { searchChannel = youtubeChannelSearch.get(position - 1); Log.d(TAG, searchChannel.toString()); addThumbnail(searchChannel.getThumbnail()); if (Var.isEmpty(userName_edt.getText().toString())) userName_edt.setText(searchChannel.getName()); name_tv.setText(searchChannel.getName()); imageLoader.DisplayImage(searchChannel.getThumbnail(), thumbnail_iv); toggleSearch(Var.SEARCH_YT_CHANNEL); searchChannel(); } if (searchMode == Var.SEARCH_TWITTER) { editUser.getMediaFeed().add(twitterFeedSearch.get(position - 1)); addThumbnail(twitterFeedSearch.get(position - 1).getThumbnail()); if (Var.isEmpty(userName_edt.getText().toString())) userName_edt.setText(twitterFeedSearch.get(position - 1).getDisplayName()); toggleSearch(Var.SEARCH_NONE); } }
public void setDate(Date date) { if (date == null) { mParent.setText(""); } else { mParent.setText(mFormat.format(date)); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mEditTextIp = (EditText) findViewById(R.id.editTextServerIp); mEditTextIp.setText(CavanAndroid.getPreference(this, KEY_SERVER_IP, DEFAULT_SERVER_IP)); mEditTextPort = (EditText) findViewById(R.id.editTextServerPort); mEditTextPort.setText(CavanAndroid.getPreference(this, KEY_SERVER_PORT, DEFAULT_SERVER_PORT)); mEditTextBdAddr = (EditText) findViewById(R.id.editTextBdAddr); mEditTextBdAddr.setKeyListener(null); mEditTextAddrRemain = (EditText) findViewById(R.id.editTextAddrRemain); mEditTextAddrRemain.setKeyListener(null); mButtonComplete = (Button) findViewById(R.id.buttonComplete); mButtonComplete.setOnClickListener(this); mButtonBurn = (Button) findViewById(R.id.buttonBurn); mButtonBurn.setOnClickListener(this); mButtonRequest = (Button) findViewById(R.id.buttonRequest); mButtonRequest.setOnClickListener(this); showScanActivity(); }
private void sendComment() { String comment = getComment(); String userinput = getUserInput(); if (userinput != null) { appendComment(BotAdapter.Type.Voice, userinput); etComment.setText(null); btnSendComment.setCurrentState(SendRequestButton.STATE_DONE); } if (comment != null) { appendComment(BotAdapter.Type.Voice, comment); etComment.setText(null); btnSendComment.setCurrentState(SendRequestButton.STATE_DONE); /*if (comment.equals("Calling")) // let's try and open Skype... { callSkype(); } else*/ // TODO remove after fix message tts.speak(comment, TextToSpeech.QUEUE_FLUSH, null, "1"); } }
@Override protected void onStart() { super.onStart(); utility.updateHeader( Utility.NO_FILE, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header); Intent intent = getIntent(); Serializable extra = intent.getSerializableExtra(EDIT_MOTOR_CONTROLLER_CONFIG); if (extra != null) { motorControllerConfigurationConfig = (MotorControllerConfiguration) extra; motors = (ArrayList<DeviceConfiguration>) motorControllerConfigurationConfig.getMotors(); motor1 = (MotorConfiguration) motors.get(0); motor2 = (MotorConfiguration) motors.get(1); controller_name.setText(motorControllerConfigurationConfig.getName()); motor1_name.setText(motor1.getName()); motor2_name.setText(motor2.getName()); addListenerOnPort1(); handleDisabledMotor(motor1, checkbox_motor1); addListenerOnPort2(); handleDisabledMotor(motor2, checkbox_motor2); } }
@AfterViews public void setPreferences() { SharedPreferences preferences = getActivity().getSharedPreferences("CurrentUser", Context.MODE_PRIVATE); accessToken = preferences.getString("access_token", "").replace("\"", ""); if (getArguments() != null) { Todo todo = (Todo) getArguments().getSerializable(NEW_INSTANCE_TODO_KEY); concernedMembers.addAll(todo.members); currentTodoId = todo.id; todoInput.setText(todo.text); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = new Date(); try { date = format.parse(todo.remindMeAt); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); SimpleDateFormat formatToShow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); formatToShow.setTimeZone(tz); String[] splitDate = formatToShow.format(date).split(" "); dateText.setText(splitDate[0]); timeText.setText(splitDate[1]); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); presenter = new LoginPresenter(this, new LoginService(this)); // register buttonn Login_OnClickButtonListener(); ClearDB_OnClickButtonListener(); RegistrationLink_OnClickListener(); // text handles header = (TextView) findViewById(R.id.textView_header); username = (EditText) findViewById(R.id.editText_username); password = (EditText) findViewById(R.id.editText_password); Typeface type = Typeface.createFromAsset(getAssets(), "fonts/Sansation-LightItalic.ttf"); Typeface glyphicons = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf"); // initialize values header.setTypeface(type); username.setText(""); username.setTypeface(glyphicons); username.setHint(" \uf007 Username"); password.setText(""); password.setTypeface(glyphicons); password.setHint(" \uf023 Password"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_item_edit); // retrieve selected item from the database // set values of the UI to that of the retrieved item selectedItem = MainActivity.database.getItem(MainActivity.SECONDARY_POSITION); nameEditText = (EditText) findViewById(R.id.nameEditText); priceEditText = (EditText) findViewById(R.id.priceEditText); paidEditText = (EditText) findViewById(R.id.paidEditText); remainingTextView = (TextView) findViewById(R.id.RemainingTextView); dateTextViewButton = (Button) findViewById(R.id.dateTextViewButton); doneCheckBox = (CheckBox) findViewById(R.id.doneCheckBox); nameEditText.setText("" + selectedItem.get_name()); priceEditText.setText("" + selectedItem.get_price()); paidEditText.setText("" + selectedItem.get_paid()); remainingTextView.setText("" + selectedItem.get_remaining()); doneCheckBox.setChecked((selectedItem.get_remaining() == 0) ? true : false); Formatter formatter = new Formatter(); dateTextViewButton.setText( formatter .format("\t %tF \t(Click To Edit)", selectedItem.get_deadline_calendar()) .toString()); formatter.close(); datePicker = new DatePickerFragment(); }
public void bind(PaslonEntity paslonEntity) { header.setText(paslonEntity.kind.toUpperCase()); namaCapil.setText(paslonEntity.nama); bod.setText(paslonEntity.pob + " / " + paslonEntity.dob); job.setText(paslonEntity.pekerjaan); address.setText(paslonEntity.alamat); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Get latitude and longitude double lat = getArguments().getDouble(BUNDLE_KEY_LAT); double lng = getArguments().getDouble(BUNDLE_KEY_LNG); loc = new LatLng(lat, lng); // Create the builder AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Set the title builder.setTitle("Pin a New Tak"); // Set the main content view LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.fragment_createtak, null); builder.setView(v); // Set positive and negative buttons builder.setPositiveButton("Pin", this); builder.setNegativeButton("Cancel", this); // Get widgets on the dialog fragment etTakName = (EditText) v.findViewById(R.id.addtak_et_takname); etTakDesc = (EditText) v.findViewById(R.id.addtak_et_description); etLat = (EditText) v.findViewById(R.id.addtak_et_lat); etLng = (EditText) v.findViewById(R.id.addtak_et_lng); // Add location passed in to the edit texts etLat.setText("" + loc.latitude); etLng.setText("" + loc.longitude); return builder.create(); }
/** * This callback-method has to be called from Fragment.onActivityResult within your fragment with * parameters directly on passthru.<br> * You can check in your fragment if it was really a RecognizerIntent that was handled here, if * so, this method returns true. In this case, you should call super.onActivityResult in your * fragment.onActivityResult. * * <p>If this method returns false, then it wasnt a request with a RecognizerIntent, so you can * handle these other requests as you need. * * @param activityRequestCode if this equals the requestCode specified by constructor, then * results of voice-recognition */ public boolean handleActivityResult( int activityRequestCode, int resultCode, Intent data, EditText textField) { boolean result = false; // handle the result of voice recognition, put it into the textfield if (activityRequestCode == this.requestCode) { // this was handled here, even if voicerecognition fails for any reason // so your program flow wont get chaotic if you dont explicitly state // your own requestCodes. result = true; if (resultCode == Activity.RESULT_OK) { // Fill the quickAddBox-view with the string the recognizer thought it could have heard ArrayList<String> match = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); // make sure we only do this if there is SomeThing (tm) returned if (match != null && match.size() > 0 && match.get(0).length() > 0) { String recognizedSpeech = match.get(0); recognizedSpeech = recognizedSpeech.substring(0, 1).toUpperCase() + recognizedSpeech.substring(1).toLowerCase(); if (append) { textField.setText((textField.getText() + " " + recognizedSpeech).trim()); } else { textField.setText(recognizedSpeech); } } } } return result; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_request); Bundle extras = getIntent().getExtras(); if (extras != null) { person = extras.getString("AVAILABILITY_PERSON"); price = extras.getString("AVAILABILITY_PRICE"); } TextView userNameText = (TextView) findViewById(R.id.userName); EditText priceEdit = (EditText) findViewById(R.id.approxPriceEditMyPosting); if (person != null) { userNameText.setText(person); } else { userNameText.setText("error"); } if (price != null) { priceEdit.setText(price); } else { priceEdit.setText("error"); } }
@Override public void doAfter(JSONArray jsonArray) { flProxy.setVisibility(View.GONE); if (jsonArray != null) { try { Gson gson = new Gson(); Response response = gson.fromJson(jsonArray.getJSONObject(0).toString(), Response.class); android.support.design.widget.Snackbar.make( findViewById(R.id.cl_container), response.getMessage(), android.support.design.widget.Snackbar.LENGTH_LONG) .show(); if (response.getStatus()) { etSubject.setText(""); etMessage.setText(""); } } catch (JSONException e) { e.printStackTrace(); } } else { android.support.design.widget.Snackbar.make( findViewById(R.id.cl_container), "Falhou, tente novamente.", android.support.design.widget.Snackbar.LENGTH_LONG) .show(); } }