Skip to content

Commit 60d2842

Browse files
authored
feat!: add partial night & day theme support (#1818)
* feat!: partial night & day theme support * feat!: prefix core resource values files with cdv_
1 parent cab5c5b commit 60d2842

File tree

12 files changed

+108
-47
lines changed

12 files changed

+108
-47
lines changed

lib/Api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class Api {
7272
platformWww: path.join(this.root, 'platform_www'),
7373
configXml: path.join(appRes, 'xml', 'config.xml'),
7474
defaultConfigXml: path.join(this.root, 'cordova', 'defaults.xml'),
75-
strings: path.join(appRes, 'values', 'strings.xml'),
76-
themes: path.join(appRes, 'values', 'themes.xml'),
77-
colors: path.join(appRes, 'values', 'colors.xml'),
75+
strings: path.join(appRes, 'values', 'cdv_strings.xml'),
76+
themes: path.join(appRes, 'values', 'cdv_themes.xml'),
77+
colors: path.join(appRes, 'values', 'cdv_colors.xml'),
7878
manifest: path.join(appMain, 'AndroidManifest.xml'),
7979
build: path.join(this.root, 'build'),
8080
javaSrc: path.join(appMain, 'java')

lib/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ exports.create = function (project_path, config, options, events) {
264264
fs.mkdirSync(activity_dir, { recursive: true });
265265
fs.cpSync(path.join(project_template_dir, 'Activity.java'), activity_path);
266266
utils.replaceFileContents(activity_path, /__ACTIVITY__/, safe_activity_name);
267-
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, utils.escape(project_name));
267+
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'cdv_strings.xml'), /__NAME__/, utils.escape(project_name));
268268
utils.replaceFileContents(activity_path, /__ID__/, package_name);
269269

270270
const manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));

