Display/Editor views should not be cleared by closing activity if new activity has already been started
This commit is contained in:
parent
127f27810e
commit
70a5e7e2e5
@ -22,7 +22,6 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -60,27 +59,6 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
|
||||
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void setDisplay(@Nonnull Activity activity) {
|
||||
final AndroidCalculatorDisplayView displayView = (AndroidCalculatorDisplayView) activity.findViewById(R.id.calculator_display);
|
||||
displayView.init(activity);
|
||||
Locator.getInstance().getDisplay().setView(displayView);
|
||||
}
|
||||
|
||||
public void clearDisplay() {
|
||||
Locator.getInstance().getDisplay().setView(null);
|
||||
}
|
||||
|
||||
public void setEditor(@Nonnull Activity activity) {
|
||||
final AndroidCalculatorEditorView editorView = (AndroidCalculatorEditorView) activity.findViewById(R.id.calculator_editor);
|
||||
editorView.init();
|
||||
Locator.getInstance().getEditor().setView(editorView);
|
||||
}
|
||||
|
||||
public void clearEditor() {
|
||||
Locator.getInstance().getEditor().setView(null);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
|
@ -42,6 +42,8 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
|
||||
@Nonnull
|
||||
private FragmentUi fragmentHelper;
|
||||
@Nonnull
|
||||
private AndroidCalculatorDisplayView displayView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -67,7 +69,9 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
((AndroidCalculator) Locator.getInstance().getCalculator()).setDisplay(getActivity());
|
||||
displayView = (AndroidCalculatorDisplayView) root.findViewById(R.id.calculator_display);
|
||||
displayView.init(getActivity());
|
||||
Locator.getInstance().getDisplay().setView(displayView);
|
||||
|
||||
fragmentHelper.onViewCreated(this, root);
|
||||
}
|
||||
@ -93,7 +97,7 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
((AndroidCalculator) Locator.getInstance().getCalculator()).clearDisplay();
|
||||
Locator.getInstance().getDisplay().clearView(displayView);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,9 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
@Nonnull
|
||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
||||
|
||||
@Nonnull
|
||||
private AndroidCalculatorEditorView editorView;
|
||||
|
||||
public CalculatorEditorFragment() {
|
||||
}
|
||||
|
||||
@ -56,7 +59,9 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
|
||||
fragmentUi.onViewCreated(this, view);
|
||||
|
||||
((AndroidCalculator) Locator.getInstance().getCalculator()).setEditor(getActivity());
|
||||
editorView = (AndroidCalculatorEditorView) view.findViewById(R.id.calculator_editor);
|
||||
editorView.init();
|
||||
Locator.getInstance().getEditor().setView(editorView);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,7 +104,7 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
((AndroidCalculator) Locator.getInstance().getCalculator()).clearEditor();
|
||||
Locator.getInstance().getEditor().clearView(editorView);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public interface CalculatorDisplay extends CalculatorEventListener {
|
||||
|
||||
void setView(@Nullable CalculatorDisplayView view);
|
||||
void setView(@Nonnull CalculatorDisplayView view);
|
||||
void clearView(@Nonnull CalculatorDisplayView view);
|
||||
|
||||
@Nullable
|
||||
CalculatorDisplayView getView();
|
||||
|
@ -25,7 +25,12 @@ package org.solovyev.android.calculator;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.*;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.calculation_cancelled;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.calculation_failed;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.calculation_result;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.conversion_failed;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.conversion_result;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -56,14 +61,20 @@ public class CalculatorDisplayImpl implements CalculatorDisplay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setView(@Nullable CalculatorDisplayView view) {
|
||||
public void setView(@Nonnull CalculatorDisplayView view) {
|
||||
synchronized (viewLock) {
|
||||
this.view = view;
|
||||
|
||||
if (view != null) {
|
||||
this.view.setState(viewState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearView(@Nonnull CalculatorDisplayView view) {
|
||||
synchronized (viewLock) {
|
||||
if (this.view == view) {
|
||||
this.view = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -25,7 +25,6 @@ package org.solovyev.android.calculator;
|
||||
import org.solovyev.common.gui.CursorControl;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@ -37,7 +36,8 @@ public interface CalculatorEditor extends CalculatorEventListener {
|
||||
@Nonnull
|
||||
String TAG = CalculatorEditor.class.getSimpleName();
|
||||
|
||||
void setView(@Nullable CalculatorEditorView view);
|
||||
void setView(@Nonnull CalculatorEditorView view);
|
||||
void clearView(@Nonnull CalculatorEditorView view);
|
||||
|
||||
@Nonnull
|
||||
CalculatorEditorViewState getViewState();
|
||||
|
@ -73,12 +73,18 @@ public class CalculatorEditorImpl implements CalculatorEditor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setView(@Nullable CalculatorEditorView view) {
|
||||
public void setView(@Nonnull CalculatorEditorView view) {
|
||||
synchronized (viewLock) {
|
||||
this.view = view;
|
||||
this.view.setState(lastViewState);
|
||||
}
|
||||
}
|
||||
|
||||
if (view != null) {
|
||||
view.setState(lastViewState);
|
||||
@Override
|
||||
public void clearView(@Nonnull CalculatorEditorView view) {
|
||||
synchronized (viewLock) {
|
||||
if (this.view == view) {
|
||||
this.view = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user