Ejemplo n.º 1
0
  public void appendExtraEventData(
      TiUIView view, int itemIndex, int sectionIndex, String bindId, String itemId) {
    KrollDict existingData = view.getAdditionalEventData();
    if (existingData == null) {
      existingData = new KrollDict();
      view.setAdditionalEventData(existingData);
    }

    // itemIndex = realItemIndex + header (if exists). We want the real item index.
    if (headerTitle != null || headerView != null) {
      itemIndex -= 1;
    }

    existingData.put(TiC.PROPERTY_SECTION, this);
    existingData.put(TiC.PROPERTY_SECTION_INDEX, sectionIndex);
    existingData.put(TiC.PROPERTY_ITEM_INDEX, itemIndex);

    if (!bindId.startsWith(TiListViewTemplate.GENERATED_BINDING)
        && !bindId.equals(TiC.PROPERTY_PROPERTIES)) {
      existingData.put(TiC.PROPERTY_BIND_ID, bindId);
    } else if (existingData.containsKey(TiC.PROPERTY_BIND_ID)) {
      existingData.remove(TiC.PROPERTY_BIND_ID);
    }

    if (itemId != null) {
      existingData.put(TiC.PROPERTY_ITEM_ID, itemId);
    } else if (existingData.containsKey(TiC.PROPERTY_ITEM_ID)) {
      existingData.remove(TiC.PROPERTY_ITEM_ID);
    }
  }
Ejemplo n.º 2
0
  protected void handleAnimate() {
    TiUIView tiv = peekView();

    if (tiv != null) {
      tiv.animate();
    }
  }
 @Override
 public TiUIView createView(Activity activity) {
   TiUIView view = new BranchUniversalObjectView(this);
   view.getLayoutParams().autoFillsHeight = true;
   view.getLayoutParams().autoFillsWidth = true;
   return view;
 }
Ejemplo n.º 4
0
  @Kroll.method
  @Kroll.getProperty
  public boolean getKeepScreenOn() {
    Boolean keepScreenOn = null;
    TiUIView v = peekView();
    if (v != null) {
      View nv = v.getNativeView();
      if (nv != null) {
        keepScreenOn = nv.getKeepScreenOn();
      }
    }

    // Keep the proxy in the correct state
    Object current = getProperty(TiC.PROPERTY_KEEP_SCREEN_ON);
    if (current != null) {
      boolean currentValue = TiConvert.toBoolean(current);
      if (keepScreenOn == null) {
        keepScreenOn = currentValue;
      } else {
        if (currentValue != keepScreenOn) {
          setProperty(TiC.PROPERTY_KEEP_SCREEN_ON, keepScreenOn);
        } else {
          keepScreenOn = currentValue;
        }
      }
    } else {
      if (keepScreenOn == null) {
        keepScreenOn = false; // Android default
      }

      setProperty(TiC.PROPERTY_KEEP_SCREEN_ON, keepScreenOn);
    }

    return keepScreenOn;
  }
 @Override
 public TiUIView createView(Activity activity) {
   TiUIView view = new ExampleView(this);
   view.getLayoutParams().autoFillsHeight = true;
   view.getLayoutParams().autoFillsWidth = true;
   return view;
 }
Ejemplo n.º 6
0
 @Override
 public Object instantiateItem(View container, int position) {
   synchronized (viewsLock) {
     ViewGroup pager = (ViewGroup) container;
     TiViewProxy tiProxy = mViews.get(position);
     TiUIView tiView = tiProxy.getOrCreateView();
     View view = tiView.getOuterView();
     ViewGroup.LayoutParams params =
         new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
     TiCompositeLayout layout = new TiCompositeLayout(tiProxy.getActivity());
     ViewParent parent = view.getParent();
     if (parent instanceof ViewGroup) {
       pager.removeView((View) parent);
       ViewGroup group = (ViewGroup) parent;
       group.removeView(view);
     }
     layout.addView(view, tiView.getLayoutParams());
     if (position < pager.getChildCount()) {
       pager.addView(layout, position, params);
     } else {
       pager.addView(layout, params);
     }
     return tiProxy;
   }
 }
Ejemplo n.º 7
0
  protected KrollDict handleToImage() {
    TiUIView view = getOrCreateView();
    if (view == null) {
      return null;
    }

    return view.toImage();
  }
Ejemplo n.º 8
0
 private void handleFinishLayout() {
   if (view.iszIndexChanged()) {
     view.forceLayoutNativeView(true);
     view.setzIndexChanged(false);
   } else {
     view.forceLayoutNativeView(false);
   }
 }
Ejemplo n.º 9
0
 public void setClickable(boolean clickable) {
   TiUIView v = peekView();
   if (v != null) {
     View nv = v.getNativeView();
     if (nv != null) {
       nv.setClickable(clickable);
     }
   }
 }
  @Override
  public void add(TiUIView child) {
    super.add(child);

    if (getNativeView() != null) {
      getLayout().requestLayout();
      if (child.getNativeView() != null) {
        child.getNativeView().requestLayout();
      }
    }
  }
Ejemplo n.º 11
0
 public void remove(TiUIView child) {
   if (child != null) {
     View cv = child.getNativeView();
     if (cv != null) {
       View nv = getNativeView();
       if (nv instanceof ViewGroup) {
         ((ViewGroup) nv).removeView(cv);
         children.remove(child);
         child.parent = null;
       }
     }
   }
 }
