Java Code Examples for org.appcelerator.titanium.TiApplication#getAppCurrentActivity()

The following examples show how to use org.appcelerator.titanium.TiApplication#getAppCurrentActivity() . 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: 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 2
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.");
	}
}