Tabs
This commit is contained in:
parent
0b100efcf0
commit
f2eca251f8
@ -20,28 +20,27 @@
|
|||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
|
<activity android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
|
<activity android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsFragmentActivity"/>
|
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsFragmentActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsFragmentActivity"/>
|
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsFragmentActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsFragmentActivity"/>
|
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsFragmentActivity"/>
|
||||||
|
|
||||||
|
@ -209,5 +209,7 @@
|
|||||||
|
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="result">Result</string>
|
<string name="result">Result</string>
|
||||||
|
<string name="other">Other</string>
|
||||||
|
<string name="derivatives">Derivatives/Integrals</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -25,6 +25,7 @@ import net.robotmedia.billing.IBillingObserver;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||||
@ -44,7 +45,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IBillingObserver billingObserver;
|
private IBillingObserver billingObserver;
|
||||||
|
|
||||||
private boolean useBackAsPrev;
|
private boolean useBackAsPrev;
|
||||||
@ -74,14 +75,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
activityHelper.logDebug("super.onCreate");
|
activityHelper.logDebug("super.onCreate");
|
||||||
|
|
||||||
if (findViewById(R.id.main_second_pane) != null) {
|
if (findViewById(R.id.main_second_pane) != null) {
|
||||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "vars", CalculatorVarsFragment.class, null, R.string.c_vars, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "functions", CalculatorFunctionsFragment.class, null, R.string.c_functions, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "plot", CalculatorPlotFragment.class, null, R.string.c_plot, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.plotter, null, R.id.main_second_pane);
|
||||||
|
|
||||||
activityHelper.restoreSavedTab(this);
|
|
||||||
} else {
|
} else {
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
}
|
}
|
||||||
@ -208,6 +207,13 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
getCalculator().evaluate();
|
getCalculator().evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -7,6 +7,7 @@ import android.view.View;
|
|||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -29,6 +30,9 @@ public interface CalculatorActivityHelper {
|
|||||||
void onResume(@NotNull SherlockFragmentActivity activity);
|
void onResume(@NotNull SherlockFragmentActivity activity);
|
||||||
void onResume(@NotNull Activity activity);
|
void onResume(@NotNull Activity activity);
|
||||||
|
|
||||||
|
void onPause(@NotNull Activity activity);
|
||||||
|
void onPause(@NotNull SherlockFragmentActivity activity);
|
||||||
|
|
||||||
void onDestroy(@NotNull SherlockFragmentActivity activity);
|
void onDestroy(@NotNull SherlockFragmentActivity activity);
|
||||||
void onDestroy(@NotNull Activity activity);
|
void onDestroy(@NotNull Activity activity);
|
||||||
|
|
||||||
@ -36,11 +40,17 @@ public interface CalculatorActivityHelper {
|
|||||||
@NotNull String tag,
|
@NotNull String tag,
|
||||||
@NotNull Class<? extends Fragment> fragmentClass,
|
@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable Bundle fragmentArgs,
|
@Nullable Bundle fragmentArgs,
|
||||||
int captionResId, int parentViewId);
|
int captionResId,
|
||||||
|
int parentViewId);
|
||||||
|
|
||||||
|
void addTab(@NotNull SherlockFragmentActivity activity,
|
||||||
|
@NotNull CalculatorFragmentType fragmentType,
|
||||||
|
@Nullable Bundle fragmentArgs,
|
||||||
|
int parentViewId);
|
||||||
|
|
||||||
void restoreSavedTab(@NotNull SherlockFragmentActivity activity);
|
|
||||||
|
|
||||||
void logDebug(@NotNull String message);
|
void logDebug(@NotNull String message);
|
||||||
|
|
||||||
void processButtons(@NotNull Activity activity, @NotNull View root);
|
void processButtons(@NotNull Activity activity, @NotNull View root);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -32,7 +33,6 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
private static final String SELECTED_NAV = "selected_nav";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
@ -51,8 +51,8 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
private int navPosition = 0;
|
|
||||||
|
|
||||||
|
private int selectedNavigationIndex = 0;
|
||||||
|
|
||||||
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
|
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
|
||||||
super(logTag);
|
super(logTag);
|
||||||
@ -68,8 +68,8 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(activity);
|
super.onCreate(activity);
|
||||||
|
|
||||||
if ( activity instanceof CalculatorEventListener) {
|
if (activity instanceof CalculatorEventListener) {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener)activity);
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
@ -85,10 +85,6 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
} else {
|
} else {
|
||||||
Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
|
Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,29 +97,34 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
actionBar.setHomeButtonEnabled(false);
|
actionBar.setHomeButtonEnabled(false);
|
||||||
actionBar.setDisplayShowHomeEnabled(true);
|
actionBar.setDisplayShowHomeEnabled(true);
|
||||||
|
|
||||||
if (activity instanceof CalculatorActivity) {
|
toggleTitle(activity, true);
|
||||||
if ( AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT ) {
|
|
||||||
actionBar.setDisplayShowTitleEnabled(true);
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
actionBar.setDisplayShowTitleEnabled(true);
|
|
||||||
}
|
|
||||||
actionBar.setIcon(R.drawable.icon_action_bar);
|
actionBar.setIcon(R.drawable.icon_action_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void toggleTitle(@NotNull SherlockFragmentActivity activity, boolean showTitle) {
|
||||||
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
|
|
||||||
|
if (activity instanceof CalculatorActivity) {
|
||||||
|
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
actionBar.setDisplayShowTitleEnabled(true);
|
||||||
|
} else {
|
||||||
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
actionBar.setDisplayShowTitleEnabled(showTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
|
if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) {
|
||||||
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
|
actionBar.setSelectedNavigationItem(selectedNavigationIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
||||||
onSaveInstanceState((Activity) activity, outState);
|
onSaveInstanceState((Activity) activity, outState);
|
||||||
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,18 +141,41 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause(@NotNull Activity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause(@NotNull SherlockFragmentActivity activity) {
|
||||||
|
onPause((Activity) activity);
|
||||||
|
|
||||||
|
final int selectedNavigationIndex = activity.getSupportActionBar().getSelectedNavigationIndex();
|
||||||
|
if (selectedNavigationIndex >= 0) {
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
final SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
editor.putInt(getSavedTabPreferenceName(activity), selectedNavigationIndex);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getSavedTabPreferenceName(@NotNull Activity activity) {
|
||||||
|
return "tab_" + activity.getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(@NotNull Activity activity) {
|
public void onDestroy(@NotNull Activity activity) {
|
||||||
super.onDestroy(activity);
|
super.onDestroy(activity);
|
||||||
|
|
||||||
if ( activity instanceof CalculatorEventListener) {
|
if (activity instanceof CalculatorEventListener) {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener)activity);
|
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(@NotNull SherlockFragmentActivity activity) {
|
public void onDestroy(@NotNull SherlockFragmentActivity activity) {
|
||||||
this.onDestroy((Activity)activity);
|
this.onDestroy((Activity) activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -161,9 +185,10 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
@Nullable Bundle fragmentArgs,
|
@Nullable Bundle fragmentArgs,
|
||||||
int captionResId,
|
int captionResId,
|
||||||
int parentViewId) {
|
int parentViewId) {
|
||||||
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
|
||||||
|
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
|
|
||||||
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
|
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
final ActionBar.Tab tab = actionBar.newTab();
|
||||||
tab.setTag(tag);
|
tab.setTag(tag);
|
||||||
tab.setText(captionResId);
|
tab.setText(captionResId);
|
||||||
@ -173,8 +198,11 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
actionBar.addTab(tab);
|
actionBar.addTab(tab);
|
||||||
|
|
||||||
fragmentTags.add(tag);
|
fragmentTags.add(tag);
|
||||||
|
}
|
||||||
|
|
||||||
restoreSavedTab(activity);
|
@Override
|
||||||
|
public void addTab(@NotNull SherlockFragmentActivity activity, @NotNull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) {
|
||||||
|
addTab(activity, fragmentType.getFragmentTag(), fragmentType.getFragmentClass(), fragmentArgs, fragmentType.getDefaultTitleResId(), parentViewId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -191,5 +219,9 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
@Override
|
@Override
|
||||||
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
||||||
onResume((Activity) activity);
|
onResume((Activity) activity);
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
selectedNavigationIndex = preferences.getInt(getSavedTabPreferenceName(activity), -1);
|
||||||
|
restoreSavedTab(activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package org.solovyev.android.calculator.about;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
|
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||||
|
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||||
|
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||||
|
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||||
|
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 03.10.12
|
||||||
|
* Time: 11:30
|
||||||
|
*/
|
||||||
|
public enum CalculatorFragmentType {
|
||||||
|
|
||||||
|
history(CalculatorHistoryFragment.class, "history", R.string.c_history),
|
||||||
|
saved_history(CalculatorSavedHistoryFragment.class, "saved_history", R.string.c_saved_history),
|
||||||
|
variables(CalculatorVarsFragment.class, "vars", R.string.c_vars),
|
||||||
|
functions(CalculatorFunctionsFragment.class, "functions", R.string.c_functions),
|
||||||
|
operators(CalculatorOperatorsFragment.class, "operators", R.string.c_operators),
|
||||||
|
plotter(CalculatorPlotFragment.class, "plotter", R.string.c_plot);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Class<? extends Fragment> fragmentClass;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final String fragmentTag;
|
||||||
|
|
||||||
|
private int defaultTitleResId;
|
||||||
|
|
||||||
|
private CalculatorFragmentType(@NotNull Class<? extends Fragment> fragmentClass, @NotNull String fragmentTag, int defaultTitleResId) {
|
||||||
|
this.fragmentClass = fragmentClass;
|
||||||
|
this.fragmentTag = fragmentTag;
|
||||||
|
this.defaultTitleResId = defaultTitleResId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getFragmentTag() {
|
||||||
|
return fragmentTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultTitleResId() {
|
||||||
|
return defaultTitleResId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Class<? extends Fragment> getFragmentClass() {
|
||||||
|
return fragmentClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String createSubFragmentTag(@NotNull String subFragmentTag) {
|
||||||
|
return this.fragmentTag + "_" + subFragmentTag;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -28,8 +29,8 @@ public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity
|
|||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_layout);
|
activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_layout);
|
||||||
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_layout);
|
activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,6 +47,14 @@ public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity
|
|||||||
activityHelper.onResume(this);
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -11,6 +11,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
||||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
||||||
|
|
||||||
@ -30,9 +31,12 @@ public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivit
|
|||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
|
||||||
|
|
||||||
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
|
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
|
||||||
activityHelper.addTab(this, category.name(), CalculatorFunctionsFragment.class, AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,6 +53,14 @@ public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivit
|
|||||||
activityHelper.onResume(this);
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -11,7 +11,10 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
||||||
|
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
||||||
|
import org.solovyev.android.calculator.model.AndroidOperatorsMathRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -29,7 +32,11 @@ public class CalculatorOperatorsFragmentActivity extends SherlockFragmentActivit
|
|||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_layout);
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
|
||||||
|
|
||||||
|
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.getCategoriesByTabOrder()) {
|
||||||
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,6 +53,14 @@ public class CalculatorOperatorsFragmentActivity extends SherlockFragmentActivit
|
|||||||
activityHelper.onResume(this);
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -12,6 +12,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
||||||
import org.solovyev.android.calculator.model.VarCategory;
|
import org.solovyev.android.calculator.model.VarCategory;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity imp
|
|||||||
bundle = null;
|
bundle = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.variables;
|
||||||
|
|
||||||
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
||||||
|
|
||||||
@ -52,7 +54,8 @@ public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity imp
|
|||||||
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
|
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
activityHelper.addTab(this, category.name(), CalculatorVarsFragment.class, fragmentParameters, category.getCaptionId(), R.id.main_layout);
|
|
||||||
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.getCaptionId(), R.id.main_layout);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +74,14 @@ public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity imp
|
|||||||
activityHelper.onResume(this);
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -2,9 +2,7 @@ package org.solovyev.android.calculator.math.edit;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -7,13 +7,17 @@
|
|||||||
package org.solovyev.android.calculator.model;
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import jscl.math.operator.Operator;
|
import jscl.math.function.ArcTrigonometric;
|
||||||
|
import jscl.math.function.Comparison;
|
||||||
|
import jscl.math.function.Trigonometric;
|
||||||
|
import jscl.math.operator.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.common.JBuilder;
|
import org.solovyev.common.JBuilder;
|
||||||
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -48,7 +52,12 @@ public class AndroidOperatorsMathRegistry extends AbstractAndroidMathRegistry<Op
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@NotNull Operator mathEntity) {
|
public String getCategory(@NotNull Operator operator) {
|
||||||
|
for (Category category : Category.values()) {
|
||||||
|
if ( category.isInCategory(operator) ) {
|
||||||
|
return category.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,4 +98,83 @@ public class AndroidOperatorsMathRegistry extends AbstractAndroidMathRegistry<Op
|
|||||||
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* STATIC
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static enum Category {
|
||||||
|
|
||||||
|
derivatives(R.string.derivatives, 100){
|
||||||
|
@Override
|
||||||
|
boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
other(R.string.other, 200) {
|
||||||
|
@Override
|
||||||
|
boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return operator instanceof Sum || operator instanceof Product;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
my(R.string.c_fun_category_my, 0) {
|
||||||
|
@Override
|
||||||
|
boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
return !operator.isSystem();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
common(R.string.c_fun_category_common, 50) {
|
||||||
|
@Override
|
||||||
|
boolean isInCategory(@NotNull Operator operator) {
|
||||||
|
for (Category category : values()) {
|
||||||
|
if ( category != this ) {
|
||||||
|
if ( category.isInCategory(operator) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int captionId;
|
||||||
|
|
||||||
|
private final int tabOrder;
|
||||||
|
|
||||||
|
Category(int captionId, int tabOrder) {
|
||||||
|
this.captionId = captionId;
|
||||||
|
this.tabOrder = tabOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCaptionId() {
|
||||||
|
return captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract boolean isInCategory(@NotNull Operator operator);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<Category> getCategoriesByTabOrder() {
|
||||||
|
final List<Category> result = CollectionsUtils.asList(Category.values());
|
||||||
|
|
||||||
|
Collections.sort(result, new Comparator<Category>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Category category, Category category1) {
|
||||||
|
return category.tabOrder - category1.tabOrder;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// todo serso: current solution (as creating operators is not implemented yet)
|
||||||
|
result.remove(my);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,12 @@ public class AndroidPostfixFunctionsRegistry extends AbstractAndroidMathRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@NotNull Operator mathEntity) {
|
public String getCategory(@NotNull Operator operator) {
|
||||||
|
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
|
||||||
|
if ( category.isInCategory(operator) ) {
|
||||||
|
return category.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.solovyev.android.calculator.CalculatorActivityHelper;
|
import org.solovyev.android.calculator.CalculatorActivityHelper;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -34,7 +35,7 @@ public class CalculatorPlotActivity extends SherlockFragmentActivity {
|
|||||||
arguments = null;
|
arguments = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
activityHelper.addTab(this, "plot", CalculatorPlotFragment.class, arguments, R.string.c_plot, R.id.main_layout);
|
activityHelper.addTab(this, CalculatorFragmentType.plotter, arguments, R.id.main_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,6 +52,14 @@ public class CalculatorPlotActivity extends SherlockFragmentActivity {
|
|||||||
activityHelper.onResume(this);
|
activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
Loading…
Reference in New Issue
Block a user