Ejemplo n.º 12
0
 public void add(TiUIView child) {
   if (child != null) {
     View cv = child.getNativeView();
     if (cv != null) {
       View nv = getNativeView();
       if (nv instanceof ViewGroup) {
         if (cv.getParent() == null) {
           ((ViewGroup) nv).addView(cv, child.getLayoutParams());
         }
       }
     }
   }
 }
  protected TiViewProxy addViewToOldRow(int index, TiUIView titleView, TiViewProxy newViewProxy) {
    if (DBG) {
      Log.w(LCAT, newViewProxy + " was added an old style row, reusing the title TiUILabel");
    }
    LabelProxy label = new LabelProxy(tiContext);
    label.handleCreationDict(titleView.getProxy().getProperties());
    label.setView(titleView);
    label.setModelListener(titleView);
    titleView.setProxy(label);

    getRowProxy().getControls().add(index, label);
    views.add(newViewProxy.getView(tiContext.getActivity()));
    return label;
  }
Ejemplo n.º 14
0
  public void release() {
    for (int i = 0; i < sections.size(); i++) {
      sections.get(i).releaseViews();
    }

    templatesByBinding.clear();
    sections.clear();

    if (wrapper != null) {
      wrapper = null;
    }

    if (listView != null) {
      listView.setAdapter(null);
      listView = null;
    }
    if (headerView != null) {
      headerView = null;
    }
    if (footerView != null) {
      footerView = null;
    }

    super.release();
  }
Ejemplo n.º 15
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;
  }
Ejemplo n.º 16
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();
  }
 @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);
   }
 }
 @Override
 public void clearOpacity(View view) {
   super.clearOpacity(view);
   TiImageView iview = getView();
   if (iview != null) {
     iview.setColorFilter(null);
   }
 }
 @Override
 public void setOpacity(float opacity) {
   TiImageView view = getView();
   if (view != null) {
     view.setColorFilter(TiUIHelper.createColorFilterForOpacity(opacity));
     super.setOpacity(opacity);
   }
 }
Ejemplo n.º 20
0
 @Override
 public void release() {
   if (tableView != null) {
     tableView.release();
     tableView = null;
   }
   nativeView = null;
   super.release();
 }
Ejemplo n.º 21
0
  protected TiUIView handleGetView() {
    if (view == null) {
      Log.d(TAG, "getView: " + getClass().getSimpleName(), Log.DEBUG_MODE);

      Activity activity = getActivity();
      view = createView(activity);
      if (isDecorView) {
        if (activity != null) {
          ((TiBaseActivity) activity).setViewProxy(view.getProxy());
        } else {
          Log.w(TAG, "Activity is null", Log.DEBUG_MODE);
        }
      }
      realizeViews(view);
      view.registerForTouch();
    }
    return view;
  }
Ejemplo n.º 22
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);
  }
Ejemplo n.º 23
0
 protected void handleHide(KrollDict options) {
   if (view != null) {
     synchronized (pendingAnimationLock) {
       if (pendingAnimation != null) {
         handlePendingAnimation(false);
       }
     }
     view.hide();
     setProperty(TiC.PROPERTY_VISIBLE, false);
   }
 }
  protected View getParentView() {
    if (nativeView == null) {
      return null;
    }

    ViewParent parent = nativeView.getParent();
    if (parent instanceof View) {
      return (View) parent;
    }
    if (parent == null) {
      TiViewProxy parentProxy = proxy.getParent();
      if (parentProxy != null) {
        TiUIView parentTiUi = parentProxy.peekView();
        if (parentTiUi != null) {
          return parentTiUi.getNativeView();
        }
      }
    }
    return null;
  }
Ejemplo n.º 25
0
  @Override
  public void processProperties(KrollDict d) {
    if (d.get(TiC.PROPERTY_BUTTON_NAMES) != null && d.containsKey(TiC.PROPERTY_OK)) {
      d.remove(TiC.PROPERTY_OK);
    }

    if (d.get(TiC.PROPERTY_CUSTOM_VIEW) != null && d.containsKey(TiC.PROPERTY_OPTIONS)) {
      d.remove(TiC.PROPERTY_OPTIONS);
    }
    super.processProperties(d);
  }
Ejemplo n.º 26
0
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   if (key.equals("value")) {
     Date date = (Date) newValue;
     setValue(date.getTime());
   }
   if (key.equals(TiC.PROPERTY_CALENDAR_VIEW_SHOWN)) {
     setCalendarView(TiConvert.toBoolean(newValue));
   }
   super.propertyChanged(key, oldValue, newValue, proxy);
 }
Ejemplo n.º 27
0
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   if (DBG) {
     Log.d(LCAT, "Property: " + key + " old: " + oldValue + " new: " + newValue);
   }
   if (key.equals(TiC.PROPERTY_SEPARATOR_COLOR)) {
     tableView.setSeparatorColor(TiConvert.toString(newValue));
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }
Ejemplo n.º 28
0
  @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);
  }
Ejemplo n.º 29
0
 public void handleRemove(TiViewProxy child) {
   if (children != null) {
     children.remove(child);
     if (view != null) {
       view.remove(child.peekView());
     }
     if (child != null) {
       child.releaseViews();
     }
   }
 }
Ejemplo n.º 30
0
 @Override
 public void focus() {
   super.focus();
   if (nativeView != null) {
     if (proxy.hasProperty(TiC.PROPERTY_EDITABLE)
         && !(TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_EDITABLE)))) {
       TiUIHelper.showSoftKeyboard(nativeView, false);
     } else {
       TiUIHelper.requestSoftInputChange(proxy, nativeView);
     }
   }
 }