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

The following examples show how to use org.appcelerator.kroll.KrollDict#put() . 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: GalleryResultHandler.java    From titanium-imagepicker with Apache License 2.0 6 votes vote down vote up
protected void flushResponse(Object... params) {
	if (null != callback) {
		ArrayList<Object> args = new ArrayList<Object>();
		
		for (Object a : params) {
			args.add(a);	
		}
		
		int length = args.size();
		KrollDict response = new KrollDict();
		
		for (int i=0; i<length; i++) {		// double increase i to make key-value pair
			String key = (String) args.get(i);
			++i;
			response.put(key, args.get(i));
		}
		
		callback.callAsync(krollObject, response);
	}
}
 
Example 2
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
@Kroll.method
public KrollDict getPairedDevices()
{
	Log.d(TAG, "getPairedDevices called");
	
	Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
	
	KrollDict result = new KrollDict();
	
	// If there are paired devices
	if (pairedDevices.size() > 0) 
	{
	    // Loop through paired devices
	    for (BluetoothDevice device : pairedDevices) 
	    {
	    	//Halilk: for some devices, device name is the same so put some of mac digits
	    	String strDigitstoAdd = device.getAddress();
	    	strDigitstoAdd = strDigitstoAdd.replace(":","");
	    	result.put(device.getName()+"_"+strDigitstoAdd, device.getAddress());		    	
	    }
	}
	
	return result;
	
}
 
Example 3
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 6 votes vote down vote up
@Kroll.method
public void replaceItemsAt(int index, int count, Object data) {
	if (!isIndexValid(index)) {
		return;
	}

	if (TiApplication.isUIThread()) {
		handleReplaceItemsAt(index, count, data);
	} else {
		KrollDict d = new KrollDict();
		d.put(TiC.EVENT_PROPERTY_INDEX, index);
		d.put(TiC.PROPERTY_COUNT, count);
		d.put(TiC.PROPERTY_DATA, data);
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REPLACE_ITEMS_AT), d);
	}
}
 
Example 4
Source File: GalleryResultHandler.java    From titanium-imagepicker with Apache License 2.0 6 votes vote down vote up
protected void flushResponse(Object... params) {
	if (null != callback) {
		ArrayList<Object> args = new ArrayList<Object>();
		
		for (Object a : params) {
			args.add(a);	
		}
		
		int length = args.size();
		KrollDict response = new KrollDict();
		
		for (int i=0; i<length; i++) {		// double increase i to make key-value pair
			String key = (String) args.get(i);
			++i;
			response.put(key, args.get(i));
		}
		
		callback.callAsync(krollObject, response);
	}
}
 
Example 5
Source File: DefaultCollectionViewTemplate.java    From TiCollectionView with MIT License 5 votes vote down vote up
private void parseDefaultData(KrollDict data) {
	//for built-in template, we only process 'properties' key
	Iterator<String> bindings = data.keySet().iterator();
	while (bindings.hasNext()) {
		String binding = bindings.next();
		if (!binding.equals(TiC.PROPERTY_PROPERTIES)) {
			Log.e(TAG, "Please only use 'properties' key for built-in template", Log.DEBUG_MODE);
			bindings.remove();
		}
	}

	KrollDict properties = data.getKrollDict(TiC.PROPERTY_PROPERTIES);
	KrollDict clone_properties = new KrollDict((HashMap)properties);
	if (clone_properties.containsKey(TiC.PROPERTY_TITLE)) {
		KrollDict text = new KrollDict();
		text.put(TiC.PROPERTY_TEXT, TiConvert.toString(clone_properties, TiC.PROPERTY_TITLE));
		data.put(TiC.PROPERTY_TITLE, text);
		if (clone_properties.containsKey(TiC.PROPERTY_FONT)) {
			text.put(TiC.PROPERTY_FONT, clone_properties.getKrollDict(TiC.PROPERTY_FONT).clone());
			clone_properties.remove(TiC.PROPERTY_FONT);
		}
		if (clone_properties.containsKey(TiC.PROPERTY_COLOR)) {
			text.put(TiC.PROPERTY_COLOR, clone_properties.get(TiC.PROPERTY_COLOR));
			clone_properties.remove(TiC.PROPERTY_COLOR);
		}
		clone_properties.remove(TiC.PROPERTY_TITLE);
	}
	
	if (clone_properties.containsKey(TiC.PROPERTY_IMAGE)) {
		KrollDict image = new KrollDict();
		image.put(TiC.PROPERTY_IMAGE, TiConvert.toString(clone_properties, TiC.PROPERTY_IMAGE));
		data.put(TiC.PROPERTY_IMAGE, image);
		clone_properties.remove(TiC.PROPERTY_IMAGE);
	}
	
	data.put(TiC.PROPERTY_PROPERTIES, clone_properties);
}
 
Example 6
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void updateItemAt(int index, Object data) {
	if (!isIndexValid(index) || !(data instanceof HashMap)) {
		return;
	}

	if (TiApplication.isUIThread()) {
		handleUpdateItemAt(index,  new Object[]{data});
	} else {
		KrollDict d = new KrollDict();
		d.put(TiC.EVENT_PROPERTY_INDEX, index);
		d.put(TiC.PROPERTY_DATA, new Object[]{data});
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_UPDATE_ITEM_AT), d);
	}
}
 
