From d23f8e2c40f2bb426151a36cb0a3c5beaa2eeead Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 26 Jan 2015 12:38:45 +0100 Subject: [PATCH] GA integration + Base activity --- .idea/encodings.xml | 5 +- ...ctivityHelperImpl.java => ActivityUi.java} | 686 +++++++++--------- .../org/solovyev/android/calculator/App.java | 20 +- .../android/calculator/BaseActivity.java | 73 ++ ...tractCalculatorHelper.java => BaseUi.java} | 642 ++++++++-------- .../calculator/CalculatorActivity.java | 46 +- .../calculator/CalculatorActivityHelper.java | 95 --- .../calculator/CalculatorApplication.java | 16 +- .../calculator/CalculatorDisplayFragment.java | 2 +- .../calculator/CalculatorEditorFragment.java | 2 +- .../calculator/CalculatorFragment.java | 4 +- .../CalculatorFragmentActivity.java | 89 --- .../CalculatorKeyboardFragment.java | 2 +- .../calculator/CalculatorListFragment.java | 4 +- .../calculator/CalculatorWikiActivity.java | 2 +- ...FragmentHelper.java => EmptyActivity.java} | 36 +- ...ragmentHelperImpl.java => FragmentUi.java} | 15 +- .../about/CalculatorAboutActivity.java | 13 +- .../solovyev/android/calculator/ga/Ga.java | 50 ++ .../AbstractCalculatorHistoryFragment.java | 2 +- .../history/CalculatorHistoryActivity.java | 57 +- .../history/HistoryArrayAdapter.java | 2 +- .../edit/AbstractMathEntityListFragment.java | 5 +- .../edit/CalculatorFunctionsActivity.java | 52 +- .../edit/CalculatorOperatorsActivity.java | 53 +- .../math/edit/CalculatorVarsActivity.java | 54 +- .../matrix/CalculatorMatrixActivity.java | 6 +- .../model/AndroidMathEntityDao.java | 4 +- .../plot/CalculatorPlotActivity.java | 6 +- android-app/src/main/res/xml/ga.xml | 6 + 30 files changed, 899 insertions(+), 1150 deletions(-) rename android-app/src/main/java/org/solovyev/android/calculator/{CalculatorActivityHelperImpl.java => ActivityUi.java} (90%) create mode 100644 android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java rename android-app/src/main/java/org/solovyev/android/calculator/{AbstractCalculatorHelper.java => BaseUi.java} (96%) delete mode 100644 android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java delete mode 100644 android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentActivity.java rename android-app/src/main/java/org/solovyev/android/calculator/{CalculatorFragmentHelper.java => EmptyActivity.java} (50%) rename android-app/src/main/java/org/solovyev/android/calculator/{CalculatorFragmentHelperImpl.java => FragmentUi.java} (92%) create mode 100644 android-app/src/main/java/org/solovyev/android/calculator/ga/Ga.java create mode 100644 android-app/src/main/res/xml/ga.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 1ccfa6c8..13692363 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,10 +1,7 @@ - - - + - \ No newline at end of file diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java similarity index 90% rename from android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index 98356ecd..f592505a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -1,349 +1,337 @@ -/* - * 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.SharedPreferences; -import android.content.res.Configuration; -import android.graphics.Color; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockFragmentActivity; -import org.solovyev.android.Activities; -import org.solovyev.android.Views; -import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 9/25/12 - * Time: 10:32 PM - */ -public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper { - - /* - ********************************************************************** - * - * CONSTANTS - * - ********************************************************************** - */ - - /* - ********************************************************************** - * - * FIELDS - * - ********************************************************************** - */ - - private int layoutId; - - private boolean homeIcon = false; - - @Nonnull - private CalculatorPreferences.Gui.Theme theme; - - @Nonnull - private CalculatorPreferences.Gui.Layout layout; - - private int selectedNavigationIndex = 0; - - public CalculatorActivityHelperImpl(int layoutId, @Nonnull String logTag) { - super(logTag); - this.layoutId = layoutId; - } - - public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) { - this.layoutId = layoutId; - this.homeIcon = homeIcon; - } - - @Override - public void onCreate(@Nonnull Activity activity, @Nullable Bundle savedInstanceState) { - super.onCreate(activity); - - if (activity instanceof CalculatorEventListener) { - Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity); - } - - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - - this.theme = CalculatorPreferences.Gui.getTheme(preferences); - activity.setTheme(this.theme.getThemeId()); - - this.layout = CalculatorPreferences.Gui.getLayout(preferences); - - activity.setContentView(layoutId); - - final View root = activity.findViewById(R.id.main_layout); - if (root != null) { - processButtons(activity, root); - addHelpInfo(activity, root); - } else { - Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName()); - } - } - - @Override - public void onCreate(@Nonnull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) { - this.onCreate((Activity) activity, savedInstanceState); - - final ActionBar actionBar = activity.getSupportActionBar(); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(homeIcon); - actionBar.setHomeButtonEnabled(false); - actionBar.setDisplayShowHomeEnabled(true); - - toggleTitle(activity, true); - - actionBar.setIcon(R.drawable.ab_icon); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - } - - private void toggleTitle(@Nonnull SherlockFragmentActivity activity, boolean showTitle) { - final ActionBar actionBar = activity.getSupportActionBar(); - - if (activity instanceof CalculatorActivity) { - if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) { - actionBar.setDisplayShowTitleEnabled(true); - } else { - actionBar.setDisplayShowTitleEnabled(false); - } - } else { - actionBar.setDisplayShowTitleEnabled(showTitle); - } - } - - public void restoreSavedTab(@Nonnull SherlockFragmentActivity activity) { - final ActionBar actionBar = activity.getSupportActionBar(); - if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) { - actionBar.setSelectedNavigationItem(selectedNavigationIndex); - } - } - - @Override - public void onSaveInstanceState(@Nonnull SherlockFragmentActivity activity, @Nonnull Bundle outState) { - onSaveInstanceState((Activity) activity, outState); - } - - @Override - public void onSaveInstanceState(@Nonnull Activity activity, @Nonnull Bundle outState) { - } - - @Override - public void onResume(@Nonnull Activity activity) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - - final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences); - if (!theme.equals(newTheme)) { - Activities.restartActivity(activity); - } - } - - @Override - public void onPause(@Nonnull Activity activity) { - } - - @Override - public void onPause(@Nonnull 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.apply(); - } - - } - - @Nonnull - private String getSavedTabPreferenceName(@Nonnull Activity activity) { - return "tab_" + activity.getClass().getSimpleName(); - } - - @Override - public void onDestroy(@Nonnull Activity activity) { - super.onDestroy(activity); - - if (activity instanceof CalculatorEventListener) { - Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) activity); - } - } - - @Override - public void onDestroy(@Nonnull SherlockFragmentActivity activity) { - this.onDestroy((Activity) activity); - } - - @Override - public void addTab(@Nonnull SherlockFragmentActivity activity, - @Nonnull String tag, - @Nonnull Class fragmentClass, - @Nullable Bundle fragmentArgs, - int captionResId, - int parentViewId) { - final ActionBar actionBar = activity.getSupportActionBar(); - - final ActionBar.Tab tab = actionBar.newTab(); - tab.setTag(tag); - tab.setText(captionResId); - - final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId); - tab.setTabListener(listener); - actionBar.addTab(tab); - } - - @Override - public void addTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { - addTab(activity, fragmentType.getFragmentTag(), fragmentType.getFragmentClass(), fragmentArgs, fragmentType.getDefaultTitleResId(), parentViewId); - } - - @Override - public void setFragment(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { - final FragmentManager fm = activity.getSupportFragmentManager(); - - Fragment fragment = fm.findFragmentByTag(fragmentType.getFragmentTag()); - if (fragment == null) { - fragment = Fragment.instantiate(activity, fragmentType.getFragmentClass().getName(), fragmentArgs); - final FragmentTransaction ft = fm.beginTransaction(); - ft.add(parentViewId, fragment, fragmentType.getFragmentTag()); - ft.commit(); - } else { - if (fragment.isDetached()) { - final FragmentTransaction ft = fm.beginTransaction(); - ft.attach(fragment); - ft.commit(); - } - - } - } - - @Override - public void selectTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType) { - final ActionBar actionBar = activity.getSupportActionBar(); - for (int i = 0; i < actionBar.getTabCount(); i++) { - final ActionBar.Tab tab = actionBar.getTabAt(i); - if (tab != null && fragmentType.getFragmentTag().equals(tab.getTag())) { - actionBar.setSelectedNavigationItem(i); - break; - } - } - } - - @Override - public int getLayoutId() { - return layoutId; - } - - @Override - @Nonnull - public CalculatorPreferences.Gui.Theme getTheme() { - return theme; - } - - @Override - @Nonnull - public CalculatorPreferences.Gui.Layout getLayout() { - return layout; - } - - @Override - public void onResume(@Nonnull SherlockFragmentActivity activity) { - onResume((Activity) activity); - - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - selectedNavigationIndex = preferences.getInt(getSavedTabPreferenceName(activity), -1); - restoreSavedTab(activity); - } - - private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) { - if (CalculatorApplication.isMonkeyRunner(activity)) { - if (root instanceof ViewGroup) { - final TextView helperTextView = new TextView(activity); - - final DisplayMetrics dm = new DisplayMetrics(); - activity.getWindowManager().getDefaultDisplay().getMetrics(dm); - - helperTextView.setTextSize(15); - helperTextView.setTextColor(Color.WHITE); - - final Configuration c = activity.getResources().getConfiguration(); - - final StringBuilder helpText = new StringBuilder(); - helpText.append("Size: "); - if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) { - helpText.append("xlarge"); - } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) { - helpText.append("large"); - } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) { - helpText.append("normal"); - } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) { - helpText.append("small"); - } else { - helpText.append("unknown"); - } - - helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")"); - - helpText.append(" Density: "); - switch (dm.densityDpi) { - case DisplayMetrics.DENSITY_LOW: - helpText.append("ldpi"); - break; - case DisplayMetrics.DENSITY_MEDIUM: - helpText.append("mdpi"); - break; - case DisplayMetrics.DENSITY_HIGH: - helpText.append("hdpi"); - break; - case DisplayMetrics.DENSITY_XHIGH: - helpText.append("xhdpi"); - break; - case DisplayMetrics.DENSITY_TV: - helpText.append("tv"); - break; - } - - helpText.append(" (").append(dm.densityDpi).append(")"); - - helperTextView.setText(helpText); - - ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - } - } - } -} +/* + * 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.SharedPreferences; +import android.content.res.Configuration; +import android.graphics.Color; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.solovyev.android.Activities; +import org.solovyev.android.Views; +import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ActivityUi extends BaseUi { + + /* + ********************************************************************** + * + * CONSTANTS + * + ********************************************************************** + */ + + /* + ********************************************************************** + * + * FIELDS + * + ********************************************************************** + */ + + private int layoutId; + + private boolean homeIcon = false; + + @Nonnull + private CalculatorPreferences.Gui.Theme theme; + + @Nonnull + private CalculatorPreferences.Gui.Layout layout; + + private int selectedNavigationIndex = 0; + + public ActivityUi(int layoutId, @Nonnull String logTag) { + super(logTag); + this.layoutId = layoutId; + } + + public ActivityUi(int layoutId, boolean homeIcon) { + this.layoutId = layoutId; + this.homeIcon = homeIcon; + } + + @Override + public void onCreate(@Nonnull Activity activity) { + super.onCreate(activity); + + if (activity instanceof CalculatorEventListener) { + Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity); + } + + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + + this.theme = CalculatorPreferences.Gui.getTheme(preferences); + activity.setTheme(this.theme.getThemeId()); + + this.layout = CalculatorPreferences.Gui.getLayout(preferences); + + activity.setContentView(layoutId); + + final View root = activity.findViewById(R.id.main_layout); + if (root != null) { + processButtons(activity, root); + addHelpInfo(activity, root); + } else { + Log.e(ActivityUi.class.getSimpleName(), "Root is null for " + activity.getClass().getName()); + } + } + + public void onCreate(@Nonnull final SherlockFragmentActivity activity) { + onCreate((Activity)activity); + + final ActionBar actionBar = activity.getSupportActionBar(); + actionBar.setDisplayUseLogoEnabled(false); + actionBar.setDisplayHomeAsUpEnabled(homeIcon); + actionBar.setHomeButtonEnabled(false); + actionBar.setDisplayShowHomeEnabled(true); + + toggleTitle(activity, true); + + actionBar.setIcon(R.drawable.ab_icon); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + } + + private void toggleTitle(@Nonnull SherlockFragmentActivity activity, boolean showTitle) { + final ActionBar actionBar = activity.getSupportActionBar(); + + if (activity instanceof CalculatorActivity) { + if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) { + actionBar.setDisplayShowTitleEnabled(true); + } else { + actionBar.setDisplayShowTitleEnabled(false); + } + } else { + actionBar.setDisplayShowTitleEnabled(showTitle); + } + } + + public void restoreSavedTab(@Nonnull SherlockFragmentActivity activity) { + final ActionBar actionBar = activity.getSupportActionBar(); + if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) { + actionBar.setSelectedNavigationItem(selectedNavigationIndex); + } + } + + public void onSaveInstanceState(@Nonnull SherlockFragmentActivity activity, @Nonnull Bundle outState) { + onSaveInstanceState((Activity) activity, outState); + } + + public void onSaveInstanceState(@Nonnull Activity activity, @Nonnull Bundle outState) { + } + + public void onResume(@Nonnull Activity activity) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + + final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences); + if (!theme.equals(newTheme)) { + Activities.restartActivity(activity); + } + } + + public void onPause(@Nonnull Activity activity) { + } + + public void onPause(@Nonnull 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.apply(); + } + + } + + @Nonnull + private String getSavedTabPreferenceName(@Nonnull Activity activity) { + return "tab_" + activity.getClass().getSimpleName(); + } + + @Override + public void onDestroy(@Nonnull Activity activity) { + super.onDestroy(activity); + + if (activity instanceof CalculatorEventListener) { + Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) activity); + } + } + + public void onDestroy(@Nonnull SherlockFragmentActivity activity) { + this.onDestroy((Activity) activity); + } + + public void addTab(@Nonnull SherlockFragmentActivity activity, + @Nonnull String tag, + @Nonnull Class fragmentClass, + @Nullable Bundle fragmentArgs, + int captionResId, + int parentViewId) { + final ActionBar actionBar = activity.getSupportActionBar(); + + final ActionBar.Tab tab = actionBar.newTab(); + tab.setTag(tag); + tab.setText(captionResId); + + final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId); + tab.setTabListener(listener); + actionBar.addTab(tab); + } + + public void addTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { + addTab(activity, fragmentType.getFragmentTag(), fragmentType.getFragmentClass(), fragmentArgs, fragmentType.getDefaultTitleResId(), parentViewId); + } + + public void setFragment(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { + final FragmentManager fm = activity.getSupportFragmentManager(); + + Fragment fragment = fm.findFragmentByTag(fragmentType.getFragmentTag()); + if (fragment == null) { + fragment = Fragment.instantiate(activity, fragmentType.getFragmentClass().getName(), fragmentArgs); + final FragmentTransaction ft = fm.beginTransaction(); + ft.add(parentViewId, fragment, fragmentType.getFragmentTag()); + ft.commit(); + } else { + if (fragment.isDetached()) { + final FragmentTransaction ft = fm.beginTransaction(); + ft.attach(fragment); + ft.commit(); + } + + } + } + + public void selectTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType) { + final ActionBar actionBar = activity.getSupportActionBar(); + for (int i = 0; i < actionBar.getTabCount(); i++) { + final ActionBar.Tab tab = actionBar.getTabAt(i); + if (tab != null && fragmentType.getFragmentTag().equals(tab.getTag())) { + actionBar.setSelectedNavigationItem(i); + break; + } + } + } + + public int getLayoutId() { + return layoutId; + } + + @Nonnull + public CalculatorPreferences.Gui.Theme getTheme() { + return theme; + } + + @Nonnull + public CalculatorPreferences.Gui.Layout getLayout() { + return layout; + } + + public void onResume(@Nonnull SherlockFragmentActivity activity) { + onResume((Activity) activity); + + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + selectedNavigationIndex = preferences.getInt(getSavedTabPreferenceName(activity), -1); + restoreSavedTab(activity); + } + + private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) { + if (CalculatorApplication.isMonkeyRunner(activity)) { + if (root instanceof ViewGroup) { + final TextView helperTextView = new TextView(activity); + + final DisplayMetrics dm = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(dm); + + helperTextView.setTextSize(15); + helperTextView.setTextColor(Color.WHITE); + + final Configuration c = activity.getResources().getConfiguration(); + + final StringBuilder helpText = new StringBuilder(); + helpText.append("Size: "); + if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) { + helpText.append("xlarge"); + } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) { + helpText.append("large"); + } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) { + helpText.append("normal"); + } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) { + helpText.append("small"); + } else { + helpText.append("unknown"); + } + + helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")"); + + helpText.append(" Density: "); + switch (dm.densityDpi) { + case DisplayMetrics.DENSITY_LOW: + helpText.append("ldpi"); + break; + case DisplayMetrics.DENSITY_MEDIUM: + helpText.append("mdpi"); + break; + case DisplayMetrics.DENSITY_HIGH: + helpText.append("hdpi"); + break; + case DisplayMetrics.DENSITY_XHIGH: + helpText.append("xhdpi"); + break; + case DisplayMetrics.DENSITY_TV: + helpText.append("tv"); + break; + } + + helpText.append(" (").append(dm.densityDpi).append(")"); + + helperTextView.setText(helpText); + + ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + } + } + } + + public void onStop(@Nonnull Activity activity) { + App.getGa().getAnalytics().reportActivityStop(activity); + } + + public void onStart(@Nonnull Activity activity) { + App.getGa().getAnalytics().reportActivityStart(activity); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/App.java b/android-app/src/main/java/org/solovyev/android/calculator/App.java index 0f575d7d..71e08815 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/App.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/App.java @@ -24,6 +24,7 @@ package org.solovyev.android.calculator; import android.app.Application; import org.solovyev.android.UiThreadExecutor; +import org.solovyev.android.calculator.ga.Ga; import org.solovyev.common.listeners.JEvent; import org.solovyev.common.listeners.JEventListener; import org.solovyev.common.listeners.JEventListeners; @@ -72,6 +73,9 @@ public final class App { @Nonnull private static CalculatorBroadcaster broadcaster; + @Nonnull + private static volatile Ga ga; + private App() { throw new AssertionError(); } @@ -100,6 +104,7 @@ public final class App { App.application = application; App.uiThreadExecutor = uiThreadExecutor; App.eventBus = eventBus; + App.ga = new Ga(application, eventBus); if (serviceLocator != null) { App.locator = serviceLocator; } else { @@ -138,16 +143,6 @@ public final class App { return (A) application; } - /** - * @param real type of service locator - * @return instance of service locator user in application - */ - @Nonnull - public static L getLocator() { - checkInit(); - return (L) locator; - } - /** * Method returns executor which runs on Main Application's thread. It's safe to do all UI work on this executor * @@ -172,4 +167,9 @@ public final class App { public static CalculatorBroadcaster getBroadcaster() { return broadcaster; } + + @Nonnull + public static Ga getGa() { + return ga; + } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java new file mode 100644 index 00000000..b52dd6d1 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -0,0 +1,73 @@ +package org.solovyev.android.calculator; + +import android.os.Bundle; +import android.support.annotation.LayoutRes; +import com.actionbarsherlock.app.SherlockFragmentActivity; + +import javax.annotation.Nonnull; + +public class BaseActivity extends SherlockFragmentActivity { + + @Nonnull + protected final ActivityUi ui; + + public BaseActivity(@Nonnull ActivityUi ui) { + this.ui = ui; + } + + public BaseActivity(@LayoutRes int layout) { + this(layout, "Activity"); + } + + public BaseActivity(@LayoutRes int layout, @Nonnull String logTag) { + this.ui = CalculatorApplication.getInstance().createActivityHelper(layout, logTag); + } + + @Nonnull + public ActivityUi getUi() { + return ui; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ui.onCreate(this); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + ui.onSaveInstanceState(this, outState); + } + + @Override + protected void onStart() { + super.onStart(); + ui.onStart(this); + } + + @Override + protected void onStop() { + ui.onStop(this); + super.onStop(); + } + + @Override + protected void onResume() { + super.onResume(); + ui.onResume(this); + } + + @Override + protected void onPause() { + this.ui.onPause(this); + super.onPause(); + } + + + @Override + protected void onDestroy() { + super.onDestroy(); + ui.onDestroy(this); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java b/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java similarity index 96% rename from android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java rename to android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java index 41bad375..a6a94f4d 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java @@ -1,321 +1,321 @@ -/* - * 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.app.KeyguardManager; -import android.content.Context; -import android.content.SharedPreferences; -import android.graphics.Typeface; -import android.os.Vibrator; -import android.preference.PreferenceManager; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View; -import android.widget.TextView; -import org.solovyev.android.Views; -import org.solovyev.android.calculator.history.CalculatorHistoryState; -import org.solovyev.android.calculator.view.AngleUnitsButton; -import org.solovyev.android.calculator.view.NumeralBasesButton; -import org.solovyev.android.calculator.view.OnDragListenerVibrator; -import org.solovyev.android.calculator.view.ViewsCache; -import org.solovyev.android.history.HistoryDragProcessor; -import org.solovyev.android.view.drag.*; -import org.solovyev.common.listeners.JListeners; -import org.solovyev.common.listeners.Listeners; -import org.solovyev.common.math.Point2d; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; - -import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple; -import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile; -import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit; -import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase; - -/** - * User: serso - * Date: 9/28/12 - * Time: 12:12 AM - */ -public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener { - - @Nonnull - private static final List viewIds = new ArrayList(200); - - @Nonnull - private CalculatorPreferences.Gui.Layout layout; - - @Nonnull - private CalculatorPreferences.Gui.Theme theme; - - @Nullable - private Vibrator vibrator; - - @Nonnull - private final JListeners dpclRegister = Listeners.newHardRefListeners(); - - @Nonnull - private String logTag = "CalculatorActivity"; - - @Nullable - private AngleUnitsButton angleUnitsButton; - - @Nullable - private NumeralBasesButton clearButton; - - protected AbstractCalculatorHelper() { - } - - protected AbstractCalculatorHelper(@Nonnull String logTag) { - this.logTag = logTag; - } - - protected void onCreate(@Nonnull Activity activity) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - - vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE); - layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); - theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences); - - preferences.registerOnSharedPreferenceChangeListener(this); - - // let's disable locking of screen for monkeyrunner - if (CalculatorApplication.isMonkeyRunner(activity)) { - final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); - km.newKeyguardLock(activity.getClass().getName()).disableKeyguard(); - } - } - - public void logDebug(@Nonnull String message) { - Log.d(logTag, message); - } - - public void logError(@Nonnull String message) { - Log.e(logTag, message); - } - - public void processButtons(@Nonnull final Activity activity, @Nonnull View root) { - dpclRegister.removeListeners(); - - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity); - - final ViewsCache views = ViewsCache.forView(root); - setOnDragListeners(views, dragPreferences, preferences); - - final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor(getCalculator()), dragPreferences), vibrator, preferences); - final DragButton historyButton = getButton(views, R.id.cpp_button_history); - if (historyButton != null) { - historyButton.setOnDragListener(historyOnDragListener); - } - - final DragButton subtractionButton = getButton(views, R.id.cpp_button_subtraction); - if (subtractionButton != null) { - subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { - @Override - public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) { - if (dragDirection == DragDirection.down) { - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null); - return true; - } - return false; - } - }, dragPreferences), vibrator, preferences)); - } - - final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences); - - final DragButton rightButton = getButton(views, R.id.cpp_button_right); - if (rightButton != null) { - rightButton.setOnDragListener(toPositionOnDragListener); - } - - final DragButton leftButton = getButton(views, R.id.cpp_button_left); - if (leftButton != null) { - leftButton.setOnDragListener(toPositionOnDragListener); - } - - final DragButton equalsButton = getButton(views, R.id.cpp_button_equals); - if (equalsButton != null) { - equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EqualsDragProcessor(), dragPreferences), vibrator, preferences)); - } - - angleUnitsButton = getButton(views, R.id.cpp_button_6); - if (angleUnitsButton != null) { - angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences)); - } - - clearButton = getButton(views, R.id.cpp_button_clear); - if (clearButton != null) { - clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences)); - } - - final DragButton varsButton = getButton(views, R.id.cpp_button_vars); - if (varsButton != null) { - varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences)); - } - - final DragButton functionsButton = getButton(views, R.id.cpp_button_functions); - if (functionsButton != null) { - functionsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.FunctionsDragProcessor(activity), dragPreferences), vibrator, preferences)); - } - - final DragButton roundBracketsButton = getButton(views, R.id.cpp_button_round_brackets); - if (roundBracketsButton != null) { - roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences)); - } - - if (layout == simple || layout == simple_mobile) { - toggleButtonDirectionText(views, R.id.cpp_button_1, false, DragDirection.up, DragDirection.down); - toggleButtonDirectionText(views, R.id.cpp_button_2, false, DragDirection.up, DragDirection.down); - toggleButtonDirectionText(views, R.id.cpp_button_3, false, DragDirection.up, DragDirection.down); - - toggleButtonDirectionText(views, R.id.cpp_button_6, false, DragDirection.up, DragDirection.down); - toggleButtonDirectionText(views, R.id.cpp_button_7, false, DragDirection.left, DragDirection.up, DragDirection.down); - toggleButtonDirectionText(views, R.id.cpp_button_8, false, DragDirection.left, DragDirection.up, DragDirection.down); - - toggleButtonDirectionText(views, R.id.cpp_button_clear, false, DragDirection.left, DragDirection.up, DragDirection.down); - - toggleButtonDirectionText(views, R.id.cpp_button_4, false, DragDirection.down); - toggleButtonDirectionText(views, R.id.cpp_button_5, false, DragDirection.down); - - toggleButtonDirectionText(views, R.id.cpp_button_9, false, DragDirection.left); - - toggleButtonDirectionText(views, R.id.cpp_button_multiplication, false, DragDirection.left); - toggleButtonDirectionText(views, R.id.cpp_button_plus, false, DragDirection.down, DragDirection.up); - } - - CalculatorButtons.processButtons(theme, layout, root); - CalculatorButtons.toggleEqualsButton(preferences, activity); - CalculatorButtons.initMultiplicationButton(root); - NumeralBaseButtons.toggleNumericDigits(activity, preferences); - - // some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views - final Typeface typeFace = CalculatorApplication.getInstance().getTypeFace(); - Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor() { - @Override - public void process(@Nonnull TextView view) { - int style = Typeface.NORMAL; - final Typeface oldTypeface = view.getTypeface(); - if (oldTypeface != null) { - style = oldTypeface.getStyle(); - } - view.setTypeface(typeFace, style); - } - }); - } - - private void toggleButtonDirectionText(@Nonnull ViewsCache views, int id, boolean showDirectionText, @Nonnull DragDirection... dragDirections) { - final View v = getButton(views, id); - if (v instanceof DirectionDragButton) { - final DirectionDragButton button = (DirectionDragButton) v; - for (DragDirection dragDirection : dragDirections) { - button.showDirectionText(showDirectionText, dragDirection); - } - } - } - - @Nonnull - private Calculator getCalculator() { - return Locator.getInstance().getCalculator(); - } - - - private void setOnDragListeners(@Nonnull ViewsCache views, @Nonnull SimpleOnDragListener.Preferences dragPreferences, @Nonnull SharedPreferences preferences) { - final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences); - - final List viewIds = getViewIds(); - for (Integer viewId : viewIds) { - final View view = views.findViewById(viewId); - if (view instanceof DragButton) { - ((DragButton) view).setOnDragListener(onDragListener); - } - } - } - - @Nonnull - private static List getViewIds() { - if (viewIds.isEmpty()) { - for (Field field : R.id.class.getDeclaredFields()) { - int modifiers = field.getModifiers(); - if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { - try { - viewIds.add(field.getInt(R.id.class)); - } catch (IllegalAccessException e) { - Log.e(R.id.class.getName(), e.getMessage()); - } - } - } - } - return viewIds; - } - - @Nonnull - private CalculatorKeyboard getKeyboard() { - return Locator.getInstance().getKeyboard(); - } - - @Nullable - private T getButton(@Nonnull ViewsCache views, int buttonId) { - return (T) views.findViewById(buttonId); - } - - @Nonnull - private SimpleOnDragListener newOnDragListener(@Nonnull SimpleOnDragListener.DragProcessor dragProcessor, - @Nonnull SimpleOnDragListener.Preferences dragPreferences) { - final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences); - dpclRegister.addListener(onDragListener); - return onDragListener; - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { - if (key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) { - final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()); - for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) { - dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences); - } - } - - if (angleUnit.isSameKey(key) || numeralBase.isSameKey(key)) { - if (angleUnitsButton != null) { - angleUnitsButton.setAngleUnit(angleUnit.getPreference(preferences)); - } - - if (clearButton != null) { - clearButton.setNumeralBase(numeralBase.getPreference(preferences)); - } - } - } - - public void onDestroy(@Nonnull Activity activity) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - - preferences.unregisterOnSharedPreferenceChangeListener(this); - } -} +/* + * 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.app.KeyguardManager; +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.Typeface; +import android.os.Vibrator; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; +import android.widget.TextView; +import org.solovyev.android.Views; +import org.solovyev.android.calculator.history.CalculatorHistoryState; +import org.solovyev.android.calculator.view.AngleUnitsButton; +import org.solovyev.android.calculator.view.NumeralBasesButton; +import org.solovyev.android.calculator.view.OnDragListenerVibrator; +import org.solovyev.android.calculator.view.ViewsCache; +import org.solovyev.android.history.HistoryDragProcessor; +import org.solovyev.android.view.drag.*; +import org.solovyev.common.listeners.JListeners; +import org.solovyev.common.listeners.Listeners; +import org.solovyev.common.math.Point2d; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple; +import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile; +import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit; +import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase; + +/** + * User: serso + * Date: 9/28/12 + * Time: 12:12 AM + */ +public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Nonnull + private static final List viewIds = new ArrayList(200); + + @Nonnull + private CalculatorPreferences.Gui.Layout layout; + + @Nonnull + private CalculatorPreferences.Gui.Theme theme; + + @Nullable + private Vibrator vibrator; + + @Nonnull + private final JListeners dpclRegister = Listeners.newHardRefListeners(); + + @Nonnull + private String logTag = "CalculatorActivity"; + + @Nullable + private AngleUnitsButton angleUnitsButton; + + @Nullable + private NumeralBasesButton clearButton; + + protected BaseUi() { + } + + protected BaseUi(@Nonnull String logTag) { + this.logTag = logTag; + } + + protected void onCreate(@Nonnull Activity activity) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + + vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE); + layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); + theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences); + + preferences.registerOnSharedPreferenceChangeListener(this); + + // let's disable locking of screen for monkeyrunner + if (CalculatorApplication.isMonkeyRunner(activity)) { + final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); + km.newKeyguardLock(activity.getClass().getName()).disableKeyguard(); + } + } + + public void logDebug(@Nonnull String message) { + Log.d(logTag, message); + } + + public void logError(@Nonnull String message) { + Log.e(logTag, message); + } + + public void processButtons(@Nonnull final Activity activity, @Nonnull View root) { + dpclRegister.removeListeners(); + + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity); + + final ViewsCache views = ViewsCache.forView(root); + setOnDragListeners(views, dragPreferences, preferences); + + final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor(getCalculator()), dragPreferences), vibrator, preferences); + final DragButton historyButton = getButton(views, R.id.cpp_button_history); + if (historyButton != null) { + historyButton.setOnDragListener(historyOnDragListener); + } + + final DragButton subtractionButton = getButton(views, R.id.cpp_button_subtraction); + if (subtractionButton != null) { + subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { + @Override + public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) { + if (dragDirection == DragDirection.down) { + Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null); + return true; + } + return false; + } + }, dragPreferences), vibrator, preferences)); + } + + final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences); + + final DragButton rightButton = getButton(views, R.id.cpp_button_right); + if (rightButton != null) { + rightButton.setOnDragListener(toPositionOnDragListener); + } + + final DragButton leftButton = getButton(views, R.id.cpp_button_left); + if (leftButton != null) { + leftButton.setOnDragListener(toPositionOnDragListener); + } + + final DragButton equalsButton = getButton(views, R.id.cpp_button_equals); + if (equalsButton != null) { + equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EqualsDragProcessor(), dragPreferences), vibrator, preferences)); + } + + angleUnitsButton = getButton(views, R.id.cpp_button_6); + if (angleUnitsButton != null) { + angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences)); + } + + clearButton = getButton(views, R.id.cpp_button_clear); + if (clearButton != null) { + clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences)); + } + + final DragButton varsButton = getButton(views, R.id.cpp_button_vars); + if (varsButton != null) { + varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences)); + } + + final DragButton functionsButton = getButton(views, R.id.cpp_button_functions); + if (functionsButton != null) { + functionsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.FunctionsDragProcessor(activity), dragPreferences), vibrator, preferences)); + } + + final DragButton roundBracketsButton = getButton(views, R.id.cpp_button_round_brackets); + if (roundBracketsButton != null) { + roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences)); + } + + if (layout == simple || layout == simple_mobile) { + toggleButtonDirectionText(views, R.id.cpp_button_1, false, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(views, R.id.cpp_button_2, false, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(views, R.id.cpp_button_3, false, DragDirection.up, DragDirection.down); + + toggleButtonDirectionText(views, R.id.cpp_button_6, false, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(views, R.id.cpp_button_7, false, DragDirection.left, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(views, R.id.cpp_button_8, false, DragDirection.left, DragDirection.up, DragDirection.down); + + toggleButtonDirectionText(views, R.id.cpp_button_clear, false, DragDirection.left, DragDirection.up, DragDirection.down); + + toggleButtonDirectionText(views, R.id.cpp_button_4, false, DragDirection.down); + toggleButtonDirectionText(views, R.id.cpp_button_5, false, DragDirection.down); + + toggleButtonDirectionText(views, R.id.cpp_button_9, false, DragDirection.left); + + toggleButtonDirectionText(views, R.id.cpp_button_multiplication, false, DragDirection.left); + toggleButtonDirectionText(views, R.id.cpp_button_plus, false, DragDirection.down, DragDirection.up); + } + + CalculatorButtons.processButtons(theme, layout, root); + CalculatorButtons.toggleEqualsButton(preferences, activity); + CalculatorButtons.initMultiplicationButton(root); + NumeralBaseButtons.toggleNumericDigits(activity, preferences); + + // some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views + final Typeface typeFace = CalculatorApplication.getInstance().getTypeFace(); + Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor() { + @Override + public void process(@Nonnull TextView view) { + int style = Typeface.NORMAL; + final Typeface oldTypeface = view.getTypeface(); + if (oldTypeface != null) { + style = oldTypeface.getStyle(); + } + view.setTypeface(typeFace, style); + } + }); + } + + private void toggleButtonDirectionText(@Nonnull ViewsCache views, int id, boolean showDirectionText, @Nonnull DragDirection... dragDirections) { + final View v = getButton(views, id); + if (v instanceof DirectionDragButton) { + final DirectionDragButton button = (DirectionDragButton) v; + for (DragDirection dragDirection : dragDirections) { + button.showDirectionText(showDirectionText, dragDirection); + } + } + } + + @Nonnull + private Calculator getCalculator() { + return Locator.getInstance().getCalculator(); + } + + + private void setOnDragListeners(@Nonnull ViewsCache views, @Nonnull SimpleOnDragListener.Preferences dragPreferences, @Nonnull SharedPreferences preferences) { + final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences); + + final List viewIds = getViewIds(); + for (Integer viewId : viewIds) { + final View view = views.findViewById(viewId); + if (view instanceof DragButton) { + ((DragButton) view).setOnDragListener(onDragListener); + } + } + } + + @Nonnull + private static List getViewIds() { + if (viewIds.isEmpty()) { + for (Field field : R.id.class.getDeclaredFields()) { + int modifiers = field.getModifiers(); + if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { + try { + viewIds.add(field.getInt(R.id.class)); + } catch (IllegalAccessException e) { + Log.e(R.id.class.getName(), e.getMessage()); + } + } + } + } + return viewIds; + } + + @Nonnull + private CalculatorKeyboard getKeyboard() { + return Locator.getInstance().getKeyboard(); + } + + @Nullable + private T getButton(@Nonnull ViewsCache views, int buttonId) { + return (T) views.findViewById(buttonId); + } + + @Nonnull + private SimpleOnDragListener newOnDragListener(@Nonnull SimpleOnDragListener.DragProcessor dragProcessor, + @Nonnull SimpleOnDragListener.Preferences dragPreferences) { + final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences); + dpclRegister.addListener(onDragListener); + return onDragListener; + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { + if (key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) { + final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()); + for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) { + dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences); + } + } + + if (angleUnit.isSameKey(key) || numeralBase.isSameKey(key)) { + if (angleUnitsButton != null) { + angleUnitsButton.setAngleUnit(angleUnit.getPreference(preferences)); + } + + if (clearButton != null) { + clearButton.setNumeralBase(numeralBase.getPreference(preferences)); + } + } + } + + public void onDestroy(@Nonnull Activity activity) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + + preferences.unregisterOnSharedPreferenceChangeListener(this); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index e39f0a58..dd42c3f4 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -70,7 +70,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar private boolean useBackAsPrev; @Nonnull - private CalculatorActivityHelper activityHelper; + private ActivityUi activityUi; /** * Called when the activity is first created. @@ -81,20 +81,20 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); - activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG); - activityHelper.logDebug("onCreate"); - activityHelper.onCreate(this, savedInstanceState); + activityUi = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG); + activityUi.logDebug("onCreate"); + activityUi.onCreate(this); super.onCreate(savedInstanceState); - activityHelper.logDebug("super.onCreate"); + activityUi.logDebug("super.onCreate"); if (isMultiPane()) { - activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane); - activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane); - activityHelper.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane); - activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane); - activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane); - activityHelper.addTab(this, CalculatorPlotActivity.getPlotterFragmentType(), null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane); + activityUi.addTab(this, CalculatorPlotActivity.getPlotterFragmentType(), null, R.id.main_second_pane); } else { final ActionBar actionBar = getSupportActionBar(); if (Build.VERSION.SDK_INT <= GINGERBREAD_MR1 || (Build.VERSION.SDK_INT >= ICE_CREAM_SANDWICH && hasPermanentMenuKey())) { @@ -127,6 +127,18 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar } } + @Override + protected void onStart() { + super.onStart(); + activityUi.onStart(this); + } + + @Override + protected void onStop() { + activityUi.onStop(this); + super.onStop(); + } + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private boolean hasPermanentMenuKey() { return ViewConfiguration.get(this).hasPermanentMenuKey(); @@ -232,7 +244,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar @Override protected void onPause() { - this.activityHelper.onPause(this); + this.activityUi.onPause(this); super.onPause(); } @@ -243,7 +255,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences); - if (newLayout != activityHelper.getLayout()) { + if (newLayout != activityUi.getLayout()) { Activities.restartActivity(this); } @@ -254,12 +266,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar window.clearFlags(FLAG_KEEP_SCREEN_ON); } - this.activityHelper.onResume(this); + this.activityUi.onResume(this); } @Override protected void onDestroy() { - activityHelper.onDestroy(this); + activityUi.onDestroy(this); PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this); @@ -281,7 +293,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - activityHelper.onSaveInstanceState(this, outState); + activityUi.onSaveInstanceState(this, outState); } private void toggleOrientationChange(@Nullable SharedPreferences preferences) { @@ -391,7 +403,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar // do nothing - fragment shown and already registered for plot updates } else { // otherwise - open fragment - activityHelper.selectTab(CalculatorActivity.this, CalculatorFragmentType.plotter); + activityUi.selectTab(CalculatorActivity.this, CalculatorFragmentType.plotter); } } else { // start new activity diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java deleted file mode 100644 index fcde5e68..00000000 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelper.java +++ /dev/null @@ -1,95 +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.View; - -import com.actionbarsherlock.app.SherlockFragmentActivity; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 9/25/12 - * Time: 10:31 PM - */ -public interface CalculatorActivityHelper { - - void onCreate(@Nonnull SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState); - - void onCreate(@Nonnull Activity activity, @Nullable Bundle savedInstanceState); - - void onSaveInstanceState(@Nonnull SherlockFragmentActivity activity, @Nonnull Bundle outState); - - void onSaveInstanceState(@Nonnull Activity activity, @Nonnull Bundle outState); - - int getLayoutId(); - - @Nonnull - CalculatorPreferences.Gui.Theme getTheme(); - - @Nonnull - CalculatorPreferences.Gui.Layout getLayout(); - - void onResume(@Nonnull SherlockFragmentActivity activity); - - void onResume(@Nonnull Activity activity); - - void onPause(@Nonnull Activity activity); - - void onPause(@Nonnull SherlockFragmentActivity activity); - - void onDestroy(@Nonnull SherlockFragmentActivity activity); - - void onDestroy(@Nonnull Activity activity); - - void addTab(@Nonnull SherlockFragmentActivity activity, - @Nonnull String tag, - @Nonnull Class fragmentClass, - @Nullable Bundle fragmentArgs, - int captionResId, - int parentViewId); - - void addTab(@Nonnull SherlockFragmentActivity activity, - @Nonnull CalculatorFragmentType fragmentType, - @Nullable Bundle fragmentArgs, - int parentViewId); - - void setFragment(@Nonnull SherlockFragmentActivity activity, - @Nonnull CalculatorFragmentType fragmentType, - @Nullable Bundle fragmentArgs, - int parentViewId); - - - void logDebug(@Nonnull String message); - - void processButtons(@Nonnull Activity activity, @Nonnull View root); - - void logError(@Nonnull String message); - - void selectTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType); -} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 158ed592..7407e297 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -226,23 +226,23 @@ public class CalculatorApplication extends android.app.Application implements Sh } @Nonnull - public CalculatorActivityHelper createActivityHelper(int layoutResId, @Nonnull String logTag) { - return new CalculatorActivityHelperImpl(layoutResId, logTag); + public ActivityUi createActivityHelper(int layoutResId, @Nonnull String logTag) { + return new ActivityUi(layoutResId, logTag); } @Nonnull - public CalculatorFragmentHelper createFragmentHelper(int layoutId) { - return new CalculatorFragmentHelperImpl(layoutId); + public FragmentUi createFragmentHelper(int layoutId) { + return new FragmentUi(layoutId); } @Nonnull - public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId) { - return new CalculatorFragmentHelperImpl(layoutId, titleResId); + public FragmentUi createFragmentHelper(int layoutId, int titleResId) { + return new FragmentUi(layoutId, titleResId); } @Nonnull - public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId, boolean listenersOnCreate) { - return new CalculatorFragmentHelperImpl(layoutId, titleResId, listenersOnCreate); + public FragmentUi createFragmentHelper(int layoutId, int titleResId, boolean listenersOnCreate) { + return new FragmentUi(layoutId, titleResId, listenersOnCreate); } @Nonnull diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java index 18ccab8a..d68b96b0 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java @@ -41,7 +41,7 @@ import javax.annotation.Nonnull; public class CalculatorDisplayFragment extends SherlockFragment { @Nonnull - private CalculatorFragmentHelper fragmentHelper; + private FragmentUi fragmentHelper; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java index 7804baf4..b496acda 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java @@ -49,7 +49,7 @@ import org.solovyev.android.sherlock.menu.SherlockMenuHelper; public class CalculatorEditorFragment extends SherlockFragment { @Nonnull - private CalculatorFragmentHelper fragmentHelper; + private FragmentUi fragmentHelper; @Nonnull private ActivityMenu menu = ListActivityMenu.fromEnum(CalculatorMenu.class, SherlockMenuHelper.getInstance()); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java index 51e46ea0..bb193cef 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java @@ -40,7 +40,7 @@ import javax.annotation.Nonnull; public abstract class CalculatorFragment extends SherlockFragment { @Nonnull - private final CalculatorFragmentHelper fragmentHelper; + private final FragmentUi fragmentHelper; protected CalculatorFragment(int layoutResId, int titleResId) { fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId); @@ -50,7 +50,7 @@ public abstract class CalculatorFragment extends SherlockFragment { fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); } - protected CalculatorFragment(@Nonnull CalculatorFragmentHelper fragmentHelper) { + protected CalculatorFragment(@Nonnull FragmentUi fragmentHelper) { this.fragmentHelper = fragmentHelper; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentActivity.java deleted file mode 100644 index 77d61696..00000000 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentActivity.java +++ /dev/null @@ -1,89 +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.os.Bundle; - -import com.actionbarsherlock.app.SherlockFragmentActivity; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 03.10.12 - * Time: 14:07 - */ -public abstract class CalculatorFragmentActivity extends SherlockFragmentActivity { - - @Nonnull - private final CalculatorActivityHelper activityHelper; - - protected CalculatorFragmentActivity() { - this(R.layout.main_empty); - } - - protected CalculatorFragmentActivity(int layoutResId) { - this.activityHelper = CalculatorApplication.getInstance().createActivityHelper(layoutResId, getClass().getSimpleName()); - } - - @Nonnull - protected CalculatorActivityHelper getActivityHelper() { - return activityHelper; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - activityHelper.onCreate(this, savedInstanceState); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - activityHelper.onDestroy(this); - } -} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java index 3a5f2421..7b4e35ba 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java @@ -55,7 +55,7 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar private CalculatorPreferences.Gui.Theme theme; @Nonnull - private CalculatorFragmentHelper fragmentHelper; + private FragmentUi fragmentHelper; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java index 731bc456..f105164b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java @@ -40,7 +40,7 @@ import javax.annotation.Nonnull; public abstract class CalculatorListFragment extends SherlockListFragment { @Nonnull - private final CalculatorFragmentHelper fragmentHelper; + private final FragmentUi fragmentHelper; protected CalculatorListFragment(int layoutResId, int titleResId) { fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId); @@ -50,7 +50,7 @@ public abstract class CalculatorListFragment extends SherlockListFragment { fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); } - protected CalculatorListFragment(@Nonnull CalculatorFragmentHelper fragmentHelper) { + protected CalculatorListFragment(@Nonnull FragmentUi fragmentHelper) { this.fragmentHelper = fragmentHelper; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorWikiActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorWikiActivity.java index 8cdbbe2b..0d338ef2 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorWikiActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorWikiActivity.java @@ -30,7 +30,7 @@ import android.webkit.WebView; * Date: 6/16/13 * Time: 6:26 PM */ -public final class CalculatorWikiActivity extends CalculatorFragmentActivity { +public final class CalculatorWikiActivity extends EmptyActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelper.java b/android-app/src/main/java/org/solovyev/android/calculator/EmptyActivity.java similarity index 50% rename from android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelper.java rename to android-app/src/main/java/org/solovyev/android/calculator/EmptyActivity.java index dc5b8044..1222c795 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelper.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/EmptyActivity.java @@ -22,35 +22,13 @@ package org.solovyev.android.calculator; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; +public abstract class EmptyActivity extends BaseActivity { -import javax.annotation.Nonnull; -import javax.annotation.Nullable; + protected EmptyActivity() { + this(R.layout.main_empty); + } -/** - * User: serso - * Date: 9/26/12 - * Time: 10:14 PM - */ -public interface CalculatorFragmentHelper { - - boolean isPane(@Nonnull Fragment fragment); - - void setPaneTitle(@Nonnull Fragment fragment, int titleResId); - - void onCreate(@Nonnull Fragment fragment); - - @Nonnull - View onCreateView(@Nonnull Fragment fragment, @Nonnull LayoutInflater inflater, @Nullable ViewGroup container); - - void onViewCreated(@Nonnull Fragment fragment, @Nonnull View root); - - void onResume(@Nonnull Fragment fragment); - - void onPause(@Nonnull Fragment fragment); - - void onDestroy(@Nonnull Fragment fragment); + protected EmptyActivity(int layoutResId) { + super(layoutResId); + } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelperImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java similarity index 92% rename from android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelperImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java index 997da7aa..8ad2772b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentHelperImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java @@ -42,7 +42,7 @@ import static java.util.Arrays.asList; * Date: 9/26/12 * Time: 10:14 PM */ -public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper implements CalculatorFragmentHelper { +public class FragmentUi extends BaseUi { private ActivityCheckout checkout; @@ -58,22 +58,21 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple @Nullable private Boolean adFree = null; - public CalculatorFragmentHelperImpl(int layoutId) { + public FragmentUi(int layoutId) { this.layoutId = layoutId; } - public CalculatorFragmentHelperImpl(int layoutId, int titleResId) { + public FragmentUi(int layoutId, int titleResId) { this.layoutId = layoutId; this.titleResId = titleResId; } - public CalculatorFragmentHelperImpl(int layoutId, int titleResId, boolean listenersOnCreate) { + public FragmentUi(int layoutId, int titleResId, boolean listenersOnCreate) { this.layoutId = layoutId; this.titleResId = titleResId; this.listenersOnCreate = listenersOnCreate; } - @Override public boolean isPane(@Nonnull Fragment fragment) { return fragment.getActivity() instanceof CalculatorActivity; } @@ -89,7 +88,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple } } - @Override public void onCreate(@Nonnull Fragment fragment) { final FragmentActivity activity = fragment.getActivity(); super.onCreate(activity); @@ -104,7 +102,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple checkout.start(); } - @Override public void onResume(@Nonnull Fragment fragment) { if (adView != null) { adView.resume(); @@ -136,7 +133,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple } } - @Override public void onPause(@Nonnull Fragment fragment) { adFree = null; if (adView != null) { @@ -149,7 +145,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple } } - @Override public void onViewCreated(@Nonnull Fragment fragment, @Nonnull View root) { adView = (AdView) root.findViewById(R.id.ad); final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout); @@ -170,7 +165,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple } } - @Override public void onDestroy(@Nonnull Fragment fragment) { if (adView != null) { adView.destroy(); @@ -189,7 +183,6 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple } @Nonnull - @Override public View onCreateView(@Nonnull Fragment fragment, @Nonnull LayoutInflater inflater, @Nullable ViewGroup container) { return inflater.inflate(layoutId, container, false); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java index 270d6003..bcfd8e57 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java @@ -23,25 +23,24 @@ package org.solovyev.android.calculator.about; import android.os.Bundle; - -import javax.annotation.Nullable; - -import org.solovyev.android.calculator.CalculatorFragmentActivity; +import org.solovyev.android.calculator.EmptyActivity; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; +import javax.annotation.Nullable; + /** * User: serso * Date: 9/16/11 * Time: 11:52 PM */ -public class CalculatorAboutActivity extends CalculatorFragmentActivity { +public class CalculatorAboutActivity extends EmptyActivity { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getActivityHelper().addTab(this, CalculatorFragmentType.about, null, R.id.main_layout); - getActivityHelper().addTab(this, CalculatorFragmentType.release_notes, null, R.id.main_layout); + getUi().addTab(this, CalculatorFragmentType.about, null, R.id.main_layout); + getUi().addTab(this, CalculatorFragmentType.release_notes, null, R.id.main_layout); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/ga/Ga.java b/android-app/src/main/java/org/solovyev/android/calculator/ga/Ga.java new file mode 100644 index 00000000..ad5e150d --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/calculator/ga/Ga.java @@ -0,0 +1,50 @@ +package org.solovyev.android.calculator.ga; + +import android.content.Context; +import android.util.Log; +import com.google.android.gms.analytics.GoogleAnalytics; +import com.google.android.gms.analytics.Tracker; +import org.solovyev.android.calculator.R; +import org.solovyev.common.listeners.JEvent; +import org.solovyev.common.listeners.JEventListener; +import org.solovyev.common.listeners.JEventListeners; + +import javax.annotation.Nonnull; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +public final class Ga { + + @Nonnull + private final GoogleAnalytics analytics; + + @Nonnull + private final Tracker tracker; + + public Ga(@Nonnull Context context, @Nonnull JEventListeners, JEvent> bus) { + analytics = GoogleAnalytics.getInstance(context); + tracker = analytics.newTracker(R.xml.ga); + } + + @Nonnull + private String getStackTrace(@Nonnull Exception e) { + try { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + e.printStackTrace(new PrintStream(out)); + return new String(out.toByteArray()); + } catch (Exception e1) { + Log.e("Ga", e1.getMessage(), e1); + } + return ""; + } + + @Nonnull + public GoogleAnalytics getAnalytics() { + return analytics; + } + + @Nonnull + public Tracker getTracker() { + return tracker; + } +} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java index 3fd1a722..744c11a8 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java @@ -108,7 +108,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag private HistoryArrayAdapter adapter; @Nonnull - private CalculatorFragmentHelper fragmentHelper; + private FragmentUi fragmentHelper; private final ActivityMenu menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, SherlockMenuHelper.getInstance(), new HistoryMenuFilter()); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java index 3c6da3bb..491a475c 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java @@ -23,64 +23,26 @@ package org.solovyev.android.calculator.history; import android.os.Bundle; - -import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.android.calculator.*; - import static org.solovyev.android.calculator.CalculatorFragmentType.history; import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history; -/** - * User: serso - * Date: 12/18/11 - * Time: 7:37 PM - */ -public class CalculatorHistoryActivity extends SherlockFragmentActivity implements CalculatorEventListener { +public class CalculatorHistoryActivity extends BaseActivity implements CalculatorEventListener { - @Nonnull - private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + public CalculatorHistoryActivity() { + super(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - activityHelper.onCreate(this, savedInstanceState); - - activityHelper.addTab(this, history, null, R.id.main_layout); - activityHelper.addTab(this, saved_history, null, R.id.main_layout); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - activityHelper.onDestroy(this); + ui.addTab(this, history, null, R.id.main_layout); + ui.addTab(this, saved_history, null, R.id.main_layout); } @Override @@ -89,9 +51,4 @@ public class CalculatorHistoryActivity extends SherlockFragmentActivity implemen this.finish(); } } - - @Nonnull - CalculatorActivityHelper getActivityHelper() { - return activityHelper; - } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java index 7b167b27..fe4fdf9a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java @@ -99,7 +99,7 @@ public class HistoryArrayAdapter extends ArrayAdapter { final Context context = getContext(); if (context instanceof CalculatorHistoryActivity) { final CalculatorHistoryActivity activity = (CalculatorHistoryActivity) context; - activity.getActivityHelper().selectTab(activity, saved_history); + activity.getUi().selectTab(activity, saved_history); } } }); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java index 8c7898ea..b7419d36 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java @@ -33,7 +33,6 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -44,7 +43,7 @@ import org.solovyev.android.calculator.CalculatorApplication; import org.solovyev.android.calculator.CalculatorEventData; import org.solovyev.android.calculator.CalculatorEventListener; import org.solovyev.android.calculator.CalculatorEventType; -import org.solovyev.android.calculator.CalculatorFragmentHelper; +import org.solovyev.android.calculator.FragmentUi; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorMathRegistry; import org.solovyev.android.calculator.Locator; @@ -96,7 +95,7 @@ public abstract class AbstractMathEntityListFragment exten private String category; @Nonnull - private final CalculatorFragmentHelper fragmentHelper; + private final FragmentUi fragmentHelper; @Nonnull private final Handler uiHandler = new Handler(); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsActivity.java index c0250c27..3f6123a1 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsActivity.java @@ -25,31 +25,21 @@ package org.solovyev.android.calculator.math.edit; import android.content.Intent; import android.os.Bundle; import android.util.Log; - -import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.android.calculator.*; -import org.solovyev.android.calculator.history.CalculatorHistoryActivity; +public class CalculatorFunctionsActivity extends BaseActivity implements CalculatorEventListener { -/** - * User: serso - * Date: 12/21/11 - * Time: 10:33 PM - */ -public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener { - - @Nonnull - private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + public CalculatorFunctionsActivity() { + super(R.layout.main_empty, CalculatorFunctionsActivity.class.getSimpleName()); + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - activityHelper.onCreate(this, savedInstanceState); - final Bundle bundle; final Intent intent = getIntent(); @@ -74,41 +64,11 @@ public class CalculatorFunctionsActivity extends SherlockFragmentActivity implem fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name()); } - activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidCategory.getCaptionId(), R.id.main_layout); + ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidCategory.getCaptionId(), R.id.main_layout); } else { Log.e(CalculatorFunctionsActivity.class.getSimpleName(), "Unable to find android function category for " + category); } } - - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - this.activityHelper.onDestroy(this); } @Override diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java index 13594ff5..1924d81a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java @@ -23,72 +23,33 @@ package org.solovyev.android.calculator.math.edit; import android.os.Bundle; - -import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.android.calculator.*; -import org.solovyev.android.calculator.history.CalculatorHistoryActivity; +public class CalculatorOperatorsActivity extends BaseActivity implements CalculatorEventListener { -/** - * User: serso - * Date: 12/21/11 - * Time: 10:33 PM - */ -public class CalculatorOperatorsActivity extends SherlockFragmentActivity implements CalculatorEventListener { - - @Nonnull - private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + public CalculatorOperatorsActivity() { + super(R.layout.main_empty, CalculatorOperatorsActivity.class.getSimpleName()); + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - activityHelper.onCreate(this, savedInstanceState); - final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators; for (OperatorCategory category : OperatorCategory.getCategoriesByTabOrder()) { final AndroidOperatorCategory androidCategory = AndroidOperatorCategory.valueOf(category); if (androidCategory != null) { - activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), androidCategory.getCaptionId(), R.id.main_layout); + ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), androidCategory.getCaptionId(), R.id.main_layout); } else { - activityHelper.logError("Unable to find android operator category for " + category); + ui.logError("Unable to find android operator category for " + category); } } } - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - this.activityHelper.onDestroy(this); - } - @Override public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { switch (calculatorEventType) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java index f535373d..08be5def 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsActivity.java @@ -24,31 +24,21 @@ package org.solovyev.android.calculator.math.edit; import android.content.Intent; import android.os.Bundle; - -import com.actionbarsherlock.app.SherlockFragmentActivity; +import org.solovyev.android.calculator.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.android.calculator.*; -import org.solovyev.android.calculator.history.CalculatorHistoryActivity; +public class CalculatorVarsActivity extends BaseActivity implements CalculatorEventListener { -/** - * User: serso - * Date: 12/21/11 - * Time: 11:05 PM - */ -public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener { - - @Nonnull - private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + public CalculatorVarsActivity() { + super(R.layout.main_empty, CalculatorVarsActivity.class.getSimpleName()); + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - activityHelper.onCreate(this, savedInstanceState); - final Bundle bundle; final Intent intent = getIntent(); @@ -75,43 +65,13 @@ public class CalculatorVarsActivity extends SherlockFragmentActivity implements final AndroidVarCategory androidVarCategory = AndroidVarCategory.valueOf(category); if (androidVarCategory != null) { - activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout); + ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout); } else { - activityHelper.logError("Unable to find android var category for " + category); + ui.logError("Unable to find android var category for " + category); } - } } - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - activityHelper.onSaveInstanceState(this, outState); - } - - @Override - protected void onResume() { - super.onResume(); - - activityHelper.onResume(this); - } - - @Override - protected void onPause() { - this.activityHelper.onPause(this); - - super.onPause(); - } - - - @Override - protected void onDestroy() { - super.onDestroy(); - - this.activityHelper.onDestroy(this); - } - @Override public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { switch (calculatorEventType) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java index ad8f91da..ec028731 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/matrix/CalculatorMatrixActivity.java @@ -24,7 +24,7 @@ package org.solovyev.android.calculator.matrix; import android.os.Bundle; -import org.solovyev.android.calculator.CalculatorFragmentActivity; +import org.solovyev.android.calculator.EmptyActivity; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; @@ -35,13 +35,13 @@ import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD; * Date: 12.10.12 * Time: 10:56 */ -public class CalculatorMatrixActivity extends CalculatorFragmentActivity { +public class CalculatorMatrixActivity extends EmptyActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setNavigationMode(NAVIGATION_MODE_STANDARD); - getActivityHelper().setFragment(this, CalculatorFragmentType.matrix_edit, null, R.id.main_layout); + getUi().setFragment(this, CalculatorFragmentType.matrix_edit, null, R.id.main_layout); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java b/android-app/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java index f1af8b66..31265e4e 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java @@ -29,10 +29,10 @@ import android.content.res.Resources; import android.preference.PreferenceManager; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; -import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.MathEntityDao; import org.solovyev.android.calculator.MathEntityPersistenceContainer; import org.solovyev.android.calculator.MathPersistenceEntity; +import org.solovyev.android.calculator.R; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -111,7 +111,7 @@ public class AndroidMathEntityDao implements Ma public String getDescription(@Nonnull String descriptionId) { final Resources resources = context.getResources(); - final int stringId = resources.getIdentifier(descriptionId, "string", App.getApplication().getClass().getPackage().getName()); + final int stringId = resources.getIdentifier(descriptionId, "string", R.class.getPackage().getName()); try { return resources.getString(stringId); } catch (Resources.NotFoundException e) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java index f2c5a602..c6dc0beb 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java @@ -25,7 +25,7 @@ package org.solovyev.android.calculator.plot; import android.content.Intent; import android.os.Bundle; -import org.solovyev.android.calculator.CalculatorFragmentActivity; +import org.solovyev.android.calculator.EmptyActivity; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; @@ -39,7 +39,7 @@ import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD; * Date: 9/30/12 * Time: 4:56 PM */ -public class CalculatorPlotActivity extends CalculatorFragmentActivity { +public class CalculatorPlotActivity extends EmptyActivity { @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -55,7 +55,7 @@ public class CalculatorPlotActivity extends CalculatorFragmentActivity { } getSupportActionBar().setNavigationMode(NAVIGATION_MODE_STANDARD); - getActivityHelper().setFragment(this, getPlotterFragmentType(), arguments, R.id.main_layout); + getUi().setFragment(this, getPlotterFragmentType(), arguments, R.id.main_layout); } @Nonnull diff --git a/android-app/src/main/res/xml/ga.xml b/android-app/src/main/res/xml/ga.xml new file mode 100644 index 00000000..83a49feb --- /dev/null +++ b/android-app/src/main/res/xml/ga.xml @@ -0,0 +1,6 @@ + + + UA-28724009-2 + true + true + \ No newline at end of file