Postpone GA initialization

This commit is contained in:
Sergey Solovyev 2017-05-25 16:15:55 +02:00
parent ef4ca97e2e
commit b6945f17e7
3 changed files with 42 additions and 25 deletions

View File

@ -1,5 +1,11 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Preferences.Gui.keepScreenOn;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
@ -12,10 +18,13 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.*; import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
@ -27,11 +36,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import butterknife.Bind;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import butterknife.ButterKnife;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; import dagger.Lazy;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Preferences.Gui.keepScreenOn;
public abstract class BaseActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public abstract class BaseActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -48,7 +55,7 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
@Inject @Inject
Calculator calculator; Calculator calculator;
@Inject @Inject
Ga ga; Lazy<Ga> ga;
@Inject @Inject
Typeface typeface; Typeface typeface;
@Bind(R.id.main) @Bind(R.id.main)
@ -78,11 +85,11 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
} }
public void reportActivityStop(@Nonnull Activity activity) { public void reportActivityStop(@Nonnull Activity activity) {
ga.getAnalytics().reportActivityStop(activity); ga.get().getAnalytics().reportActivityStop(activity);
} }
public void reportActivityStart(@Nonnull Activity activity) { public void reportActivityStart(@Nonnull Activity activity) {
ga.getAnalytics().reportActivityStart(activity); ga.get().getAnalytics().reportActivityStart(activity);
} }
public static void setFont(@Nonnull View view, @Nonnull Typeface newTypeface) { public static void setFont(@Nonnull View view, @Nonnull Typeface newTypeface) {

View File

@ -28,8 +28,9 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import android.util.TimingLogger; import android.util.TimingLogger;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import jscl.MathEngine;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ACRAConfiguration; import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender; import org.acra.sender.HttpSender;
@ -39,11 +40,15 @@ import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import java.util.Locale;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.util.Locale;
import java.util.concurrent.Executor; import dagger.Lazy;
import jscl.MathEngine;
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -91,7 +96,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
ActivityLauncher launcher; ActivityLauncher launcher;
@Inject @Inject
Ga ga; Lazy<Ga> ga;
@Nonnull @Nonnull
private final TimingLogger timer = new TimingLogger("App", "onCreate"); private final TimingLogger timer = new TimingLogger("App", "onCreate");
@ -127,13 +132,12 @@ public class CalculatorApplication extends android.app.Application implements Sh
history.init(initThread); history.init(initThread);
} }
private void onPostCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) { private void onPostCreate(@Nonnull final SharedPreferences preferences, @Nonnull Languages languages) {
App.init(this); App.init(this);
languages.init(); languages.init();
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
languages.updateContextLocale(this, true); languages.updateContextLocale(this, true);
ga.reportInitially(preferences);
calculator.init(initThread); calculator.init(initThread);
@ -141,6 +145,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Override @Override
public void run() { public void run() {
warmUpEngine(); warmUpEngine();
// delayed GA reporting in order to avoid initialization of GA on the main
// application thread and to postpone it as much as possible
ga.get().reportInitially(preferences);
} }
}); });
} }

View File

@ -22,17 +22,17 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.Spannable; import android.text.Spannable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import dagger.Lazy;
import jscl.NumeralBase;
import jscl.math.Expression;
import jscl.math.Generic;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.ga.Ga;
@ -46,7 +46,10 @@ import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; import dagger.Lazy;
import jscl.NumeralBase;
import jscl.math.Expression;
import jscl.math.Generic;
@Singleton @Singleton
public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListener { public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -67,7 +70,7 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
@Inject @Inject
Engine engine; Engine engine;
@Inject @Inject
Ga ga; Lazy<Ga> ga;
@Inject @Inject
Lazy<Clipboard> clipboard; Lazy<Clipboard> clipboard;
@Inject @Inject
@ -109,13 +112,13 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
final char glyph = text.charAt(0); final char glyph = text.charAt(0);
final CppSpecialButton button = CppSpecialButton.getByGlyph(glyph); final CppSpecialButton button = CppSpecialButton.getByGlyph(glyph);
if (button != null) { if (button != null) {
ga.onButtonPressed(button.action); ga.get().onButtonPressed(button.action);
handleSpecialAction(button); handleSpecialAction(button);
return true; return true;
} }
} }
ga.onButtonPressed(text); ga.get().onButtonPressed(text);
if (!processSpecialAction(text)) { if (!processSpecialAction(text)) {
processText(prepareText(text)); processText(prepareText(text));
} }