Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SynchronizingWatcher implements TextWatcher {
- Set<EditText> synchronizedViews = new HashSet<EditText>();
- public void watchView(EditText view) {
- view.addTextChangedListener(this);
- synchronizedViews.add(view);
- }
- public void afterTextChanged(Editable arg0) {
- for(EditText editText : synchronizedViews) {
- editText.removeTextChangedListener(this);
- if(editText.equals((EditText) findViewById(R.id.editText1))) {
- EditText width = (EditText) findViewById(R.id.editText1);
- EditText height = (EditText) findViewById(R.id.editText2);
- if(width.getText().toString().equals("")) {
- return;
- }
- double dWidth = Double.parseDouble(width.getText().toString());
- double coefficient = dWidth / IMAGE_WIDTH;
- double newHeight = coefficient * IMAGE_HEIGHT;
- double roundedHeight = Math.round(newHeight);
- String heightDoubleString = String.valueOf(Double.toString(roundedHeight));
- String heightString = heightDoubleString.substring(0, heightDoubleString.length() - 2);
- int insert = Integer.parseInt(heightString);
- height.setText(String.valueOf(insert));
- }
- if(editText.equals((EditText) findViewById(R.id.editText2))) {
- EditText width = (EditText) findViewById(R.id.editText1);
- EditText height = (EditText) findViewById(R.id.editText2);
- if(height.getText().toString().equals("")) {
- return;
- }
- double dHeight = Double.parseDouble(height.getText().toString());
- double coefficient = dHeight / IMAGE_HEIGHT;
- double newWidth = coefficient * IMAGE_WIDTH;
- double roundedWidth = Math.round(newWidth);
- String widthDoubleString = String.valueOf(Double.toString(roundedWidth));
- String widthString = widthDoubleString.substring(0, widthDoubleString.length() - 2);
- int insert = Integer.parseInt(widthString);
- width.setText(String.valueOf(insert));
- }
- editText.addTextChangedListener(this);
- }
- }
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement