Search in sources :

Example 1 with ConfigurationBuilder

use of im.actor.core.ConfigurationBuilder in project actor-platform by actorapp.

the class ActorSDK method createActor.

//
// SDK Initialization
//
public void createActor(final Application application) {
    this.application = application;
    ThreadDispatcher.pushDispatcher(Runtime::postToMainThread);
    Runtime.dispatch(() -> {
        //
        // SDK Tools
        //
        ImagePipelineConfig config = ImagePipelineConfig.newBuilder(application).setDownsampleEnabled(true).build();
        Fresco.initialize(application, config);
        SmileProcessor emojiProcessor = new SmileProcessor(application);
        ActorSystem.system().addDispatcher("voice_capture_dispatcher", 1);
        //
        // SDK Configuration
        //
        ConfigurationBuilder builder = new ConfigurationBuilder();
        for (String s : endpoints) {
            builder.addEndpoint(s);
        }
        for (String t : trustedKeys) {
            builder.addTrustedKey(t);
        }
        builder.setPhoneBookProvider(new AndroidPhoneBook());
        builder.setVideoCallsEnabled(videoCallsEnabled);
        builder.setOnClientPrivacyEnabled(onClientPrivacyEnabled);
        builder.setNotificationProvider(new AndroidNotifications(application));
        builder.setDeviceCategory(DeviceCategory.MOBILE);
        builder.setPlatformType(PlatformType.ANDROID);
        builder.setIsEnabledGroupedChatList(false);
        builder.setApiConfiguration(new ApiConfiguration(appName, apiAppId, apiAppKey, Devices.getDeviceName(), AndroidContext.getContext().getPackageName() + ":" + Build.SERIAL));
        //
        // Adding Locales
        //
        Locale defaultLocale = Locale.getDefault();
        Log.d(TAG, "Found Locale: " + defaultLocale.getLanguage() + "-" + defaultLocale.getCountry());
        Log.d(TAG, "Found Locale: " + defaultLocale.getLanguage());
        builder.addPreferredLanguage(defaultLocale.getLanguage() + "-" + defaultLocale.getCountry());
        builder.addPreferredLanguage(defaultLocale.getLanguage());
        //
        // Adding TimeZone
        //
        String timeZone = TimeZone.getDefault().getID();
        Log.d(TAG, "Found TimeZone: " + timeZone);
        builder.setTimeZone(timeZone);
        //
        if (customApplicationName != null) {
            builder.setCustomAppName(customApplicationName);
        }
        //
        // Calls Support
        //
        builder.setCallsProvider(new AndroidCallProvider());
        //
        // Handle raw updates
        //
        builder.setRawUpdatesHandler(getDelegate().getRawUpdatesHandler());
        //
        for (String s : autoJoinGroups) {
            builder.addAutoJoinGroup(s);
        }
        builder.setAutoJoinType(autoJoinType);
        //
        // Building Messenger
        //
        this.messenger = new AndroidMessenger(application, builder.build());
        //
        if (isKeepAliveEnabled) {
            Intent keepAliveService = new Intent(application, KeepAliveService.class);
            PendingIntent pendingIntent = PendingIntent.getService(application, 0, keepAliveService, 0);
            AlarmManager alarm = (AlarmManager) application.getSystemService(Context.ALARM_SERVICE);
            alarm.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 30 * 1000, pendingIntent);
        }
        //
        if (actorPushEndpoint != null) {
            ActorPushRegister.registerForPush(application, actorPushEndpoint, endpoint -> {
                Log.d(TAG, "On Actor push registered: " + endpoint);
                messenger.registerActorPush(endpoint);
            });
        }
        //
        try {
            if (pushId != 0) {
                final ActorPushManager pushManager = (ActorPushManager) Class.forName("im.actor.push.PushManager").newInstance();
                pushManager.registerPush(application);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        synchronized (LOAD_LOCK) {
            isLoaded = true;
            LOAD_LOCK.notifyAll();
        }
        //
        // Loading Emoji
        //
        emojiProcessor.loadEmoji();
    });
}
Also used : Locale(java.util.Locale) ConfigurationBuilder(im.actor.core.ConfigurationBuilder) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ActorIntent(im.actor.sdk.intents.ActorIntent) AndroidPhoneBook(im.actor.sdk.core.AndroidPhoneBook) AndroidMessenger(im.actor.core.AndroidMessenger) ApiConfiguration(im.actor.core.ApiConfiguration) ActorPushManager(im.actor.sdk.core.ActorPushManager) Runtime(im.actor.runtime.Runtime) AndroidCallProvider(im.actor.sdk.core.AndroidCallProvider) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) AndroidNotifications(im.actor.sdk.core.AndroidNotifications) SmileProcessor(im.actor.sdk.view.emoji.SmileProcessor)

Aggregations

AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 ImagePipelineConfig (com.facebook.imagepipeline.core.ImagePipelineConfig)1 AndroidMessenger (im.actor.core.AndroidMessenger)1 ApiConfiguration (im.actor.core.ApiConfiguration)1 ConfigurationBuilder (im.actor.core.ConfigurationBuilder)1 Runtime (im.actor.runtime.Runtime)1 ActorPushManager (im.actor.sdk.core.ActorPushManager)1 AndroidCallProvider (im.actor.sdk.core.AndroidCallProvider)1 AndroidNotifications (im.actor.sdk.core.AndroidNotifications)1 AndroidPhoneBook (im.actor.sdk.core.AndroidPhoneBook)1 ActorIntent (im.actor.sdk.intents.ActorIntent)1 SmileProcessor (im.actor.sdk.view.emoji.SmileProcessor)1 Locale (java.util.Locale)1