Android App zur Berechnung einer HDR Belichtungsreihe.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

EasyBracketMain.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. package ch.spherIC;
  2. import java.text.DecimalFormat;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import android.app.Activity;
  6. import android.app.Dialog;
  7. import android.content.Context;
  8. import android.content.SharedPreferences;
  9. import android.os.Bundle;
  10. import android.view.Gravity;
  11. import android.view.Menu;
  12. import android.view.MenuInflater;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.widget.AdapterView;
  17. import android.widget.Button;
  18. import android.widget.LinearLayout;
  19. import android.widget.ListView;
  20. import android.widget.TextView;
  21. import android.widget.Toast;
  22. import android.widget.AdapterView.OnItemSelectedListener;
  23. import ch.spherIC.components.ApertureSpinner;
  24. import ch.spherIC.components.ShutterSpeedSpinner;
  25. import ch.spherIC.components.XSpinner;
  26. import ch.spherIC.resultlist.Exposure;
  27. import ch.spherIC.resultlist.ExposureAdapter;
  28. import ch.spherIC.resultlist.ExposureFactory;
  29. import ch.spherIC.settings.SettingsDlg;
  30. /**
  31. * Main class EasyBracketing
  32. */
  33. public class EasyBracketMain extends Activity {
  34. public static final int ABOUT_DLG = 0;
  35. public static final int SETTINGS_DLG = 1;
  36. public static final int USERGUIDE_DLG = 2;
  37. private static String DEF_SHUTTER_SPEED = "1/125";
  38. private static String DEF_APERTURE = "f/8";
  39. private static String DEF_EVSTEP = "2.0";
  40. private ShutterSpeedSpinner spnDPShutterSpeed;
  41. private ApertureSpinner spnDPAperture;
  42. private ShutterSpeedSpinner spnBPShutterSpeed;
  43. private ApertureSpinner spnBPAperture;
  44. private TextView txtDPEVValue;
  45. private TextView txtBPEVValue;
  46. private TextView txtCalcPDeltaEV;
  47. private ApertureSpinner spnCalcPAperture;
  48. private XSpinner spnCalcPEVStep;
  49. private Button resetBtn;
  50. private Button calculateBtn;
  51. private ListView resultList;
  52. private LinearLayout resultsHeader;
  53. private double bpCorrection;
  54. private double dpCorrection;
  55. private boolean fixBP;
  56. private double dpEV;
  57. private double bpEV;
  58. public static final DecimalFormat DF = new DecimalFormat("0.##");
  59. /**
  60. * Called when the activity is first created.
  61. */
  62. @Override
  63. public void onCreate(Bundle savedInstanceState) {
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.main);
  66. initComponents();
  67. setDefaults();
  68. loadSettings();
  69. }
  70. /**
  71. * Loads and stores the settings
  72. */
  73. public void loadSettings() {
  74. // Load settings
  75. SharedPreferences settings = getSharedPreferences(SettingsDlg.PREFS_NAME, Context.MODE_PRIVATE);
  76. this.fixBP = settings.getBoolean("fixBrightPoint", true);
  77. this.bpCorrection = settings.getFloat("brightPointCorrection", 0f);
  78. this.dpCorrection = settings.getFloat("darkPointCorrection", 0f);
  79. }
  80. /**
  81. * {@inheritDoc}
  82. */
  83. @Override
  84. public boolean onCreateOptionsMenu(Menu menu) {
  85. super.onCreateOptionsMenu(menu);
  86. MenuInflater inflater = getMenuInflater();
  87. inflater.inflate(R.menu.mainmenu, menu);
  88. return true;
  89. }
  90. /**
  91. * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
  92. */
  93. @Override
  94. public boolean onOptionsItemSelected(MenuItem item) {
  95. // Handle item selection
  96. switch (item.getItemId()) {
  97. case R.id.itemAbout:
  98. showDialog(ABOUT_DLG);
  99. return true;
  100. case R.id.itemSettings:
  101. showDialog(SETTINGS_DLG);
  102. return true;
  103. case R.id.itemUserGuide:
  104. showDialog(USERGUIDE_DLG);
  105. return true;
  106. default:
  107. return super.onOptionsItemSelected(item);
  108. }
  109. }
  110. /**
  111. * Initialization method
  112. */
  113. private void initComponents() {
  114. // initialize dropdowns
  115. OnItemSelectedListener evRangeItemSelListener = new OnItemSelectedListener() {
  116. @Override
  117. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  118. EasyBracketMain.this.dpEV = EVFormula.calcEV(EasyBracketMain.this.spnDPAperture.getSelectedAperture(),
  119. EasyBracketMain.this.spnDPShutterSpeed
  120. .getSelectedShutterSpeed());
  121. EasyBracketMain.this.bpEV = EVFormula.calcEV(EasyBracketMain.this.spnBPAperture.getSelectedAperture(),
  122. EasyBracketMain.this.spnBPShutterSpeed
  123. .getSelectedShutterSpeed());
  124. EasyBracketMain.this.txtDPEVValue.setText(EasyBracketMain.DF.format(EasyBracketMain.this.dpEV));
  125. EasyBracketMain.this.txtBPEVValue.setText(EasyBracketMain.DF.format(EasyBracketMain.this.bpEV));
  126. EasyBracketMain.this.txtCalcPDeltaEV.setText(EasyBracketMain.DF.format((EasyBracketMain.this.bpEV
  127. + EasyBracketMain.this.bpCorrection)
  128. - (EasyBracketMain.this.dpEV
  129. - EasyBracketMain.this.dpCorrection)));
  130. EasyBracketMain.this.calculateBtn.setEnabled(EasyBracketMain.this.bpEV > EasyBracketMain.this.dpEV);
  131. EasyBracketMain.this.resultsHeader.setVisibility(View.INVISIBLE);
  132. findViewById(R.id.View_ResHeader_Understroke).setVisibility(View.INVISIBLE);
  133. EasyBracketMain.this.resultList.setAdapter(null);
  134. if (EasyBracketMain.this.bpEV < EasyBracketMain.this.dpEV) {
  135. Toast toast = Toast.makeText(EasyBracketMain.this, R.string.toastWarningDP_BP, Toast.LENGTH_LONG);
  136. toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
  137. toast.show();
  138. }
  139. }
  140. @Override
  141. public void onNothingSelected(AdapterView<?> parent) {
  142. }
  143. };
  144. OnItemSelectedListener calcPItemSelListener = new OnItemSelectedListener() {
  145. @Override
  146. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  147. toggleResultsList(false);
  148. }
  149. @Override
  150. public void onNothingSelected(AdapterView<?> parent) {
  151. }
  152. };
  153. this.spnDPShutterSpeed = (ShutterSpeedSpinner) findViewById(R.id.Spinner_DP_Shutter);
  154. this.spnDPAperture = (ApertureSpinner) findViewById(R.id.Spinner_DP_Aperture);
  155. this.spnBPShutterSpeed = (ShutterSpeedSpinner) findViewById(R.id.Spinner_BP_Shutter);
  156. this.spnBPAperture = (ApertureSpinner) findViewById(R.id.Spinner_BP_Aperture);
  157. this.spnCalcPAperture = (ApertureSpinner) findViewById(R.id.Spinner_calcP_Aperture);
  158. this.spnCalcPEVStep = (XSpinner) findViewById(R.id.Spinner_calcP_EVStep);
  159. this.txtDPEVValue = (TextView) findViewById(R.id.Text_EVVal_DP);
  160. this.txtBPEVValue = (TextView) findViewById(R.id.Text_EVVal_BP);
  161. this.txtCalcPDeltaEV = (TextView) findViewById(R.id.label_deltaEV_Val);
  162. this.resultsHeader = (LinearLayout) ExposureAdapter.getHeaderView(this,
  163. (LinearLayout)
  164. findViewById(R.id.LinearLayout_ResultsHeader));
  165. this.resultsHeader.setVisibility(View.INVISIBLE);
  166. findViewById(R.id.View_ResHeader_Understroke).setVisibility(View.INVISIBLE);
  167. this.resultList = (ListView) findViewById(R.id.ListView_ExpResults);
  168. this.resultList.setAdapter(null);
  169. this.resetBtn = (Button) findViewById(R.id.Btn_Reset);
  170. this.calculateBtn = (Button) findViewById(R.id.Btn_Calculate);
  171. this.calculateBtn.setEnabled(false);
  172. this.spnDPShutterSpeed.setOnItemSelectedListener(evRangeItemSelListener);
  173. this.spnDPAperture.setOnItemSelectedListener(evRangeItemSelListener);
  174. this.spnBPShutterSpeed.setOnItemSelectedListener(evRangeItemSelListener);
  175. this.spnBPAperture.setOnItemSelectedListener(evRangeItemSelListener);
  176. this.resetBtn.setOnClickListener(new OnClickListener() {
  177. @Override
  178. public void onClick(View v) {
  179. setDefaults();
  180. toggleResultsList(false);
  181. }
  182. });
  183. this.calculateBtn.setOnClickListener(new OnClickListener() {
  184. @Override
  185. public void onClick(View v) {
  186. toggleResultsList(true);
  187. calculateExposures();
  188. }
  189. });
  190. this.spnCalcPAperture.setOnItemSelectedListener(calcPItemSelListener);
  191. this.spnCalcPEVStep.setOnItemSelectedListener(calcPItemSelListener);
  192. }
  193. /**
  194. * Clears the results list.
  195. */
  196. private void toggleResultsList(boolean visible) {
  197. if (visible) {
  198. EasyBracketMain.this.resultsHeader.setVisibility(View.VISIBLE);
  199. findViewById(R.id.View_ResHeader_Understroke).setVisibility(View.VISIBLE);
  200. } else {
  201. EasyBracketMain.this.resultsHeader.setVisibility(View.INVISIBLE);
  202. findViewById(R.id.View_ResHeader_Understroke).setVisibility(View.INVISIBLE);
  203. EasyBracketMain.this.resultList.setAdapter(null);
  204. }
  205. }
  206. /**
  207. * Sets the default values.
  208. */
  209. public void setDefaults() {
  210. this.spnDPShutterSpeed.setSelectionByVal(DEF_SHUTTER_SPEED);
  211. this.spnDPAperture.setSelectionByVal(DEF_APERTURE);
  212. this.spnBPShutterSpeed.setSelectionByVal(DEF_SHUTTER_SPEED);
  213. this.spnBPAperture.setSelectionByVal(DEF_APERTURE);
  214. this.spnCalcPAperture.setSelectionByVal(DEF_APERTURE);
  215. this.spnCalcPEVStep.setSelectionByVal(DEF_EVSTEP);
  216. this.txtDPEVValue.setText(DF.format(EVFormula.calcEV(this.spnDPAperture.getSelectedAperture(),
  217. this.spnDPShutterSpeed.getSelectedShutterSpeed())));
  218. this.txtBPEVValue.setText(DF.format(EVFormula.calcEV(this.spnBPAperture.getSelectedAperture(),
  219. this.spnBPShutterSpeed.getSelectedShutterSpeed())));
  220. this.txtCalcPDeltaEV.setText(DF.format(this.bpEV + this.bpCorrection - (this.dpEV - this.dpCorrection)));
  221. }
  222. /**
  223. * Initiates the calculation of the exposure values according to the input parameters.
  224. */
  225. private void calculateExposures() {
  226. List<Exposure> exposureList;
  227. double calcPrmAperture = this.spnCalcPAperture.getSelectedAperture();
  228. double calcPrmEvStep = Double.valueOf(this.spnCalcPEVStep.getSelectedItem().toString());
  229. List<Double> allowedShutters = getShutterSpeeds();
  230. exposureList = ExposureFactory.calculateExposures(this, this.dpEV - this.dpCorrection,
  231. this.bpEV + this.bpCorrection, calcPrmAperture, calcPrmEvStep,
  232. this.fixBP, allowedShutters);
  233. this.resultList.setAdapter(new ExposureAdapter(this, exposureList));
  234. }
  235. /**
  236. * Retrieves the list of all shutter speeds in drop down list as Double's.
  237. *
  238. * @return list of all shutter speeds in drop down list as Double's
  239. */
  240. private List<Double> getShutterSpeeds() {
  241. List<Double> shutterSpeeds = new ArrayList<Double>();
  242. for (int i = 0; i < this.spnBPShutterSpeed.getCount(); i++) {
  243. shutterSpeeds.add(this.spnBPShutterSpeed.getShutterSpeedAt(i));
  244. }
  245. return shutterSpeeds;
  246. }
  247. /**
  248. * {@inheritDoc}
  249. */
  250. @Override
  251. protected Dialog onCreateDialog(int id) {
  252. return DialogFactory.createDialog(id, this);
  253. }
  254. }