-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ❇️ added android support using middleware-android as upstream
- Loading branch information
Showing
23 changed files
with
1,400 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
</manifest> |
64 changes: 64 additions & 0 deletions
64
android/src/main/java/com/middlewarereactnative/ActivityCallbacks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.middlewarereactnative; | ||
|
||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class ActivityCallbacks implements Application.ActivityLifecycleCallbacks { | ||
private boolean isRegisteredForLifecycleCallbacks; | ||
|
||
public void registerActivityLifecycleCallbacks(Context context) { | ||
// Make sure the callback is registered only once. | ||
if (isRegisteredForLifecycleCallbacks) { | ||
return; | ||
} | ||
Context appContext = context.getApplicationContext(); | ||
if (appContext instanceof Application) { | ||
((Application) appContext).registerActivityLifecycleCallbacks(this); | ||
isRegisteredForLifecycleCallbacks = true; | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { | ||
boolean isColdStart = savedInstanceState == null; | ||
Log.d("MiddlewareReactNative", "onActivityCreated: " + isColdStart); | ||
AppStartTracker.getInstance().setColdStart(isColdStart); | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityResumed(@NonNull Activity activity) { | ||
String simpleName = activity.getClass().getSimpleName(); | ||
Log.d("MiddlewareReactNative", "onActivityResumed: " + simpleName); | ||
} | ||
|
||
@Override | ||
public void onActivityPaused(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityStopped(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(@NonNull Activity activity) { | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
android/src/main/java/com/middlewarereactnative/AppStartTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.middlewarereactnative; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class AppStartTracker { | ||
private static final @NotNull AppStartTracker instance = new AppStartTracker(); | ||
|
||
private boolean isColdStart = false; | ||
|
||
public static @NotNull AppStartTracker getInstance() { | ||
return instance; | ||
} | ||
|
||
public boolean isColdStart() { | ||
return isColdStart; | ||
} | ||
|
||
public void setColdStart(boolean coldStart) { | ||
isColdStart = coldStart; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
android/src/main/java/com/middlewarereactnative/ConfigMapReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.middlewarereactnative; | ||
|
||
import com.facebook.react.bridge.ReadableMap; | ||
|
||
public class ConfigMapReader extends MapReader { | ||
private final ReadableMap map; | ||
|
||
public ConfigMapReader(ReadableMap map) { | ||
this.map = map; | ||
} | ||
|
||
public String getTarget() { | ||
return Keys.TARGET.get(map); | ||
} | ||
|
||
public String getAccountKey() { | ||
return Keys.ACCOUNT_KEY.get(map); | ||
} | ||
|
||
|
||
public String getProjectName() { | ||
return Keys.PROJECT_NAME.get(map); | ||
} | ||
|
||
public String getServiceName() { | ||
return Keys.SERVICE_NAME.get(map); | ||
} | ||
|
||
public String getDeploymentEnvironment() { | ||
return Keys.DEPLOYMENT_ENVIRONMENT.get(map); | ||
} | ||
|
||
public ReadableMap getGlobalAttributes() { | ||
return Keys.GLOBAL_ATTRIBUTES.getMap(map); | ||
} | ||
|
||
private interface Keys { | ||
StringKey TARGET = new StringKey("target"); | ||
StringKey ACCOUNT_KEY = new StringKey("accountKey"); | ||
StringKey PROJECT_NAME = new StringKey("projectName"); | ||
StringKey SERVICE_NAME = new StringKey("serviceName"); | ||
StringKey DEPLOYMENT_ENVIRONMENT = new StringKey("deploymentEnvironment"); | ||
MapKey GLOBAL_ATTRIBUTES = new MapKey("globalAttributes"); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
android/src/main/java/com/middlewarereactnative/MapReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.middlewarereactnative; | ||
|
||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.ReadableType; | ||
|
||
public abstract class MapReader { | ||
protected static class StringKey { | ||
private final String key; | ||
|
||
public StringKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String get(ReadableMap map) { | ||
if (map.hasKey(key) && map.getType(key) == ReadableType.String) { | ||
return map.getString(key); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
protected static class BooleanKey { | ||
private final String key; | ||
|
||
public BooleanKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public Boolean get(ReadableMap map) { | ||
if (map.hasKey(key) && map.getType(key) == ReadableType.Boolean) { | ||
return map.getBoolean(key); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
protected static class NumberKey { | ||
private final String key; | ||
|
||
public NumberKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public Long getLong(ReadableMap map) { | ||
if (map.hasKey(key) && map.getType(key) == ReadableType.Number) { | ||
return (long) map.getDouble(key); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
protected static class MapKey { | ||
private final String key; | ||
|
||
public MapKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public ReadableMap getMap(ReadableMap map) { | ||
if (map.hasKey(key) && map.getType(key) == ReadableType.Map) { | ||
return map.getMap(key); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
android/src/main/java/com/middlewarereactnative/MiddlewarePreferenceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.middlewarereactnative; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class MiddlewarePreferenceProvider extends ContentProvider { | ||
|
||
private static final long appStartTime = System.currentTimeMillis(); | ||
|
||
public static long getAppStartTime() { | ||
return appStartTime; | ||
} | ||
|
||
@Override | ||
public boolean onCreate() { | ||
Log.d("MiddlewareReactNative", "perfProvider onCreate: " + appStartTime); | ||
|
||
ActivityCallbacks activityCallbacks = new ActivityCallbacks(); | ||
activityCallbacks.registerActivityLifecycleCallbacks(getContext()); | ||
|
||
//TODO deregister callbacks? | ||
return false; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getType(@NonNull Uri uri) { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.