org.appcelerator.kroll.annotations.Kroll Java Examples

The following examples show how to use org.appcelerator.kroll.annotations.Kroll. 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: CollectionViewProxy.java    From TiCollectionView with MIT License 6 votes vote down vote up
@Kroll.setProperty @Kroll.method
public void setSections(Object sections)
{
	if (!(sections instanceof Object[])) {
		Log.e(TAG, "Invalid argument type to setSection(), needs to be an array", Log.DEBUG_MODE);
		return;
	}
	//Update java and javascript property
	setProperty(TiC.PROPERTY_SECTIONS, sections);

	Object[] sectionsArray = (Object[]) sections;
	TiUIView listView = peekView();
	//Preload sections if listView is not opened.
	if (listView == null) {
		preload = true;
		clearPreloadSections();
		addPreloadSections(sectionsArray, -1, true);
	} else {
		if (TiApplication.isUIThread()) {
			((CollectionView)listView).processSectionsAndNotify(sectionsArray);
		} else {
			TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_SECTIONS), sectionsArray);
		}
		
	}
}
 
Example #2
Source File: TiGooshModule.java    From ti.goosh with MIT License 6 votes vote down vote up
@Kroll.method
public void unregisterForPushNotifications() {
	final String senderId = getSenderId();
	final Context context = TiApplication.getInstance().getApplicationContext();

	new AsyncTask<Void, Void, Void>() {
		@Override
		protected Void doInBackground(Void... params) {
			try {
				InstanceID.getInstance(context).deleteToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
				Log.d(LCAT, "delete instanceid succeeded");
			} catch (final IOException e) {
				Log.e(LCAT, "remove token failed - error: " + e.getMessage());
			}
			return null;
		}
	}.execute();
}
 
Example #3
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 #4
Source File: CaffeinaGCMModule.java    From gcm with MIT License 5 votes vote down vote up
@Kroll.method
@SuppressWarnings("unchecked")
public void registerForPushNotifications(HashMap options) {
	String senderId = (String)options.get("senderId");

	successCallback = (KrollFunction)options.get("success");
	errorCallback = (KrollFunction)options.get("error");
	messageCallback = (KrollFunction)options.get("callback");

	if (senderId != null) {
		GCMRegistrar.register(TiApplication.getInstance(), senderId);
	} else {
		sendError("No GCM senderId specified; get it from the Google Play Developer Console");
	}
}
 
Example #5
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 #6
Source File: DrawerProxy.java    From Ti.DrawerLayout with MIT License 5 votes vote down vote up
@Kroll.method
public void toggleLeftWindow(@Kroll.argument(optional = true) Object obj) {
	if (TiApplication.isUIThread()) {
		handleToggleLeftView();
		return;
	}
	Message message = getMainHandler().obtainMessage(MSG_TOGGLE_LEFT_VIEW);
	message.sendToTarget();
}
 
Example #7
Source File: ViewProxy.java    From TiTouchImageView with MIT License 5 votes vote down vote up
@Kroll.method
public void scrollTo(float x, float y) {
	if (!TiApplication.isUIThread()) {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO, (int)x, (int)y), getActivity());
	} else {
		handleScrollTo(x,y);
	}
}
 
Example #8
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel a notification by the id given in the payload.
 * @param notificationId
 */
@Kroll.method
public void cancelNotificationById(int notificationId) {
    try {
        NotificationManager notificationManager = (NotificationManager) TiApplication.getInstance().getApplicationContext().getSystemService(TiApplication.NOTIFICATION_SERVICE);
        notificationManager.cancel(notificationId);
        Log.i(LCAT, "Notification " + notificationId + " cleared successfully");
    } catch (Exception ex) {
        Log.e(LCAT, "Cannot cancel notification:" + notificationId + " Error: " + ex.getMessage());
    }
}
 
Example #9
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@Kroll.getProperty
@SuppressWarnings("unchecked")
public KrollDict getNotificationSettings() {
    Log.d(LCAT, "Getting notification settings");
    Map map = new Gson().fromJson(TiApplication.getInstance().getAppProperties().getString(GCMModule.NOTIFICATION_SETTINGS, null), Map.class);
    return map != null ? new KrollDict(map) : null;
}
 
Example #10
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@Kroll.setProperty
@SuppressWarnings("unchecked")
public void setNotificationSettings(Map notificationSettings) {
    Log.d(LCAT, "Setting notification settings");
    JSONObject json = new JSONObject(notificationSettings);
    TiApplication.getInstance().getAppProperties().setString(GCMModule.NOTIFICATION_SETTINGS, json.toString());
}
 
Example #11
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
@Kroll.method
public void enableBluetooth()
{
       if(!bluetoothAdapter.isEnabled())
       {
           bluetoothAdapter.enable();
           Log.i(TAG, "Bluetooth Enabled");
       }		
}
 
Example #12
Source File: CameraViewProxy.java    From Ti-Android-CameraView with MIT License 5 votes vote down vote up
@Kroll.method
public void snapPicture()
{
	Log.i(TAG, "Snap");
	Camera cam = ((CameraView) view).currentCameraInstance();
	
	if( isAutoFocusSupported() ) {
		cam.autoFocus(mAutoFocusCallback);
	} else {
		cam.takePicture(null, null, mPicture);
	}
}
 
