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;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -60,27 +59,6 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
|
|||||||
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
|
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
|
@Nonnull
|
||||||
private FragmentUi fragmentHelper;
|
private FragmentUi fragmentHelper;
|
||||||
|
@Nonnull
|
||||||
|
private AndroidCalculatorDisplayView displayView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -67,7 +69,9 @@ public class CalculatorDisplayFragment extends Fragment {
|
|||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(root, 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);
|
fragmentHelper.onViewCreated(this, root);
|
||||||
}
|
}
|
||||||
@ -93,7 +97,7 @@ public class CalculatorDisplayFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
((AndroidCalculator) Locator.getInstance().getCalculator()).clearDisplay();
|
Locator.getInstance().getDisplay().clearView(displayView);
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,9 @@ public class CalculatorEditorFragment extends Fragment {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private AndroidCalculatorEditorView editorView;
|
||||||
|
|
||||||
public CalculatorEditorFragment() {
|
public CalculatorEditorFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +59,9 @@ public class CalculatorEditorFragment extends Fragment {
|
|||||||
|
|
||||||
fragmentUi.onViewCreated(this, view);
|
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
|
@Override
|
||||||
@ -99,7 +104,7 @@ public class CalculatorEditorFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
((AndroidCalculator) Locator.getInstance().getCalculator()).clearEditor();
|
Locator.getInstance().getEditor().clearView(editorView);
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ import javax.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public interface CalculatorDisplay extends CalculatorEventListener {
|
public interface CalculatorDisplay extends CalculatorEventListener {
|
||||||
|
|
||||||
void setView(@Nullable CalculatorDisplayView view);
|
void setView(@Nonnull CalculatorDisplayView view);
|
||||||
|
void clearView(@Nonnull CalculatorDisplayView view);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
CalculatorDisplayView getView();
|
CalculatorDisplayView getView();
|
||||||
|
@ -25,7 +25,12 @@ package org.solovyev.android.calculator;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
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
|
* User: serso
|
||||||
@ -56,14 +61,20 @@ public class CalculatorDisplayImpl implements CalculatorDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setView(@Nullable CalculatorDisplayView view) {
|
public void setView(@Nonnull CalculatorDisplayView view) {
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
if (view != null) {
|
|
||||||
this.view.setState(viewState);
|
this.view.setState(viewState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearView(@Nonnull CalculatorDisplayView view) {
|
||||||
|
synchronized (viewLock) {
|
||||||
|
if (this.view == view) {
|
||||||
|
this.view = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -25,7 +25,6 @@ package org.solovyev.android.calculator;
|
|||||||
import org.solovyev.common.gui.CursorControl;
|
import org.solovyev.common.gui.CursorControl;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
@ -37,7 +36,8 @@ public interface CalculatorEditor extends CalculatorEventListener {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
String TAG = CalculatorEditor.class.getSimpleName();
|
String TAG = CalculatorEditor.class.getSimpleName();
|
||||||
|
|
||||||
void setView(@Nullable CalculatorEditorView view);
|
void setView(@Nonnull CalculatorEditorView view);
|
||||||
|
void clearView(@Nonnull CalculatorEditorView view);
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CalculatorEditorViewState getViewState();
|
CalculatorEditorViewState getViewState();
|
||||||
|
@ -73,12 +73,18 @@ public class CalculatorEditorImpl implements CalculatorEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setView(@Nullable CalculatorEditorView view) {
|
public void setView(@Nonnull CalculatorEditorView view) {
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.view.setState(lastViewState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (view != null) {
|
@Override
|
||||||
view.setState(lastViewState);
|
public void clearView(@Nonnull CalculatorEditorView view) {
|
||||||
|
synchronized (viewLock) {
|
||||||
|
if (this.view == view) {
|
||||||
|
this.view = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user