Program: 35134
Project: 35134
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_calc);
  mCalc=Calculator.getCalculator(this);
  mDisplay=(EditTextCursorWatcher)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);
      }
      return false;
    }
  }
);
  FragmentManager fm=getSupportFragmentManager();
  mResultFragment=(ResultListFragment)fm.findFragmentById(R.id.resultListfragmentContainer);
  if (mResultFragment == null) {
    mResultFragment=new ResultListFragment();
    fm.beginTransaction().add(R.id.resultListfragmentContainer,mResultFragment).commit();
  }
  mConvKeysViewPager=(ViewPager)findViewById(R.id.convertKeyPager);
  mConvKeysViewPager.setAdapter(new FragmentStatePagerAdapter(fm){
    @Override public int getCount(){
      return mCalc.getUnitTypeSize();
    }
    @Override public Fragment getItem(    int pos){
      return ConvKeysFragment.newInstance(pos);
    }
  }
);
  mConvKeysViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){
    @Override public void onPageSelected(    int pos){
      mCalc.getCurrUnitType().clearUnitSelection();
      updateScreen(false);
      mCalc.setUnitTypePos(pos);
      DisplayMetrics metrics=getResources().getDisplayMetrics();
      int padLeft=(int)(metrics.density * 8f + 0.5f);
      int padRight=(int)(metrics.density * 8f + 0.5f);
      mConvKeysViewPager.setPadding(padLeft,0,padRight,0);
      if (unitToSelectAfterScroll != null) {
        FragmentStatePagerAdapter tempAdapter=(FragmentStatePagerAdapter)mConvKeysViewPager.getAdapter();
        ConvKeysFragment currFrag=(ConvKeysFragment)tempAdapter.instantiateItem(mConvKeysViewPager,mConvKeysViewPager.getCurrentItem());
        currFrag.selectUnit(unitToSelectAfterScroll);
        unitToSelectAfterScroll=null;
      }
    }
    @Override public void onPageScrolled(    int pos,    float posOffset,    int posOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
    }
  }
);
  DisplayMetrics metrics=getResources().getDisplayMetrics();
  int padLeft=(int)(metrics.density * 8f + 0.5f);
  int padRight=padLeft;
  mConvKeysViewPager.setPadding(padLeft,0,padRight,0);
  mConvKeysViewPager.setClipToPadding(false);
  mConvKeysViewPager.setPageMargin(8);
  mConvKeysViewPager.setCurrentItem(2);
  calcButton=new ArrayList<Button>();
  for (  int id : BUTTON_IDS) {
    Button button=(Button)findViewById(id);
    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.decimal_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.ee_button:
buttonValue="String_Node_Str";
break;
case R.id.power_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);
}
}
);
calcButton.add(button);
}
ImageButton backspaceButton=(ImageButton)findViewById(R.id.backspace_button);
backspaceButton.setOnTouchListener(new View.OnTouchListener(){
private Handler mColorHoldHandler;
private View mView;
@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);
break;
case MotionEvent.ACTION_UP:
if (mColorHoldHandler == null) return true;
numButtonPressed("String_Node_Str");
view.setBackgroundColor(getResources().getColor(R.color.op_button_normal));
mColorHoldHandler.removeCallbacks(mBackspaceColor);
mColorHoldHandler=null;
break;
}
return false;
}
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;
private static final int BACKSPACE_HOLD_TIME=500;
@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,BACKSPACE_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));
System.out.println("String_Node_Str" + deltaRed);
System.out.println("String_Node_Str" + ((Color.red(mEndColor) - Color.red(mStartColor)) * mInc ^ 3));
System.out.println("String_Node_Str" + mInc);
mInc++;
}
}
;
}
);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_calc);
  mCalc=Calculator.getCalculator(this);
  mDisplay=(EditTextCursorWatcher)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);
      }
      return false;
    }
  }
);
  FragmentManager fm=getSupportFragmentManager();
  mResultFragment=(ResultListFragment)fm.findFragmentById(R.id.resultListfragmentContainer);
  if (mResultFragment == null) {
    mResultFragment=new ResultListFragment();
    fm.beginTransaction().add(R.id.resultListfragmentContainer,mResultFragment).commit();
  }
  mConvKeysViewPager=(ViewPager)findViewById(R.id.convertKeyPager);
  mConvKeysViewPager.setAdapter(new FragmentStatePagerAdapter(fm){
    @Override public int getCount(){
      return mCalc.getUnitTypeSize();
    }
    @Override public Fragment getItem(    int pos){
      return ConvKeysFragment.newInstance(pos);
    }
  }
);
  mConvKeysViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){
    @Override public void onPageSelected(    int pos){
      mCalc.setUnitTypePos(pos);
      DisplayMetrics metrics=getResources().getDisplayMetrics();
      int padLeft=(int)(metrics.density * 8f + 0.5f);
      int padRight=(int)(metrics.density * 8f + 0.5f);
      mConvKeysViewPager.setPadding(padLeft,0,padRight,0);
      int currConvKeyPos=mConvKeysViewPager.getCurrentItem();
      clearConvKeyForFragPos(currConvKeyPos - 1);
      clearConvKeyForFragPos(currConvKeyPos + 1);
      if (unitToSelectAfterScroll != null) {
        getConvKeyFrag(mConvKeysViewPager.getCurrentItem()).selectUnit(unitToSelectAfterScroll);
        unitToSelectAfterScroll=null;
      }
    }
    @Override public void onPageScrolled(    int pos,    float posOffset,    int posOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
    }
  }
);
  DisplayMetrics metrics=getResources().getDisplayMetrics();
  int padLeft=(int)(metrics.density * 8f + 0.5f);
  int padRight=padLeft;
  mConvKeysViewPager.setPadding(padLeft,0,padRight,0);
  mConvKeysViewPager.setClipToPadding(false);
  mConvKeysViewPager.setPageMargin(8);
  mConvKeysViewPager.setCurrentItem(2);
  calcButton=new ArrayList<Button>();
  for (  int id : BUTTON_IDS) {
    Button button=(Button)findViewById(id);
    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.decimal_button:
buttonValue="String_Node_Str";
break;
case R.id.equals_button:
buttonValue="String_Node_Str";
break;
case R.id.ee_button:
buttonValue="String_Node_Str";
break;
case R.id.power_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);
}
}
);
calcButton.add(button);
}
ImageButton backspaceButton=(ImageButton)findViewById(R.id.backspace_button);
backspaceButton.setOnTouchListener(new View.OnTouchListener(){
private Handler mColorHoldHandler;
private View mView;
@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);
break;
case MotionEvent.ACTION_UP:
if (mColorHoldHandler == null) return true;
numButtonPressed("String_Node_Str");
view.setBackgroundColor(getResources().getColor(R.color.op_button_normal));
mColorHoldHandler.removeCallbacks(mBackspaceColor);
mColorHoldHandler=null;
break;
}
return false;
}
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;
private static final int BACKSPACE_HOLD_TIME=500;
@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,BACKSPACE_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));
System.out.println("String_Node_Str" + deltaRed);
System.out.println("String_Node_Str" + ((Color.red(mEndColor) - Color.red(mStartColor)) * mInc ^ 3));
System.out.println("String_Node_Str" + mInc);
mInc++;
}
}
;
}
);
}