<commit_before>package com.hyphenate.chatuidemo;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.util.Log;

import com.hyphenate.EMCallBack;
import com.hyphenate.EMConnectionListener;
import com.hyphenate.EMError;
import com.hyphenate.EMMessageListener;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMCmdMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMMessage.ChatType;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.chatuidemo.call.CallReceiver;
import com.hyphenate.chatuidemo.call.CallStateChangeListener;
import com.hyphenate.chatuidemo.call.VideoCallActivity;
import com.hyphenate.chatuidemo.call.VoiceCallActivity;
import com.hyphenate.chatuidemo.chat.ChatActivity;
import com.hyphenate.chatuidemo.chat.MessageNotifier;
import com.hyphenate.chatuidemo.group.GroupChangeListener;
import com.hyphenate.chatuidemo.ui.MainActivity;
import com.hyphenate.chatuidemo.user.ContactsChangeListener;
import com.hyphenate.chatuidemo.user.model.UserEntity;
import com.hyphenate.chatuidemo.user.model.UserProfileManager;
import com.hyphenate.easeui.EaseUI;
import com.hyphenate.easeui.model.EaseUser;
import com.hyphenate.easeui.utils.EaseCommonUtils;
import com.hyphenate.util.EMLog;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by wei on 2016/10/11.
 * Demo app helper class
 */
public class DemoHelper {

    protected static final String TAG = DemoHelper.class.getSimpleName();

    //
    private static DemoHelper instance;

    // context
    private Context mContext;

    // Call broadcast receiver
    private CallReceiver mCallReceiver = null;

    // Call state listener
    private CallStateChangeListener mCallStateChangeListener = null;

    // Contacts listener
    private ContactsChangeListener mContactListener = null;

    private DefaultGroupChangeListener mGroupListener = null;

    private UserProfileManager mUserManager;

    //whether in calling
    public boolean isVoiceCalling;
    public boolean isVideoCalling;

    /**
     * save foreground Activity which registered message listeners
     */
    private List<Activity> activityList = new ArrayList<Activity>();

    private MessageNotifier mNotifier = new MessageNotifier();

    private DemoHelper() {
    }

    public synchronized static DemoHelper getInstance() {
        if (instance == null) {
            instance = new DemoHelper();
        }
        return instance;
    }

    /**
     * init helper
     *
     * @param context application context
     */
    public void init(Context context) {
        mContext = context;

        if (isMainProcess()) {
            EMLog.d(TAG, "------- init hyphenate start --------------");
            //init hyphenate sdk with options
            EMClient.getInstance().init(context, initOptions());
            // init call options
            initCallOptions();
            // set debug mode open:true, close:false
            EMClient.getInstance().setDebugMode(true);
            //init EaseUI if you want to use it
            EaseUI.getInstance().init(context);
            PreferenceManager.init(context);
            //init user manager
            getUserManager().init(context);
            //init message notifier
            mNotifier.init(context);
            //set events listeners
            setGlobalListener();
            setEaseUIProviders();

            EMLog.d(TAG, "------- init hyphenate end --------------");
        }
    }

    /**
     * init sdk options
     */
    private EMOptions initOptions() {
        // set init sdk options
        EMOptions options = new EMOptions();
        // change to need confirm contact invitation
        options.setAcceptInvitationAlways(false);
        // set if need read ack
        options.setRequireAck(true);
        // set if need delivery ack
        options.setRequireDeliveryAck(false);
        // set auto accept group invitation
        SharedPreferences preferences =
                android.preference.PreferenceManager.getDefaultSharedPreferences(mContext);
        options.setAutoAcceptGroupInvitation(preferences.getBoolean(
                mContext.getString(R.string.em_pref_key_accept_group_invite_automatically), false));

        //set gcm project number
        options.setGCMNumber("324169311137");

        return options;
    }

    /**
     * init call options
     */
    private void initCallOptions() {
        // set video call bitrate, default(150)
        EMClient.getInstance().callManager().getCallOptions().setMaxVideoKbps(800);

        // set video call resolution, default(320, 240)
        EMClient.getInstance().callManager().getCallOptions().setVideoResolution(640, 480);

        // send push notification when user offline
        EMClient.getInstance().callManager().getCallOptions().setIsSendPushIfOffline(false);
    }

    /**
     * init global listener
     */
    private void setGlobalListener() {
        // set call listener
        setCallReceiverListener();
        // set connection listener
        setConnectionListener();

        // register message listener
        registerMessageListener();

        // register contacts listener
        registerContactsListener();

        registerGroupListener();
    }

    private void registerGroupListener() {
        if (mGroupListener == null) {
            mGroupListener = new DefaultGroupChangeListener();
        }

        EMClient.getInstance().groupManager().addGroupChangeListener(mGroupListener);
    }

