From afa82973d62ee85c1d2201bfe1de290ec71ac40e Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 13 Dec 2016 21:37:56 +0100 Subject: [PATCH] NBT editor has better error UI for invalid input now + improve input layouts for performance --- .../blocktopograph/nbt/EditorFragment.java | 23 +++++++------- .../main/res/layout/tag_boolean_layout.xml | 26 ++++++---------- app/src/main/res/layout/tag_byte_layout.xml | 30 +++++++------------ .../main/res/layout/tag_compound_layout.xml | 21 +++++-------- .../main/res/layout/tag_default_layout.xml | 21 +++++-------- app/src/main/res/layout/tag_double_layout.xml | 30 +++++++------------ app/src/main/res/layout/tag_float_layout.xml | 30 +++++++------------ app/src/main/res/layout/tag_int_layout.xml | 30 +++++++------------ app/src/main/res/layout/tag_list_layout.xml | 21 +++++-------- app/src/main/res/layout/tag_long_layout.xml | 30 +++++++------------ app/src/main/res/layout/tag_root_layout.xml | 22 ++++++-------- app/src/main/res/layout/tag_short_layout.xml | 30 +++++++------------ app/src/main/res/layout/tag_string_layout.xml | 5 ++-- 13 files changed, 121 insertions(+), 198 deletions(-) diff --git a/app/src/main/java/com/protolambda/blocktopograph/nbt/EditorFragment.java b/app/src/main/java/com/protolambda/blocktopograph/nbt/EditorFragment.java index 3fbe52d0..371a0bca 100644 --- a/app/src/main/java/com/protolambda/blocktopograph/nbt/EditorFragment.java +++ b/app/src/main/java/com/protolambda/blocktopograph/nbt/EditorFragment.java @@ -227,11 +227,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { String sValue = s.toString(); try { - byteTag.setValue(Byte.valueOf(sValue)); + int value = Integer.parseInt(sValue); + if(value < 0 || value > 0xff) + throw new NumberFormatException("No unsigned byte."); + byteTag.setValue((byte) value); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); @@ -255,8 +257,7 @@ public void afterTextChanged(Editable s) { shortTag.setValue(Short.valueOf(sValue)); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); @@ -280,8 +281,7 @@ public void afterTextChanged(Editable s) { intTag.setValue(Integer.valueOf(sValue)); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); @@ -305,8 +305,7 @@ public void afterTextChanged(Editable s) { longTag.setValue(Long.valueOf(sValue)); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); @@ -330,8 +329,7 @@ public void afterTextChanged(Editable s) { floatTag.setValue(Float.valueOf(sValue)); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); @@ -355,8 +353,7 @@ public void afterTextChanged(Editable s) { doubleTag.setValue(Double.valueOf(sValue)); nbt.setModified(); } catch (NumberFormatException e){ - Snackbar.make(editText, String.format(context.getString(R.string.x_is_invalid), sValue), Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + editText.setError(String.format(context.getString(R.string.x_is_invalid), sValue)); } } }); diff --git a/app/src/main/res/layout/tag_boolean_layout.xml b/app/src/main/res/layout/tag_boolean_layout.xml index e60ad74c..802efe54 100644 --- a/app/src/main/res/layout/tag_boolean_layout.xml +++ b/app/src/main/res/layout/tag_boolean_layout.xml @@ -1,39 +1,31 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_byte_layout.xml b/app/src/main/res/layout/tag_byte_layout.xml index 814739ac..9e5e7eb0 100644 --- a/app/src/main/res/layout/tag_byte_layout.xml +++ b/app/src/main/res/layout/tag_byte_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_compound_layout.xml b/app/src/main/res/layout/tag_compound_layout.xml index a8903a84..ace5d964 100644 --- a/app/src/main/res/layout/tag_compound_layout.xml +++ b/app/src/main/res/layout/tag_compound_layout.xml @@ -1,29 +1,24 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp"/> - + diff --git a/app/src/main/res/layout/tag_default_layout.xml b/app/src/main/res/layout/tag_default_layout.xml index 8e18c5dc..7446a222 100644 --- a/app/src/main/res/layout/tag_default_layout.xml +++ b/app/src/main/res/layout/tag_default_layout.xml @@ -1,29 +1,24 @@ - + android:id="@+id/icon"/> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_double_layout.xml b/app/src/main/res/layout/tag_double_layout.xml index f9fb6b0a..fc71012d 100644 --- a/app/src/main/res/layout/tag_double_layout.xml +++ b/app/src/main/res/layout/tag_double_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_float_layout.xml b/app/src/main/res/layout/tag_float_layout.xml index 0cd11c44..b901456a 100644 --- a/app/src/main/res/layout/tag_float_layout.xml +++ b/app/src/main/res/layout/tag_float_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_int_layout.xml b/app/src/main/res/layout/tag_int_layout.xml index 08da557f..b75a11e2 100644 --- a/app/src/main/res/layout/tag_int_layout.xml +++ b/app/src/main/res/layout/tag_int_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_list_layout.xml b/app/src/main/res/layout/tag_list_layout.xml index 22392c9f..8fb5ad6b 100644 --- a/app/src/main/res/layout/tag_list_layout.xml +++ b/app/src/main/res/layout/tag_list_layout.xml @@ -1,29 +1,24 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp"/> - + diff --git a/app/src/main/res/layout/tag_long_layout.xml b/app/src/main/res/layout/tag_long_layout.xml index de4c9845..419a39d8 100644 --- a/app/src/main/res/layout/tag_long_layout.xml +++ b/app/src/main/res/layout/tag_long_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp"/> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_root_layout.xml b/app/src/main/res/layout/tag_root_layout.xml index e820fb9e..15b5f25e 100644 --- a/app/src/main/res/layout/tag_root_layout.xml +++ b/app/src/main/res/layout/tag_root_layout.xml @@ -1,30 +1,26 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp" /> - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/tag_short_layout.xml b/app/src/main/res/layout/tag_short_layout.xml index 0c9a8b8f..872cb4c8 100644 --- a/app/src/main/res/layout/tag_short_layout.xml +++ b/app/src/main/res/layout/tag_short_layout.xml @@ -1,41 +1,33 @@ - + android:id="@+id/icon" /> + android:layout_marginLeft="10dp"/> + android:layout_marginLeft="10dp" /> - + diff --git a/app/src/main/res/layout/tag_string_layout.xml b/app/src/main/res/layout/tag_string_layout.xml index c9621798..fbf4b3f5 100644 --- a/app/src/main/res/layout/tag_string_layout.xml +++ b/app/src/main/res/layout/tag_string_layout.xml @@ -1,8 +1,9 @@