Search in sources :

Example 1 with AndroidPhoneBook

use of im.actor.sdk.core.AndroidPhoneBook 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)

Example 2 with AndroidPhoneBook

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

the class InviteFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fragment_list, container, false);
    res.findViewById(R.id.listView).setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    emptyText = (TextView) res.findViewById(R.id.emptyView);
    emptyText.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    emptyText.setText(R.string.progress_common);
    collection = (RecyclerListView) res.findViewById(R.id.listView);
    AndroidPhoneBook phoneBookLoader = new AndroidPhoneBook();
    phoneBookLoader.useDelay(false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    phoneBookLoader.loadPhoneBook(contacts -> {
        if (contacts.size() > 0) {
            getActivity().runOnUiThread(() -> {
                InviteFragment.this.contacts = contacts;
                adapter = new InviteAdapter(getActivity(), contacts, new OnItemClickedListener<PhoneBookContact>() {

                    @Override
                    public void onClicked(PhoneBookContact item) {
                        onItemClicked(item);
                    }

                    @Override
                    public boolean onLongClicked(PhoneBookContact item) {
                        return false;
                    }
                });
                collection.setAdapter(adapter);
                hideView(emptyText);
                showView(collection);
                showMenu();
            });
        }
    });
    return res;
}
Also used : PhoneBookContact(im.actor.core.entity.PhoneBookContact) OnItemClickedListener(im.actor.sdk.view.adapters.OnItemClickedListener) TextView(android.widget.TextView) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) AndroidPhoneBook(im.actor.sdk.core.AndroidPhoneBook)

Aggregations

AndroidPhoneBook (im.actor.sdk.core.AndroidPhoneBook)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)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 PhoneBookContact (im.actor.core.entity.PhoneBookContact)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 ActorIntent (im.actor.sdk.intents.ActorIntent)1 OnItemClickedListener (im.actor.sdk.view.adapters.OnItemClickedListener)1 RecyclerListView (im.actor.sdk.view.adapters.RecyclerListView)1 SmileProcessor (im.actor.sdk.view.emoji.SmileProcessor)1 Locale (java.util.Locale)1