From 7a1d788f2a2883bbe667b6676515d581853c952e Mon Sep 17 00:00:00 2001 From: m2049r Date: Sun, 17 Nov 2019 10:31:19 +0100 Subject: [PATCH] UI tweaks (#638) * fix amount entry field * password entry on own line * remove errors when typing; field spacing --- .../m2049r/xmrwallet/GenerateFragment.java | 56 ++++-- .../xmrwallet/widget/ExchangeBtcEditText.java | 187 ------------------ app/src/main/res/layout/fragment_generate.xml | 77 ++++---- .../res/layout/view_exchange_btc_edit.xml | 74 ------- .../main/res/layout/view_exchange_edit.xml | 34 ++-- 5 files changed, 90 insertions(+), 338 deletions(-) delete mode 100644 app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeBtcEditText.java delete mode 100644 app/src/main/res/layout/view_exchange_btc_edit.xml diff --git a/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java b/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java index e792437..e1b4603 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java @@ -79,6 +79,23 @@ public class GenerateFragment extends Fragment { private String type = null; + private void clearErrorOnTextEntry(final TextInputLayout textInputLayout) { + textInputLayout.getEditText().addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable editable) { + textInputLayout.setError(null); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -110,6 +127,23 @@ public class GenerateFragment extends Fragment { } } }); + clearErrorOnTextEntry(etWalletName); + + etWalletPassword.getEditText().addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable editable) { + checkPassword(); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }); + etWalletMnemonic.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -118,6 +152,8 @@ public class GenerateFragment extends Fragment { } } }); + clearErrorOnTextEntry(etWalletMnemonic); + etWalletAddress.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -126,6 +162,8 @@ public class GenerateFragment extends Fragment { } } }); + clearErrorOnTextEntry(etWalletAddress); + etWalletViewKey.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -134,6 +172,8 @@ public class GenerateFragment extends Fragment { } } }); + clearErrorOnTextEntry(etWalletViewKey); + etWalletSpendKey.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -142,6 +182,7 @@ public class GenerateFragment extends Fragment { } } }); + clearErrorOnTextEntry(etWalletSpendKey); Helper.showKeyboard(getActivity()); @@ -310,21 +351,6 @@ public class GenerateFragment extends Fragment { } }); - etWalletPassword.getEditText().addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable editable) { - checkPassword(); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - }); - etWalletName.requestFocus(); initZxcvbn(); diff --git a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeBtcEditText.java b/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeBtcEditText.java deleted file mode 100644 index be47e0c..0000000 --- a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeBtcEditText.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2017 m2049r - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// based on https://code.tutsplus.com/tutorials/creating-compound-views-on-android--cms-22889 - -package com.m2049r.xmrwallet.widget; - -import android.content.Context; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; - -import com.m2049r.xmrwallet.R; -import com.m2049r.xmrwallet.util.Helper; - -import timber.log.Timber; - -public class ExchangeBtcEditText extends LinearLayout { - - String btcAmount = null; - String xmrAmount = null; - - private boolean validate(String amount, double max, double min) { - boolean ok = true; - if (amount != null) { - try { - double x = Double.parseDouble(amount); - if ((x < min) || (x > max)) { - ok = false; - } - } catch (NumberFormatException ex) { - Timber.e(ex.getLocalizedMessage()); - ok = false; - } - } else { - ok = false; - } - return ok; - } - - public boolean validate(double maxBtc, double minBtc) { - Timber.d("validate(maxBtc=%f,minBtc=%f)", maxBtc, minBtc); - boolean ok = true; - if (!validate(btcAmount, maxBtc, minBtc)) { - Timber.d("btcAmount invalid %s", btcAmount); - shakeAmountField(); - return false; - } - return true; - } - - void shakeAmountField() { - etAmountA.startAnimation(Helper.getShakeAnimation(getContext())); - } - - void shakeExchangeField() { - tvAmountB.startAnimation(Helper.getShakeAnimation(getContext())); - } - - public void setRate(double xmrBtcRate) { - this.xmrBtcRate = xmrBtcRate; - post(new Runnable() { - @Override - public void run() { - exchange(); - } - }); - } - - public void setAmount(String btcAmount) { - this.btcAmount = btcAmount; - etAmountA.setText(btcAmount); - xmrAmount = null; - exchange(); - } - - public void setEditable(boolean editable) { - etAmountA.setEnabled(editable); - } - - public String getAmount() { - return btcAmount; - } - - EditText etAmountA; - TextView tvAmountB; - Spinner sCurrencyA; - Spinner sCurrencyB; - - public ExchangeBtcEditText(Context context) { - super(context); - initializeViews(context); - } - - public ExchangeBtcEditText(Context context, AttributeSet attrs) { - super(context, attrs); - initializeViews(context); - } - - public ExchangeBtcEditText(Context context, - AttributeSet attrs, - int defStyle) { - super(context, attrs, defStyle); - initializeViews(context); - } - - /** - * Inflates the views in the layout. - * - * @param context the current context for the view. - */ - private void initializeViews(Context context) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.view_exchange_btc_edit, this); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - etAmountA = findViewById(R.id.etAmountA); - etAmountA.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - exchange(); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - }); - tvAmountB = findViewById(R.id.tvAmountB); - sCurrencyA = findViewById(R.id.sCurrencyA); - sCurrencyB = findViewById(R.id.sCurrencyB); - - ArrayAdapter btcAdapter = new ArrayAdapter(getContext(), - android.R.layout.simple_spinner_item, - new String[]{"BTC"}); - sCurrencyA.setAdapter(btcAdapter); - sCurrencyA.setEnabled(false); - ArrayAdapter xmrAdapter = new ArrayAdapter(getContext(), - android.R.layout.simple_spinner_item, - new String[]{"XMR"}); - sCurrencyB.setAdapter(xmrAdapter); - sCurrencyB.setEnabled(false); - etAmountA.setFocusable(true); - etAmountA.setFocusableInTouchMode(true); - } - - double xmrBtcRate = 0; - - public void exchange() { - btcAmount = etAmountA.getText().toString(); - if (!btcAmount.isEmpty() && (xmrBtcRate > 0)) { - double xmr = xmrBtcRate * Double.parseDouble(btcAmount); - xmrAmount = Helper.getFormattedAmount(xmr, true); - } else { - xmrAmount = ""; - } - tvAmountB.setText(getResources().getString(R.string.send_amount_btc_xmr, xmrAmount)); - Timber.d("%s BTC =%f> %s XMR", btcAmount, xmrBtcRate, xmrAmount); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_generate.xml b/app/src/main/res/layout/fragment_generate.xml index 3a6492e..5a013ac 100644 --- a/app/src/main/res/layout/fragment_generate.xml +++ b/app/src/main/res/layout/fragment_generate.xml @@ -10,54 +10,43 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:layout_marginBottom="@dimen/header_top_first" + app:errorEnabled="true"> - + android:hint="@string/generate_name_hint" + android:imeOptions="actionNext" + android:inputType="text" + android:maxLines="1" + android:textAlignment="textStart" /> + - + - + - - - - - - + @@ -103,8 +93,8 @@ style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/header_top_first" android:visibility="gone" - app:counterEnabled="true" app:counterMaxLength="95" app:errorEnabled="true"> @@ -124,6 +114,7 @@ style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/header_top_first" android:visibility="gone" app:counterEnabled="true" app:counterMaxLength="64" @@ -144,6 +135,7 @@ style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/header_top_first" android:visibility="gone" app:counterEnabled="true" app:counterMaxLength="64" @@ -164,6 +156,7 @@ style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/header_top_first" android:visibility="gone" app:errorEnabled="true"> diff --git a/app/src/main/res/layout/view_exchange_btc_edit.xml b/app/src/main/res/layout/view_exchange_btc_edit.xml deleted file mode 100644 index 8591849..0000000 --- a/app/src/main/res/layout/view_exchange_btc_edit.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/view_exchange_edit.xml b/app/src/main/res/layout/view_exchange_edit.xml index 295ce75..bdb0808 100644 --- a/app/src/main/res/layout/view_exchange_edit.xml +++ b/app/src/main/res/layout/view_exchange_edit.xml @@ -17,26 +17,20 @@ android:gravity="center" android:textAlignment="center" /> - - - - +