예제 #1
0
  private void addSearchLayout(RelativeLayout layout, TiViewProxy searchView, TiUIView search) {
    RelativeLayout.LayoutParams p = createBasicSearchLayout();
    p.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    TiDimension rawHeight;
    if (searchView.hasProperty(TiC.PROPERTY_HEIGHT)) {
      rawHeight = TiConvert.toTiDimension(searchView.getProperty(TiC.PROPERTY_HEIGHT), 0);
    } else {
      rawHeight = TiConvert.toTiDimension(MIN_SEARCH_HEIGHT, 0);
    }
    p.height = rawHeight.getAsPixels(layout);

    View nativeView = search.getNativeView();
    layout.addView(nativeView, p);

    p = createBasicSearchLayout();
    p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    p.addRule(RelativeLayout.BELOW, nativeView.getId());
    ViewParent parentWrapper = wrapper.getParent();
    if (parentWrapper != null && parentWrapper instanceof ViewGroup) {
      // get the previous layout params so we can reset with new layout
      ViewGroup.LayoutParams lp = wrapper.getLayoutParams();
      ViewGroup parentView = (ViewGroup) parentWrapper;
      // remove view from parent
      parentView.removeView(wrapper);
      // add new layout
      layout.addView(wrapper, p);
      parentView.addView(layout, lp);

    } else {
      layout.addView(wrapper, p);
    }
    this.searchLayout = layout;
  }
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   TiImageView view = getView();
   if (view == null) {
     return;
   }
   if (key.equals(TiC.PROPERTY_CAN_SCALE)) {
     view.setCanScaleImage(TiConvert.toBoolean(newValue));
   } else if (key.equals(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
     view.setEnableZoomControls(TiConvert.toBoolean(newValue));
   } else if (key.equals(TiC.PROPERTY_URL)) {
     Log.w(LCAT, "The url property of ImageView is deprecated, use image instead.");
     setImageSource(newValue);
     firedLoad = false;
     setImage(true);
   } else if (key.equals(TiC.PROPERTY_IMAGE)) {
     setImageSource(newValue);
     firedLoad = false;
     setImage(true);
   } else if (key.equals(TiC.PROPERTY_IMAGES)) {
     if (newValue instanceof Object[]) {
       setImageSource(newValue);
       setImages();
     }
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }
  private void loadColors(Object[] colors) {
    this.colors = new int[colors.length];
    int offsetCount = 0;
    for (int i = 0; i < colors.length; i++) {
      Object color = colors[i];
      if (color instanceof HashMap) {
        HashMap<String, Object> colorRefObject = (HashMap) color;
        this.colors[i] = TiConvert.toColor(colorRefObject, "color");

        if (offsets == null) {
          offsets = new float[colors.length];
        }

        float offset = TiConvert.toFloat(colorRefObject, "offset", -1);
        if (offset >= 0.0f && offset <= 1.0f) {
          offsets[offsetCount++] = offset;
        }

      } else {
        this.colors[i] = TiConvert.toColor(color.toString());
      }
    }

    // If the number of offsets doesn't match the number of colors,
    // just distribute the colors evenly along the gradient line.
    if (offsetCount != this.colors.length) {
      offsets = null;
    }
  }
예제 #4
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    TextView tv = (TextView) getNativeView();
    // Only accept one, prefer text to title.
    if (d.containsKey("text")) {
      tv.setText(TiConvert.toString(d, "text"));
    } else if (d.containsKey("title")) { // TODO this may not need to be supported.
      tv.setText(TiConvert.toString(d, "title"));
    }

    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("highlightedColor")) {
      tv.setHighlightColor(TiConvert.toColor(d, "highlightedColor"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign")) {
      String textAlign = d.getString("textAlign");
      setAlignment(tv, textAlign);
    }
    tv.invalidate();
  }
예제 #5
0
  protected void handleAddRoute(HashMap routeMap) {
    Object routeArray = routeMap.get("points");
    if (routeArray instanceof Object[]) {
      Object[] routes = (Object[]) routeArray;
      MapPoint[] pointsType = new MapPoint[routes.length];
      for (int i = 0; i < routes.length; i++) {

        if (routes[i] instanceof HashMap) {
          HashMap tempRoute = (HashMap) routes[i];
          MapPoint mp =
              new MapPoint(
                  TiConvert.toDouble(tempRoute, "latitude"),
                  TiConvert.toDouble(tempRoute, "longitude"));
          pointsType[i] = mp;
        }
      }

      MapRoute mr =
          new MapRoute(
              pointsType,
              TiConvert.toColor(routeMap, "color"),
              TiConvert.toInt(routeMap, "width"),
              TiConvert.toString(routeMap, "name"));

      if (mapView == null) {
        this.routes.add(mr);
      } else {
        mapView.addRoute(mr);
      }
    }
  }
  private void addTabToGroup(TiUITabGroup tg, TabProxy tab) {
    TiTabActivity tta = weakActivity.get();
    if (tta == null) {
      if (DBG) {
        Log.w(LCAT, "Could not add tab because tab activity no longer exists");
      }
    }
    Drawable icon =
        TiDrawableReference.fromObject(getTiContext(), tab.getProperty(TiC.PROPERTY_ICON))
            .getDrawable();
    String tag = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TAG));
    String title = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TITLE));
    if (title == null) {
      title = "";
    }
    tab.setTabGroup(this);
    final WindowProxy vp = (WindowProxy) tab.getProperty(TiC.PROPERTY_WINDOW);
    vp.setTabGroupProxy(this);
    vp.setTabProxy(tab);
    if (tag != null && vp != null) {
      TabSpec tspec = tg.newTab(tag);
      if (icon == null) {
        tspec.setIndicator(title);
      } else {
        tspec.setIndicator(title, icon);
      }

      Intent intent = new Intent(tta, TiActivity.class);
      vp.fillIntentForTab(intent);

      tspec.setContent(intent);

      tg.addTab(tspec);
    }
  }
  private void handleAddTab(TabProxy tab) {
    String tag = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TAG));
    if (tag == null) {
      String title = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TITLE));
      if (title == null) {
        String icon = TiConvert.toString(tab.getProperty(TiC.PROPERTY_ICON));
        if (icon == null) {
          tag = tab.toString();
        } else {
          tag = icon;
        }
      } else {
        tag = title;
      }

      tab.setProperty(TiC.PROPERTY_TAG, tag, false); // store in proxy
    }

    if (tabs.size() == 0) {
      initialActiveTab = tab;
    }
    tabs.add(tab);

    if (peekView() != null) {
      TiUITabGroup tg = (TiUITabGroup) peekView();
      addTabToGroup(tg, tab);
    }
  }
