Skip to content

Commit c293239

Browse files
authored
Merge pull request #861 from OneSignal/outcome_events_release
Outcome events release
2 parents 6039337 + f9671ba commit c293239

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4536
-473
lines changed

OneSignalSDK/app/src/main/java/com/onesignal/MainActivity.java

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import android.app.Activity;
3131
import android.app.NotificationManager;
3232
import android.content.Context;
33-
import android.content.SharedPreferences;
3433
import android.os.AsyncTask;
3534
import android.os.Bundle;
35+
import android.os.Handler;
3636
import android.os.Looper;
3737
import android.util.Log;
3838
import android.view.Menu;
@@ -42,11 +42,9 @@
4242
import android.widget.CheckBox;
4343
import android.widget.CompoundButton;
4444
import android.widget.TextView;
45-
import android.os.Handler;
4645
import android.widget.Toast;
4746

4847
import com.onesignal.OneSignal.NotificationOpenedHandler;
49-
5048
import com.onesignal.example.OneSignalExampleApp;
5149
import com.onesignal.example.R;
5250
import com.onesignal.example.iap.IabHelper;
@@ -65,16 +63,21 @@ public class MainActivity extends Activity implements OSEmailSubscriptionObserve
6563
R.id.unsubscribe,
6664
R.id.sendTags,
6765
R.id.getTags,
68-
R.id.setEmail,
66+
R.id.sendEvent,
6967
R.id.postNotification,
7068
R.id.postNotificationAsync,
7169
R.id.postNotificationGroupCheckBox,
7270
R.id.postNotificationAsyncGroupCheckBox};
7371

7472
private TextView debugTextView;
7573
private TextView emailTextView;
74+
private TextView outcomeName;
75+
private TextView outcomeValueName;
76+
private TextView outcomeValue;
77+
private TextView outcomeUnique;
7678
private Button consentButton;
7779
private Button setEmailButton;
80+
private Button sendEvent;
7881
private Button logoutEmailButton;
7982
private Button postNotifButton;
8083
private Button postNotifAsyncButton;
@@ -86,7 +89,6 @@ public class MainActivity extends Activity implements OSEmailSubscriptionObserve
8689
private TextView iamHost;
8790
private TextView triggerKeyTextView;
8891
private TextView triggerValueTextView;
89-
private String SHARDPRES_KEY_IAM_HOST = "SHARDPRES_KEY_IAM_HOST";
9092

9193
@Override
9294
public boolean onCreateOptionsMenu(Menu menu) {
@@ -115,15 +117,21 @@ protected void onCreate(Bundle savedInstanceState) {
115117
setContentView(com.onesignal.example.R.layout.activity_main);
116118

117119
this.consentButton = this.findViewById(R.id.consentButton);
118-
this.setEmailButton = this.findViewById(R.id.setEmail);
119120
this.logoutEmailButton = this.findViewById(R.id.logoutEmail);
120121
this.postNotifButton = this.findViewById(R.id.postNotification);
121122
this.postNotifAsyncButton = this.findViewById(R.id.postNotificationAsync);
122123
this.postNotifGroupCheckBox = this.findViewById(R.id.postNotificationGroupCheckBox);
123124
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);
124128
this.iamHost = this.findViewById(R.id.iamHost);
125129
this.triggerKeyTextView = this.findViewById(R.id.triggerKey);
126130
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);
127135
this.iamHost.setText(OneSignalExampleApp.getOneSignalAppId(this));
128136

129137
if (OneSignal.requiresUserPrivacyConsent()) {
@@ -257,10 +265,9 @@ public void onUnsubscribeClicked(View v) {
257265
this.debugTextView.setText("Unsubscribed");
258266
}
259267

260-
261268
public void onSendTagsClicked(View v) {
262269
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() {
264271
@Override
265272
public void onSuccess(JSONObject tags) {
266273
updateTextView("Successfully sent tags: " + tags.toString());
@@ -320,6 +327,51 @@ public void onFailure(OneSignal.EmailUpdateError error) {
320327
});
321328
}
322329

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+
323375
public void onLogoutEmailClicked(View v) {
324376
OneSignal.logoutEmail(new OneSignal.EmailUpdateHandler() {
325377
@Override

0 commit comments

Comments
 (0)