Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BaseActivityDelegate.java « base « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70b9b5685fa3f7e404803ef047120567d9a2008e (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
103
104
105
106
107
108
109
110
111
112
113
114
package com.mapswithme.maps.base;

import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.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.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.Statistics;

public class BaseActivityDelegate
{
  private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
  private static final String TAG = BaseActivityDelegate.class.getSimpleName();
  @NonNull
  private final BaseActivity mActivity;
  @Nullable
  private String mThemeName;

  public BaseActivityDelegate(@NonNull BaseActivity activity)
  {
    mActivity = activity;
  }

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

  public void onSafeCreate()
  {
    logLifecycleMethod("onSafeCreate()");
  }

  public void onSafeDestroy()
  {
    logLifecycleMethod("onSafeDestroy()");
  }

  public void onDestroy()
  {
    logLifecycleMethod("onDestroy()");
    ViewServer.get(mActivity.get()).removeWindow(mActivity.get());
  }

  public void onPostCreate()
  {
    logLifecycleMethod("onPostCreate()");
    ViewServer.get(mActivity.get()).addWindow(mActivity.get());
  }

  public void onStart()
  {
    logLifecycleMethod("onStart()");
    Statistics.INSTANCE.startActivity(mActivity.get());
  }

  public void onStop()
  {
    logLifecycleMethod("onStop()");
    Statistics.INSTANCE.stopActivity(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());
  }

  public 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)
  {
    String msg = mActivity.getClass().getSimpleName() + ": " + method + " activity: " + mActivity;
    CrashlyticsUtils.log(Log.INFO, TAG, msg);
    LOGGER.i(TAG, msg);
  }
}