예제 #8
0
  private void initializeBorder(KrollDict d, Integer bgColor) {
    if (d.containsKey(TiC.PROPERTY_BORDER_RADIUS)
        || d.containsKey(TiC.PROPERTY_BORDER_COLOR)
        || d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {

      if (nativeView != null) {
        if (background == null) {
          applyCustomBackground();
        }

        if (background.getBorder() == null) {
          background.setBorder(new TiBackgroundDrawable.Border());
        }

        TiBackgroundDrawable.Border border = background.getBorder();

        if (d.containsKey(TiC.PROPERTY_BORDER_RADIUS)) {
          border.setRadius(TiConvert.toFloat(d, TiC.PROPERTY_BORDER_RADIUS));
        }
        if (d.containsKey(TiC.PROPERTY_BORDER_COLOR) || d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
          if (d.containsKey(TiC.PROPERTY_BORDER_COLOR)) {
            border.setColor(TiConvert.toColor(d, TiC.PROPERTY_BORDER_COLOR));
          } else {
            if (bgColor != null) {
              border.setColor(bgColor);
            }
          }
          if (d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
            border.setWidth(TiConvert.toFloat(d, TiC.PROPERTY_BORDER_WIDTH));
          }
        }
        // applyCustomBackground();
      }
    }
  }
예제 #9
0
  @Kroll.method
  public void deselectAnnotation(Object[] args) {
    String title = null;
    AnnotationProxy selectedAnnotation = null;
    if (args.length > 0) {
      if (args[0] instanceof AnnotationProxy) {
        selectedAnnotation = (AnnotationProxy) args[0];
        title = TiConvert.toString(selectedAnnotation.getProperty("title"));
      } else if (args[0] instanceof String) {
        title = TiConvert.toString(args[0]);
      }
    }
    if (title != null) {
      boolean animate = false;

      if (args.length > 1) {
        animate = TiConvert.toBoolean(args[1]);
      }

      if (mapView == null) {
        int numSelectedAnnotations = selectedAnnotations.size();
        for (int i = 0; i < numSelectedAnnotations; i++) {
          if ((selectedAnnotations.get(i)).title.equals(title)) {
            selectedAnnotations.remove(i);
          }
        }
      } else {
        mapView.selectAnnotation(false, title, selectedAnnotation, animate, false);
      }
    }
  }
예제 #10
0
  @Kroll.method
  public void removeAnnotation(Object arg) {
    String title = null;
    AnnotationProxy annotation = null;
    if (arg != null) {
      if (arg instanceof AnnotationProxy) {
        annotation = (AnnotationProxy) arg;
        title = TiConvert.toString(annotation.getProperty(TiC.PROPERTY_TITLE));
      } else {
        title = TiConvert.toString(arg);
      }

      if (title != null) {
        int existsIndex = findAnnotation(title, annotation);
        if (existsIndex > -1) {
          annotations.get(existsIndex).setViewProxy(null);
          annotations.remove(existsIndex);
        }

        if (mapView != null) {
          mapView.updateAnnotations();
        }
      }
    }
  }
  private void fillIntent(Activity activity, Intent intent) {
    KrollDict props = getProperties();

    if (props != null) {
      if (props.containsKey(TiC.PROPERTY_FULLSCREEN)) {
        intent.putExtra(
            TiC.PROPERTY_FULLSCREEN, TiConvert.toBoolean(props, TiC.PROPERTY_FULLSCREEN));
      }
      if (props.containsKey(TiC.PROPERTY_NAV_BAR_HIDDEN)) {
        intent.putExtra(
            TiC.PROPERTY_NAV_BAR_HIDDEN, TiConvert.toBoolean(props, TiC.PROPERTY_NAV_BAR_HIDDEN));
      }
    }

    if (props != null && props.containsKey(TiC.PROPERTY_EXIT_ON_CLOSE)) {
      intent.putExtra(
          TiC.INTENT_PROPERTY_FINISH_ROOT, TiConvert.toBoolean(props, TiC.PROPERTY_EXIT_ON_CLOSE));
    } else {
      intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, activity.isTaskRoot());
    }

    Messenger messenger = new Messenger(getUIHandler());
    intent.putExtra(TiC.INTENT_PROPERTY_MESSENGER, messenger);
    intent.putExtra(TiC.INTENT_PROPERTY_MSG_ID, MSG_FINISH_OPEN);
  }
