[DEV] create a corect wallpaper without android knolege needed

This commit is contained in:
Edouard DUPIN 2013-08-26 22:31:51 +02:00
parent 6db445d6ee
commit 683e80d103

View File

@ -100,6 +100,8 @@ class Target(lutinTarget.Target):
#FINAL_FILE_ABSTRACTION
self.file_finalAbstraction = self.folder_javaProject + "/" + pkgName + ".java"
compleatePackageName = pkgProperties["COMPAGNY_TYPE"]+"."+pkgProperties["COMPAGNY_NAME2"]+"." + pkgName
debug.printElement("pkg", "absractionFile", "<==", "dynamic file")
# Create folder :
lutinTools.CreateDirectoryOfFile(self.file_finalAbstraction)
@ -112,7 +114,7 @@ class Target(lutinTarget.Target):
tmpFile.write( " * @license BSD v3 (see license file)\n")
tmpFile.write( " * @note This file is autogenerate ==> see documantation to generate your own\n")
tmpFile.write( " */\n")
tmpFile.write( "package "+pkgProperties["COMPAGNY_TYPE"]+"."+pkgProperties["COMPAGNY_NAME2"]+"." + pkgName + ";\n")
tmpFile.write( "package "+ compleatePackageName + ";\n")
tmpFile.write( "import org.ewol.EwolActivity;\n")
tmpFile.write( "public class " + pkgName + " extends EwolActivity {\n")
tmpFile.write( " public void onCreate(android.os.Bundle savedInstanceState) {\n")
@ -128,7 +130,7 @@ class Target(lutinTarget.Target):
tmpFile.write( " * @license BSD v3 (see license file)\n")
tmpFile.write( " * @note This file is autogenerate ==> see documantation to generate your own\n")
tmpFile.write( " */\n")
tmpFile.write( "package "+pkgProperties["COMPAGNY_TYPE"]+"."+pkgProperties["COMPAGNY_NAME2"]+"." + pkgName + ";\n")
tmpFile.write( "package "+ compleatePackageName + ";\n")
tmpFile.write( "import org.ewol.EwolWallpaper;\n")
tmpFile.write( "public class " + pkgName + " extends EwolWallpaper {\n")
tmpFile.write( " public static final String SHARED_PREFS_NAME = \"" + pkgName + "settings\";\n")
@ -154,7 +156,7 @@ class Target(lutinTarget.Target):
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
tmpFile.write( "<!-- Manifest is autoGenerated with Ewol ... do not patch it-->\n")
tmpFile.write( "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" \n")
tmpFile.write( " package=\""+pkgProperties["COMPAGNY_TYPE"]+"."+pkgProperties["COMPAGNY_NAME2"]+"." + pkgName + "\" \n")
tmpFile.write( " package=\"" + compleatePackageName + "\" \n")
tmpFile.write( " android:versionCode=\"1\" \n")
tmpFile.write( " android:versionName=\""+pkgProperties["VERSION"]+"\"> \n")
tmpFile.write( " <uses-feature android:glEsVersion=\"0x00020000\" android:required=\"true\" />\n")
@ -178,9 +180,9 @@ class Target(lutinTarget.Target):
tmpFile.write( " </application> \n")
else:
tmpFile.write( " <application android:label=\"" + pkgName + "\" \n")
tmpFile.write( " android:permission=\"android.permission.BIND_WALLPAPER\" \n")
tmpFile.write( " android:icon=\"@drawable/icon\">\n")
tmpFile.write( " <service android:name=\"." + pkgName + "\" \n")
tmpFile.write( " android:permission=\"android.permission.BIND_WALLPAPER\" \n")
tmpFile.write( " android:label=\"" + pkgProperties["NAME"])
if "debug"==self.buildMode:
tmpFile.write("-debug")
@ -189,11 +191,10 @@ class Target(lutinTarget.Target):
tmpFile.write( " <intent-filter>\n")
tmpFile.write( " <action android:name=\"android.service.wallpaper.WallpaperService\" />\n")
tmpFile.write( " </intent-filter>\n")
if True: #len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
tmpFile.write( " <meta-data android:name=\"android.service.wallpaper\"\n")
tmpFile.write( " android:resource=\"@xml/livewallpaper\" />\n")
tmpFile.write( " android:resource=\"@xml/" + pkgName + "_resource\" />\n")
tmpFile.write( " </service>\n")
if True: #len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
if len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
tmpFile.write( " <activity android:label=\"Setting\"\n")
tmpFile.write( " android:name=\"." + pkgName + "Settings\"\n")
tmpFile.write( " android:theme=\"@android:style/Theme.Light.WallpaperSettings\"\n")
@ -201,9 +202,6 @@ class Target(lutinTarget.Target):
tmpFile.write( " android:icon=\"@drawable/icon\">\n")
tmpFile.write( " </activity>\n")
tmpFile.write( " </application>\n")
# TODO : Generate Needed files for configurations
# TODO : Set the configuration properties on the ewol properties
# TODO : Set wallpaper without properties
# write package autorisations :
if True==self.CheckRightPackage(pkgProperties, "WRITE_EXTERNAL_STORAGE"):
tmpFile.write( " <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /> \n")
@ -236,6 +234,105 @@ class Target(lutinTarget.Target):
tmpFile.close()
# end generating android manifest
if pkgProperties["ANDROID_APPL_TYPE"]!="APPL":
#create the Wallpaper sub files : (main element for the application
debug.printElement("pkg", pkgName + "_resource.xml", "<==", "package configurations")
lutinTools.CreateDirectoryOfFile(self.GetStagingFolder(pkgName) + "/res/xml/" + pkgName + "_resource.xml")
tmpFile = open(self.GetStagingFolder(pkgName) + "/res/xml/" + pkgName + "_resource.xml", 'w')
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
tmpFile.write( "<wallpaper xmlns:android=\"http://schemas.android.com/apk/res/android\"\n")
if len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
tmpFile.write( " android:settingsActivity=\""+compleatePackageName + "."+ pkgName + "Settings\"\n")
tmpFile.write( " android:thumbnail=\"@drawable/icon\"/>\n")
tmpFile.flush()
tmpFile.close()
# create wallpaper setting if needed (class and config file)
if len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
lutinTools.CreateDirectoryOfFile(self.folder_javaProject + pkgName + "Settings.java")
debug.printElement("pkg", self.folder_javaProject + pkgName + "Settings.java", "<==", "package configurations")
tmpFile = open(self.folder_javaProject + pkgName + "Settings.java", 'w');
tmpFile.write( "package " + compleatePackageName + ";\n")
tmpFile.write( "\n")
tmpFile.write( "import " + compleatePackageName + ".R;\n")
tmpFile.write( "\n")
tmpFile.write( "import android.content.SharedPreferences;\n")
tmpFile.write( "import android.os.Bundle;\n")
tmpFile.write( "import android.preference.PreferenceActivity;\n")
tmpFile.write( "\n")
tmpFile.write( "public class " + pkgName + "Settings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener\n")
tmpFile.write( "{\n")
tmpFile.write( " @Override protected void onCreate(Bundle icicle) {\n")
tmpFile.write( " super.onCreate(icicle);\n")
tmpFile.write( " getPreferenceManager().setSharedPreferencesName("+ pkgName + ".SHARED_PREFS_NAME);\n")
tmpFile.write( " addPreferencesFromResource(R.xml."+ pkgName + "_settings);\n")
tmpFile.write( " getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);\n")
tmpFile.write( " }\n")
tmpFile.write( " @Override protected void onResume() {\n")
tmpFile.write( " super.onResume();\n")
tmpFile.write( " }\n")
tmpFile.write( " @Override protected void onDestroy() {\n")
tmpFile.write( " getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);\n")
tmpFile.write( " super.onDestroy();\n")
tmpFile.write( " }\n")
tmpFile.write( " public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) { }\n")
tmpFile.write( "}\n")
tmpFile.flush()
tmpFile.close()
debug.printElement("pkg", self.GetStagingFolder(pkgName) + "/res/xml/" + pkgName + "_settings.xml", "<==", "package configurations")
lutinTools.CreateDirectoryOfFile(self.GetStagingFolder(pkgName) + "/res/xml/" + pkgName + "_settings.xml")
tmpFile = open(self.GetStagingFolder(pkgName) + "/res/xml/" + pkgName + "_settings.xml", 'w');
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
tmpFile.write( "<PreferenceScreen xmlns:android=\"http://schemas.android.com/apk/res/android\"\n")
tmpFile.write( " android:title=\"Settings\"\n")
tmpFile.write( " android:key=\"" + pkgName + "_settings\">\n")
WALL_haveArray = False
for WALL_type, WALL_key, WALL_title, WALL_summary, WALL_other in pkgProperties["ANDROID_WALLPAPER_PROPERTIES"]:
debug.info("find : '" + WALL_type + "'");
if WALL_type == "list":
debug.info(" create : LIST");
tmpFile.write( " <ListPreference android:key=\"" + pkgName + "_" + WALL_key + "\"\n")
tmpFile.write( " android:title=\"" + WALL_title + "\"\n")
tmpFile.write( " android:summary=\"" + WALL_summary + "\"\n")
tmpFile.write( " android:entries=\"@array/" + pkgName + "_" + WALL_key + "_names\"\n")
tmpFile.write( " android:entryValues=\"@array/" + pkgName + "_" + WALL_key + "_prefix\"/>\n")
WALL_haveArray=True
elif WALL_type == "bool":
debug.info(" create : CHECKBOX");
tmpFile.write( " <CheckBoxPreference android:key=\"" + pkgName + "_" + WALL_key + "\"\n")
tmpFile.write( " android:title=\"" + WALL_title + "\"\n")
tmpFile.write( " android:summary=\"" + WALL_summary + "\"\n")
tmpFile.write( " android:summaryOn=\"" + WALL_other[0] + "\"\n")
tmpFile.write( " android:summaryOff=\"" + WALL_other[1] + "\"/>\n")
tmpFile.write( "</PreferenceScreen>\n")
tmpFile.flush()
tmpFile.close()
if WALL_haveArray==True:
for WALL_type, WALL_key, WALL_title, WALL_summary, WALL_other in pkgProperties["ANDROID_WALLPAPER_PROPERTIES"]:
if WALL_type == "list":
debug.printElement("pkg", self.GetStagingFolder(pkgName) + "/res/values/" + WALL_key + ".xml", "<==", "package configurations")
lutinTools.CreateDirectoryOfFile(self.GetStagingFolder(pkgName) + "/res/values/" + WALL_key + ".xml")
tmpFile = open(self.GetStagingFolder(pkgName) + "/res/values/" + WALL_key + ".xml", 'w');
tmpFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
tmpFile.write( "<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n")
tmpFile.write( " <string-array name=\"" + pkgName + "_" + WALL_key + "_names\">\n")
for WALL_subKey, WALL_display in WALL_other:
tmpFile.write( " <item>" + WALL_display + "</item>\n")
tmpFile.write( " </string-array>\n")
tmpFile.write( " <string-array name=\"" + pkgName + "_" + WALL_key + "_prefix\">\n")
for WALL_subKey, WALL_display in WALL_other:
tmpFile.write( " <item>" + WALL_subKey + "</item>\n")
tmpFile.write( " </string-array>\n")
tmpFile.write( "</resources>\n")
tmpFile.flush()
tmpFile.close()
#add properties on wallpaper :
# myModule.pkgAdd("ANDROID_WALLPAPER_PROPERTIES", ["list", key, title, summary, [["key","value display"],["key2","value display 2"]])
# myModule.pkgAdd("ANDROID_WALLPAPER_PROPERTIES", ["list", "testpattern", "Select test pattern", "Choose which test pattern to display", [["key","value display"],["key2","value display 2"]]])
# myModule.pkgAdd("ANDROID_WALLPAPER_PROPERTIES", ["bool", key, title, summary, ["enable string", "disable String"])
# myModule.pkgAdd("ANDROID_WALLPAPER_PROPERTIES", ["bool", "movement", "Motion", "Apply movement to test pattern", ["Moving test pattern", "Still test pattern"]
#copy needed resources :
for res_source, res_dest in pkgProperties["ANDROID_RESOURCES"]:
if res_source == "":
@ -277,6 +374,8 @@ class Target(lutinTarget.Target):
else:
filesString += element + " "
if len(pkgProperties["ANDROID_WALLPAPER_PROPERTIES"])!=0:
filesString += self.folder_javaProject + pkgName + "Settings.java "
cmdLine = "javac " \
+ "-d " + self.GetStagingFolder(pkgName) + "/build/classes " \