• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Anyway to do this apart from super big IF statement?

Hi guys.

I'm creating an android app for photographers as part of a project at school and could do with a bit of help.

I'm making a long exposure calculator, this allows the user to input their current shutter speed, select a EV (exposure value) and then click calculate to work out an equivalent exposure.

Both the current shutter speed and the desired EV change are selected from spinners as you can see in the attached screenshot.
The resulting equivalent exposure is dependent on the two variables.

For example:
Current Shutter Speed: 1/100
EV: +1
Equivalent Shutter Speed = 1/50

Current Shutter Speed: 1/100
EV: +2
Equivalent Shutter Speed = 1/25

The only way I've worked out how to do this for all the variables is a MASSIVE if statement:
If shutter speed is 1/100 and EV is +2, therefore equivalent shutter speed is 1/25.

There are 20 different shutter speeds and 10 different EV values, so that's going to be loads of IFs.

Anybody have a better idea about how I could possibly do this?

Any help would be hugely appreciated!
 

Attachments

  • 2013-04-17 11.31.47.png
    2013-04-17 11.31.47.png
    348.6 KB · Views: 141
If you can come up with a mathematical formula, then yes. It depends on how you've calculated the equivalent shutter speed from the shutter speed and EV. Your example doesn't really shed much light on that to someone that doesn't know anything about photography.
 
If you can find or derive a mathematical formula for it, that would be best, otherwise, you could just use a lookup table.
 
As Appventive suggested, create a 3D hash table and populate it when your object is constructed, example...

Code:
HashMap<String,HashMap<String,HashMap<String,Object>>> lookupTable;

// ...

String exposure = lookupTable.get("1/100").get("+1").get("effective_exposure");

// ...

If there is a formula you can use to fill the table than you can save yourself a large amount of typing but given enough RAM, lookup tables will almost always outperform real-time calculations. If your data set is subject to change it may also be worthwhile to store all of the data in an XML file that gets serialized into your lookup table. That way you can easily change the values without needing to dig through a large amount of code.
 
Back
Top Bottom