Example 7
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void insertItemsAt(int index, Object data) {
	if (!isIndexValid(index)) {
		return;
	}
	
	if (TiApplication.isUIThread()) {
		handleInsertItemsAt(index, data);
	} else {
		KrollDict d = new KrollDict();
		d.put(TiC.PROPERTY_DATA, data);
		d.put(TiC.EVENT_PROPERTY_INDEX, index);
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_INSERT_ITEMS_AT), d);
	}
}
 
Example 8
Source File: CollectionItem.java    From TiCollectionView with MIT License 5 votes vote down vote up
public void processProperties(KrollDict d) {

		if (d.containsKey(TiC.PROPERTY_ACCESSORY_TYPE)) {
			int accessory = TiConvert.toInt(d.get(TiC.PROPERTY_ACCESSORY_TYPE), -1);
			handleAccessory(accessory);
		}
		if (d.containsKey(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR)) {
			d.put(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR, d.get(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR));
		}
		if (d.containsKey(TiC.PROPERTY_SELECTED_BACKGROUND_IMAGE)) {
			d.put(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE, d.get(TiC.PROPERTY_SELECTED_BACKGROUND_IMAGE));
		}
		super.processProperties(d);
	}
 
Example 9
Source File: CameraViewProxy.java    From Ti-Android-CameraView with MIT License 5 votes vote down vote up
private void triggerEvent( String path )
{
	KrollDict imagePath = new KrollDict();
	
	File extFile = new File(path);
	Uri uriPath = Uri.fromFile(extFile);
	imagePath.put("path", uriPath.toString());
	
	Log.i(TAG, "Sending path back to Titanium. Image Path > "+uriPath.toString());
	
	fireEvent("picture_taken", imagePath);
}
 
Example 10
Source File: RealSwitch.java    From RealSwitch with MIT License 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton btn, boolean value) {
	KrollDict data = new KrollDict();

	proxy.setProperty(TiC.PROPERTY_VALUE, value);
	// if user triggered change, we fire it.
	if (oldValue != value) {
		data.put(TiC.PROPERTY_VALUE, value);
		fireEvent(TiC.EVENT_CHANGE, data);
		oldValue = value;
	}
}
 
Example 11
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 4 votes vote down vote up
private void sendReplaceSectionMessage(int index, Object section) {
	KrollDict data = new KrollDict();
	data.put("index", index);
	data.put("section", section);
	TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REPLACE_SECTION_AT), data);
}
 
Example 12
Source File: DefaultCollectionViewTemplate.java    From TiCollectionView with MIT License 4 votes vote down vote up
public void generateDefaultProps(Activity activity) {
	
	//Generate root item data proxy
	CollectionItemProxy proxy = new CollectionItemProxy();
	proxy.setActivity(activity);
	rootItem = new DataItem(proxy, TiC.PROPERTY_PROPERTIES, null);
	dataItems.put(itemID, rootItem);

	//Init default properties for our proxies
	KrollDict defaultLabelProperties = new KrollDict();
	KrollDict defaultImageProperties = new KrollDict();

	//Generate label proxy
	LabelProxy labelProxy = new LabelProxy();
	labelProxy.getProperties().put(TiC.PROPERTY_TOUCH_ENABLED, false);
	labelProxy.setActivity(activity);
	//Generate properties
	defaultLabelProperties.put(TiC.PROPERTY_LEFT, "2dp");
	defaultLabelProperties.put(TiC.PROPERTY_WIDTH, "55%");
	defaultLabelProperties.put(TiC.PROPERTY_TEXT, "label");
	//bind the proxy and default propertiess
	DataItem labelItem = new DataItem(labelProxy, TiC.PROPERTY_TITLE, rootItem);
	dataItems.put(TiC.PROPERTY_TITLE, labelItem);
	//set default properties
	labelItem.setDefaultProperties(defaultLabelProperties);
	//add child
	rootItem.addChild(labelItem);
	
	//Generate image proxy
	ImageViewProxy imageProxy = new ImageViewProxy();
	imageProxy.getProperties().put(TiC.PROPERTY_TOUCH_ENABLED, false);
	imageProxy.setActivity(activity);
	//Generate properties
	defaultImageProperties.put(TiC.PROPERTY_RIGHT, "25dp");
	defaultImageProperties.put(TiC.PROPERTY_WIDTH, "15%");
	//bind the proxy and default properties
	DataItem imageItem = new DataItem (imageProxy, TiC.PROPERTY_IMAGE, rootItem);
	dataItems.put(TiC.PROPERTY_IMAGE, imageItem);
	//set default properties
	imageItem.setDefaultProperties(defaultImageProperties);
	//add child
	rootItem.addChild(imageItem);
	

}
 
Example 13
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 4 votes vote down vote up
private void sendInsertSectionMessage(int index, Object section) {
	KrollDict data = new KrollDict();
	data.put("index", index);
	data.put("section", section);
	TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_INSERT_SECTION_AT), data);
}
 
