[ 
https://issues.apache.org/jira/browse/CB-13685?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16516784#comment-16516784
 ] 

ASF GitHub Bot commented on CB-13685:
-------------------------------------

raphinesse commented on a change in pull request #448: CB-13685 android: 
Adaptive Icon Support
URL: https://github.com/apache/cordova-android/pull/448#discussion_r196332956
 
 

 ##########
 File path: spec/unit/prepare.spec.js
 ##########
 @@ -0,0 +1,935 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    'License'); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+var rewire = require('rewire');
+var path = require('path');
+var CordovaError = require('cordova-common').CordovaError;
+
+const PATH_RESOURCE = path.join('platforms', 'android', 'app', 'src', 'main', 
'res');
+
+/**
+ * Creates blank resource map object, used for testing.
+ *
+ * @param {String} target specific resource item
+ */
+function createResourceMap (target) {
+    let resources = {};
+
+    [
+        'mipmap-ldpi',
+        'mipmap-mdpi',
+        'mipmap-hdpi',
+        'mipmap-xhdpi',
+        'mipmap-xxhdpi',
+        'mipmap-xxxhdpi',
+        'mipmap-ldpi-v26',
+        'mipmap-mdpi-v26',
+        'mipmap-hdpi-v26',
+        'mipmap-xhdpi-v26',
+        'mipmap-xxhdpi-v26',
+        'mipmap-xxxhdpi-v26'
+    ].forEach((mipmap) => {
+        if (!target || target === 'ic_launcher.png') 
resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher.png')] = null;
+        if (!target || target === 'ic_launcher_foreground.png') 
resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher_foreground.png')] = 
null;
+        if (!target || target === 'ic_launcher_background.png') 
resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher_background.png')] = 
null;
+        if (!target || target === 'ic_launcher_foreground.xml') 
resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher_foreground.xml')] = 
null;
+        if (!target || target === 'ic_launcher_background.xml') 
resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher_background.xml')] = 
null;
+
+        if (
+            !mipmap.includes('-v26') &&
+            (!target || target === 'ic_launcher.xml')
+        ) {
+            resources[path.join(PATH_RESOURCE, mipmap, 'ic_launcher.xml')] = 
null;
+        }
+    });
+
+    return resources;
+}
+
+describe('updateIcons method', function () {
+    // Rewire
+    let prepare;
+
+    // Spies
+    let updateIconResourceForAdaptiveSpy;
+    let updateIconResourceForLegacySpy;
+    let emitSpy;
+    let updatePathsSpy;
+
+    // Mock Data
+    let cordovaProject;
+    let platformResourcesDir;
+
+    beforeEach(function () {
+        prepare = rewire('../../bin/templates/cordova/lib/prepare');
+
+        cordovaProject = {
+            root: '/mock',
+            projectConfig: {
+                path: '/mock/config.xml',
+                cdvNamespacePrefix: 'cdv'
+            },
+            locations: {
+                plugins: '/mock/plugins',
+                www: '/mock/www'
+            }
+        };
+        platformResourcesDir = PATH_RESOURCE;
+
+        emitSpy = jasmine.createSpy('emit');
+        prepare.__set__('events', {
+            emit: emitSpy
+        });
+
+        updatePathsSpy = jasmine.createSpy('updatePaths');
+        prepare.__set__('FileUpdater', {
+            updatePaths: updatePathsSpy
+        });
+
+        // mocking initial responses for mapImageResources
+        prepare.__set__('mapImageResources', function (rootDir, subDir, type, 
resourceName) {
+            if (resourceName.includes('ic_launcher.png')) {
+                return createResourceMap('ic_launcher.png');
+            } else if (resourceName.includes('ic_launcher_foreground.png')) {
+                return createResourceMap('ic_launcher_foreground.png');
+            } else if (resourceName.includes('ic_launcher_background.png')) {
+                return createResourceMap('ic_launcher_background.png');
+            } else if (resourceName.includes('ic_launcher_foreground.xml')) {
+                return createResourceMap('ic_launcher_foreground.xml');
+            } else if (resourceName.includes('ic_launcher_background.xml')) {
+                return createResourceMap('ic_launcher_background.xml');
+            } else if (resourceName.includes('ic_launcher.xml')) {
+                return createResourceMap('ic_launcher.xml');
+            }
+        });
+    });
+
+    it('Test#001 : Should detect no defined icons.', function (done) {
+        const updateIcons = prepare.__get__('updateIcons');
+
+        // mock data.
+        cordovaProject.projectConfig.getIcons = function () {
+            return [];
+        };
+
+        updateIcons(cordovaProject, platformResourcesDir);
+
+        // The emit was called
+        expect(emitSpy).toHaveBeenCalled();
+
+        // The emit message was.
+        let actual = emitSpy.calls.argsFor(0)[1];
+        let expected = 'This app does not have launcher icons defined';
+        expect(actual).toEqual(expected);
+
+        done();
+    });
+
+    it('Test#002 : Should detech incorrect configrations for adaptive icon and 
throws error.', function (done) {
+        const updateIcons = prepare.__get__('updateIcons');
+
+        // mock data.
+        cordovaProject.projectConfig.getIcons = function () {
+            return [{
+                src: undefined,
+                target: undefined,
+                density: 'mdpi',
+                platform: 'android',
+                width: undefined,
+                height: undefined,
+                background: 'res/icon/android/mdpi-background.png',
+                foreground: undefined
+            }];
+        };
+
+        expect(function () {
+            updateIcons(cordovaProject, platformResourcesDir);
+        }).toThrow(
+            new CordovaError('One of the following attributes are set but 
missing the other for the density type: mdpi. Please ensure that all require 
attributes are defined.')
+        );
+
+        done();
+    });
+
+    it('Test#003 : Should detech incorrect configrations (missing foreground) 
for adaptive icon and throw an error.', function (done) {
+        const updateIcons = prepare.__get__('updateIcons');
+
+        // mock data.
+        cordovaProject.projectConfig.getIcons = function () {
+            return [{
+                src: undefined,
+                target: undefined,
+                density: 'mdpi',
+                platform: 'android',
+                width: undefined,
+                height: undefined,
+                background: 'res/icon/android/mdpi-background.png',
+                foreground: undefined
+            }];
+        };
+
+        expect(function () {
+            updateIcons(cordovaProject, platformResourcesDir);
+        }).toThrow(
+            new CordovaError('One of the following attributes are set but 
missing the other for the density type: mdpi. Please ensure that all require 
attributes are defined.')
+        );
+
+        done();
+    });
+
+    it('Test#004 : Should detech incorrect configrations (missing background) 
for adaptive icon and throw an error.', function (done) {
+        const updateIcons = prepare.__get__('updateIcons');
+
+        // mock data.
+        cordovaProject.projectConfig.getIcons = function () {
+            return [{
+                src: undefined,
+                target: undefined,
+                density: 'mdpi',
+                platform: 'android',
+                width: undefined,
+                height: undefined,
+                background: undefined,
+                foreground: 'res/icon/android/mdpi-foreground.png'
+            }];
+        };
+
+        expect(function () {
+            updateIcons(cordovaProject, platformResourcesDir);
+        }).toThrow(
+            new CordovaError('One of the following attributes are set but 
missing the other for the density type: mdpi. Please ensure that all require 
attributes are defined.')
+        );
+
+        done();
+    });
+
+    it('Test#005 : Should detech incorrect configrations and throw an error.', 
function (done) {
+        const updateIcons = prepare.__get__('updateIcons');
+
+        // mock data.
+        cordovaProject.projectConfig.getIcons = function () {
+            return [{
+                src: undefined,
+                target: undefined,
+                density: 'mdpi',
+                platform: 'android',
+                width: undefined,
+                height: undefined,
+                background: undefined,
+                foreground: undefined
+            }];
+        };
+
+        expect(function () {
+            updateIcons(cordovaProject, platformResourcesDir);
+        }).toThrow(
+            new CordovaError('One of the following attributes are set but 
missing the other for the density type: mdpi. Please ensure that all require 
attributes are defined.')
+        );
+
+        done();
 
 Review comment:
   Are these tests asynchronous? If not, we don't need this. If so, I suggest 
returning promises to Jasmine instead of using the done callback.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Android Adaptive Icons
> ----------------------
>
>                 Key: CB-13685
>                 URL: https://issues.apache.org/jira/browse/CB-13685
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-android
>         Environment: All
>            Reporter: Josef Brandl
>            Assignee: Joe Bowser
>            Priority: Minor
>
> Starting with Android 8 Oreo (API level 26) Android allows developers to 
> create app icons using a background and a foreground image file. This feature 
> is called "adaptive icons". One major change that goes with this feature is 
> that icons get now clipped into a shape by the system. This leads to a very 
> uniform and clean design like on iOS where all icons are a rounded rectangle. 
> The other advantage is that visual effects can be applied to the icon by the 
> system due to the separation between foreground an background.
> Android Studio greatly assists the developer at the creation of the app icon 
> resources because it creates backwards compatible icons for older devices 
> that don't support the adaptive icons feature.
> https://developer.android.com/studio/write/image-asset-studio.html
> The following resources are created.
> {code}
> res
> ├── drawable
> │   ├── ic_launcher_background.xml
> │   └── ic_launcher_foreground.xml
> ├── mipmap-anydpi-v26
> │   ├── ic_launcher.xml
> │   └── ic_launcher_round.xml
> ├── mipmap-hdpi
> │   ├── ic_launcher.png
> │   └── ic_launcher_round.png
> ├── mipmap-mdpi
> │   ├── ic_launcher.png
> │   └── ic_launcher_round.png
> ├── mipmap-xhdpi
> │   ├── ic_launcher.png
> │   └── ic_launcher_round.png
> ├── mipmap-xxhdpi
> │   ├── ic_launcher.png
> │   └── ic_launcher_round.png
> └── mipmap-xxxhdpi
>      ├── ic_launcher.png
>      └── ic_launcher_round.png
> {code}
> It is currently not clear how these files can be used inside a cordova 
> project.
> - res/mipmap-anydpi-v26/ic_launcher.xml points to other image resources 
> (foreground, background)
> - The foreground and background can be vector graphics (-> xml files in 
> res/drawable)
> - The documentation needs to be updated
> (I've never reported an issue using JIRA before - I'm only used to github. 
> So, please guide me if I'm doing something incorrect)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to