From 8eeafc140e98e460c6aeb8a46ed2c91e76522210 Mon Sep 17 00:00:00 2001 From: likaid Date: Tue, 30 Jun 2015 11:17:57 +0800 Subject: SnapdragonCamera: fix NumberFormatException when input value invalide NumberFormatException occurred when converted the invalid input values, for example, user only input "." for some float values. Catch the NumberFormatException and show invalid input toast. Change-Id: Ie10b204950d43cca22a06532f04b9569fa545cbb CRs-Fixed: 862960 --- src/com/android/camera/PhotoModule.java | 39 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/com/android/camera/PhotoModule.java') diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 9616961a1..8abeff197 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -3839,7 +3839,13 @@ public class PhotoModule double focuspos = 0; String focusStr = input.getText().toString(); if (focusStr.length() > 0) { - focuspos = Double.parseDouble(focusStr); + try { + focuspos = Double.parseDouble(focusStr); + } catch (NumberFormatException e) { + Log.w(TAG, "Input foucspos " + focuspos + " is invalid"); + focuspos = maxFocusPos + 1f; + } + } else { RotateTextToast.makeText(mActivity, "Invalid focus position", Toast.LENGTH_SHORT).show(); @@ -3978,10 +3984,20 @@ public class PhotoModule String Rgain = Rinput.getText().toString(); String Ggain = Ginput.getText().toString(); String Bgain = Binput.getText().toString(); + double Rgainf = -1; + double Ggainf = -1; + double Bgainf = -1; if (Rgain.length() > 0 && Ggain.length() > 0 && Bgain.length() > 0) { - double Rgainf = Double.parseDouble(Rgain); - double Ggainf = Double.parseDouble(Ggain); - double Bgainf = Double.parseDouble(Bgain); + try { + Rgainf = Double.parseDouble(Rgain); + Ggainf = Double.parseDouble(Ggain); + Bgainf = Double.parseDouble(Bgain); + } catch (NumberFormatException e) { + Log.w(TAG, "Input RGB gain is invalid"); + Rgainf = maxGain + 1f; + Ggainf = maxGain + 1f; + Bgainf = maxGain + 1f; + } String RGBGain = Rgain + "," + Ggain + "," + Bgain; if (Rgainf <= maxGain && Rgainf >= minGain && Ggainf <= maxGain && Ggainf >= minGain && @@ -4105,7 +4121,12 @@ public class PhotoModule double newExpTime = -1; String expTime = ExpTimeInput.getText().toString(); if (expTime.length() > 0) { - newExpTime = Double.parseDouble(expTime); + try { + newExpTime = Double.parseDouble(expTime); + } catch (NumberFormatException e) { + Log.w(TAG, "Input expTime " + expTime + " is invalid"); + newExpTime = Double.parseDouble(maxExpTime) + 1f; + } } if (newExpTime <= Double.parseDouble(maxExpTime) && newExpTime >= Double.parseDouble(minExpTime)) { @@ -4151,7 +4172,13 @@ public class PhotoModule double newExpTime = -1; String expTime = ExpTimeInput.getText().toString(); if (expTime.length() > 0) { - newExpTime = Double.parseDouble(expTime); + try { + newExpTime = Double.parseDouble(expTime); + } catch (NumberFormatException e) { + Log.w(TAG, "input newExpTime " + newExpTime + " is invalid"); + newExpTime = Double.parseDouble(maxExpTime) + 1f; + } + } if (newISO <= maxISO && newISO >= minISO && newExpTime <= Double.parseDouble(maxExpTime) && -- cgit v1.2.3