public int getResponseData() {
    if (responseData != null && responseDataKey == -1) {
      TitaniumModuleManager tmm = weakTmm.get();
      if (tmm != null) {
        TitaniumMemoryBlob blob = new TitaniumMemoryBlob(responseData);
        responseDataKey = tmm.cacheObject(blob);
      }
    } else {
      responseDataKey = -1;
    }

    return responseDataKey;
  }
  @Override
  public void createControl(TitaniumModuleManager tmm) {
    SeekBar b = new SeekBar(tmm.getAppContext());
    b.setOnSeekBarChangeListener(this);

    offset = -min;
    int length = (int) Math.floor(Math.sqrt(Math.pow(max - min, 2)));
    b.setMax(length);
    b.setProgress(pos + offset);

    control = b;

    control.isFocusable();
    control.setId(100);
  }
 public TitaniumHttpClient(TitaniumModuleManager tmm, String userAgent) {
   if (httpClientThreadCounter == null) {
     httpClientThreadCounter = new AtomicInteger();
   }
   this.weakTmm = new WeakReference<TitaniumModuleManager>(tmm);
   me = this;
   onReadyStateChangeCallback = null;
   readyState = 0;
   responseText = "";
   responseDataKey = -1;
   credentials = null;
   this.userAgent = userAgent;
   this.softWebView = new SoftReference<TitaniumWebView>(tmm.getWebView());
   this.nvPairs = new ArrayList<NameValuePair>();
   this.parts = new HashMap<String, ContentBody>();
 }
Esempio n. 4
0
 public TitaniumApp(TitaniumModuleManager moduleMgr, String name, TitaniumAppInfo appInfo) {
   super(moduleMgr, name);
   this.appInfo = appInfo;
   this.appProperties = new TitaniumProperties(moduleMgr.getActivity(), "titanium", false);
   systemProperties = appInfo.getSystemProperties();
 }
 public TitaniumJSEventManager(TitaniumModuleManager manager) {
   this(manager.getWebView());
 }
  @Override
  public void createControl(TitaniumModuleManager tmm) {
    tv = new EditText(tmm.getAppContext());
    tv.isFocusable();
    tv.setId(100);

    tv.addTextChangedListener(this);
    tv.setOnEditorActionListener(this);
    tv.setText(value);
    tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    tv.setPadding(4, 2, 4, 2);
    tv.setSingleLine();
    TitaniumUIHelper.styleText(tv, fontSize, fontWeight);

    if (color != null) {
      tv.setTextColor(TitaniumColorHelper.parseColor(color));
    }
    if (backgroundColor != null) {
      tv.setBackgroundColor(TitaniumColorHelper.parseColor(backgroundColor));
    }

    cancelBtn = new ImageButton(tmm.getAppContext());
    cancelBtn.isFocusable();
    cancelBtn.setId(101);
    cancelBtn.setPadding(0, 0, 0, 0);
    Drawable d = new BitmapDrawable(this.getClass().getResourceAsStream("cancel.png"));
    cancelBtn.setImageDrawable(d);
    cancelBtn.setMinimumWidth(48);

    cancelBtn.setVisibility(showCancel ? View.VISIBLE : View.GONE);
    cancelBtn.setOnClickListener(
        new OnClickListener() {

          public void onClick(View view) {
            handler.sendEmptyMessage(MSG_CANCEL);
          }
        });

    RelativeLayout layout = new RelativeLayout(tmm.getAppContext());
    control = layout;

    layout.setGravity(Gravity.NO_GRAVITY);
    layout.setPadding(0, 0, 0, 0);
    if (barColor != null) {
      layout.setBackgroundColor(TitaniumColorHelper.parseColor(barColor));
    }

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    params.addRule(RelativeLayout.LEFT_OF, 101);
    params.setMargins(4, 4, 0, 4);
    layout.addView(tv, params);

    params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    params.setMargins(0, 4, 4, 4);
    layout.addView(cancelBtn, params);
  }
    public String handleResponse(HttpResponse response) throws HttpResponseException, IOException {
      String clientResponse = null;

      if (client != null) {
        TitaniumHttpClient c = client.get();
        if (c != null) {
          c.response = response;
          c.setReadyState(READY_STATE_LOADED, syncId);
          c.setStatus(response.getStatusLine().getStatusCode());
          c.setStatusText(response.getStatusLine().getReasonPhrase());
          c.setReadyState(READY_STATE_INTERACTIVE, syncId);
        }

        if (DBG) {
          try {
            Log.w(LCAT, "Entity Type: " + response.getEntity().getClass());
            Log.w(LCAT, "Entity Content Type: " + response.getEntity().getContentType().getValue());
            Log.w(LCAT, "Entity isChunked: " + response.getEntity().isChunked());
            Log.w(LCAT, "Entity isStreaming: " + response.getEntity().isStreaming());
          } catch (Throwable t) {
            // Ignore
          }
        }

        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
          throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
        }

        entity = response.getEntity();

        if (c.onDataStreamCallback != null) {
          is = entity.getContent();

          if (is != null) {
            final String cb = c.onDataStreamCallback;
            final TitaniumWebView webView = softWebView.get();

            long contentLength = entity.getContentLength();
            if (DBG) {
              Log.d(LCAT, "Content length: " + contentLength);
            }
            int count = 0;
            int totalSize = 0;
            byte[] buf = new byte[4096];
            if (DBG) {
              Log.d(LCAT, "Available: " + is.available());
            }
            if (aborted) {
              if (entity != null) {
                entity.consumeContent();
              }
            } else {
              while ((count = is.read(buf)) != -1) {
                totalSize += count;
                if (webView != null) {
                  TitaniumModuleManager tmm = weakTmm.get();
                  if (tmm != null) {
                    try {
                      JSONObject o = new JSONObject();
                      o.put("totalCount", contentLength);
                      o.put("totalSize", totalSize);
                      o.put("size", count);
                      byte[] newbuf = new byte[count];
                      for (int i = 0; i < count; i++) {
                        newbuf[i] = buf[i];
                      }
                      TitaniumMemoryBlob blob = new TitaniumMemoryBlob(newbuf);
                      int key = tmm.cacheObject(blob);
                      o.put("key", key);
                      webView.evalJS(cb, o.toString(), syncId);
                    } catch (JSONException e) {
                      Log.e(LCAT, "Unable to send ondatastream event: ", e);
                    }
                  }
                }
                if (!entity.isStreaming()) {
                  break;
                }
              }
              if (entity != null) {
                entity.consumeContent();
              }
            }
          }
        } else {
          setResponseData(entity);
        }
      }
      return clientResponse;
    }