fix for NPE

This commit is contained in:
Sergey Solovyev 2013-06-15 23:21:50 +04:00
parent 4658f42a8a
commit d1677c97e6
2 changed files with 9 additions and 7 deletions

View File

@ -49,9 +49,6 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
private volatile boolean viewStateChange = false; private volatile boolean viewStateChange = false;
@Nonnull
private final Object viewLock = new Object();
@Nonnull @Nonnull
private final Handler uiHandler = new Handler(); private final Handler uiHandler = new Handler();
@ -155,7 +152,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
@Override @Override
public void setState(@Nonnull final CalculatorEditorViewState viewState) { public void setState(@Nonnull final CalculatorEditorViewState viewState) {
synchronized (viewLock) { synchronized (this) {
final CharSequence text = prepareText(viewState.getText(), highlightText); final CharSequence text = prepareText(viewState.getText(), highlightText);
@ -163,7 +160,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
@Override @Override
public void run() { public void run() {
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this; final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
synchronized (viewLock) { synchronized (AndroidCalculatorEditorView.this) {
try { try {
editorView.viewStateChange = true; editorView.viewStateChange = true;
editorView.viewState = viewState; editorView.viewState = viewState;
@ -181,7 +178,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
@Override @Override
protected void onSelectionChanged(int selStart, int selEnd) { protected void onSelectionChanged(int selStart, int selEnd) {
synchronized (viewLock) { synchronized (this) {
if (!viewStateChange) { if (!viewStateChange) {
// external text change => need to notify editor // external text change => need to notify editor
super.onSelectionChanged(selStart, selEnd); super.onSelectionChanged(selStart, selEnd);
@ -195,7 +192,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
} }
public void handleTextChange(Editable s) { public void handleTextChange(Editable s) {
synchronized (viewLock) { synchronized (this) {
if (!viewStateChange) { if (!viewStateChange) {
// external text change => need to notify editor // external text change => need to notify editor
Locator.getInstance().getEditor().setText(String.valueOf(s)); Locator.getInstance().getEditor().setText(String.valueOf(s));

View File

@ -24,6 +24,11 @@ public class AndroidCalculatorEditorViewTest {
CalculatorTestUtils.initViews(context);*/ CalculatorTestUtils.initViews(context);*/
} }
@Test
public void testCreation() throws Exception {
new AndroidCalculatorEditorView(CalculatorApplication.getInstance());
}
@Test @Test
public void testAsyncWork() throws Exception { public void testAsyncWork() throws Exception {
/* final int threadNum = 10; /* final int threadNum = 10;