@@ -148,15 +148,20 @@ class AndroidBuild extends JavaBuild {
148148 static private final String WEAR_GRADLE_BUILD_ECJ_TEMPLATE = "WearBuildECJ.gradle.tmpl" ;
149149 static private final String WEAR_GRADLE_BUILD_TEMPLATE = "WearBuild.gradle.tmpl" ;
150150
151- // Icon files
152- static final String ICON_36 = "icon-36.png" ;
153- static final String ICON_48 = "icon-48.png" ;
154- static final String ICON_72 = "icon-72.png" ;
155- static final String ICON_96 = "icon-96.png" ;
156- static final String ICON_144 = "icon-144.png" ;
157- static final String ICON_192 = "icon-192.png" ;
158- static final String WATCHFACE_ICON_CIRCULAR = "preview_circular.png" ;
159- static final String WATCHFACE_ICON_RECTANGULAR = "preview_rectangular.png" ;
151+ // Launcher and watch face icon files
152+ static final String [] SKETCH_LAUNCHER_ICONS = {"launcher_36.png" , "launcher_48.png" ,
153+ "launcher_72.png" , "launcher_96.png" ,
154+ "launcher_144.png" , "launcher_192.png" };
155+ static final String [] SKETCH_OLD_LAUNCHER_ICONS = {"icon-36.png" , "icon-48.png" ,
156+ "icon-72.png" , "icon-96.png" ,
157+ "icon-144.png" , "icon-192.png" };
158+ static final String [] BUILD_LAUNCHER_ICONS = {"mipmap-ldpi/ic_launcher.png" , "mipmap-mdpi/ic_launcher.png" ,
159+ "mipmap-hdpi/ic_launcher.png" , "mipmap-xhdpi/ic_launcher.png" ,
160+ "mipmap-xxhdpi/ic_launcher.png" , "mipmap-xxxhdpi/ic_launcher.png" };
161+ static final String [] SKETCH_WATCHFACE_ICONS = {"preview_circular.png" ,
162+ "preview_rectangular.png" };
163+ static final String [] BUILD_WATCHFACE_ICONS = {"drawable-nodpi/preview_circular.png" ,
164+ "drawable-nodpi/preview_rectangular.png" };
160165
161166 private int appComponent = APP ;
162167
@@ -638,10 +643,10 @@ private void writeRes(File resFolder) throws SketchException {
638643 }
639644
640645 File sketchFolder = sketch .getFolder ();
641- writeAppIconFiles (sketchFolder , resFolder );
646+ writeLauncherIconFiles (sketchFolder , resFolder );
642647 if (comp == WATCHFACE ) {
643648 // Need the preview icons for watch faces.
644- writeWatchIconFiles (sketchFolder , resFolder );
649+ writeWatchFaceIconFiles (sketchFolder , resFolder );
645650 }
646651 }
647652
@@ -650,74 +655,38 @@ private void writeRes(File resFolder) throws SketchException {
650655 // Icons
651656
652657
653- private void writeAppIconFiles (File sketchFolder , File resFolder ) {
654- File localIcon36 = new File (sketchFolder , ICON_36 );
655- File localIcon48 = new File (sketchFolder , ICON_48 );
656- File localIcon72 = new File (sketchFolder , ICON_72 );
657- File localIcon96 = new File (sketchFolder , ICON_96 );
658- File localIcon144 = new File (sketchFolder , ICON_144 );
659- File localIcon192 = new File (sketchFolder , ICON_192 );
660-
661- File buildIcon48 = new File (resFolder , "drawable/icon.png" );
662- File buildIcon36 = new File (resFolder , "drawable-ldpi/icon.png" );
663- File buildIcon72 = new File (resFolder , "drawable-hdpi/icon.png" );
664- File buildIcon96 = new File (resFolder , "drawable-xhdpi/icon.png" );
665- File buildIcon144 = new File (resFolder , "drawable-xxhdpi/icon.png" );
666- File buildIcon192 = new File (resFolder , "drawable-xxxhdpi/icon.png" );
667-
668- if (!localIcon36 .exists () && !localIcon48 .exists () &&
669- !localIcon72 .exists () && !localIcon96 .exists () &&
670- !localIcon144 .exists () && !localIcon192 .exists ()) {
671- try {
672- // if no icons are in the sketch folder, then copy all the defaults
673- copyIcon (mode .getContentFile ("icons/" + ICON_36 ), buildIcon36 );
674- copyIcon (mode .getContentFile ("icons/" + ICON_48 ), buildIcon48 );
675- copyIcon (mode .getContentFile ("icons/" + ICON_72 ), buildIcon72 );
676- copyIcon (mode .getContentFile ("icons/" + ICON_96 ), buildIcon96 );
677- copyIcon (mode .getContentFile ("icons/" + ICON_144 ), buildIcon144 );
678- copyIcon (mode .getContentFile ("icons/" + ICON_192 ), buildIcon192 );
679- } catch (IOException e ) {
680- e .printStackTrace ();
681- }
682- } else {
683- // if at least one of the icons already exists, then use that across the board
684- try {
685- if (localIcon36 .exists ()) copyIcon (localIcon36 , buildIcon36 );
686- if (localIcon48 .exists ()) copyIcon (localIcon48 , buildIcon48 );
687- if (localIcon72 .exists ()) copyIcon (localIcon72 , buildIcon72 );
688- if (localIcon96 .exists ()) copyIcon (localIcon96 , buildIcon96 );
689- if (localIcon144 .exists ()) copyIcon (localIcon144 , buildIcon144 );
690- if (localIcon192 .exists ()) copyIcon (localIcon192 , buildIcon192 );
691- } catch (IOException e ) {
692- System .err .println ("Problem while copying app icons." );
693- e .printStackTrace ();
694- }
695- }
658+ private void writeLauncherIconFiles (File sketchFolder , File resFolder ) {
659+ writeIconFiles (sketchFolder , resFolder , SKETCH_LAUNCHER_ICONS , SKETCH_OLD_LAUNCHER_ICONS , BUILD_LAUNCHER_ICONS );
696660 }
697661
698662
699- private void writeWatchIconFiles (File sketchFolder , File resFolder ) {
700- copyWatchIcon (new File (sketchFolder , WATCHFACE_ICON_CIRCULAR ),
701- new File (resFolder , "drawable/preview_circular.png" ),
702- mode .getContentFile ("icons/" + WATCHFACE_ICON_CIRCULAR ));
703- copyWatchIcon (new File (sketchFolder , WATCHFACE_ICON_RECTANGULAR ),
704- new File (resFolder , "drawable/preview_rectangular.png" ),
705- mode .getContentFile ("icons/" + WATCHFACE_ICON_RECTANGULAR ));
663+ private void writeWatchFaceIconFiles (File sketchFolder , File resFolder ) {
664+ writeIconFiles (sketchFolder , resFolder , SKETCH_WATCHFACE_ICONS , null , BUILD_WATCHFACE_ICONS );
706665 }
707666
708667
709- private void copyWatchIcon (File srcFile , File destFile , File defFile ) {
710- if (!srcFile .exists ()) {
668+ private void writeIconFiles (File sketchFolder , File resFolder ,
669+ String [] sketchIconNames , String [] oldIconNames , String [] buildIconNames ) {
670+ File [] localIcons = AndroidUtil .getFileList (sketchFolder , sketchIconNames , oldIconNames );
671+ File [] buildIcons = AndroidUtil .getFileList (resFolder , buildIconNames );
672+ if (AndroidUtil .noFileExists (localIcons )) {
673+ // If no icons are in the sketch folder, then copy all the defaults
674+ File [] defaultIcons = AndroidUtil .getFileList (mode , "icons/" , sketchIconNames );
711675 try {
712- copyIcon (defFile , destFile );
676+ for (int i = 0 ; i < localIcons .length ; i ++) {
677+ copyIcon (defaultIcons [i ], buildIcons [i ]);
678+ }
713679 } catch (IOException e ) {
714680 e .printStackTrace ();
715- }
681+ }
716682 } else {
683+ // If at least one of the icons already exists, then use that across the board
717684 try {
718- copyIcon (srcFile , destFile );
685+ for (int i = 0 ; i < localIcons .length ; i ++) {
686+ if (localIcons [i ].exists ()) copyIcon (localIcons [i ], buildIcons [i ]);
687+ }
719688 } catch (IOException e ) {
720- System .err .println ("Problem while copying watch face icon ." );
689+ System .err .println ("Problem while copying icons ." );
721690 e .printStackTrace ();
722691 }
723692 }
@@ -732,73 +701,7 @@ private void copyIcon(File srcFile, File destFile) throws IOException {
732701 System .err .println ("Could not create \" " + destFile .getParentFile () + "\" folder." );
733702 }
734703 }
735-
736-
737- // ---------------------------------------------------------------------------
738- // Dependencies
739-
740-
741- // private void copyWearLib(File libsFolder) throws IOException {
742- // The wear aar is needed even when the app is not a watch face, because on
743- // devices with android < 5 the dependencies of the PWatchFace* classes
744- // cannot be resolved.
745- // copyAARFileFromSDK(sdk.getWearableFolder() + "/$VER", "wearable-$VER.aar", WEAR_VER, libsFolder);
746- // }
747-
748-
749- // private void copySupportLibs(File libsFolder) throws IOException {
750- // copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-core-utils/$VER", "support-core-utils-$VER.aar", SUPPORT_VER, libsFolder);
751- // copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-compat/$VER", "support-compat-$VER.aar", SUPPORT_VER, libsFolder);
752- // copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-fragment/$VER", "support-fragment-$VER.aar", SUPPORT_VER, libsFolder);
753- // copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-vector-drawable/$VER", "support-vector-drawable-$VER.aar", SUPPORT_VER, libsFolder);
754- // }
755-
756-
757- // private void copyAppCompatLib(File libsFolder) throws IOException {
758- // copyAARFileFromSDK(sdk.getSupportLibrary() + "/appcompat-v7/$VER", "appcompat-v7-$VER.aar", SUPPORT_VER, libsFolder);
759- // }
760-
761-
762- // private void copyGVRLibs(File libsFolder) throws IOException {
763- // copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-base-$VER.aar", GVR_VER, libsFolder);
764- // copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-common-$VER.aar", GVR_VER, libsFolder);
765- // copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-audio-$VER.aar", GVR_VER, libsFolder);
766- // }
767704
768- // private void copyGARLibs(File libsFolder) throws IOException {
769- // copyAARFileFromMode("/libraries/ar/garsdk/$VER", "sdk-common-$VER.aar", GAR_VER, libsFolder);
770- // }
771-
772- /*
773- private void copyAARFileFromSDK(String srcFolder, String filename, String version, File destFolder)
774- throws IOException {
775- String fn = filename.replace("$VER", version);
776- File srcFile = new File(srcFolder.replace("$VER", version), fn);
777- File destFile = new File(destFolder, fn);
778- if (srcFile.exists()) {
779- Util.copyFile(srcFile, destFile);
780- } else {
781- // If the AAR file does not exist in the installed SDK, gradle should be able to download it, and so
782- // we don't to anything besides printing a warning.
783- System.out.println("Warning: cannot find AAR package " + fn + " in installed SDK, gradle will try to download.");
784- }
785- }
786-
787-
788- private void copyAARFileFromMode(String srcFolder, String filename, String version, File destFolder)
789- throws IOException {
790- String fn = filename.replace("$VER", version);
791- File srcFile = mode.getContentFile(srcFolder.replace("$VER", version) + "/" + fn);
792- File destFile = new File(destFolder, fn);
793- if (srcFile.exists()) {
794- Util.copyFile(srcFile, destFile);
795- } else {
796- // If the AAR file does not exist in the mode, gradle should be able to download it, and so
797- // we don't to anything besides printing a warning.
798- System.out.println("Warning: cannot find AAR package " + fn + " in Android mode, gradle will try to download");
799- }
800- }
801- */
802705
803706 // ---------------------------------------------------------------------------
804707 // Export project
0 commit comments