<commit_before>package ly.count.android.api;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.OpenUDID.OpenUDID_manager;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

public class Countly {
    private static Countly sharedInstance_;
    private Timer timer_;
    private ConnectionQueue queue_;
    private EventQueue eventQueue_;
    private boolean isVisible_;
    private double unsentSessionLength_;
    private double lastTime_;
    private int activityCount_;
    private CountlyStore countlyStore_;

    protected static final int SESSION_DURATION_WHEN_TIME_ADJUSTED = 15;

    static public Countly sharedInstance() {
        if (sharedInstance_ == null)
            sharedInstance_ = new Countly();

        return sharedInstance_;
    }

    private Countly() {
        queue_ = new ConnectionQueue();
        timer_ = new Timer();
        timer_.schedule(new TimerTask() {
            @Override
            public void run() {
                onTimer();
            }
        }, 60 * 1000, 60 * 1000);

        isVisible_ = false;
        unsentSessionLength_ = 0;
        activityCount_ = 0;
    }

    public void init(Context context, String serverURL, String appKey) {
        init(context, serverURL, appKey, null, null, null);
    }

    /**
     * Make it compatible with old init method
     * 
     * @param context
     * @param serverURL
     * @param appKey
     * @param region
     * @param server
     * @param channel
     * 
     * @author wangqi 2014-05-20 
     */
    public void init(Context context, String serverURL, String appKey, 
    		String region, String server, String channel) {
    	
        OpenUDID_manager.sync(context);
        countlyStore_ = new CountlyStore(context);

        queue_.setContext(context);
        queue_.setServerURL(serverURL);
        queue_.setAppKey(appKey);
        /**
         * Check first if the additional fields are set.
         * wangqi 2014-05-20
         */
        if ( region != null ) {
        	queue_.setRegion(region);
        }
        if ( server != null ) {
        	queue_.setServer(server);	
        }
        if ( channel != null ) {
        	queue_.setChannel(channel);
        }
        queue_.setCountlyStore(countlyStore_);

        eventQueue_ = new EventQueue(countlyStore_);
    }
    
    public void onStart() {
        activityCount_++;
        if (activityCount_ == 1)
            onStartHelper();
    }

    public void onStop() {
        activityCount_--;
        if (activityCount_ == 0)<commit_msg>Add setServer setChannel and setRegion methods<commit_after>package ly.count.android.api;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.OpenUDID.OpenUDID_manager;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

public class Countly {
    private static Countly sharedInstance_;
    private Timer timer_;
    private ConnectionQueue queue_;
    private EventQueue eventQueue_;
    private boolean isVisible_;
    private double unsentSessionLength_;
    private double lastTime_;
    private int activityCount_;
    private CountlyStore countlyStore_;

    protected static final int SESSION_DURATION_WHEN_TIME_ADJUSTED = 15;

    static public Countly sharedInstance() {
        if (sharedInstance_ == null)
            sharedInstance_ = new Countly();

        return sharedInstance_;
    }

    private Countly() {
        queue_ = new ConnectionQueue();
        timer_ = new Timer();
        timer_.schedule(new TimerTask() {
            @Override
            public void run() {
                onTimer();
            }
        }, 60 * 1000, 60 * 1000);

        isVisible_ = false;
        unsentSessionLength_ = 0;
        activityCount_ = 0;
    }

    public void init(Context context, String serverURL, String appKey) {
        init(context, serverURL, appKey, null, null, null);
    }

    /**
     * Make it compatible with old init method
     * 
     * @param context
     * @param serverURL
     * @param appKey
     * @param region
     * @param server
     * @param channel
     * 
     * @author wangqi 2014-05-20 
     */
    public void init(Context context, String serverURL, String appKey, 
    		String region, String server, String channel) {
    	
        OpenUDID_manager.sync(context);
        countlyStore_ = new CountlyStore(context);

        queue_.setContext(context);
        queue_.setServerURL(serverURL);
        queue_.setAppKey(appKey);
        /**
         * Check first if the additional fields are set.
         * wangqi 2014-05-20
         */
        if ( region != null ) {
        	queue_.setRegion(region);
        }
        if ( server != null ) {
        	queue_.setServer(server);	
        }
        if ( channel != null ) {
        	queue_.setChannel(channel);
        }
        queue_.setCountlyStore(countlyStore_);

        eventQueue_ = new EventQueue(countlyStore_);
    }
    
    public void setServer(String server) {
    	queue_.setServer(server);
    }

    public void setChannel(String channel) {
    	queue_.setChannel(channel);
    }
    
    public void setRegion(String region) {
    	queue_.setRegion(region);
    }
    
    public void onStart() {
        activityCount_++;
        if (activityCount_ == 1)
            onStartHelper();
    }

    public void onStop() {
        activityCount_--;
        if (activityCount_ == 0)
{'fraction_non_alphanumeric': 0.09114212475078325, 'fraction_numerical': 0.00968385075477072, 'mean_word_length': 2.66162669447341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '253592', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1943, 'n_words': 487}