예제 #12
0
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   if ("volume".equals(key)) {
     setVolume(TiConvert.toFloat(newValue));
   } else if ("time".equals(key)) {
     setTime(TiConvert.toInt(newValue));
   }
 }
예제 #13
0
  @Override
  public void processProperties(KrollDict d) {

    if (d.containsKey(TiC.PROPERTY_PAGE_WIDTH)) {
      setPageWidth(d.get(TiC.PROPERTY_PAGE_WIDTH));
    }
    if (d.containsKey(TiC.PROPERTY_PAGE_OFFSET)) {
      setPageOffset(d.get(TiC.PROPERTY_PAGE_OFFSET));
    }

    if (d.containsKey(TiC.PROPERTY_VIEWS)) {
      setViews(d.get(TiC.PROPERTY_VIEWS));
    }

    if (d.containsKey(TiC.PROPERTY_CURRENT_PAGE)) {
      int page = d.optInt(TiC.PROPERTY_CURRENT_PAGE, 0);
      if (page > 0) {
        setCurrentPage(page);
      }
    }

    if (d.containsKey(TiC.PROPERTY_SHOW_PAGING_CONTROL)) {
      if (TiConvert.toBoolean(d, TiC.PROPERTY_SHOW_PAGING_CONTROL)) {
        showPager();
      }
    }

    if (d.containsKey(TiC.PROPERTY_SCROLLING_ENABLED)) {
      mEnabled = TiConvert.toBoolean(d, TiC.PROPERTY_SCROLLING_ENABLED);
    }

    if (d.containsKey(TiC.PROPERTY_OVER_SCROLL_MODE)) {
      if (Build.VERSION.SDK_INT >= 9) {
        mPager.setOverScrollMode(
            TiConvert.toInt(d.get(TiC.PROPERTY_OVER_SCROLL_MODE), View.OVER_SCROLL_ALWAYS));
      }
    }

    if (d.containsKey(TiC.PROPERTY_CACHE_SIZE)) {
      cacheSize = TiConvert.toInt(d, TiC.PROPERTY_CACHE_SIZE);
      if (cacheSize < 3) {
        // WHAT.  Let's make it something sensible.
        cacheSize = 3;
      }
      updateCacheSize();
    }

    if (d.containsKey(TiC.PROPERTY_TRANSITION)) {
      transition =
          TransitionHelper.transitionFromObject(
              (HashMap) d.get(TiC.PROPERTY_TRANSITION), null, null);
      mPager.updatePageTransformer();
    }
    super.processProperties(d);
  }
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   // TODO Auto-generated method stub
   if (key.equals(TiC.PROPERTY_TITLE)) {
     actionBar.setTitle(TiConvert.toString(newValue));
   } else if (key.equals(TiC.PROPERTY_SWIPEABLE)) {
     swipeable = TiConvert.toBoolean(newValue);
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }
  @Override
  public void processProperties(KrollDict d) {
    tableView = new TiTableView(proxy.getTiContext(), (TableViewProxy) proxy);
    tableView.setOnItemClickListener(this);

    if (d.containsKey(TiC.PROPERTY_SEARCH)) {
      RelativeLayout layout = new RelativeLayout(proxy.getTiContext().getActivity());
      layout.setGravity(Gravity.NO_GRAVITY);
      layout.setPadding(0, 0, 0, 0);

      TiViewProxy searchView = (TiViewProxy) d.get(TiC.PROPERTY_SEARCH);
      TiUISearchBar searchBar =
          (TiUISearchBar) searchView.getView(proxy.getTiContext().getActivity());
      searchBar.setOnSearchChangeListener(tableView);
      searchBar.getNativeView().setId(102);

      RelativeLayout.LayoutParams p =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
      p.addRule(RelativeLayout.ALIGN_PARENT_TOP);
      p.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
      p.height = 52;

      layout.addView(searchBar.getNativeView(), p);

      p =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
      p.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
      p.addRule(RelativeLayout.BELOW, 102);
      layout.addView(tableView, p);
      setNativeView(layout);
    } else {
      setNativeView(tableView);
    }

    if (d.containsKey(TiC.PROPERTY_FILTER_ATTRIBUTE)) {
      tableView.setFilterAttribute(TiConvert.toString(d, TiC.PROPERTY_FILTER_ATTRIBUTE));
    } else {
      // Default to title to match iPhone default.
      proxy.setProperty(TiC.PROPERTY_FILTER_ATTRIBUTE, TiC.PROPERTY_TITLE, false);
      tableView.setFilterAttribute(TiC.PROPERTY_TITLE);
    }

    boolean filterCaseInsensitive = true;
    if (d.containsKey(TiC.PROPERTY_FILTER_CASE_INSENSITIVE)) {
      filterCaseInsensitive = TiConvert.toBoolean(d, TiC.PROPERTY_FILTER_CASE_INSENSITIVE);
    }
    tableView.setFilterCaseInsensitive(filterCaseInsensitive);
    super.processProperties(d);
  }
