GA integration + Base activity

This commit is contained in:
serso 2015-01-26 12:38:45 +01:00
parent c30645e5c7
commit d23f8e2c40
30 changed files with 899 additions and 1150 deletions

View File

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="file://$PROJECT_DIR$/android-app-core-tests/build.gradle" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/android-app-core/src/main/java/org/solovyev/android/calculator/App.java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/android-app-core/src/main/java/org/solovyev/android/calculator/ServiceLocator.java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/android-app-tests/build.gradle" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/android-app-tests/src/test/java/org/solovyev/android/CalculatorTestRunner.java" charset="UTF-8" />
</component>
</project>

View File

@ -45,12 +45,7 @@ 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 {
public class ActivityUi extends BaseUi {
/*
**********************************************************************
@ -80,18 +75,18 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
private int selectedNavigationIndex = 0;
public CalculatorActivityHelperImpl(int layoutId, @Nonnull String logTag) {
public ActivityUi(int layoutId, @Nonnull String logTag) {
super(logTag);
this.layoutId = layoutId;
}
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
public ActivityUi(int layoutId, boolean homeIcon) {
this.layoutId = layoutId;
this.homeIcon = homeIcon;
}
@Override
public void onCreate(@Nonnull Activity activity, @Nullable Bundle savedInstanceState) {
public void onCreate(@Nonnull Activity activity) {
super.onCreate(activity);
if (activity instanceof CalculatorEventListener) {
@ -112,13 +107,12 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
processButtons(activity, root);
addHelpInfo(activity, root);
} else {
Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
Log.e(ActivityUi.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);
public void onCreate(@Nonnull final SherlockFragmentActivity activity) {
onCreate((Activity)activity);
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false);
@ -153,16 +147,13 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
@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);
@ -172,11 +163,9 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
@Override
public void onPause(@Nonnull Activity activity) {
}
@Override
public void onPause(@Nonnull SherlockFragmentActivity activity) {
onPause((Activity) activity);
@ -204,12 +193,10 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
@Override
public void onDestroy(@Nonnull SherlockFragmentActivity activity) {
this.onDestroy((Activity) activity);
}
@Override
public void addTab(@Nonnull SherlockFragmentActivity activity,
@Nonnull String tag,
@Nonnull Class<? extends Fragment> fragmentClass,
@ -227,12 +214,10 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
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();
@ -252,7 +237,6 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
@Override
public void selectTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType) {
final ActionBar actionBar = activity.getSupportActionBar();
for (int i = 0; i < actionBar.getTabCount(); i++) {
@ -264,24 +248,20 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
@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);
@ -346,4 +326,12 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
}
}
}
public void onStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity);
}
public void onStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity);
}
}

View File

@ -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 <L> real type of service locator
* @return instance of service locator user in application
*/
@Nonnull
public static <L extends ServiceLocator> 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;
}
}

View File

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

View File

@ -62,7 +62,7 @@ import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Pref
* Date: 9/28/12
* Time: 12:12 AM
*/
public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
private static final List<Integer> viewIds = new ArrayList<Integer>(200);
@ -88,10 +88,10 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@Nullable
private NumeralBasesButton clearButton;
protected AbstractCalculatorHelper() {
protected BaseUi() {
}
protected AbstractCalculatorHelper(@Nonnull String logTag) {
protected BaseUi(@Nonnull String logTag) {
this.logTag = logTag;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, SherlockMenuHelper.getInstance());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
/**
* 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() {
this(R.layout.main_empty);
}
protected EmptyActivity(int layoutResId) {
super(layoutResId);
}
}

View File

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

View File

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

View File

@ -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<JEventListener<? extends JEvent>, 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;
}
}

View File

@ -108,7 +108,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
private HistoryArrayAdapter adapter;
@Nonnull
private CalculatorFragmentHelper fragmentHelper;
private FragmentUi fragmentHelper;
private final ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, SherlockMenuHelper.getInstance(), new HistoryMenuFilter());

View File

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

View File

@ -99,7 +99,7 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
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);
}
}
});

View File

@ -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<T extends MathEntity> exten
private String category;
@Nonnull
private final CalculatorFragmentHelper fragmentHelper;
private final FragmentUi fragmentHelper;
@Nonnull
private final Handler uiHandler = new Handler();

View File

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

View File

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

View File

@ -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,41 +65,11 @@ 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

View File

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

View File

@ -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<T extends MathPersistenceEntity> 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) {

View File

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

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId">UA-28724009-2</string>
<bool name="ga_reportUncaughtExceptions">true</bool>
<bool name="ga_autoActivityTracking">true</bool>
</resources>