Skip to content

Commit 52d8900

Browse files
Merge pull request #825 from BranchMetrics/Staging
Release 5.0.0
2 parents 69ec086 + 8db8fd1 commit 52d8900

File tree

13 files changed

+202
-512
lines changed

13 files changed

+202
-512
lines changed

Branch-SDK-TestBed/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</activity>
5252

5353
<activity android:name="io.branch.branchandroiddemo.CreditHistoryActivity"/>
54+
<activity android:name=".SettingsActivity"/>
5455

5556
<activity android:name=".AutoDeepLinkTestActivity">
5657
<!-- Keys for auto deep linking this activity -->

Branch-SDK-TestBed/src/main/java/io/branch/branchandroiddemo/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ public void onClick(View view) {
374374
}
375375
});
376376

377+
findViewById(R.id.settings_btn).setOnClickListener(new OnClickListener() {
378+
@Override
379+
public void onClick(View v) {
380+
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
381+
startActivity(intent);
382+
}
383+
});
384+
377385
// Tracking events
378386
findViewById(R.id.cmdTrackCustomEvent).setOnClickListener(new OnClickListener() {
379387
@Override
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.branch.branchandroiddemo;
2+
3+
import android.app.Activity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Switch;
8+
9+
import io.branch.referral.Branch;
10+
import io.branch.referral.PrefHelper;
11+
12+
public class SettingsActivity extends Activity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_settings);
18+
19+
setupDisableAdNetworkCalloutsSwitch();
20+
}
21+
22+
void setupDisableAdNetworkCalloutsSwitch() {
23+
final Switch disableAdNetworkCalloutsSwitch = findViewById(R.id.disable_ad_network_callouts);
24+
25+
/*
26+
* Initialize switch state from SharedPreferences.
27+
*/
28+
final PrefHelper prefHelper = PrefHelper.getInstance(this);
29+
disableAdNetworkCalloutsSwitch.setChecked(prefHelper.getAdNetworkCalloutsDisabled());
30+
31+
/*
32+
* Update the setting whenever the switch changes state.
33+
*/
34+
disableAdNetworkCalloutsSwitch.setOnClickListener(new View.OnClickListener() {
35+
@Override
36+
public void onClick(View v) {
37+
Branch.getInstance().disableAdNetworkCallouts(disableAdNetworkCalloutsSwitch.isChecked());
38+
}
39+
});
40+
41+
}
42+
}

Branch-SDK-TestBed/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149
android:text="Fire notif"
150150
android:layout_marginTop="20dp"/>
151151

152+
<Button
153+
android:id="@+id/settings_btn"
154+
style="@style/testbed_button_style"
155+
android:layout_below="@+id/notif_btn"
156+
android:layout_centerHorizontal="true"
157+
android:text="@string/settings"
158+
android:layout_marginTop="20dp"/>
159+
152160
</RelativeLayout>
153161

154162
</ScrollView>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
<LinearLayout
7+
android:layout_width="match_parent"
8+
android:layout_height="wrap_content"
9+
android:orientation="horizontal">
10+
<TextView
11+
android:layout_width="wrap_content"
12+
android:layout_height="match_parent"
13+
android:text="@string/disable_ad_network_callouts"/>
14+
<Switch
15+
android:id="@+id/disable_ad_network_callouts"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"/>
18+
</LinearLayout>
19+
</LinearLayout>

Branch-SDK-TestBed/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
<string name="launch_mode_branch">"Launched by Branch on auto deep linking!"</string>
1212
<string name="launch_mode_normal">"Launched by normal application flow"</string>
1313

14+
<string name="disable_ad_network_callouts">Disable ad network callouts</string>
15+
<string name="settings">Settings</string>
1416
</resources>

Branch-SDK/src/androidTest/java/io/branch/referral/PrefHelperTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.junit.Assert;
77
import org.junit.Test;
88

9-
109
public class PrefHelperTest extends BranchTest {
1110

1211
void assertDefaultURL() {
@@ -53,4 +52,22 @@ public void testSetAPIUrl_InvalidEmpty() {
5352
PrefHelper.setAPIUrl("");
5453
assertDefaultURL();
5554
}
55+
56+
@Test
57+
public void testSetAdNetworkCalloutsDisabled() {
58+
Context context = getTestContext();
59+
PrefHelper prefHelper = PrefHelper.getInstance(context);
60+
prefHelper.setAdNetworkCalloutsDisabled(true);
61+
62+
Assert.assertTrue(prefHelper.getAdNetworkCalloutsDisabled());
63+
}
64+
65+
@Test
66+
public void testSetAdNetworkCalloutsEnabled() {
67+
Context context = getTestContext();
68+
PrefHelper prefHelper = PrefHelper.getInstance(context);
69+
prefHelper.setAdNetworkCalloutsDisabled(false);
70+
71+
Assert.assertFalse(prefHelper.getAdNetworkCalloutsDisabled());
72+
}
5673
}

0 commit comments

Comments
 (0)