-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathActivityExampleConsent.java
More file actions
74 lines (63 loc) · 2.7 KB
/
ActivityExampleConsent.java
File metadata and controls
74 lines (63 loc) · 2.7 KB
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
package ly.count.android.demo;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.switchmaterial.SwitchMaterial;
import ly.count.android.sdk.Countly;
public class ActivityExampleConsent extends AppCompatActivity {
private static final String[][] FEATURES = {
{"sessions", "switchSessions"},
{"events", "switchEvents"},
{"views", "switchViews"},
{"crashes", "switchCrashes"},
{"attribution", "switchAttribution"},
{"users", "switchUsers"},
{"push", "switchPush"},
{"starRating", "switchStarRating"},
{"remoteConfig", "switchRemoteConfig"},
{"location", "switchLocation"},
{"feedback", "switchFeedback"},
{"apm", "switchApm"},
{"content", "switchContent"},
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_consent);
// Set initial switch states and listeners
for (String[] feature : FEATURES) {
String featureName = feature[0];
int resId = getResources().getIdentifier(feature[1], "id", getPackageName());
SwitchMaterial sw = findViewById(resId);
if (sw != null) {
sw.setChecked(Countly.sharedInstance().consent().getConsent(featureName));
sw.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
Countly.sharedInstance().consent().giveConsent(new String[]{featureName});
} else {
Countly.sharedInstance().consent().removeConsent(new String[]{featureName});
}
});
}
}
findViewById(R.id.btnGiveAllConsent).setOnClickListener(v -> {
Countly.sharedInstance().consent().giveConsentAll();
refreshSwitches();
Toast.makeText(this, "All consent given", Toast.LENGTH_SHORT).show();
});
findViewById(R.id.btnRemoveAllConsent).setOnClickListener(v -> {
Countly.sharedInstance().consent().removeConsentAll();
refreshSwitches();
Toast.makeText(this, "All consent removed", Toast.LENGTH_SHORT).show();
});
}
private void refreshSwitches() {
for (String[] feature : FEATURES) {
int resId = getResources().getIdentifier(feature[1], "id", getPackageName());
SwitchMaterial sw = findViewById(resId);
if (sw != null) {
sw.setChecked(Countly.sharedInstance().consent().getConsent(feature[0]));
}
}
}
}