public void removeView(Object viewObject) {
   Message msg = getUIHandler().obtainMessage(MSG_REMOVE_VIEW);
   AsyncResult result = new AsyncResult(viewObject);
   msg.obj = result;
   msg.sendToTarget();
   result.getResult(); // Wait for it
 }
 public void setViews(Object viewsObject) {
   Message msg = getUIHandler().obtainMessage(MSG_SET_VIEWS);
   AsyncResult result = new AsyncResult(viewsObject);
   msg.obj = result;
   msg.sendToTarget();
   result.getResult(); // Wait for it
 }
示例#3
0
 @Override
 public boolean handleMessage(Message msg) {
   if (msg.what == SET_IMAGE) {
     AsyncResult result = (AsyncResult) msg.obj;
     getView().setImageBitmap((Bitmap) result.getArg());
     result.setResult(null);
   }
   return false;
 }
示例#4
0
 public void setImage(final Bitmap bitmap) {
   if (bitmap != null) {
     if (!proxy.getTiContext().isUIThread()) {
       Message msg = Message.obtain(handler, SET_IMAGE);
       AsyncResult result = new AsyncResult(bitmap);
       msg.obj = result;
       msg.sendToTarget();
       result.getResult();
     } else {
       getView().setImageBitmap(bitmap);
     }
   }
 }
  /**
   * Sends a message on blockQueue, and dispatches messages on the current queue while blocking on
   * the passed in AsyncResult
   *
   * @param msg The message to send.
   * @param blockQueue The TiMessageQueue to send it to.
   * @param asyncResult The AsyncResult to block on.
   * @return The value of asyncResult.getResult()
   */
  public Object sendBlockingMessage(
      Message msg, final TiMessageQueue blockQueue, final AsyncResult asyncResult) {
    @SuppressWarnings("serial")
    AsyncResult blockingResult =
        new AsyncResult(asyncResult.getArg()) {
          @Override
          public Object getResult() {
            int timeout = 0;
            try {
              // TODO: create a multi-semaphore condition
              // here so we don't unnecessarily poll
              while (!tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                if (messageQueue.size() == 0) {
                  timeout = 50;
                } else {
                  dispatchPendingMessages();
                }
              }
            } catch (InterruptedException e) {
              Log.e(TAG, "interrupted waiting for async result", e);
              dispatchPendingMessages();
            }
            if (exception != null) {
              throw new RuntimeException(exception);
            }
            return result;
          }

          @Override
          public void setResult(Object result) {
            super.setResult(result);
            asyncResult.setResult(result);
          }
        };
    blockCount.incrementAndGet();
    msg.obj = blockingResult;
    blockQueue.sendMessage(msg);

    Object o = blockingResult.getResult();
    blockCount.decrementAndGet();
    dispatchPendingMessages();
    return o;
  }
 @Override
 public boolean handleMessage(Message msg) {
   switch (msg.what) {
     case MSG_ADD_TAB:
       {
         AsyncResult result = (AsyncResult) msg.obj;
         handleAddTab((TabProxy) result.getArg());
         result.setResult(null); // signal added
         return true;
       }
     case MSG_REMOVE_TAB:
       {
         AsyncResult result = (AsyncResult) msg.obj;
         handleRemoveTab((TabProxy) result.getArg());
         result.setResult(null); // signal added
         return true;
       }
     case MSG_FINISH_OPEN:
       {
         TiTabActivity activity = (TiTabActivity) msg.obj;
         view = new TiUITabGroup(this, activity);
         modelListener = view;
         handlePostOpen(activity);
         return true;
       }
     default:
       {
         return super.handleMessage(msg);
       }
   }
 }
  @Override
  public boolean handleMessage(Message msg) {
    if (msg.what == MSG_UPDATE_VIEW) {
      getTableView().updateView();
      ((AsyncResult) msg.obj).setResult(0);
      return true;
    } else if (msg.what == MSG_SCROLL_TO_INDEX) {
      getTableView().scrollToIndex(msg.arg1);
      return true;
    } else if (msg.what == MSG_SET_DATA) {
      AsyncResult result = (AsyncResult) msg.obj;
      Object[] data = (Object[]) result.getArg();
      handleSetData(data);
      result.setResult(0);
      return true;
    } else if (msg.what == MSG_INSERT_ROW) {
      AsyncResult result = (AsyncResult) msg.obj;
      if (msg.arg1 == INSERT_ROW_AFTER) {
        handleInsertRowAfter(msg.arg2, result.getArg());
      } else {
        handleInsertRowBefore(msg.arg2, result.getArg());
      }
      result.setResult(0);
      return true;
    } else if (msg.what == MSG_APPEND_ROW) {
      AsyncResult result = (AsyncResult) msg.obj;
      handleAppendRow(result.getArg());
      result.setResult(0);
      return true;
    } else if (msg.what == MSG_DELETE_ROW) {
      handleDeleteRow(msg.arg1);
      return true;
    } else if (msg.what == MSG_SCROLL_TO_TOP) {
      getTableView().scrollToTop(msg.arg1);
      return true;
    }

    return super.handleMessage(msg);
  }
  public boolean handleMessage(Message msg) {
    boolean handled = false;

    switch (msg.what) {
      case MSG_SHOW_PAGER:
        getView().showPager();
        break;
      case MSG_HIDE_PAGER:
        getView().hidePager();
        handled = true;
        break;
      case MSG_MOVE_PREV:
        inScroll.set(true);
        getView().doMovePrevious();
        inScroll.set(false);
        handled = true;
        break;
      case MSG_MOVE_NEXT:
        inScroll.set(true);
        getView().doMoveNext();
        inScroll.set(false);
        handled = true;
        break;
      case MSG_SCROLL_TO:
        inScroll.set(true);
        getView().doScrollToView(msg.obj);
        inScroll.set(false);
        handled = true;
        break;
      case MSG_SET_CURRENT:
        getView().doSetCurrentPage(msg.obj);
        handled = true;
        break;
      case MSG_SET_VIEWS:
        {
          AsyncResult holder = (AsyncResult) msg.obj;
          Object views = holder.getArg();
          getView().setViews(views);
          holder.setResult(null); // signal complete.			
          handled = true;
          break;
        }
      case MSG_ADD_VIEW:
        {
          AsyncResult holder = (AsyncResult) msg.obj;
          Object view = holder.getArg();
          if (view instanceof TiViewProxy) {
            getView().addView((TiViewProxy) view);
            handled = true;
          }
          holder.setResult(null); // signal complete.
          break;
        }
      case MSG_REMOVE_VIEW:
        {
          AsyncResult holder = (AsyncResult) msg.obj;
          Object view = holder.getArg();
          if (view instanceof TiViewProxy) {
            getView().removeView((TiViewProxy) view);
            handled = true;
          }
          holder.setResult(null); // signal complete.
          break;
        }
      default:
        handled = super.handleMessage(msg);
    }

    return handled;
  }