[Android] Prevent NumberFormatException
Geoffrey Métais
git at videolan.org
Tue Mar 24 15:28:37 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 24 13:53:04 2015 +0100| [1c194e140c4e2260f00cc9404a06d1712328a3ca] | committer: Geoffrey Métais
Prevent NumberFormatException
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1c194e140c4e2260f00cc9404a06d1712328a3ca
---
.../src/org/videolan/vlc/gui/dialogs/JumpToTimeDialog.java | 5 +++--
.../src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java | 10 ++++------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/JumpToTimeDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/JumpToTimeDialog.java
index e2e4b4a..3493072 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/JumpToTimeDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/JumpToTimeDialog.java
@@ -23,6 +23,7 @@
package org.videolan.vlc.gui.dialogs;
import android.os.Bundle;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -60,8 +61,8 @@ public class JumpToTimeDialog extends PickTimeFragment {
protected void executeAction() {
long hours = mHours != null ? Long.parseLong(mHours.getText().toString()) * HOURS_IN_MICROS : 0l;
- long minutes = Long.parseLong(mMinutes.getText().toString()) * MINUTES_IN_MICROS ;
- long seconds = Long.parseLong(mSeconds.getText().toString()) * SECONDS_IN_MICROS;
+ long minutes = TextUtils.isEmpty(mMinutes.getText().toString()) ? 0l : Long.parseLong(mMinutes.getText().toString()) * MINUTES_IN_MICROS ;
+ long seconds = TextUtils.isEmpty(mSeconds.getText().toString()) ? 0l : Long.parseLong(mSeconds.getText().toString()) * SECONDS_IN_MICROS;
mLibVLC.setTime((hours + minutes + seconds)/1000l); //Time in ms
dismiss();
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
index 9db6fd6..9a0032e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
@@ -21,23 +21,21 @@
*/
package org.videolan.vlc.gui.dialogs;
-import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
+import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
-import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.videolan.libvlc.LibVLC;
import org.videolan.vlc.R;
-import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.VLCInstance;
public abstract class PickTimeFragment extends DialogFragment implements DialogInterface.OnKeyListener, View.OnClickListener, View.OnFocusChangeListener, TextView.OnEditorActionListener {
@@ -231,9 +229,9 @@ public abstract class PickTimeFragment extends DialogFragment implements DialogI
protected long getTime(){
long sign = mSign.getText().equals("-") ? -1 : 1;
- long minutes = Long.parseLong(mMinutes.getText().toString());
- long seconds = Long.parseLong(mSeconds.getText().toString());
- long millis = Long.parseLong(mMillis.getText().toString());
+ long minutes = TextUtils.isEmpty(mMinutes.getText().toString()) ? 0l : Long.parseLong(mMinutes.getText().toString());
+ long seconds = TextUtils.isEmpty(mSeconds.getText().toString()) ? 0l : Long.parseLong(mSeconds.getText().toString());
+ long millis = TextUtils.isEmpty(mMillis.getText().toString()) ? 0l : Long.parseLong(mMillis.getText().toString());
return sign * (minutes * MINUTES_IN_MICROS + seconds * SECONDS_IN_MICROS + millis * MILLIS_IN_MICROS);
}
More information about the Android
mailing list