From 1b8c4334b7be2f389a87cccba117bf49f95e29d8 Mon Sep 17 00:00:00 2001 From: dpalou Date: Mon, 17 Sep 2018 16:42:35 +0200 Subject: [PATCH] MOBILE-2608 android: Fix crash with splash screen in xxxhdpi devices --- .gitignore | 1 - hooks/after_prepare/030_android_splash.js | 49 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 hooks/after_prepare/030_android_splash.js diff --git a/.gitignore b/.gitignore index a9aaff62a..2de4d4521 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,6 @@ dist/ node_modules/ tmp/ temp/ -hooks/ platforms/ /plugins/ /plugins/android.json diff --git a/hooks/after_prepare/030_android_splash.js b/hooks/after_prepare/030_android_splash.js new file mode 100755 index 000000000..494739776 --- /dev/null +++ b/hooks/after_prepare/030_android_splash.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +// This hook copies Android splash screen files from dev directories into the appropriate platform specific location. +// The code was extracted from here: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/ + +var filesToCopy = [{ + 'resources/android/splash/drawable-land-hdpi-screen.png': 'platforms/android/app/src/main/res/drawable-land-hdpi/screen.png' + }, { + 'resources/android/splash/drawable-land-ldpi-screen.png': 'platforms/android/app/src/main/res/drawable-land-ldpi/screen.png' + }, { + 'resources/android/splash/drawable-land-mdpi-screen.png.png': 'platforms/android/app/src/main/res/drawable-land-mdpi/screen.png' + }, { + 'resources/android/splash/drawable-land-xhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-land-xhdpi/screen.png' + }, { + 'resources/android/splash/drawable-land-xxhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-land-xxhdpi/screen.png' + }, { + 'resources/android/splash/drawable-land-xxxhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-land-xxxhdpi/screen.png' + }, { + 'resources/android/splash/drawable-port-hdpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-hdpi/screen.png' + }, { + 'resources/android/splash/drawable-port-ldpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-ldpi/screen.png' + }, { + 'resources/android/splash/drawable-port-mdpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-mdpi/screen.png' + }, { + 'resources/android/splash/drawable-port-xhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-xhdpi/screen.png' + }, { + 'resources/android/splash/drawable-port-xxhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-xxhdpi/screen.png' + }, { + 'resources/android/splash/drawable-port-xxxhdpi-screen.png': 'platforms/android/app/src/main/res/drawable-port-xxxhdpi/screen.png' + } +]; + +var fs = require('fs'); +var path = require('path'); + +// no need to configure below +var rootDir = process.argv[2]; + +filesToCopy.forEach(function(obj) { + Object.keys(obj).forEach(function(key) { + var val = obj[key]; + var srcFile = path.join(rootDir, key); + var destFile = path.join(rootDir, val); + var destDir = path.dirname(destFile); + if (fs.existsSync(srcFile) && fs.existsSync(destDir)) { + fs.createReadStream(srcFile).pipe(fs.createWriteStream(destFile)); + } + }); +});