当前位置: 首页>>代码示例>>Java>>正文


Java MXSession.setSyncDelay方法代码示例

本文整理汇总了Java中org.matrix.androidsdk.MXSession.setSyncDelay方法的典型用法代码示例。如果您正苦于以下问题:Java MXSession.setSyncDelay方法的具体用法?Java MXSession.setSyncDelay怎么用?Java MXSession.setSyncDelay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.matrix.androidsdk.MXSession的用法示例。


在下文中一共展示了MXSession.setSyncDelay方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: suspendApp

import org.matrix.androidsdk.MXSession; //导入方法依赖的package包/类
/**
 * Suspend background threads.
 */
private void suspendApp() {
    GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(VectorApp.this).getSharedGCMRegistrationManager();

    // suspend the events thread if the client uses GCM
    if (!gcmRegistrationManager.isBackgroundSyncAllowed() || (gcmRegistrationManager.useGCM() && gcmRegistrationManager.hasRegistrationToken())) {
        Log.d(LOG_TAG, "suspendApp ; pause the event stream");
        CommonActivityUtils.pauseEventStream(VectorApp.this);
    } else {
        Log.d(LOG_TAG, "suspendApp ; the event stream is not paused because GCM is disabled.");
    }

    // the sessions are not anymore seen as "online"
    ArrayList<MXSession> sessions = Matrix.getInstance(this).getSessions();

    for (MXSession session : sessions) {
        if (session.isAlive()) {
            session.setIsOnline(false);
            session.setSyncDelay(gcmRegistrationManager.isBackgroundSyncAllowed() ? gcmRegistrationManager.getBackgroundSyncDelay() : 0);
            session.setSyncTimeout(gcmRegistrationManager.getBackgroundSyncTimeOut());

            // remove older medias
            if ((System.currentTimeMillis() - mLastMediasCheck) < (24 * 60 * 60 * 1000)) {
                mLastMediasCheck = System.currentTimeMillis();
                session.removeMediasBefore(VectorApp.this, PreferencesManager.getMinMediasLastAccessTime(getApplicationContext()));
            }

            if (session.getDataHandler().areLeftRoomsSynced()) {
                session.getDataHandler().releaseLeftRooms();
            }
        }
    }

    clearSyncingSessions();

    PIDsRetriever.getInstance().onAppBackgrounded();

    MyPresenceManager.advertiseAllUnavailable();

    onAppPause();
}
 
开发者ID:vector-im,项目名称:riot-android,代码行数:44,代码来源:VectorApp.java

示例2: stopActivityTransitionTimer

import org.matrix.androidsdk.MXSession; //导入方法依赖的package包/类
/**
 * Stop the background detection.
 */
private void stopActivityTransitionTimer() {
    Log.d(LOG_TAG, "## stopActivityTransitionTimer()");

    if (mActivityTransitionTimerTask != null) {
        mActivityTransitionTimerTask.cancel();
        mActivityTransitionTimerTask = null;
    }

    if (mActivityTransitionTimer != null) {
        mActivityTransitionTimer.cancel();
        mActivityTransitionTimer = null;
    }

    if (isAppInBackground() && !mIsCallingInBackground) {
        // the event stream service has been killed
        if (EventStreamService.isStopped()) {
            CommonActivityUtils.startEventStreamService(VectorApp.this);
        } else {
            CommonActivityUtils.resumeEventStream(VectorApp.this);

            // try to perform a GCM registration if it failed
            // or if the GCM server generated a new push key
            GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(this).getSharedGCMRegistrationManager();

            if (null != gcmRegistrationManager) {
                gcmRegistrationManager.checkRegistrations();
            }
        }

        // get the contact update at application launch
        ContactsManager.getInstance().clearSnapshot();
        ContactsManager.getInstance().refreshLocalContactsSnapshot();

        List<MXSession> sessions = Matrix.getInstance(this).getSessions();
        for (MXSession session : sessions) {
            session.getMyUser().refreshUserInfos(null);
            session.setIsOnline(true);
            session.setSyncDelay(0);
            session.setSyncTimeout(0);
            addSyncingSession(session);
        }

        mCallsManager.checkDeadCalls();
        Matrix.getInstance(this).getSharedGCMRegistrationManager().onAppResume();
    }

    MyPresenceManager.advertiseAllOnline();

    mIsCallingInBackground = false;
    mIsInBackground = false;
}
 
开发者ID:vector-im,项目名称:riot-android,代码行数:55,代码来源:VectorApp.java

示例3: startEventStreamService

import org.matrix.androidsdk.MXSession; //导入方法依赖的package包/类
/**
 * Start the events stream service.
 *
 * @param context the context.
 */
public static void startEventStreamService(Context context) {
    // the events stream service is launched
    // either the application has never be launched
    // or the service has been killed on low memory
    if (EventStreamService.isStopped()) {
        ArrayList<String> matrixIds = new ArrayList<>();
        Collection<MXSession> sessions = Matrix.getInstance(context.getApplicationContext()).getSessions();

        if ((null != sessions) && (sessions.size() > 0)) {
            GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(context).getSharedGCMRegistrationManager();
            Log.e(LOG_TAG, "## startEventStreamService() : restart EventStreamService");

            for (MXSession session : sessions) {
                // reported by GA
                if ((null != session.getDataHandler()) && (null != session.getDataHandler().getStore())) {
                    boolean isSessionReady = session.getDataHandler().getStore().isReady();

                    if (!isSessionReady) {
                        Log.e(LOG_TAG, "## startEventStreamService() : the session " + session.getMyUserId() + " is not opened");
                        session.getDataHandler().getStore().open();
                    } else {
                        // it seems that the crypto is not always restarted properly after a crash
                        Log.e(LOG_TAG, "## startEventStreamService() : check if the crypto of the session " + session.getMyUserId());
                        session.checkCrypto();
                    }

                    session.setSyncDelay(gcmRegistrationManager.isBackgroundSyncAllowed() ? gcmRegistrationManager.getBackgroundSyncDelay() : 0);
                    session.setSyncTimeout(gcmRegistrationManager.getBackgroundSyncTimeOut());

                    // session to activate
                    matrixIds.add(session.getCredentials().userId);
                }
            }

            // check size
            if (matrixIds.size() > 0) {
                Intent intent = new Intent(context, EventStreamService.class);
                intent.putExtra(EventStreamService.EXTRA_MATRIX_IDS, matrixIds.toArray(new String[matrixIds.size()]));
                intent.putExtra(EventStreamService.EXTRA_STREAM_ACTION, EventStreamService.StreamAction.START.ordinal());
                context.startService(intent);
            }
        }
    }
}
 
开发者ID:vector-im,项目名称:riot-android,代码行数:50,代码来源:CommonActivityUtils.java


注:本文中的org.matrix.androidsdk.MXSession.setSyncDelay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。