CREATE GPRS CONNECTION RasSetEntryProperties problem - Windows Mobile Software Development
Hi
I must create programmatically a new connection to a VPN network whit "Cellular Line (GPRS)".What's wrong in this code?
#include "stdafx.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>
// (DEBUT) DECLARATIONS+PROTOTYPES CONCERNANT LES ENTREES RAS
// Code ajouté pour entrées RAS
#include "stdlib.h"
#include "tchar.h"
#include "windows.h"
// ----
#include "ras.h"
#include "raserror.h"
#include "tapi.h"
#ifndef TAPI_CURRENT_VERSION
#define TAPI_CURRENT_VERSION 0x00020000
#endif
#define TAPI_VERSION_1_0 0x00010003
#define TAPI_VERSION_3_0 0x00030000
LPVARSTRING lpDevCfg = NULL;
DWORD WINAPI GetDevCfg(DWORD dwLineId, HWND Hwnd, bool bShowDialog);
DWORD WINAPI RasEnumDev(LPWSTR lpstr);
DWORD WINAPI RasEnum(LPWSTR lpstr);
DWORD WINAPI test();
DWORD WINAPI CreateRasEntry(LPWSTR lpszName, LPWSTR lpszLogin, LPWSTR lpszPassword, LPWSTR lpszDeviceName);
DWORD GetConnectionStatus();
BOOLEAN showErr=TRUE; BOOLEAN debug=TRUE;
DWORD TraitementsRAS(); // SPECIFIQUE A CETTE APPLICATION
// (FIN) DECLARATIONS+PROTOTYPES CONCERNANT LES ENTREES RAS
// (DEBUT) DECLARATIONS+PROTOTYPES CONCERNANT LA BASE DE REGISTRES
#include "winreg.h"
DWORD WriteKey();
DWORD DeleteKey();
// (FIN) DECLARATIONS+PROTOTYPES CONCERNANT LA BASE DE REGISTRES
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // The current instance
HWND hwndCB; // The command bar handle
static SHACTIVATEINFO s_sai;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
//RasEnum(_T(""));
// RasEnumDev(_T(""));
TraitementsRAS();
// test();
return TRUE;
}
DWORD WINAPI test(){
//RETAILMSG(1,(TEXT("start\r\n")));
RASENTRY RasEntry;
RASDIALPARAMS RasDialParams;
HRASCONN hRasConn=NULL;
DWORD dwSize;
DWORD dwError;
TCHAR szError[100];
TCHAR szMsg[100];
// Initialize the RASENTRY structure.
dwSize=sizeof(RasEntry);
memset (&RasEntry, 0, dwSize);
RasEntry.dwSize=dwSize;
RasEntry.dwfOptions=0;
wcscpy(RasEntry.szLocalPhoneNumber,TEXT("4"));
RasEntry.dwfNetProtocols=RASNP_Ip;
RasEntry.dwFramingProtocol=RASFP_Ppp;
wcscpy(RasEntry.szDeviceType,RASDT_Modem);
// Get the name of the modem, i left this function out...
//InitializeTAPI();
wcscpy(RasEntry.szDeviceName,_T("Cellular Line"));
// Create a new phone-book entry.
dwError=RasSetEntryProperties(NULL,
TEXT("entry"),&RasEntry,sizeof(RASENTRY),NULL,0);
if (dwError!=0)
{
wsprintf (szError, TEXT("Unable to create the phonebook entry!%ld\r\n"),dwError);
MessageBox(NULL, szError, _T("ERROR:GetDevCfg"), MB_OK);
//RETAILMSG(1,(szError));
return(0);
}
// Initialize the RASDIALPARAMS structure.
memset (&RasDialParams,0,sizeof(RasDialParams));
RasDialParams.dwSize=sizeof(RasDialParams);
wcscpy(RasDialParams.szEntryName,TEXT("entry"));
RasDialParams.szPhoneNumber[0]=NULL;
RasDialParams.szCallbackNumber[0]=NULL;
wcscpy(RasDialParams.szUserName,TEXT("testuser"));
wcscpy(RasDialParams.szPassword,TEXT("secret"));
wcscpy(RasDialParams.szDomain,TEXT("testdomain"));
// Change the connection data.
dwError=RasSetEntryDialParams (NULL, &RasDialParams, FALSE);
if (dwError!=0)
{
wsprintf (szError, TEXT("Unable to set the connection information.")
TEXT(" Error %ld\r\n"), dwError);
MessageBox(NULL, szError, _T("ERROR:GetDevCfg"), MB_OK);
//RETAILMSG(1,(szError));
return(0);
}
hRasConn = NULL;
DWORD dwRval;
dwRval=RasDial(NULL,NULL,&RasDialParams,0,NULL,&hRasConn);
if (dwRval!=0)
{
wsprintf(szMsg,TEXT("Error RasDial(): %ld\r\n"),dwRval);
MessageBox(NULL,szMsg, _T("ERROR:GetDevCfg"), MB_OK);
}
else
{
MessageBox(NULL,_T("RasDial ok!"), _T("ERROR:GetDevCfg"), MB_OK);
}
return(0);
}
DWORD WINAPI TraitementsRAS() {
DWORD ret;
TCHAR szMess[128];
wsprintf(szMess, _T("OK per lanciare la connessione Cancel per annullarla"));
int rep=MessageBox(NULL, szMess, _T("Connessione"), MB_OKCANCEL);
if (rep!=IDCANCEL) {
// OBTENTION DEVICE CONFIGURATION POUR dwLineID=1 (Modem IrDA générique) HKEY_LOC_MACH\DRIVERS\BUILTIN
ret=GetDevCfg(3,NULL,FALSE);
if ( (ret!=0) && (showErr==TRUE) ) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("ERROR:GetDevCfg"), MB_OK);
}
else {
if (debug==TRUE) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("DBG:GetDevCfg:OK"), MB_OK);
}
}
// RAS CREATE ENTRY
ret=CreateRasEntry(_T("RFI"),_T("pippo"),_T("pippo"), _T("Cellular Line (GPRS)"));
if ( (ret!=0) && (showErr==TRUE) ) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("ERROR:CreateRasEntry"), MB_OK);
}
else {
if (debug==TRUE) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("DBG:CreateRasEntry:OK"), MB_OK);
}
}
// PER RENDERE VISIBILE LA CONNESSIONE
WriteKey();
// RAS DIAL ENTRY
RASDIALPARAMS rasDialParam;
// Configure the RASDIALPARAMS structure.
rasDialParam.dwSize = sizeof (RASDIALPARAMS);
rasDialParam.szPhoneNumber[0] = TEXT('\0');
rasDialParam.szCallbackNumber[0] = TEXT('\0');
wcscpy (rasDialParam.szEntryName, _T("RFI"));
HRASCONN rasConn=NULL;
unsigned long connection;
ret=RasDial(NULL, NULL, &rasDialParam, NULL, NULL, &rasConn);
if ( (ret!=0) && (showErr==TRUE) ) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("ERROR:RasDial"), MB_OK);
}
else {
if (debug==TRUE) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("DBG:RasDial:OK"), MB_OK);
}
}
if (ret==0) {
connection = (unsigned long) rasConn;
wsprintf(szMess, _T("Cliquez sur OK lorsque vous voudrez déconnecter la borne infrarouge..."));
MessageBox(NULL, szMess, _T("JAHLIGHT CONNEXION INFRAROUGE"), MB_OK);
}
/*
ret=RasHangUp((HRASCONN) connection);
if ( (ret!=0) && (showErr==TRUE) ) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("ERROR:RasHangUp"), MB_OK);
}
else {
if (debug==TRUE) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("DBG:RasHangUp:OK"), MB_OK);
}
}
DeleteKey();
LPWSTR lpszEntry=_T("JAHLIGHT");
ret=RasDeleteEntry(NULL, lpszEntry);
if ( (ret!=0) && (showErr==TRUE) ) {
wsprintf(szMess, _T("RasDeleteEntry returned %ld"), ret);
MessageBox(NULL, szMess, _T("ERROR:RasDeleteEntry"), MB_OK);
}
else {
if (debug==TRUE) {
wsprintf(szMess, _T("ret=%ld"), ret);
MessageBox(NULL, szMess, _T("DBG:RasDeleteEntry:OK"), MB_OK);
}
}
*/
}
return 0;
}
DWORD WINAPI GetDevCfg(DWORD dwLineId, HWND Hwnd, bool bShowDialog)
{
DWORD dwErr = 0;
LPVARSTRING cfg = NULL;
WCHAR lpszString[20];
wcscpy(lpszString,_T("/0"));
if (!(cfg = (LPVARSTRING) LocalAlloc(LPTR, 280)))
{
return 1;
}
if (!(lpDevCfg = (LPVARSTRING) LocalAlloc(LPTR, 280)))
{
return 1;
}
cfg->dwTotalSize = 280;
cfg->dwStringFormat=STRINGFORMAT_BINARY;
lpDevCfg->dwTotalSize = 280;
lpDevCfg->dwStringFormat=STRINGFORMAT_BINARY;
if (bShowDialog)
{
dwErr = lineGetDevConfig(dwLineId, cfg, _T("tapi/line"));
dwErr = lineConfigDialogEdit(dwLineId, Hwnd , _T("tapi/line"),
(LPVOID)((LPBYTE)cfg + cfg->dwStringOffset),
cfg->dwNeededSize,
lpDevCfg);
}
else
{
dwErr = lineGetDevConfig(dwLineId, lpDevCfg, _T("tapi/line"));
}
return dwErr;
LocalFree(cfg);
}
void WINAPI RasHang(HRASCONN &connection)
{
if (connection == 0)
connection = NULL;
if (connection != NULL)
{
RasHangUp(connection);
connection = NULL;
}
else
MessageBox(NULL,_T("Pas de connexion active."),_T("Connexions"),MB_OK | MB_ICONWARNING);
}
DWORD WINAPI RasConnect(LPWSTR sName, DWORD &connection)
{
HRASCONN g_hRasConn = NULL;
RASDIALPARAMS rasDialParams;
DWORD dwRes;
BOOL bPassword;
rasDialParams.dwSize = sizeof(RASDIALPARAMS);
wcscpy(rasDialParams.szEntryName,sName);
dwRes = RasGetEntryDialParams(NULL, &rasDialParams, &bPassword);
if (dwRes != 0)
{
// Error getting Dial params
return dwRes;
}
if(!bPassword)
MessageBox(NULL,_T("Pas de mot de passe"),_T("Connexions"),MB_OK | MB_ICONINFORMATION);
dwRes = RasDial(NULL,NULL,&rasDialParams,0,NULL,&g_hRasConn);
if (dwRes != 0)
{
// Error Dialing RAS
RasHangUp(g_hRasConn);
g_hRasConn = NULL;
return dwRes;
}
connection = (unsigned long)g_hRasConn;
return dwRes;
}
DWORD WINAPI RasEnum(LPWSTR lpstr) {
LPRASENTRYNAME lpRasEntry = NULL;
RASENTRY RasEntry;
DWORD dwRes,dwError, dwSize, dwSize2, dwEntries, dw;
TCHAR szError[100];
WCHAR szTmp[255];
wcscpy(szTmp,_T(""));
lpRasEntry = new RASENTRYNAME[20];
if(lpRasEntry == NULL) {
return 1;
}
lpRasEntry[0].dwSize = sizeof(RASENTRYNAME);
dwSize = sizeof(RASENTRYNAME) * 20;
memset(&RasEntry,0,sizeof(RASENTRY));
dwSize2 = sizeof(RASENTRY);
RasEntry.dwSize = dwSize2;
dwRes = RasEnumEntries(NULL, NULL, lpRasEntry, &dwSize, &dwEntries);
if (dwRes != 0)
MessageBox(NULL,_T("Error getting RAS entries"),_T("Connexions"),MB_OK | MB_ICONWARNING);
else {
//for(dw = 0; dw < dwEntries; dw++) {
for(dw = 0; dw < 1; dw++) {
MessageBox(NULL,lpRasEntry[dw].szEntryName,_T("TEST"),MB_OK);
// Retrieve the entry properties
if (dwError = RasGetEntryProperties(NULL, lpRasEntry[dw].szEntryName, &RasEntry, &dwSize2, NULL, NULL)) {
wsprintf(szError, _T("Unable to read default entry properties.")_T(" Error %ld"),dwError);
MessageBox(NULL,szError,_T("RasGetEntryProperties Error"),MB_OK | MB_ICONWARNING);
}
else{
// RASIPADDR mio = RasEntry.ipaddr;
wsprintf(szError, _T("dwfOptions")_T(" Error %ld"),RasEntry.dwCountryCode);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
// MessageBox(NULL,mio.a,_T("ipaddr"),MB_OK | MB_ICONWARNING);
//RASIPADDR
/*
wsprintf(szError, _T("dwFramingProtocol")_T(" Error %ld"),RasEntry.dwFramingProtocol);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
wsprintf(szError, _T("dwAlternatesOffset")_T(" Error %ld"),RasEntry.dwAlternatesOffset);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
wsprintf(szError, _T("dwFrameSize")_T(" Error %ld"),RasEntry.dwFrameSize);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
wsprintf(szError, _T("dwfNetProtocols")_T(" Error %ld"),RasEntry.dwfNetProtocols);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szScript,_T("szScript"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szAutoDialDll,_T("szAutoDialDll"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szAutoDialFunc,_T("szAutoDialFunc"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szDeviceType,_T("szDeviceType"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szDeviceName,_T("szDeviceName"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szX25PadType,_T("szX25PadType"),MB_OK | MB_ICONWARNING);
MessageBox(NULL,RasEntry.szAutoDialFunc,_T("szAutoDialFunc"),MB_OK | MB_ICONWARNING);
wsprintf(szError, _T("dwChannels")_T(" Error %ld"),RasEntry.dwChannels);
MessageBox(NULL,szError,_T("TROVO"),MB_OK | MB_ICONWARNING);
*/
}
wcscat(szTmp,lpRasEntry[dw].szEntryName);
wcscat(szTmp,_T("\n"));
}
wcscpy(lpstr,szTmp);
}
delete [] lpRasEntry;
return dwRes;
}
DWORD WINAPI RasEnumDev(LPWSTR lpstr) {
DWORD lpcb = 0 , lpcDevices, nRet, dw;
WCHAR szTmp[255];
LPRASDEVINFOW lpRasDevInfo = NULL;
RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices);
lpRasDevInfo = (LPRASDEVINFOW) GlobalAlloc(GPTR, lpcb);
lpRasDevInfo->dwSize = sizeof(RASDEVINFOW);
nRet = RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices);
/* debug only
// convert long to string
_ltow(lpcDevices, szTmp, 10);
MessageBox(NULL,szTmp,_T("Connexions"),MB_OK | MB_ICONWARNING);
*/
// initialisation de la variable temporaire szTmp
wcscpy(szTmp,_T(""));
if (nRet !=0) {
MessageBox(NULL,_T("RasEnumDevices failed"),_T("Connexions"),MB_OK | MB_ICONWARNING);
}
else {
for (dw = 0; dw < lpcDevices; dw++) {
wcscat(szTmp, lpRasDevInfo->szDeviceName);
wcscat(szTmp,_T("\n"));
MessageBox(NULL,szTmp,_T("Connexions"),MB_OK | MB_ICONWARNING);
lpRasDevInfo++;
}
wcscpy(lpstr,szTmp);
}
return nRet;
}
DWORD WINAPI CreateRasEntry(LPWSTR lpszName, LPWSTR lpszLogin, LPWSTR lpszPassword, LPWSTR lpszDeviceName) {
DWORD dwSize,
dwDevInfo = 280 /* 128 */,
dwError = 0;
//PDEVCFG pDevCfg;
TCHAR szError[100];
RASENTRY RasEntry;
RASIPADDR ipaddrDns ;
ipaddrDns.a = 145;
ipaddrDns.b = 130;
ipaddrDns.c = 233;
ipaddrDns.d = 10;
RASDIALPARAMS RasDialParams;
// Validate the format of a connection entry name
//
if (dwError = RasValidateEntryName(NULL, lpszName)) {
wsprintf(szError, _T("Unable to validate entry name.")_T(" Error %ld"),dwError);
MessageBox(NULL,szError,_T("Create Entry"),MB_OK | MB_ICONWARNING);
return dwError;
}
// initialize the RASENTRY structure
//
memset(&RasEntry,0,sizeof(RASENTRY));
dwSize = sizeof(RASENTRY);
RasEntry.dwSize = dwSize;
// Retrieve the entry properties
if (dwError = RasGetEntryProperties(NULL, _T(""), &RasEntry, &dwSize, NULL, NULL)) {
wsprintf(szError, _T("Unable to read default entry properties.")_T(" Error %ld"),dwError);
MessageBox(NULL,szError,_T("Create Entry"),MB_OK | MB_ICONWARNING);
return dwError;
}
// Fill the RASENTRY structure
//
// _tcscpy(RasEntry.szAreaCode, _T("\0"));
RasEntry.dwCountryID=(DWORD) 0;
// RasEntry.dwCountryCode = (DWORD) 0;
//_tcscpy(RasEntry.szAreaCode, lpszAreaCode);
RasEntry.dwCountryCode = (DWORD) 0;
_tcscpy(RasEntry.szLocalPhoneNumber, _T("~GPRS!rfi.tim.it"));
_tcscpy(RasEntry.szDeviceType, RASDT_Modem);
//_tcscpy(RasEntry.szDeviceName, _T("GSM Modem on COM2:"));
_tcscpy(RasEntry.szDeviceName, lpszDeviceName);
// RasEntry.dwfOptions = RASEO_UseCountryAndAreaCodes;
RasEntry.dwfOptions = RASEO_SpecificNameServers ;
RasEntry.dwAlternatesOffset=(DWORD) 1;
RasEntry.ipaddrDns = ipaddrDns;
RasEntry.dwfNetProtocols = (DWORD) 4;
RasEntry.dwFramingProtocol=RASFP_Ppp;
//memcpy( &(RasEntry.ipaddrDns), &RasEntry, sizeof( RASIPADDR ) );
// Create a new phone-book entry.
if (dwError = RasSetEntryProperties(NULL, lpszName, &RasEntry,sizeof(RASENTRY), (LPBYTE)lpDevCfg + lpDevCfg->dwStringOffset, lpDevCfg->dwStringSize)) {
//wsprintf(szError, _T("Unable to create the phone-book entry.")_T(" Error %ld"),dwError);
//MessageBox(NULL,szError,_T("Create Entry"),MB_OK | MB_ICONWARNING);
LocalFree(lpDevCfg);
return dwError;
}
LocalFree(lpDevCfg);
// Initialize a RASDIALPARAMS structure
//
memset(&RasDialParams,0,sizeof(RASDIALPARAMS));
RasDialParams.dwSize = sizeof(RASDIALPARAMS);
_tcscpy(RasDialParams.szEntryName, lpszName);
// Insert code here to fill up the RASDIALPARAMS structure
// RasDialParams.szPhoneNumber, lpszPhoneNumber;
// RasDialParams.szCallbackNumber[0], _T("\0");
RasDialParams.szPhoneNumber[0]=NULL;
RasDialParams.szCallbackNumber[0]=NULL;
wcscpy(RasDialParams.szUserName,lpszLogin);
wcscpy(RasDialParams.szPassword,lpszPassword);
wcscpy(RasDialParams.szDomain,TEXT("rfi.tim.it"));
// _tcscpy(RasDialParams.szUserName, lpszLogin);
// _tcscpy(RasDialParams.szPassword, lpszPassword);
// Change the connection data
//
if (dwError = RasSetEntryDialParams(NULL, &RasDialParams, FALSE)) {
//wsprintf(szError, _T("Unable to create the phone-book entry.")_T(" Error %ld"),dwError);
//MessageBox(NULL,szError,_T("Create Entry"),MB_OK | MB_ICONWARNING);
return dwError;
}
return dwError;
}
// ----------------------------------------------------------------
// (FIN) FONCTIONS CONCERNANT LA CREATION/DESTRUCTION D'ENTREES RAS
// ----------------------------------------------------------------
// -------------------------------------------------
// (DEBUT) FONCTIONS CONCERNANT LA BASE DE REGISTRES
// -------------------------------------------------
DWORD WriteKey()
{
//{ADB0B001-10B5-3F39-27C6-9742E785FCD4} = DestId (param internet)
//{18AD9FBD-F716-ACB6-FD8A-1965DB95B814} (param travail)
HKEY RegKey;
DWORD dwDisposition;
// Ouverture de la clé racine HKCU/Software
// if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\ConnMgr\\Providers\\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\\Connections"), 0, 0, &RegKey)==ERROR_SUCCESS)
if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\ConnMgr\\Providers\\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\\Connections"), 0, TEXT(""), 0, 0, NULL, &RegKey,
&dwDisposition)==ERROR_SUCCESS)
{
HKEY WorkKey;
DWORD dwDisposition;
// Création ou ouverture de la clé MyRegistryKey
if (RegCreateKeyEx (RegKey, TEXT("RFI"), 0, TEXT(""), 0, 0, NULL, &WorkKey,
&dwDisposition)==ERROR_SUCCESS)
{
TCHAR Key[32], Value[64];
wsprintf (Key, TEXT("DestId"));
wsprintf (Value, TEXT("{ADB0B001-10B5-3F39-27C6-9742E785FCD4}"));
RegSetValueEx (WorkKey, Key, 0, REG_SZ, (BYTE *)Value, lstrlen(Value)*sizeof(TCHAR));
DWORD dwValue;
wsprintf(Key, TEXT("RequirePw"));
dwValue=1;
RegSetValueEx (WorkKey, Key, 0, REG_DWORD, (BYTE *)&dwValue, sizeof(DWORD));
wsprintf(Key, TEXT("Enabled"));
dwValue=1;
RegSetValueEx (WorkKey, Key, 0, REG_DWORD, (BYTE *)&dwValue, sizeof(DWORD));
wsprintf(Key, TEXT("EntryType"));
dwValue=0;
RegSetValueEx (WorkKey, Key, 0, REG_DWORD, (BYTE *)&dwValue, sizeof(DWORD));
RegCloseKey(WorkKey);
if (debug==TRUE)
{
MessageBox(NULL, _T("RAS entry added in registry."), _T("DBG:RegCreateKeyEx"), MB_OK);
}
}
else
{
if (showErr==TRUE)
{
MessageBox(NULL, _T("Error while adding RAS entry in registry"), _T("ERROR:RegCreateEntryEx"), MB_OK);
}
}
RegCloseKey(RegKey);
}
return 0;
}
DWORD DeleteKey()
{
//{ADB0B001-10B5-3F39-27C6-9742E785FCD4} = DestId (param internet)
//{18AD9FBD-F716-ACB6-FD8A-1965DB95B814} (param travail)
DWORD ret=NULL;
ret=RegDeleteKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\ConnMgr\\Providers\\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\\Connections\\RFI"));
if (ret==ERROR_SUCCESS)
{
if (debug==TRUE)
{
MessageBox(NULL, _T("Key successfully deleted."), _T("JAHLIGHT IR connect"), MB_OK);
}
}
else
{
if (showErr==TRUE)
{
TCHAR szMess[128];
if (ret!=87) wsprintf(szMess, _T("ERROR: Key not deleted, Error code=%ld"), ret);
else wsprintf(szMess, _T("RegDeleteKey:ERROR_INVALID_PARAMETER"));
MessageBox(NULL, szMess, _T("ERROR:RegDeleteKey"), MB_OK);
}
}
return 0;
}
// -------------------------------------------------
// (FIN) FONCTIONS CONCERNANT LA BASE DE REGISTRES
// -------------------------------------------------
Thank's in advance
CREATE RAS ENTRY
Why don't work :? :? :? :? :?
DWORD WINAPI CreateRasEntry(LPWSTR lpszName, LPWSTR lpszLogin, LPWSTR lpszPassword) {
DWORD dwSize,
dwDevInfo = 280 /* 128 */,
dwError = 0;
//PDEVCFG pDevCfg;
TCHAR szError[100];
RASENTRY RasEntry;
RASIPADDR ipaddrDns ;
RASDIALPARAMS RasDialParams;
// Validate the format of a connection entry name
//
if (dwError = RasValidateEntryName(NULL, lpszName)) {
return dwError;
}
// initialize the RASENTRY structure
//
memset(&RasEntry,0,sizeof(RASENTRY));
dwSize = sizeof(RASENTRY);
RasEntry.dwSize = dwSize;
// Retrieve the entry properties
if (dwError = RasGetEntryProperties(NULL, _T(""), &RasEntry, &dwSize, NULL, NULL)) {
return dwError;
}
// Fill the RASENTRY structure
//
ipaddrDns.a = 145;
ipaddrDns.b = 130;
ipaddrDns.c = 233;
ipaddrDns.d = 10;
_tcscpy(RasEntry.szDeviceType, RASDT_Vpn);
_tcscpy(RasEntry.szDeviceName, _T("Cellular Line (GPRS)"));
RasEntry.dwfOptions = RASEO_SpecificNameServers ;
RasEntry.ipaddrDns = ipaddrDns;
// Create a new phone-book entry.
if (dwError = RasSetEntryProperties(NULL, lpszName, &RasEntry,sizeof(RASENTRY), (LPBYTE)lpDevCfg + lpDevCfg->dwStringOffset, lpDevCfg->dwStringSize)) {
LocalFree(lpDevCfg);
return dwError;
}
LocalFree(lpDevCfg);
// Initialize a RASDIALPARAMS structure
//
memset(&RasDialParams,0,sizeof(RASDIALPARAMS));
RasDialParams.dwSize = sizeof(RASDIALPARAMS);
_tcscpy(RasDialParams.szEntryName, lpszName);
// Insert code here to fill up the RASDIALPARAMS structure
wcscpy(RasDialParams.szUserName,lpszLogin);
wcscpy(RasDialParams.szPassword,lpszPassword);
// Change the connection data
//
if (dwError = RasSetEntryDialParams(NULL, &RasDialParams, FALSE)) {
return dwError;
}
return dwError;
}
Related
Writing a Today Plugin
I am trying to write a today plugin. I've used most of the same code from the sample but it doesn't work. The plugin displays for a few seconds then disappears. Code: // HelloToday2.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "todaycmn.h" #define HELLOTODAY TEXT("HelloToday") HINSTANCE hInst; //HWND hWnd; void OnPaint(HWND); BOOL OnQueryRefreshCache(HWND, TODAYLISTITEM*); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { hInst = (HINSTANCE)hModule; //RegisterClass(hInst); break; } case DLL_PROCESS_DETACH: { UnregisterClass(HELLOTODAY, hInst); break; } } return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: OnPaint(hWnd); break; case WM_TODAYCUSTOM_CLEARCACHE: break; case WM_TODAYCUSTOM_QUERYREFRESHCACHE: OnQueryRefreshCache(hWnd, (TODAYLISTITEM*)wParam); break; case WM_LBUTTONUP: // ButtonProc(); break; } return 0; } void OnPaint(HWND hWnd) { PAINTSTRUCT ps; HDC hDC; COLORREF crText = (COLORREF)SendMessage(GetParent(hWnd), TODAYM_GETCOLOR, (WPARAM)TODAYCOLOR_TEXT, 0); COLORREF crHighlight = (COLORREF)SendMessage(GetParent(hWnd), TODAYM_GETCOLOR, (WPARAM)TODAYCOLOR_HIGHLIGHT, 0); TODAYDRAWWATERMARKINFO dwi; RECT rc; GetClientRect(hWnd, &rc); dwi.rc = rc; dwi.hwnd = hWnd; dwi.hdc = hDC; hDC = BeginPaint(hWnd, &ps); SetTextColor(hDC, crText); int nBkMode = SetBkMode(hDC, OPAQUE); SetBkColor(hDC, crHighlight); DrawText(hDC, TEXT("Hello World!"), -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE); SetBkMode(hDC, nBkMode); EndPaint(hWnd, &ps); } BOOL OnQueryRefreshCache(HWND hWnd, TODAYLISTITEM* pItem) { if(!pItem) return FALSE; pItem->cyp = DRA::SCALEY(20); return TRUE; } HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *pItem, HWND hWndParent) { if(!pItem->fEnabled) return NULL; WNDCLASS wc; memset(&wc, 0, sizeof(wc)); wc.style = 0; wc.lpfnWndProc = (WNDPROC)WndProc; //wc.cbClsExtra = 0; //wc.cbWndExtra = 0; wc.hInstance = hInst; wc.hIcon = 0; wc.hCursor = 0; wc.lpszClassName = TEXT("HelloToday"); wc.hbrBackground = NULL; RegisterClass(&wc); HWND hWnd = CreateWindow(TEXT("HelloToday"), NULL, WS_VISIBLE | WS_CHILD, 0, 0, 240, 20, hWndParent, NULL, hInst, 0); if(pItem->fEnabled = TRUE) ShowWindow(hWnd, SW_SHOW); return hWnd; }
Kinetic Scroller
hello guys. just want to share this code to you PHP: using System; namespace FBScroller { using System.Windows.Forms; using System.Drawing; public class KineticScroller { /* * Kinetic Scroller * by: Jayson Ragasa * supports Windows Forms and WinMobile Forms * --------------------------------------- * Code stripped from: Implementing a smoothly animated ListBox * http://www.codeproject.com/KB/list/SmoothListBox.aspx * * by: Fredrik Bornander * http://www.codeproject.com/Members/Fredrik-Bornander * --------------------------------------- * Usage: * make a panel1 on a form * KineticScroller.HorizontalScroller ks = new KineticScroller.HorizontalScroller(panel1, this); * make a new panel2 inside panel1 * KineticScroller.VerticalScroller ks2 = new KineticScroller.VerticalScroller(panel2, panel1); */ public class VerticalScroller { #region vars private Point previousPoint = new Point(); private int draggedDistance = 0; private float velocity = 0.0f; private bool mouseIsDown = false; private Control _ctl; private Control _root; Timer t = new Timer(); #endregion #region animation stuff private float dragDistanceFactor = 50.0f; public float DragDistanceFactor { set { if (value < 1.0f) throw new ArgumentException("DragDistanceFactor must be greater than or equal to 1.0", "value"); dragDistanceFactor = value; } } private float maxVelocity = 9000.0f; public float MaxVelocity { set { if (value < 1.0f) throw new ArgumentException("MaxVelocity must be greater than or equal to 1.0", "value"); maxVelocity = value; } } private float deaccelerationFactor = 0.9000f; public float DeAccelerationFactor { set { if (value <= 0.0f || value >= 1.0f) throw new ArgumentException("DeaccelerationFactor must fall within exclusive range 0.0 < value < 1.0", "value"); deaccelerationFactor = value; } } private float snapBackFactor = 0.2f; public float SnapBackFactor { set { if (value <= 0.0f || value >= 1.0f) throw new ArgumentException("SnapBackFactor must fall within exclusive range 0.0 < value < 1.0", "value"); snapBackFactor = value; } } #endregion public VerticalScroller(Control control, Control root) { t.Interval = 50; t.Enabled = true; t.Tick += new EventHandler(t_Tick); _ctl = control; _ctl.Location = new Point(0, 0); _ctl.MouseDown += new MouseEventHandler(_ctl_MouseDown); _ctl.MouseMove += new MouseEventHandler(_ctl_MouseMove); _ctl.MouseUp += new MouseEventHandler(_ctl_MouseUp); _root = root; } void _ctl_MouseUp(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Left) { velocity = Math.Min(Math.Max(dragDistanceFactor * draggedDistance, -maxVelocity), maxVelocity); draggedDistance = 0; Animate(); } mouseIsDown = false; } void _ctl_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point absolutePoint = GetAbsolute(new Point(e.X, e.Y), _ctl, _root); int delta = absolutePoint.Y - previousPoint.Y; draggedDistance = delta; Scroll(delta); previousPoint = absolutePoint; } } void _ctl_MouseDown(object sender, MouseEventArgs e) { mouseIsDown = true; if (e.Button == MouseButtons.Left) { previousPoint = GetAbsolute(new Point(e.X, e.Y), _ctl, _root); } } void t_Tick(object sender, EventArgs e) { Animate(); } void Animate() { if (!mouseIsDown) { velocity *= deaccelerationFactor; float elapsedTime = t.Interval / 1000.0f; float deltaDistance = elapsedTime * velocity; if (Math.Abs(deltaDistance) >= 1.0f) { Scroll((int)deltaDistance); } if (_ctl.Top != 0) { if (_ctl.Top > 0) { velocity = 0; Scroll(-Math.Max(1, (int)(snapBackFactor * (float)(_ctl.Top)))); } else { if (_ctl.Height > _root.ClientSize.Height) { int bottomPosition = _ctl.Top + _ctl.Height; if (bottomPosition < _root.ClientSize.Height) { velocity = 0; Scroll(Math.Max(1, (int)(snapBackFactor * (float)(_root.ClientSize.Height - bottomPosition)))); } } else { velocity = 0; Scroll(Math.Max(1, -((int)(snapBackFactor * (float)_ctl.Top)))); } } } } } void Scroll(int offset) { if (_ctl != null) _ctl.Top += offset; } private Point GetAbsolute(Point point, Control sourceControl, Control rootControl) { Point tempPoint = new Point(); for (Control iterator = sourceControl; iterator != rootControl; iterator = iterator.Parent) { tempPoint.Offset(iterator.Left, iterator.Top); } tempPoint.Offset(point.X, point.Y); return tempPoint; } } public class HorizontalScroller { #region vars private Point previousPoint = new Point(); private int draggedDistance = 0; private float velocity = 0.0f; private bool mouseIsDown = false; private Control _ctl; private Control _root; Timer t = new Timer(); #endregion #region animation stuff private float dragDistanceFactor = 50.0f; public float DragDistanceFactor { set { if (value < 1.0f) throw new ArgumentException("DragDistanceFactor must be greater than or equal to 1.0", "value"); dragDistanceFactor = value; } } private float maxVelocity = 9000.0f; public float MaxVelocity { set { if (value < 1.0f) throw new ArgumentException("MaxVelocity must be greater than or equal to 1.0", "value"); maxVelocity = value; } } private float deaccelerationFactor = 0.9000f; public float DeAccelerationFactor { set { if (value <= 0.0f || value >= 1.0f) throw new ArgumentException("DeaccelerationFactor must fall within exclusive range 0.0 < value < 1.0", "value"); deaccelerationFactor = value; } } private float snapBackFactor = 0.2f; public float SnapBackFactor { set { if (value <= 0.0f || value >= 1.0f) throw new ArgumentException("SnapBackFactor must fall within exclusive range 0.0 < value < 1.0", "value"); snapBackFactor = value; } } #endregion public HorizontalScroller(Control control, Control root) { t.Interval = 50; t.Enabled = true; t.Tick += new EventHandler(t_Tick); _ctl = control; _ctl.Location = new Point(0, 0); _ctl.MouseDown += new MouseEventHandler(_ctl_MouseDown); _ctl.MouseMove += new MouseEventHandler(_ctl_MouseMove); _ctl.MouseUp += new MouseEventHandler(_ctl_MouseUp); _root = root; } void _ctl_MouseUp(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Left) { velocity = Math.Min(Math.Max(dragDistanceFactor * draggedDistance, -maxVelocity), maxVelocity); draggedDistance = 0; Animate(); } mouseIsDown = false; } void _ctl_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point absolutePoint = GetAbsolute(new Point(e.X, e.Y), _ctl, _root); int delta = absolutePoint.X - previousPoint.X; draggedDistance = delta; Scroll(delta); previousPoint = absolutePoint; } } void _ctl_MouseDown(object sender, MouseEventArgs e) { mouseIsDown = true; if (e.Button == MouseButtons.Left) { previousPoint = GetAbsolute(new Point(e.X, e.Y), _ctl, _root); } } void t_Tick(object sender, EventArgs e) { Animate(); } void Animate() { if (!mouseIsDown) { velocity *= deaccelerationFactor; float elapsedTime = t.Interval / 1000.0f; float deltaDistance = elapsedTime * velocity; if (Math.Abs(deltaDistance) >= 1.0f) { Scroll((int)deltaDistance); } if (_ctl.Left != 0) { if (_ctl.Left > 0) { velocity = 0; Scroll(-Math.Max(1, (int)(snapBackFactor * (float)(_ctl.Left)))); } else { if (_ctl.Width > _root.ClientSize.Width) { int rightPosition = _ctl.Left + _ctl.Width; if (rightPosition < _root.ClientSize.Width) { velocity = 0; Scroll(Math.Max(1, (int)(snapBackFactor * (float)(_root.ClientSize.Width - rightPosition)))); } } else { velocity = 0; Scroll(Math.Max(1, -((int)(snapBackFactor * (float)_ctl.Left)))); } } } } } void Scroll(int offset) { if (_ctl != null) _ctl.Left += offset; } private Point GetAbsolute(Point point, Control sourceControl, Control rootControl) { Point tempPoint = new Point(); for (Control iterator = sourceControl; iterator != rootControl; iterator = iterator.Parent) { tempPoint.Offset(iterator.Left, iterator.Top); } tempPoint.Offset(point.X, point.Y); return tempPoint; } } } } I stipped his code and made a class version of his smooth scroller and modified to make a Horizontal and Vertical scroller
Did you do any updates to his code?
Incoming/outgoing Call Block
Hi, How do I block some specific number incoming/outgoing uisng TAPI. I have tried the following code Code: int Tapi(HINSTANCE hInstance) { LONG lRet; DWORD dwNumDevs; DWORD dwAPIVersion = TAPI_API_HIGH_VERSION; DWORD dwTAPILineDeviceID; const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE; //Line init, Callbackfunc registration if(lineInitialize(&hLineApp,hInstance,(LINECALLBACK)lineCallbackFunc,L"CallDrop1",&dwNumDevs)) { MessageBox (NULL, _T ("initial rice"), _T ("failed"), MB_OK); } lRet = lineSetAppPriority(L"CallDrop1",LINEMEDIAMODE_INTERACTIVEVOICE ,NULL,0, NULL, 1); // get the device ID dwTAPILineDeviceID = GetTSPLineDeviceID(hLineApp, dwNumDevs, TAPI_API_LOW_VERSION, TAPI_API_HIGH_VERSION, CELLTSP_LINENAME_STRING); // error getting the line device ID? if (0xffffffff == dwTAPILineDeviceID) { MessageBox (NULL, _T ("line device ID"), _T ("could not fetch"), MB_OK); return 0; } if(lineOpen(hLineApp, dwTAPILineDeviceID, &hLine, dwAPIVersion, 0, 0, LINECALLPRIVILEGE_OWNER, dwMediaMode, 0)) { MessageBox (NULL, _T ("line open"), _T ("failed"), MB_OK); } return 0; } VOID CALLBACK lineCallbackFunc ( DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3 ) { switch (dwMsg) { case LINE_CALLSTATE://Call case State changes: { switch(dwParam1) { case LINECALLSTATE_OFFERING : { lineDrop((HCALL)hDevice, NULL, 0); }break; case LINECALLSTATE_DISCONNECTED : // // break; default : break; } } break; default: break; } } Here incoming call get disconnected, because of lineDrop() function, but the "Phone-Incoming" window pops up for a few seconds and on nav bar i get miss call notification. I want to remove the "Phone-Incoming" window and miss call notification. How to achieve that ???
[Q] How to read store.vol file Windows phone 7
Hello! I have file store.vol copy from Windows phone device(HTC HD7). I use EDB API to read it. My problem: I could not open store.vol file. ERROR_BAD_FORMAT. How can I open this file. Thanks!!! My code: Code: #include "stdafx.h" #include "Winphone7_Lib.h" #include "clsReadEDB.h" #include <iosfwd> #define EDB extern "C" { #include <windbase_edb.h> } // clsReadEDB IMPLEMENT_DYNAMIC(clsReadEDB, CWnd) clsReadEDB::clsReadEDB() { } void clsReadEDB::readFile(char* path) { CEGUID guid; CEVOLUMEOPTIONS cevo = {0}; cevo.wVersion = 1; CEOIDINFOEX oidInfo = {0}; wchar_t buff[250]; HANDLE hSes, hBD, hBDS; BOOL rez; rez = CeMountDBVolEx(&guid, L"store.vol", &cevo,OPEN_EXISTING); if (rez == FALSE) { } DWORD dw = GetLastError(); hBD = CeFindFirstDatabaseEx(&guid, 0); if (hBD != INVALID_HANDLE_VALUE) { oidInfo.wVersion = CEOIDINFOEX_VERSION; oidInfo.wObjType = OBJTYPE_DATABASE; //creare sesiune hSes = CeCreateSession(&guid); if (hSes == INVALID_HANDLE_VALUE) {/* error */} CEOID oidBD = CeFindNextDatabaseEx(hBD, &guid); while (oidBD != 0) { //obtain database information rez = CeOidGetInfoEx2(&guid, oidBD, &oidInfo); if (rez != TRUE) {/* error */} //open database hBDS = CeOpenDatabaseInSession(hSes, &guid, &oidBD, oidInfo.infDatabase.szDbaseName, NULL, CEDB_AUTOINCREMENT, NULL); if (hBDS == INVALID_HANDLE_VALUE) {/* error */} PCEPROPVAL pInreg = NULL; PBYTE pBuffInreg = NULL;//memory is allocated by function WORD wProp;//number of properties DWORD dwLgInreg;// record lengths //memory is allocatd by function CEOID ceoid = CeReadRecordPropsEx(hBDS, CEDB_ALLOWREALLOC, &wProp, NULL, &(LPBYTE)pBuffInreg, &dwLgInreg, NULL); int k = 0; while(ceoid != 0) { pInreg = (PCEPROPVAL)pBuffInreg; //for each field for (int i = 0; i < wProp; i++) { switch(LOWORD(pInreg->propid)) { case CEVT_LPWSTR: //process string values break; //integers case CEVT_I2: case CEVT_I4: case CEVT_UI2: case CEVT_UI4: case CEVT_BLOB: case CEVT_BOOL: //process integer values break; case CEVT_R8: //process floating point values break; default: //other types break; } OutputDebugString(buff); //next field pInreg++; } LocalFree(pBuffInreg); //next record ceoid = CeReadRecordPropsEx(hBDS, CEDB_ALLOWREALLOC, &wProp, NULL, &(LPBYTE)pBuffInreg, &dwLgInreg, NULL); k++; } CloseHandle(hBDS); //next database oidBD = CeFindNextDatabaseEx(hBD, &guid); } CloseHandle(hBD); CloseHandle(hSes); } CeUnmountDBVol(&guid); } clsReadEDB::~clsReadEDB() { }
GWD loads watchface.xml this way (java source inside)
This is from the GWD file : C:\Program Files (x86)\GearWatchDesigner\plugins\com.samsung.gwd_1.6.2.201810300802.jar This is a Java package. When looking inside with a "Java decompiler" (free download), find the loadXml.class and you'll see the following code. Once we analyze this, I think we can kind of figure out the schema. Code: package com.samsung.gwd; import com.samsung.gwd.gef.models.ActionConfig; import com.samsung.gwd.gef.models.ActionConfigEnum.ACTION_STATE; import com.samsung.gwd.gef.models.Condition; import com.samsung.gwd.gef.models.ModelAnimation; import com.samsung.gwd.gef.models.ModelBackground; import com.samsung.gwd.gef.models.ModelComponent; import com.samsung.gwd.gef.models.ModelDigitalclock; import com.samsung.gwd.gef.models.ModelGroup; import com.samsung.gwd.gef.models.ModelHand; import com.samsung.gwd.gef.models.ModelImage; import com.samsung.gwd.gef.models.ModelIndex; import com.samsung.gwd.gef.models.ModelRoot; import com.samsung.gwd.gef.models.ModelText; import com.samsung.gwd.source.Source; import com.samsung.gwd.ui.dialog.bitmapfont.BitmapFont; import com.samsung.gwd.utils.RM; import com.samsung.gwd.utils.Util; import java.awt.Color; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; import org.xml.sax.SAXException; public class LoadXml { public static final int TIME_ONE_MINUTE = 900; public static final int TIME_ONE_HOUR = 54000; public static final double PLATFORM_HOUR_MINUTE_CORRECTION = 0.005D; Project project; ModelRoot root; String path; Document doc; String projectDir; int width; int height; public LoadXml(String path, String name, Project project) { this.path = path; File file = new File(path + name); this.project = project; this.projectDir = project.getProjectDir(); if (file.isFile()) { DocumentBuilderFactory docBuildFact = DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuild = docBuildFact.newDocumentBuilder(); this.doc = docBuild.parse(file); this.doc.getDocumentElement().normalize(); NodeList watchface = this.doc.getElementsByTagName("watchface"); Node watchfaceNode = watchface.item(0); this.width = Integer.parseInt(((Element)watchfaceNode).getAttribute("width")); this.height = Integer.parseInt(((Element)watchfaceNode).getAttribute("height")); NodeList groupsList = this.doc.getElementsByTagName("groups"); for (int i = 0; i < groupsList.getLength(); i++) { Node groupsNode = groupsList.item(i); processGroups((Element)groupsNode); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { Application.LOGGER.error("Loading XML failed : " + path + name); } } void processGroups(Element groupsElmt) { if (groupsElmt.getAttribute("type").equals("ambient")) { this.project.initLowBitAmbientMode(); this.root = this.project.getAmbientLowRoot(); } else if (groupsElmt.getAttribute("type").equals("ambient-fullcolor")) { this.project.initHighColorAmbientMode(); this.root = this.project.getAmbientHighRoot(); } else if (groupsElmt.getAttribute("type").equals("current")) { this.root = this.project.getModelRoot(); } else { this.root = this.project.getNormalRoot(); } NodeList groupList = groupsElmt.getElementsByTagName("group"); for (int j = 0; j < groupList.getLength(); j++) { Node groupNode = groupList.item(j); processGroup((Element)groupNode); } } void processGroup(Element groupElm) { ModelGroup group = null; ActionConfig actionConf = null; String tmpStr = groupElm.getAttribute("x"); if (!groupElm.getAttribute("name").startsWith("__DEFAULT_GROUP")) { if (!tmpStr.isEmpty()) { group = new ModelGroup(this.root); group.setRect(Integer.parseInt(groupElm.getAttribute("x")), Integer.parseInt(groupElm.getAttribute("y")), Integer.parseInt(groupElm.getAttribute("width")), Integer.parseInt(groupElm.getAttribute("height"))); } else { group = new ModelGroup(this.root); group.setRect(0, 0, this.width, this.height); } } Point groupLoc; Point groupLoc; if (!groupElm.getAttribute("x").isEmpty()) { groupLoc = new Point(Integer.parseInt(groupElm.getAttribute("x")), Integer.parseInt(groupElm.getAttribute("y"))); } else { groupLoc = new Point(0, 0); } NodeList groupChildList = groupElm.getChildNodes(); for (int i = 0; i < groupChildList.getLength(); i++) { Node childNode = groupChildList.item(i); if ((childNode.getNodeType() == 1) && (childNode.getNodeName().equals("action"))) { Element childElm = (Element)childNode; String on_event = childElm.getAttribute("on_event"); if (on_event.equals("tap")) { String type = childElm.getAttribute("type"); if (type.equals("launch")) { NodeList launchList = childElm.getElementsByTagName("launch"); if (launchList.getLength() != 0) { Node launchNode = launchList.item(0); String appid = ((Element)launchNode).getAttribute("app_id"); if (appid.isEmpty()) { appid = ((Element)launchNode).getAttribute("preset"); } if (actionConf != null) { break; } actionConf = new ActionConfig(DeviceSpec.GEAR_S2.getOpenAppTable()); actionConf.setActionState("Open App"); actionConf.setSelectAppId(appid); } } else if (type.equals("image-set-show-next")) { if (actionConf != null) { break; } actionConf = new ActionConfig(DeviceSpec.GEAR_S2.getOpenAppTable()); actionConf.setActionState("Change Image"); } } } } for (int i = 0; i < groupChildList.getLength(); i++) { Node childNode = groupChildList.item(i); if (childNode.getNodeType() == 1) { Element childElmnt = (Element)childNode; if (childNode.getNodeName().equals("part")) { ModelComponent model = processPart(childElmnt, group, actionConf); if (model != null) { model.setLocation(model.getLocation().x + groupLoc.x, model.getLocation().y + groupLoc.y); try { if (actionConf == null) { break; } actionConf.setModel(model); model.setActionConfig(actionConf); model.setButton(true); } catch (Exception e) { e.printStackTrace(); if (group == null) { this.root.removeChild(model); continue; } group.removeChild(model); continue; } } } else if (childNode.getNodeName().equals("condition")) { ModelComponent model = processCondition(childElmnt, group, 0, 0, null, actionConf); if (model != null) { model.setLocation(model.getLocation().x + groupLoc.x, model.getLocation().y + groupLoc.y); try { if (group == null) { this.root.addChild(model); } else { group.addChild(model); } if (actionConf == null) { break; } actionConf.setModel(model); model.setActionConfig(actionConf); model.setButton(true); } catch (Exception e) { e.printStackTrace(); if (group == null) { this.root.removeChild(model); } else { group.removeChild(model); } } } } } } } ModelComponent processPart(Element partElmt, ModelGroup group, ActionConfig actionConf) { Rectangle partRect = null; String tmpStr = partElmt.getAttribute("x"); if (!tmpStr.isEmpty()) { partRect = new Rectangle(Integer.parseInt(tmpStr), Integer.parseInt(partElmt.getAttribute("y")), Integer.parseInt(partElmt.getAttribute("width")), Integer.parseInt(partElmt.getAttribute("height"))); } String type = partElmt.getAttribute("type"); if (type.equals("image")) { return processPartImage(partElmt, group, partRect, actionConf); } if (type.equals("text")) { return processPartText(partElmt, group, partRect); } if (!type.equals("draw")) { Application.LOGGER.error("Not supporeted part type : " + type); } return null; } ModelComponent processPartImage(Element partElmt, ModelGroup group, Rectangle partRect, ActionConfig actionConf) { ModelImage obj = null; boolean isHands = false; boolean isBackground = false; boolean isIndex = false; ModelComponent parent; ModelComponent parent; if (group != null) { parent = group; } else { parent = this.root; } NodeList partAttrList = null; Node partAttrNode = null; Element partAttrElmnt = null; Element metaElmnt = null; partAttrList = partElmt.getElementsByTagName("metadata"); if (partAttrList.getLength() != 0) { for (int i = 0; i < partAttrList.getLength(); i++) { partAttrNode = partAttrList.item(i); metaElmnt = (Element)partAttrNode; String tmpStr = metaElmnt.getAttribute("type"); if (tmpStr.equals("hands")) { isHands = true; } else if (tmpStr.equals("background")) { isBackground = true; } else if (tmpStr.equals("index")) { isIndex = true; } } } else { partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; if ((partAttrElmnt.getAttribute("source").equals("hour0-23.minute")) || (partAttrElmnt.getAttribute("source").equals("minute"))) { isHands = true; } } } partAttrList = partElmt.getElementsByTagName("image-set"); if ((partAttrList.getLength() == 0) || ((actionConf != null) && (actionConf.getActionState() == ActionConfigEnum.ACTION_STATE.CHANGE_IMAGE))) { String baseName = null; if ((actionConf != null) && (actionConf.getActionState() == ActionConfigEnum.ACTION_STATE.CHANGE_IMAGE)) { String projResDir = new String(this.project.getProjectDir() + BuildConfig.PATH_XML); partAttrList = partElmt.getElementsByTagName("image-set"); if (partAttrList.getLength() != 0) { int changeNum = 0; NodeList imageSetChildList = partAttrList.item(0).getChildNodes(); for (int nodeIndex = 0; nodeIndex < imageSetChildList.getLength(); nodeIndex++) { Node imageSetChildNode = imageSetChildList.item(nodeIndex); if (imageSetChildNode.getNodeType() == 1) { if (imageSetChildNode.getNodeName().equals("image")) { Element imageElmnt = (Element)imageSetChildNode; if (nodeIndex == 0) { baseName = imageElmnt.getTextContent(); } else { if ((imageElmnt.getTextContent() == "") || (imageElmnt.getTextContent().compareTo(baseName) == 0)) { actionConf.setChangeImage(null, changeNum, null); } else { String str_des = new String(imageElmnt.getTextContent()); if (System.getProperty("os.name").contains("Windows")) { while (str_des.contains("/")) { str_des = str_des.replace("/", File.separator); } } actionConf.setChangeImage(RM.getImage(projResDir + str_des), changeNum, projResDir + str_des); } changeNum++; } } } } } Rectangle tempRect = new Rectangle(partRect); if (isHands) { obj = new ModelHand(parent, this.path, baseName); } else if (isBackground) { obj = new ModelBackground(parent, this.path, baseName); } else { obj = new ModelImage(parent, this.path, baseName); } obj.setRect(tempRect); } else { partAttrList = partElmt.getElementsByTagName("image"); partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; NodeList partAttrChildList = partAttrNode.getChildNodes(); Rectangle tempRect = new Rectangle(partRect); if (partAttrChildList.getLength() == 1) { if (isHands) { obj = new ModelHand(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } else if (isBackground) { obj = new ModelBackground(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } else if (isIndex) { String tmpStr = metaElmnt.getAttribute("image"); if (!tmpStr.isEmpty()) { obj = new ModelIndex(parent, this.path, tmpStr); obj.setRect(tempRect); ((ModelIndex)obj).setOriginalRect(new Rectangle(Integer.parseInt(metaElmnt.getAttribute("x")), Integer.parseInt(metaElmnt.getAttribute("y")), Integer.parseInt(metaElmnt.getAttribute("width")), Integer.parseInt(metaElmnt.getAttribute("height")))); } else { obj = new ModelIndex(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } tmpStr = metaElmnt.getAttribute("range"); if (tmpStr.isEmpty()) { return null; } ((ModelIndex)obj).setRange(0.0D, Integer.parseInt(tmpStr)); tmpStr = metaElmnt.getAttribute("number"); ((ModelIndex)obj).setNumber(Integer.parseInt(tmpStr)); ((ModelIndex)obj).apply(); ((ModelIndex)obj).setRect(tempRect); } else { obj = new ModelImage(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } } else { Application.LOGGER.error("LoadXml : Implement me - image condition, length=" + partAttrChildList.getLength()); } } if (obj != null) { partAttrList = partElmt.getElementsByTagName("color"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String tmpStr = partAttrElmnt.getAttribute("a"); if (!tmpStr.isEmpty()) { tmpStr = partAttrElmnt.getAttribute("r"); if (!tmpStr.isEmpty()) { obj.setFilterEnable(true); float[] hsl = Color.RGBtoHSB(Integer.parseInt(partAttrElmnt.getAttribute("r")), Integer.parseInt(partAttrElmnt.getAttribute("g")), Integer.parseInt(partAttrElmnt.getAttribute("b")), null); obj.setHue((int)(hsl[0] * 360.0F - 180.0F)); obj.setSaturation((int)(hsl[1] * 200.0F - 100.0F)); obj.setLightness((int)(hsl[2] * 200.0F - 100.0F)); obj.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } else { obj.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } } } partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String source = partAttrElmnt.getAttribute("source"); if (!source.isEmpty()) { if (isHands) { ModelHand hand = (ModelHand)obj; hand.setSource(Source.findById(source)); if (!partElmt.getAttribute("x").isEmpty()) { hand.setPivot(Integer.parseInt(partAttrElmnt.getAttribute("center_x")) + Integer.parseInt(partElmt.getAttribute("x")), Integer.parseInt(partAttrElmnt.getAttribute("center_y")) + Integer.parseInt(partElmt.getAttribute("y"))); hand.setStartAngle(Double.parseDouble(partAttrElmnt.getAttribute("start_angle"))); hand.setEndAngle(Double.parseDouble(partAttrElmnt.getAttribute("end_angle"))); hand.setStartValue(Double.parseDouble(partAttrElmnt.getAttribute("start_value"))); hand.setEndValue(Double.parseDouble(partAttrElmnt.getAttribute("end_value"))); } else { if (group == null) { hand.setPivot(Integer.parseInt(partAttrElmnt.getAttribute("center_x")), Integer.parseInt(partAttrElmnt.getAttribute("center_y"))); } hand.setStartAngle(Double.parseDouble(partAttrElmnt.getAttribute("start_angle"))); hand.setEndAngle(Double.parseDouble(partAttrElmnt.getAttribute("end_angle"))); hand.setStartValue(Double.parseDouble(partAttrElmnt.getAttribute("start_value"))); hand.setEndValue(Double.parseDouble(partAttrElmnt.getAttribute("end_value"))); } if (partAttrElmnt.getAttribute("animation").equals("tick")) { hand.setTensionFrame(Integer.parseInt(partAttrElmnt.getAttribute("tick_frame")) / 2); hand.setTensionAngle(Double.parseDouble(partAttrElmnt.getAttribute("tick_angle"))); hand.setTension((int)(hand.getTensionAngle() * 100.0D / 6.0D)); hand.setTensionEnabled(true); } if (source.equals("hour0-11.minute")) { hand.setSource(Source.findById("hour0-23.minute")); if (hand.getStartAngle() < hand.getEndAngle()) { hand.setEndAngle(hand.getEndAngle() + 360.0D); } else { hand.setEndAngle(hand.getEndAngle() - 360.0D); } } } } else if (!partAttrElmnt.getAttribute("angle").isEmpty()) { if (Util.checkExprTag(partAttrElmnt.getAttribute("angle"))) { obj.setAngle(Util.removeExprTag(partAttrElmnt.getAttribute("angle"))); } else { obj.setAngle(Double.parseDouble(partAttrElmnt.getAttribute("angle"))); } } } } } else { partAttrList = partElmt.getElementsByTagName("image-set"); if (partAttrList.getLength() != 0) { ModelAnimation ani = new ModelAnimation(parent); int frameNum = 0; ani.setRect(partRect); NodeList imageSetChildList = partAttrList.item(0).getChildNodes(); for (int nodeIndex = 0; nodeIndex < imageSetChildList.getLength(); nodeIndex++) { Node imageSetChildNode = imageSetChildList.item(nodeIndex); if (imageSetChildNode.getNodeType() == 1) { if (imageSetChildNode.getNodeName().equals("image")) { Element imageElmnt = (Element)imageSetChildNode; ModelImage frameItem = new ModelImage(ani, this.path, imageElmnt.getTextContent()); frameItem.setRect(0, 0, partRect.width, partRect.height); frameItem.setId("Frame " + (nodeIndex + 1)); frameItem.getCondition().deleteAll(); frameItem.getCondition().addItem(frameNum, frameNum + 1); } frameNum++; } } partAttrList = partElmt.getElementsByTagName("color"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String tmpStr = partAttrElmnt.getAttribute("a"); if (!tmpStr.isEmpty()) { ani.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } } partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrElmnt = (Element)partAttrList.item(0); if (!partAttrElmnt.getAttribute("angle").isEmpty()) { if (Util.checkExprTag(partAttrElmnt.getAttribute("angle"))) { ani.setAngle(Util.removeExprTag(partAttrElmnt.getAttribute("angle"))); } else { ani.setAngle(Double.parseDouble(partAttrElmnt.getAttribute("angle"))); } } } return ani; } } return obj; }
Con't Code: ModelComponent processPartText(Element partElmt, ModelGroup group, Rectangle partRect) { String tmpStr = null; boolean isDigitalclock = false; NodeList partAttrList = null; Node partAttrNode = null; Element partAttrElmnt = null; partAttrList = partElmt.getElementsByTagName("metadata"); if (partAttrList.getLength() != 0) { for (int i = 0; i < partAttrList.getLength(); i++) { partAttrNode = partAttrList.item(i); partAttrElmnt = (Element)partAttrNode; tmpStr = partAttrElmnt.getAttribute("type"); if (tmpStr.equals("digitalclock")) { isDigitalclock = true; } } } Rectangle tempRect = new Rectangle(partRect); if (group != null) { tempRect.x += group.getRect().x; tempRect.y += group.getRect().y; } ModelComponent parent; ModelComponent parent; if (group != null) { parent = group; } else { parent = this.root; } ModelText mText; ModelText mText; if (isDigitalclock) { mText = new ModelDigitalclock(parent); } else { mText = new ModelText(parent); } mText.setRect(partRect); partAttrList = partElmt.getElementsByTagName("style"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; tmpStr = partAttrElmnt.getAttribute("typeface"); if (!tmpStr.isEmpty()) { mText.setFontName(tmpStr); } tmpStr = partAttrElmnt.getAttribute("size"); mText.setFont(mText.getFontName(), Integer.parseInt(tmpStr)); tmpStr = partAttrElmnt.getAttribute("style"); if (!tmpStr.isEmpty()) { if (tmpStr.equals("Bold")) { mText.setFontStyle(1); } mText.setFontStyle(mText.getFontStyle()); } tmpStr = partAttrElmnt.getAttribute("filename"); if (!tmpStr.isEmpty()) { mText.setFontName(tmpStr); mText.setCustomFont(tmpStr, mText.getFontSize()); } } partAttrList = partElmt.getElementsByTagName("color"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; tmpStr = partAttrElmnt.getAttribute("r"); if (!tmpStr.isEmpty()) { mText.setColor(RM.getColor(Integer.parseInt(partAttrElmnt.getAttribute("r")), Integer.parseInt(partAttrElmnt.getAttribute("g")), Integer.parseInt(partAttrElmnt.getAttribute("b")))); mText.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } else { tmpStr = partAttrElmnt.getAttribute("a"); if (!tmpStr.isEmpty()) { mText.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } } } partAttrList = partElmt.getElementsByTagName("icu-skeleton"); int j; Locale[] pcLocales; if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; mText.setText(partAttrElmnt.getTextContent()); String strLocales = partAttrElmnt.getAttribute("locale"); if (!strLocales.isEmpty()) { String[] tokens = strLocales.split(";"); List<Locale> locales = new ArrayList(); String[] arrayOfString1; j = (arrayOfString1 = tokens).length; for (int i = 0; i < j; i++) { String token = arrayOfString1[i]; pcLocales = Locale.getAvailableLocales(); for (int i = 0; i < pcLocales.length; i++) { String str = pcLocales[i].getLanguage() + "_" + pcLocales[i].getCountry(); if (token.equals(str)) { locales.add(pcLocales[i]); break; } } } mText.setLocale(locales); } } partAttrList = partElmt.getElementsByTagName("text"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String strAlign = partAttrElmnt.getAttribute("align"); if (!strAlign.isEmpty()) { if (strAlign.equals("left")) { mText.setAlignment(16384); } else if (strAlign.equals("right")) { mText.setAlignment(131072); } else { mText.setAlignment(16777216); } } String strLocales = partAttrElmnt.getAttribute("locale"); if (!strLocales.isEmpty()) { String[] tokens = strLocales.split(";"); List<Locale> locales = new ArrayList(); int k = (pcLocales = tokens).length; for (j = 0; j < k; j++) { Object token = pcLocales[j]; Locale[] pcLocales = Locale.getAvailableLocales(); for (int i = 0; i < pcLocales.length; i++) { String str = pcLocales[i].getLanguage() + "_" + pcLocales[i].getCountry(); if (((String)token).equals(str)) { locales.add(pcLocales[i]); break; } } } mText.setLocale(locales); } if (partAttrElmnt.getElementsByTagName("format").getLength() != 0) { String front = null;String source = null;String back = null; NodeList textChildList = partAttrElmnt.getChildNodes(); for (int i = 0; i < 2; i++) { Node textChildNode = textChildList.item(0); if (textChildNode.getNodeType() == 1) { Element textChildElmnt = (Element)textChildNode; if (textChildElmnt.getTagName().equals("format")) { break; } textChildList = textChildElmnt.getChildNodes(); } } boolean isFormatProcessed = false; for (int i = 0; i < textChildList.getLength(); i++) { Node textChildNode = textChildList.item(i); if (textChildNode.getNodeType() == 1) { Element textChildElmnt = (Element)textChildNode; if (textChildElmnt.getTagName().equals("format")) { source = textChildElmnt.getAttribute("source"); isFormatProcessed = true; } } else if (textChildNode.getNodeType() == 3) { Text textChildElmnt = (Text)textChildNode; tmpStr = textChildElmnt.getTextContent(); if (!tmpStr.isEmpty()) { if (!isFormatProcessed) { front = tmpStr; } else { back = tmpStr; } } } } Application.LOGGER.info(String.format("contents = %s, %s, %s", new Object[] { front, source, back })); mText.setSource(Source.findById(source)); mText.setFormat(front, back); } else { tmpStr = partAttrElmnt.getTextContent(); Application.LOGGER.info("contents = " + tmpStr); if ((!isDigitalclock) && (!tmpStr.isEmpty())) { mText.setText(tmpStr); } } } partAttrList = partElmt.getElementsByTagName("font"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; tmpStr = partAttrElmnt.getAttribute("filename"); if (!tmpStr.isEmpty()) { mText.setCustomFont(partAttrElmnt.getAttribute("filename"), Integer.parseInt(partAttrElmnt.getAttribute("size"))); } tmpStr = partAttrElmnt.getAttribute("family"); if (!tmpStr.isEmpty()) { NodeList bitmapFontsList = this.doc.getElementsByTagName("bitmap-fonts"); if (bitmapFontsList.getLength() != 0) { Node bitmapFontsNode = bitmapFontsList.item(0); NodeList bitmapFontList = bitmapFontsNode.getChildNodes(); for (int item = 0; item < bitmapFontList.getLength(); item++) { Node bitmapFontNode = bitmapFontList.item(item); if (bitmapFontNode.getNodeType() == 1) { Element fontElmt = (Element)bitmapFontNode; String fontName = fontElmt.getAttribute("name"); if (fontName.equals(tmpStr)) { processBitmapFonts((Element)bitmapFontNode, mText); break; } } } } } tmpStr = partAttrElmnt.getAttribute("slant"); if ((!tmpStr.isEmpty()) && (tmpStr.equals("italic"))) { mText.addFontStyle(2); } tmpStr = partAttrElmnt.getAttribute("weight"); if ((!tmpStr.isEmpty()) && (tmpStr.equals("bold"))) { mText.addFontStyle(1); } } partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String source = partAttrElmnt.getAttribute("source"); if (!source.isEmpty()) { mText.setSource(Source.findById(source)); } else if (!partAttrElmnt.getAttribute("angle").isEmpty()) { if (Util.checkExprTag(partAttrElmnt.getAttribute("angle"))) { mText.setAngle(Util.removeExprTag(partAttrElmnt.getAttribute("angle"))); } else { mText.setAngle(Double.parseDouble(partAttrElmnt.getAttribute("angle"))); } } } partAttrList = partElmt.getElementsByTagName("underline"); if (partAttrList.getLength() != 0) { mText.addFontStyle(4); } partAttrList = partElmt.getElementsByTagName("strike-through"); if (partAttrList.getLength() != 0) { mText.addFontStyle(8); } mText.setFontStyle(mText.getFontStyle()); return mText; } ModelComponent processCondition(Element conditionElmt, ModelGroup group, int start, int end, ModelComponent _obj, ActionConfig actionConf) { ModelComponent conditionObj = _obj; int depth = 0; int startValue = 0; String source = conditionElmt.getAttribute("source"); if (source.equals("battery.percent")) { NodeList conditionChildList = conditionElmt.getChildNodes(); for (int i = 0; i < conditionChildList.getLength(); i++) { Node conditionChildNode = conditionChildList.item(i); if (conditionChildNode.getNodeType() == 1) { Element conditionChildElmnt = (Element)conditionChildNode; if (conditionChildNode.getNodeName().equals("compare")) { String compareValue = conditionChildElmnt.getAttribute("lt"); if (compareValue.isEmpty()) { compareValue = conditionChildElmnt.getAttribute("le"); } int value = Integer.parseInt(compareValue); ModelComponent obj = processCompareBattery(conditionChildElmnt, group, start + startValue, value, conditionObj, actionConf); if ((obj != null) && (conditionObj == null)) { conditionObj = obj; } else { startValue = value; } } else { conditionChildNode.getNodeName().equals("default"); } } } } else if (source.equals("pedometer.stepPercent")) { NodeList conditionChildList = conditionElmt.getChildNodes(); for (int i = 0; i < conditionChildList.getLength(); i++) { Node conditionChildNode = conditionChildList.item(i); if (conditionChildNode.getNodeType() == 1) { Element conditionChildElmnt = (Element)conditionChildNode; if (conditionChildNode.getNodeName().equals("compare")) { String compareValue = conditionChildElmnt.getAttribute("lt"); if (compareValue.isEmpty()) { compareValue = conditionChildElmnt.getAttribute("le"); } if (!compareValue.isEmpty()) { int value = Integer.parseInt(compareValue); ModelComponent obj = processComparePedometer(conditionChildElmnt, group, start + startValue, value, conditionObj, actionConf); if ((obj != null) && (conditionObj == null)) { conditionObj = obj; } else { startValue = value; } } } else { conditionChildNode.getNodeName().equals("default"); } } } } else { if (source.equals("hour0-23.minute")) { depth = 1; } else if (source.equals("second.millisecond")) { depth = 2; startValue = start; } NodeList conditionChildList = conditionElmt.getChildNodes(); for (int i = 0; i < conditionChildList.getLength(); i++) { Node conditionChildNode = conditionChildList.item(i); if (conditionChildNode.getNodeType() == 1) { Element conditionChildElmnt = (Element)conditionChildNode; if (conditionChildNode.getNodeName().equals("compare")) { String compareValue = conditionChildElmnt.getAttribute("lt"); if (!compareValue.isEmpty()) { if (depth == 1) { int value = (int)Math.round((Double.parseDouble(compareValue) + 0.005D) * 54000.0D); if (value % 900 != 0) { value = (int)Math.round(Double.parseDouble(compareValue) * 54000.0D); } ModelComponent obj = processCompareTimeline(conditionChildElmnt, group, start + startValue, value, conditionObj, actionConf); if ((obj != null) && (conditionObj == null)) { conditionObj = obj; } else { startValue = value; } } else { int value = (int)Math.round(Double.parseDouble(compareValue) * 15.0D) + start; ModelComponent obj = processCompareTimeline(conditionChildElmnt, group, startValue, value, conditionObj, actionConf); if ((obj != null) && (conditionObj == null)) { conditionObj = obj; } else { startValue = value; } } } } else if ((conditionChildNode.getNodeName().equals("default")) && (depth == 2)) { ModelComponent obj = processCompareTimeline(conditionChildElmnt, group, startValue, end, conditionObj, actionConf); if ((obj != null) && (conditionObj == null)) { conditionObj = obj; } else { startValue = end; } } } } } return conditionObj; } ModelComponent processCompareTimeline(Element compareElmt, ModelGroup group, int start, int end, ModelComponent _obj, ActionConfig actionConf) { ModelComponent conditionObj = _obj; int startValue = start; int endValue = end; NodeList compareChildList = compareElmt.getChildNodes(); if (compareChildList.getLength() == 0) { return null; } for (int i = 0; i < compareChildList.getLength(); i++) { Node compareChildNode = compareChildList.item(i); if (compareChildNode.getNodeType() == 1) { Element compareChildElmnt = (Element)compareChildNode; if (compareChildNode.getNodeName().equals("part")) { ModelComponent obj = processPart(compareChildElmnt, group, actionConf); if (obj != null) { endValue = end; if (_obj == null) { conditionObj = obj; conditionObj.getCondition().deleteAll(); conditionObj.getCondition().addItem(startValue, endValue); } else { conditionObj.getCondition().addItem(startValue, endValue); } } else { startValue = end; } return obj; } if (compareChildNode.getNodeName().equals("condition")) { ModelComponent obj = processCondition(compareChildElmnt, group, endValue - 900, endValue, conditionObj, actionConf); return obj; } } } return null; } ModelComponent processCompareBattery(Element compareElmt, ModelGroup group, int start, int end, ModelComponent _obj, ActionConfig actionConf) { ModelComponent conditionObj = _obj; int startValue = start; int endValue = end; NodeList compareChildList = compareElmt.getChildNodes(); if (compareChildList.getLength() == 0) { return null; } for (int i = 0; i < compareChildList.getLength(); i++) { Node compareChildNode = compareChildList.item(i); if (compareChildNode.getNodeType() == 1) { Element compareChildElmnt = (Element)compareChildNode; if (compareChildNode.getNodeName().equals("part")) { ModelComponent obj = processPart(compareChildElmnt, group, actionConf); if (obj != null) { endValue = end; if (conditionObj == null) { conditionObj = obj; conditionObj.getCondition().setSource("battery"); conditionObj.getCondition().deleteAll(); conditionObj.getCondition().addItem(startValue, endValue); } else { conditionObj.getCondition().addItem(startValue, endValue); } } else { startValue = end; } return conditionObj; } } } return null; } void processBitmapFonts(Element bitmapElmt, ModelText txt) { NodeList bitmapChildList = bitmapElmt.getChildNodes(); if (bitmapChildList.getLength() == 0) { return; } txt.loadBitmapFont(bitmapElmt.getAttribute("name")); for (int item = 0; item < bitmapChildList.getLength(); item++) { Node bitmapChildNode = bitmapChildList.item(item); if (bitmapChildNode.getNodeType() == 1) { Element bitmapChildElmnt = (Element)bitmapChildNode; if (bitmapChildNode.getNodeName().equals("character")) { String name = bitmapChildElmnt.getAttribute("name"); txt.getBitmapFont().setCharacter(name, RM.getImage(this.projectDir + BuildConfig.PATH_CUSTOM_FONT + name + '/' + bitmapChildElmnt.getAttribute("filepath"))); } } } } ModelComponent processComparePedometer(Element compareElmt, ModelGroup group, int start, int end, ModelComponent _obj, ActionConfig actionConf) { ModelComponent conditionObj = _obj; int startValue = start; int endValue = end; NodeList compareChildList = compareElmt.getChildNodes(); if (compareChildList.getLength() == 0) { return null; } for (int i = 0; i < compareChildList.getLength(); i++) { Node compareChildNode = compareChildList.item(i); if (compareChildNode.getNodeType() == 1) { Element compareChildElmnt = (Element)compareChildNode; if (compareChildNode.getNodeName().equals("part")) { ModelComponent obj = processPart(compareChildElmnt, group, actionConf); if (obj != null) { endValue = end; if (conditionObj == null) { conditionObj = obj; conditionObj.getCondition().setSource("workout"); conditionObj.getCondition().deleteAll(); conditionObj.getCondition().addItem(startValue, endValue); } else { conditionObj.getCondition().addItem(startValue, endValue); } } else { startValue = end; } return conditionObj; } } } return null; } public int getWidth() { return this.width; } public int getHeight() { return this.height; } }
Why such complicated? just download the gwd file and convert to tpk file to upload to your smartwatch. I can teach you how to do if you interest to know it. Ping me at [email protected] Zeuserx said: This is from the GWD file : C:\Program Files (x86)\GearWatchDesigner\plugins\com.samsung.gwd_1.6.2.201810300802.jar This is a Java package. When looking inside with a "Java decompiler" (free download), find the loadXml.class and you'll see the following code. Once we analyze this, I think we can kind of figure out the schema. Code: package com.samsung.gwd; import com.samsung.gwd.gef.models.ActionConfig; import com.samsung.gwd.gef.models.ActionConfigEnum.ACTION_STATE; import com.samsung.gwd.gef.models.Condition; import com.samsung.gwd.gef.models.ModelAnimation; import com.samsung.gwd.gef.models.ModelBackground; import com.samsung.gwd.gef.models.ModelComponent; import com.samsung.gwd.gef.models.ModelDigitalclock; import com.samsung.gwd.gef.models.ModelGroup; import com.samsung.gwd.gef.models.ModelHand; import com.samsung.gwd.gef.models.ModelImage; import com.samsung.gwd.gef.models.ModelIndex; import com.samsung.gwd.gef.models.ModelRoot; import com.samsung.gwd.gef.models.ModelText; import com.samsung.gwd.source.Source; import com.samsung.gwd.ui.dialog.bitmapfont.BitmapFont; import com.samsung.gwd.utils.RM; import com.samsung.gwd.utils.Util; import java.awt.Color; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; import org.xml.sax.SAXException; public class LoadXml { public static final int TIME_ONE_MINUTE = 900; public static final int TIME_ONE_HOUR = 54000; public static final double PLATFORM_HOUR_MINUTE_CORRECTION = 0.005D; Project project; ModelRoot root; String path; Document doc; String projectDir; int width; int height; public LoadXml(String path, String name, Project project) { this.path = path; File file = new File(path + name); this.project = project; this.projectDir = project.getProjectDir(); if (file.isFile()) { DocumentBuilderFactory docBuildFact = DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuild = docBuildFact.newDocumentBuilder(); this.doc = docBuild.parse(file); this.doc.getDocumentElement().normalize(); NodeList watchface = this.doc.getElementsByTagName("watchface"); Node watchfaceNode = watchface.item(0); this.width = Integer.parseInt(((Element)watchfaceNode).getAttribute("width")); this.height = Integer.parseInt(((Element)watchfaceNode).getAttribute("height")); NodeList groupsList = this.doc.getElementsByTagName("groups"); for (int i = 0; i < groupsList.getLength(); i++) { Node groupsNode = groupsList.item(i); processGroups((Element)groupsNode); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { Application.LOGGER.error("Loading XML failed : " + path + name); } } void processGroups(Element groupsElmt) { if (groupsElmt.getAttribute("type").equals("ambient")) { this.project.initLowBitAmbientMode(); this.root = this.project.getAmbientLowRoot(); } else if (groupsElmt.getAttribute("type").equals("ambient-fullcolor")) { this.project.initHighColorAmbientMode(); this.root = this.project.getAmbientHighRoot(); } else if (groupsElmt.getAttribute("type").equals("current")) { this.root = this.project.getModelRoot(); } else { this.root = this.project.getNormalRoot(); } NodeList groupList = groupsElmt.getElementsByTagName("group"); for (int j = 0; j < groupList.getLength(); j++) { Node groupNode = groupList.item(j); processGroup((Element)groupNode); } } void processGroup(Element groupElm) { ModelGroup group = null; ActionConfig actionConf = null; String tmpStr = groupElm.getAttribute("x"); if (!groupElm.getAttribute("name").startsWith("__DEFAULT_GROUP")) { if (!tmpStr.isEmpty()) { group = new ModelGroup(this.root); group.setRect(Integer.parseInt(groupElm.getAttribute("x")), Integer.parseInt(groupElm.getAttribute("y")), Integer.parseInt(groupElm.getAttribute("width")), Integer.parseInt(groupElm.getAttribute("height"))); } else { group = new ModelGroup(this.root); group.setRect(0, 0, this.width, this.height); } } Point groupLoc; Point groupLoc; if (!groupElm.getAttribute("x").isEmpty()) { groupLoc = new Point(Integer.parseInt(groupElm.getAttribute("x")), Integer.parseInt(groupElm.getAttribute("y"))); } else { groupLoc = new Point(0, 0); } NodeList groupChildList = groupElm.getChildNodes(); for (int i = 0; i < groupChildList.getLength(); i++) { Node childNode = groupChildList.item(i); if ((childNode.getNodeType() == 1) && (childNode.getNodeName().equals("action"))) { Element childElm = (Element)childNode; String on_event = childElm.getAttribute("on_event"); if (on_event.equals("tap")) { String type = childElm.getAttribute("type"); if (type.equals("launch")) { NodeList launchList = childElm.getElementsByTagName("launch"); if (launchList.getLength() != 0) { Node launchNode = launchList.item(0); String appid = ((Element)launchNode).getAttribute("app_id"); if (appid.isEmpty()) { appid = ((Element)launchNode).getAttribute("preset"); } if (actionConf != null) { break; } actionConf = new ActionConfig(DeviceSpec.GEAR_S2.getOpenAppTable()); actionConf.setActionState("Open App"); actionConf.setSelectAppId(appid); } } else if (type.equals("image-set-show-next")) { if (actionConf != null) { break; } actionConf = new ActionConfig(DeviceSpec.GEAR_S2.getOpenAppTable()); actionConf.setActionState("Change Image"); } } } } for (int i = 0; i < groupChildList.getLength(); i++) { Node childNode = groupChildList.item(i); if (childNode.getNodeType() == 1) { Element childElmnt = (Element)childNode; if (childNode.getNodeName().equals("part")) { ModelComponent model = processPart(childElmnt, group, actionConf); if (model != null) { model.setLocation(model.getLocation().x + groupLoc.x, model.getLocation().y + groupLoc.y); try { if (actionConf == null) { break; } actionConf.setModel(model); model.setActionConfig(actionConf); model.setButton(true); } catch (Exception e) { e.printStackTrace(); if (group == null) { this.root.removeChild(model); continue; } group.removeChild(model); continue; } } } else if (childNode.getNodeName().equals("condition")) { ModelComponent model = processCondition(childElmnt, group, 0, 0, null, actionConf); if (model != null) { model.setLocation(model.getLocation().x + groupLoc.x, model.getLocation().y + groupLoc.y); try { if (group == null) { this.root.addChild(model); } else { group.addChild(model); } if (actionConf == null) { break; } actionConf.setModel(model); model.setActionConfig(actionConf); model.setButton(true); } catch (Exception e) { e.printStackTrace(); if (group == null) { this.root.removeChild(model); } else { group.removeChild(model); } } } } } } } ModelComponent processPart(Element partElmt, ModelGroup group, ActionConfig actionConf) { Rectangle partRect = null; String tmpStr = partElmt.getAttribute("x"); if (!tmpStr.isEmpty()) { partRect = new Rectangle(Integer.parseInt(tmpStr), Integer.parseInt(partElmt.getAttribute("y")), Integer.parseInt(partElmt.getAttribute("width")), Integer.parseInt(partElmt.getAttribute("height"))); } String type = partElmt.getAttribute("type"); if (type.equals("image")) { return processPartImage(partElmt, group, partRect, actionConf); } if (type.equals("text")) { return processPartText(partElmt, group, partRect); } if (!type.equals("draw")) { Application.LOGGER.error("Not supporeted part type : " + type); } return null; } ModelComponent processPartImage(Element partElmt, ModelGroup group, Rectangle partRect, ActionConfig actionConf) { ModelImage obj = null; boolean isHands = false; boolean isBackground = false; boolean isIndex = false; ModelComponent parent; ModelComponent parent; if (group != null) { parent = group; } else { parent = this.root; } NodeList partAttrList = null; Node partAttrNode = null; Element partAttrElmnt = null; Element metaElmnt = null; partAttrList = partElmt.getElementsByTagName("metadata"); if (partAttrList.getLength() != 0) { for (int i = 0; i < partAttrList.getLength(); i++) { partAttrNode = partAttrList.item(i); metaElmnt = (Element)partAttrNode; String tmpStr = metaElmnt.getAttribute("type"); if (tmpStr.equals("hands")) { isHands = true; } else if (tmpStr.equals("background")) { isBackground = true; } else if (tmpStr.equals("index")) { isIndex = true; } } } else { partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; if ((partAttrElmnt.getAttribute("source").equals("hour0-23.minute")) || (partAttrElmnt.getAttribute("source").equals("minute"))) { isHands = true; } } } partAttrList = partElmt.getElementsByTagName("image-set"); if ((partAttrList.getLength() == 0) || ((actionConf != null) && (actionConf.getActionState() == ActionConfigEnum.ACTION_STATE.CHANGE_IMAGE))) { String baseName = null; if ((actionConf != null) && (actionConf.getActionState() == ActionConfigEnum.ACTION_STATE.CHANGE_IMAGE)) { String projResDir = new String(this.project.getProjectDir() + BuildConfig.PATH_XML); partAttrList = partElmt.getElementsByTagName("image-set"); if (partAttrList.getLength() != 0) { int changeNum = 0; NodeList imageSetChildList = partAttrList.item(0).getChildNodes(); for (int nodeIndex = 0; nodeIndex < imageSetChildList.getLength(); nodeIndex++) { Node imageSetChildNode = imageSetChildList.item(nodeIndex); if (imageSetChildNode.getNodeType() == 1) { if (imageSetChildNode.getNodeName().equals("image")) { Element imageElmnt = (Element)imageSetChildNode; if (nodeIndex == 0) { baseName = imageElmnt.getTextContent(); } else { if ((imageElmnt.getTextContent() == "") || (imageElmnt.getTextContent().compareTo(baseName) == 0)) { actionConf.setChangeImage(null, changeNum, null); } else { String str_des = new String(imageElmnt.getTextContent()); if (System.getProperty("os.name").contains("Windows")) { while (str_des.contains("/")) { str_des = str_des.replace("/", File.separator); } } actionConf.setChangeImage(RM.getImage(projResDir + str_des), changeNum, projResDir + str_des); } changeNum++; } } } } } Rectangle tempRect = new Rectangle(partRect); if (isHands) { obj = new ModelHand(parent, this.path, baseName); } else if (isBackground) { obj = new ModelBackground(parent, this.path, baseName); } else { obj = new ModelImage(parent, this.path, baseName); } obj.setRect(tempRect); } else { partAttrList = partElmt.getElementsByTagName("image"); partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; NodeList partAttrChildList = partAttrNode.getChildNodes(); Rectangle tempRect = new Rectangle(partRect); if (partAttrChildList.getLength() == 1) { if (isHands) { obj = new ModelHand(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } else if (isBackground) { obj = new ModelBackground(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } else if (isIndex) { String tmpStr = metaElmnt.getAttribute("image"); if (!tmpStr.isEmpty()) { obj = new ModelIndex(parent, this.path, tmpStr); obj.setRect(tempRect); ((ModelIndex)obj).setOriginalRect(new Rectangle(Integer.parseInt(metaElmnt.getAttribute("x")), Integer.parseInt(metaElmnt.getAttribute("y")), Integer.parseInt(metaElmnt.getAttribute("width")), Integer.parseInt(metaElmnt.getAttribute("height")))); } else { obj = new ModelIndex(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } tmpStr = metaElmnt.getAttribute("range"); if (tmpStr.isEmpty()) { return null; } ((ModelIndex)obj).setRange(0.0D, Integer.parseInt(tmpStr)); tmpStr = metaElmnt.getAttribute("number"); ((ModelIndex)obj).setNumber(Integer.parseInt(tmpStr)); ((ModelIndex)obj).apply(); ((ModelIndex)obj).setRect(tempRect); } else { obj = new ModelImage(parent, this.path, partAttrElmnt.getTextContent()); obj.setRect(tempRect); } } else { Application.LOGGER.error("LoadXml : Implement me - image condition, length=" + partAttrChildList.getLength()); } } if (obj != null) { partAttrList = partElmt.getElementsByTagName("color"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String tmpStr = partAttrElmnt.getAttribute("a"); if (!tmpStr.isEmpty()) { tmpStr = partAttrElmnt.getAttribute("r"); if (!tmpStr.isEmpty()) { obj.setFilterEnable(true); float[] hsl = Color.RGBtoHSB(Integer.parseInt(partAttrElmnt.getAttribute("r")), Integer.parseInt(partAttrElmnt.getAttribute("g")), Integer.parseInt(partAttrElmnt.getAttribute("b")), null); obj.setHue((int)(hsl[0] * 360.0F - 180.0F)); obj.setSaturation((int)(hsl[1] * 200.0F - 100.0F)); obj.setLightness((int)(hsl[2] * 200.0F - 100.0F)); obj.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } else { obj.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } } } partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String source = partAttrElmnt.getAttribute("source"); if (!source.isEmpty()) { if (isHands) { ModelHand hand = (ModelHand)obj; hand.setSource(Source.findById(source)); if (!partElmt.getAttribute("x").isEmpty()) { hand.setPivot(Integer.parseInt(partAttrElmnt.getAttribute("center_x")) + Integer.parseInt(partElmt.getAttribute("x")), Integer.parseInt(partAttrElmnt.getAttribute("center_y")) + Integer.parseInt(partElmt.getAttribute("y"))); hand.setStartAngle(Double.parseDouble(partAttrElmnt.getAttribute("start_angle"))); hand.setEndAngle(Double.parseDouble(partAttrElmnt.getAttribute("end_angle"))); hand.setStartValue(Double.parseDouble(partAttrElmnt.getAttribute("start_value"))); hand.setEndValue(Double.parseDouble(partAttrElmnt.getAttribute("end_value"))); } else { if (group == null) { hand.setPivot(Integer.parseInt(partAttrElmnt.getAttribute("center_x")), Integer.parseInt(partAttrElmnt.getAttribute("center_y"))); } hand.setStartAngle(Double.parseDouble(partAttrElmnt.getAttribute("start_angle"))); hand.setEndAngle(Double.parseDouble(partAttrElmnt.getAttribute("end_angle"))); hand.setStartValue(Double.parseDouble(partAttrElmnt.getAttribute("start_value"))); hand.setEndValue(Double.parseDouble(partAttrElmnt.getAttribute("end_value"))); } if (partAttrElmnt.getAttribute("animation").equals("tick")) { hand.setTensionFrame(Integer.parseInt(partAttrElmnt.getAttribute("tick_frame")) / 2); hand.setTensionAngle(Double.parseDouble(partAttrElmnt.getAttribute("tick_angle"))); hand.setTension((int)(hand.getTensionAngle() * 100.0D / 6.0D)); hand.setTensionEnabled(true); } if (source.equals("hour0-11.minute")) { hand.setSource(Source.findById("hour0-23.minute")); if (hand.getStartAngle() < hand.getEndAngle()) { hand.setEndAngle(hand.getEndAngle() + 360.0D); } else { hand.setEndAngle(hand.getEndAngle() - 360.0D); } } } } else if (!partAttrElmnt.getAttribute("angle").isEmpty()) { if (Util.checkExprTag(partAttrElmnt.getAttribute("angle"))) { obj.setAngle(Util.removeExprTag(partAttrElmnt.getAttribute("angle"))); } else { obj.setAngle(Double.parseDouble(partAttrElmnt.getAttribute("angle"))); } } } } } else { partAttrList = partElmt.getElementsByTagName("image-set"); if (partAttrList.getLength() != 0) { ModelAnimation ani = new ModelAnimation(parent); int frameNum = 0; ani.setRect(partRect); NodeList imageSetChildList = partAttrList.item(0).getChildNodes(); for (int nodeIndex = 0; nodeIndex < imageSetChildList.getLength(); nodeIndex++) { Node imageSetChildNode = imageSetChildList.item(nodeIndex); if (imageSetChildNode.getNodeType() == 1) { if (imageSetChildNode.getNodeName().equals("image")) { Element imageElmnt = (Element)imageSetChildNode; ModelImage frameItem = new ModelImage(ani, this.path, imageElmnt.getTextContent()); frameItem.setRect(0, 0, partRect.width, partRect.height); frameItem.setId("Frame " + (nodeIndex + 1)); frameItem.getCondition().deleteAll(); frameItem.getCondition().addItem(frameNum, frameNum + 1); } frameNum++; } } partAttrList = partElmt.getElementsByTagName("color"); if (partAttrList.getLength() != 0) { partAttrNode = partAttrList.item(0); partAttrElmnt = (Element)partAttrNode; String tmpStr = partAttrElmnt.getAttribute("a"); if (!tmpStr.isEmpty()) { ani.setAlpha(Integer.parseInt(partAttrElmnt.getAttribute("a"))); } } partAttrList = partElmt.getElementsByTagName("rotation"); if (partAttrList.getLength() != 0) { partAttrElmnt = (Element)partAttrList.item(0); if (!partAttrElmnt.getAttribute("angle").isEmpty()) { if (Util.checkExprTag(partAttrElmnt.getAttribute("angle"))) { ani.setAngle(Util.removeExprTag(partAttrElmnt.getAttribute("angle"))); } else { ani.setAngle(Double.parseDouble(partAttrElmnt.getAttribute("angle"))); } } } return ani; } } return obj; } Click to expand... Click to collapse