Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #616 #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void createAdaptiveIcons(
}

// Create adaptive icon background
if (isAdaptiveIconConfigPngFile(backgroundConfig)) {
if (!isAdaptiveIconConfigColor(backgroundConfig)) {
_createAdaptiveBackgrounds(
config,
backgroundConfig,
Expand Down Expand Up @@ -163,7 +163,7 @@ void createMipmapXmlFile(
String xmlContent = '';

if (config.hasAndroidAdaptiveConfig) {
if (isAdaptiveIconConfigPngFile(config.adaptiveIconBackground!)) {
if (!isAdaptiveIconConfigColor(config.adaptiveIconBackground!)) {
xmlContent +=
' <background android:drawable="@drawable/ic_launcher_background"/>\n';
} else {
Expand Down Expand Up @@ -462,8 +462,8 @@ int? _getMinSdkFlutterGradle(File localPropertiesFile) {
}

/// Returns true if the adaptive icon configuration is a PNG image
bool isAdaptiveIconConfigPngFile(String backgroundFile) {
return backgroundFile.endsWith('.png');
bool isAdaptiveIconConfigColor(String backgroundFile) {
return backgroundFile.startsWith('#');
}

/// (NOTE THIS IS JUST USED FOR UNIT TEST)
Expand Down
38 changes: 16 additions & 22 deletions test/android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ void main() {
);
});

test('Adaptive icon color', () {
//for file not in only png format
expect(android.isAdaptiveIconConfigColor('assets/icons/adaptive_icon_background.jpg'), equals(false));
//for color bg
expect(android.isAdaptiveIconConfigColor('#FFFFFF'), equals(true));
});

test('Correct number of adaptive foreground icons', () {
expect(android.adaptiveForegroundIcons.length, 5);
});
Expand Down Expand Up @@ -79,13 +86,9 @@ void main() {
});
});

test(
'Transforming manifest with icon already in place should leave it unchanged',
() async {
final String inputManifest =
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"');
final String expectedManifest =
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"');
test('Transforming manifest with icon already in place should leave it unchanged', () async {
final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"');
final String expectedManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"');

await withTempFile('AndroidManifest.xml', (File androidManifestFile) async {
androidManifestFile.writeAsStringSync(inputManifest);
Expand All @@ -97,11 +100,8 @@ void main() {
});
});

test(
'Transforming manifest with trailing newline should keep newline untouched',
() async {
final String inputManifest =
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n';
test('Transforming manifest with trailing newline should keep newline untouched', () async {
final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n';
final String expectedManifest = inputManifest;

await withTempFile('AndroidManifest.xml', (File androidManifestFile) async {
Expand All @@ -114,12 +114,8 @@ void main() {
});
});

test(
'Transforming manifest with 3 trailing newlines should keep newlines untouched',
() async {
final String inputManifest =
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') +
'\n\n\n';
test('Transforming manifest with 3 trailing newlines should keep newlines untouched', () async {
final String inputManifest = getAndroidManifestExample('android:icon="@mipmap/ic_launcher"') + '\n\n\n';
final String expectedManifest = inputManifest;

await withTempFile('AndroidManifest.xml', (File androidManifestFile) async {
Expand All @@ -132,12 +128,10 @@ void main() {
});
});

test(
'Transforming manifest with special newline characters should leave special newline characters untouched',
test('Transforming manifest with special newline characters should leave special newline characters untouched',
() async {
final String inputManifest =
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"')
.replaceAll('\n', '\r\n');
getAndroidManifestExample('android:icon="@mipmap/ic_launcher"').replaceAll('\n', '\r\n');
final String expectedManifest = inputManifest;

await withTempFile('AndroidManifest.xml', (File androidManifestFile) async {
Expand Down