示例#1
0
  // Only for test
  private int getVideoDimens() {

    File file = new File("sdcard/nim.properties");

    if (file.exists()) {
      InputStream is = null;

      try {
        is = new BufferedInputStream(new FileInputStream(file));
        Properties properties = new Properties();
        properties.load(is);
        int dimens = Integer.parseInt(properties.getProperty("avchat.video.dimens", "0"));
        LogUtil.i(TAG, "dimes:" + dimens);
        return dimens;
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }

    return 0;
  }
  public void buildCache() {
    // 获取我所有的好友关系
    List<Friend> friends = NIMClient.getService(FriendService.class).getFriends();
    for (Friend f : friends) {
      friendMap.put(f.getAccount(), f);
    }

    // 获取我所有好友的帐号
    List<String> accounts = NIMClient.getService(FriendService.class).getFriendAccounts();
    if (accounts == null || accounts.isEmpty()) {
      return;
    }

    // 排除黑名单
    List<String> blacks = NIMClient.getService(FriendService.class).getBlackList();
    accounts.removeAll(blacks);

    // 排除掉自己
    accounts.remove(NimUIKit.getAccount());

    // 确定缓存
    friendAccountSet.addAll(accounts);

    LogUtil.i(
        UIKitLogTag.FRIEND_CACHE,
        "build FriendDataCache completed, friends count = " + friendAccountSet.size());
  }
示例#3
0
  private void init(ImageLoaderConfiguration config) {
    try {
      ImageLoader.getInstance().init(config == null ? getDefaultConfig() : config);
    } catch (IOException e) {
      LogUtil.e(TAG, "init ImageLoaderKit error, e=" + e.getMessage().toString());
    }

    LogUtil.i(TAG, "init ImageLoaderKit completed");
  }
示例#4
0
  /** 构建头像缓存 */
  public static void buildAvatarCache(List<String> accounts) {
    if (accounts == null || accounts.isEmpty()) {
      return;
    }

    UserInfoProvider.UserInfo userInfo;
    for (String account : accounts) {
      userInfo = NimUIKit.getUserInfoProvider().getUserInfo(account);
      asyncLoadAvatarBitmapToCache(userInfo);
    }

    LogUtil.i(TAG, "build avatar cache completed, avatar count =" + accounts.size());
  }
示例#5
0
  private ImageLoaderConfiguration getDefaultConfig() throws IOException {
    int MAX_CACHE_MEMORY_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8);
    File cacheDir =
        StorageUtils.getOwnCacheDirectory(context, context.getPackageName() + "/cache/image/");

    LogUtil.i(TAG, "ImageLoader memory cache size = " + MAX_CACHE_MEMORY_SIZE / M + "M");
    LogUtil.i(TAG, "ImageLoader disk cache directory = " + cacheDir.getAbsolutePath());

    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(context)
            .threadPoolSize(3) // 线程池内加载的数量
            .threadPriority(Thread.NORM_PRIORITY - 2) // 降低线程的优先级,减小对UI主线程的影响
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new LruMemoryCache(MAX_CACHE_MEMORY_SIZE))
            .discCache(new LruDiskCache(cacheDir, new Md5FileNameGenerator(), 0))
            .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            .imageDownloader(
                new BaseImageDownloader(
                    context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
            .writeDebugLogs()
            .build();

    return config;
  }