Example 14
Source File: BluetoothService.java    From NovarumBluetooth with MIT License 4 votes vote down vote up
private void postError(String Error)
{
	KrollDict data = new KrollDict();
	data.put("error", Error);
	NovarumbluetoothModule.sendEvent("nb_onError", data);
}
 
Example 15
Source File: DatePickerProxy.java    From TiDialogs with MIT License 4 votes vote down vote up
private DatePickerDialog getDialog() {
	DatePickerDialog picker = new DatePickerDialog(this.proxy.getActivity(),
				new DatePickerDialog.OnDateSetListener() {
					// when dialog box is closed, below method will be
					// called.
					public void onDateSet(DatePicker view,
							int selectedYear, int selectedMonth,
							int selectedDay) {
						year = selectedYear;
						month = selectedMonth;
						day = selectedDay;

						KrollDict data = new KrollDict();

							Calendar calendar = Calendar.getInstance();
							calendar.set(Calendar.YEAR, year);
							calendar.set(Calendar.MONTH, month);
							calendar.set(Calendar.DAY_OF_MONTH, day);
							Date value = calendar.getTime();

							data.put("value", value);
							data.put("year", year);
							data.put("month", month);
							data.put("day", day);
                                  fireEvent("click", data);		

					}
				}, year, month, day);
	picker.setCanceledOnTouchOutside(false);

	picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);

	picker.setButton(DialogInterface.BUTTON_NEGATIVE, cancelButtonTitle,
		new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				fireEvent("cancel", new KrollDict());
			}
		});

	return picker;
}
 
Example 16
Source File: BluetoothService.java    From NovarumBluetooth with MIT License 4 votes vote down vote up
private void PostReceivedData(String data)
{
	if(data == null)
		return;
	
	//Activity can be closed, open the activity//
	TiApplication appContext = TiApplication.getInstance();
	Activity activity = appContext.getRootOrCurrentActivity();
	
	final TiIntentWrapper barcodeIntent = new TiIntentWrapper(new Intent(activity,appContext.getRootOrCurrentActivity().getClass()));
	
	try
	{			
		barcodeIntent.getIntent().putExtra("BluetoothData",data);
		appContext.startActivity(barcodeIntent.getIntent());
	}
	catch(Exception e)
	{
		Log.w(TAG,"Opening activity error on Service-PostReceivedData: "+e.getMessage());
		e.printStackTrace();
		
		//Then activity is background, try setting the flag//
		barcodeIntent.getIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		try
		{
			appContext.startActivity(barcodeIntent.getIntent());
		}
		catch(Exception e2)
		{
			Log.w(TAG,"Opening activity error on Service-PostReceivedData: "+e.getMessage());
			e.printStackTrace();				
		}
		
	}
	
	
	//Send the data//
	KrollDict receivedict = new KrollDict();
	
	receivedict.put("data", data);
	NovarumbluetoothModule.sendEvent("nb_onReceiveData", receivedict);		
	
	
	
}
 
Example 17
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 4 votes vote down vote up
private void postError(String Error)
{
	KrollDict data = new KrollDict();
	data.put("error", Error);
	this.fireEvent("nb_onError", data);
}
 
Example 18
Source File: TimePickerProxy.java    From TiDialogs with MIT License 4 votes vote down vote up
private TimePickerDialog getDialog() {
	TimePickerDialog picker = new TimePickerDialog(this.proxy.getActivity(),
				new TimePickerDialog.OnTimeSetListener() {

					@Override
					public void onTimeSet(TimePicker selectedTime,
							int selectedHour, int selectedMinute) {
						// TODO Auto-generated method stub

						hour = selectedHour;
						minute = selectedMinute;

						KrollDict data = new KrollDict();

							Calendar calendar = Calendar.getInstance();
							calendar.set(Calendar.HOUR_OF_DAY, hour);
							calendar.set(Calendar.MINUTE, minute);
							Date value = calendar.getTime();

							data.put("value", value);
							data.put("hour", hour);
							data.put("minute", minute);
                                  fireEvent("click", data);

					}
				}, hour, minute, DateFormat.is24HourFormat(this.proxy
						.getActivity()));

	picker.setCanceledOnTouchOutside(false);

	picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);

	picker.setButton(DialogInterface.BUTTON_NEGATIVE, cancelButtonTitle,
		new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				fireEvent("cancel", new KrollDict());
			}
		});

	return picker;
}
 
Example 19
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 3 votes vote down vote up
private void PostReceivedData(String data)
{
	if(data == null)
		return;
	
	
	KrollDict receivedict = new KrollDict();
	
	receivedict.put("data", data);
	this.fireEvent("nb_onReceiveData", receivedict);
	
	
	
}
 
Example 20
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 3 votes vote down vote up
public void discoverabilityResult(int Result)
{
	KrollDict data = new KrollDict();
	
	data.put("result",Integer.toString(Result));
	
	Log.w(TAG,"NovarumBluetooth Discoverability Result" + Result);
	
	fireEvent("nb_onDiscoverabilityResult", data);
}