Skip to content

Commit

Permalink
fix potential UIThread problem in ETV for setText
Browse files Browse the repository at this point in the history
  • Loading branch information
mg4gh committed Nov 4, 2023
1 parent 80ea6ea commit 65ae7d2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mgmap/src/main/java/mg/mgmap/generic/view/ExtendedTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ public boolean setValue(Object value){
String newText = Formatter.format(formatType, value, getPaint() /*availablePaint*/, availableWidth*getMaxLines());
if (!newText.equals(availableText)){
mgLog.d(logName+":"+newText /*+ " availableWidth="+availableWidth +" textSize="+getTextSize()*/);
setText( newText );
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
setText( newText );
} else {
mgLog.d("need UIThread: "+logName+ " context="+getContext().getClass().getSimpleName());
Activity activity = (Activity) this.getContext();
activity.runOnUiThread(() -> setText( newText ));
}
availableText = newText;
onChange("onSetValue: "+newText);
return true;
Expand Down Expand Up @@ -284,9 +290,9 @@ private void onChange(String reason){
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
setCompoundDrawables(drawable, null, null, null);
} else {
mgLog.d("need UIThread: "+logName+ " context="+getContext().getClass().getSimpleName());
Activity activity = (Activity) this.getContext();
activity.runOnUiThread(() -> setCompoundDrawables(drawable, null, null, null));
mgLog.d("was here: "+logName);
}
}
}
Expand Down

0 comments on commit 65ae7d2

Please sign in to comment.