Java Code Examples for org.appcelerator.kroll.KrollDict#get()

The following examples show how to use org.appcelerator.kroll.KrollDict#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionViewTemplate.java    From TiCollectionView with MIT License 6 votes vote down vote up
public void updateOrMergeWithDefaultProperties(KrollDict data, boolean update) {
	for (String binding: data.keySet()) {
		DataItem dataItem = dataItems.get(binding);
		if (dataItem == null) continue;

		KrollDict defaultProps = dataItem.getDefaultProperties();
		KrollDict props = new KrollDict((HashMap)data.get(binding));
		if (defaultProps != null) {
			if (update) {
				//update default properties
				Set<String> existingKeys = defaultProps.keySet();
				for (String key:  props.keySet()) {
					if (!existingKeys.contains(key)) {
						defaultProps.put(key, null);
					}
				}
			} else {
				//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);
			}
		}
	}

}
 
Example 2
Source File: ViewItem.java    From TiCollectionView with MIT License 6 votes vote down vote up
/**
 * 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 (CollectionView.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;
	
}
 
Example 3
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 6 votes vote down vote up
public CollectionItemData (KrollDict properties, CollectionViewTemplate 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;
			Object searchText = propsHash.get(TiC.PROPERTY_SEARCHABLE_TEXT);
			if (propsHash.containsKey(TiC.PROPERTY_SEARCHABLE_TEXT) && searchText != null) {
				searchableText = TiConvert.toString(searchText);
			}
		}
	}

}
 
Example 4
Source File: CollectionViewTemplate.java    From TiCollectionView with MIT License 5 votes vote down vote up
private DataItem bindProxiesAndProperties(KrollDict properties, boolean isRootTemplate, DataItem parent) {
	Object proxy = null;
	String id = null;
	Object props = null;
	DataItem item = null;
	if (properties.containsKey(TiC.PROPERTY_TI_PROXY)) {
		proxy = properties.get(TiC.PROPERTY_TI_PROXY);
	}

	//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);
	} else {
		id = GENERATED_BINDING + Math.random();
	}
	

	if (proxy instanceof TiViewProxy) {
		TiViewProxy viewProxy = (TiViewProxy) proxy;
		if (isRootTemplate) {
			rootItem = item = new DataItem(viewProxy, TiC.PROPERTY_PROPERTIES, null);
		} else {
			item = new DataItem(viewProxy, id, parent);
			parent.addChild(item);
		}
		dataItems.put(id, item);
	}

	if (properties.containsKey(TiC.PROPERTY_PROPERTIES)) {
		props = properties.get(TiC.PROPERTY_PROPERTIES);
	}
	
	if (props instanceof HashMap) {
		item.setDefaultProperties(new KrollDict((HashMap)props));
	}

	return item;
}
 
Example 5
Source File: CollectionView.java    From TiCollectionView with MIT License 5 votes vote down vote up
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));
		CollectionViewTemplate template = new CollectionViewTemplate(key, properties);
		//Set type to template, for recycling purposes.
		template.setType(getItemType());
		templatesByBinding.put(key, template);
		//set parent of root item
		template.setRootParent(proxy);
	}
}
 
Example 6
Source File: CollectionItemProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
private void fireItemClick(String event, Object data)
{
	if (event.equals(TiC.EVENT_CLICK) && data instanceof HashMap) {
		KrollDict eventData = new KrollDict((HashMap) data);
		Object source = eventData.get(TiC.EVENT_PROPERTY_SOURCE);
		if (source != null && !source.equals(this) && listProxy != null) {
			TiViewProxy listViewProxy = listProxy.get();
			if (listViewProxy != null) {
				listViewProxy.fireEvent(TiC.EVENT_ITEM_CLICK, eventData);
			}
		}
	}
}
 
Example 7
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
public void handleCreationDict(KrollDict options) {
	super.handleCreationDict(options);
	//Adding sections to preload sections, so we can handle appendSections/insertSection
	//accordingly if user call these before TiListView is instantiated.
	if (options.containsKey(TiC.PROPERTY_SECTIONS)) {
		Object obj = options.get(TiC.PROPERTY_SECTIONS);
		if (obj instanceof Object[]) {
			addPreloadSections((Object[]) obj, -1, true);
		}
	}
}
 
Example 8
Source File: ImagepickerModule.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Kroll.method
public void createCustomGallery(KrollDict options) {
	if ( (options != null) && options.containsKeyAndNotNull(Defaults.Params.IMAGES) ) {
		Object[] imageArray = (Object []) options.get(Defaults.Params.IMAGES);
		int size = imageArray.length;

		if (size != 0) {
			ArrayList<ImageViewerInfo> imagesInfo = new ArrayList<ImageViewerInfo>();

			for (int i=0; i<size; i++) {
				Object o = imageArray[i];
				KrollDict info = new KrollDict((HashMap<String, Object>) o);

				if ( (info != null) && info.containsKeyAndNotNull(Defaults.Params.IMAGE_PATH) ) {
					String path = info.getString(Defaults.Params.IMAGE_PATH);
					String title = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE) ? info.getString(Defaults.Params.IMAGE_TITLE) : "";
					String titleColor = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE_COLOR) ? info.getString(Defaults.Params.IMAGE_TITLE_COLOR) : Defaults.IMAGE_TITLE_COLOR;
					String titleBgColor = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE_BACKGROUND_COLOR) ? info.getString(Defaults.Params.IMAGE_TITLE_BACKGROUND_COLOR) : Defaults.IMAGE_TITLE_BACKGROUND_COLOR;

					imagesInfo.add(new ImageViewerInfo(path, title, titleColor, titleBgColor));
				}
			}

			if (imagesInfo.size() > 0) {
				Activity activity = TiApplication.getAppCurrentActivity();

				Intent intent = new Intent(activity, ImageViewerActivity.class);
				intent = prepareExtrasForIntent(intent, options, false);
				intent.putParcelableArrayListExtra(Defaults.Params.IMAGES, imagesInfo);

				activity.startActivity(intent);
			}

		} else {
			Log.e(Defaults.LCAT, "No images passed.");
		}

	} else {
		Log.e(Defaults.LCAT, "No options passed.");
	}
}
 
Example 9
Source File: ImagepickerModule.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Kroll.method
public void createCustomGallery(KrollDict options) {
	if ( (options != null) && options.containsKeyAndNotNull(Defaults.Params.IMAGES) ) {
		Object[] imageArray = (Object []) options.get(Defaults.Params.IMAGES);
		int size = imageArray.length;

		if (size != 0) {
			ArrayList<ImageViewerInfo> imagesInfo = new ArrayList<ImageViewerInfo>();

			for (int i=0; i<size; i++) {
				Object o = imageArray[i];
				KrollDict info = new KrollDict((HashMap<String, Object>) o);

				if ( (info != null) && info.containsKeyAndNotNull(Defaults.Params.IMAGE_PATH) ) {
					String path = info.getString(Defaults.Params.IMAGE_PATH);
					String title = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE) ? info.getString(Defaults.Params.IMAGE_TITLE) : "";
					String titleColor = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE_COLOR) ? info.getString(Defaults.Params.IMAGE_TITLE_COLOR) : Defaults.IMAGE_TITLE_COLOR;
					String titleBgColor = info.containsKeyAndNotNull(Defaults.Params.IMAGE_TITLE_BACKGROUND_COLOR) ? info.getString(Defaults.Params.IMAGE_TITLE_BACKGROUND_COLOR) : Defaults.IMAGE_TITLE_BACKGROUND_COLOR;

					imagesInfo.add(new ImageViewerInfo(path, title, titleColor, titleBgColor));
				}
			}

			if (imagesInfo.size() > 0) {
				Activity activity = TiApplication.getAppCurrentActivity();

				Intent intent = new Intent(activity, ImageViewerActivity.class);
				intent = prepareExtrasForIntent(intent, options, false);
				intent.putParcelableArrayListExtra(Defaults.Params.IMAGES, imagesInfo);

				activity.startActivity(intent);
			}

		} else {
			Log.e(Defaults.LCAT, "No images passed.");
		}

	} else {
		Log.e(Defaults.LCAT, "No options passed.");
	}
}
 
Example 10
Source File: TicroutonModule.java    From TiCrouton with MIT License 4 votes vote down vote up
@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();
 			}
 		});
	
}
 
Example 11
Source File: TicroutonModule.java    From TiCrouton with MIT License 4 votes vote down vote up
@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;
	
}