Postpone GA initialization
This commit is contained in:
parent
ef4ca97e2e
commit
b6945f17e7
@ -1,5 +1,11 @@
|
||||
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.content.SharedPreferences;
|
||||
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.AppCompatActivity;
|
||||
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 butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.ga.Ga;
|
||||
import org.solovyev.android.calculator.language.Language;
|
||||
@ -27,11 +36,9 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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 butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import dagger.Lazy;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@ -48,7 +55,7 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
|
||||
@Inject
|
||||
Calculator calculator;
|
||||
@Inject
|
||||
Ga ga;
|
||||
Lazy<Ga> ga;
|
||||
@Inject
|
||||
Typeface typeface;
|
||||
@Bind(R.id.main)
|
||||
@ -78,11 +85,11 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
|
||||
}
|
||||
|
||||
public void reportActivityStop(@Nonnull Activity activity) {
|
||||
ga.getAnalytics().reportActivityStop(activity);
|
||||
ga.get().getAnalytics().reportActivityStop(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) {
|
||||
|
@ -28,8 +28,9 @@ import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.util.TimingLogger;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
import jscl.MathEngine;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ACRAConfiguration;
|
||||
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.Languages;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
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 {
|
||||
|
||||
@ -91,7 +96,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
ActivityLauncher launcher;
|
||||
|
||||
@Inject
|
||||
Ga ga;
|
||||
Lazy<Ga> ga;
|
||||
|
||||
@Nonnull
|
||||
private final TimingLogger timer = new TimingLogger("App", "onCreate");
|
||||
@ -127,13 +132,12 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
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);
|
||||
languages.init();
|
||||
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
languages.updateContextLocale(this, true);
|
||||
ga.reportInitially(preferences);
|
||||
|
||||
calculator.init(initThread);
|
||||
|
||||
@ -141,6 +145,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
@Override
|
||||
public void run() {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -22,17 +22,17 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
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.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.ga.Ga;
|
||||
@ -46,7 +46,10 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
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
|
||||
public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@ -67,7 +70,7 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||
@Inject
|
||||
Engine engine;
|
||||
@Inject
|
||||
Ga ga;
|
||||
Lazy<Ga> ga;
|
||||
@Inject
|
||||
Lazy<Clipboard> clipboard;
|
||||
@Inject
|
||||
@ -109,13 +112,13 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||
final char glyph = text.charAt(0);
|
||||
final CppSpecialButton button = CppSpecialButton.getByGlyph(glyph);
|
||||
if (button != null) {
|
||||
ga.onButtonPressed(button.action);
|
||||
ga.get().onButtonPressed(button.action);
|
||||
handleSpecialAction(button);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ga.onButtonPressed(text);
|
||||
ga.get().onButtonPressed(text);
|
||||
if (!processSpecialAction(text)) {
|
||||
processText(prepareText(text));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user