class wsPackagerPhonegap extends wsPackager {
- protected $splashdone = array();
+ protected $resources = '';
public function __construct($book_id, $vdir = null, $whole = true) {
parent::__construct($book_id, $vdir, $whole);
unlink($this->vdir . '/cache.appcache');
//rmdir($this->vdir . '/data');
- $this->makeConfig();
- }
+ $this->resources = $this->vdir . '/Resources';
- protected function makeConfig() {
-
- $appId = $this->book->parametres->phonegapId;
- $appId = str_replace('$id', $this->book_id, $appId);
-
- $config = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" version="' . $this->book->parametres->phonegapVersion . '" id="' . $appId . '" />');
- $ns = $config->getDocNamespaces();
- $config->addChild('name', $this->book->parametres->title);
- $config->addChild('description');
- $author = $config->addChild('author', 'Fluidbook');
- $author->addAttribute('href', 'http://www.fluidbook.com');
- $author->addAttribute('email', 'contact@fluidbook.com');
- $preferences = array('phonegap-version' => '2.0.0',
- 'target-device' => 'universal',
- 'fullscreen' => 'false',
- 'webviewbounce' => 'false',
- 'prerendered-icon' => 'true',
- 'stay-in-webview' => 'false',
- 'ios-statusbarstyle' => 'black-opaque',
- 'exit-on-suspend' => 'false');
-
- foreach ($preferences as $k => $v) {
- $p = $config->addChild('preference');
- $p->addAttribute('name', $k);
- $p->addAttribute('value', $v);
- }
+ $this->makeResources();
+ }
- $access = $config->addChild('access');
- $access->addAttribute('origin', '*');
+ protected function makeResources() {
+ $splashs = array('320x480' => 'Default~iphone', '640x960' => 'Default@2x~iphone', '1024x768' => 'Default-Landscape~ipad', '768x1024' => 'Default-Portrait~ipad', '2048x1496' => 'Default-Landscape@2x~ipad', '1536x2008' => 'Default-Portrait@2x~ipad', '640x1136' => 'Default-568h@2x');
+ $icons = array(57 => 'icon', 72 => 'icon-72', 114 => 'icon@2x', 144 => 'icon-72@2x');
- $icon = $config->addChild('icon');
- $icon->addAttribute('src', 'icon.png');
- if ($this->theme->parametres->favicon != '') {
- copy($this->themeRoot . '/' . $this->theme->parametres->favicon, $this->vdir . '/icon.png');
- } else {
- copy(WS_COMPILE_ASSETS . '/_ico/phonegap.png', $this->vdir . '/icon.png');
+ if (!file_exists($this->resources . '/splash')) {
+ mkdir($this->resources . '/splash', 0777, true);
}
-
-
- $ios = array('320x480', '640x960', '1024x768', '768x1024');
- $android = array('ldpi' => '320x480', 'mdpi' => '640x960', 'hdpi' => '1024x768', 'xhdpi' => '1280x1920');
-
- if (!file_exists($this->vdir . '/splash')) {
- mkdir($this->vdir . '/splash');
+ if (!file_exists($this->resources . '/icons')) {
+ mkdir($this->resources . '/icons', 0777, true);
}
- foreach ($ios as $size) {
+ foreach ($splashs as $size => $name) {
list($width, $height) = explode('x', $size);
- $this->_makeSplash($width, $height);
-
- $s = $config->addChild('gap:splash', null, $ns['gap']);
- $s->addAttribute('src', 'splash/' . $size . '.png');
- $s->addAttribute('width', $width);
- $s->addAttribute('height', $height);
+ $this->_makeSplash($width, $height, $name);
}
-
- foreach ($android as $density => $size) {
- list($width, $height) = explode('x', $size);
- $this->_makeSplash($width, $height);
-
- $s = $config->addChild('gap:splash', null, $ns['gap']);
- $s->addAttribute('src', 'splash/' . $size . '.png');
- $s->addAttribute('gap:platform', 'android', $ns['gap']);
- $s->addAttribute('gap:density', $density, $ns['gap']);
+ foreach ($icons as $size => $name) {
+ $this->_makeIcon($size, $name);
}
- copy($this->vdir . '/splash/768x1024.png', $this->vdir . '/splash.png');
- file_put_contents($this->vdir . '/config.xml', $config->asXML());
}
- protected function _makeSplash($width, $height) {
- if (isset($this->splashdone[$width . 'x' . $height])) {
- return;
- }
-
+ protected function _makeSplash($width, $height, $name) {
$im = imagecreatetruecolor($width, $height);
// Draw Background
$back = imagecolorhexallocate($im, $this->theme->parametres->backgroundColor);
imagefill($im, 0, 0, $back);
// Draw image
$this->_drawBackImage($im, $width, $height);
+ imagepng($im, $this->resources . '/splash/' . $name . '.png');
+ }
- imagepng($im, $this->vdir . '/splash/' . $width . 'x' . $height . '.png');
+ protected function _makeIcon($size, $name) {
+ if ($this->theme->parametres->favicon != '') {
+ $base = $this->themeRoot . '/' . $this->theme->parametres->favicon;
+ } else {
+ $base = WS_COMPILE_ASSETS . '/_ico/phonegap.png';
+ }
- $this->splashdone[$width . 'x' . $height] = true;
+ $it = new imageTools();
+ $it->loadImage($base);
+ $it->resize($size, $size, 'ratio');
+ $it->output('png', $this->resources . '/icons/' . $name . '.png');
}
protected function _drawBackImage($im, $width, $height) {