Fix assertion

EditorView must have Editor attached
This commit is contained in:
serso 2016-02-07 13:56:17 +01:00
parent fc5eb9e281
commit 106783eee7
3 changed files with 17 additions and 39 deletions

View File

@ -9,6 +9,7 @@ import org.solovyev.android.calculator.history.BaseHistoryFragment;
import org.solovyev.android.calculator.history.EditHistoryFragment; import org.solovyev.android.calculator.history.EditHistoryFragment;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenView;
import org.solovyev.android.calculator.operators.OperatorsFragment; import org.solovyev.android.calculator.operators.OperatorsFragment;
import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PreferencesActivity;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
@ -42,4 +43,5 @@ public interface AppComponent {
void inject(PurchaseDialogActivity activity); void inject(PurchaseDialogActivity activity);
void inject(PreferencesActivity activity); void inject(PreferencesActivity activity);
void inject(BaseKeyboardUi ui); void inject(BaseKeyboardUi ui);
void inject(CalculatorOnscreenView view);
} }

View File

@ -32,18 +32,11 @@ import android.os.IBinder;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.Display;
import org.solovyev.android.calculator.Editor;
import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -68,8 +61,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
Display display; Display display;
@Inject @Inject
SharedPreferences preferences; SharedPreferences preferences;
@Inject
Keyboard keyboard;
@Nonnull @Nonnull
private static Class<?> getIntentListenerClass() { private static Class<?> getIntentListenerClass() {
@ -120,7 +111,7 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
final int width = Math.min(width0, height0); final int width = Math.min(width0, height0);
final int height = Math.max(width0, height0); final int height = Math.max(width0, height0);
view = CalculatorOnscreenView.create(this, CalculatorOnscreenViewState.create(width, height, -1, -1), this, preferences, keyboard); view = CalculatorOnscreenView.create(this, CalculatorOnscreenViewState.create(width, height, -1, -1), this, preferences);
view.show(); view.show();
view.updateEditorState(editor.getState()); view.updateEditorState(editor.getState());
view.updateDisplayState(display.getState()); view.updateDisplayState(display.getState());

View File

@ -31,54 +31,40 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.*;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppButton; import org.solovyev.android.calculator.buttons.CppButton;
import org.solovyev.android.calculator.DisplayState;
import org.solovyev.android.calculator.DisplayView;
import org.solovyev.android.calculator.EditorState;
import org.solovyev.android.calculator.EditorView;
import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.prefs.Preference; import org.solovyev.android.prefs.Preference;
import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Locale;
import static org.solovyev.android.calculator.App.cast;
public class CalculatorOnscreenView { public class CalculatorOnscreenView {
private static final String TAG = CalculatorOnscreenView.class.getSimpleName(); private static final String TAG = CalculatorOnscreenView.class.getSimpleName();
private static final Preference<CalculatorOnscreenViewState> viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.createDefault()); private static final Preference<CalculatorOnscreenViewState> viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.createDefault());
@Nonnull
private View root; private View root;
@Nonnull
private View content; private View content;
@Nonnull
private View header; private View header;
@Nonnull
private ImageView headerTitle; private ImageView headerTitle;
private Drawable headerTitleDrawable; private Drawable headerTitleDrawable;
@Nonnull
private EditorView editorView; private EditorView editorView;
@Nonnull
private DisplayView displayView; private DisplayView displayView;
@Nonnull
private Context context; private Context context;
@Nonnull @Nonnull
private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.createDefault(); private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.createDefault();
@Nullable @Nullable
private OnscreenViewListener viewListener; private OnscreenViewListener viewListener;
@Nonnull @Inject
private Keyboard keyboard; Keyboard keyboard;
@Inject
Editor editor;
private boolean minimized; private boolean minimized;
private boolean attached; private boolean attached;
@ -93,16 +79,14 @@ public class CalculatorOnscreenView {
public static CalculatorOnscreenView create(@Nonnull Context context, public static CalculatorOnscreenView create(@Nonnull Context context,
@Nonnull CalculatorOnscreenViewState state, @Nonnull CalculatorOnscreenViewState state,
@Nullable OnscreenViewListener viewListener, @Nullable OnscreenViewListener viewListener,
@NonNull SharedPreferences preferences, @NonNull SharedPreferences preferences) {
@NonNull Keyboard keyboard) {
final CalculatorOnscreenView view = new CalculatorOnscreenView(); final CalculatorOnscreenView view = new CalculatorOnscreenView();
cast(context).getComponent().inject(view);
final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences); final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences);
final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences); final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences);
view.root = View.inflate(context, theme.getOnscreenLayout(appTheme), null); view.root = View.inflate(context, theme.getOnscreenLayout(appTheme), null);
view.context = context; view.context = context;
view.viewListener = viewListener; view.viewListener = viewListener;
view.keyboard = keyboard;
final CalculatorOnscreenViewState persistedState = readState(context); final CalculatorOnscreenViewState persistedState = readState(context);
if (persistedState != null) { if (persistedState != null) {
@ -190,6 +174,7 @@ public class CalculatorOnscreenView {
displayView = (DisplayView) root.findViewById(R.id.calculator_display); displayView = (DisplayView) root.findViewById(R.id.calculator_display);
editorView = (EditorView) root.findViewById(R.id.calculator_editor); editorView = (EditorView) root.findViewById(R.id.calculator_editor);
editorView.setEditor(editor);
final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button); final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button);
onscreenFoldButton.setOnClickListener(new View.OnClickListener() { onscreenFoldButton.setOnClickListener(new View.OnClickListener() {