Skip to content

Commit

Permalink
Merge pull request #45 from velocidi/add-annotation-companion-object
Browse files Browse the repository at this point in the history
  • Loading branch information
duartepinto authored Apr 27, 2021
2 parents 006e2ad + 990d718 commit 38e38f9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
17 changes: 9 additions & 8 deletions velocidi-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.velocidi.sampleapp">
package="com.velocidi.sampleapp">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".SampleApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".SampleApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:usesCleartextTraffic="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".JavaActivity"></activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.velocidi.sampleapp;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import com.velocidi.Channel;
import com.velocidi.Config;
import com.velocidi.Velocidi;
import com.velocidi.UserId;

import org.json.JSONObject;

import java.util.Arrays;

public class JavaActivity extends AppCompatActivity {
private static final String TAG = "MyActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Channel trackEndpoint = new Channel(Uri.parse("http://tr.cdp.velocidi.com/events"), true);
Channel matchEndpoint = new Channel(Uri.parse("http://match.cdp.velocidi.com/match"), true);
Config config = new Config(trackEndpoint, matchEndpoint);

Velocidi.init(config, this);

try {
JSONObject eventJsonObj = new JSONObject();
eventJsonObj.put("clientId", "velocidi");
eventJsonObj.put("siteId", "velocidi.com");
eventJsonObj.put("type", "appView");

Velocidi.getInstance().track(
new UserId("user_email_hash", "email_sha256"),
eventJsonObj
);

} catch (Exception e) {
Log.d(TAG, "Error sending tracking event");
}


Velocidi.getInstance().match(
"someProvider",
Arrays.asList(
new UserId("user_email_hash", "email_sha256"),
new UserId("user_advertising_id", "gaid")
)
);
}
}
3 changes: 3 additions & 0 deletions velocidi-sdk/src/main/kotlin/com/velocidi/Velocidi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ open class Velocidi internal constructor(val config: Config, context: Context) {

companion object {
// Singleton instance of the sdk
@JvmSynthetic
internal lateinit var instance: Velocidi

/**
Expand All @@ -126,6 +127,7 @@ open class Velocidi internal constructor(val config: Config, context: Context) {
* @param context Android application context
* @return Velocidi instance
*/
@JvmStatic
fun init(config: Config, context: Context): Velocidi {
if (!Util.checkPermission(context, Manifest.permission.INTERNET)) {
throw SecurityException("Velocidi SDK requires Internet permission")
Expand All @@ -143,6 +145,7 @@ open class Velocidi internal constructor(val config: Config, context: Context) {
*
* @return The Velocidi instance
*/
@JvmStatic
fun getInstance(): Velocidi =
when (::instance.isInitialized) {
true -> instance
Expand Down

0 comments on commit 38e38f9

Please sign in to comment.