Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package io.branch.branchandroiddemo;

import static android.content.Intent.getIntent;
import static androidx.core.content.ContextCompat.startActivity;

import static java.security.AccessController.getContext;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onClick(View view) {
branchWrapper.showLogWindow("",false, this, Constants.LOG_DATA);
} else if (view == btCreateQrCode) {
branchWrapper.getQRCode(this, getIntent(), MainActivity.this);
}else {
} else {
branchWrapper.showLogWindow("",false, this, Constants.UNKNOWN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
android:layout_marginBottom="@dimen/_2sdp"
android:text="Send Standard Event"
android:textAllCaps="false" />

<Button
android:id="@+id/bt_Read_Logs"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion Branch-SDK-TestBed/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</activity>

<activity android:name="io.branch.branchandroidtestbed.SettingsActivity" />

<activity android:name="io.branch.branchandroidtestbed.LogOutputActivity" />
<activity android:name="io.branch.branchandroidtestbed.AutoDeepLinkTestActivity">
<!-- Keys for auto deep linking this activity -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,47 @@
import android.app.Application;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import io.branch.interfaces.IBranchLoggingCallbacks;
import io.branch.referral.Branch;
import io.branch.referral.BranchLogger;
import io.branch.referral.Defines;

public final class CustomBranchApp extends Application {
@Override
public void onCreate() {
super.onCreate();

IBranchLoggingCallbacks iBranchLoggingCallbacks = new IBranchLoggingCallbacks() {
@Override
public void onBranchLog(String logMessage, String severityConstantName) {
Log.v( "CustomTag", logMessage);
}

IBranchLoggingCallbacks loggingCallbacks = (message, tag) -> {
Log.d("BranchTestbed", message);
saveLogToFile(message);
};
Branch.enableLogging(BranchLogger.BranchLogLevel.VERBOSE); // Pass in iBranchLoggingCallbacks to enable logging redirects
Branch.enableLogging(loggingCallbacks);

Branch.getAutoInstance(this);
}

private void saveLogToFile(String logMessage) {
File logFile = new File(getFilesDir(), "branchlogs.txt");

try {
if (!logFile.exists()) {
boolean fileCreated = logFile.createNewFile();
Log.d("BranchTestbed", "Log file created: " + fileCreated);
}

try (FileOutputStream fos = new FileOutputStream(logFile, true);
OutputStreamWriter writer = new OutputStreamWriter(fos)) {
writer.write(logMessage + "\n");
}

} catch (Exception e) {
Log.e("BranchTestbed", "Error writing to log file", e);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.branch.branchandroidtestbed;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class LogOutputActivity extends Activity {
private TextView logOutputTextView;
private File logFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_output);

logOutputTextView = findViewById(R.id.logOutputTextView);
logFile = new File(getFilesDir(), "branchlogs.txt");
displayLogs();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_log_output, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_clear_logs) {
clearLogs();
return true;
}
return super.onOptionsItemSelected(item);
}

private void displayLogs() {
if (logFile.exists()) {
StringBuilder logContent = new StringBuilder();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile)))) {
String line;
while ((line = reader.readLine()) != null) {
logContent.append(line).append("\n");
}
} catch (Exception e) {
e.printStackTrace();
logContent.append("Error reading log file.");
}

logOutputTextView.setText(logContent.toString());
} else {
logOutputTextView.setText("Log file not found.");
}
}

private void clearLogs() {
if (logFile.exists()) {
if (logFile.delete()) {
Toast.makeText(this, "Logs cleared.", Toast.LENGTH_SHORT).show();
logOutputTextView.setText("Logs cleared.");
finish();
} else {
Toast.makeText(this, "Failed to clear logs.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No log file to clear.", Toast.LENGTH_SHORT).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
Expand Down Expand Up @@ -128,7 +127,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error != null) {
Log.e("BranchSDK_Tester", "branch set Identity failed. Caused by -" + error.getMessage());
}
Toast.makeText(getApplicationContext(), "Set Identity to " + userID, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Set Identity to " + userID, Toast.LENGTH_LONG).show();


}
Expand All @@ -154,10 +153,10 @@ public void onClick(View v) {
public void onLogoutFinished(boolean loggedOut, BranchError error) {
if (error != null) {
Log.e("BranchSDK_Tester", "onLogoutFinished Error: " + error);
Toast.makeText(getApplicationContext(), "Error Logging Out: " + error.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Error Logging Out: " + error.getMessage(), Toast.LENGTH_LONG).show();
} else {
Log.d("BranchSDK_Tester", "onLogoutFinished succeeded: " + loggedOut);
Toast.makeText(getApplicationContext(), "Cleared User ID: " + currentUserId, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Cleared User ID: " + currentUserId, Toast.LENGTH_LONG).show();
}
}
});
Expand Down Expand Up @@ -415,6 +414,13 @@ public void onChannelSelected(String channelName) {
}
});

findViewById(R.id.viewLogsButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, LogOutputActivity.class);
startActivity(intent);
}
});

