Program: 35089
Project: 35089
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);
    }
    @Override public CharSequence getPageTitle(    int pos){
      return mCalc.getUnitTypeName(pos % mCalc.getUnitTypeSize());
    }
  }
);
  TabPageIndicator convertPageIndicator=(TabPageIndicator)findViewById(R.id.titles);
  convertPageIndicator.setViewPager(mConvKeysViewPager);
  convertPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){
    @Override public void onPageSelected(    int pos){
      mCalc.setUnitTypePos(pos);
      int currConvKeyPos=mConvKeysViewPager.getCurrentItem();
      clearConvKeyForFragPos(currConvKeyPos - 1);
      clearConvKeyForFragPos(currConvKeyPos);
      clearConvKeyForFragPos(currConvKeyPos + 1);
      mCalc.getCurrUnitType().clearUnitSelection();
      if (unitToSelectAfterScroll != null) {
        getConvKeyFrag(mConvKeysViewPager.getCurrentItem()).selectUnit(unitToSelectAfterScroll);
        unitToSelectAfterScroll=null;
      }
      updateScreen(false);
    }
    @Override public void onPageScrolled(    int pos,    float posOffset,    int posOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
    }
  }
);
  mConvKeysViewPager.setCurrentItem(mCalc.getUnitTypePos());
  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.percent_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 Handler mResetHandler;
private View mView;
private static final int CLEAR_HOLD_TIME=2200;
@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,CLEAR_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();
updateScreen(true);
mConvKeysViewPager.setCurrentItem(mCalc.getUnitTypePos());
}
}
;
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));
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);
    }
    @Override public CharSequence getPageTitle(    int pos){
      return mCalc.getUnitTypeName(pos % mCalc.getUnitTypeSize());
    }
  }
);
  TabPageIndicator convertPageIndicator=(TabPageIndicator)findViewById(R.id.titles);
  convertPageIndicator.setViewPager(mConvKeysViewPager);
  convertPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){
    @Override public void onPageSelected(    int pos){
      mCalc.setUnitTypePos(pos);
      int currConvKeyPos=mConvKeysViewPager.getCurrentItem();
      clearConvKeyForFragPos(currConvKeyPos - 1);
      clearConvKeyForFragPos(currConvKeyPos);
      clearConvKeyForFragPos(currConvKeyPos + 1);
      mCalc.getCurrUnitType().clearUnitSelection();
      if (unitToSelectAfterScroll != null) {
        getConvKeyFrag(mConvKeysViewPager.getCurrentItem()).selectUnit(unitToSelectAfterScroll);
        unitToSelectAfterScroll=null;
      }
      updateScreen(false);
    }
    @Override public void onPageScrolled(    int pos,    float posOffset,    int posOffsetPixels){
    }
    @Override public void onPageScrollStateChanged(    int state){
    }
  }
);
  mConvKeysViewPager.setCurrentItem(mCalc.getUnitTypePos());
  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.percent_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 Handler mResetHandler;
private View mView;
private static final int CLEAR_HOLD_TIME=2200;
@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,CLEAR_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();
updateScreen(true);
mConvKeysViewPager.setCurrentItem(mCalc.getUnitTypePos());
}
}
;
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));
mInc++;
}
}
;
}
);
float px=mDisplay.getTextSize();
DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float logicalDensity=metrics.density;
int dp=(int)Math.ceil(px / logicalDensity);
System.out.println("String_Node_Str" + dp);
System.out.println("String_Node_Str" + px);
}