Example #13
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void setMarker(Object marker) {
	if (marker instanceof HashMap) {
		HashMap<String, Integer> m = (HashMap<String, Integer>) marker;
		TiUIView listView = peekView();
		if (listView != null) {
			((CollectionView)listView).setMarker(m);
		} else {
			preloadMarker = m;
		}
	}
}
 
Example #14
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * disables or enables the icon
 * @param arg
 */
@Kroll.method @Kroll.setProperty
public void setDisableIcon(@Kroll.argument(optional = true) Boolean arg) {
	
	Boolean disabled = true;
	
	if (arg != null) {
		disabled = TiConvert.toBoolean(arg);
	}
	
	Message message = getMainHandler().obtainMessage(MSG_DISABLE_ICON, disabled);
	message.sendToTarget();
}
 
Example #15
Source File: TicroutonModule.java    From TiCrouton with MIT License 5 votes vote down vote up
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
	Log.d(TAG, "inside onAppCreate");
	// put module init code that needs to run when the application is created
	
	
}
 
Example #16
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.getProperty
public Object[] getItems() {
	if (itemProperties == null) {
		return new Object[0];
	} else if (TiApplication.isUIThread()) {
		return itemProperties.toArray();
	} else {
		return (Object[]) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_GET_ITEMS));
	}
}
 
Example #17
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setItems(Object data) {
	if (TiApplication.isUIThread()) {
		handleSetItems(data);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_ITEMS), data);
	}
}
 
Example #18
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setFooterTitle(String footerTitle) {
	if (TiApplication.isUIThread()) {
		handleSetFooterTitle(footerTitle);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_FOOTER_TITLE), footerTitle);
	}
}
 
Example #19
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
@Kroll.method
public boolean sendData(String data) 
{
	if(useService)
	{
		  return BluetoothService.sendData(data);
	}
	else
	{
		if (btsocket != null && isConnected == true) 
		{
			try 
			{
				outputStream.write(data.getBytes());
				outputStream.flush();
				
				return true;
				
			} 
			catch (Exception e) 
			{
				postError(e.getMessage());
				return false;
			}
		}
		else
		{
			postError("Not connected or data is null");
			return false;
		}
	}
}
 
Example #20
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * returns the height of the Actionbar as absolute pixels
 * @return int	actionbar height
 */
@Kroll.getProperty @Kroll.method
public int getActionbarHeight() {
	TiApplication appContext = TiApplication.getInstance();
	final TypedArray styledAttributes = appContext.getTheme().obtainStyledAttributes(
               new int[] { android.R.attr.actionBarSize }
       );
	int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
	styledAttributes.recycle();
	return mActionBarSize;
}
 
Example #21
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void setRefreshing(boolean refreshing) {
	TiUIView listView = peekView();
	
	if (listView != null) {
		((CollectionView) listView).setRefreshing(refreshing);
	}	
}
 
Example #22
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
@Kroll.getProperty @Kroll.method
public String getTitle()
{
	ActionBar actionBar = getActionBar();
	if (actionBar == null) {
		return "";
	}
	return actionBar.getTitle().toString();
}
 
Example #23
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void insertSectionAt(int index, Object section) {
	if (TiApplication.isUIThread()) {
		handleInsertSectionAt(index, section);
	} else {
		sendInsertSectionMessage(index, section);
	}
}
 
Example #24
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void appendSection(Object section) {
	if (TiApplication.isUIThread()) {
		handleAppendSection(section);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_APPEND_SECTION), section);
	}
}
 
Example #25
Source File: ImagepickerModule.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Kroll.method
  public TiBlob resizeAsSame(String filePath, int reqWidth, int reqHeight) {
filePath = filePath.replaceFirst("file://", "");
      return Blobby.rescale(filePath, reqWidth, reqHeight, false);
  }
 
Example #26
Source File: ExampleProxy.java    From TiCollectionView with MIT License 4 votes vote down vote up
@Kroll.method
public void printMessage(String message)
{
	Log.d(LCAT, "printing message: " + message);
}
 
Example #27
Source File: TicroutonModule.java    From TiCrouton with MIT License 4 votes vote down vote up
@Kroll.method
public void cancelAllCroutons()
{
	Crouton.cancelAllCroutons();
}
 
Example #28
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 #29
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 4 votes vote down vote up
/**
 * Set the Actionbar background color
 * @param color
 */
@Kroll.method @Kroll.setProperty
public void setBackgroundColor(String color) {
	Message message = getMainHandler().obtainMessage(MSG_BACKGROUND_COLOR, color);
	message.sendToTarget();
}
 
Example #30
Source File: ImagepickerModule.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Kroll.method
  public TiBlob resizeAsAspect(String filePath, int reqWidth, int reqHeight) {
filePath = filePath.replaceFirst("file://", "");
      return Blobby.rescale(filePath, reqWidth, reqHeight, true);
  }