/*
   * (non-Javadoc)
   * @see com.socialize.SocializeService#destroy(boolean)
   */
  @Override
  public synchronized void destroy(boolean force) {
    if (force) {

      if (AsyncTaskManager.isManaged()) {
        AsyncTaskManager.terminateAll(10, TimeUnit.SECONDS);
      }

      if (container != null) {
        if (logger != null && logger.isDebugEnabled()) {
          logger.debug("Destroying IOC container");
        }
        container.destroy();
      }

      config.destroy();
      system.destroy();
      initCount = 0;
      initPaths = null;
      entityLoader = null;
      session = null;
    } else {
      destroy();
    }
  }
예제 #2
0
  @Override
  public void onViewUpdate(IOCContainer container) {
    super.onViewUpdate(container);

    if (container != null) {
      setErrorHandler((SocializeErrorHandler) container.getBean("socializeUIErrorHandler"));
    }

    // Make sure we notify after authenticate to dismiss any pending dialogs.
    onAfterAuthenticate(container);
  }
예제 #3
0
  @Override
  public final void onViewLoad(IOCContainer container) {
    super.onViewLoad(container);

    setErrorHandler((SocializeErrorHandler) container.getBean("socializeUIErrorHandler"));

    consumerKey = getConsumerKey(container);
    consumerSecret = getConsumerSecret(container);
    fbAppId = getFacebookAppId(container);

    SocializeAuthListener listener = getAuthListener(container);

    onBeforeAuthenticate(container);

    getSocialize().authenticate(getContext(), consumerKey, consumerSecret, listener);
  }
 @Override
 public boolean isInitialized(Context context) {
   return this.initCount > 0 && container.getContext() == context;
 }
 protected synchronized void initEntityLoader() {
   EntityLoaderUtils entityLoaderUtils = container.getBean("entityLoaderUtils");
   entityLoaderUtils.initEntityLoader();
 }
  public synchronized void init(
      Context context, final IOCContainer container, SocializeInitListener listener) {
    if (!isInitialized()) {
      try {
        this.container = container;

        this.logger = container.getBean("logger");

        this.shareSystem = container.getBean("shareSystem");
        this.userSystem = container.getBean("userSystem");
        this.asserter = container.getBean("initializationAsserter");
        this.authProviders = container.getBean("authProviders");
        this.authProviderInfoBuilder = container.getBean("authProviderInfoBuilder");
        this.notificationChecker = container.getBean("notificationChecker");
        this.appUtils = container.getBean("appUtils");
        this.locationProvider = container.getBean("locationProvider");
        this.listenerHolder = container.getBean("listenerHolder");

        SocializeConfig mainConfig = container.getBean("config");

        mainConfig.merge(config);
        mainConfig.merge(ConfigUtils.preInitConfig);

        this.config = mainConfig;
        this.initCount++;

        verify3rdPartyAuthConfigured();

        // Create the entity loader if we have one
        initEntityLoader();

        // Check we are configured ok
        appUtils.checkAndroidManifest(context);

        ActivityIOCProvider.getInstance().setContainer(container);

        initNotifications(context);

        if (listener != null) {
          listener.onInit(context, container);
        }
      } catch (Exception e) {
        if (logger != null) {
          logger.error(SocializeLogger.INITIALIZE_FAILED, e);
        } else {
          SocializeLogger.e(e.getMessage(), e);
        }
      }
    } else {
      this.initCount++;
    }
  }
 void onContextDestroyed(Context context) {
   if (container != null) {
     container.onContextDestroyed(context);
   }
 }
 void setContext(Context context) {
   if (container != null) {
     container.setContext(context);
   }
 }
  public synchronized IOCContainer initWithContainer(
      Context context, SocializeInitListener listener, String... paths) throws Exception {
    boolean init = false;

    // Check socialize is supported on this device.
    isSocializeSupported(context);

    String[] localPaths = getInitPaths();

    if (paths != null) {

      if (isInitialized()) {

        if (localPaths != null) {
          for (String path : paths) {
            if (binarySearch(localPaths, path) < 0) {

              if (logger != null && logger.isInfoEnabled()) {
                logger.info("New path found for beans [" + path + "].  Re-initializing Socialize");
              }

              this.initCount = 0;

              // Destroy the container so we recreate bean references
              if (container != null) {
                if (logger != null && logger.isDebugEnabled()) {
                  logger.debug("Destroying IOC container");
                }
                container.destroy();
              }

              init = true;

              break;
            }
          }
        } else {
          String msg =
              "Socialize reported as initialize, but no initPaths were found.  This should not happen!";
          if (logger != null) {
            logger.error(msg);
          } else {
            System.err.println(msg);
          }

          destroy();
          init = true;
        }
      } else {
        init = true;
      }

      if (init) {
        try {
          Logger.LOG_KEY = Socialize.LOG_KEY;
          Logger.logLevel = Log.WARN;

          this.initPaths = paths;

          sort(this.initPaths);

          if (container == null) {
            container = newSocializeIOC();
          }

          ResourceLocator locator = newResourceLocator();

          locator.setLogger(newLogger());

          ClassLoaderProvider provider = newClassLoaderProvider();

          locator.setClassLoaderProvider(provider);

          if (logger != null) {

            if (logger.isDebugEnabled()) {
              for (String path : paths) {
                logger.debug("Initializing Socialize with path [" + path + "]");
              }

              Logger.logLevel = Log.DEBUG;
            } else if (logger.isInfoEnabled()) {
              Logger.logLevel = Log.INFO;
            }
          }

          ((SocializeIOC) container).init(context, locator, paths);

          init(context, container, listener); // initCount incremented here
        } catch (Exception e) {
          throw e;
        }
      } else {
        this.initCount++;
      }

      // Always set the context on the container
      setContext(context);
    } else {
      String msg = "Attempt to initialize Socialize with null bean config paths";
      if (logger != null) {
        logger.error(msg);
      } else {
        System.err.println(msg);
      }
    }

    return container;
  }