From c6c26823624119455cb4188340fe54a43c310ff0 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Tue, 25 Sep 2012 23:06:08 +0400 Subject: [PATCH] Fragments --- calculatorpp/AndroidManifest.xml | 138 ++-- calculatorpp/pom.xml | 656 +++++++++--------- calculatorpp/project.properties | 3 + .../res/layout-large-land/main_calculator.xml | 78 +++ .../res/values/styles-metro-blue-theme.xml | 50 +- .../calculator/CalculatorActivityHelper.java | 19 + .../CalculatorActivityHelperImpl.java | 121 ++++ .../CalculatorActivityLauncher.java | 4 +- .../calculator/CalculatorApplication.java | 5 + ...=> AbstractCalculatorHistoryFragment.java} | 137 ++-- ...ab.java => CalculatorHistoryFragment.java} | 3 +- .../CalculatorHistoryFragmentActivity.java | 40 ++ .../history/CalculatorHistoryTabActivity.java | 50 -- ...va => CalculatorSavedHistoryFragment.java} | 3 +- .../history/HistoryArrayAdapter.java | 6 +- .../history/HistoryItemMenuItem.java | 8 +- 16 files changed, 782 insertions(+), 539 deletions(-) create mode 100644 calculatorpp/res/layout-large-land/main_calculator.xml create mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java create mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java rename calculatorpp/src/main/java/org/solovyev/android/calculator/history/{AbstractHistoryActivity.java => AbstractCalculatorHistoryFragment.java} (64%) rename calculatorpp/src/main/java/org/solovyev/android/calculator/history/{HistoryActivityTab.java => CalculatorHistoryFragment.java} (91%) create mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragmentActivity.java delete mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryTabActivity.java rename calculatorpp/src/main/java/org/solovyev/android/calculator/history/{SavedHistoryActivityTab.java => CalculatorSavedHistoryFragment.java} (91%) diff --git a/calculatorpp/AndroidManifest.xml b/calculatorpp/AndroidManifest.xml index d8c8ee64..79af9dc1 100644 --- a/calculatorpp/AndroidManifest.xml +++ b/calculatorpp/AndroidManifest.xml @@ -1,70 +1,70 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/pom.xml b/calculatorpp/pom.xml index 6ebba13e..151b9511 100644 --- a/calculatorpp/pom.xml +++ b/calculatorpp/pom.xml @@ -1,322 +1,336 @@ - - - - - org.solovyev.android - calculatorpp-parent - 1.3.2 - - - 4.0.0 - - org.solovyev.android - calculatorpp - apk - Calculator++ Application - - - - - - - org.solovyev.android - calculatorpp-core - 1.3.2 - - - - org.solovyev - common-core - - - - org.solovyev - common-text - - - - org.solovyev.android - android-common-core - apklib - - - - org.solovyev.android - android-common-ads - apklib - - - - org.solovyev.android - android-common-view - apklib - - - - org.solovyev.android - android-common-preferences - apklib - - - - org.solovyev.android - android-common-other - apklib - - - - org.solovyev.android - android-common-menu - apklib - - - - org.solovyev - jscl - - - - - - com.google.android - android - provided - - - - com.google.android - support-v4 - - - - net.sf.opencsv - opencsv - 2.0 - test - - - - org.simpleframework - simple-xml - - - - achartengine - achartengine - 0.7.0 - - - - admob - admob - 6.1.0 - - - - org.solovyev.android - billing - 0.1 - - - - - com.google.guava - guava - 11.0.2 - - - - junit - junit - test - - - - com.intellij - annotations - - - - - - - - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - true - - - true - - - - - manifestUpdate - process-resources - - manifest-update - - - - alignApk - package - - zipalign - - - - - - - - - - - - - release - - - - performRelease - true - - - - - - - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - - - initialize - - read-project-properties - - - - ${project.basedir}/misc/env/jarsigner.properties - - - - - - - - org.apache.maven.plugins - maven-jarsigner-plugin - - - signing - - sign - verify - - package - true - - true - - - ${project.build.directory}/${project.artifactId}-${project.version}.apk - - ${sign.keystore} - ${sign.alias} - ${sign.storepass} - ${sign.keypass} - false - - - - - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - true - - - - false - - - - false - ${project.build.directory}/${project.artifactId}-${project.version}.apk - ${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk - - - - false - true - - - - true - - - - - - manifestUpdate - process-resources - - manifest-update - - - - alignApk - package - - zipalign - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - - ${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk - apk - signed-aligned - - - ${project.build.directory}/proguard/mapping.txt - map - release - - - - - - attach-signed-aligned - package - - attach-artifact - - - - - - - - - - - + + + + + org.solovyev.android + calculatorpp-parent + 1.3.2 + + + 4.0.0 + + org.solovyev.android + calculatorpp + apk + Calculator++ Application + + + + + + + org.solovyev.android + calculatorpp-core + 1.3.2 + + + + org.solovyev + common-core + + + + org.solovyev + common-text + + + + org.solovyev.android + android-common-core + apklib + + + + org.solovyev.android + android-common-ads + apklib + + + + org.solovyev.android + android-common-view + apklib + + + + org.solovyev.android + android-common-preferences + apklib + + + + org.solovyev.android + android-common-other + apklib + + + + org.solovyev.android + android-common-menu + apklib + + + + org.solovyev.android + android-common-sherlock + 1.0.0 + apklib + + + + + org.solovyev + jscl + + + + + + com.google.android + android + provided + + + + com.google.android + support-v4 + + + + com.actionbarsherlock + library + 4.1.0 + + + + net.sf.opencsv + opencsv + 2.0 + test + + + + org.simpleframework + simple-xml + + + + achartengine + achartengine + 0.7.0 + + + + admob + admob + 6.1.0 + + + + org.solovyev.android + billing + 0.1 + + + + + com.google.guava + guava + 11.0.2 + + + + junit + junit + test + + + + com.intellij + annotations + + + + + + + + + + + com.jayway.maven.plugins.android.generation2 + android-maven-plugin + true + + + true + + + + + manifestUpdate + process-resources + + manifest-update + + + + alignApk + package + + zipalign + + + + + + + + + + + + + release + + + + performRelease + true + + + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + ${project.basedir}/misc/env/jarsigner.properties + + + + + + + + org.apache.maven.plugins + maven-jarsigner-plugin + + + signing + + sign + verify + + package + true + + true + + + ${project.build.directory}/${project.artifactId}-${project.version}.apk + + ${sign.keystore} + ${sign.alias} + ${sign.storepass} + ${sign.keypass} + false + + + + + + + + com.jayway.maven.plugins.android.generation2 + android-maven-plugin + true + + + + false + + + + false + ${project.build.directory}/${project.artifactId}-${project.version}.apk + ${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk + + + + false + true + + + + true + + + + + + manifestUpdate + process-resources + + manifest-update + + + + alignApk + package + + zipalign + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + + ${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk + apk + signed-aligned + + + ${project.build.directory}/proguard/mapping.txt + map + release + + + + + + attach-signed-aligned + package + + attach-artifact + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/project.properties b/calculatorpp/project.properties index 1b733b09..6ccd5193 100644 --- a/calculatorpp/project.properties +++ b/calculatorpp/project.properties @@ -15,5 +15,8 @@ android.library.reference.3=gen-external-apklibs/org.solovyev.android_android-co android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0 android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0 android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0 +android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0 +android.library.reference.8=gen-external-apklibs/com.actionbarsherlock_library_4.0.2 +android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0 diff --git a/calculatorpp/res/layout-large-land/main_calculator.xml b/calculatorpp/res/layout-large-land/main_calculator.xml new file mode 100644 index 00000000..25da91dc --- /dev/null +++ b/calculatorpp/res/layout-large-land/main_calculator.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculatorpp/res/values/styles-metro-blue-theme.xml b/calculatorpp/res/values/styles-metro-blue-theme.xml index 1328c18c..ba07b423 100644 --- a/calculatorpp/res/values/styles-metro-blue-theme.xml +++ b/calculatorpp/res/values/styles-metro-blue-theme.xml @@ -1,26 +1,26 @@ - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java new file mode 100644 index 00000000..d6542555 --- /dev/null +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java @@ -0,0 +1,19 @@ +package org.solovyev.android.calculator; + +import android.os.Bundle; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * User: serso + * Date: 9/25/12 + * Time: 10:31 PM + */ +public interface CalculatorActivityHelper { + + void onCreate(@NotNull SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState); + + void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState); + +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java new file mode 100644 index 00000000..02ca1f1e --- /dev/null +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java @@ -0,0 +1,121 @@ +package org.solovyev.android.calculator; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.history.CalculatorHistoryFragment; +import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; + +/** + * User: serso + * Date: 9/25/12 + * Time: 10:32 PM + */ +public class CalculatorActivityHelperImpl implements CalculatorActivityHelper { + + /* + ********************************************************************** + * + * CONSTANTS + * + ********************************************************************** + */ + private static final String SELECTED_NAV = "selected_nav"; + + /* + ********************************************************************** + * + * FIELDS + * + ********************************************************************** + */ + + private int layoutId; + + private boolean showActionBarTabs = true; + + private boolean homeIcon = false; + + public CalculatorActivityHelperImpl(int layoutId) { + this.layoutId = layoutId; + } + + public CalculatorActivityHelperImpl(int layoutId, boolean showActionBarTabs, boolean homeIcon) { + this.layoutId = layoutId; + this.showActionBarTabs = showActionBarTabs; + this.homeIcon = homeIcon; + } + + @Override + public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) { + activity.setContentView(layoutId); + + final ActionBar actionBar = activity.getSupportActionBar(); + actionBar.setDisplayUseLogoEnabled(false); + actionBar.setDisplayHomeAsUpEnabled(homeIcon); + actionBar.setDisplayShowHomeEnabled(true); + actionBar.setDisplayShowTitleEnabled(true); + + if (showActionBarTabs) { + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + addTab(activity, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.drawable.icon); + //addTab(activity, "messages", MessengerChatsFragment.class, null, R.string.c_messages, R.drawable.msg_footer_messages_icon); + + // settings tab + final ActionBar.Tab tab = actionBar.newTab(); + tab.setTag("settings"); + tab.setText(R.string.c_settings); + //tab.setIcon(R.drawable.msg_footer_settings_icon); + tab.setTabListener(new ActionBar.TabListener() { + @Override + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { + activity.startActivity(new Intent(activity.getApplicationContext(), CalculatorPreferencesActivity.class)); + } + + @Override + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { + } + + @Override + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { + } + }); + actionBar.addTab(tab); + + int navPosition = -1; + if (savedInstanceState != null) { + navPosition = savedInstanceState.getInt(SELECTED_NAV, -1); + } + + if (navPosition >= 0) { + activity.getSupportActionBar().setSelectedNavigationItem(navPosition); + } + } + } + + @Override + public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) { + outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex()); + } + + private void addTab(@NotNull SherlockFragmentActivity activity, + @NotNull String tag, + @NotNull Class fragmentClass, + @Nullable Bundle fragmentArgs, + int captionResId, + int iconResId) { + final ActionBar actionBar = activity.getSupportActionBar(); + final ActionBar.Tab tab = actionBar.newTab(); + tab.setTag(tag); + tab.setText(captionResId); + //tab.setIcon(iconResId); + tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, R.id.content_second_pane)); + actionBar.addTab(tab); + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index b11ace1f..c68e7547 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -9,7 +9,7 @@ import org.achartengine.ChartFactory; import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.about.CalculatorAboutTabActivity; import org.solovyev.android.calculator.help.CalculatorHelpTabActivity; -import org.solovyev.android.calculator.history.CalculatorHistoryTabActivity; +import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity; import org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity; import org.solovyev.android.calculator.math.edit.CalculatorOperatorsActivity; import org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity; @@ -25,7 +25,7 @@ import org.solovyev.common.text.StringUtils; public class CalculatorActivityLauncher { public static void showHistory(@NotNull final Context context) { - context.startActivity(new Intent(context, CalculatorHistoryTabActivity.class)); + context.startActivity(new Intent(context, CalculatorHistoryFragmentActivity.class)); } public static void showHelp(@NotNull final Context context) { diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 7f252ea4..fe659e47 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -109,4 +109,9 @@ public class CalculatorApplication extends android.app.Application { public static void registerOnRemoteStackTrace() { //Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(null, REMOTE_STACK_TRACE_URL)); } + + @NotNull + public CalculatorActivityHelper createCalculatorHistoryHelper(int layoutResId) { + return new CalculatorActivityHelperImpl(layoutResId); + } } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java similarity index 64% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryActivity.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java index 649687f1..3ec0ded2 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryActivity.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java @@ -6,15 +6,16 @@ package org.solovyev.android.calculator.history; -import android.app.ListActivity; +import android.app.Activity; import android.content.Context; import android.os.Bundle; -import android.view.MenuInflater; -import android.view.MenuItem; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import com.actionbarsherlock.app.SherlockListFragment; import com.google.ads.AdView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,7 +42,8 @@ import java.util.List; * Date: 10/15/11 * Time: 1:13 PM */ -public abstract class AbstractHistoryActivity extends ListActivity { +public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment { + public static final Comparator COMPARATOR = new Comparator() { @Override @@ -65,65 +67,73 @@ public abstract class AbstractHistoryActivity extends ListActivity { @Nullable private AdView adView; - @Override - protected void onCreate(Bundle savedInstanceState) { + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.history_activity, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + adView = AdsController.getInstance().inflateAd(this.getActivity()); + + adapter = new HistoryArrayAdapter(this.getActivity(), getLayoutId(), R.id.history_item, new ArrayList()); + setListAdapter(adapter); + + final ListView lv = getListView(); + lv.setTextFilterEnabled(true); + + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(final AdapterView parent, + final View view, + final int position, + final long id) { + + useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), getActivity()); + } + }); + + lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { + final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position); + + final Context context = getActivity(); + + final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter); + + final List menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values()); + + if (historyState.isSaved()) { + menuItems.remove(HistoryItemMenuItem.save); + } else { + if (isAlreadySaved(historyState)) { + menuItems.remove(HistoryItemMenuItem.save); + } + menuItems.remove(HistoryItemMenuItem.remove); + menuItems.remove(HistoryItemMenuItem.edit); + } + + if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) { + menuItems.remove(HistoryItemMenuItem.copy_result); + } + + final AMenuBuilder menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems)); + menuBuilder.create(data).show(); + + return true; + } + }); + } + + @Override + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - setContentView(R.layout.history_activity); - - adView = AdsController.getInstance().inflateAd(this); - - adapter = new HistoryArrayAdapter(this, getLayoutId(), R.id.history_item, new ArrayList()); - setListAdapter(adapter); - - final ListView lv = getListView(); - lv.setTextFilterEnabled(true); - - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - public void onItemClick(final AdapterView parent, - final View view, - final int position, - final long id) { - - useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), AbstractHistoryActivity.this); - } - }); - - lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { - final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position); - - final Context context = AbstractHistoryActivity.this; - - final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter); - - final List menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values()); - - if (historyState.isSaved()) { - menuItems.remove(HistoryItemMenuItem.save); - } else { - if (isAlreadySaved(historyState)) { - menuItems.remove(HistoryItemMenuItem.save); - } - menuItems.remove(HistoryItemMenuItem.remove); - menuItems.remove(HistoryItemMenuItem.edit); - } - - if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) { - menuItems.remove(HistoryItemMenuItem.copy_result); - } - - final AMenuBuilder menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems)); - menuBuilder.create(data).show(); - - return true; - } - }); } @Override - protected void onDestroy() { + public void onDestroy() { if ( this.adView != null ) { this.adView.destroy(); } @@ -133,7 +143,7 @@ public abstract class AbstractHistoryActivity extends ListActivity { protected abstract int getLayoutId(); @Override - protected void onResume() { + public void onResume() { super.onResume(); final List historyList = getHistoryList(); @@ -173,7 +183,7 @@ public abstract class AbstractHistoryActivity extends ListActivity { return result; } - public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull AbstractHistoryActivity activity) { + public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull Activity activity) { final EditorHistoryState editorState = historyState.getEditorState(); CalculatorLocatorImpl.getInstance().getEditor().setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition()); @@ -219,7 +229,8 @@ public abstract class AbstractHistoryActivity extends ListActivity { return jsclOperation == JsclOperation.simplify ? "≡" : "="; } - @Override + // todo serso: menu +/* @Override public boolean onCreateOptionsMenu(android.view.Menu menu) { final MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.history_menu, menu); @@ -240,7 +251,7 @@ public abstract class AbstractHistoryActivity extends ListActivity { } return result; - } + }*/ protected abstract void clearHistory(); diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryActivityTab.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragment.java similarity index 91% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryActivityTab.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragment.java index 22715d94..54adaa44 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryActivityTab.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragment.java @@ -18,7 +18,8 @@ import java.util.List; * Date: 12/18/11 * Time: 7:39 PM */ -public class HistoryActivityTab extends AbstractHistoryActivity { +public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment { + @Override protected int getLayoutId() { return R.layout.history; diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragmentActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragmentActivity.java new file mode 100644 index 00000000..b2b50849 --- /dev/null +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryFragmentActivity.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2009-2011. Created by serso aka se.solovyev. + * For more information, please, contact se.solovyev@gmail.com + * or visit http://se.solovyev.org + */ + +package org.solovyev.android.calculator.history; + +import android.os.Bundle; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.CalculatorActivityHelper; +import org.solovyev.android.calculator.CalculatorApplication; +import org.solovyev.android.calculator.R; + +/** + * User: serso + * Date: 12/18/11 + * Time: 7:37 PM + */ +public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity { + + @NotNull + private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.history_activity); + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + activityHelper.onCreate(this, savedInstanceState); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + activityHelper.onSaveInstanceState(this, outState); + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryTabActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryTabActivity.java deleted file mode 100644 index 59c6be28..00000000 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryTabActivity.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2009-2011. Created by serso aka se.solovyev. - * For more information, please, contact se.solovyev@gmail.com - * or visit http://se.solovyev.org - */ - -package org.solovyev.android.calculator.history; - -import android.app.TabActivity; -import android.os.Bundle; -import android.widget.TabHost; -import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; -import org.solovyev.android.LastTabSaver; -import org.solovyev.android.calculator.R; - -/** - * User: serso - * Date: 12/18/11 - * Time: 7:37 PM - */ -public class CalculatorHistoryTabActivity extends TabActivity { - - @Nullable - private LastTabSaver lastTabSaver; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.tabs); - - final TabHost tabHost = getTabHost(); - - AndroidUtils.addTab(this, tabHost, "saved_history", R.string.c_saved_history, SavedHistoryActivityTab.class); - AndroidUtils.addTab(this, tabHost, "history", R.string.c_history, HistoryActivityTab.class); - - this.lastTabSaver = new LastTabSaver(this, "saved_history"); - - AndroidUtils.centerAndWrapTabsFor(tabHost); - } - - @Override - protected void onDestroy() { - if ( this.lastTabSaver != null ) { - this.lastTabSaver.destroy(); - } - super.onDestroy(); - } -} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/SavedHistoryActivityTab.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorSavedHistoryFragment.java similarity index 91% rename from calculatorpp/src/main/java/org/solovyev/android/calculator/history/SavedHistoryActivityTab.java rename to calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorSavedHistoryFragment.java index 60a697ba..28b85fbe 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/SavedHistoryActivityTab.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/CalculatorSavedHistoryFragment.java @@ -18,7 +18,8 @@ import java.util.List; * Date: 12/18/11 * Time: 7:40 PM */ -public class SavedHistoryActivityTab extends AbstractHistoryActivity { +public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment { + @Override protected int getLayoutId() { return R.layout.saved_history; diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java index e8dedbd4..ea495536 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java @@ -40,7 +40,7 @@ public class HistoryArrayAdapter extends ArrayAdapter { time.setText(new SimpleDateFormat().format(new Date(state.getTime()))); final TextView editor = (TextView) result.findViewById(R.id.history_item); - editor.setText(AbstractHistoryActivity.getHistoryText(state)); + editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state)); final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment); if (commentView != null) { @@ -57,7 +57,7 @@ public class HistoryArrayAdapter extends ArrayAdapter { if (state.isSaved()) { status.setText(getContext().getString(R.string.c_history_item_saved)); } else { - if ( AbstractHistoryActivity.isAlreadySaved(state) ) { + if ( AbstractCalculatorHistoryFragment.isAlreadySaved(state) ) { status.setText(getContext().getString(R.string.c_history_item_already_saved)); } else { status.setText(getContext().getString(R.string.c_history_item_not_saved)); @@ -71,7 +71,7 @@ public class HistoryArrayAdapter extends ArrayAdapter { @Override public void notifyDataSetChanged() { this.setNotifyOnChange(false); - this.sort(AbstractHistoryActivity.COMPARATOR); + this.sort(AbstractCalculatorHistoryFragment.COMPARATOR); this.setNotifyOnChange(true); super.notifyDataSetChanged(); } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java index 9d716715..4097d4ee 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java @@ -33,10 +33,10 @@ public enum HistoryItemMenuItem implements LabeledMenuItem use(R.string.c_use) { @Override public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) { - if (context instanceof AbstractHistoryActivity) { - AbstractHistoryActivity.useHistoryItem(data.getHistoryState(), (AbstractHistoryActivity) context); + if (context instanceof Activity) { + AbstractCalculatorHistoryFragment.useHistoryItem(data.getHistoryState(), (Activity) context); } else { - Log.e(HistoryItemMenuItem.class.getName(), AbstractHistoryActivity.class + " must be passed as context!"); + Log.e(HistoryItemMenuItem.class.getName(), AbstractCalculatorHistoryFragment.class + " must be passed as context!"); } } }, @@ -110,7 +110,7 @@ public enum HistoryItemMenuItem implements LabeledMenuItem final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View editView = layoutInflater.inflate(R.layout.history_edit, null); final TextView historyExpression = (TextView)editView.findViewById(R.id.history_edit_expression); - historyExpression.setText(AbstractHistoryActivity.getHistoryText(historyState)); + historyExpression.setText(AbstractCalculatorHistoryFragment.getHistoryText(historyState)); final EditText comment = (EditText)editView.findViewById(R.id.history_edit_comment); comment.setText(historyState.getComment());