Skip to content

Commit e4853e4

Browse files
committed
0.0.5: Fixed spacing bug
1 parent ec59be3 commit e4853e4

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

materialtextview/src/main/java/uk/co/onemandan/materialtextview/MaterialTextView.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,20 @@ private void handleAttributes(Context context, AttributeSet attrs){
130130
}
131131

132132
private void handleHelperVisibility(CharSequence text){
133-
if(text.length() == 0 && !_keepHelperSpacing && _helperView.getVisibility() != View.GONE){
134-
_helperView.setVisibility(View.GONE);
135-
} else if (_helperView.getVisibility() != View.VISIBLE){
133+
if(text.length() == 0 && !_keepHelperSpacing){
134+
if(_helperView.getVisibility() != View.GONE){
135+
_helperView.setVisibility(View.GONE);
136+
}
137+
} else if (_helperView.getVisibility() != View.VISIBLE) {
136138
_helperView.setVisibility(View.VISIBLE);
137139
}
138140
}
139141

140142
private void handleLabelVisibility(){
141-
if(_labelText.length() == 0 && !_keepLabelSpacing && _labelView.getVisibility() != View.GONE){
142-
_labelView.setVisibility(View.GONE);
143+
if(_labelText.length() == 0 && !_keepLabelSpacing){
144+
if(_labelView.getVisibility() != View.GONE) {
145+
_labelView.setVisibility(View.GONE);
146+
}
143147
} else if(_labelView.getVisibility() != View.VISIBLE){
144148
_labelView.setVisibility(View.VISIBLE);
145149
}
@@ -172,6 +176,7 @@ public void setError(@Nullable CharSequence error){
172176
_isErrord = false;
173177

174178
_labelView.setTextColor(_labelTextColour);
179+
_contentView.setTextColor(_contentTextColour);
175180
_helperView.setTextColor(_helperTextColour);
176181
_helperView.setText(_helperText);
177182

@@ -181,6 +186,7 @@ public void setError(@Nullable CharSequence error){
181186
_isErrord = true;
182187

183188
_labelView.setTextColor(_errorTextColour);
189+
_contentView.setTextColor(_errorTextColour);
184190
_helperView.setTextColor(_errorTextColour);
185191
_helperView.setText(error);
186192

@@ -329,4 +335,7 @@ public CharSequence getHelperText(){
329335

330336
@SuppressWarnings("unused")
331337
public Boolean getSingleLine(){ return _singleLine; }
338+
339+
@SuppressWarnings("unused")
340+
public Boolean getError(){ return _isErrord; }
332341
}

sample/src/main/java/uk/co/onemandan/materialtextviewsample/Sample.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,34 @@
99

1010
public class Sample extends AppCompatActivity {
1111

12-
private boolean _error = false;
13-
1412
@Override
1513
protected void onCreate(Bundle savedInstanceState) {
1614
super.onCreate(savedInstanceState);
1715
setContentView(R.layout.activity_sample);
1816

1917
final MaterialTextView materialTextView = findViewById(R.id.mtv_sample);
18+
final MaterialTextView materialTextView2 = findViewById(R.id.mtv_sample2);
2019

2120
materialTextView.setOnClickListener(new View.OnClickListener() {
2221
@Override
2322
public void onClick(View v) {
24-
_error = !_error;
25-
26-
if(_error){
23+
if(!materialTextView.getError()){
2724
materialTextView.setError("Error!");
2825
} else {
2926
materialTextView.setError(null);
3027
}
3128
}
3229
});
30+
31+
materialTextView2.setOnClickListener(new View.OnClickListener() {
32+
@Override
33+
public void onClick(View v) {
34+
if(!materialTextView2.getError()){
35+
materialTextView2.setError("");
36+
} else {
37+
materialTextView2.setError(null);
38+
}
39+
}
40+
});
3341
}
3442
}

sample/src/main/res/layout/activity_sample.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
android:orientation="horizontal">
5555

5656
<uk.co.onemandan.materialtextview.MaterialTextView
57+
android:id="@+id/mtv_sample2"
5758
android:layout_width="0dp"
5859
android:layout_height="wrap_content"
5960
android:layout_weight="1"
6061
android:layout_marginEnd="8dp"
6162
android:layout_marginRight="8dp"
6263
app:mtv_labelText="Label Left"
63-
app:mtv_contentText="Content Leftttttttt"
64-
app:mtv_singleLine="true"/>
64+
app:mtv_contentText="Content Left" />
6565

6666
<uk.co.onemandan.materialtextview.MaterialTextView
6767
android:layout_width="0dp"
@@ -74,4 +74,16 @@
7474

7575
</LinearLayout>
7676

77+
<uk.co.onemandan.materialtextview.MaterialTextView
78+
android:layout_width="match_parent"
79+
android:layout_height="wrap_content"
80+
android:layout_marginStart="@dimen/margin_large"
81+
android:layout_marginLeft="@dimen/margin_large"
82+
android:layout_marginEnd="@dimen/margin_large"
83+
android:layout_marginRight="@dimen/margin_large"
84+
android:layout_marginTop="@dimen/margin_large"
85+
app:mtv_labelText="Single Line"
86+
app:mtv_contentText="The Quick Brown Fox Jumps OverThe Lazy Dog"
87+
app:mtv_singleLine="true"/>
88+
7789
</LinearLayout>

0 commit comments

Comments
 (0)