예제 #1
0
    @Override
    protected void onPostExecute(Drawable d) {
      super.onPostExecute(d);

      if (d != null) {
        final Drawable fDrawable = d;

        // setImageDrawable has to run in the UI thread since it updates the UI
        TiMessenger.getMainMessenger()
            .post(
                new Runnable() {
                  @Override
                  public void run() {
                    setImageDrawable(fDrawable, token);
                  }
                });

      } else {
        if (Log.isDebugModeEnabled()) {
          String traceMsg = "Background image load returned null";
          if (proxy.hasProperty(TiC.PROPERTY_IMAGE)) {
            Object image = proxy.getProperty(TiC.PROPERTY_IMAGE);
            if (image instanceof String) {
              traceMsg += " (" + TiConvert.toString(image) + ")";
            }
          }
          Log.d(TAG, traceMsg);
        }
      }
    }
    @Override
    protected Bitmap doInBackground(final ImageArgs... params) {
      final ImageArgs imageArgs = params[0];

      recycle = imageArgs.mRecycle;
      mNetworkURL = imageArgs.mNetworkURL;
      Bitmap bitmap = null;

      mUrl = imageArgs.mImageref.getUrl();

      if (mNetworkURL) {
        boolean getAsync = true;
        try {
          String imageUrl = TiUrl.getCleanUri(imageArgs.mImageref.getUrl()).toString();

          URI uri = new URI(imageUrl);
          getAsync = !TiResponseCache.peek(uri); // expensive, don't want to do in UI thread
        } catch (URISyntaxException e) {
          Log.e(TAG, "URISyntaxException for url " + imageArgs.mImageref.getUrl(), e);
          getAsync = false;
        } catch (NullPointerException e) {
          Log.e(TAG, "NullPointerException for url " + imageArgs.mImageref.getUrl(), e);
          getAsync = false;
        } catch (Exception e) {
          Log.e(TAG, "Caught exception for url" + imageArgs.mImageref.getUrl(), e);
        }
        if (getAsync) {
          //
          // We've got to start the download back on the UI thread, if we do it on one
          // of the AsyncTask threads it will throw an exception.
          //
          mAsync = true;

          TiMessenger.getMainMessenger()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      imageArgs.mImageref.getBitmapAsync(imageDownloadListener);
                    }
                  });

        } else {
          bitmap =
              (imageArgs.mImageref)
                  .getBitmap(
                      imageArgs.mView, imageArgs.mRequestedWidth, imageArgs.mRequestedHeight);
        }
      } else {
        bitmap =
            (imageArgs.mImageref)
                .getBitmap(imageArgs.mView, imageArgs.mRequestedWidth, imageArgs.mRequestedHeight);
      }
      return bitmap;
    }
예제 #3
0
  protected void handleSendMessage(int messageId) {
    try {
      Message message = TiMessenger.getMainMessenger().getHandler().obtainMessage(messageId, this);
      messenger.send(message);

    } catch (RemoteException e) {
      Log.e(TAG, "Unable to message creator. finishing.", e);
      finish();

    } catch (RuntimeException e) {
      Log.e(TAG, "Unable to message creator. finishing.", e);
      finish();
    }
  }