1111import android .content .Context ;
1212import android .content .pm .PackageManager ;
1313import android .content .pm .ResolveInfo ;
14- import android .os . Bundle ;
14+ import android .support . annotation . NonNull ;
1515import android .util .Log ;
1616
1717import java .io .File ;
@@ -59,59 +59,15 @@ public static final class Builder {
5959 * <p>
6060 * This context will then be passed through to the rest of the Parse SDK for use during
6161 * initialization.
62- * <p>
63- * <p/>
64- * You may define {@code com.parse.SERVER_URL}, {@code com.parse.APPLICATION_ID} and (optional) {@code com.parse.CLIENT_KEY}
65- * {@code meta-data} in your {@code AndroidManifest.xml}:
66- * <pre>
67- * <manifest ...>
68- *
69- * ...
70- *
71- * <application ...>
72- * <meta-data
73- * android:name="com.parse.SERVER_URL"
74- * android:value="@string/parse_server_url" />
75- * <meta-data
76- * android:name="com.parse.APPLICATION_ID"
77- * android:value="@string/parse_app_id" />
78- * <meta-data
79- * android:name="com.parse.CLIENT_KEY"
80- * android:value="@string/parse_client_key" />
81- *
82- * ...
83- *
84- * </application>
85- * </manifest>
86- * </pre>
87- * <p/>
88- * <p>
89- * This will cause the values for {@code server}, {@code applicationId} and {@code clientKey} to be set to
90- * those defined in your manifest.
9162 *
9263 * @param context The active {@link Context} for your application. Cannot be null.
9364 */
94- public Builder (Context context ) {
65+ public Builder (@ NonNull Context context ) {
9566 this .context = context ;
96-
97- // Yes, our public API states we cannot be null. But for unit tests, it's easier just to
98- // support null here.
99- if (context != null ) {
100- Context applicationContext = context .getApplicationContext ();
101- Bundle metaData = ManifestInfo .getApplicationMetadata (applicationContext );
102- if (metaData != null ) {
103- server (metaData .getString (PARSE_SERVER_URL ));
104- applicationId = metaData .getString (PARSE_APPLICATION_ID );
105- clientKey = metaData .getString (PARSE_CLIENT_KEY );
106- }
107- }
10867 }
10968
11069 /**
11170 * Set the application id to be used by Parse.
112- * <p>
113- * This method is only required if you intend to use a different {@code applicationId} than
114- * is defined by {@code com.parse.APPLICATION_ID} in your {@code AndroidManifest.xml}.
11571 *
11672 * @param applicationId The application id to set.
11773 * @return The same builder, for easy chaining.
@@ -123,9 +79,6 @@ public Builder applicationId(String applicationId) {
12379
12480 /**
12581 * Set the client key to be used by Parse.
126- * <p>
127- * This method is only required if you intend to use a different {@code clientKey} than
128- * is defined by {@code com.parse.CLIENT_KEY} in your {@code AndroidManifest.xml}.
12982 *
13083 * @param clientKey The client key to set.
13184 * @return The same builder, for easy chaining.
@@ -224,10 +177,6 @@ private Configuration(Builder builder) {
224177 }
225178 }
226179
227- private static final String PARSE_SERVER_URL = "com.parse.SERVER_URL" ;
228- private static final String PARSE_APPLICATION_ID = "com.parse.APPLICATION_ID" ;
229- private static final String PARSE_CLIENT_KEY = "com.parse.CLIENT_KEY" ;
230-
231180 private static final Object MUTEX = new Object ();
232181 static ParseEventuallyQueue eventuallyQueue = null ;
233182
@@ -239,7 +188,7 @@ private Configuration(Builder builder) {
239188 /**
240189 * Enable pinning in your application. This must be called before your application can use
241190 * pinning. You must invoke {@code enableLocalDatastore(Context)} before
242- * {@link #initialize(Context)} :
191+ * {@link #initialize(Configuration)} :
243192 * <p/>
244193 * <pre>
245194 * public class MyApplication extends Application {
@@ -284,99 +233,20 @@ public static boolean isLocalDatastoreEnabled() {
284233
285234 /**
286235 * Authenticates this client as belonging to your application.
287- * <p/>
288- * You may define {@code com.parse.SERVER_URL}, {@code com.parse.APPLICATION_ID} and (optional) {@code com.parse.CLIENT_KEY}
289- * {@code meta-data} in your {@code AndroidManifest.xml}:
290- * <pre>
291- * <manifest ...>
292- *
293- * ...
294- *
295- * <application ...>
296- * <meta-data
297- * android:name="com.parse.SERVER_URL"
298- * android:value="@string/parse_server_url" />
299- * <meta-data
300- * android:name="com.parse.APPLICATION_ID"
301- * android:value="@string/parse_app_id" />
302- * <meta-data
303- * android:name="com.parse.CLIENT_KEY"
304- * android:value="@string/parse_client_key" />
305- *
306- * ...
307- *
308- * </application>
309- * </manifest>
310- * </pre>
311- * <p/>
312- * This must be called before your application can use the Parse library.
313- * The recommended way is to put a call to {@code Parse.initialize}
314- * in your {@code Application}'s {@code onCreate} method:
315- * <p/>
316- * <pre>
317- * public class MyApplication extends Application {
318- * public void onCreate() {
319- * Parse.initialize(this);
320- * }
321- * }
322- * </pre>
323- *
324- * @param context The active {@link Context} for your application.
325- */
326- public static void initialize (Context context ) {
327- Configuration .Builder builder = new Configuration .Builder (context );
328- if (builder .server == null ) {
329- throw new RuntimeException ("ServerUrl not defined. " +
330- "You must provide ServerUrl in AndroidManifest.xml.\n " +
331- "<meta-data\n " +
332- " android:name=\" com.parse.SERVER_URL\" \n " +
333- " android:value=\" <Your Server Url>\" />" );
334- }
335- if (builder .applicationId == null ) {
336- throw new RuntimeException ("ApplicationId not defined. " +
337- "You must provide ApplicationId in AndroidManifest.xml.\n " +
338- "<meta-data\n " +
339- " android:name=\" com.parse.APPLICATION_ID\" \n " +
340- " android:value=\" <Your Application Id>\" />" );
341- }
342- initialize (builder
343- .setLocalDatastoreEnabled (isLocalDatastoreEnabled )
344- .build ()
345- );
346- }
347-
348- /**
349- * Authenticates this client as belonging to your application.
350- * <p/>
351- * This method is only required if you intend to use a different {@code applicationId} or
352- * {@code clientKey} than is defined by {@code com.parse.APPLICATION_ID} or
353- * {@code com.parse.CLIENT_KEY} in your {@code AndroidManifest.xml}.
354- * <p/>
355236 * This must be called before your
356237 * application can use the Parse library. The recommended way is to put a call to
357238 * {@code Parse.initialize} in your {@code Application}'s {@code onCreate} method:
358239 * <p/>
359240 * <pre>
360241 * public class MyApplication extends Application {
361242 * public void onCreate() {
362- * Parse.initialize(this, "your application id", "your client key" );
243+ * Parse.initialize(configuration );
363244 * }
364245 * }
365246 * </pre>
366247 *
367- * @param context The active {@link Context} for your application.
368- * @param applicationId The application id provided in the Parse dashboard.
369- * @param clientKey The client key provided in the Parse dashboard.
248+ * @param configuration The configuration for your application.
370249 */
371- public static void initialize (Context context , String applicationId , String clientKey ) {
372- initialize (new Configuration .Builder (context )
373- .applicationId (applicationId )
374- .clientKey (clientKey )
375- .setLocalDatastoreEnabled (isLocalDatastoreEnabled )
376- .build ()
377- );
378- }
379-
380250 public static void initialize (Configuration configuration ) {
381251 if (isInitialized ()) {
382252 PLog .w (TAG , "Parse is already initialized" );
0 commit comments