예제 #16
0
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawColor(
          (props.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR))
              ? TiConvert.toColor(props, TiC.PROPERTY_BACKGROUND_COLOR)
              : TiConvert.toColor("transparent"));

      canvas.drawBitmap(tiBitmap, 0, 0, tiBitmapPaint);

      canvas.drawPath(tiPath, tiPaint);
    }
예제 #17
0
  protected KrollDict handleStyleOptions(KrollDict options) {
    String viewId = getProxyId();
    TreeSet<String> styleClasses = new TreeSet<String>();
    // TODO styleClasses.add(getShortAPIName().toLowerCase());

    if (options.containsKey(TiC.PROPERTY_ID)) {
      viewId = TiConvert.toString(options, TiC.PROPERTY_ID);
    }
    if (options.containsKey(TiC.PROPERTY_CLASS_NAME)) {
      String className = TiConvert.toString(options, TiC.PROPERTY_CLASS_NAME);
      for (String clazz : className.split(" ")) {
        styleClasses.add(clazz);
      }
    }
    if (options.containsKey(TiC.PROPERTY_CLASS_NAMES)) {
      Object c = options.get(TiC.PROPERTY_CLASS_NAMES);
      if (c.getClass().isArray()) {
        int length = Array.getLength(c);
        for (int i = 0; i < length; i++) {
          Object clazz = Array.get(c, i);
          if (clazz != null) {
            styleClasses.add(clazz.toString());
          }
        }
      }
    }

    String baseUrl = getBaseUrlForStylesheet();
    KrollDict dict = TiApplication.getInstance().getStylesheet(baseUrl, styleClasses, viewId);
    if (dict.size() > 0) {
      extend(dict);
    }

    if (DBG) {
      Log.d(
          LCAT,
          "trying to get stylesheet for base:"
              + baseUrl
              + ",classes:"
              + styleClasses
              + ",id:"
              + viewId
              + ",dict:"
              + dict);
    }
    if (dict != null) {
      // merge in our stylesheet details to the passed in dictionary
      // our passed in dictionary takes precedence over the stylesheet
      dict.putAll(options);
      return dict;
    }
    return options;
  }
