From 106783eee7bd3fb6cf128163010643bc6479d5e6 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 7 Feb 2016 13:56:17 +0100 Subject: [PATCH] Fix assertion EditorView must have Editor attached --- .../android/calculator/AppComponent.java | 2 + .../onscreen/CalculatorOnscreenService.java | 13 +----- .../onscreen/CalculatorOnscreenView.java | 41 ++++++------------- 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index 02389a27..907e2083 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -9,6 +9,7 @@ import org.solovyev.android.calculator.history.BaseHistoryFragment; import org.solovyev.android.calculator.history.EditHistoryFragment; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; 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.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; @@ -42,4 +43,5 @@ public interface AppComponent { void inject(PurchaseDialogActivity activity); void inject(PreferencesActivity activity); void inject(BaseKeyboardUi ui); + void inject(CalculatorOnscreenView view); } diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java b/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java index aea37965..9c6f2fe2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java +++ b/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java @@ -32,18 +32,11 @@ import android.os.IBinder; import android.support.v4.app.NotificationCompat; import android.util.DisplayMetrics; import android.view.WindowManager; - import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; - import org.solovyev.android.Check; import org.solovyev.android.Views; -import org.solovyev.android.calculator.App; -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 org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -68,8 +61,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi Display display; @Inject SharedPreferences preferences; - @Inject - Keyboard keyboard; @Nonnull private static Class getIntentListenerClass() { @@ -120,7 +111,7 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi final int width = Math.min(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.updateEditorState(editor.getState()); view.updateDisplayState(display.getState()); diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java b/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java index 29afdba7..40f5646f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java +++ b/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java @@ -31,54 +31,40 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.util.DisplayMetrics; import android.util.Log; -import android.view.Gravity; -import android.view.HapticFeedbackConstants; -import android.view.MotionEvent; -import android.view.View; -import android.view.WindowManager; +import android.view.*; import android.widget.ImageView; - +import org.solovyev.android.calculator.*; 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 java.util.Locale; - import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.inject.Inject; +import java.util.Locale; + +import static org.solovyev.android.calculator.App.cast; public class CalculatorOnscreenView { private static final String TAG = CalculatorOnscreenView.class.getSimpleName(); private static final Preference viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.createDefault()); - @Nonnull private View root; - @Nonnull private View content; - @Nonnull private View header; - @Nonnull private ImageView headerTitle; private Drawable headerTitleDrawable; - @Nonnull private EditorView editorView; - @Nonnull private DisplayView displayView; - @Nonnull private Context context; @Nonnull private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.createDefault(); @Nullable private OnscreenViewListener viewListener; - @Nonnull - private Keyboard keyboard; + @Inject + Keyboard keyboard; + @Inject + Editor editor; private boolean minimized; private boolean attached; @@ -93,16 +79,14 @@ public class CalculatorOnscreenView { public static CalculatorOnscreenView create(@Nonnull Context context, @Nonnull CalculatorOnscreenViewState state, @Nullable OnscreenViewListener viewListener, - @NonNull SharedPreferences preferences, - @NonNull Keyboard keyboard) { + @NonNull SharedPreferences preferences) { final CalculatorOnscreenView view = new CalculatorOnscreenView(); - + cast(context).getComponent().inject(view); final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences); final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences); view.root = View.inflate(context, theme.getOnscreenLayout(appTheme), null); view.context = context; view.viewListener = viewListener; - view.keyboard = keyboard; final CalculatorOnscreenViewState persistedState = readState(context); if (persistedState != null) { @@ -190,6 +174,7 @@ public class CalculatorOnscreenView { displayView = (DisplayView) root.findViewById(R.id.calculator_display); editorView = (EditorView) root.findViewById(R.id.calculator_editor); + editorView.setEditor(editor); final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button); onscreenFoldButton.setOnClickListener(new View.OnClickListener() {