/config/src/com/google/marvin/config/InstallerActivity.java
Java | 99 lines | 69 code | 19 blank | 11 comment | 1 complexity | 2171dd3607f776f8186cf5f5c272573c MD5 | raw file
1package com.google.marvin.config; 2 3import org.w3c.dom.Document; 4import org.w3c.dom.NamedNodeMap; 5import org.w3c.dom.NodeList; 6import org.xml.sax.SAXException; 7 8import java.io.IOException; 9import java.io.InputStream; 10import java.net.URL; 11import java.net.URLConnection; 12import java.util.ArrayList; 13 14import javax.xml.parsers.DocumentBuilder; 15import javax.xml.parsers.DocumentBuilderFactory; 16import javax.xml.parsers.FactoryConfigurationError; 17import javax.xml.parsers.ParserConfigurationException; 18 19import android.app.Activity; 20import android.app.ProgressDialog; 21import android.os.Bundle; 22 23/** 24 * InstallerActivity that displays the list of installable apps from the 25 * Eyes-Free project. 26 * 27 * @author clchen@google.com (Charles L. Chen) 28 */ 29public class InstallerActivity extends Activity { 30 31 private InstallerActivity self; 32 33 private AppListView appList; 34 private ProgressDialog loadingDialog = null; 35 36 /** Called when the activity is first created. */ 37 @Override 38 public void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 self = this; 41 42 appList = new AppListView(this); 43 44 setContentView(appList); 45 getAppsList(); 46 } 47 48 private void getAppsList() { 49 loadingDialog = ProgressDialog.show(self, "Loading", "Please wait.", true); 50 51 class appListLoader implements Runnable { 52 public void run() { 53 try { 54 URLConnection cn; 55 URL url = new URL("http://eyes-free.googlecode.com/svn/trunk/config/assets/applist.xml"); 56 cn = url.openConnection(); 57 cn.connect(); 58 InputStream stream = cn.getInputStream(); 59 DocumentBuilder docBuild = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 60 Document appListDoc = docBuild.parse(stream); 61 NodeList appNodes = appListDoc.getElementsByTagName("app"); 62 63 ArrayList<AppDesc> appDescs = new ArrayList<AppDesc>(); 64 for (int i = 0; i < appNodes.getLength(); i++) { 65 NamedNodeMap attribs = appNodes.item(i).getAttributes(); 66 String packageName = attribs.getNamedItem("packageName").getNodeValue(); 67 String title = attribs.getNamedItem("title").getNodeValue(); 68 String description = attribs.getNamedItem("desc").getNodeValue(); 69 appDescs.add(new AppDesc(packageName, title, description)); 70 } 71 72 appList.updateApps(appDescs); 73 appList.postInvalidate(); 74 } catch (IOException e) { 75 // TODO Auto-generated catch block 76 e.printStackTrace(); 77 } catch (SAXException e) { 78 // TODO Auto-generated catch block 79 e.printStackTrace(); 80 } catch (ParserConfigurationException e) { 81 // TODO Auto-generated catch block 82 e.printStackTrace(); 83 } catch (FactoryConfigurationError e) { 84 // TODO Auto-generated catch block 85 e.printStackTrace(); 86 } finally { 87 loadingDialog.dismiss(); 88 } 89 } 90 } 91 Thread loadThread = (new Thread(new appListLoader())); 92 loadThread.start(); 93 } 94 95 96 97 98 99}