├── README.md ├── ajax_example └── optimizely.js ├── mobile_dialog_and_geotargeting ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── Opticon2015Demo.iml ├── app │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── josiahgaskin │ │ │ └── opticon2015demo │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── josiahgaskin │ │ │ └── opticon2015demo │ │ │ ├── DialogDetailFragment.java │ │ │ ├── GeofenceTransitionsIntentService.java │ │ │ ├── GeofencingDetailFragment.java │ │ │ ├── LiveVariableDialogBuilder.java │ │ │ ├── MainActivity.java │ │ │ ├── MyApplication.java │ │ │ └── NavigationDrawerFragment.java │ │ └── res │ │ ├── drawable-hdpi │ │ ├── drawer_shadow.9.png │ │ └── ic_drawer.png │ │ ├── drawable-mdpi │ │ ├── drawer_shadow.9.png │ │ └── ic_drawer.png │ │ ├── drawable-xhdpi │ │ ├── drawer_shadow.9.png │ │ └── ic_drawer.png │ │ ├── drawable-xxhdpi │ │ ├── drawer_shadow.9.png │ │ └── ic_drawer.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_dialogs.xml │ │ ├── fragment_geofencing.xml │ │ └── fragment_navigation_drawer.xml │ │ ├── menu │ │ ├── global.xml │ │ └── main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── api_key.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── results_api_sample ├── README.md ├── config.js ├── favicon.ico ├── index.html └── optimizely.js ├── salesforce_list_targeting ├── .gitignore ├── README.md ├── beatbox-0.96.zip ├── build_list.py ├── config.yaml.template └── requirements.txt ├── stats_api_phone_home ├── .gitignore ├── README.md ├── app │ ├── app.yaml │ ├── appengine_config.py │ ├── config.yaml.template │ ├── main.py │ └── models.py └── requirements.txt └── wordpress_plugin └── optimizely ├── admin.php ├── config.js ├── config.php ├── edit.js ├── edit.php ├── optimizely.js ├── optimizely.php ├── readme.txt └── style.css /README.md: -------------------------------------------------------------------------------- 1 | See [developers.optimizely.com](http://developers.optimizely.com). 2 | -------------------------------------------------------------------------------- /ajax_example/optimizely.js: -------------------------------------------------------------------------------- 1 | /* 2 | The OptimizelyAPI class provides a connection to the API via Javascript and lets you make authenticated calls without repeating yourself. 3 | 4 | We store the API token in each instance of the object, and we can connect to multiple different accounts by creating new instances of the OptimizelyAPI class. 5 | 6 | Finally, we keep track of how many requests are outstanding so we can tell when all the calls are complete. 7 | */ 8 | 9 | OptimizelyAPI = function(token) { 10 | this.outstandingRequests = 0; 11 | this.token = token; 12 | } 13 | 14 | /* 15 | To call the API, we use jQuery's `$.ajax` function, which sends an asynchronous request based on a set of `options`. 16 | 17 | Our function takes four arguments: 18 | 19 | * The request `type`, like GET or POST 20 | * The `endpoint` to hit, like `projects/27` 21 | * The `data` to send along with a POST or PUT request 22 | * A `callback` function to run when the operation is done. The callback should take one argument, the `response`. 23 | 24 | We construct the URL by appending the endpoint to the base API link, and we authenticate by adding the token in the headers section. 25 | 26 | To send data, we set content type to JSON and encode the array as a JSON string to send over the wire. 27 | */ 28 | 29 | OptimizelyAPI.prototype.call = function(type, endpoint, data, callback) { 30 | 31 | var self = this; 32 | 33 | var options = { 34 | url: "https://www.optimizelyapis.com/experiment/v1/" + endpoint, 35 | type: type, 36 | headers: {"Token": this.token}, 37 | contentType: 'application/json', 38 | success: function(response) { 39 | self.outstandingRequests -= 1; 40 | callback(response); 41 | } 42 | } 43 | 44 | if (data) { 45 | options.data = JSON.stringify(data); 46 | options.dataType = 'json'; 47 | } 48 | 49 | this.outstandingRequests += 1; 50 | jQuery.ajax(options); 51 | 52 | } 53 | 54 | /* 55 | Using our `call` function, we can define convenience functions for GETs, POSTs, PUTs, and DELETEs. 56 | */ 57 | 58 | OptimizelyAPI.prototype.get = function(endpoint, callback) { 59 | this.call('GET', endpoint, "", callback); 60 | } 61 | 62 | OptimizelyAPI.prototype.delete = function(endpoint, callback) { 63 | this.call('DELETE', endpoint, "", callback); 64 | } 65 | 66 | OptimizelyAPI.prototype.post = function(endpoint, data, callback) { 67 | this.call('POST', endpoint, data, callback); 68 | } 69 | 70 | OptimizelyAPI.prototype.put = function(endpoint, data, callback) { 71 | this.call('PUT', endpoint, data, callback); 72 | } 73 | 74 | /* 75 | We've also added an extra convenience function, `patch`, that updates a model by changing only the specified fields. The function works by reading in an entity, changing a few keys, and then sending it back to Optimizely. 76 | */ 77 | 78 | OptimizelyAPI.prototype.patch = function(endpoint, data, callback) { 79 | var self = this; 80 | self.get(endpoint, function(base) { 81 | for (var key in data) { 82 | base[key] = data[key]; 83 | } 84 | self.put(endpoint, base, callback); 85 | }); 86 | } -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/.name: -------------------------------------------------------------------------------- 1 | Opticon2015Demo -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.6 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/Opticon2015Demo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.josiahgaskin.opticon2015demo" 9 | minSdkVersion 11 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:22.1.1' 25 | compile('com.optimizely:optimizely:+@aar') { 26 | transitive = true 27 | } 28 | compile 'com.google.android.gms:play-services:7.5.0' 29 | } 30 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jgaskin/Library/Application Support/Google/Android Studio/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/androidTest/java/com/josiahgaskin/opticon2015demo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/DialogDetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | /** 11 | * A placeholder fragment containing a simple view. 12 | */ 13 | public class DialogDetailFragment extends Fragment { 14 | 15 | /** 16 | * The fragment argument representing the section number for this 17 | * fragment. 18 | */ 19 | private static final String ARG_SECTION_NUMBER = "section_number"; 20 | 21 | private LiveVariableDialogBuilder mSalesDialogBuilder; 22 | private LiveVariableDialogBuilder mAnotherDialogBuilder; 23 | 24 | /** 25 | * Returns a new instance of this fragment for the given section 26 | * number. 27 | */ 28 | public static DialogDetailFragment newInstance(int sectionNumber) { 29 | DialogDetailFragment fragment = new DialogDetailFragment(); 30 | Bundle args = new Bundle(); 31 | args.putInt(ARG_SECTION_NUMBER, sectionNumber); 32 | fragment.setArguments(args); 33 | return fragment; 34 | } 35 | 36 | public DialogDetailFragment() { 37 | } 38 | 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 41 | Bundle savedInstanceState) { 42 | View rootView = inflater.inflate(R.layout.fragment_dialogs, container, false); 43 | rootView.findViewById(R.id.sales_dialog).setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | mSalesDialogBuilder.show(); 47 | } 48 | }); 49 | rootView.findViewById(R.id.another_dialog).setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | mAnotherDialogBuilder.show(); 53 | } 54 | }); 55 | return rootView; 56 | } 57 | 58 | @Override 59 | public void onAttach(Activity activity) { 60 | super.onAttach(activity); 61 | ((MainActivity) activity).onSectionAttached( 62 | getArguments().getInt(ARG_SECTION_NUMBER)); 63 | mSalesDialogBuilder = new LiveVariableDialogBuilder(activity).setVariableKey("SalesDialog"); 64 | mAnotherDialogBuilder = new LiveVariableDialogBuilder(activity).setVariableKey("AnotherDialog"); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/GeofenceTransitionsIntentService.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import com.google.android.gms.location.Geofence; 4 | import com.google.android.gms.location.GeofenceStatusCodes; 5 | import com.google.android.gms.location.GeofencingEvent; 6 | 7 | import android.app.IntentService; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.SharedPreferences; 11 | import android.util.Log; 12 | 13 | import java.util.Collections; 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | /** 18 | * Service to receive geofencing notifications 19 | */ 20 | public class GeofenceTransitionsIntentService extends IntentService { 21 | public GeofenceTransitionsIntentService() { 22 | super("Optimizely Geofencing"); 23 | } 24 | 25 | protected void onHandleIntent(Intent intent) { 26 | GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); 27 | if (geofencingEvent.hasError()) { 28 | String errorMessage = getErrorString(geofencingEvent.getErrorCode()); 29 | Log.e("OPT DEMO", errorMessage); 30 | return; 31 | } 32 | 33 | // Get the transition type. 34 | int geofenceTransition = geofencingEvent.getGeofenceTransition(); 35 | 36 | // Test that the reported transition was of interest. 37 | if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) { 38 | SharedPreferences prefs = getSharedPreferences("brickandmortar", Context.MODE_PRIVATE); 39 | Set visitedSet = new HashSet(prefs.getStringSet("VISITED_SET", 40 | Collections.emptySet())); 41 | int newTotal = prefs.getInt("TOTAL_VISITS", 0); 42 | for (Geofence fence : geofencingEvent.getTriggeringGeofences()) { 43 | newTotal++; 44 | visitedSet.add(fence.getRequestId()); 45 | Log.i("OPT DEMO", "Visited " + fence.getRequestId()); 46 | } 47 | prefs.edit() 48 | .putStringSet("VISITED_SET", visitedSet) 49 | .putInt("TOTAL_VISITS", newTotal) 50 | .apply(); 51 | } 52 | } 53 | 54 | /** 55 | * Returns the error string for a geofencing error code. 56 | */ 57 | public static String getErrorString(int errorCode) { 58 | switch (errorCode) { 59 | case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: 60 | return "Geofence not available"; 61 | case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: 62 | return "Too many geofences"; 63 | case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: 64 | return "Too many pending intents"; 65 | default: 66 | return "Unknown Error"; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/GeofencingDetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import com.optimizely.Optimizely; 4 | 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.content.SharedPreferences; 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.TextView; 14 | 15 | import java.util.Collections; 16 | 17 | /** 18 | * A placeholder fragment containing a simple view. 19 | */ 20 | public class GeofencingDetailFragment extends Fragment { 21 | 22 | /** 23 | * The fragment argument representing the section number for this 24 | * fragment. 25 | */ 26 | private static final String ARG_SECTION_NUMBER = "section_number"; 27 | 28 | /** 29 | * Returns a new instance of this fragment for the given section 30 | * number. 31 | */ 32 | public static GeofencingDetailFragment newInstance(int sectionNumber) { 33 | GeofencingDetailFragment fragment = new GeofencingDetailFragment(); 34 | Bundle args = new Bundle(); 35 | args.putInt(ARG_SECTION_NUMBER, sectionNumber); 36 | fragment.setArguments(args); 37 | return fragment; 38 | } 39 | 40 | public GeofencingDetailFragment() { 41 | } 42 | 43 | @Override 44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 45 | Bundle savedInstanceState) { 46 | View rootView = inflater.inflate(R.layout.fragment_geofencing, container, false); 47 | final SharedPreferences prefs = getActivity() 48 | .getSharedPreferences("brickandmortar", Context.MODE_PRIVATE); 49 | int totalVisits = prefs.getInt("TOTAL_VISITS", 0); 50 | ((TextView)rootView.findViewById(R.id.total_visits)).setText(String.format("Total Visits: %d", totalVisits)); 51 | 52 | StringBuilder sb = new StringBuilder(); 53 | sb.append("You have visited the following locations: "); 54 | for (String locationName : prefs.getStringSet("VISITED_SET", Collections.emptySet())) { 55 | sb.append(locationName).append(" "); 56 | } 57 | ((TextView)rootView.findViewById(R.id.all_locations)).setText(sb.toString()); 58 | return rootView; 59 | } 60 | 61 | @Override 62 | public void onAttach(Activity activity) { 63 | super.onAttach(activity); 64 | ((MainActivity) activity).onSectionAttached( 65 | getArguments().getInt(ARG_SECTION_NUMBER)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/LiveVariableDialogBuilder.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import com.optimizely.Optimizely; 4 | import com.optimizely.Variable.LiveVariable; 5 | 6 | import android.content.Context; 7 | import android.support.annotation.NonNull; 8 | import android.support.v7.app.AlertDialog; 9 | 10 | /** 11 | * Dialog builder that uses LiveVariables for message and title. 12 | */ 13 | public class LiveVariableDialogBuilder extends AlertDialog.Builder { 14 | LiveVariable mMessageVariable; 15 | LiveVariable mTitleVariable; 16 | 17 | public LiveVariableDialogBuilder(Context context) { super(context); } 18 | public LiveVariableDialogBuilder(Context context, int theme) { super(context, theme); } 19 | 20 | public LiveVariableDialogBuilder setVariableKey(@NonNull String variableKey) { 21 | mMessageVariable = Optimizely.stringVariable(variableKey + "_message", ""); 22 | mTitleVariable = Optimizely.stringVariable(variableKey+"_title", ""); 23 | return this; 24 | } 25 | 26 | @NonNull @Override 27 | public AlertDialog create() { 28 | if (mMessageVariable != null) { setMessage(mMessageVariable.get()); } 29 | if (mTitleVariable != null) { setTitle(mTitleVariable.get()); } 30 | return super.create(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.app.ActionBar; 6 | import android.support.v4.app.FragmentManager; 7 | import android.os.Bundle; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.support.v4.widget.DrawerLayout; 11 | 12 | public class MainActivity extends AppCompatActivity 13 | implements NavigationDrawerFragment.NavigationDrawerCallbacks { 14 | 15 | /** 16 | * Fragment managing the behaviors, interactions and presentation of the navigation drawer. 17 | */ 18 | private NavigationDrawerFragment mNavigationDrawerFragment; 19 | 20 | /** 21 | * Used to store the last screen title. For use in {@link #restoreActionBar()}. 22 | */ 23 | private CharSequence mTitle; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | 30 | mNavigationDrawerFragment = (NavigationDrawerFragment) 31 | getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); 32 | mTitle = getTitle(); 33 | 34 | // Set up the drawer. 35 | mNavigationDrawerFragment.setUp( 36 | R.id.navigation_drawer, 37 | (DrawerLayout) findViewById(R.id.drawer_layout)); 38 | } 39 | 40 | @Override 41 | public void onNavigationDrawerItemSelected(int position) { 42 | // update the main content by replacing fragments 43 | FragmentManager fragmentManager = getSupportFragmentManager(); 44 | final Fragment fragment; 45 | switch (position) { 46 | case 0: 47 | fragment = DialogDetailFragment.newInstance(position); 48 | break; 49 | case 1: 50 | fragment = GeofencingDetailFragment.newInstance(position); 51 | break; 52 | default: 53 | fragment = null; 54 | } 55 | if (fragment != null) { 56 | fragmentManager.beginTransaction() 57 | .replace(R.id.container, fragment) 58 | .commit(); 59 | } 60 | } 61 | 62 | public void onSectionAttached(int number) { 63 | switch (number) { 64 | case 0: 65 | mTitle = getString(R.string.title_section1); 66 | break; 67 | case 1: 68 | mTitle = getString(R.string.title_section2); 69 | break; 70 | } 71 | restoreActionBar(); 72 | } 73 | 74 | public void restoreActionBar() { 75 | ActionBar actionBar = getSupportActionBar(); 76 | if (actionBar != null) { 77 | actionBar.setDisplayShowTitleEnabled(true); 78 | actionBar.setTitle(mTitle); 79 | } 80 | } 81 | 82 | @Override 83 | public boolean onOptionsItemSelected(MenuItem item) { 84 | // Handle action bar item clicks here. The action bar will 85 | // automatically handle clicks on the Home/Up button, so long 86 | // as you specify a parent activity in AndroidManifest.xml. 87 | int id = item.getItemId(); 88 | 89 | //noinspection SimplifiableIfStatement 90 | if (id == R.id.action_settings) { 91 | return true; 92 | } 93 | 94 | return super.onOptionsItemSelected(item); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import com.google.android.gms.common.ConnectionResult; 4 | import com.google.android.gms.common.GooglePlayServicesUtil; 5 | import com.google.android.gms.common.api.GoogleApiClient; 6 | import com.google.android.gms.location.Geofence; 7 | import com.google.android.gms.location.GeofencingRequest; 8 | import com.google.android.gms.location.LocationServices; 9 | import com.google.android.gms.maps.model.LatLng; 10 | 11 | import com.optimizely.Optimizely; 12 | 13 | import android.app.Application; 14 | import android.app.PendingIntent; 15 | import android.content.Intent; 16 | import android.content.SharedPreferences; 17 | import android.os.Bundle; 18 | import android.util.Log; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * App Subclass 28 | */ 29 | public class MyApplication extends Application implements 30 | GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { 31 | private static final long GEOFENCE_EXPIRATION_IN_MILLISECONDS = 12 * 60 * 60 * 1000; // 12 hours 32 | private static final int GEOFENCE_RADIUS_IN_METERS = 100; 33 | private static final String TAG = "OPT DEBUG"; 34 | 35 | private static final Map SF_LANDMARKS = new HashMap(); 36 | static { 37 | SF_LANDMARKS.put("Pier27", new LatLng(37.805497, -122.403386)); 38 | SF_LANDMARKS.put("OptimizelyOffice", new LatLng(37.786208, -122.398714)); 39 | } 40 | 41 | private List mGeofenceList = new ArrayList(); 42 | 43 | private GoogleApiClient mGoogleApiClient; 44 | 45 | @Override 46 | public void onCreate() { 47 | super.onCreate(); 48 | // Add current data to optimizely 49 | SharedPreferences prefs = getSharedPreferences("brickandmortar", MODE_PRIVATE); 50 | int totalVisits = prefs.getInt("TOTAL_VISITS", 0); 51 | Optimizely.setCustomTag("brickandmortar_TotalVisits", Integer.toString(totalVisits)); 52 | for (String locationName : prefs.getStringSet("VISITED_SET", Collections.emptySet())) { 53 | Optimizely.setCustomTag("brickandmortar_visited_" + locationName, "true"); 54 | } 55 | 56 | String apiKey = getString(R.string.api_key); 57 | if (!apiKey.isEmpty()) { 58 | Optimizely.startOptimizely(apiKey, this); 59 | } else { 60 | Log.e("OPT DEMO", "No API key found! Please add your API token in the api_key.xml values file"); 61 | } 62 | mGoogleApiClient = new GoogleApiClient.Builder(this) 63 | .addConnectionCallbacks(this) 64 | .addOnConnectionFailedListener(this) 65 | .addApi(LocationServices.API) 66 | .build(); 67 | mGoogleApiClient.connect(); 68 | } 69 | 70 | /** 71 | * Runs when a GoogleApiClient object successfully connects. 72 | */ 73 | @Override 74 | public void onConnected(Bundle connectionHint) { 75 | Log.i(TAG, "Connected to GoogleApiClient"); 76 | populateGeofenceList(); 77 | sendGeofencingRequest(); 78 | } 79 | 80 | @Override 81 | public void onConnectionFailed(ConnectionResult result) { 82 | // Refer to the javadoc for ConnectionResult to see what error codes might be returned in 83 | // onConnectionFailed. 84 | Log.i(TAG, "Connection failed: " + result.toString()); 85 | } 86 | 87 | @Override 88 | public void onConnectionSuspended(int cause) { 89 | // The connection to Google Play services was lost for some reason. 90 | Log.i(TAG, "Connection suspended"); 91 | 92 | // onConnected() will be called again automatically when the service reconnects 93 | } 94 | 95 | /** 96 | * Builds and sends a GeofencingRequest. 97 | */ 98 | private void sendGeofencingRequest() { 99 | GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); 100 | builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER); 101 | builder.addGeofences(mGeofenceList); 102 | final GeofencingRequest request = builder.build(); 103 | 104 | Intent intent = new Intent(this, GeofenceTransitionsIntentService.class); 105 | final PendingIntent pendingIntent = PendingIntent 106 | .getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 107 | 108 | try { 109 | LocationServices.GeofencingApi.addGeofences( 110 | mGoogleApiClient, 111 | request, 112 | pendingIntent); 113 | } catch (SecurityException securityException) { 114 | // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. 115 | } 116 | } 117 | 118 | 119 | /** 120 | * This sample hard codes geofence data. A real app might dynamically create geofences or 121 | * fetch them from a server 122 | */ 123 | public void populateGeofenceList() { 124 | for (Map.Entry entry : SF_LANDMARKS.entrySet()) { 125 | 126 | mGeofenceList.add(new Geofence.Builder() 127 | // Set the request ID of the geofence. This is a string to identify this 128 | // geofence. 129 | .setRequestId(entry.getKey()) 130 | // Set the circular region of this geofence. 131 | .setCircularRegion( 132 | entry.getValue().latitude, 133 | entry.getValue().longitude, 134 | GEOFENCE_RADIUS_IN_METERS 135 | ) 136 | // Set the expiration duration of the geofence. This geofence gets automatically 137 | // removed after this period of time. 138 | .setExpirationDuration(GEOFENCE_EXPIRATION_IN_MILLISECONDS) 139 | // Set the transition types of interest. Alerts are only generated for these 140 | // transition. We track entry and exit transitions in this sample. 141 | .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | 142 | Geofence.GEOFENCE_TRANSITION_EXIT) 143 | // Create the geofence. 144 | .build()); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/java/com/josiahgaskin/opticon2015demo/NavigationDrawerFragment.java: -------------------------------------------------------------------------------- 1 | package com.josiahgaskin.opticon2015demo; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.app.Activity; 5 | import android.support.v7.app.ActionBar; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.ActionBarDrawerToggle; 8 | import android.support.v4.view.GravityCompat; 9 | import android.support.v4.widget.DrawerLayout; 10 | import android.content.SharedPreferences; 11 | import android.content.res.Configuration; 12 | import android.os.Bundle; 13 | import android.preference.PreferenceManager; 14 | import android.view.LayoutInflater; 15 | import android.view.Menu; 16 | import android.view.MenuInflater; 17 | import android.view.MenuItem; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.widget.AdapterView; 21 | import android.widget.ArrayAdapter; 22 | import android.widget.ListView; 23 | import android.widget.Toast; 24 | 25 | /** 26 | * Fragment used for managing interactions for and presentation of a navigation drawer. 27 | * See the 28 | * design guidelines for a complete explanation of the behaviors implemented here. 29 | */ 30 | public class NavigationDrawerFragment extends Fragment { 31 | 32 | /** 33 | * Remember the position of the selected item. 34 | */ 35 | private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; 36 | 37 | /** 38 | * Per the design guidelines, you should show the drawer on launch until the user manually 39 | * expands it. This shared preference tracks this. 40 | */ 41 | private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; 42 | 43 | /** 44 | * A pointer to the current callbacks instance (the Activity). 45 | */ 46 | private NavigationDrawerCallbacks mCallbacks; 47 | 48 | /** 49 | * Helper component that ties the action bar to the navigation drawer. 50 | */ 51 | private ActionBarDrawerToggle mDrawerToggle; 52 | 53 | private DrawerLayout mDrawerLayout; 54 | 55 | private ListView mDrawerListView; 56 | 57 | private View mFragmentContainerView; 58 | 59 | private int mCurrentSelectedPosition = 0; 60 | 61 | private boolean mFromSavedInstanceState; 62 | 63 | private boolean mUserLearnedDrawer; 64 | 65 | public NavigationDrawerFragment() { 66 | } 67 | 68 | @Override 69 | public void onCreate(Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | 72 | // Read in the flag indicating whether or not the user has demonstrated awareness of the 73 | // drawer. See PREF_USER_LEARNED_DRAWER for details. 74 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); 75 | mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); 76 | 77 | if (savedInstanceState != null) { 78 | mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); 79 | mFromSavedInstanceState = true; 80 | } 81 | 82 | // Select either the default item (0) or the last selected item. 83 | selectItem(mCurrentSelectedPosition); 84 | } 85 | 86 | @Override 87 | public void onActivityCreated(Bundle savedInstanceState) { 88 | super.onActivityCreated(savedInstanceState); 89 | // Indicate that this fragment would like to influence the set of actions in the action bar. 90 | setHasOptionsMenu(true); 91 | } 92 | 93 | @Override 94 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 95 | Bundle savedInstanceState) { 96 | mDrawerListView = (ListView) inflater.inflate( 97 | R.layout.fragment_navigation_drawer, container, false); 98 | mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 99 | @Override 100 | public void onItemClick(AdapterView parent, View view, int position, long id) { 101 | selectItem(position); 102 | } 103 | }); 104 | mDrawerListView.setAdapter(new ArrayAdapter( 105 | getActionBar().getThemedContext(), 106 | android.R.layout.simple_list_item_activated_1, 107 | android.R.id.text1, 108 | new String[]{ 109 | getString(R.string.title_section1), 110 | getString(R.string.title_section2), 111 | })); 112 | mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); 113 | return mDrawerListView; 114 | } 115 | 116 | public boolean isDrawerOpen() { 117 | return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); 118 | } 119 | 120 | /** 121 | * Users of this fragment must call this method to set up the navigation drawer interactions. 122 | * 123 | * @param fragmentId The android:id of this fragment in its activity's layout. 124 | * @param drawerLayout The DrawerLayout containing this fragment's UI. 125 | */ 126 | public void setUp(int fragmentId, DrawerLayout drawerLayout) { 127 | mFragmentContainerView = getActivity().findViewById(fragmentId); 128 | mDrawerLayout = drawerLayout; 129 | 130 | // set a custom shadow that overlays the main content when the drawer opens 131 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); 132 | // set up the drawer's list view with items and click listener 133 | 134 | ActionBar actionBar = getActionBar(); 135 | actionBar.setDisplayHomeAsUpEnabled(true); 136 | actionBar.setHomeButtonEnabled(true); 137 | 138 | // ActionBarDrawerToggle ties together the the proper interactions 139 | // between the navigation drawer and the action bar app icon. 140 | mDrawerToggle = new ActionBarDrawerToggle( 141 | getActivity(), /* host Activity */ 142 | mDrawerLayout, /* DrawerLayout object */ 143 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ 144 | R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ 145 | R.string.navigation_drawer_close /* "close drawer" description for accessibility */ 146 | ) { 147 | @Override 148 | public void onDrawerClosed(View drawerView) { 149 | super.onDrawerClosed(drawerView); 150 | if (!isAdded()) { 151 | return; 152 | } 153 | 154 | getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() 155 | } 156 | 157 | @Override 158 | public void onDrawerOpened(View drawerView) { 159 | super.onDrawerOpened(drawerView); 160 | if (!isAdded()) { 161 | return; 162 | } 163 | 164 | if (!mUserLearnedDrawer) { 165 | // The user manually opened the drawer; store this flag to prevent auto-showing 166 | // the navigation drawer automatically in the future. 167 | mUserLearnedDrawer = true; 168 | SharedPreferences sp = PreferenceManager 169 | .getDefaultSharedPreferences(getActivity()); 170 | sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); 171 | } 172 | 173 | getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() 174 | } 175 | }; 176 | 177 | // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, 178 | // per the navigation drawer design guidelines. 179 | if (!mUserLearnedDrawer && !mFromSavedInstanceState) { 180 | mDrawerLayout.openDrawer(mFragmentContainerView); 181 | } 182 | 183 | // Defer code dependent on restoration of previous instance state. 184 | mDrawerLayout.post(new Runnable() { 185 | @Override 186 | public void run() { 187 | mDrawerToggle.syncState(); 188 | } 189 | }); 190 | 191 | mDrawerLayout.setDrawerListener(mDrawerToggle); 192 | } 193 | 194 | private void selectItem(int position) { 195 | mCurrentSelectedPosition = position; 196 | if (mDrawerListView != null) { 197 | mDrawerListView.setItemChecked(position, true); 198 | } 199 | if (mDrawerLayout != null) { 200 | mDrawerLayout.closeDrawer(mFragmentContainerView); 201 | } 202 | if (mCallbacks != null) { 203 | mCallbacks.onNavigationDrawerItemSelected(position); 204 | } 205 | } 206 | 207 | @Override 208 | public void onAttach(Activity activity) { 209 | super.onAttach(activity); 210 | try { 211 | mCallbacks = (NavigationDrawerCallbacks) activity; 212 | } catch (ClassCastException e) { 213 | throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); 214 | } 215 | } 216 | 217 | @Override 218 | public void onDetach() { 219 | super.onDetach(); 220 | mCallbacks = null; 221 | } 222 | 223 | @Override 224 | public void onSaveInstanceState(Bundle outState) { 225 | super.onSaveInstanceState(outState); 226 | outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); 227 | } 228 | 229 | @Override 230 | public void onConfigurationChanged(Configuration newConfig) { 231 | super.onConfigurationChanged(newConfig); 232 | // Forward the new configuration the drawer toggle component. 233 | mDrawerToggle.onConfigurationChanged(newConfig); 234 | } 235 | 236 | @Override 237 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 238 | // If the drawer is open, show the global app actions in the action bar. See also 239 | // showGlobalContextActionBar, which controls the top-left area of the action bar. 240 | if (mDrawerLayout != null && isDrawerOpen()) { 241 | inflater.inflate(R.menu.global, menu); 242 | showGlobalContextActionBar(); 243 | } 244 | super.onCreateOptionsMenu(menu, inflater); 245 | } 246 | 247 | @Override 248 | public boolean onOptionsItemSelected(MenuItem item) { 249 | if (mDrawerToggle.onOptionsItemSelected(item)) { 250 | return true; 251 | } 252 | 253 | if (item.getItemId() == R.id.action_example) { 254 | Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); 255 | return true; 256 | } 257 | 258 | return super.onOptionsItemSelected(item); 259 | } 260 | 261 | /** 262 | * Per the navigation drawer design guidelines, updates the action bar to show the global app 263 | * 'context', rather than just what's in the current screen. 264 | */ 265 | private void showGlobalContextActionBar() { 266 | ActionBar actionBar = getActionBar(); 267 | actionBar.setDisplayShowTitleEnabled(true); 268 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); 269 | actionBar.setTitle(R.string.app_name); 270 | } 271 | 272 | private ActionBar getActionBar() { 273 | return ((AppCompatActivity) getActivity()).getSupportActionBar(); 274 | } 275 | 276 | /** 277 | * Callbacks interface that all activities using this fragment must implement. 278 | */ 279 | public static interface NavigationDrawerCallbacks { 280 | 281 | /** 282 | * Called when an item in the navigation drawer is selected. 283 | */ 284 | void onNavigationDrawerItemSelected(int position); 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-hdpi/drawer_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-hdpi/drawer_shadow.9.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-hdpi/ic_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-hdpi/ic_drawer.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-mdpi/drawer_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-mdpi/drawer_shadow.9.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-mdpi/ic_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-mdpi/ic_drawer.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-xhdpi/ic_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-xhdpi/ic_drawer.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/drawable-xxhdpi/ic_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optimizely/optimizely-api-samples/7082fc7088748203dcf5302b3094cf7377124041/mobile_dialog_and_geotargeting/app/src/main/res/drawable-xxhdpi/ic_drawer.png -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 16 | 17 | 22 | 24 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /mobile_dialog_and_geotargeting/app/src/main/res/layout/fragment_dialogs.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 |

27 | 28 |
29 | 32 | 33 | 34 | 35 |