/*
 * Copyright (C) 2011 Pixmob (http://github.com/pixmob)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pixmob.droidlink;

import static com.pixmob.droidlink.Constants.DEVELOPER_MODE;
import static com.pixmob.droidlink.Constants.SHARED_PREFERENCES_FILE;
import static com.pixmob.droidlink.Constants.SP_KEY_ACCOUNT;
import static com.pixmob.droidlink.Constants.SP_KEY_IGNORE_MISSED_CALLS;
import static com.pixmob.droidlink.Constants.SP_KEY_IGNORE_RECEIVED_SMS;
import android.accounts.Account;
import android.content.Intent;
import android.content.SharedPreferences;

import com.pixmob.droidlink.feature.Features;
import com.pixmob.droidlink.feature.SharedPreferencesSaverFeature;
import com.pixmob.droidlink.feature.StrictModeFeature;
import com.pixmob.droidlink.service.DeviceInitService;
import com.pixmob.droidlink.util.Accounts;

/**
 * Application entry point.
 * @author Pixmob
 */
public class Application extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        if (DEVELOPER_MODE) {
            // Enable StrictMode if it's available.
            Features.getFeature(StrictModeFeature.class).enable();
        }
        
        // Set default values for preferences.
        final SharedPreferences prefs = getSharedPreferences(SHARED_PREFERENCES_FILE, MODE_PRIVATE);
        final SharedPreferences.Editor prefsEditor = prefs.edit();
        prefsEditor.putBoolean(SP_KEY_IGNORE_MISSED_CALLS, true);
        prefsEditor.putBoolean(SP_KEY_IGNORE_RECEIVED_SMS, true);
        
        // If there is only one account, select it.
        final Account[] accounts = Accounts.list(this);
        if (accounts.length == 1) {
            prefsEditor.putString(SP_KEY_ACCOUNT, accounts[0].name);
        }
        
        Features.getFeature(SharedPreferencesSaverFeature.class).save(prefsEditor);
        
        // Make sure a device id is generated for this device.
        startService(new Intent(this, DeviceInitService.class));
    }
}

@@ -862,156 +862,8 @@
 T;%0D%0A
-import static com.pixmob.droidlink.Constants.SP_KEY_IGNORE_MISSED_CALLS;%0D%0Aimport static com.pixmob.droidlink.Constants.SP_KEY_IGNORE_RECEIVED_SMS;%0D%0A
 impo
@@ -1630,45 +1630,148 @@
  // 
-Set default values for preferences.%0D%0A
+If there is only one account, select it.%0D%0A        final Account%5B%5D accounts = Accounts.list(this);%0D%0A        if (accounts.length == 1) %7B%0D%0A    
     
@@ -1851,16 +1851,33 @@
 ES_FILE,
+%0D%0A               
  MODE_PR
@@ -1881,24 +1881,28 @@
 _PRIVATE);%0D%0A
+    
         fina
@@ -1961,299 +1961,8 @@
 );%0D%0A
-        prefsEditor.putBoolean(SP_KEY_IGNORE_MISSED_CALLS, true);%0D%0A        prefsEditor.putBoolean(SP_KEY_IGNORE_RECEIVED_SMS, true);%0D%0A        %0D%0A        // If there is only one account, select it.%0D%0A        final Account%5B%5D accounts = Accounts.list(this);%0D%0A        if (accounts.length == 1) %7B%0D%0A
     
@@ -2031,33 +2031,16 @@
 );%0D%0A    
-    %7D%0D%0A        %0D%0A
         
@@ -2112,24 +2112,35 @@
 fsEditor);%0D%0A
+        %7D%0D%0A
         %0D%0A  

Fix default values for preferences