diff --git a/android-app-tests/android-app-tests.iml b/android-app-tests/android-app-tests.iml
index 3209f068..359e3483 100644
--- a/android-app-tests/android-app-tests.iml
+++ b/android-app-tests/android-app-tests.iml
@@ -74,43 +74,42 @@
+
+
-
-
+
-
-
+
-
-
-
+
+
-
-
-
+
+
-
+
-
-
+
+
+
\ No newline at end of file
diff --git a/android-app/android-app.iml b/android-app/android-app.iml
index 216195a7..3ad2eb52 100644
--- a/android-app/android-app.iml
+++ b/android-app/android-app.iml
@@ -69,12 +69,12 @@
-
+
-
-
-
-
+
+
+
+
@@ -84,7 +84,7 @@
-
+
@@ -102,9 +102,9 @@
+
-
@@ -112,29 +112,29 @@
-
-
+
+
+
-
-
-
+
+
-
+
\ No newline at end of file
diff --git a/android-app/build.gradle b/android-app/build.gradle
index e519eb6f..07cf4c32 100644
--- a/android-app/build.gradle
+++ b/android-app/build.gradle
@@ -56,8 +56,8 @@ dependencies {
compile 'org.solovyev:common-core:1.0.7'
compile 'org.solovyev:common-text:1.0.7'
compile 'org.solovyev:common-security:1.0.7'
- compile 'com.android.support:support-v4:22.1.1'
- compile 'com.android.support:appcompat-v7:22.1.1'
+ compile 'com.android.support:support-v4:22.2.0'
+ compile 'com.android.support:appcompat-v7:22.2.0'
compile('ch.acra:acra:4.5.0') {
exclude group: 'org.json'
}
@@ -71,10 +71,10 @@ dependencies {
exclude(module: 'xercesImpl')
}
compile 'org.solovyev.android:checkout:0.7.2@aar'
- compile 'org.solovyev.android:material:0.1.2@aar'
- compile 'com.google.android.gms:play-services-ads:7.3.0@aar'
- compile 'com.google.android.gms:play-services-base:7.3.0@aar'
- compile 'com.google.android.gms:play-services-analytics:7.3.0@aar'
+ compile 'org.solovyev.android:material:0.1.3@aar'
+ compile 'com.google.android.gms:play-services-ads:7.5.0@aar'
+ compile 'com.google.android.gms:play-services-base:7.5.0@aar'
+ compile 'com.google.android.gms:play-services-analytics:7.5.0@aar'
compile 'com.melnykov:floatingactionbutton:1.1.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AdView.java b/android-app/src/main/java/org/solovyev/android/calculator/AdView.java
index 2feb81c6..4b7732d5 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/AdView.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/AdView.java
@@ -5,15 +5,21 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
+
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
+import org.solovyev.android.Check;
+
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class AdView extends FrameLayout {
@Nullable
private com.google.android.gms.ads.AdView admobView;
+ @Nullable
+ private AdView.AdViewListener admobListener;
public AdView(Context context) {
super(context);
@@ -28,8 +34,18 @@ public class AdView extends FrameLayout {
}
public void destroy() {
+ destroyAdmobView();
+ }
+
+ private void destroyAdmobView() {
if (admobView != null) {
admobView.destroy();
+ admobView.setAdListener(null);
+ admobView = null;
+ }
+ if(admobListener != null) {
+ admobListener.destroy();
+ admobListener = null;
}
}
@@ -52,22 +68,13 @@ public class AdView extends FrameLayout {
LayoutInflater.from(getContext()).inflate(R.layout.admob, this);
admobView = (com.google.android.gms.ads.AdView) findViewById(R.id.admob);
- if (admobView == null) throw new AssertionError();
+ Check.isNotNull(admobView);
+ if (admobView == null) {
+ return;
+ }
- admobView.setAdListener(new AdListener() {
- @Override
- public void onAdFailedToLoad(int errorCode) {
- hide();
- }
-
- @Override
- public void onAdLoaded() {
- if (admobView != null) {
- admobView.setVisibility(View.VISIBLE);
- }
- setVisibility(VISIBLE);
- }
- });
+ admobListener = new AdView.AdViewListener(this);
+ admobView.setAdListener(admobListener);
final AdRequest.Builder b = new AdRequest.Builder();
b.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
@@ -87,7 +94,40 @@ public class AdView extends FrameLayout {
admobView.setVisibility(View.GONE);
admobView.pause();
- admobView.destroy();
- admobView = null;
+ destroyAdmobView();
+ }
+
+ private static class AdViewListener extends AdListener {
+
+ @Nullable
+ private AdView adView;
+
+ public AdViewListener(@Nonnull AdView adView) {
+ this.adView = adView;
+ }
+
+ void destroy() {
+ adView = null;
+ }
+
+ @Override
+ public void onAdFailedToLoad(int errorCode) {
+ if (adView != null) {
+ adView.hide();
+ adView = null;
+ }
+ }
+
+ @Override
+ public void onAdLoaded() {
+ if (adView != null) {
+ final com.google.android.gms.ads.AdView admobView = adView.admobView;
+ if (admobView != null) {
+ admobView.setVisibility(View.VISIBLE);
+ }
+ adView.setVisibility(VISIBLE);
+ adView = null;
+ }
+ }
}
}
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 229662d2..ee30cf2c 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 Fragment {
@Nonnull
- private FragmentUi fragmentHelper;
+ private FragmentUi fragmentUi;
@Nonnull
private AndroidCalculatorDisplayView displayView;
@@ -52,17 +52,17 @@ public class CalculatorDisplayFragment extends Fragment {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs);
if (!layout.isOptimized()) {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display_mobile, R.string.result);
+ fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display_mobile, R.string.result);
} else {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display, R.string.result);
+ fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display, R.string.result);
}
- fragmentHelper.onCreate(this);
+ fragmentUi.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return fragmentHelper.onCreateView(this, inflater, container);
+ return fragmentUi.onCreateView(this, inflater, container);
}
@Override
@@ -73,7 +73,7 @@ public class CalculatorDisplayFragment extends Fragment {
displayView.init(getActivity());
Locator.getInstance().getDisplay().setView(displayView);
- fragmentHelper.onViewCreated(this, root);
+ fragmentUi.onViewCreated(this, root);
}
@Override
@@ -85,12 +85,12 @@ public class CalculatorDisplayFragment extends Fragment {
public void onResume() {
super.onResume();
- fragmentHelper.onResume(this);
+ fragmentUi.onResume(this);
}
@Override
public void onPause() {
- fragmentHelper.onPause(this);
+ fragmentUi.onPause(this);
super.onPause();
}
@@ -98,12 +98,13 @@ public class CalculatorDisplayFragment extends Fragment {
@Override
public void onDestroyView() {
Locator.getInstance().getDisplay().clearView(displayView);
+ fragmentUi.onDestroyView(this);
super.onDestroyView();
}
@Override
public void onDestroy() {
- fragmentHelper.onDestroy(this);
+ fragmentUi.onDestroy(this);
super.onDestroy();
}
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 19aaae4a..91638ab8 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
@@ -105,6 +105,7 @@ public class CalculatorEditorFragment extends Fragment {
@Override
public void onDestroyView() {
Locator.getInstance().getEditor().clearView(editorView);
+ fragmentUi.onDestroyView(this);
super.onDestroyView();
}
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 f969cb7b..06e0b095 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,18 +40,18 @@ import javax.annotation.Nonnull;
public abstract class CalculatorFragment extends Fragment {
@Nonnull
- private final FragmentUi fragmentHelper;
+ private final FragmentUi fragmentUi;
protected CalculatorFragment(int layoutResId, int titleResId) {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
+ fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
}
protected CalculatorFragment(@Nonnull CalculatorFragmentType fragmentType) {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
+ fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
}
- protected CalculatorFragment(@Nonnull FragmentUi fragmentHelper) {
- this.fragmentHelper = fragmentHelper;
+ protected CalculatorFragment(@Nonnull FragmentUi fragmentUi) {
+ this.fragmentUi = fragmentUi;
}
@Override
@@ -63,43 +63,44 @@ public abstract class CalculatorFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- fragmentHelper.onCreate(this);
+ fragmentUi.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return fragmentHelper.onCreateView(this, inflater, container);
+ return fragmentUi.onCreateView(this, inflater, container);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- fragmentHelper.onViewCreated(this, view);
+ fragmentUi.onViewCreated(this, view);
}
@Override
public void onResume() {
super.onResume();
- this.fragmentHelper.onResume(this);
+ this.fragmentUi.onResume(this);
}
@Override
public void onPause() {
- this.fragmentHelper.onPause(this);
+ this.fragmentUi.onPause(this);
super.onPause();
}
@Override
public void onDestroyView() {
+ fragmentUi.onDestroyView(this);
super.onDestroyView();
}
@Override
public void onDestroy() {
- fragmentHelper.onDestroy(this);
+ fragmentUi.onDestroy(this);
super.onDestroy();
}
@@ -109,6 +110,6 @@ public abstract class CalculatorFragment extends Fragment {
}
public boolean isPaneFragment() {
- return fragmentHelper.isPane(this);
+ return fragmentUi.isPane(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 4bd5323f..fb7d2f42 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
@@ -89,6 +89,12 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
super.onPause();
}
+ @Override
+ public void onDestroyView() {
+ ui.onDestroyView(this);
+ super.onDestroyView();
+ }
+
@Override
public void onDestroy() {
super.onDestroy();
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 37e06cea..0bd9a3f9 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,18 +40,18 @@ import javax.annotation.Nonnull;
public abstract class CalculatorListFragment extends ListFragment {
@Nonnull
- private final FragmentUi fragmentHelper;
+ private final FragmentUi ui;
protected CalculatorListFragment(int layoutResId, int titleResId) {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
+ ui = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
}
protected CalculatorListFragment(@Nonnull CalculatorFragmentType fragmentType) {
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
+ ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
}
- protected CalculatorListFragment(@Nonnull FragmentUi fragmentHelper) {
- this.fragmentHelper = fragmentHelper;
+ protected CalculatorListFragment(@Nonnull FragmentUi ui) {
+ this.ui = ui;
}
@Override
@@ -63,43 +63,42 @@ public abstract class CalculatorListFragment extends ListFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- fragmentHelper.onCreate(this);
+ ui.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return fragmentHelper.onCreateView(this, inflater, container);
+ return ui.onCreateView(this, inflater, container);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- fragmentHelper.onViewCreated(this, view);
+ ui.onViewCreated(this, view);
}
@Override
public void onResume() {
super.onResume();
-
- this.fragmentHelper.onResume(this);
+ this.ui.onResume(this);
}
@Override
public void onPause() {
- this.fragmentHelper.onPause(this);
-
+ this.ui.onPause(this);
super.onPause();
}
@Override
public void onDestroyView() {
+ ui.onDestroyView(this);
super.onDestroyView();
}
@Override
public void onDestroy() {
- fragmentHelper.onDestroy(this);
+ ui.onDestroy(this);
super.onDestroy();
}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java
index 8fd3cfc0..ce1abb46 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java
@@ -27,15 +27,18 @@ import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.widget.TextView;
+
import org.solovyev.android.checkout.ActivityCheckout;
import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.Inventory;
import org.solovyev.android.checkout.ProductTypes;
+import java.util.Locale;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Locale;
/**
* User: serso
@@ -169,11 +172,6 @@ public class FragmentUi extends BaseUi {
}
public void onDestroy(@Nonnull Fragment fragment) {
- if (adView != null) {
- adView.destroy();
- adView = null;
- }
-
if (listenersOnCreate) {
if (fragment instanceof CalculatorEventListener) {
Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
@@ -189,4 +187,11 @@ public class FragmentUi extends BaseUi {
public View onCreateView(@Nonnull Fragment fragment, @Nonnull LayoutInflater inflater, @Nullable ViewGroup container) {
return inflater.inflate(layoutId, container, false);
}
+
+ public void onDestroyView(@Nonnull Fragment fragment) {
+ if (adView != null) {
+ adView.destroy();
+ adView = null;
+ }
+ }
}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
index fc0ffee9..6e1fb990 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
@@ -32,15 +32,36 @@ import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.util.Log;
-import android.view.*;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
+
import com.melnykov.fab.FloatingActionButton;
-import org.solovyev.android.calculator.*;
+
+import org.solovyev.android.calculator.App;
+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.CalculatorFragmentType;
+import org.solovyev.android.calculator.FragmentUi;
+import org.solovyev.android.calculator.Locator;
+import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.jscl.JsclOperation;
-import org.solovyev.android.menu.*;
+import org.solovyev.android.menu.AMenuItem;
+import org.solovyev.android.menu.ActivityMenu;
+import org.solovyev.android.menu.AndroidMenuHelper;
+import org.solovyev.android.menu.ContextMenuBuilder;
+import org.solovyev.android.menu.IdentifiableMenuItem;
+import org.solovyev.android.menu.ListActivityMenu;
+import org.solovyev.android.menu.ListContextMenu;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.Collections;
import org.solovyev.common.equals.Equalizer;
@@ -48,12 +69,13 @@ import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRulesChain;
import org.solovyev.common.text.Strings;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested;
public abstract class BaseHistoryFragment extends ListFragment implements CalculatorEventListener {
@@ -97,7 +119,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
private HistoryArrayAdapter adapter;
@Nonnull
- private FragmentUi fragmentHelper;
+ private FragmentUi ui;
private final ActivityMenu