/** * Configure PlayHaven * * @param context of the application * @param token configured in the PlayHaven Dashboard * @param secret configured in the PlayHaven Dashboard * @param projectId for push notification, optionally configured in PlayHaven Dashboard * @throws PlayHavenException if a problem occurs * @see <a href="https://dashboard.playhaven.com/">https://dashboard.playhaven.com/</a> */ public static void configure(Context context, String token, String secret, String projectId) throws PlayHavenException { // Minimal validation validateToken(token); validateSecret(secret); // Setup default configuration values SharedPreferences.Editor editor = defaultConfiguration(context); // Setup PlayHaven values editor.putString(Config.Token.toString(), token); editor.putString(Config.Secret.toString(), secret); editor.putString(Config.PushProjectId.toString(), projectId); // And commit it editor.commit(); /** * This will generate a log that looks like this: * * <pre>D/PlayHaven( 754): PlayHaven initialized: 2.0.0-SNAPSHOT-fe5c52f** 2012-11-21 08:45 * </pre> * * Which can then be used to find the actual commit the version was against: <code> * git log -n 1 fe5c52f</code> */ i("PlayHaven initialized: %s", Version.BANNER); debugConfig(context); }
/** * Log the configured key/value pairs to logcat using the DEBUG log level * * @param context of the application */ private static void debugConfig(Context context) { // Application-wide configuration Context appContext = context.getApplicationContext(); // PlayHaven specific configuration for this Application SharedPreferences pref = appContext.getSharedPreferences(SHARED_PREF_NAME, SHARED_PREF_MODE); Map<String, ?> map = pref.getAll(); d("Configuration Parameters"); for (String key : map.keySet()) { // don't output the Secret to the logs if (key.equals(Config.Secret.toString())) continue; d("%s: %s", key, map.get(key)); } }