    private class DefaultGroupChangeListener extends GroupChangeListener {
        @Override public void onInvitationReceived(String s, String s1, String s2, String s3) {<commit_msg>enable push notification when remote user offline.<commit_after>package com.hyphenate.chatuidemo;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.util.Log;

import com.hyphenate.EMCallBack;
import com.hyphenate.EMConnectionListener;
import com.hyphenate.EMError;
import com.hyphenate.EMMessageListener;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMCmdMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMMessage.ChatType;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.chatuidemo.call.CallReceiver;
import com.hyphenate.chatuidemo.call.CallStateChangeListener;
import com.hyphenate.chatuidemo.call.VideoCallActivity;
import com.hyphenate.chatuidemo.call.VoiceCallActivity;
import com.hyphenate.chatuidemo.chat.ChatActivity;
import com.hyphenate.chatuidemo.chat.MessageNotifier;
import com.hyphenate.chatuidemo.group.GroupChangeListener;
import com.hyphenate.chatuidemo.ui.MainActivity;
import com.hyphenate.chatuidemo.user.ContactsChangeListener;
import com.hyphenate.chatuidemo.user.model.UserEntity;
import com.hyphenate.chatuidemo.user.model.UserProfileManager;
import com.hyphenate.easeui.EaseUI;
import com.hyphenate.easeui.model.EaseUser;
import com.hyphenate.easeui.utils.EaseCommonUtils;
import com.hyphenate.util.EMLog;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by wei on 2016/10/11.
 * Demo app helper class
 */
public class DemoHelper {

    protected static final String TAG = DemoHelper.class.getSimpleName();

    //
    private static DemoHelper instance;

    // context
    private Context mContext;

    // Call broadcast receiver
    private CallReceiver mCallReceiver = null;

    // Call state listener
    private CallStateChangeListener mCallStateChangeListener = null;

    // Contacts listener
    private ContactsChangeListener mContactListener = null;

    private DefaultGroupChangeListener mGroupListener = null;

    private UserProfileManager mUserManager;

    //whether in calling
    public boolean isVoiceCalling;
    public boolean isVideoCalling;

    /**
     * save foreground Activity which registered message listeners
     */
    private List<Activity> activityList = new ArrayList<Activity>();

    private MessageNotifier mNotifier = new MessageNotifier();

    private DemoHelper() {
    }

    public synchronized static DemoHelper getInstance() {
        if (instance == null) {
            instance = new DemoHelper();
        }
        return instance;
    }

    /**
     * init helper
     *
     * @param context application context
     */
    public void init(Context context) {
        mContext = context;

        if (isMainProcess()) {
            EMLog.d(TAG, "------- init hyphenate start --------------");
            //init hyphenate sdk with options
            EMClient.getInstance().init(context, initOptions());
            // init call options
            initCallOptions();
            // set debug mode open:true, close:false
            EMClient.getInstance().setDebugMode(true);
            //init EaseUI if you want to use it
            EaseUI.getInstance().init(context);
            PreferenceManager.init(context);
            //init user manager
            getUserManager().init(context);
            //init message notifier
            mNotifier.init(context);
            //set events listeners
            setGlobalListener();
            setEaseUIProviders();

            EMLog.d(TAG, "------- init hyphenate end --------------");
        }
    }

    /**
     * init sdk options
     */
    private EMOptions initOptions() {
        // set init sdk options
        EMOptions options = new EMOptions();
        // change to need confirm contact invitation
        options.setAcceptInvitationAlways(false);
        // set if need read ack
        options.setRequireAck(true);
        // set if need delivery ack
        options.setRequireDeliveryAck(false);
        // set auto accept group invitation
        SharedPreferences preferences =
                android.preference.PreferenceManager.getDefaultSharedPreferences(mContext);
        options.setAutoAcceptGroupInvitation(preferences.getBoolean(
                mContext.getString(R.string.em_pref_key_accept_group_invite_automatically), false));

        //set gcm project number
        options.setGCMNumber("324169311137");

        return options;
    }

    /**
     * init call options
     */
    private void initCallOptions() {
        // set video call bitrate, default(150)
        EMClient.getInstance().callManager().getCallOptions().setMaxVideoKbps(800);

        // set video call resolution, default(320, 240)
        EMClient.getInstance().callManager().getCallOptions().setVideoResolution(640, 480);

        // send push notification when user offline
        EMClient.getInstance().callManager().getCallOptions().setIsSendPushIfOffline(true);
    }

    /**
     * init global listener
     */
    private void setGlobalListener() {
        // set call listener
        setCallReceiverListener();
        // set connection listener
        setConnectionListener();

        // register message listener
        registerMessageListener();

        // register contacts listener
        registerContactsListener();

        registerGroupListener();
    }

    private void registerGroupListener() {
        if (mGroupListener == null) {
            mGroupListener = new DefaultGroupChangeListener();
        }

        EMClient.getInstance().groupManager().addGroupChangeListener(mGroupListener);
    }

    private class DefaultGroupChangeListener extends GroupChangeListener {
        @Override public void onInvitationReceived(String s, String s1, String s2, String s3) {
{'fraction_non_alphanumeric': 0.09457638537982146, 'fraction_numerical': 0.0069058447027118075, 'mean_word_length': 2.883257030739045, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2557841', 'n_tokens_mistral': 3286, 'n_tokens_neox': 3104, 'n_words': 716}