Inject WidgetProvider

This commit is contained in:
serso 2016-02-28 13:28:17 +01:00
parent d761ef553e
commit c324c1408e
2 changed files with 15 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import org.solovyev.android.calculator.variables.EditVariableFragment; import org.solovyev.android.calculator.variables.EditVariableFragment;
import org.solovyev.android.calculator.variables.VariablesFragment; import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.view.Tabs; import org.solovyev.android.calculator.view.Tabs;
import org.solovyev.android.calculator.widget.CalculatorWidget;
import org.solovyev.android.calculator.wizard.DragButtonWizardStep; import org.solovyev.android.calculator.wizard.DragButtonWizardStep;
import dagger.Component; import dagger.Component;
@ -61,4 +62,5 @@ public interface AppComponent {
void inject(PlotDimensionsFragment fragment); void inject(PlotDimensionsFragment fragment);
void inject(HistoryActivity activity); void inject(HistoryActivity activity);
void inject(Tabs tabs); void inject(Tabs tabs);
void inject(CalculatorWidget widget);
} }

View File

@ -48,11 +48,13 @@ import org.solovyev.android.calculator.buttons.CppButton;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.EnumMap; import java.util.EnumMap;
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT; import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Broadcaster.*; import static org.solovyev.android.calculator.Broadcaster.*;
import static org.solovyev.android.calculator.WidgetReceiver.newButtonClickedIntent; import static org.solovyev.android.calculator.WidgetReceiver.newButtonClickedIntent;
@ -64,6 +66,12 @@ public class CalculatorWidget extends AppWidgetProvider {
private static final Intents intents = new Intents(); private static final Intents intents = new Intents();
@Nullable @Nullable
private static SpannedString cursorString; private static SpannedString cursorString;
@Inject
Editor editor;
@Inject
Display display;
@Inject
Engine engine;
public CalculatorWidget() { public CalculatorWidget() {
} }
@ -109,8 +117,8 @@ public class CalculatorWidget extends AppWidgetProvider {
@Nonnull AppWidgetManager manager, @Nonnull AppWidgetManager manager,
@Nonnull int[] widgetIds, @Nonnull int[] widgetIds,
boolean partially) { boolean partially) {
final EditorState editorState = App.getEditor().getState(); final EditorState editorState = editor.getState();
final DisplayState displayState = App.getDisplay().getState(); final DisplayState displayState = display.getState();
final Resources resources = context.getResources(); final Resources resources = context.getResources();
final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme()); final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme());
@ -136,7 +144,7 @@ public class CalculatorWidget extends AppWidgetProvider {
updateEditorState(context, views, editorState, theme); updateEditorState(context, views, editorState, theme);
updateDisplayState(context, views, displayState, theme); updateDisplayState(context, views, displayState, theme);
views.setTextViewText(R.id.cpp_button_multiplication, Locator.getInstance().getEngine().getMultiplicationSign()); views.setTextViewText(R.id.cpp_button_multiplication, engine.getMultiplicationSign());
if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
manager.partiallyUpdateAppWidget(widgetId, views); manager.partiallyUpdateAppWidget(widgetId, views);
@ -186,6 +194,8 @@ public class CalculatorWidget extends AppWidgetProvider {
@Override @Override
public void onReceive(@Nonnull Context context, @Nonnull Intent intent) { public void onReceive(@Nonnull Context context, @Nonnull Intent intent) {
cast(context).getComponent().inject(this);
super.onReceive(context, intent); super.onReceive(context, intent);
final String action = intent.getAction(); final String action = intent.getAction();