Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
NBT editor has better error UI for invalid input now + improve input …
Browse files Browse the repository at this point in the history
…layouts for performance
  • Loading branch information
protolambda committed Dec 13, 2016
1 parent 84fdfdc commit afa8297
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
Expand All @@ -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));
}
}
});
Expand All @@ -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));
}
}
});
Expand All @@ -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));
}
}
});
Expand All @@ -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));
}
}
});
Expand All @@ -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));
}
}
});
Expand Down
26 changes: 9 additions & 17 deletions app/src/main/res/layout/tag_boolean_layout.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_byte"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon" />

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp" />

<CheckBox
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/tag_name"
android:id="@+id/checkBox"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tag_name" />
android:layout_marginLeft="10dp" />

</RelativeLayout>
</LinearLayout>
30 changes: 11 additions & 19 deletions app/src/main/res/layout/tag_byte_layout.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_byte"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon" />

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp" />

<EditText
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="64dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/tag_name"
android:inputType="number"
android:ems="3"
android:id="@+id/byteField"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tag_name" />
android:layout_marginLeft="10dp" />

</RelativeLayout>
</LinearLayout>
21 changes: 8 additions & 13 deletions app/src/main/res/layout/tag_compound_layout.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_compound"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon" />

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp"/>

</RelativeLayout>
</LinearLayout>
21 changes: 8 additions & 13 deletions app/src/main/res/layout/tag_default_layout.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_default"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon"/>

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp" />

</RelativeLayout>
</LinearLayout>
30 changes: 11 additions & 19 deletions app/src/main/res/layout/tag_double_layout.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_double"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon" />

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp" />

<EditText
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="188dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/tag_name"
android:inputType="numberSigned|numberDecimal"
android:ems="10"
android:id="@+id/doubleField"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tag_name" />
android:layout_marginLeft="10dp" />

</RelativeLayout>
</LinearLayout>
30 changes: 11 additions & 19 deletions app/src/main/res/layout/tag_float_layout.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
xmlns:tools="http://schemas.android.com/tools">

<ImageView
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_tag_float"
android:id="@+id/icon"
android:layout_alignParentLeft="true" />
android:id="@+id/icon" />

<TextView
android:layout_centerVertical="true"
android:textSize="19sp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/icon"
android:id="@+id/tag_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Tag name here"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/icon" />
android:layout_marginLeft="10dp" />

<EditText
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="188dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/tag_name"
android:inputType="numberSigned|numberDecimal"
android:ems="10"
android:id="@+id/floatField"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tag_name" />
android:layout_marginLeft="10dp" />

</RelativeLayout>
</LinearLayout>
Loading

0 comments on commit afa8297

Please sign in to comment.