You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/06/08 10:28:40 UTC

[GitHub] erisu opened a new pull request #448: CB-13685 android: Adaptive Icon Support

erisu opened a new pull request #448: CB-13685 android: Adaptive Icon Support
URL: https://github.com/apache/cordova-android/pull/448
 
 
   <!--
   Please make sure the checklist boxes are all checked before submitting the PR. The checklist
   is intended as a quick reference, for complete details please see our Contributor Guidelines:
   
   http://cordova.apache.org/contribute/contribute_guidelines.html
   
   Thanks!
   -->
   
   ### Platforms affected
   Android
   
   ### What does this PR do?
   This PR adds support for Adaptive Icon.
   
   Changes to Default Template Project
   - Updated AndroidManifest to use adaptive icons configuration by default.
   - Added adaptive icons and ic_launcher.xml for Android platform 26 and higher.
   
   Added JavaScript Unit Testing.
   
   **config.xml for Adaptive Icons with Images**
   ```
   <platform name="android">
     <icon background="res/icon/android/ldpi-background.png" density="ldpi" foreground="res/icon/android/ldpi-foreground.png" />
     <icon background="res/icon/android/mdpi-background.png" density="mdpi" foreground="res/icon/android/mdpi-foreground.png" />
     <icon background="res/icon/android/hdpi-background.png" density="hdpi" foreground="res/icon/android/hdpi-foreground.png" />
     <icon background="res/icon/android/xhdpi-background.png" density="xhdpi" foreground="res/icon/android/xhdpi-foreground.png" />
     <icon background="res/icon/android/xxhdpi-background.png" density="xxhdpi" foreground="res/icon/android/xxhdpi-foreground.png" />
     <icon background="res/icon/android/xxxhdpi-background.png" density="xxxhdpi" foreground="res/icon/android/xxxhdpi-foreground.png" />
   </platform>
   ```
   
   In this case, the foreground image will automatically be applied to the src attribute value. This is to support non-adaptive icon supported Android devices. If the user supplies their own src value, foreground will not be copied over.
   
   **config.xml for Adaptive Icons with Vectors**
   ```
   <platform name="android">
     <icon background="res/icon/android/ldpi-background.xml” density="ldpi" foreground="res/icon/android/ldpi-foreground.xml” src="res/icon/android/ldpi-icon.png" />
     <icon background="res/icon/android/mdpi-background.xml” density="mdpi" foreground="res/icon/android/mdpi-foreground.xml” src="res/icon/android/mdpi-icon.png" />
     <icon background="res/icon/android/hdpi-background.xml” density="hdpi" foreground="res/icon/android/hdpi-foreground.xml” src="res/icon/android/hdpi-icon.png" />
     <icon background="res/icon/android/xhdpi-background.xml” density="xhdpi" foreground="res/icon/android/xhdpi-foreground.xml” src="res/icon/android/xdpi-icon.png" />
     <icon background="res/icon/android/xxhdpi-background.xml” density="xxhdpi" foreground="res/icon/android/xxhdpi-foreground.xml” src="res/icon/android/xxhdpi-icon.png" />
     <icon background="res/icon/android/xxxhdpi-background.xml” density="xxxhdpi" foreground="res/icon/android/xxxhdpi-foreground.xml” src="res/icon/android/xxxhdpi-icon.png" />
   </platform>
   ```
   
   In this example, the adaptive icon supports vectors and colors for the foreground and background. If the foreground is a vector or color, the src attribute must also be defined with a PNG for Android devices that does not support adaptive icon.
   
   **config.xml for Adaptive Icons with Colors for Background**
   First: create colors.xml file with content
   ```
   <?xml version="1.0" encoding="utf-8"?>
   <resources>
       <color name="background">#FF0000</color>
   </resources>
   ```
   Second: update config.xml with…
   ```
   <platform name="android">
     <resource-file src="/res/values/colors.xml" target="/app/src/main/res/values/colors.xml" />
   
     <icon background=“@color/background” density="ldpi" foreground="res/icon/android/ldpi-foreground.png" />
     <icon background="@color/background" density="mdpi" foreground="res/icon/android/mdpi-foreground.png" />
     <icon background="@color/background" density="hdpi" foreground="res/icon/android/hdpi-foreground.png" />
     <icon background="@color/background" density="xhdpi" foreground="res/icon/android/xhdpi-foreground.png" />
     <icon background="@color/background" density="xxhdpi" foreground="res/icon/android/xxhdpi-foreground.png" />
     <icon background="@color/background" density="xxxhdpi" foreground="res/icon/android/xxxhdpi-foreground.png" />
   </platform>
   ```
   
   The naming convention for the two new attributes, `background` and `foreground`, was decided to match the element names that is used in the `ic_launcher.xml` for consistency. https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive#creating_adaptive_icons_in_xml
   
   **
Error Example: Foreground contains vector and missing src attribute.**
   
   ```
   <platform name="android">
     <icon background="res/icon/android/mdpi-background.png" foreground="res/icon/android/mdpi-foreground.xml” density=“mdpi" />
   </platform>
   ```
   
   ### What testing has been done on this change?
   - Built default app with no modifications to config.xml
   - Built default app with legacy icon set defined
   - Built default app with adaptive icon set with images.
   - Built default app with adaptive icon set with vectors.
   - Built default app with adaptive icon set with colors.
   - Converted from adaptive to legacy icon set and rebuilt.
   - Converted from legacy to adaptive icon set and rebuild.
   
   
   ### Checklist
   - [X] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
   - [X] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
   - [X] Added automated test coverage as appropriate for this change.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org