-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMainActivity.java
132 lines (107 loc) · 4.65 KB
/
MainActivity.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package ru.tachos.admitadstatistic;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import java.util.Random;
import java.util.UUID;
import ru.tachos.admitadstatisticsdk.AdmitadEvent;
import ru.tachos.admitadstatisticsdk.AdmitadOrder;
import ru.tachos.admitadstatisticsdk.AdmitadTracker;
import ru.tachos.admitadstatisticsdk.AdmitadTrackerCode;
import ru.tachos.admitadstatisticsdk.TrackerInitializationCallback;
import ru.tachos.admitadstatisticsdk.TrackerListener;
public class MainActivity extends AppCompatActivity implements TrackerListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdmitadTracker.setLogEnabled(true);
AdmitadTracker.initialize(getApplicationContext(), "TestAndroidPostback", new TrackerInitializationCallback() {
@Override
public void onInitializationSuccess() {
}
@Override
public void onInitializationFailed(Exception exception) {
}
});
AdmitadTracker.getInstance().addListener(this);
onNewIntent(getIntent());
logConsole("Current admitad_uid: " + AdmitadTracker.getInstance().getAdmitadUid());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
if (intent.getData() != null) {
AdmitadTracker.getInstance().handleDeeplink(intent.getData());
}
}
@Override
public void onSuccess(AdmitadEvent result) {
logConsole("Event send successfully + " + result);
}
@Override
public void onFailure(int errorCode, @Nullable String errorText) {
logConsole("Event failed to send, code = " + errorCode + ",msg: " + errorText);
}
public void registrationClick(View v) {
AdmitadTracker.getInstance().logRegistration("TestRegistrationUid");
}
public void orderClick(View v) {
Random r = new Random();
int order_id = r.nextInt(10000);
final AdmitadOrder order = new AdmitadOrder.Builder("id" + String.valueOf(order_id), "100.00")
.setCurrencyCode("RUB")
.putItem(new AdmitadOrder.Item("Item1", "ItemName1", 3))
.putItem(new AdmitadOrder.Item("Item2", "ItemName2", 5))
.setUserInfo(new AdmitadOrder.UserInfo().putExtra("Surname", "Kek").putExtra("Age", "10"))
.setPromocode("PROMO") // setting up promocode for order
.build();
AdmitadTracker.getInstance().logOrder(order, new TrackerListener() {
@Override
public void onSuccess(AdmitadEvent result) {
logConsole("Order event send successfully + " + result.toString());
}
@Override
public void onFailure(int errorCode, @Nullable String errorText) {
logConsole("Order event failed to send, code = " + errorCode + ",msg: " + errorText);
}
});
}
public void purchaseClick(View v) {
Random r = new Random();
int purchase_id = r.nextInt(10000);
final AdmitadOrder order = new AdmitadOrder.Builder("id" + String.valueOf(purchase_id), "1756.00")
.setCurrencyCode("USD")
.putItem(new AdmitadOrder.Item("Item1", "ItemName1", 7))
.putItem(new AdmitadOrder.Item("Item2", "ItemName2", 8))
.setUserInfo(new AdmitadOrder.UserInfo().putExtra("Name", "Keksel").putExtra("Age", "1430"))
.build();
AdmitadTracker.getInstance().logPurchase(order);
}
public void returnClick(View v) {
AdmitadTracker.getInstance().logUserReturn("TestReturnUserUid", 5);
}
public void loyaltyClick(View v) {
AdmitadTracker.getInstance().logUserLoyalty("TestUserLoyaltyUid", 10);
}
public void manyEventsQueue(View v) {
for (int i = 0; i < 100; i++) {
AdmitadTracker.getInstance().logRegistration("userRegistration" + i);
AdmitadTracker.getInstance().logUserLoyalty("userLoyalty" + i, i);
}
}
public void setupNewAdmitadUid(View v) {
AdmitadTracker.getInstance().handleDeeplink(Uri.parse("schema://host?uid=" + UUID.randomUUID()));
logConsole("Current admitad_uid: " + AdmitadTracker.getInstance().getAdmitadUid());
}
private void logConsole(String message) {
Log.d("MainActivity", message);
}
}