예제 #18
0
  public void send(Object userData) throws MethodNotSupportedException {
    // TODO consider using task manager
    final TiHTTPClient me = this;
    double totalLength = 0;
    needMultipart = false;

    if (userData != null) {
      if (userData instanceof TiDict) {
        TiDict data = (TiDict) userData;

        // first time through check if we need multipart for POST
        for (String key : data.keySet()) {
          Object value = data.get(key);
          if (value instanceof TiBaseFile || value instanceof TiBlob) {
            needMultipart = true;
          }
        }

        for (String key : data.keySet()) {
          Object value = data.get(key);

          if (method.equals("POST") || method.equals("PUT")) {
            if (value instanceof TiBaseFile || value instanceof TiBlob) {
              totalLength += addTitaniumFileAsPostData(key, value);
            } else {
              String str = TiConvert.toString(value);
              addPostData(key, str);
              totalLength += str.length();
            }
          } else if (method.equals("GET")) {
            uri = uri.buildUpon().appendQueryParameter(key, TiConvert.toString(value)).build();
          }
        }
      } else {
        addStringData(TiConvert.toString(userData));
      }
    }

    request = new DefaultHttpRequestFactory().newHttpRequest(method, uri.toString());
    for (String header : headers.keySet()) {
      request.setHeader(header, headers.get(header));
    }

    clientThread =
        new Thread(
            new ClientRunnable(totalLength),
            "TiHttpClient-" + httpClientThreadCounter.incrementAndGet());
    clientThread.setPriority(Thread.MIN_PRIORITY);
    clientThread.start();
    if (DBG) {
      Log.d(LCAT, "Leaving send()");
    }
  }
예제 #19
0
  @Override
  public void processProperties(KrollDict d) {
    if (d.containsKey("volume")) {
      setVolume(TiConvert.toFloat(d, "volume"));
    } else {
      setVolume(0.5f);
    }

    if (d.containsKey("time")) {
      setTime(TiConvert.toInt(d, "time"));
    }
  }
