From 05024841e7c4a24be415dd6083fe64bb9a5ba48c Mon Sep 17 00:00:00 2001 From: serso Date: Fri, 5 Feb 2016 21:52:36 +0100 Subject: [PATCH] Fragments --- .../android/calculator/AppComponent.java | 5 +- .../android/calculator/BaseFragment.java | 16 ++- .../calculator/CalculatorActivity.java | 4 +- .../calculator/CalculatorDisplayFragment.java | 109 ----------------- .../calculator/CalculatorFragment.java | 114 ------------------ .../calculator/CalculatorFragmentType.java | 12 +- .../calculator/CalculatorListFragment.java | 109 ----------------- .../android/calculator/DisplayFragment.java | 75 ++++++++++++ .../android/calculator/EditorFragment.java | 89 ++++---------- .../android/calculator/FragmentUi.java | 4 +- ...ardFragment.java => KeyboardFragment.java} | 93 ++++++-------- .../calculator/NumeralBaseButtons.java | 5 - .../calculator/about/AboutFragment.java | 76 ++++++++++++ .../about/CalculatorAboutFragment.java | 69 ----------- ...ragment.java => ReleaseNotesFragment.java} | 42 ++++--- .../calculator/buttons/CppButtons.java | 47 ++++---- .../entities/BaseEntitiesFragment.java | 4 - .../functions/FunctionsFragment.java | 8 +- .../history/BaseHistoryFragment.java | 1 - .../history/RecentHistoryFragment.java | 13 +- .../history/SavedHistoryFragment.java | 14 ++- ...tFragment.java => EditMatrixFragment.java} | 47 ++------ .../operators/OperatorsFragment.java | 8 +- .../preferences/PurchaseDialogActivity.java | 42 ++++--- .../variables/VariablesFragment.java | 8 +- app/src/main/res/layout/about_fragment.xml | 6 +- .../res/layout/release_notes_fragment.xml | 16 +-- 27 files changed, 356 insertions(+), 680 deletions(-) delete mode 100644 app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java delete mode 100644 app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java delete mode 100644 app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java create mode 100644 app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java rename app/src/main/java/org/solovyev/android/calculator/{CalculatorKeyboardFragment.java => KeyboardFragment.java} (62%) create mode 100644 app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java delete mode 100644 app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutFragment.java rename app/src/main/java/org/solovyev/android/calculator/about/{CalculatorReleaseNotesFragment.java => ReleaseNotesFragment.java} (53%) rename app/src/main/java/org/solovyev/android/calculator/matrix/{CalculatorMatrixEditFragment.java => EditMatrixFragment.java} (77%) 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 6add75bc..3340f076 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -1,5 +1,6 @@ package org.solovyev.android.calculator; +import dagger.Component; import org.solovyev.android.calculator.errors.FixableErrorFragment; import org.solovyev.android.calculator.errors.FixableErrorsActivity; import org.solovyev.android.calculator.functions.EditFunctionFragment; @@ -13,8 +14,6 @@ import org.solovyev.android.calculator.variables.VariablesFragment; import javax.inject.Singleton; -import dagger.Component; - @Singleton @Component(modules = AppModule.class) public interface AppComponent { @@ -34,4 +33,6 @@ public interface AppComponent { void inject(CalculatorActivity activity); void inject(FixableErrorsActivity activity); void inject(CalculatorReceiver receiver); + void inject(DisplayFragment fragment); + void inject(KeyboardFragment fragment); } diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java b/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java index c478c11a..cb8bad3e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java @@ -12,20 +12,24 @@ import static org.solovyev.android.calculator.App.cast; public abstract class BaseFragment extends Fragment { - @Nonnull - protected final FragmentUi ui; - - public BaseFragment(@Nonnull CalculatorFragmentType type) { - ui = new FragmentUi(type.getDefaultLayoutId(), type.getDefaultTitleResId(), false); - } + protected FragmentUi ui; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); inject(cast(getActivity().getApplication()).getComponent()); + ui = createUi(); ui.onCreate(this); } + @Nonnull + protected abstract FragmentUi createUi(); + + @Nonnull + protected final FragmentUi createUi(@Nonnull CalculatorFragmentType type) { + return new FragmentUi(type.getDefaultLayoutId(), type.getDefaultTitleResId(), false); + } + protected void inject(@Nonnull AppComponent component) { } diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index b993dd37..298b3bf4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -174,8 +174,8 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference } FragmentUtils.createFragment(this, EditorFragment.class, R.id.editorContainer, "editor"); - FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display"); - FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard"); + FragmentUtils.createFragment(this, DisplayFragment.class, R.id.displayContainer, "display"); + FragmentUtils.createFragment(this, KeyboardFragment.class, R.id.keyboardContainer, "keyboard"); this.useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences); if (savedInstanceState == null) { diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java deleted file mode 100644 index 6a39ae8c..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 25.09.12 - * Time: 12:03 - */ -public class CalculatorDisplayFragment extends Fragment { - - @Nonnull - private FragmentUi fragmentUi; - @Nonnull - private DisplayView displayView; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); - final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs); - if (!layout.optimized) { - fragmentUi = new FragmentUi(R.layout.cpp_app_display_mobile, R.string.result); - } else { - fragmentUi = new FragmentUi(R.layout.cpp_app_display, R.string.result); - } - - fragmentUi.onCreate(this); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return fragmentUi.onCreateView(this, inflater, container); - } - - @Override - public void onViewCreated(View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - - displayView = (DisplayView) root.findViewById(R.id.calculator_display); - App.getDisplay().setView(displayView); - - fragmentUi.onViewCreated(this, root); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - } - - @Override - public void onResume() { - super.onResume(); - - fragmentUi.onResume(this); - } - - @Override - public void onPause() { - fragmentUi.onPause(this); - - super.onPause(); - } - - @Override - public void onDestroyView() { - App.getDisplay().clearView(displayView); - fragmentUi.onDestroyView(this); - super.onDestroyView(); - } - - @Override - public void onDestroy() { - fragmentUi.onDestroy(this); - - super.onDestroy(); - } -} diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java deleted file mode 100644 index 37ad7c76..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 03.10.12 - * Time: 14:18 - */ -public abstract class CalculatorFragment extends Fragment { - - @Nonnull - private final FragmentUi fragmentUi; - - protected CalculatorFragment(int layoutResId, int titleResId) { - fragmentUi = new FragmentUi(layoutResId, titleResId); - } - - protected CalculatorFragment(@Nonnull CalculatorFragmentType fragmentType) { - fragmentUi = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); - } - - protected CalculatorFragment(@Nonnull FragmentUi fragmentUi) { - this.fragmentUi = fragmentUi; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - fragmentUi.onCreate(this); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return fragmentUi.onCreateView(this, inflater, container); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - fragmentUi.onViewCreated(this, view); - } - - @Override - public void onResume() { - super.onResume(); - - this.fragmentUi.onResume(this); - } - - @Override - public void onPause() { - this.fragmentUi.onPause(this); - - super.onPause(); - } - - @Override - public void onDestroyView() { - fragmentUi.onDestroyView(this); - super.onDestroyView(); - } - - @Override - public void onDestroy() { - fragmentUi.onDestroy(this); - super.onDestroy(); - } - - @Override - public void onDetach() { - super.onDetach(); - } - - public boolean isPaneFragment() { - return fragmentUi.isPane(this); - } -} diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java index bfb9c250..46f97425 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java @@ -24,14 +24,14 @@ package org.solovyev.android.calculator; import android.support.v4.app.Fragment; -import org.solovyev.android.calculator.about.CalculatorAboutFragment; -import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment; +import org.solovyev.android.calculator.about.AboutFragment; +import org.solovyev.android.calculator.about.ReleaseNotesFragment; import org.solovyev.android.calculator.history.RecentHistoryFragment; import org.solovyev.android.calculator.history.SavedHistoryFragment; import org.solovyev.android.calculator.functions.FunctionsFragment; import org.solovyev.android.calculator.operators.OperatorsFragment; import org.solovyev.android.calculator.variables.VariablesFragment; -import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment; +import org.solovyev.android.calculator.matrix.EditMatrixFragment; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import javax.annotation.Nonnull; @@ -54,11 +54,11 @@ public enum CalculatorFragmentType { purchase_dialog(PurchaseDialogActivity.PurchaseDialogFragment.class, R.layout.cpp_purchase_dialog_fragment, R.string.cpp_purchase_title), - about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about), + about(AboutFragment.class, R.layout.about_fragment, R.string.c_about), // todo serso: strings - matrix_edit(CalculatorMatrixEditFragment.class, R.layout.matrix_edit_fragment, R.string.c_release_notes), - release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes); + matrix_edit(EditMatrixFragment.class, R.layout.matrix_edit_fragment, R.string.c_release_notes), + release_notes(ReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes); private final int defaultLayoutId; @Nonnull diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java deleted file mode 100644 index 2688724f..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 03.10.12 - * Time: 14:18 - */ -public abstract class CalculatorListFragment extends ListFragment { - - @Nonnull - private final FragmentUi ui; - - protected CalculatorListFragment(int layoutResId, int titleResId) { - ui = new FragmentUi(layoutResId, titleResId); - } - - protected CalculatorListFragment(@Nonnull CalculatorFragmentType fragmentType) { - ui = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); - } - - protected CalculatorListFragment(@Nonnull FragmentUi ui) { - this.ui = ui; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ui.onCreate(this); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return ui.onCreateView(this, inflater, container); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - ui.onViewCreated(this, view); - } - - @Override - public void onResume() { - super.onResume(); - this.ui.onResume(this); - } - - @Override - public void onPause() { - this.ui.onPause(this); - super.onPause(); - } - - @Override - public void onDestroyView() { - ui.onDestroyView(this); - super.onDestroyView(); - } - - @Override - public void onDestroy() { - ui.onDestroy(this); - super.onDestroy(); - } - - @Override - public void onDetach() { - super.onDetach(); - } -} - diff --git a/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java b/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java new file mode 100644 index 00000000..811499aa --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.calculator; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import butterknife.Bind; +import butterknife.ButterKnife; + +import javax.annotation.Nonnull; +import javax.inject.Inject; + +public class DisplayFragment extends BaseFragment { + + @Bind(R.id.calculator_display) + DisplayView displayView; + @Inject + SharedPreferences preferences; + @Inject + Display display; + + @Override + protected void inject(@Nonnull AppComponent component) { + super.inject(component); + component.inject(this); + } + + @Nonnull + @Override + protected FragmentUi createUi() { + final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); + if (!layout.optimized) { + return new FragmentUi(R.layout.cpp_app_display_mobile, R.string.result); + } else { + return new FragmentUi(R.layout.cpp_app_display, R.string.result); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + display.setView(displayView); + return view; + } + + @Override + public void onDestroyView() { + display.clearView(displayView); + super.onDestroyView(); + } +} diff --git a/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java b/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java index c91547e7..1b783aca 100644 --- a/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java @@ -22,28 +22,17 @@ package org.solovyev.android.calculator; -import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; - +import android.view.*; +import butterknife.Bind; +import butterknife.ButterKnife; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; +import javax.annotation.Nonnull; import javax.inject.Inject; -import static org.solovyev.android.calculator.App.cast; - -public class EditorFragment extends Fragment { - - private FragmentUi ui; - - private EditorView editorView; +public class EditorFragment extends BaseFragment { @Inject Editor editor; @@ -51,57 +40,38 @@ public class EditorFragment extends Fragment { SharedPreferences preferences; @Inject ActivityLauncher launcher; - - public EditorFragment() { - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } + @Bind(R.id.calculator_editor) + EditorView editorView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - cast(getActivity().getApplication()).getComponent().inject(this); - - final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); - if (!layout.optimized) { - ui = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor); - } else { - ui = new FragmentUi(R.layout.cpp_app_editor, R.string.editor); - } - - ui.onCreate(this); setHasOptionsMenu(true); } @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + protected void inject(@Nonnull AppComponent component) { + super.inject(component); + component.inject(this); + } - ui.onViewCreated(this, view); - - editorView = (EditorView) view.findViewById(R.id.calculator_editor); - editor.setView(editorView); + @Nonnull + @Override + protected FragmentUi createUi() { + final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); + if (!layout.optimized) { + return new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor); + } else { + return new FragmentUi(R.layout.cpp_app_editor, R.string.editor); + } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return ui.onCreateView(this, inflater, container); - } - - @Override - public void onResume() { - super.onResume(); - this.ui.onResume(this); - } - - @Override - public void onPause() { - this.ui.onPause(this); - super.onPause(); + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + editor.setView(editorView); + return view; } @Override @@ -112,17 +82,6 @@ public class EditorFragment extends Fragment { } @Override - public void onDestroy() { - ui.onDestroy(this); - super.onDestroy(); - } - - @Override - public void onDetach() { - super.onDetach(); - } - - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.main, menu); } diff --git a/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java b/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java index 64a7d7f9..8e76893b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java @@ -144,7 +144,7 @@ public class FragmentUi extends BaseUi { adView = (AdView) root.findViewById(R.id.ad); final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout); - if (fragment instanceof CalculatorDisplayFragment || fragment instanceof EditorFragment || fragment instanceof CalculatorKeyboardFragment) { + if (fragment instanceof DisplayFragment || fragment instanceof EditorFragment || fragment instanceof KeyboardFragment) { // no ads in those fragments } else { if (adView != null) { @@ -153,7 +153,7 @@ public class FragmentUi extends BaseUi { } } - if (fragment instanceof CalculatorKeyboardFragment) { + if (fragment instanceof KeyboardFragment) { processButtons(fragment.getActivity(), root); } fixFonts(root); diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java b/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java similarity index 62% rename from app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java rename to app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java index 5853e87a..8e9cb87f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java @@ -24,89 +24,68 @@ package org.solovyev.android.calculator; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; - +import android.widget.Button; +import butterknife.Bind; +import butterknife.ButterKnife; import org.solovyev.android.calculator.buttons.CppButtons; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; +import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign; +import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; import static org.solovyev.android.calculator.NumeralBaseButtons.toggleNumericDigits; import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits; import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton; -import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign; -import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; -/** - * User: Solovyev_S - * Date: 25.09.12 - * Time: 12:25 - */ -public class CalculatorKeyboardFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener { +public class KeyboardFragment extends BaseFragment implements SharedPreferences.OnSharedPreferenceChangeListener { - @Nonnull - private FragmentUi ui; + @Inject + SharedPreferences preferences; + @Bind(R.id.cpp_button_multiplication) + Button multiplicationButton; + @Nullable + @Bind(R.id.cpp_button_equals) + Button equalsButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - final SharedPreferences preferences = App.getPreferences(); - - final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); - if (!layout.optimized) { - ui = new FragmentUi(R.layout.cpp_app_keyboard_mobile); - } else { - ui = new FragmentUi(R.layout.cpp_app_keyboard); - } - - ui.onCreate(this); - preferences.registerOnSharedPreferenceChangeListener(this); } + @Override + protected void inject(@Nonnull AppComponent component) { + super.inject(component); + component.inject(this); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return ui.onCreateView(this, inflater, container); + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + return view; } + @Nonnull @Override - public void onViewCreated(View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - ui.onViewCreated(this, root); - } - - - @Override - public void onResume() { - super.onResume(); - this.ui.onResume(this); - } - - @Override - public void onPause() { - this.ui.onPause(this); - super.onPause(); - } - - @Override - public void onDestroyView() { - ui.onDestroyView(this); - super.onDestroyView(); + protected FragmentUi createUi() { + final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); + if (!layout.optimized) { + return new FragmentUi(R.layout.cpp_app_keyboard_mobile); + } else { + return new FragmentUi(R.layout.cpp_app_keyboard); + } } @Override public void onDestroy() { + preferences.unregisterOnSharedPreferenceChangeListener(this); super.onDestroy(); - ui.onDestroy(this); - App.getPreferences().unregisterOnSharedPreferenceChangeListener(this); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); } @Override @@ -115,12 +94,12 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer toggleNumericDigits(this.getActivity(), preferences); } - if (showEqualsButton.isSameKey(key)) { - CppButtons.toggleEqualsButton(preferences, this.getActivity()); + if (equalsButton != null && showEqualsButton.isSameKey(key)) { + CppButtons.toggleEqualsButton(preferences, getActivity(), equalsButton); } if (multiplicationSign.isSameKey(key)) { - CppButtons.initMultiplicationButton(getView()); + multiplicationButton.setText(Engine.Preferences.multiplicationSign.getPreference(preferences)); } } } diff --git a/app/src/main/java/org/solovyev/android/calculator/NumeralBaseButtons.java b/app/src/main/java/org/solovyev/android/calculator/NumeralBaseButtons.java index 117728d2..24e62e03 100644 --- a/app/src/main/java/org/solovyev/android/calculator/NumeralBaseButtons.java +++ b/app/src/main/java/org/solovyev/android/calculator/NumeralBaseButtons.java @@ -32,11 +32,6 @@ import static jscl.NumeralBase.hex; import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits; -/** - * User: serso - * Date: 4/20/12 - * Time: 5:03 PM - */ public class NumeralBaseButtons { public static void toggleNumericDigits(@Nonnull Activity activity, @Nonnull NumeralBase currentNumeralBase) { diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java new file mode 100644 index 00000000..0873dec5 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java @@ -0,0 +1,76 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.calculator.about; + +import android.os.Bundle; +import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; +import butterknife.Bind; +import butterknife.ButterKnife; +import org.solovyev.android.calculator.BaseFragment; +import org.solovyev.android.calculator.FragmentUi; +import org.solovyev.android.calculator.R; + +import javax.annotation.Nonnull; + +import static android.view.View.GONE; +import static org.solovyev.android.calculator.CalculatorFragmentType.about; +import static org.solovyev.common.text.Strings.isEmpty; + +public class AboutFragment extends BaseFragment { + + @Bind(R.id.about_image) + ImageView imageView; + @Bind(R.id.about_text) + TextView textView; + @Bind(R.id.about_translators_label) + TextView translatorsLabel; + @Bind(R.id.about_translators) + TextView translatorsView; + + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(about); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + if (ui.getTheme().light) { + imageView.setImageResource(R.drawable.logo_wizard_light); + } + textView.setMovementMethod(LinkMovementMethod.getInstance()); + + if (isEmpty(translatorsView.getText())) { + translatorsLabel.setVisibility(GONE); + translatorsView.setVisibility(GONE); + } + return view; + } +} diff --git a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutFragment.java b/app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutFragment.java deleted file mode 100644 index 9d3432c0..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutFragment.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator.about; - -import android.os.Bundle; -import android.text.method.LinkMovementMethod; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; - -import static android.view.View.GONE; -import static org.solovyev.common.text.Strings.isEmpty; - -/** - * User: serso - * Date: 12/24/11 - * Time: 11:55 PM - */ -public class CalculatorAboutFragment extends CalculatorFragment { - - public CalculatorAboutFragment() { - super(CalculatorFragmentType.about); - } - - @Override - public void onViewCreated(View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - - if (App.getTheme().light) { - final ImageView image = (ImageView) root.findViewById(R.id.about_image); - image.setImageResource(R.drawable.logo_wizard_light); - } - - final TextView aboutTextView = (TextView) root.findViewById(R.id.cpp_about_textview); - aboutTextView.setMovementMethod(LinkMovementMethod.getInstance()); - - final TextView translatorsTextTextView = (TextView) root.findViewById(R.id.cpp_about_translators_text); - final TextView translatorsTextView = (TextView) root.findViewById(R.id.cpp_about_translators); - if (isEmpty(translatorsTextView.getText())) { - translatorsTextTextView.setVisibility(GONE); - translatorsTextView.setVisibility(GONE); - } - } -} diff --git a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java b/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java similarity index 53% rename from app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java rename to app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java index fe53ede7..40838a2a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java @@ -25,32 +25,38 @@ package org.solovyev.android.calculator.about; import android.os.Bundle; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; - -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; +import butterknife.Bind; +import butterknife.ButterKnife; +import org.solovyev.android.calculator.BaseFragment; +import org.solovyev.android.calculator.FragmentUi; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.release.ReleaseNotes; -/** - * User: serso - * Date: 12/25/11 - * Time: 12:00 AM - */ -public class CalculatorReleaseNotesFragment extends CalculatorFragment { +import javax.annotation.Nonnull; - public CalculatorReleaseNotesFragment() { - super(CalculatorFragmentType.release_notes); +import static org.solovyev.android.calculator.CalculatorFragmentType.release_notes; + +public class ReleaseNotesFragment extends BaseFragment { + + @Bind(R.id.releasenotes_text) + TextView text; + + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(release_notes); } @Override - public void onViewCreated(View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - - final TextView releaseNotes = (TextView) root.findViewById(R.id.releaseNotesTextView); - releaseNotes.setMovementMethod(LinkMovementMethod.getInstance()); - - releaseNotes.setText(Html.fromHtml(ReleaseNotes.getReleaseNotes(this.getActivity()))); + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + text.setMovementMethod(LinkMovementMethod.getInstance()); + text.setText(Html.fromHtml(ReleaseNotes.getReleaseNotes(getActivity()))); + return view; } } diff --git a/app/src/main/java/org/solovyev/android/calculator/buttons/CppButtons.java b/app/src/main/java/org/solovyev/android/calculator/buttons/CppButtons.java index d8695580..45f18ed0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/buttons/CppButtons.java +++ b/app/src/main/java/org/solovyev/android/calculator/buttons/CppButtons.java @@ -33,17 +33,10 @@ import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.widget.Button; - +import jscl.AngleUnit; +import jscl.NumeralBase; import org.solovyev.android.Views; -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.CalculatorEventType; -import org.solovyev.android.calculator.DigitButtonDragProcessor; -import org.solovyev.android.calculator.Engine; -import org.solovyev.android.calculator.Keyboard; -import org.solovyev.android.calculator.Locator; -import org.solovyev.android.calculator.Preferences; -import org.solovyev.android.calculator.PreferredPreferences; -import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.ScreenMetrics; @@ -54,9 +47,6 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import jscl.AngleUnit; -import jscl.NumeralBase; - public final class CppButtons { private CppButtons() { @@ -95,22 +85,27 @@ public final class CppButtons { public static void toggleEqualsButton(@Nullable SharedPreferences preferences, @Nonnull Activity activity) { preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences; + final DragButton equalsButton = (DragButton) activity.findViewById(R.id.cpp_button_equals); + if(equalsButton == null) { + return; + } + toggleEqualsButton(preferences, activity, equalsButton); + } + + public static void toggleEqualsButton(@Nonnull SharedPreferences preferences, @Nonnull Activity activity, @Nonnull Button button) { final boolean large = App.isLargeScreen() && Preferences.Gui.getLayout(preferences).optimized; + if (large) { + return; + } + if (Views.getScreenOrientation(activity) != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.autoOrientation.getPreference(preferences)) { + return; + } - if (!large) { - if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT - || !Preferences.Gui.autoOrientation.getPreference(preferences)) { - - final DragButton equalsButton = (DragButton) activity.findViewById(R.id.cpp_button_equals); - if (equalsButton != null) { - if (Preferences.Gui.showEqualsButton.getPreference(preferences)) { - equalsButton.setVisibility(View.VISIBLE); - } else { - equalsButton.setVisibility(View.GONE); - } - } - } + if (Preferences.Gui.showEqualsButton.getPreference(preferences)) { + button.setVisibility(View.VISIBLE); + } else { + button.setVisibility(View.GONE); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java index 2c82581d..d659b02e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java @@ -71,10 +71,6 @@ public abstract class BaseEntitiesFragment extends BaseFra @Nullable private String category; - protected BaseEntitiesFragment(@Nonnull CalculatorFragmentType type) { - super(type); - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java index 0d49c3d0..f6ea875a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java @@ -43,6 +43,8 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import static org.solovyev.android.calculator.CalculatorFragmentType.functions; + public class FunctionsFragment extends BaseEntitiesFragment { @Inject @@ -52,8 +54,10 @@ public class FunctionsFragment extends BaseEntitiesFragment { @Inject Bus bus; - public FunctionsFragment() { - super(CalculatorFragmentType.functions); + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(functions); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java index 49b9adee..a13a4456 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java @@ -69,7 +69,6 @@ public abstract class BaseHistoryFragment extends BaseFragment { private HistoryAdapter adapter; protected BaseHistoryFragment(@Nonnull CalculatorFragmentType type) { - super(type); recentHistory = type == CalculatorFragmentType.history; } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java index b2332fdf..832273b2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java @@ -22,19 +22,20 @@ package org.solovyev.android.calculator.history; -import android.view.ContextMenu; -import android.view.MenuItem; import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.FragmentUi; import javax.annotation.Nonnull; -import java.util.List; - -import static android.view.Menu.NONE; public class RecentHistoryFragment extends BaseHistoryFragment { public RecentHistoryFragment() { super(CalculatorFragmentType.history); } + + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(CalculatorFragmentType.history); + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java index 9259de17..d667b3d4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java @@ -22,11 +22,21 @@ package org.solovyev.android.calculator.history; -import org.solovyev.android.calculator.CalculatorFragmentType; +import org.solovyev.android.calculator.FragmentUi; + +import javax.annotation.Nonnull; + +import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history; public class SavedHistoryFragment extends BaseHistoryFragment { public SavedHistoryFragment() { - super(CalculatorFragmentType.saved_history); + super(saved_history); + } + + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(saved_history); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixEditFragment.java b/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java similarity index 77% rename from app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixEditFragment.java rename to app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java index ce9fb3e8..d1839fef 100644 --- a/app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixEditFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java @@ -25,30 +25,16 @@ package org.solovyev.android.calculator.matrix; import android.os.Bundle; import android.view.View; -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.*; import org.solovyev.android.view.IntegerRange; import org.solovyev.android.view.Picker; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** - * User: Solovyev_S - * Date: 12.10.12 - * Time: 10:41 - */ -public class CalculatorMatrixEditFragment extends CalculatorFragment implements Picker.OnChangedListener { - - /* - ********************************************************************** - * - * CONSTANTS - * - ********************************************************************** - */ +import static org.solovyev.android.calculator.CalculatorFragmentType.matrix_edit; +public class EditMatrixFragment extends BaseFragment implements Picker.OnChangedListener { private static final int MAX_COUNT = 10; private static final int MIN_COUNT = 2; private static final int DEFAULT_ROWS = 2; @@ -56,29 +42,15 @@ public class CalculatorMatrixEditFragment extends CalculatorFragment implements private static final String MATRIX = "matrix"; - - /* - ********************************************************************** - * - * CONSTRUCTORS - * - ********************************************************************** - */ - - public CalculatorMatrixEditFragment() { - super(CalculatorFragmentType.matrix_edit); - + public EditMatrixFragment() { setRetainInstance(true); } - /* - ********************************************************************** - * - * METHODS - * - ********************************************************************** - */ - + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(matrix_edit); + } @Override public void onViewCreated(View root, @Nullable Bundle in) { @@ -143,5 +115,4 @@ public class CalculatorMatrixEditFragment extends CalculatorFragment implements private void onRowsCountChange(@Nonnull Integer newRows) { getMatrixView(getView()).setMatrixRows(newRows); } - } diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java index ffb72ca9..9bde9107 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java @@ -37,6 +37,8 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import static org.solovyev.android.calculator.CalculatorFragmentType.operators; + public class OperatorsFragment extends BaseEntitiesFragment { @Inject @@ -44,8 +46,10 @@ public class OperatorsFragment extends BaseEntitiesFragment { @Inject PostfixFunctionsRegistry postfixFunctionsRegistry; - public OperatorsFragment() { - super(CalculatorFragmentType.operators); + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(operators); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java index cdfd09f3..83402f07 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java @@ -26,15 +26,14 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; -import org.solovyev.android.calculator.ActivityUi; -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.BaseActivity; -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; +import butterknife.Bind; +import butterknife.ButterKnife; +import org.solovyev.android.calculator.*; import org.solovyev.android.checkout.ActivityCheckout; import org.solovyev.android.checkout.BillingRequests; import org.solovyev.android.checkout.Checkout; @@ -46,11 +45,8 @@ import org.solovyev.android.fragments.FragmentUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** - * User: serso - * Date: 1/20/13 - * Time: 2:36 PM - */ +import static org.solovyev.android.calculator.CalculatorFragmentType.purchase_dialog; + public class PurchaseDialogActivity extends BaseActivity { @Nonnull @@ -117,18 +113,25 @@ public class PurchaseDialogActivity extends BaseActivity { super.onDestroy(); } - public static class PurchaseDialogFragment extends CalculatorFragment { + public static class PurchaseDialogFragment extends BaseFragment { - public PurchaseDialogFragment() { - super(CalculatorFragmentType.purchase_dialog); + @Bind(R.id.cpp_purchase_text) + TextView purchaseText; + @Bind(R.id.cpp_continue_button) + View continueButton; + + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(purchase_dialog); } @Override - public void onViewCreated(@Nonnull View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - - ((TextView) root.findViewById(R.id.cpp_purchase_text)).setMovementMethod(ScrollingMovementMethod.getInstance()); - root.findViewById(R.id.cpp_continue_button).setOnClickListener(new View.OnClickListener() { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + ButterKnife.bind(this, view); + purchaseText.setMovementMethod(ScrollingMovementMethod.getInstance()); + continueButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Activity activity = getActivity(); @@ -137,6 +140,7 @@ public class PurchaseDialogActivity extends BaseActivity { } } }); + return view; } } } diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java index d3d43aa4..6f064754 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java @@ -46,6 +46,8 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import static org.solovyev.android.calculator.CalculatorFragmentType.variables; + public class VariablesFragment extends BaseEntitiesFragment { @Inject @@ -55,8 +57,10 @@ public class VariablesFragment extends BaseEntitiesFragment { @Inject Bus bus; - public VariablesFragment() { - super(CalculatorFragmentType.variables); + @Nonnull + @Override + protected FragmentUi createUi() { + return createUi(variables); } public static boolean isValidValue(@Nonnull String value) { diff --git a/app/src/main/res/layout/about_fragment.xml b/app/src/main/res/layout/about_fragment.xml index 5ecea236..4384cd65 100644 --- a/app/src/main/res/layout/about_fragment.xml +++ b/app/src/main/res/layout/about_fragment.xml @@ -48,7 +48,7 @@ a:orientation="vertical"> - - \ No newline at end of file