-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
812 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.0" | ||
|
||
defaultConfig { | ||
applicationId "com.appboy.segment.appboysample" | ||
minSdkVersion 16 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
// Grabs the first line of the changelog to get the current version. Expects the line to start with Markdown syntax | ||
// (ex: ## major.minor.build) | ||
def changelogFile = new File("../public/CHANGELOG.md") | ||
if (changelogFile.exists()) { | ||
changelogFile.withReader { | ||
version = it.readLine().substring(3) | ||
} | ||
logger.lifecycle("Setting version to last recorded version in `../appboy-segment-integration/CHANGELOG.md`: " + version) | ||
} else { | ||
version = "+" | ||
logger.lifecycle("Setting version to highest version found in local maven cache: " + version) | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support:design:28.0.0' | ||
implementation('com.segment.analytics.android:analytics:4.3.1') { | ||
transitive = true | ||
} | ||
implementation "com.appboy:appboy-segment-integration:${version}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/brianwheeler/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.appboy.segment.appboysample" > | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
android:name=".AppboySegmentApplication"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name="com.appboy.ui.AppboyWebViewActivity" /> | ||
</application> | ||
</manifest> |
33 changes: 33 additions & 0 deletions
33
...oy-sample/app/src/main/java/com/appboy/segment/appboysample/AppboySegmentApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.appboy.segment.appboysample; | ||
|
||
import android.app.Application; | ||
import android.util.Log; | ||
|
||
import com.appboy.Constants; | ||
import com.appboy.support.AppboyLogger; | ||
import com.segment.analytics.Analytics; | ||
import com.segment.analytics.android.integrations.appboy.AppboyIntegration; | ||
|
||
public class AppboySegmentApplication extends Application { | ||
private static final String TAG = String.format("%s.%s", Constants.APPBOY_LOG_TAG_PREFIX, AppboySegmentApplication.class.getName()); | ||
private static final String WRITE_KEY = @"YOUR_WRITE_KEY"; | ||
private static final String APPBOY_KEY = "Appboy"; | ||
public static boolean sAppboySegmentEnabled = false; | ||
|
||
@Override public void onCreate() { | ||
super.onCreate(); | ||
AppboyLogger.setLogLevel(Log.VERBOSE); | ||
Analytics.Builder builder = new Analytics.Builder(this, WRITE_KEY); | ||
builder.use(AppboyIntegration.FACTORY); | ||
builder.logLevel(Analytics.LogLevel.VERBOSE); | ||
Analytics.setSingletonInstance(builder.build()); | ||
|
||
Analytics.with(this).onIntegrationReady(APPBOY_KEY, new Analytics.Callback() { | ||
@Override | ||
public void onReady(Object instance) { | ||
Log.i(TAG, "analytics.onIntegrationReady() called"); | ||
sAppboySegmentEnabled = true; | ||
} | ||
}); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
appboy-sample/app/src/main/java/com/appboy/segment/appboysample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.appboy.segment.appboysample; | ||
|
||
import android.content.Context; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.inputmethod.InputMethodManager; | ||
import android.widget.Toast; | ||
|
||
import com.appboy.Constants; | ||
import com.appboy.support.AppboyLogger; | ||
import com.appboy.ui.AppboyFeedFragment; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private static final String TAG = String.format("%s.%s", Constants.APPBOY_LOG_TAG_PREFIX, MainActivity.class.getName()); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
AppboyLogger.setLogLevel(Log.VERBOSE); | ||
setContentView(R.layout.activity_main); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
final FragmentManager fragmentManager = getSupportFragmentManager(); | ||
Fragment currentFragment = fragmentManager.findFragmentById(R.id.root); | ||
|
||
if (currentFragment == null) { | ||
fragmentManager.beginTransaction().add(R.id.root, new MainFragment()).commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (!AppboySegmentApplication.sAppboySegmentEnabled) { | ||
Toast.makeText(this, "Appboy integration disabled. Doing nothing.", Toast.LENGTH_LONG).show(); | ||
return super.onOptionsItemSelected(item); | ||
} | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
if (id == R.id.newsfeed) { | ||
replaceCurrentFragment(new AppboyFeedFragment()); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
private void replaceCurrentFragment(Fragment newFragment) { | ||
FragmentManager fragmentManager = getSupportFragmentManager(); | ||
Fragment currentFragment = fragmentManager.findFragmentById(R.id.root); | ||
|
||
if (currentFragment != null && currentFragment.getClass().equals(newFragment.getClass())) { | ||
Log.i(TAG, String.format("Fragment of type %s is already the active fragment. Ignoring request to replace " + | ||
"current fragment.", currentFragment.getClass())); | ||
return; | ||
} | ||
|
||
hideSoftKeyboard(); | ||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | ||
fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, | ||
android.R.anim.fade_in, android.R.anim.fade_out); | ||
fragmentTransaction.replace(R.id.root, newFragment, newFragment.getClass().toString()); | ||
if (currentFragment != null) { | ||
fragmentTransaction.addToBackStack(newFragment.getClass().toString()); | ||
} else { | ||
fragmentTransaction.addToBackStack(null); | ||
} | ||
fragmentTransaction.commit(); | ||
} | ||
|
||
private void hideSoftKeyboard() { | ||
if (getCurrentFocus() != null) { | ||
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | ||
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), | ||
InputMethodManager.RESULT_UNCHANGED_SHOWN); | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
appboy-sample/app/src/main/java/com/appboy/segment/appboysample/MainFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.appboy.segment.appboysample; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import com.segment.analytics.Analytics; | ||
import com.segment.analytics.Properties; | ||
import com.segment.analytics.Traits; | ||
|
||
import java.util.Date; | ||
import java.util.Random; | ||
|
||
public class MainFragment extends Fragment { | ||
|
||
Random mRandom = new Random(); | ||
|
||
public MainFragment() {} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) { | ||
final View view = layoutInflater.inflate(R.layout.content_main, container, false); | ||
|
||
Button identifyButton = view.findViewById(R.id.identifyButton); | ||
identifyButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View arg0) { | ||
EditText userIDTextField = view.findViewById(R.id.userIDField); | ||
String newUser = Integer.toString(Math.abs(mRandom.nextInt())); | ||
if (userIDTextField.getText().toString().length() > 0) { | ||
newUser = userIDTextField.getText().toString(); | ||
} | ||
TextView textView = view.findViewById(R.id.helloText); | ||
textView.setText("Hello Appboy and Segment! Current User: " + newUser); | ||
Toast.makeText(getContext(), "identify() called with user id: " + newUser + ".", Toast.LENGTH_LONG).show(); | ||
Traits traits = new Traits(); | ||
Date birthday = new Date(System.currentTimeMillis()); | ||
traits.putBirthday(birthday); | ||
traits.putEmail("abc@123.com"); | ||
traits.putFirstName("First"); | ||
traits.putLastName("Last"); | ||
traits.putGender("m"); | ||
traits.putPhone("5555555555"); | ||
Traits.Address address = new Traits.Address(); | ||
address.putCity("City"); | ||
address.putCountry("USA"); | ||
traits.putAddress(address); | ||
traits.put("boolean", new Boolean(true)); | ||
traits.put("integer", new Integer(50)); | ||
traits.put("double", new Double(7.2)); | ||
traits.put("float", new Float(120.4)); | ||
traits.put("long", new Long(1234L)); | ||
traits.put("string", "hello"); | ||
traits.put("date", new Date(System.currentTimeMillis())); | ||
Analytics.with(getContext()).identify(newUser, traits, null); | ||
} | ||
}); | ||
|
||
Button flushButton = view.findViewById(R.id.flushButton); | ||
flushButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View arg0) { | ||
Toast.makeText(getContext(), "flush() called.", Toast.LENGTH_LONG).show(); | ||
Analytics.with(getContext()).flush(); | ||
} | ||
}); | ||
|
||
Button trackButton = view.findViewById(R.id.trackButton); | ||
trackButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View arg0) { | ||
EditText customEventTextField = view.findViewById(R.id.customEventField); | ||
EditText propertyKeyTextField = view.findViewById(R.id.propertyKeyField); | ||
EditText propertyValueTextField = view.findViewById(R.id.propertyValueField); | ||
String customEvent = "custom_event"; | ||
String propertyKey = "property_key"; | ||
String propertyValue = "property_value"; | ||
if (customEventTextField.getText().toString().length() > 0) { | ||
customEvent = customEventTextField.getText().toString(); | ||
} | ||
if (propertyKeyTextField.getText().toString().length() > 0) { | ||
propertyKey = propertyKeyTextField.getText().toString(); | ||
} | ||
if (propertyValueTextField.getText().toString().length() > 0) { | ||
propertyValue = propertyValueTextField.getText().toString(); | ||
} | ||
Toast.makeText(getContext(), "track() called for custom event '" + customEvent + "' and purchase 'custom_purchase'.", Toast.LENGTH_LONG).show(); | ||
Analytics.with(getContext()).track(customEvent, new Properties().putValue(propertyKey, propertyValue)); | ||
Properties purchaseProperties = new Properties(); | ||
purchaseProperties.put("property_key", "property_value"); | ||
purchaseProperties.putRevenue(10.0); | ||
purchaseProperties.putCurrency("JPY"); | ||
Analytics.with(getContext()).track("custom_purchase", purchaseProperties); | ||
Analytics.with(getContext()).track("Install Attributed", new Properties() | ||
.putValue("provider", "Tune/Kochava/Branch") | ||
.putValue("campaign", new Properties() | ||
.putValue("source", "Network/FB/AdWords/MoPub/Source") | ||
.putValue("name", "Campaign Name") | ||
.putValue("content", "Organic Content Title") | ||
.putValue("ad_creative", "Red Hello World Ad") | ||
.putValue("ad_group", "Red Ones"))); | ||
} | ||
}); | ||
return view; | ||
} | ||
} |
Oops, something went wrong.