예제 #20
0
  @Kroll.method
  public void show(KrollDict args) {
    Log.d(TAG, "show called");

    final Crouton crouton;

    Activity activity;
    String text = "";
    Style style = null;
    Builder config = new Configuration.Builder();

    if (args.containsKey(TiC.PROPERTY_ACTIVITY)) {
      ActivityProxy activityProxy = (ActivityProxy) args.get(TiC.PROPERTY_ACTIVITY);
      activity = activityProxy.getActivity();
    } else {
      activity = TiApplication.getInstance().getCurrentActivity();
    }

    if (args.containsKey(TiC.PROPERTY_TEXT)) {
      text = TiConvert.toString(args.get(TiC.PROPERTY_TEXT));
    }

    if (args.containsKey(TiC.PROPERTY_STYLE)) {
      style = getStyle(TiConvert.toInt(args.get(TiC.PROPERTY_STYLE)));
    }

    if (args.containsKey(TiC.PROPERTY_COLOR)) {

      String color = (String) args.get(TiC.PROPERTY_COLOR);

      style = new Style.Builder().setBackgroundColorValue(TiConvert.toColor(color)).build();
    }

    if (style == null) {
      style = Style.INFO;
    }

    crouton = Crouton.makeText(activity, text, style);

    if (args.containsKey(TiC.PROPERTY_DURATION)) {
      config.setDuration(TiConvert.toInt(args.get(TiC.PROPERTY_DURATION)));
      crouton.setConfiguration(config.build());
    }

    TiUIHelper.runUiDelayedIfBlock(
        new Runnable() {
          @Override
          public void run() {
            crouton.show();
          }
        });
  }
예제 #21
0
 /**
  * Check whether the called view is a text editor, in which case it would make sense to
  * automatically display a soft input window for it.
  */
 @Override
 public boolean onCheckIsTextEditor() {
   if (proxy.hasProperty(TiC.PROPERTY_SOFT_KEYBOARD_ON_FOCUS)
       && TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_SOFT_KEYBOARD_ON_FOCUS))
           == TiUIView.SOFT_KEYBOARD_HIDE_ON_FOCUS) {
     return false;
   }
   if (proxy.hasProperty(TiC.PROPERTY_EDITABLE)
       && !(TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_EDITABLE)))) {
     return false;
   }
   return true;
 }
예제 #22
0
 private void setPageOffset(Object value) {
   if (verticalLayout) {
     TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
     params.optionHeight =
         TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_TOP);
     mPager.setLayoutParams(params);
   } else {
     TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
     params.optionWidth =
         TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_LEFT);
     mPager.setLayoutParams(params);
   }
 }
예제 #23
0
  @Override
  public void processProperties(KrollDict d) {
    super.processProperties(d);

    if (d.containsKey(TiC.PROPERTY_MESSAGE)) {
      handleSetMessage(TiConvert.toString(d, TiC.PROPERTY_MESSAGE));
    }
    if (d.containsKey(TiC.PROPERTY_COLOR)) {
      final int color = TiConvert.toColor(d, TiC.PROPERTY_COLOR);
      progress.getProgressDrawable().setColorFilter(color, Mode.SRC_IN);
      handleSetMessageColor(color);
    }
    updateProgress();
  }
예제 #24
0
 protected void didProcessProperties() {
   if ((mProcessUpdateFlags & TIFLAG_NEEDS_OPTIONS) != 0) {
     clearDialog();
     getBuilder().setView(null);
     String[] optionText = TiConvert.toStringArray(proxy.getProperty(TiC.PROPERTY_OPTIONS));
     int selectedIndex = TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_SELECTED_INDEX), -1);
     if (selectedIndex >= optionText.length) {
       selectedIndex = -1;
     }
     processOptions(optionText, selectedIndex);
     mProcessUpdateFlags &= ~TIFLAG_NEEDS_OPTIONS;
   }
   super.didProcessProperties();
 }
예제 #25
0
  protected void initialize() throws IOException {
    try {
      mp = new MediaPlayer();
      String url = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_URL));
      if (URLUtil.isAssetUrl(url)) {
        Context context = proxy.getTiContext().getTiApp();
        String path = url.substring(TiConvert.ASSET_URL.length());
        AssetFileDescriptor afd = null;
        try {
          afd = context.getAssets().openFd(path);
          // Why mp.setDataSource(afd) doesn't work is a problem for another day.
          // http://groups.google.com/group/android-developers/browse_thread/thread/225c4c150be92416
          mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        } catch (IOException e) {
          Log.e(LCAT, "Error setting file descriptor: ", e);
        } finally {
          if (afd != null) {
            afd.close();
          }
        }
      } else {
        Uri uri = Uri.parse(url);
        if (uri.getScheme().equals(TiC.PROPERTY_FILE)) {
          mp.setDataSource(uri.getPath());
        } else {
          remote = true;
          mp.setDataSource(url);
        }
      }

      mp.setLooping(looping);
      mp.setOnCompletionListener(this);
      mp.setOnErrorListener(this);
      mp.setOnInfoListener(this);
      mp.setOnBufferingUpdateListener(this);

      mp.prepare(); // Probably need to allow for Async
      setState(STATE_INITIALIZED);

      setVolume(volume);
      if (proxy.hasProperty(TiC.PROPERTY_TIME)) {
        setTime(TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_TIME)));
      }
    } catch (Throwable t) {
      Log.w(LCAT, "Issue while initializing : ", t);
      release();
      setState(STATE_STOPPED);
    }
  }
