Advertisement
Guest User

Stack overflowing

a guest
Sep 18th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. class SynchronizingWatcher implements TextWatcher {
  2.  
  3.         Set<EditText> synchronizedViews = new HashSet<EditText>();
  4.        
  5.         public void watchView(EditText view) {
  6.             view.addTextChangedListener(this);
  7.             synchronizedViews.add(view);
  8.         }
  9.        
  10.         public void afterTextChanged(Editable arg0) {
  11.             for(EditText editText : synchronizedViews) {
  12.                 editText.removeTextChangedListener(this);
  13.                
  14.                 if(editText.equals((EditText) findViewById(R.id.editText1))) {
  15.                     EditText width = (EditText) findViewById(R.id.editText1);
  16.                     EditText height = (EditText) findViewById(R.id.editText2);
  17.  
  18.                     if(width.getText().toString().equals("")) {
  19.                         return;
  20.                     }
  21.                                        
  22.                     double dWidth = Double.parseDouble(width.getText().toString());
  23.                     double coefficient = dWidth / IMAGE_WIDTH;
  24.                     double newHeight = coefficient * IMAGE_HEIGHT;
  25.                     double roundedHeight = Math.round(newHeight);
  26.                     String heightDoubleString = String.valueOf(Double.toString(roundedHeight));
  27.                     String heightString = heightDoubleString.substring(0, heightDoubleString.length() - 2);
  28.                     int insert = Integer.parseInt(heightString);
  29.                    
  30.                     height.setText(String.valueOf(insert));
  31.                 }
  32.                
  33.                 if(editText.equals((EditText) findViewById(R.id.editText2))) {
  34.                     EditText width = (EditText) findViewById(R.id.editText1);
  35.                     EditText height = (EditText) findViewById(R.id.editText2);
  36.  
  37.                     if(height.getText().toString().equals("")) {
  38.                         return;
  39.                     }
  40.                                        
  41.                     double dHeight = Double.parseDouble(height.getText().toString());
  42.                     double coefficient = dHeight / IMAGE_HEIGHT;
  43.                     double newWidth = coefficient * IMAGE_WIDTH;
  44.                     double roundedWidth = Math.round(newWidth);
  45.                     String widthDoubleString = String.valueOf(Double.toString(roundedWidth));
  46.                     String widthString = widthDoubleString.substring(0, widthDoubleString.length() - 2);
  47.                     int insert = Integer.parseInt(widthString);
  48.                    
  49.                     width.setText(String.valueOf(insert));
  50.                 }
  51.  
  52.                 editText.addTextChangedListener(this);
  53.             }
  54.         }
  55.  
  56.         public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
  57.  
  58.         public void onTextChanged(CharSequence s, int start, int before, int count) {}
  59.        
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement