/**
  * {@linkplain #stop() Stops ImageLoader} and clears current configuration. <br>
  * You can {@linkplain #init(ImageLoaderConfiguration) init} ImageLoader with new configuration
  * after calling this method.
  */
 public void destroy() {
   if (configuration != null) L.d(LOG_DESTROY);
   stop();
   configuration.diskCache.close();
   engine = null;
   configuration = null;
 }
예제 #2
0
  /**
   * {@linkplain #stop() Stops ImageLoader} and clears current configuration. <br>
   * You can {@linkplain #init(ImageLoaderConfiguration) init} ImageLoader with new configuration
   * after calling this method.
   */
  public void destroy() {
    if (configuration != null && configuration.writeLogs) {
      L.d(LOG_DESTROY);
    }

    stop();
    engine = null;
    configuration = null;
  }
  @Override
  public void run() {
    if (engine.configuration.writeLogs) L.d(LOG_POSTPROCESS_IMAGE, imageLoadingInfo.memoryCacheKey);

    BitmapProcessor processor = imageLoadingInfo.options.getPostProcessor();
    Bitmap processedBitmap = processor.process(bitmap);
    DisplayBitmapTask displayBitmapTask =
        new DisplayBitmapTask(processedBitmap, imageLoadingInfo, engine, LoadedFrom.MEMORY_CACHE);
    displayBitmapTask.setLoggingEnabled(engine.configuration.writeLogs);
    LoadAndDisplayImageTask.runTask(
        displayBitmapTask, imageLoadingInfo.options.isSyncLoading(), handler, engine);
  }
 /**
  * Initializes ImageLoader instance with configuration.<br>
  * If configurations was set before ( {@link #isInited()} == true) then this method does nothing.
  * <br>
  * To force initialization with new configuration you should {@linkplain #destroy() destroy
  * ImageLoader} at first.
  *
  * @param configuration {@linkplain ImageLoaderConfiguration ImageLoader configuration}
  * @throws IllegalArgumentException if <b>configuration</b> parameter is null
  */
 public synchronized void init(
     ImageLoaderConfiguration configuration, ImageTokenCallback tokenCallback) {
   if (configuration == null) {
     throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);
   }
   this.tokenCallback = tokenCallback;
   if (this.configuration == null) {
     L.d(LOG_INIT_CONFIG);
     engine = new ImageLoaderEngine(configuration);
     this.configuration = configuration;
   } else {
     L.w(WARNING_RE_INIT_CONFIG);
   }
 }
예제 #5
0
  /**
   * Initializes ImageLoader instance with configuration.<br>
   * If configurations was set before ( {@link #isInited()} == true) then this method does nothing.
   * <br>
   * To force initialization with new configuration you should {@linkplain #destroy() destroy
   * ImageLoader} at first.
   *
   * @param configuration {@linkplain ImageLoaderConfiguration ImageLoader configuration}
   * @throws IllegalArgumentException if <b>configuration</b> parameter is null
   */
  public synchronized void init(ImageLoaderConfiguration configuration) {
    if (configuration == null) {
      throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);
    }

    if (this.configuration == null) {
      if (configuration.writeLogs) {
        L.d(LOG_INIT_CONFIG);
      }

      engine = new ImageLoaderEngine(configuration);
      this.configuration = configuration;

    } else {
      L.w(WARNING_RE_INIT_CONFIG);
    }
  }
예제 #6
0
  /**
   * Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br>
   * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method
   * call
   *
   * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
   * @param imageView {@link ImageView} which should display image
   * @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If
   *     <b>null</b> - default display image options {@linkplain
   *     ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
   *     configuration} will be used.
   * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener
   *     fires events on UI thread.
   * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
   *     before
   * @throws IllegalArgumentException if passed <b>imageView</b> is null
   */
  public void displayImage(
      String uri, ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener) {
    checkConfiguration();

    if (imageView == null) {
      throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
    }

    if (listener == null) {
      listener = emptyListener;
    }

    if (options == null) {
      options = configuration.defaultDisplayImageOptions;
    }

    if (TextUtils.isEmpty(uri)) {
      engine.cancelDisplayTaskFor(imageView);
      listener.onLoadingStarted(uri, imageView);

      if (options.shouldShowImageResForEmptyUri()) {
        imageView.setImageResource(options.getImageResForEmptyUri());

      } else if (options.shouldShowImageForEmptyUri()) {
        imageView.setImageDrawable(options.getImageForEmptyUri());

      } else {
        imageView.setImageDrawable(null);
      }

      listener.onLoadingComplete(uri, imageView, null);
      return;
    }

    ImageSize targetSize =
        ImageSizeUtils.defineTargetSizeForView(
            imageView,
            configuration.maxImageWidthForMemoryCache,
            configuration.maxImageHeightForMemoryCache);
    String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
    engine.prepareDisplayTaskFor(imageView, memoryCacheKey);

    listener.onLoadingStarted(uri, imageView);
    Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);

    if (bmp != null && !bmp.isRecycled()) {
      if (configuration.writeLogs) {
        L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
      }

      if (options.shouldPostProcess()) {
        ImageLoadingInfo imageLoadingInfo =
            new ImageLoadingInfo(
                uri,
                imageView,
                targetSize,
                memoryCacheKey,
                options,
                listener,
                engine.getLockForUri(uri));
        ProcessAndDisplayImageTask displayTask =
            new ProcessAndDisplayImageTask(engine, bmp, imageLoadingInfo, options.getHandler());
        engine.submit(displayTask);

      } else {
        options.getDisplayer().display(bmp, imageView, LoadedFrom.MEMORY_CACHE);
        listener.onLoadingComplete(uri, imageView, bmp);
      }

    } else {
      if (options.shouldShowImageResOnLoading()) {
        imageView.setImageResource(options.getImageResOnLoading());

      } else if (options.shouldShowImageOnLoading()) {
        imageView.setImageDrawable(options.getImageOnLoading());

      } else {
        if (options.isResetViewBeforeLoading()) {
          imageView.setImageDrawable(null);
        }
      }

      ImageLoadingInfo imageLoadingInfo =
          new ImageLoadingInfo(
              uri,
              imageView,
              targetSize,
              memoryCacheKey,
              options,
              listener,
              engine.getLockForUri(uri));
      LoadAndDisplayImageTask displayTask =
          new LoadAndDisplayImageTask(engine, imageLoadingInfo, options.getHandler());
      engine.submit(displayTask);
    }
  }
예제 #7
0
  public static String[] getPhone(Context mContext, Cursor mCursor) {
    String phoneResult[] = new String[2];
    if (mCursor != null && !mCursor.isClosed() && mCursor.getCount() > 0) {
      L.d("choosenumber->mCursor", "不为null");
      if (mCursor.moveToFirst()) {
        L.d("choosenumber->mCursor", "移动到第一个");
        int phoneColumn = mCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
        int phoneNameColumn = mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
        int phoneNum = mCursor.getInt(phoneColumn);
        if (phoneNum > 0) {
          L.d("choosenumber->phoneNum", "存在数值");
          // 获得联系人的ID号
          int idColumn = mCursor.getColumnIndex(ContactsContract.Contacts._ID);
          String contactId = mCursor.getString(idColumn);
          phoneResult[0] = mCursor.getString(phoneNameColumn) + "";
          L.d("choosenumber->获取到联系人", phoneResult[0]);
          // 获得联系人的电话号码的cursor;
          Cursor phones =
              mContext
                  .getContentResolver()
                  .query(
                      ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                      null,
                      ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
                      null,
                      null);
          if (phones != null && phones.moveToFirst()) {
            L.d("choosenumber->最内层,不为空", "准备循环获取号码");

            // 遍历所有的电话号码
            for (; !phones.isAfterLast(); phones.moveToNext()) {
              int index = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
              int typeindex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
              int phone_type = phones.getInt(typeindex);
              String phoneNumber = phones.getString(index);
              if (!TextUtils.isEmpty(phoneNumber)) {
                L.d("choosenumber->获取到电话号码", phoneNumber);
                if (phoneNumber.contains("+86")) {
                  phoneNumber = phoneNumber.replace("+86", ""); // 移除开头的+86
                }
                phoneResult[1] = phoneNumber + "";
                break;
              }
              // 很多手机修改过不同类型值对应的类型,2代表的是手机号,几乎都遵从这个约定,但这里如果联系人存了座机号码,也让其选择
              //                            switch (phone_type) {
              //                                case 2:
              //                                    L.d("choosenumber->获取到电话号码", phoneNumber);
              //                                    phoneResult[1] = phoneNumber + "";
              //                                    break;
              //                            }
            }
            if (!phones.isClosed()) {
              phones.close();
            }
          }
        } else {
          L.d("choosenumber->phoneNum", "不存在");
        }
      } else {
        L.d("choosenumber->mCursor", "moveToFirst失败");
      }
    }
    return phoneResult;
  }
 private void log(String message, Object... args) {
   if (writeLogs) L.d(message, args);
 }
 private void log(String message) {
   if (writeLogs) L.d(message, memoryCacheKey);
 }