# HG changeset patch # User Xeli # Date 1322351640 -3600 # Node ID a49d01b9618586737be5e8a9db5aefa7b5c60055 # Parent fd151457fae69142f206e6337ff3cbdbca96beaa android: cleaned up the code a bit and removed a bug with the parsing of the xml diff -r fd151457fae6 -r a49d01b96185 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java Sun Nov 27 00:53:08 2011 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java Sun Nov 27 00:54:00 2011 +0100 @@ -163,8 +163,9 @@ try { input.close(); } catch (IOException e) {} - }//end if contentType == "zip" - + }else{//end if contentType == "zip" + return EXIT_URLFAIL; + } if(conn != null) conn.disconnect(); if(checkMD5(digester, pack))return EXIT_SUCCESS; @@ -195,20 +196,20 @@ byte[] buffer = new byte[1024];//size is large enough to hold the entire hash BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); int bytesRead = bis.read(buffer); + String hash = null; if(bytesRead > -1){ - String hash = new String(buffer, 0, bytesRead); - StringBuffer sb = new StringBuffer(); - Integer tmp = 0; - for(int i = 0; i < messageDigest.length; i++){ - tmp = 0xFF & messageDigest[i]; - if(tmp < 0xF) sb.append('0'); - sb.append(Integer.toHexString(tmp)); - } - sb.append('\n');//add newline to become identical with the hash file + hash = new String(buffer, 0, bytesRead); + } + StringBuffer sb = new StringBuffer(); + Integer tmp = 0; + for(int i = 0; i < messageDigest.length; i++){ + tmp = 0xFF & messageDigest[i]; + if(tmp < 0xF) sb.append('0'); + sb.append(Integer.toHexString(tmp)); + } + sb.append('\n');//add newline to become identical with the hash file - return hash.equals(sb.toString()); - } - return false; + return hash.equals(sb.toString()); } catch (IOException e) { e.printStackTrace(); return true; diff -r fd151457fae6 -r a49d01b96185 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java Sun Nov 27 00:53:08 2011 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java Sun Nov 27 00:54:00 2011 +0100 @@ -79,19 +79,27 @@ }); } } - eventType = xmlPuller.nextTag(); + eventType = getEventType(xmlPuller); } } catch (XmlPullParserException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } + } + - + /** + * Skips whitespaces.. + */ + private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{ + int eventType = xmlPuller.next(); + while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){ + eventType = xmlPuller.next(); + } + return eventType; } public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { diff -r fd151457fae6 -r a49d01b96185 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java Sun Nov 27 00:53:08 2011 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java Sun Nov 27 00:54:00 2011 +0100 @@ -205,8 +205,6 @@ case DownloadAsyncTask.EXIT_MD5: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; case DownloadAsyncTask.EXIT_URLFAIL: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; case DownloadAsyncTask.EXIT_CANCELLED: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break; - - } stopForeground(true);