Example #1
0
  public void sync365(
      boolean riliSource, boolean eventSource, boolean noteSource, boolean birthSource) {

    AppInitializer initializer = new AppInitializer();
    initializer.init(this.context, this.handler, riliSource, eventSource, noteSource, birthSource);
    Configuration configuration = initializer.getConfiguration();

    Vector<AppSyncSource> sources = initializer.getSourcesToSync();
    if (sources == null || sources.size() == 0) {
      SyncLock.getInstance().releaseLock();
      if (SyncService.isWaiting()) {
        SyncService.synchronizeWaiting(context);
      }
      return;
    }
    try {
      NetworkStatus networkStatus = new NetworkStatus(this.context);
      SyncEngine syncEngine = new SyncEngine(configuration, networkStatus);
      CalendarSyncEngineListener listener =
          new CalendarSyncEngineListener(this.context, this.handler);
      syncEngine.setListener(listener);
      syncEngine.synchronize(sources);
    } catch (Exception e) {
      SyncLock.getInstance().releaseLock();
      if (SyncService.isWaiting()) {
        SyncService.synchronizeWaiting(context);
      }
    } finally {

    }
  }
Example #2
0
  public void run() {
    // 判断网络连接apn,如果是wap则设置代理,供HttpConnectionAdapter使用
    NetType netType = NetworkControl.getNetType(context);
    if (netType != null && netType.isWap()) {
      SyncService.proxy =
          new Proxy(
              java.net.Proxy.Type.HTTP,
              new InetSocketAddress(netType.getProxy(), netType.getPort()));
    } else {
      SyncService.proxy = null;
    }

    MyAccountManager accountControl = new MyAccountManager(this.context);
    AccountEntity account = accountControl.getAccount();
    if (account.getGoogleAccountState() == AccountEntity.GOOGLE_USER_BIND) // 有google帐号时才同步google
    {
      SyncControl.updateLastSyncTime(context, System.currentTimeMillis());
      SyncControl.setNextSync(context);
      SyncService.syncGoogleCalendar(true, this.handler, this.context);
    }
  }