findViewById(R.id.notif_btn).setOnClickListener(new OnClickListener() {
@Override
Expand Down Expand Up @@ -454,13 +460,40 @@ public void onClick(View v) {
((ToggleButton) findViewById(R.id.tracking_cntrl_btn)).setOnCheckedChangeListener((buttonView, isChecked) -> {
Branch.getInstance().disableTracking(isChecked, (trackingDisabled, referringParams, error) -> {
if (trackingDisabled) {
Toast.makeText(getApplicationContext(), "Disabled Tracking", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Disabled Tracking", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Enabled Tracking", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Enabled Tracking", Toast.LENGTH_LONG).show();
}
});
});

findViewById(R.id.cmdConsumerProtectionPreference).setOnClickListener(v -> {
final String[] options = {"Full", "Reduced", "Minimal", "None"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Select Consumer Protection Attribution Level")
.setItems(options, (dialog, which) -> {
Defines.BranchAttributionLevel preference;
switch (which) {
case 1:
preference = Defines.BranchAttributionLevel.REDUCED;
break;
case 2:
preference = Defines.BranchAttributionLevel.MINIMAL;
break;
case 3:
preference = Defines.BranchAttributionLevel.NONE;
break;
case 0:
default:
preference = Defines.BranchAttributionLevel.FULL;
break;
}
Branch.getInstance().setConsumerProtectionAttributionLevel(preference);
Toast.makeText(MainActivity.this, "Consumer Protection Preference set to " + options[which], Toast.LENGTH_LONG).show();
});
builder.create().show();
});

findViewById(R.id.qrCode_btn).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -541,13 +574,13 @@ public void onClick(View v) {
.logEvent(MainActivity.this, new BranchEvent.BranchLogEventCallback() {
@Override
public void onSuccess(int responseCode) {
Toast.makeText(getApplicationContext(), "Sent Branch Commerce Event: " + responseCode, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Sent Branch Commerce Event: " + responseCode, Toast.LENGTH_LONG).show();
}

@Override
public void onFailure(Exception e) {
Log.d("BranchSDK_Tester", e.toString());
Toast.makeText(getApplicationContext(), "Error sending Branch Commerce Event: " + e.toString(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Error sending Branch Commerce Event: " + e.toString(), Toast.LENGTH_LONG).show();
}
});

Expand All @@ -565,8 +598,18 @@ public void onClick(View v) {
.setSearchQuery("product name")
.addCustomDataProperty("Custom_Event_Property_Key1", "Custom_Event_Property_val1")
.addContentItems(branchUniversalObject)
.logEvent(MainActivity.this);
Toast.makeText(getApplicationContext(), "Sent Branch Content Event", Toast.LENGTH_SHORT).show();
.logEvent(MainActivity.this, new BranchEvent.BranchLogEventCallback() {
@Override
public void onSuccess(int responseCode) {
Toast.makeText(getApplicationContext(), "Sent Branch Content Event: " + responseCode, Toast.LENGTH_LONG).show();
}

@Override
public void onFailure(Exception e) {
Log.d("BranchSDK_Tester", e.toString());
Toast.makeText(getApplicationContext(), "Error sending Branch Content Event: " + e.toString(), Toast.LENGTH_LONG).show();
}
});
}
});

Expand All @@ -580,8 +623,18 @@ public void onClick(View v) {
.setDescription("User created an account")
.addCustomDataProperty("registrationID", "12345")
.addContentItems(branchUniversalObject)
.logEvent(MainActivity.this);
Toast.makeText(getApplicationContext(), "Sent Branch Lifecycle Event", Toast.LENGTH_SHORT).show();
.logEvent(MainActivity.this, new BranchEvent.BranchLogEventCallback() {
@Override
public void onSuccess(int responseCode) {
Toast.makeText(getApplicationContext(), "Sent Branch Lifecycle Event: " + responseCode, Toast.LENGTH_LONG).show();
}

@Override
public void onFailure(Exception e) {
Log.d("BranchSDK_Tester", e.toString());
Toast.makeText(getApplicationContext(), "Error sending Branch Lifecycle Event: " + e, Toast.LENGTH_LONG).show();
}
});
}
});

Expand All @@ -592,7 +645,7 @@ public void onClick(View v) {
@Override
public void onLogoutFinished(boolean loggedOut, BranchError error) {
Log.d("BranchSDK_Tester", "onLogoutFinished " + loggedOut + " errorMessage " + error);
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_LONG).show();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M7,3H4v3H2V1h5V3zM22,6V1h-5v2h3v3H22zM7,21H4v-3H2v5h5V21zM20,18v3h-3v2h5v-5H20zM19,18c0,1.1 -0.9,2 -2,2H7c-1.1,0 -2,-0.9 -2,-2V6c0,-1.1 0.9,-2 2,-2h10c1.1,0 2,0.9 2,2V18zM15,8H9v2h6V8zM15,11H9v2h6V11zM15,14H9v2h6V14z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>

</vector>
18 changes: 18 additions & 0 deletions Branch-SDK-TestBed/src/main/res/layout/activity_log_output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/logOutputTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="Logs will appear here" />
</ScrollView>
</RelativeLayout>
13 changes: 13 additions & 0 deletions Branch-SDK-TestBed/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
android:textOff="Disable Tracking"
android:textOn="Enable Tracking" />

<Button
android:id="@+id/cmdConsumerProtectionPreference"
style="@style/testbed_button_style"
android:drawableStart="@drawable/ic_baseline_security_24"
android:text="Consumer Protection Preference" />

<TextView
style="@style/testbed_text_view"
android:text="Events"
Expand Down Expand Up @@ -127,6 +133,13 @@
android:text="Misc."
/>

<Button
android:id="@+id/viewLogsButton"
style="@style/testbed_button_style"
android:drawableStart="@drawable/baseline_document_scanner_24"
android:text="Load Branch Logs" />


<Button
android:id="@+id/notif_btn"
style="@style/testbed_button_style"
Expand Down
7 changes: 7 additions & 0 deletions Branch-SDK-TestBed/src/main/res/menu/menu_log_output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_clear_logs"
android:title="Clear Logs"
android:showAsAction="always" />
</menu>
Loading
Loading