In this block of code which is inside a broadcast receiver I have a calculation. My goal is to get a battery bar with the correct amount of Green inside it. So for the Green I have an image which is essentially a block of solid green. I am not sure if this is the best way to do this but I decided to resize the block using this calculation:
(Height of Block) * (Battery Level/100)
The actual code:
BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context ctxt, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100);
percentageView.setText(String.valueOf(level)+"%");
int height_val = (363) * (level / 100); //<-- That's the int which always returns 0
Log.e("MyTag", String.valueOf(height_val).toString());
Log.e("MyTAgg", String.valueOf(363 * (level/100)));
bar.requestLayout();
bar.getLayoutParams().height= height_val;
}
};
And it is inside a class. It's registered in the class not in the manifest. My Text View shows me the battery percentage but my Tags always show me that my calculations returns 0. Please do help me understand. Why does this calculation return 0?
Thank you.