Program: 35054
Project: 35054
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mAppContext=this;
  setContentView(R.layout.activity_calc);
  mCalc=Calculator.getCalculator(this);
  mDisplay=(EditTextDisplay)findViewById(R.id.textDisplay);
  mDisplay.setCalc(mCalc);
  mDisplay.disableSoftInputFromAppearing();
  mDisplay.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      mDisplay.selectAll();
      return false;
    }
  }
);
  mDisplay.setOnTouchListener(new View.OnTouchListener(){
    @Override public boolean onTouch(    View view,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mCalc.setSolved(false);
        mDisplay.setCursorVisible(true);
        mDisplay.clearHighlighted();
      }
      return false;
    }
  }
);
  FragmentManager fm=getSupportFragmentManager();
  mResultListFrag=(ResultListFragment)fm.findFragmentById(R.id.resultListfragmentContainer);
  if (mResultListFrag == null) {
    mResultListFrag=new ResultListFragment();
    fm.beginTransaction().add(R.id.resultListfragmentContainer,mResultListFrag).commit();
  }
  setupUnitTypePager();
  for (  int id : BUTTON_IDS) {
    final Button button=(Button)findViewById(id);
    if (id == R.id.equals_button)     mEqualsButton=button;
    if (id == R.id.percent_button) {
      ((AnimatedHoldButton)button).setPrimaryText(mCalc.mPreferences.getPercentButMain());
      ((AnimatedHoldButton)button).setSecondaryText(mCalc.mPreferences.getPercentButSec());
    }
    button.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View view){
        int buttonId=view.getId();
        String buttonValue="String_Node_Str";
switch (buttonId) {
case R.id.plus_button:
          buttonValue="String_Node_Str";
        break;
case R.id.minus_button:
      buttonValue="String_Node_Str";
    break;
case R.id.multiply_button:
  buttonValue="String_Node_Str";
break;
case R.id.divide_button:
buttonValue="String_Node_Str";
break;
case R.id.percent_button:
if (mCalc.mPreferences.getPercentButMain().equals("String_Node_Str")) buttonValue="String_Node_Str";
 else buttonValue="String_Node_Str";
break;
case R.id.decimal_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.clear_button:
buttonValue="String_Node_Str";
break;
case R.id.open_para_button:
buttonValue="String_Node_Str";
break;
case R.id.close_para_button:
buttonValue="String_Node_Str";
break;
case R.id.backspace_button:
buttonValue="String_Node_Str";
break;
default :
for (int i=0; i < 10; i++) if (buttonId == BUTTON_IDS[i]) buttonValue=String.valueOf(i);
}
numButtonPressed(buttonValue);
}
}
);
final LinearLayout mUnitContain=(LinearLayout)findViewById(R.id.unit_container);
button.setOnLongClickListener(new View.OnLongClickListener(){
@Override public boolean onLongClick(View view){
int buttonId=view.getId();
String buttonValue="String_Node_Str";
switch (buttonId) {
case R.id.multiply_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.percent_button:
if (mCalc.mPreferences.getPercentButSec().equals("String_Node_Str")) buttonValue="String_Node_Str";
 else buttonValue="String_Node_Str";
break;
case R.id.nine_button:
mCalc.refreshAllDynamicUnits(true);
break;
case R.id.minus_button:
buttonValue="String_Node_Str";
break;
case R.id.divide_button:
buttonValue="String_Node_Str";
break;
case R.id.eight_button:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
if (mUnitContain.getVisibility() == LinearLayout.GONE) {
mUnitContain.setVisibility(LinearLayout.VISIBLE);
updateScreen(true,true);
}
 else mUnitContain.setVisibility(LinearLayout.GONE);
}
break;
default :
return true;
}
if (!buttonValue.equals("String_Node_Str")) numButtonPressed(buttonValue);
return true;
}
}
);
if (button instanceof AnimatedHoldButton) {
final AnimatedHoldButton ahb=(AnimatedHoldButton)button;
ahb.setOnExtraLongClickListener(new AnimatedHoldButton.OnExtraLongClickListener(){
@Override public void onExtraLongClick(View view){
int buttonId=view.getId();
if (buttonId == R.id.percent_button) {
String main=mCalc.mPreferences.getPercentButMain();
String sec=mCalc.mPreferences.getPercentButSec();
mCalc.mPreferences.setPercentButMain(sec);
mCalc.mPreferences.setPercentButSec(main);
ViewUtils.toastLong("String_Node_Str" + sec,mAppContext);
}
}
}
);
}
}
ImageButton backspaceButton=(ImageButton)findViewById(R.id.backspace_button);
backspaceButton.setOnTouchListener(new View.OnTouchListener(){
private Handler mColorHoldHandler;
private Handler mResetHandler;
private View mView;
private static final int RESET_HOLD_TIME=2200;
private static final int CLEAR_HOLD_TIME=300;
@Override public boolean onTouch(View view,MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mView=view;
mInc=0;
if (mColorHoldHandler != null) return true;
mColorHoldHandler=new Handler();
mColorHoldHandler.postDelayed(mBackspaceColor,10);
if (mResetHandler != null) return true;
mResetHandler=new Handler();
mResetHandler.postDelayed(mBackspaceReset,RESET_HOLD_TIME);
break;
case MotionEvent.ACTION_UP:
if (mColorHoldHandler == null) return true;
if (mResetHandler == null) return true;
numButtonPressed("String_Node_Str");
view.setBackgroundColor(getResources().getColor(R.color.op_button_normal));
mColorHoldHandler.removeCallbacks(mBackspaceColor);
mColorHoldHandler=null;
mResetHandler.removeCallbacks(mBackspaceReset);
mResetHandler=null;
break;
}
return false;
}
Runnable mBackspaceReset=new Runnable(){
@Override public void run(){
mCalc.resetCalc();
setupUnitTypePager();
updateScreen(true);
ViewUtils.toastCentered("String_Node_Str",mAppContext);
}
}
;
private int mInc;
Runnable mBackspaceColor=new Runnable(){
private int mStartColor=getResources().getColor(R.color.op_button_pressed);
private int mEndColor=getResources().getColor(R.color.backspace_button_held);
private static final int NUM_COLOR_CHANGES=10;
@Override public void run(){
if (mInc == -1) {
mView.setBackgroundColor(mEndColor);
return;
}
if (mInc == NUM_COLOR_CHANGES) {
numButtonPressed("String_Node_Str");
mView.setBackgroundColor(Color.argb(255,0,0,0));
mColorHoldHandler.postDelayed(this,100);
mInc=-1;
return;
}
mColorHoldHandler.postDelayed(this,CLEAR_HOLD_TIME / NUM_COLOR_CHANGES);
float deltaRed=(float)Color.red(mStartColor) + ((float)Color.red(mEndColor) - (float)Color.red(mStartColor)) * ((float)mInc * (float)mInc * (float)mInc) / ((float)NUM_COLOR_CHANGES * (float)NUM_COLOR_CHANGES * (float)NUM_COLOR_CHANGES);
int deltaGreen=Color.green(mStartColor) + ((Color.green(mEndColor) - Color.green(mStartColor)) * mInc) / NUM_COLOR_CHANGES;
int deltaBlue=Color.blue(mStartColor) + ((Color.blue(mEndColor) - Color.blue(mStartColor)) * mInc) / NUM_COLOR_CHANGES;
mView.setBackgroundColor(Color.argb(255,(int)deltaRed,deltaGreen,deltaBlue));
mInc++;
}
}
;
}
);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mAppContext=this;
  setContentView(R.layout.activity_calc);
  mCalc=Calculator.getCalculator(this);
  mDisplay=(EditTextDisplay)findViewById(R.id.textDisplay);
  mDisplay.setCalc(mCalc);
  mDisplay.disableSoftInputFromAppearing();
  mDisplay.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      mDisplay.selectAll();
      return false;
    }
  }
);
  mDisplay.setOnTouchListener(new View.OnTouchListener(){
    @Override public boolean onTouch(    View view,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mCalc.setSolved(false);
        mDisplay.setCursorVisible(true);
        mDisplay.clearHighlighted();
      }
      return false;
    }
  }
);
  FragmentManager fm=getSupportFragmentManager();
  mResultListFrag=(ResultListFragment)fm.findFragmentById(R.id.resultListfragmentContainer);
  if (mResultListFrag == null) {
    mResultListFrag=new ResultListFragment();
    fm.beginTransaction().add(R.id.resultListfragmentContainer,mResultListFrag).commit();
  }
  setupUnitTypePager();
  for (  int id : BUTTON_IDS) {
    final Button button=(Button)findViewById(id);
    if (id == R.id.equals_button)     mEqualsButton=button;
    if (id == R.id.percent_button) {
      ((AnimatedHoldButton)button).setPrimaryText(mCalc.mPreferences.getPercentButMain());
      ((AnimatedHoldButton)button).setSecondaryText(mCalc.mPreferences.getPercentButSec());
    }
    button.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View view){
        int buttonId=view.getId();
        String buttonValue="String_Node_Str";
switch (buttonId) {
case R.id.plus_button:
          buttonValue="String_Node_Str";
        break;
case R.id.minus_button:
      buttonValue="String_Node_Str";
    break;
case R.id.multiply_button:
  buttonValue="String_Node_Str";
break;
case R.id.divide_button:
buttonValue="String_Node_Str";
break;
case R.id.percent_button:
if (mCalc.mPreferences.getPercentButMain().equals("String_Node_Str")) buttonValue="String_Node_Str";
 else buttonValue="String_Node_Str";
break;
case R.id.decimal_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.clear_button:
buttonValue="String_Node_Str";
break;
case R.id.open_para_button:
buttonValue="String_Node_Str";
break;
case R.id.close_para_button:
buttonValue="String_Node_Str";
break;
case R.id.backspace_button:
buttonValue="String_Node_Str";
break;
default :
for (int i=0; i < 10; i++) if (buttonId == BUTTON_IDS[i]) buttonValue=String.valueOf(i);
}
numButtonPressed(buttonValue);
}
}
);
final LinearLayout mUnitContain=(LinearLayout)findViewById(R.id.unit_container);
button.setOnLongClickListener(new View.OnLongClickListener(){
@Override public boolean onLongClick(View view){
int buttonId=view.getId();
String buttonValue="String_Node_Str";
switch (buttonId) {
case R.id.multiply_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.percent_button:
if (mCalc.mPreferences.getPercentButSec().equals("String_Node_Str")) buttonValue="String_Node_Str";
 else buttonValue="String_Node_Str";
break;
case R.id.nine_button:
mCalc.refreshAllDynamicUnits(true);
break;
case R.id.minus_button:
buttonValue="String_Node_Str";
break;
case R.id.divide_button:
buttonValue="String_Node_Str";
break;
case R.id.eight_button:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
if (mUnitContain.getVisibility() == LinearLayout.GONE) {
mUnitContain.setVisibility(LinearLayout.VISIBLE);
updateScreen(true,true);
}
 else mUnitContain.setVisibility(LinearLayout.GONE);
}
break;
default :
return true;
}
if (!buttonValue.equals("String_Node_Str")) numButtonPressed(buttonValue);
return true;
}
}
);
if (button instanceof AnimatedHoldButton) {
final AnimatedHoldButton ahb=(AnimatedHoldButton)button;
ahb.setOnExtraLongClickListener(new AnimatedHoldButton.OnExtraLongClickListener(){
@Override public void onExtraLongClick(View view){
int buttonId=view.getId();
if (buttonId == R.id.percent_button) {
String main=mCalc.mPreferences.getPercentButMain();
String sec=mCalc.mPreferences.getPercentButSec();
mCalc.mPreferences.setPercentButMain(sec);
mCalc.mPreferences.setPercentButSec(main);
ViewUtils.toastLong("String_Node_Str" + sec,mAppContext);
ahb.setPrimaryText(sec);
ahb.setSecondaryText(main);
ahb.invalidate();
}
}
}
);
}
}
ImageButton backspaceButton=(ImageButton)findViewById(R.id.backspace_button);
backspaceButton.setOnTouchListener(new View.OnTouchListener(){
private Handler mColorHoldHandler;
private Handler mResetHandler;
private View mView;
private static final int RESET_HOLD_TIME=2200;
private static final int CLEAR_HOLD_TIME=300;
@Override public boolean onTouch(View view,MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mView=view;
mInc=0;
if (mColorHoldHandler != null) return true;
mColorHoldHandler=new Handler();
mColorHoldHandler.postDelayed(mBackspaceColor,10);
if (mResetHandler != null) return true;
mResetHandler=new Handler();
mResetHandler.postDelayed(mBackspaceReset,RESET_HOLD_TIME);
break;
case MotionEvent.ACTION_UP:
if (mColorHoldHandler == null) return true;
if (mResetHandler == null) return true;
numButtonPressed("String_Node_Str");
view.setBackgroundColor(getResources().getColor(R.color.op_button_normal));
mColorHoldHandler.removeCallbacks(mBackspaceColor);
mColorHoldHandler=null;
mResetHandler.removeCallbacks(mBackspaceReset);
mResetHandler=null;
break;
}
return false;
}
Runnable mBackspaceReset=new Runnable(){
@Override public void run(){
mCalc.resetCalc();
setupUnitTypePager();
updateScreen(true);
ViewUtils.toastCentered("String_Node_Str",mAppContext);
}
}
;
private int mInc;
Runnable mBackspaceColor=new Runnable(){
private int mStartColor=getResources().getColor(R.color.op_button_pressed);
private int mEndColor=getResources().getColor(R.color.backspace_button_held);
private static final int NUM_COLOR_CHANGES=10;
@Override public void run(){
if (mInc == -1) {
mView.setBackgroundColor(mEndColor);
return;
}
if (mInc == NUM_COLOR_CHANGES) {
numButtonPressed("String_Node_Str");
mView.setBackgroundColor(Color.argb(255,0,0,0));
mColorHoldHandler.postDelayed(this,100);
mInc=-1;
return;
}
mColorHoldHandler.postDelayed(this,CLEAR_HOLD_TIME / NUM_COLOR_CHANGES);
float deltaRed=(float)Color.red(mStartColor) + ((float)Color.red(mEndColor) - (float)Color.red(mStartColor)) * ((float)mInc * (float)mInc * (float)mInc) / ((float)NUM_COLOR_CHANGES * (float)NUM_COLOR_CHANGES * (float)NUM_COLOR_CHANGES);
int deltaGreen=Color.green(mStartColor) + ((Color.green(mEndColor) - Color.green(mStartColor)) * mInc) / NUM_COLOR_CHANGES;
int deltaBlue=Color.blue(mStartColor) + ((Color.blue(mEndColor) - Color.blue(mStartColor)) * mInc) / NUM_COLOR_CHANGES;
mView.setBackgroundColor(Color.argb(255,(int)deltaRed,deltaGreen,deltaBlue));
mInc++;
}
}
;
}
);
}