From 5d0861e22ebc1a4e525ca6bfb17c14cb34ddee4d Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sun, 3 Aug 2014 21:18:05 +0000 Subject: [PATCH] Only allow numbers in I2PTunnel wizard port fields (ticket #1331) --- .../net/i2p/android/i2ptunnel/TunnelWizardModel.java | 2 ++ .../i2p/android/wizard/model/SingleTextFieldPage.java | 10 ++++++++++ .../i2p/android/wizard/ui/SingleTextFieldFragment.java | 3 +++ 3 files changed, 15 insertions(+) diff --git a/app/src/main/java/net/i2p/android/i2ptunnel/TunnelWizardModel.java b/app/src/main/java/net/i2p/android/i2ptunnel/TunnelWizardModel.java index bd4ec9dfa..cb1139480 100644 --- a/app/src/main/java/net/i2p/android/i2ptunnel/TunnelWizardModel.java +++ b/app/src/main/java/net/i2p/android/i2ptunnel/TunnelWizardModel.java @@ -90,6 +90,7 @@ public class TunnelWizardModel extends AbstractWizardModel { new SingleTextFieldPage(this, res.getString(R.string.i2ptunnel_wizard_k_target_port)) .setDescription(res.getString(R.string.i2ptunnel_wizard_desc_target_port)) + .setNumeric(true) .setRequired(true) .setEqualCondition(cTunnelType, res.getString(R.string.i2ptunnel_wizard_v_server)), @@ -110,6 +111,7 @@ public class TunnelWizardModel extends AbstractWizardModel { new SingleTextFieldPage(this, res.getString(R.string.i2ptunnel_wizard_k_binding_port)) .setDescription(res.getString(R.string.i2ptunnel_wizard_k_binding_port)) + .setNumeric(true) .setRequired(true) .setEqualCondition(cTunnelType, res.getString(R.string.i2ptunnel_wizard_v_client)) .setEqualCondition(cServerType, res.getString(R.string.i2ptunnel_type_httpbidirserver)), diff --git a/app/src/main/java/net/i2p/android/wizard/model/SingleTextFieldPage.java b/app/src/main/java/net/i2p/android/wizard/model/SingleTextFieldPage.java index 30e75958a..79468a302 100644 --- a/app/src/main/java/net/i2p/android/wizard/model/SingleTextFieldPage.java +++ b/app/src/main/java/net/i2p/android/wizard/model/SingleTextFieldPage.java @@ -30,6 +30,7 @@ public class SingleTextFieldPage extends Page { // The null is checked in SingleTextFieldFragment protected String mDef = null; protected String mDesc = ""; + protected boolean mNumeric = false; public SingleTextFieldPage(ModelCallbacks callbacks, String title) { super(callbacks, title); @@ -68,6 +69,15 @@ public class SingleTextFieldPage extends Page { return mDesc; } + public SingleTextFieldPage setNumeric(boolean numeric) { + mNumeric = numeric; + return this; + } + + public boolean getNumeric() { + return mNumeric; + } + // Override these in subclasses to add content verification. public boolean isValid() { diff --git a/app/src/main/java/net/i2p/android/wizard/ui/SingleTextFieldFragment.java b/app/src/main/java/net/i2p/android/wizard/ui/SingleTextFieldFragment.java index 6566f1785..2ff14c606 100644 --- a/app/src/main/java/net/i2p/android/wizard/ui/SingleTextFieldFragment.java +++ b/app/src/main/java/net/i2p/android/wizard/ui/SingleTextFieldFragment.java @@ -25,6 +25,7 @@ import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.Editable; +import android.text.InputType; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; @@ -71,6 +72,8 @@ public class SingleTextFieldFragment extends Fragment { mFieldView = ((TextView) rootView.findViewById(R.id.wizard_text_field)); mFieldView.setHint(mPage.getTitle()); + if (mPage.getNumeric()) + mFieldView.setInputType(InputType.TYPE_CLASS_NUMBER); if (mPage.getData().getString(Page.SIMPLE_DATA_KEY) != null) mFieldView.setText(mPage.getData().getString(Page.SIMPLE_DATA_KEY)); else if (mPage.getDefault() != null) { -- GitLab