Java Code Examples for org.appcelerator.titanium.util.TiConvert#toString()

The following examples show how to use org.appcelerator.titanium.util.TiConvert#toString() . 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: 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 2
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 3
Source File: ExampleProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
public ExampleView(TiViewProxy proxy) {
	super(proxy);
	LayoutArrangement arrangement = LayoutArrangement.DEFAULT;

	if (proxy.hasProperty(TiC.PROPERTY_LAYOUT)) {
		String layoutProperty = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_LAYOUT));
		if (layoutProperty.equals(TiC.LAYOUT_HORIZONTAL)) {
			arrangement = LayoutArrangement.HORIZONTAL;
		} else if (layoutProperty.equals(TiC.LAYOUT_VERTICAL)) {
			arrangement = LayoutArrangement.VERTICAL;
		}
	}
	setNativeView(new TiCompositeLayout(proxy.getActivity(), arrangement));
}
 
Example 4
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
private CollectionViewTemplate processTemplate(KrollDict itemData, int index) {
	
	CollectionView 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);
		}

		CollectionViewTemplate 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)) {
			CollectionViewTemplate defTemplate = listView.getTemplateByBinding(defaultTemplateBinding);
			if (defTemplate != null) {
				return defTemplate;
			}
		}
		return processDefaultTemplate(itemData, index);
	}	
	
}
 
Example 5
Source File: ExampleProxy.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
public ExampleView(TiViewProxy proxy) {
	super(proxy);
	LayoutArrangement arrangement = LayoutArrangement.DEFAULT;

	if (proxy.hasProperty(TiC.PROPERTY_LAYOUT)) {
		String layoutProperty = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_LAYOUT));
		if (layoutProperty.equals(TiC.LAYOUT_HORIZONTAL)) {
			arrangement = LayoutArrangement.HORIZONTAL;
		} else if (layoutProperty.equals(TiC.LAYOUT_VERTICAL)) {
			arrangement = LayoutArrangement.VERTICAL;
		}
	}
	setNativeView(new TiCompositeLayout(proxy.getActivity(), arrangement));
}
 
Example 6
Source File: CollectionView.java    From TiCollectionView with MIT License 4 votes vote down vote up
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {

		if (key.equals(TiC.PROPERTY_HEADER_TITLE)) {
			setHeaderTitle(TiConvert.toString(newValue));
		} else if (key.equals(TiC.PROPERTY_FOOTER_TITLE)) {
			setFooterTitle(TiConvert.toString(newValue));
		} else if (key.equals(TiC.PROPERTY_SECTIONS) && newValue instanceof Object[] ) {
			processSectionsAndNotify((Object[])newValue);
		} else if (key.equals(TiC.PROPERTY_SEARCH_TEXT)) {
			this.searchText = TiConvert.toString(newValue);
			if (this.searchText != null) {
				reFilter(this.searchText);
			}
		} else if (key.equals(TiC.PROPERTY_CASE_INSENSITIVE_SEARCH)) {
			this.caseInsensitive = TiConvert.toBoolean(newValue, true);
			if (this.searchText != null) {
				reFilter(this.searchText);
			}
		} else if (key.equals(TiC.PROPERTY_SEARCH_VIEW)) {
			TiViewProxy searchView = (TiViewProxy) newValue;
			if (isSearchViewValid(searchView)) {
				TiUIView search = searchView.getOrCreateView();
				setSearchListener(searchView, search);
				if (searchLayout != null) {
					searchLayout.removeAllViews();
					addSearchLayout(searchLayout, searchView, search);
				} else {
					layoutSearchView(searchView);
				}
			} else {
				Log.e(TAG, "Searchview type is invalid");
			}
			
		} else if (key.equals(TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR) && newValue != null) {
			listView.setVerticalScrollBarEnabled(TiConvert.toBoolean(newValue));
		} else if (key.equals(TiC.PROPERTY_DEFAULT_ITEM_TEMPLATE) && newValue != null) {
			defaultTemplateBinding = TiConvert.toString(newValue);
			refreshItems();
		} else if (key.equals(TiC.PROPERTY_SEPARATOR_COLOR)) {
			String color = TiConvert.toString(newValue);
			setSeparatorColor(color);
		} else {
			super.propertyChanged(key, oldValue, newValue, proxy);
		}
	}
 
Example 7
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 8
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;
	
}