lib/prepare.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function updateProjectAccordingTo (platformConfig, locations) {
346346
* @param {Object} locations A map of locations for this platform
347347
*/
348348
function updateProjectStrings (platformConfig, locations) {
349-
// Update app name by editing res/values/strings.xml
349+
// Update app name by editing res/values/cdv_strings.xml
350350
const strings = xmlHelpers.parseElementtreeSync(locations.strings);
351351

352352
const name = platformConfig.name();
@@ -377,7 +377,7 @@ function warnForDeprecatedSplashScreen (cordovaProject) {
377377
* @param {Object} locations A map of locations for this platform
378378
*/
379379
function updateProjectTheme (platformConfig, locations) {
380-
// res/values/themes.xml
380+
// res/values/cdv_themes.xml
381381
const themes = xmlHelpers.parseElementtreeSync(locations.themes);
382382
const splashScreenTheme = themes.find('style[@name="Theme.App.SplashScreen"]');
383383

@@ -408,13 +408,17 @@ function updateProjectTheme (platformConfig, locations) {
408408
if (!splashBg) {
409409
splashBg = platformConfig.getPreference('BackgroundColor', this.platform);
410410
}
411+
if (!splashBg) {
412+
splashBg = '@color/cdv_splashscreen_background';
413+
}
411414

412-
// use the user defined value for "colors.xml"
413-
updateProjectSplashScreenBackgroundColor(splashBg, locations);
415+
events.emit('verbose', 'The Android Splash Screen background color was set to: ' +
416+
(splashBg === '@color/cdv_splashscreen_background' ? 'Default' : splashBg)
417+
);
414418

415419
// force the themes value to `@color/cdv_splashscreen_background`
416420
const splashBgNode = splashScreenTheme.find('item[@name="windowSplashScreenBackground"]');
417-
splashBgNode.text = '@color/cdv_splashscreen_background';
421+
splashBgNode.text = splashBg;
418422

419423
[
420424
// Splash Screen
@@ -471,7 +475,7 @@ function updateProjectTheme (platformConfig, locations) {
471475
break;
472476

473477
case 'windowSplashScreenIconBackgroundColor':
474-
// use the user defined value for "colors.xml"
478+
// use the user defined value for "cdv_colors.xml"
475479
updateProjectSplashScreenIconBackgroundColor(cdvConfigPrefValue, locations);
476480

477481
// force the themes value to `@color/cdv_splashscreen_icon_background`
@@ -495,7 +499,7 @@ function updateProjectTheme (platformConfig, locations) {
495499
break;
496500

497501
case 'postSplashScreenTheme':
498-
themeTargetNode.text = cdvConfigPrefValue || '@style/Theme.AppCompat.NoActionBar';
502+
themeTargetNode.text = cdvConfigPrefValue || '@style/Theme.Cordova.App.DayNight';
499503
break;
500504

501505
default:
@@ -507,29 +511,13 @@ function updateProjectTheme (platformConfig, locations) {
507511
events.emit('verbose', 'Wrote out Android application themes to ' + locations.themes);
508512
}
509513

510-
/**
511-
* @param {String} splashBackgroundColor SplashScreen Background Color Hex Code
512-
* be used to update project
513-
* @param {Object} locations A map of locations for this platform
514-
*/
515-
function updateProjectSplashScreenBackgroundColor (splashBackgroundColor, locations) {
516-
if (!splashBackgroundColor) { splashBackgroundColor = '#FFFFFF'; }
517-
518-
// res/values/colors.xml
519-
const colors = xmlHelpers.parseElementtreeSync(locations.colors);
520-
colors.find('color[@name="cdv_splashscreen_background"]').text = splashBackgroundColor.replace(/'/g, '\\\'');
521-
522-
fs.writeFileSync(locations.colors, colors.write({ indent: 4 }), 'utf-8');
523-
events.emit('verbose', 'Wrote out Android application SplashScreen Color to ' + locations.colors);
524-
}
525-
526514
/**
527515
* @param {String} splashIconBackgroundColor SplashScreen Icon Background Color Hex Code
528516
* be used to update project
529517
* @param {Object} locations A map of locations for this platform
530518
*/
531519
function updateProjectSplashScreenIconBackgroundColor (splashIconBackgroundColor, locations) {
532-
// res/values/colors.xml
520+
// res/values/cdv_colors.xml
533521
const colors = xmlHelpers.parseElementtreeSync(locations.colors);
534522
// node name
535523
const name = 'cdv_splashscreen_icon_background';
@@ -627,12 +615,12 @@ function updateProjectSplashScreenImage (locations, themeKey, cdvConfigPrefKey,
627615

628616
// copy the png to correct mipmap folder with name of ic_cdv_splashscreen.png
629617
// delete ic_cdv_splashscreen.xml from drawable folder
630-
// update themes.xml windowSplashScreenAnimatedIcon value to @mipmap/ic_cdv_splashscreen
618+
// update cdv_themes.xml windowSplashScreenAnimatedIcon value to @mipmap/ic_cdv_splashscreen
631619
cleanupAndSetProjectSplashScreenImage(cdvConfigPrefValue, destFilePath, possiblePreviousDestFilePath);
632620
} else if (iconExtension === '.xml') {
633621
// copy the xml to drawable folder with name of ic_cdv_splashscreen.xml
634622
// delete ic_cdv_splashscreen.png from mipmap folder
635-
// update themes.xml windowSplashScreenAnimatedIcon value to @drawable/ic_cdv_splashscreen
623+
// update cdv_themes.xml windowSplashScreenAnimatedIcon value to @drawable/ic_cdv_splashscreen
636624
cleanupAndSetProjectSplashScreenImage(cdvConfigPrefValue, destFilePath, possiblePreviousDestFilePath);
637625
} else {
638626
// use the default destFilePath & possiblePreviousDestFilePath, no update require.

spec/unit/create.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,17 @@ describe('create', function () {
276276
});
277277
});
278278

279-
it('should interpolate the project name into strings.xml', () => {
279+
it('should interpolate the project name into cdv_strings.xml', () => {
280280
config_mock.name.and.returnValue('IncredibleApp');
281281
return create.create(project_path, config_mock, {}, events_mock).then(() => {
282-
expect(utils.replaceFileContents).toHaveBeenCalledWith(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, 'IncredibleApp');
282+
expect(utils.replaceFileContents).toHaveBeenCalledWith(path.join(app_path, 'res', 'values', 'cdv_strings.xml'), /__NAME__/, 'IncredibleApp');
283283
});
284284
});
285285

286-
it('should interpolate the escaped project name into strings.xml', () => {
286+
it('should interpolate the escaped project name into cdv_strings.xml', () => {
287287
config_mock.name.and.returnValue('<Incredible&App>');
288288
return create.create(project_path, config_mock, {}, events_mock).then(() => {
289-
expect(utils.replaceFileContents).toHaveBeenCalledWith(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, '&lt;Incredible&amp;App&gt;');
289+
expect(utils.replaceFileContents).toHaveBeenCalledWith(path.join(app_path, 'res', 'values', 'cdv_strings.xml'), /__NAME__/, '&lt;Incredible&amp;App&gt;');
290290
});
291291
});
292292

spec/unit/prepare.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ describe('prepare', () => {
930930
locations: {
931931
plugins: '/mock/plugins',
932932
www: '/mock/www',
933-
strings: '/mock/res/values/strings.xml'
933+
strings: '/mock/res/values/cdv_strings.xml'
934934
}
935935
};
936936

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<resources>
21+
<color name="cdv_background_color">@android:color/system_background_dark</color>
22+
<color name="cdv_splashscreen_background">@color/cdv_background_color</color>
23+
</resources>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<resources>
21+
<color name="cdv_background_color">#121318</color>
22+
<color name="cdv_splashscreen_background">@color/cdv_background_color</color>
23+
</resources>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<resources>
21+
<color name="cdv_background_color">@android:color/system_background_light</color>
22+
<color name="cdv_splashscreen_background">@color/cdv_background_color</color>
23+
</resources>

templates/project/res/values/colors.xml renamed to templates/project/res/values/cdv_colors.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
under the License.
1919
-->
2020
<resources xmlns:tools="http://schemas.android.com/tools">
21-
<color name="cdv_splashscreen_background">#FFFFFFFF</color>
21+
<color name="cdv_background_color">#FAF8FF</color>
22+
<color name="cdv_splashscreen_background">@color/cdv_background_color</color>
2223
</resources>
File renamed without changes.

0 commit comments

Comments
 (0)