예제 #26
0
  private void handleBorderProperty(String property, Object value) {
    if (background.getBorder() == null) {
      background.setBorder(new TiBackgroundDrawable.Border());
    }
    TiBackgroundDrawable.Border border = background.getBorder();

    if (property.equals(TiC.PROPERTY_BORDER_COLOR)) {
      border.setColor(TiConvert.toColor(value.toString()));
    } else if (property.equals(TiC.PROPERTY_BORDER_RADIUS)) {
      border.setRadius(TiConvert.toFloat(value));
    } else if (property.equals(TiC.PROPERTY_BORDER_WIDTH)) {
      border.setWidth(TiConvert.toFloat(value));
    }
    applyCustomBackground();
  }
예제 #27
0
  public TiUIFragment(TiViewProxy proxy, Activity activity) {
    super(proxy);
    // When 'fragmentOnly' property is enabled, we generate the standalone fragment, enabling
    // us to add it directly to other fragment managers.
    if (proxy.hasProperty(TiC.PROPERTY_FRAGMENT_ONLY)) {
      fragmentOnly = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_FRAGMENT_ONLY), false);
    }

    if (fragmentOnly) {
      fragment = createFragment();
    } else {
      TiCompositeLayout container =
          new TiCompositeLayout(activity, proxy) {
            @Override
            public boolean dispatchTouchEvent(MotionEvent ev) {
              return interceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
            }
          };
      container.setId(viewId++);
      setNativeView(container);

      FragmentManager manager = ((FragmentActivity) activity).getSupportFragmentManager();
      FragmentTransaction transaction = manager.beginTransaction();
      fragment = createFragment();
      transaction.add(container.getId(), fragment);
      transaction.commitAllowingStateLoss();
    }
  }
예제 #28
0
  protected void updateTitle() {
    if (window == null) return;

    if (window.hasProperty(TiC.PROPERTY_TITLE)) {
      String oldTitle = (String) getTitle();
      String newTitle = TiConvert.toString(window.getProperty(TiC.PROPERTY_TITLE));

      if (oldTitle == null) {
        oldTitle = "";
      }

      if (newTitle == null) {
        newTitle = "";
      }

      if (!newTitle.equals(oldTitle)) {
        final String fnewTitle = newTitle;
        runOnUiThread(
            new Runnable() {
              public void run() {
                setTitle(fnewTitle);
              }
            });
      }
    }
  }
예제 #29
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);
        }
      }
    }
 private long repeatingFrequency(KrollDict args) {
   long freqResults = utils.DAILY_MILLISECONDS;
   Object repeat = args.get("repeat");
   if (repeat instanceof Number) {
     utils.debugLog("Repeat value provided in milliseconds found");
     freqResults = ((Number) repeat).longValue();
   } else {
     String repeatValue = TiConvert.toString(repeat);
     utils.debugLog("Repeat value of " + repeatValue + " found");
     if (repeatValue.toUpperCase() == "HOURLY") {
       freqResults = utils.HOURLY_MILLISECONDS;
     }
     if (repeatValue.toUpperCase() == "WEEKLY") {
       freqResults = utils.WEEKLY_MILLISECONDS;
     }
     if (repeatValue.toUpperCase() == "MONTHLY") {
       freqResults = utils.MONTHLY_MILLISECONDS;
     }
     if (repeatValue.toUpperCase() == "YEARLY") {
       freqResults = utils.YEARLY_MILLISECONDS;
     }
   }
   utils.debugLog("Repeat Frequency in milliseconds is " + freqResults);
   return freqResults;
 }