private void bindProxiesAndProperties(KrollDict properties, boolean isRootTemplate) { String id = null; Object props = null; DataItem item = null; // Get/generate random bind id if (isRootTemplate) { id = itemID; } else if (properties.containsKey(TiC.PROPERTY_BIND_ID)) { id = TiConvert.toString(properties, TiC.PROPERTY_BIND_ID); } if (id == null) return; if (isRootTemplate) { rootItem = item = new DataItem(TiC.PROPERTY_PROPERTIES); } else { item = new DataItem(id); } dataItems.put(id, item); if (properties.get(TiC.PROPERTY_PROPERTIES) != null) { props = properties.get(TiC.PROPERTY_PROPERTIES); } if (props instanceof HashMap) { item.setDefaultProperties(new KrollDict((HashMap) props)); } }
@Override public void handleCreationDict(KrollDict options) { options = handleStyleOptions(options); if (langConversionTable != null) { KrollDict foundStrings = new KrollDict(); for (String key : langConversionTable.keySet()) { // if we have it already, ignore if (!options.containsKey(key)) { String convertKey = (String) langConversionTable.get(key); String langKey = (String) options.get(convertKey); if (langKey != null) { try { String localText = getLocalizedText(langKey); foundStrings.put(key, localText); } catch (TiRHelper.ResourceNotFoundException e) { Log.w(LCAT, "Localized text key '" + langKey + "' is invalid."); } } } } if (!(foundStrings.isEmpty())) { extend(foundStrings); options.putAll(foundStrings); } } options = handleStyleOptions(options); super.handleCreationDict(options); // TODO eventManager.addOnEventChangeListener(this); }
@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 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); }
@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(); } }); }
@Kroll.method public TiBlob mask(HashMap args) { KrollDict arg = new KrollDict(args); TiBlob blob = (TiBlob) arg.get("image"); TiBlob blob2 = (TiBlob) arg.get("mask"); TiDrawableReference ref = TiDrawableReference.fromBlob(activity, blob); TiDrawableReference ref2 = TiDrawableReference.fromBlob(activity, blob2); Bitmap img = mask(ref.getBitmap(), ref2.getBitmap()); TiBlob result = TiBlob.blobFromImage(img); return result; }
public TiGradientDrawable(View view, KrollDict properties) { super(new RectShape()); // Determine which type of gradient is being used. // Supported types are 'linear' and 'radial'. String type = properties.optString("type", "linear"); if (type.equals("linear")) { gradientType = GradientType.LINEAR_GRADIENT; } else if (type.equals("radial")) { gradientType = GradientType.RADIAL_GRADIENT; // TODO: Add support for radial gradients. // Android's RadialGradient only supports a single circle. // We need to figure out how to support two circle gradients // as specified by the HTML Canvas specification. return; } else { throw new IllegalArgumentException("Invalid gradient type. Must be linear or radial."); } // Load the 'startPoint' property which defines the start of the gradient. Object startPointObject = properties.get("startPoint"); if (startPointObject instanceof HashMap) { startPoint = new TiPoint((HashMap) startPointObject, 0, 0); } // Load the 'endPoint' property which defines the end of the gradient. // Note: this is only used for linear gradient since Android does not // support an ending circle for radial gradients. Object endPointObject = properties.get("endPoint"); if (endPointObject instanceof HashMap) { endPoint = new TiPoint((HashMap) endPointObject, 0, 1); } startRadius = TiConvert.toTiDimension(properties, "startRadius", TiDimension.TYPE_UNDEFINED); if (startRadius == null) { startRadius = DEFAULT_RADIUS; } Object colors = properties.get("colors"); if (!(colors instanceof Object[])) { Log.w(LCAT, "Android does not support gradients without colors."); throw new IllegalArgumentException("Must provide an array of colors."); } loadColors((Object[]) colors); this.view = view; setShaderFactory(new GradientShaderFactory()); }
private KrollDict dictFromEvent(KrollDict dictToCopy) { KrollDict data = new KrollDict(); if (dictToCopy.containsKey(TiC.EVENT_PROPERTY_X)) { data.put(TiC.EVENT_PROPERTY_X, dictToCopy.get(TiC.EVENT_PROPERTY_X)); } else { data.put(TiC.EVENT_PROPERTY_X, (double) 0); } if (dictToCopy.containsKey(TiC.EVENT_PROPERTY_Y)) { data.put(TiC.EVENT_PROPERTY_Y, dictToCopy.get(TiC.EVENT_PROPERTY_Y)); } else { data.put(TiC.EVENT_PROPERTY_Y, (double) 0); } data.put(TiC.EVENT_PROPERTY_SOURCE, proxy); return data; }
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; }
private Intent createAlarmServiceIntent(KrollDict args) { String serviceName = args.getString("service"); Intent intent = new Intent(TiApplication.getInstance().getApplicationContext(), AlarmServiceListener.class); intent.putExtra("alarm_service_name", serviceName); // Pass in flag if we need to restart the service on each call intent.putExtra("alarm_service_force_restart", (optionIsEnabled(args, "forceRestart"))); // Check if the user has selected to use intervals boolean hasInterval = (args.containsKeyAndNotNull("interval")); long intervalValue = 0; if (hasInterval) { Object interval = args.get("interval"); if (interval instanceof Number) { intervalValue = ((Number) interval).longValue(); } else { hasInterval = false; } } intent.putExtra("alarm_service_has_interval", hasInterval); if (hasInterval) { intent.putExtra("alarm_service_interval", intervalValue); } utils.debugLog( "created alarm service intent for " + serviceName + "(forceRestart: " + (optionIsEnabled(args, "forceRestart") ? "true" : "false") + ", intervalValue: " + intervalValue + ")"); return intent; }
// Handle creation options @Override public void handleCreationDict(KrollDict options) { super.handleCreationDict(options); if (options.containsKey("message")) { Log.d(TAG, "example created with message: " + options.get("message")); } }
private boolean optionIsEnabled(KrollDict args, String paramName) { if (args.containsKeyAndNotNull(paramName)) { Object value = args.get(paramName); return TiConvert.toBoolean(value); } else { return false; } }
@Kroll.method public Crouton make(KrollDict args) { Log.d(TAG, "make called"); 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()); } return crouton; }
// Methods @SuppressWarnings("deprecation") private KrollFunction getCallback(final KrollDict options, final String name) throws Exception { if (options.containsKey(name)) { return (KrollFunction) options.get(name); } else { Log.d(LCAT, "Callback not found: " + name); throw new Exception("Callback not found: " + name); } }
/** * If the row does not carry section information, it will be added to the currentSection. If it * does carry section information (i.e., a header), that section will be created and the row added * to it. Either way, whichever section the row gets added to will be returned. */ private TableViewSectionProxy addRowToSection( TableViewRowProxy row, TableViewSectionProxy currentSection) { KrollDict d = row.getProperties(); TableViewSectionProxy addedToSection = null; if (currentSection == null || d.containsKey(TiC.PROPERTY_HEADER)) { addedToSection = new TableViewSectionProxy(getTiContext()); } else { addedToSection = currentSection; } if (d.containsKey(TiC.PROPERTY_HEADER)) { addedToSection.setProperty(TiC.PROPERTY_HEADER_TITLE, d.get(TiC.PROPERTY_HEADER)); } if (d.containsKey(TiC.PROPERTY_FOOTER)) { addedToSection.setProperty(TiC.PROPERTY_FOOTER_TITLE, d.get(TiC.PROPERTY_FOOTER)); } addedToSection.add(row); return addedToSection; }
public void connect(KrollDict args) throws RuntimeException { if (device == null) { // this.getCapabilityToken(args.get("url").toString()); PendingIntentProxy proxy = (PendingIntentProxy) args.get("pendingIntent"); PendingIntent pendingIntent = proxy.getPendingIntent(); this.getCapabilityToken(args.get("url").toString(), pendingIntent); } if (args.containsKey("params") && args.get("params") instanceof HashMap) { HashMap<String, String> params = (HashMap<String, String>) args.get("params"); Map<String, String> parameters = new HashMap<String, String>(); for (String key : params.keySet()) { parameters.put(key, params.get(key).toString()); } connection = device.connect(parameters, null); } else { connection = device.connect(null, null); } }
public void processProperties(KrollDict d) { if (d.containsKey(TiC.PROPERTY_LAYOUT)) { String layout = TiConvert.toString(d, TiC.PROPERTY_LAYOUT); if (nativeView instanceof TiCompositeLayout) { ((TiCompositeLayout) nativeView).setLayoutArrangement(layout); } } if (TiConvert.fillLayout(d, layoutParams)) { if (nativeView != null) { nativeView.requestLayout(); } } Integer bgColor = null; // Default background processing. // Prefer image to color. if (hasImage(d) || hasColorState(d) || hasBorder(d)) { handleBackgroundImage(d); } else if (d.containsKey(TiC.PROPERTY_BACKGROUND_COLOR)) { bgColor = TiConvert.toColor(d, TiC.PROPERTY_BACKGROUND_COLOR); nativeView.setBackgroundColor(bgColor); } if (d.containsKey(TiC.PROPERTY_OPACITY)) { if (nativeView != null) { setOpacity(TiConvert.toFloat(d, TiC.PROPERTY_OPACITY)); } } if (d.containsKey(TiC.PROPERTY_VISIBLE)) { nativeView.setVisibility( TiConvert.toBoolean(d, TiC.PROPERTY_VISIBLE) ? View.VISIBLE : View.INVISIBLE); } if (d.containsKey(TiC.PROPERTY_ENABLED)) { nativeView.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED)); } if (d.containsKey(TiC.PROPERTY_FOCUSABLE)) { boolean focusable = TiConvert.toBoolean(d, TiC.PROPERTY_FOCUSABLE); nativeView.setFocusable(focusable); if (focusable) { registerForKeyClick(nativeView); } else { nativeView.setOnClickListener(null); } } initializeBorder(d, bgColor); if (d.containsKey(TiC.PROPERTY_TRANSFORM)) { Ti2DMatrix matrix = (Ti2DMatrix) d.get(TiC.PROPERTY_TRANSFORM); if (matrix != null) { applyTransform(matrix); } } }
@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); }
protected void processTemplates(KrollDict templates) { for (String key : templates.keySet()) { // Here we bind each template with a key so we can use it to look up later KrollDict properties = new KrollDict((HashMap) templates.get(key)); TiListViewTemplate template = new TiListViewTemplate(key, properties); // Set type to template, for recycling purposes. template.setType(getItemType()); templatesByBinding.put(key, template); // set parent of root item template.setRootParent(proxy); } }
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; }
// Handle creation options @Override public void handleCreationDict(KrollDict options) { super.handleCreationDict(options); // The identifier is what Branch will use to de-dupe the content across many different Universal // Objects if (options.containsKey("canonicalIdentifier")) { Log.d(LCAT, "setCanonicalIdentifier"); branchUniversalObject.setCanonicalIdentifier(options.getString("canonicalIdentifier")); } // This is where you define the open graph structure and how the object will appear on Facebook // or in a deepview if (options.containsKey("title")) { Log.d(LCAT, "setTitle"); branchUniversalObject.setTitle(options.getString("title")); } if (options.containsKey("contentDescription")) { Log.d(LCAT, "setContentDescription"); branchUniversalObject.setContentDescription(options.getString("contentDescription")); } if (options.containsKey("contentImageUrl")) { Log.d(LCAT, "setContentImageUrl"); branchUniversalObject.setContentImageUrl(options.getString("contentImageUrl")); } // You use this to specify whether this content can be discovered publicly - default is public if (options.containsKey("contentIndexingMode")) { Log.d(LCAT, "setContentIndexingMode"); if (options.getString("contentIndexingMode").equals("private")) { Log.d(LCAT, "private"); branchUniversalObject.setContentIndexingMode( BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE); } else { Log.d(LCAT, "public"); branchUniversalObject.setContentIndexingMode( BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC); } } // Here is where you can add custom keys/values to the deep link data if (options.containsKey("contentMetadata")) { Log.d(LCAT, "addContentMetadata"); Object contentMetadata = options.get("contentMetadata"); Map<String, String> hashMap = (Map<String, String>) contentMetadata; for (Iterator iterator = hashMap.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); branchUniversalObject.addContentMetadata(key, hashMap.get(key)); } } }
public ListItemData(KrollDict properties, TiListViewTemplate template) { this.properties = properties; this.template = template; // set searchableText if (properties.containsKey(TiC.PROPERTY_PROPERTIES)) { Object props = properties.get(TiC.PROPERTY_PROPERTIES); if (props instanceof HashMap) { HashMap<String, Object> propsHash = (HashMap<String, Object>) props; if (propsHash.containsKey(TiC.PROPERTY_SEARCHABLE_TEXT)) { searchableText = TiConvert.toString(propsHash, TiC.PROPERTY_SEARCHABLE_TEXT); } } } }
private void setPaintOptions() { tiPaint = new Paint(); tiPaint.setAntiAlias(true); tiPaint.setDither(true); tiPaint.setColor( (props.containsKeyAndNotNull("strokeColor")) ? TiConvert.toColor(props, "strokeColor") : TiConvert.toColor("black")); tiPaint.setStyle(Paint.Style.STROKE); tiPaint.setStrokeJoin(Paint.Join.ROUND); tiPaint.setStrokeCap(Paint.Cap.ROUND); tiPaint.setStrokeWidth( (props.containsKeyAndNotNull("strokeWidth")) ? TiConvert.toFloat(props.get("strokeWidth")) : 12); tiPaint.setAlpha( (props.containsKeyAndNotNull("strokeAlpha")) ? TiConvert.toInt(props.get("strokeAlpha")) : 255); alphaState = (props.containsKeyAndNotNull("strokeAlpha")) ? TiConvert.toInt(props.get("strokeAlpha")) : 255; }
@Override public void handleCreationDict(KrollDict dict) { Object data[] = null; if (dict.containsKey(TiC.PROPERTY_DATA)) { Object o = dict.get(TiC.PROPERTY_DATA); if (o != null && o instanceof Object[]) { data = (Object[]) o; dict.remove(TiC.PROPERTY_DATA); // don't override our data accessor } } super.handleCreationDict(dict); if (data != null) { processData(data); } }
public void handleCreationDict(KrollDict dict) { // getting header/footer titles from creation dictionary if (dict.containsKey(TiC.PROPERTY_HEADER_TITLE)) { headerTitle = TiConvert.toString(dict, TiC.PROPERTY_HEADER_TITLE); } if (dict.containsKey(TiC.PROPERTY_FOOTER_TITLE)) { footerTitle = TiConvert.toString(dict, TiC.PROPERTY_FOOTER_TITLE); } if (dict.containsKey(TiC.PROPERTY_HEADER_VIEW)) { Object obj = dict.get(TiC.PROPERTY_HEADER_VIEW); if (obj instanceof TiViewProxy) { headerView = (TiViewProxy) obj; } } if (dict.containsKey(TiC.PROPERTY_FOOTER_VIEW)) { Object obj = dict.get(TiC.PROPERTY_FOOTER_VIEW); if (obj instanceof TiViewProxy) { footerView = (TiViewProxy) obj; } } if (dict.containsKey(TiC.PROPERTY_ITEMS)) { handleSetItems(dict.get(TiC.PROPERTY_ITEMS)); } }
public void updateOrMergeWithDefaultProperties(KrollDict data) { for (String binding : dataItems.keySet()) { DataItem dataItem = dataItems.get(binding); if (dataItem == null) continue; KrollDict defaultProps = dataItem.getDefaultProperties(); if (defaultProps != null) { KrollDict props = data.containsKey(binding) ? new KrollDict((HashMap) data.get(binding)) : new KrollDict(); // merge default properties with new properties and update data HashMap<String, Object> newData = ((HashMap<String, Object>) defaultProps.clone()); newData.putAll(props); data.put(binding, newData); } } }
private TiListViewTemplate processTemplate(KrollDict itemData, int index) { TiListView listView = getListView(); String defaultTemplateBinding = null; if (listView != null) { defaultTemplateBinding = listView.getDefaultTemplateBinding(); } // if template is specified in data, we look it up and if one exists, we use it. // Otherwise we check if a default template is specified in ListView. If not, we use // builtInTemplate. String binding = TiConvert.toString(itemData.get(TiC.PROPERTY_TEMPLATE)); if (binding != null) { // check if template is default if (binding.equals(UIModule.LIST_ITEM_TEMPLATE_DEFAULT)) { return processDefaultTemplate(itemData, index); } TiListViewTemplate template = listView.getTemplateByBinding(binding); // if template is successfully retrieved, bind it to the index. This is b/c // each row can have a different template. if (template == null) { Log.e(TAG, "Template undefined"); } return template; } else { // if a valid default template is specify, use that one if (defaultTemplateBinding != null && !defaultTemplateBinding.equals(UIModule.LIST_ITEM_TEMPLATE_DEFAULT)) { TiListViewTemplate defTemplate = listView.getTemplateByBinding(defaultTemplateBinding); if (defTemplate != null) { return defTemplate; } } return processDefaultTemplate(itemData, index); } }
/** * This method compares applied properties of a view and our data model to generate a new set of * properties we need to set. It is crucial for scrolling performance. * * @param properties The properties from our data model * @return The difference set of properties to set */ public KrollDict generateDiffProperties(KrollDict properties) { diffProperties.clear(); for (String appliedProp : this.properties.keySet()) { if (!properties.containsKey(appliedProp)) { applyProperty(appliedProp, null); } } for (String property : properties.keySet()) { Object value = properties.get(property); if (TiListView.MUST_SET_PROPERTIES.contains(property)) { applyProperty(property, value); continue; } Object existingVal = this.properties.get(property); if (existingVal == null || value == null || !existingVal.equals(value)) { applyProperty(property, value); } } return diffProperties; }
private Intent createAlarmNotifyIntent(KrollDict args, int requestCode) { int notificationIcon = 0; String contentTitle = ""; String contentText = ""; String notificationSound = ""; boolean playSound = optionIsEnabled(args, "playSound"); boolean doVibrate = optionIsEnabled(args, "vibrate"); boolean showLights = optionIsEnabled(args, "showLights"); if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TITLE) || args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TEXT)) { if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TITLE)) { contentTitle = TiConvert.toString(args, TiC.PROPERTY_CONTENT_TITLE); } if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TEXT)) { contentText = TiConvert.toString(args, TiC.PROPERTY_CONTENT_TEXT); } ; } if (args.containsKey(TiC.PROPERTY_ICON)) { Object icon = args.get(TiC.PROPERTY_ICON); if (icon instanceof Number) { notificationIcon = ((Number) icon).intValue(); } else { String iconUrl = TiConvert.toString(icon); String iconFullUrl = resolveUrl(null, iconUrl); notificationIcon = TiUIHelper.getResourceId(iconFullUrl); if (notificationIcon == 0) { utils.debugLog("No image found for " + iconUrl); utils.debugLog("Default icon will be used"); } } } if (args.containsKey(TiC.PROPERTY_SOUND)) { notificationSound = TiConvert.toString(args, TiC.PROPERTY_SOUND); } if (args.containsKey("rootActivity")) { rootActivityClassName = TiConvert.toString(args, "rootActivity"); } Intent intent = new Intent( TiApplication.getInstance().getApplicationContext(), AlarmNotificationListener.class); // Add some extra information so when the alarm goes off we have enough to create the // notification intent.putExtra("notification_title", contentTitle); intent.putExtra("notification_msg", contentText); intent.putExtra("notification_has_icon", (notificationIcon != 0)); intent.putExtra("notification_icon", notificationIcon); intent.putExtra("notification_sound", notificationSound); intent.putExtra("notification_play_sound", playSound); intent.putExtra("notification_vibrate", doVibrate); intent.putExtra("notification_show_lights", showLights); intent.putExtra("notification_requestcode", requestCode); intent.putExtra("notification_root_classname", rootActivityClassName); intent.putExtra("notification_request_code", requestCode); intent.setData(Uri.parse("alarmId://" + requestCode)); return intent; }
@Kroll.method public void previewImage(KrollDict options) { Activity activity = TiApplication.getAppCurrentActivity(); if (activity == null) { Log.w(TAG, "Unable to get current activity for previewImage.", Log.DEBUG_MODE); return; } KrollFunction successCallback = null; KrollFunction errorCallback = null; TiBlob image = null; if (options.containsKey("success")) { successCallback = (KrollFunction) options.get("success"); } if (options.containsKey("error")) { errorCallback = (KrollFunction) options.get("error"); } if (options.containsKey("image")) { image = (TiBlob) options.get("image"); } if (image == null) { if (errorCallback != null) { errorCallback.callAsync( getKrollObject(), createErrorResponse(UNKNOWN_ERROR, "Missing image property")); } } TiBaseFile f = (TiBaseFile) image.getData(); final KrollFunction fSuccessCallback = successCallback; final KrollFunction fErrorCallback = errorCallback; Log.d(TAG, "openPhotoGallery called", Log.DEBUG_MODE); TiActivitySupport activitySupport = (TiActivitySupport) activity; Intent intent = new Intent(Intent.ACTION_VIEW); TiIntentWrapper previewIntent = new TiIntentWrapper(intent); String mimeType = image.getMimeType(); if (mimeType != null && mimeType.length() > 0) { intent.setDataAndType(Uri.parse(f.nativePath()), mimeType); } else { intent.setData(Uri.parse(f.nativePath())); } previewIntent.setWindowId(TiIntentWrapper.createActivityName("PREVIEW")); final int code = activitySupport.getUniqueResultCode(); activitySupport.launchActivityForResult( intent, code, new TiActivityResultHandler() { public void onResult(Activity activity, int requestCode, int resultCode, Intent data) { Log.e(TAG, "OnResult called: " + resultCode); if (fSuccessCallback != null) { KrollDict response = new KrollDict(); response.putCodeAndMessage(NO_ERROR, null); fSuccessCallback.callAsync(getKrollObject(), response); } } public void onError(Activity activity, int requestCode, Exception e) { String msg = "Gallery problem: " + e.getMessage(); Log.e(TAG, msg, e); if (fErrorCallback != null) { fErrorCallback.callAsync(getKrollObject(), createErrorResponse(UNKNOWN_ERROR, msg)); } } }); }