Fragments

This commit is contained in:
serso 2016-02-05 21:52:36 +01:00
parent 9d9da8a608
commit 05024841e7
27 changed files with 356 additions and 680 deletions

View File

@ -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);
}

View File

@ -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) {
}

View File

@ -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) {

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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));
}
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -71,10 +71,6 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
@Nullable
private String category;
protected BaseEntitiesFragment(@Nonnull CalculatorFragmentType type) {
super(type);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View File

@ -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<Function> {
@Inject
@ -52,8 +54,10 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
@Inject
Bus bus;
public FunctionsFragment() {
super(CalculatorFragmentType.functions);
@Nonnull
@Override
protected FragmentUi createUi() {
return createUi(functions);
}
@Override

View File

@ -69,7 +69,6 @@ public abstract class BaseHistoryFragment extends BaseFragment {
private HistoryAdapter adapter;
protected BaseHistoryFragment(@Nonnull CalculatorFragmentType type) {
super(type);
recentHistory = type == CalculatorFragmentType.history;
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<Integer> {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
import static org.solovyev.android.calculator.CalculatorFragmentType.matrix_edit;
public class EditMatrixFragment extends BaseFragment implements Picker.OnChangedListener<Integer> {
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);
}
}

View File

@ -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<Operator> {
@Inject
@ -44,8 +46,10 @@ public class OperatorsFragment extends BaseEntitiesFragment<Operator> {
@Inject
PostfixFunctionsRegistry postfixFunctionsRegistry;
public OperatorsFragment() {
super(CalculatorFragmentType.operators);
@Nonnull
@Override
protected FragmentUi createUi() {
return createUi(operators);
}
@Override

View File

@ -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;
}
}
}

View File

@ -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<IConstant> {
@Inject
@ -55,8 +57,10 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> {
@Inject
Bus bus;
public VariablesFragment() {
super(CalculatorFragmentType.variables);
@Nonnull
@Override
protected FragmentUi createUi() {
return createUi(variables);
}
public static boolean isValidValue(@Nonnull String value) {

View File

@ -48,7 +48,7 @@
a:orientation="vertical">
<TextView
a:id="@+id/cpp_about_textview"
a:id="@+id/about_text"
style="@style/CppText.About"
a:layout_width="match_parent"
a:layout_height="match_parent"
@ -56,7 +56,7 @@
<TextView
a:id="@+id/cpp_about_translators_text"
a:id="@+id/about_translators_label"
style="@style/CppText.About"
a:layout_width="match_parent"
a:layout_height="wrap_content"
@ -64,7 +64,7 @@
a:text="@string/cpp_translators_text" />
<TextView
a:id="@+id/cpp_about_translators"
a:id="@+id/about_translators"
style="@style/CppText.About"
a:layout_width="match_parent"
a:layout_height="wrap_content"

View File

@ -23,21 +23,15 @@
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<TextView
a:id="@+id/releaseNotesTextView"
a:id="@+id/releasenotes_text"
style="@style/CppText.About"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:layout_weight="1"
a:gravity="top|left"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:scrollbars="vertical" />
<!--
a:scrollbarFadeDuration="0" is not support in android_1.6_compatibility
-->
</LinearLayout>