Program: 14997
Project: 14997
Buggy source:
@Override public boolean onTouch(View v,MotionEvent event){
  if (mFormatBar.getVisibility() != View.VISIBLE)   showFormatBar();
  float pos=event.getY();
  if (event.getAction() == 0)   mLastYPos=pos;
  if (event.getAction() > 1) {
    if (((mLastYPos - pos) > 2.0f) || ((pos - mLastYPos) > 2.0f))     mScrollDetected=true;
  }
  mLastYPos=pos;
  if (event.getAction() == 1 && !mScrollDetected) {
    Layout layout=((TextView)v).getLayout();
    int x=(int)event.getX();
    int y=(int)event.getY();
    x+=v.getScrollX();
    y+=v.getScrollY();
    if (layout != null) {
      int line=layout.getLineForVertical(y);
      int charPosition=layout.getOffsetForHorizontal(line,x);
      final Spannable s=mContentEditText.getText();
      WPImageSpan[] image_spans=s.getSpans(charPosition,charPosition,WPImageSpan.class);
      if (image_spans.length != 0) {
        final WPImageSpan span=image_spans[0];
        if (!span.isVideo()) {
          LayoutInflater factory=LayoutInflater.from(EditPostActivity.this);
          final View alertView=factory.inflate(R.layout.alert_image_options,null);
          final EditText imageWidthText=(EditText)alertView.findViewById(R.id.imageWidthText);
          final EditText titleText=(EditText)alertView.findViewById(R.id.title);
          final EditText caption=(EditText)alertView.findViewById(R.id.caption);
          final CheckBox featuredCheckBox=(CheckBox)alertView.findViewById(R.id.featuredImage);
          final CheckBox featuredInPostCheckBox=(CheckBox)alertView.findViewById(R.id.featuredInPost);
          if (WordPress.getCurrentBlog().isFeaturedImageCapable()) {
            featuredCheckBox.setVisibility(View.VISIBLE);
            featuredInPostCheckBox.setVisibility(View.VISIBLE);
          }
          featuredCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            @Override public void onCheckedChanged(            CompoundButton buttonView,            boolean isChecked){
              if (isChecked) {
                featuredInPostCheckBox.setVisibility(View.VISIBLE);
              }
 else {
                featuredInPostCheckBox.setVisibility(View.GONE);
              }
            }
          }
);
          final SeekBar seekBar=(SeekBar)alertView.findViewById(R.id.imageWidth);
          final Spinner alignmentSpinner=(Spinner)alertView.findViewById(R.id.alignment_spinner);
          ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(EditPostActivity.this,R.array.alignment_array,android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          alignmentSpinner.setAdapter(adapter);
          imageWidthText.setText(String.valueOf(span.getWidth()) + "String_Node_Str");
          seekBar.setProgress(span.getWidth());
          titleText.setText(span.getTitle());
          caption.setText(span.getCaption());
          featuredCheckBox.setChecked(span.isFeatured());
          if (span.isFeatured())           featuredInPostCheckBox.setVisibility(View.VISIBLE);
 else           featuredInPostCheckBox.setVisibility(View.GONE);
          featuredInPostCheckBox.setChecked(span.isFeaturedInPost());
          alignmentSpinner.setSelection(span.getHorizontalAlignment(),true);
          final int maxWidth=getMinimumImageWitdh(span.getImageSource());
          seekBar.setMax(maxWidth / 10);
          if (span.getWidth() != 0)           seekBar.setProgress(span.getWidth() / 10);
          seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
            @Override public void onStopTrackingTouch(            SeekBar seekBar){
            }
            @Override public void onStartTrackingTouch(            SeekBar seekBar){
            }
            @Override public void onProgressChanged(            SeekBar seekBar,            int progress,            boolean fromUser){
              if (progress == 0)               progress=1;
              imageWidthText.setText(progress * 10 + "String_Node_Str");
            }
          }
);
          imageWidthText.setOnFocusChangeListener(new OnFocusChangeListener(){
            @Override public void onFocusChange(            View v,            boolean hasFocus){
              if (hasFocus) {
                imageWidthText.setText("String_Node_Str");
              }
            }
          }
);
          imageWidthText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
            @Override public boolean onEditorAction(            TextView v,            int actionId,            KeyEvent event){
              int width=getEditTextIntegerClamped(imageWidthText,10,maxWidth);
              seekBar.setProgress(width / 10);
              imageWidthText.setSelection((String.valueOf(width).length()));
              InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(imageWidthText.getWindowToken(),InputMethodManager.RESULT_UNCHANGED_SHOWN);
              return true;
            }
          }
);
          AlertDialog ad=new AlertDialog.Builder(EditPostActivity.this).setTitle(getString(R.string.image_settings)).setView(alertView).setPositiveButton(getString(R.string.ok),new DialogInterface.OnClickListener(){
            public void onClick(            DialogInterface dialog,            int whichButton){
              span.setTitle(titleText.getText().toString());
              span.setHorizontalAlignment(alignmentSpinner.getSelectedItemPosition());
              span.setWidth(getEditTextIntegerClamped(imageWidthText,10,maxWidth));
              span.setCaption(caption.getText().toString());
              span.setFeatured(featuredCheckBox.isChecked());
              if (featuredCheckBox.isChecked()) {
                WPImageSpan[] click_spans=s.getSpans(0,s.length(),WPImageSpan.class);
                if (click_spans.length > 1) {
                  for (int i=0; i < click_spans.length; i++) {
                    WPImageSpan verifySpan=click_spans[i];
                    if (verifySpan != span) {
                      verifySpan.setFeatured(false);
                      verifySpan.setFeaturedInPost(false);
                    }
                  }
                }
              }
              span.setFeaturedInPost(featuredInPostCheckBox.isChecked());
            }
          }
).setNegativeButton(getString(R.string.cancel),new DialogInterface.OnClickListener(){
            public void onClick(            DialogInterface dialog,            int whichButton){
              dialog.dismiss();
            }
          }
).create();
          ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
          ad.show();
          mScrollDetected=false;
          return true;
        }
      }
 else {
        mContentEditText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
        mContentEditText.setSelection(mContentEditText.getSelectionStart());
      }
      MediaGalleryImageSpan[] gallerySpans=s.getSpans(charPosition,charPosition,MediaGalleryImageSpan.class);
      if (gallerySpans.length > 0) {
        final MediaGalleryImageSpan gallerySpan=gallerySpans[0];
        startMediaGalleryActivity(gallerySpan.getMediaGallery());
      }
    }
  }
 else   if (event.getAction() == 1) {
    mScrollDetected=false;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onTouch(View v,MotionEvent event){
  if (mFormatBar.getVisibility() != View.VISIBLE) {
    showFormatBar();
  }
  float pos=event.getY();
  if (event.getAction() == 0)   mLastYPos=pos;
  if (event.getAction() > 1) {
    if (((mLastYPos - pos) > 2.0f) || ((pos - mLastYPos) > 2.0f))     mScrollDetected=true;
  }
  mLastYPos=pos;
  if (event.getAction() == 1 && !mScrollDetected) {
    Layout layout=((TextView)v).getLayout();
    int x=(int)event.getX();
    int y=(int)event.getY();
    x+=v.getScrollX();
    y+=v.getScrollY();
    if (layout != null) {
      int line=layout.getLineForVertical(y);
      int charPosition=layout.getOffsetForHorizontal(line,x);
      final Spannable s=mContentEditText.getText();
      WPImageSpan[] image_spans=s.getSpans(charPosition,charPosition,WPImageSpan.class);
      if (image_spans.length != 0) {
        final WPImageSpan span=image_spans[0];
        if (!span.isVideo()) {
          LayoutInflater factory=LayoutInflater.from(EditPostActivity.this);
          final View alertView=factory.inflate(R.layout.alert_image_options,null);
          final EditText imageWidthText=(EditText)alertView.findViewById(R.id.imageWidthText);
          final EditText titleText=(EditText)alertView.findViewById(R.id.title);
          final EditText caption=(EditText)alertView.findViewById(R.id.caption);
          final CheckBox featuredCheckBox=(CheckBox)alertView.findViewById(R.id.featuredImage);
          final CheckBox featuredInPostCheckBox=(CheckBox)alertView.findViewById(R.id.featuredInPost);
          if (WordPress.getCurrentBlog().isFeaturedImageCapable()) {
            featuredCheckBox.setVisibility(View.VISIBLE);
            featuredInPostCheckBox.setVisibility(View.VISIBLE);
          }
          featuredCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            @Override public void onCheckedChanged(            CompoundButton buttonView,            boolean isChecked){
              if (isChecked) {
                featuredInPostCheckBox.setVisibility(View.VISIBLE);
              }
 else {
                featuredInPostCheckBox.setVisibility(View.GONE);
              }
            }
          }
);
          final SeekBar seekBar=(SeekBar)alertView.findViewById(R.id.imageWidth);
          final Spinner alignmentSpinner=(Spinner)alertView.findViewById(R.id.alignment_spinner);
          ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(EditPostActivity.this,R.array.alignment_array,android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          alignmentSpinner.setAdapter(adapter);
          imageWidthText.setText(String.valueOf(span.getWidth()) + "String_Node_Str");
          seekBar.setProgress(span.getWidth());
          titleText.setText(span.getTitle());
          caption.setText(span.getCaption());
          featuredCheckBox.setChecked(span.isFeatured());
          if (span.isFeatured())           featuredInPostCheckBox.setVisibility(View.VISIBLE);
 else           featuredInPostCheckBox.setVisibility(View.GONE);
          featuredInPostCheckBox.setChecked(span.isFeaturedInPost());
          alignmentSpinner.setSelection(span.getHorizontalAlignment(),true);
          final int maxWidth=getMinimumImageWitdh(span.getImageSource());
          seekBar.setMax(maxWidth / 10);
          if (span.getWidth() != 0)           seekBar.setProgress(span.getWidth() / 10);
          seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
            @Override public void onStopTrackingTouch(            SeekBar seekBar){
            }
            @Override public void onStartTrackingTouch(            SeekBar seekBar){
            }
            @Override public void onProgressChanged(            SeekBar seekBar,            int progress,            boolean fromUser){
              if (progress == 0)               progress=1;
              imageWidthText.setText(progress * 10 + "String_Node_Str");
            }
          }
);
          imageWidthText.setOnFocusChangeListener(new OnFocusChangeListener(){
            @Override public void onFocusChange(            View v,            boolean hasFocus){
              if (hasFocus) {
                imageWidthText.setText("String_Node_Str");
              }
            }
          }
);
          imageWidthText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
            @Override public boolean onEditorAction(            TextView v,            int actionId,            KeyEvent event){
              int width=getEditTextIntegerClamped(imageWidthText,10,maxWidth);
              seekBar.setProgress(width / 10);
              imageWidthText.setSelection((String.valueOf(width).length()));
              InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(imageWidthText.getWindowToken(),InputMethodManager.RESULT_UNCHANGED_SHOWN);
              return true;
            }
          }
);
          AlertDialog ad=new AlertDialog.Builder(EditPostActivity.this).setTitle(getString(R.string.image_settings)).setView(alertView).setPositiveButton(getString(R.string.ok),new DialogInterface.OnClickListener(){
            public void onClick(            DialogInterface dialog,            int whichButton){
              span.setTitle(titleText.getText().toString());
              span.setHorizontalAlignment(alignmentSpinner.getSelectedItemPosition());
              span.setWidth(getEditTextIntegerClamped(imageWidthText,10,maxWidth));
              span.setCaption(caption.getText().toString());
              span.setFeatured(featuredCheckBox.isChecked());
              if (featuredCheckBox.isChecked()) {
                WPImageSpan[] click_spans=s.getSpans(0,s.length(),WPImageSpan.class);
                if (click_spans.length > 1) {
                  for (int i=0; i < click_spans.length; i++) {
                    WPImageSpan verifySpan=click_spans[i];
                    if (verifySpan != span) {
                      verifySpan.setFeatured(false);
                      verifySpan.setFeaturedInPost(false);
                    }
                  }
                }
              }
              span.setFeaturedInPost(featuredInPostCheckBox.isChecked());
            }
          }
).setNegativeButton(getString(R.string.cancel),new DialogInterface.OnClickListener(){
            public void onClick(            DialogInterface dialog,            int whichButton){
              dialog.dismiss();
            }
          }
).create();
          ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
          ad.show();
          mScrollDetected=false;
          return true;
        }
      }
 else {
        mContentEditText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
        mContentEditText.setSelection(mContentEditText.getSelectionStart());
      }
      MediaGalleryImageSpan[] gallerySpans=s.getSpans(charPosition,charPosition,MediaGalleryImageSpan.class);
      if (gallerySpans.length > 0) {
        final MediaGalleryImageSpan gallerySpan=gallerySpans[0];
        startMediaGalleryActivity(gallerySpan.getMediaGallery());
      }
    }
  }
 else   if (event.getAction() == 1) {
    mScrollDetected=false;
  }
  return false;
}