blob: b5a11ed0336948edaa005204e83cfb988a8b71a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package com.mapswithme.maps.base;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import com.mapswithme.util.Config;
import com.mapswithme.util.CrashlyticsUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.ViewServer;
import com.mapswithme.util.concurrency.UiThread;
import com.mapswithme.util.statistics.Statistics;
import com.my.tracker.MyTracker;
class BaseActivityDelegate
{
private static final String TAG = BaseActivityDelegate.class.getSimpleName();
@NonNull
private final BaseActivity mActivity;
@Nullable
private String mThemeName;
BaseActivityDelegate(@NonNull BaseActivity activity)
{
mActivity = activity;
}
void onNewIntent(@NonNull Intent intent)
{
logLifecycleMethod("onNewIntent(" + intent + ")");
}
public void onCreate()
{
logLifecycleMethod("onCreate()");
mThemeName = Config.getCurrentUiTheme();
if (!TextUtils.isEmpty(mThemeName))
mActivity.get().setTheme(mActivity.getThemeResourceId(mThemeName));
}
void onDestroy()
{
logLifecycleMethod("onDestroy()");
ViewServer.get(mActivity.get()).removeWindow(mActivity.get());
}
void onPostCreate()
{
logLifecycleMethod("onPostCreate()");
ViewServer.get(mActivity.get()).addWindow(mActivity.get());
}
void onStart()
{
logLifecycleMethod("onStart()");
Statistics.INSTANCE.startActivity(mActivity.get());
MyTracker.onStartActivity(mActivity.get());
}
void onStop()
{
logLifecycleMethod("onStop()");
Statistics.INSTANCE.stopActivity(mActivity.get());
MyTracker.onStopActivity(mActivity.get());
}
public void onResume()
{
logLifecycleMethod("onResume()");
org.alohalytics.Statistics.logEvent("$onResume", mActivity.getClass().getSimpleName() + ":" +
UiUtils.deviceOrientationAsString(mActivity.get()));
ViewServer.get(mActivity.get()).setFocusedWindow(mActivity.get());
}
public void onPause()
{
logLifecycleMethod("onPause()");
org.alohalytics.Statistics.logEvent("$onPause", mActivity.getClass().getSimpleName());
}
void onPostResume()
{
logLifecycleMethod("onPostResume()");
if (!TextUtils.isEmpty(mThemeName) && mThemeName.equals(Config.getCurrentUiTheme()))
return;
// Workaround described in https://code.google.com/p/android/issues/detail?id=93731
UiThread.runLater(new Runnable() {
@Override
public void run() {
mActivity.get().recreate();
}
});
}
private void logLifecycleMethod(@NonNull String method)
{
CrashlyticsUtils.log(Log.INFO, TAG, mActivity.getClass().getSimpleName() + ": " + method);
}
}
|