FPDocumentController - flashpress/FPNativeUI GitHub Wiki

import ru.flashpress.nui.view.control.FPButton;
import ru.flashpress.nui.document.FPDocumentController;
import ru.flashpress.nui.constants.FPControlState;
import ru.flashpress.nui.events.FPControlEvent;
import ru.flashpress.nui.view.system.FPRootView;
import ru.flashpress.nui.view.system.FPStageView;
import ru.flashpress.nui.core.FPSize;
import ru.flashpress.nui.FPNativeUI;
import ru.flashpress.nui.view.box.FPVBox;
import flash.filesystem.File;


FPNativeUI.init();
//
var box:FPVBox = new FPVBox();
box.position = new Point(50, 50);
//
var previewPDF:FPButton = createButton('preview pdf');
var sharePDF:FPButton = createButton('share pdf');
var previewImage:FPButton = createButton('preview image');
var shareImage:FPButton = createButton('share image');
function createButton(label:String):FPButton
{
	var button:FPButton = new FPButton();
	button.size = new FPSize(200, 30);
	button.backgroundColor = 0x2286da;
	button.setTitle(label, FPControlState.NORMAL);
	button.setTitleColor(0xffffff, FPControlState.NORMAL);
	button.setTitleColor(0xc2e2fd, FPControlState.HIGHLIGHTED);
	button.addEventListener(FPControlEvent.TOUCH_DOWN, buttonDownHandler);
	return button;
}
//
box.addChild(previewPDF);
box.addChild(sharePDF);
box.addChild(previewImage);
box.addChild(shareImage);
FPStageView.stage.addChild(box);
//
var document:FPDocumentController = new FPDocumentController();


function buttonDownHandler(event:FPControlEvent):void
{
	var preview:Boolean;
	var filename:String;
	switch (event.target) {
		case previewPDF:
			preview = true;
			filename = 'book.pdf';
			break;
		case sharePDF:
			preview = false;
			filename = 'book.pdf';
			break;
		case previewImage:
			preview = true;
			filename = 'image.png';
			break;
		case shareImage:
			preview = false;
			filename = 'image.png';
			break;
	}
	//
	var file:File = File.applicationDirectory.resolvePath(filename);
	document.url = file.nativePath;
	if (preview) {
		document.name = 'preview for '+filename;
		document.presentPreview(FPRootView.root);
	} else {
		document.presentOpenInMenu(FPRootView.root);
	}
}