30
30
import android .app .Activity ;
31
31
import android .app .NotificationManager ;
32
32
import android .content .Context ;
33
- import android .content .SharedPreferences ;
34
33
import android .os .AsyncTask ;
35
34
import android .os .Bundle ;
35
+ import android .os .Handler ;
36
36
import android .os .Looper ;
37
37
import android .util .Log ;
38
38
import android .view .Menu ;
42
42
import android .widget .CheckBox ;
43
43
import android .widget .CompoundButton ;
44
44
import android .widget .TextView ;
45
- import android .os .Handler ;
46
45
import android .widget .Toast ;
47
46
48
47
import com .onesignal .OneSignal .NotificationOpenedHandler ;
49
-
50
48
import com .onesignal .example .OneSignalExampleApp ;
51
49
import com .onesignal .example .R ;
52
50
import com .onesignal .example .iap .IabHelper ;
@@ -65,16 +63,21 @@ public class MainActivity extends Activity implements OSEmailSubscriptionObserve
65
63
R .id .unsubscribe ,
66
64
R .id .sendTags ,
67
65
R .id .getTags ,
68
- R .id .setEmail ,
66
+ R .id .sendEvent ,
69
67
R .id .postNotification ,
70
68
R .id .postNotificationAsync ,
71
69
R .id .postNotificationGroupCheckBox ,
72
70
R .id .postNotificationAsyncGroupCheckBox };
73
71
74
72
private TextView debugTextView ;
75
73
private TextView emailTextView ;
74
+ private TextView outcomeName ;
75
+ private TextView outcomeValueName ;
76
+ private TextView outcomeValue ;
77
+ private TextView outcomeUnique ;
76
78
private Button consentButton ;
77
79
private Button setEmailButton ;
80
+ private Button sendEvent ;
78
81
private Button logoutEmailButton ;
79
82
private Button postNotifButton ;
80
83
private Button postNotifAsyncButton ;
@@ -86,7 +89,6 @@ public class MainActivity extends Activity implements OSEmailSubscriptionObserve
86
89
private TextView iamHost ;
87
90
private TextView triggerKeyTextView ;
88
91
private TextView triggerValueTextView ;
89
- private String SHARDPRES_KEY_IAM_HOST = "SHARDPRES_KEY_IAM_HOST" ;
90
92
91
93
@ Override
92
94
public boolean onCreateOptionsMenu (Menu menu ) {
@@ -115,15 +117,21 @@ protected void onCreate(Bundle savedInstanceState) {
115
117
setContentView (com .onesignal .example .R .layout .activity_main );
116
118
117
119
this .consentButton = this .findViewById (R .id .consentButton );
118
- this .setEmailButton = this .findViewById (R .id .setEmail );
119
120
this .logoutEmailButton = this .findViewById (R .id .logoutEmail );
120
121
this .postNotifButton = this .findViewById (R .id .postNotification );
121
122
this .postNotifAsyncButton = this .findViewById (R .id .postNotificationAsync );
122
123
this .postNotifGroupCheckBox = this .findViewById (R .id .postNotificationGroupCheckBox );
123
124
this .postNotifAsyncGroupCheckBox = this .findViewById (R .id .postNotificationAsyncGroupCheckBox );
125
+ this .consentButton = (Button )this .findViewById (com .onesignal .example .R .id .consentButton );
126
+ this .logoutEmailButton = (Button )this .findViewById (com .onesignal .example .R .id .logoutEmail );
127
+ this .sendEvent = (Button )this .findViewById (R .id .sendEvent );
124
128
this .iamHost = this .findViewById (R .id .iamHost );
125
129
this .triggerKeyTextView = this .findViewById (R .id .triggerKey );
126
130
this .triggerValueTextView = this .findViewById (R .id .triggerValue );
131
+ this .outcomeName = this .findViewById (R .id .outcomeName );
132
+ this .outcomeValueName = this .findViewById (R .id .outcomeNameValue );
133
+ this .outcomeValue = this .findViewById (R .id .outcomeValue );
134
+ this .outcomeUnique = this .findViewById (R .id .outcomeUniqueName );
127
135
this .iamHost .setText (OneSignalExampleApp .getOneSignalAppId (this ));
128
136
129
137
if (OneSignal .requiresUserPrivacyConsent ()) {
@@ -257,10 +265,9 @@ public void onUnsubscribeClicked(View v) {
257
265
this .debugTextView .setText ("Unsubscribed" );
258
266
}
259
267
260
-
261
268
public void onSendTagsClicked (View v ) {
262
269
try {
263
- OneSignal .sendTags (new JSONObject ("{\" counter\" : " + String . valueOf ( sendTagsCounter ) + ", \" test_value\" : \" test_key\" }" ), new OneSignal .ChangeTagsUpdateHandler () {
270
+ OneSignal .sendTags (new JSONObject ("{\" counter\" : " + sendTagsCounter + ", \" test_value\" : \" test_key\" }" ), new OneSignal .ChangeTagsUpdateHandler () {
264
271
@ Override
265
272
public void onSuccess (JSONObject tags ) {
266
273
updateTextView ("Successfully sent tags: " + tags .toString ());
@@ -320,6 +327,51 @@ public void onFailure(OneSignal.EmailUpdateError error) {
320
327
});
321
328
}
322
329
330
+ public void onSendOutcomeClicked (View view ) {
331
+ OneSignal .sendOutcome (outcomeName .getText ().toString (), new OneSignal .OutcomeCallback () {
332
+ @ Override
333
+ public void onOutcomeSuccess (String name ) {
334
+ updateTextView (name + " Outcome sent successfully" );
335
+ }
336
+
337
+ @ Override
338
+ public void onOutcomeFail (int statusCode , String response ) {
339
+ updateTextView ("Outcome fail with status code: " + statusCode );
340
+ }
341
+ });
342
+ }
343
+
344
+ public void onSendUniqueOutcomeClicked (View view ) {
345
+ OneSignal .sendUniqueOutcome (outcomeUnique .getText ().toString (), new OneSignal .OutcomeCallback () {
346
+ @ Override
347
+ public void onOutcomeSuccess (String name ) {
348
+ updateTextView (name + " Unique Outcome sent successfully" );
349
+ }
350
+
351
+ @ Override
352
+ public void onOutcomeFail (int statusCode , String response ) {
353
+ updateTextView ("Unique Outcome fail with status code: " + statusCode );
354
+ }
355
+ });
356
+ }
357
+
358
+ public void onSendOutcomeWithValueClicked (View view ) {
359
+ if (outcomeValue .getText ().toString ().isEmpty ())
360
+ return ;
361
+
362
+ OneSignal .sendOutcomeWithValue (outcomeValueName .getText ().toString (), Float .parseFloat (outcomeValue .getText ().toString ()), new OneSignal .OutcomeCallback () {
363
+ @ Override
364
+ public void onOutcomeSuccess (String name ) {
365
+ updateTextView (name + " Outcome sent with value successfully" );
366
+ }
367
+
368
+ @ Override
369
+ public void onOutcomeFail (int statusCode , String response ) {
370
+ updateTextView ("Outcome with value fail with status code: " + statusCode );
371
+ }
372
+ });
373
+ }
374
+
323
375
public void onLogoutEmailClicked (View v ) {
324
376
OneSignal .logoutEmail (new OneSignal .EmailUpdateHandler () {
325
377
@ Override
0 commit comments