Remove CalculatorMenu
This commit is contained in:
parent
07a1608a80
commit
f50f8b599b
@ -69,57 +69,16 @@ public final class ActivityLauncher implements CalculatorEventListener {
|
||||
public ActivityLauncher() {
|
||||
}
|
||||
|
||||
private static void showActivity(@Nonnull final Context context, @NonNull Class<? extends Activity> activity) {
|
||||
showActivity(context, new Intent(context, activity));
|
||||
private static void show(@Nonnull final Context context, @NonNull Class<? extends Activity> activity) {
|
||||
show(context, new Intent(context, activity));
|
||||
}
|
||||
|
||||
private static void showActivity(@Nonnull Context context, @NonNull Intent intent) {
|
||||
private static void show(@Nonnull Context context, @NonNull Intent intent) {
|
||||
final boolean detached = !(context instanceof Activity);
|
||||
Activities.addIntentFlags(intent, detached, context);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public void showHistory() {
|
||||
showHistory(getContext());
|
||||
}
|
||||
|
||||
public void showSettings() {
|
||||
showSettings(getContext());
|
||||
}
|
||||
|
||||
public void showWidgetSettings() {
|
||||
final Context context = getContext();
|
||||
showActivity(context, PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.prefs_widget_title));
|
||||
}
|
||||
|
||||
public static void showHistory(@Nonnull final Context context) {
|
||||
show(context, HistoryActivity.class);
|
||||
}
|
||||
|
||||
private static void show(@Nonnull Context context, Class<HistoryActivity> activity) {
|
||||
showActivity(context, activity);
|
||||
}
|
||||
|
||||
public void showOperators() {
|
||||
showActivity(getContext(), OperatorsActivity.class);
|
||||
}
|
||||
|
||||
public static void showSettings(@Nonnull final Context context) {
|
||||
showActivity(context, PreferencesActivity.class);
|
||||
}
|
||||
|
||||
public static void showAbout(@Nonnull final Context context) {
|
||||
context.startActivity(new Intent(context, AboutActivity.class));
|
||||
}
|
||||
|
||||
public static void showFunctions(@Nonnull final Context context) {
|
||||
showActivity(context, FunctionsActivity.class);
|
||||
}
|
||||
|
||||
public static void showVariables(@Nonnull final Context context) {
|
||||
showActivity(context, VariablesActivity.class);
|
||||
}
|
||||
|
||||
public static void tryCreateVar(@Nonnull final Context context) {
|
||||
final Display display = App.getDisplay();
|
||||
final DisplayState state = display.getState();
|
||||
@ -190,6 +149,27 @@ public final class ActivityLauncher implements CalculatorEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void showHistory() {
|
||||
show(getContext(), HistoryActivity.class);
|
||||
}
|
||||
|
||||
public void showSettings() {
|
||||
show(getContext(), PreferencesActivity.class);
|
||||
}
|
||||
|
||||
public void showWidgetSettings() {
|
||||
final Context context = getContext();
|
||||
show(context, PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.prefs_widget_title));
|
||||
}
|
||||
|
||||
public void showOperators() {
|
||||
show(getContext(), OperatorsActivity.class);
|
||||
}
|
||||
|
||||
public void showAbout() {
|
||||
show(getContext(), AboutActivity.class);
|
||||
}
|
||||
|
||||
public void openFacebook() {
|
||||
final Uri uri = Uri.parse(application.getString(R.string.cpp_share_link));
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
@ -209,7 +189,7 @@ public final class ActivityLauncher implements CalculatorEventListener {
|
||||
}
|
||||
|
||||
public void show(@NonNull Class<HistoryActivity> activity) {
|
||||
showActivity(getContext(), activity);
|
||||
show(getContext(), activity);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -259,11 +239,11 @@ public final class ActivityLauncher implements CalculatorEventListener {
|
||||
}
|
||||
|
||||
public void showFunctions() {
|
||||
showFunctions(getContext());
|
||||
show(getContext(), FunctionsActivity.class);
|
||||
}
|
||||
|
||||
public void showVariables() {
|
||||
showVariables(getContext());
|
||||
show(getContext(), VariablesActivity.class);
|
||||
}
|
||||
|
||||
public void openApp() {
|
||||
|
@ -19,7 +19,7 @@ import dagger.Component;
|
||||
@Component(modules = AppModule.class)
|
||||
public interface AppComponent {
|
||||
void inject(CalculatorApplication application);
|
||||
void inject(CalculatorEditorFragment fragment);
|
||||
void inject(EditorFragment fragment);
|
||||
void inject(BaseUi ui);
|
||||
void inject(CalculatorOnscreenService service);
|
||||
void inject(BaseHistoryFragment fragment);
|
||||
|
@ -173,7 +173,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
|
||||
}
|
||||
}
|
||||
|
||||
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
||||
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");
|
||||
|
||||
|
@ -43,7 +43,7 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public enum CalculatorFragmentType {
|
||||
|
||||
editor(CalculatorEditorFragment.class, R.layout.cpp_app_editor, R.string.editor),
|
||||
editor(EditorFragment.class, R.layout.cpp_app_editor, R.string.editor),
|
||||
//display(CalculatorHistoryFragment.class, "history", R.layout.fragment_history, R.string.c_history),
|
||||
//keyboard(CalculatorHistoryFragment.class, "history", R.layout.fragment_history, R.string.c_history),
|
||||
history(RecentHistoryFragment.class, R.layout.fragment_history, R.string.cpp_history_tab_recent),
|
||||
|
@ -1,99 +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.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/23/12
|
||||
* Time: 2:25 PM
|
||||
*/
|
||||
enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
|
||||
|
||||
settings(R.string.c_settings) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
ActivityLauncher.showSettings(context);
|
||||
}
|
||||
},
|
||||
|
||||
history(R.string.c_history) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
ActivityLauncher.showHistory(context);
|
||||
}
|
||||
},
|
||||
|
||||
plotter(R.string.cpp_plotter) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
Locator.getInstance().getPlotter().plot();
|
||||
}
|
||||
},
|
||||
|
||||
conversion_tool(R.string.c_conversion_tool) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
new NumeralBaseConverterDialog(null).show(context);
|
||||
}
|
||||
},
|
||||
|
||||
exit(R.string.c_exit) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).finish();
|
||||
} else {
|
||||
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
about(R.string.c_about) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
ActivityLauncher.showAbout(context);
|
||||
}
|
||||
};
|
||||
|
||||
private final int captionResId;
|
||||
|
||||
CalculatorMenu(int captionResId) {
|
||||
this.captionResId = captionResId;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getCaption(@Nonnull Context context) {
|
||||
return context.getString(captionResId);
|
||||
}
|
||||
}
|
@ -33,41 +33,26 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
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 CalculatorEditorFragment extends Fragment {
|
||||
public class EditorFragment extends Fragment {
|
||||
|
||||
private FragmentUi fragmentUi;
|
||||
|
||||
@Nonnull
|
||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
||||
private FragmentUi ui;
|
||||
|
||||
private EditorView editorView;
|
||||
|
||||
@Inject
|
||||
Editor editor;
|
||||
|
||||
@Inject
|
||||
SharedPreferences preferences;
|
||||
@Inject
|
||||
ActivityLauncher launcher;
|
||||
|
||||
public CalculatorEditorFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
fragmentUi.onViewCreated(this, view);
|
||||
|
||||
editorView = (EditorView) view.findViewById(R.id.calculator_editor);
|
||||
editor.setView(editorView);
|
||||
public EditorFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,42 +68,52 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
|
||||
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences);
|
||||
if (!layout.optimized) {
|
||||
fragmentUi = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor);
|
||||
ui = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor);
|
||||
} else {
|
||||
fragmentUi = new FragmentUi(R.layout.cpp_app_editor, R.string.editor);
|
||||
ui = new FragmentUi(R.layout.cpp_app_editor, R.string.editor);
|
||||
}
|
||||
|
||||
fragmentUi.onCreate(this);
|
||||
ui.onCreate(this);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
ui.onViewCreated(this, view);
|
||||
|
||||
editorView = (EditorView) view.findViewById(R.id.calculator_editor);
|
||||
editor.setView(editorView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentUi.onCreateView(this, inflater, container);
|
||||
return ui.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
this.fragmentUi.onResume(this);
|
||||
this.ui.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
this.fragmentUi.onPause(this);
|
||||
this.ui.onPause(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
editor.clearView(editorView);
|
||||
fragmentUi.onDestroyView(this);
|
||||
ui.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentUi.onDestroy(this);
|
||||
ui.onDestroy(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -127,26 +122,30 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* MENU
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
this.menu.onCreateOptionsMenu(this.getActivity(), menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
this.menu.onPrepareOptionsMenu(this.getActivity(), menu);
|
||||
inflater.inflate(R.menu.main, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return this.menu.onOptionsItemSelected(this.getActivity(), item);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_settings:
|
||||
launcher.showSettings();
|
||||
return true;
|
||||
case R.id.menu_history:
|
||||
launcher.showHistory();
|
||||
return true;
|
||||
case R.id.menu_plotter:
|
||||
Locator.getInstance().getPlotter().plot();
|
||||
return true;
|
||||
case R.id.menu_conversion_tool:
|
||||
new NumeralBaseConverterDialog(null).show(getActivity());
|
||||
return true;
|
||||
case R.id.menu_about:
|
||||
launcher.showAbout();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -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 CalculatorEditorFragment || fragment instanceof CalculatorKeyboardFragment) {
|
||||
if (fragment instanceof CalculatorDisplayFragment || fragment instanceof EditorFragment || fragment instanceof CalculatorKeyboardFragment) {
|
||||
// no ads in those fragments
|
||||
} else {
|
||||
if (adView != null) {
|
||||
|
29
app/src/main/res/menu/main.xml
Normal file
29
app/src/main/res/menu/main.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_settings"
|
||||
android:title="@string/c_settings"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_history"
|
||||
android:title="@string/c_history"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_plotter"
|
||||
android:title="@string/cpp_plotter"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_conversion_tool"
|
||||
android:title="@string/c_conversion_tool"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_about"
|
||||
android:title="@string/c_about"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
Loading…
Reference in New Issue
Block a user