Back to project page donatello-y-raphael.
The source code is released under:
MIT License
If you think the Android project donatello-y-raphael listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.ATracePath; /*from w ww . j a v a2s .c o m*/ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.InputStream; import java.util.ArrayList; import java.util.List; public class MainActivity extends Activity { /** * Called when the activity is first created. */ private Global mGlobals = Global.getInstance(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { List<Pack> packs = new ArrayList<Pack>(); readPack(getAssets().open("packs/packs.xml"), packs); mGlobals.mPacks = packs; mGlobals.vibrate = true; } catch ( Exception e ) { e.printStackTrace(); } } public void buttonClick( View view ) { Button button = (Button) view; int id = button.getId(); if ( id == R.id.button_play ) { startActivity( new Intent( this, LevelsActivity.class ) ); } else if ( id == R.id.button_settings ) { startActivity( new Intent( this, SettingsActivity.class ) ); } } private void readPack( InputStream is, List<Pack> packs) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse( is ); NodeList nList = doc.getElementsByTagName( "pack" ); for ( int c=0; c<nList.getLength(); ++c ) { Node nNode = nList.item(c); if ( nNode.getNodeType() == Node.ELEMENT_NODE ) { Element eNode = (Element) nNode; String name = eNode.getElementsByTagName( "name" ).item(0).getFirstChild().getNodeValue(); String description = eNode.getElementsByTagName( "description" ).item(0).getFirstChild().getNodeValue(); String file = eNode.getElementsByTagName( "file" ).item(0).getFirstChild().getNodeValue(); packs.add( new Pack( name, description, file ) ); } } } catch ( Exception e ) { e.printStackTrace(); } } private void readLevels( InputStream is, List<Challenge> challenge) { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse( is ); NodeList nList = doc.getElementsByTagName( "pack" ); for (int c = 0; c < nList.getLength(); ++c ) { Node nNode = nList.item(c); if ( nNode.getNodeType() == Node.ELEMENT_NODE ) { Element eNode = (Element) nNode; String name = eNode.getElementsByTagName( "name" ).item(0).getFirstChild().getNodeValue(); String description = eNode.getElementsByTagName( "description" ).item(0).getFirstChild().getNodeValue(); String file = eNode.getElementsByTagName( "file" ).item(0).getFirstChild().getNodeValue(); //packs.add( new Pack( name, description, file ) ); } } } catch ( Exception e ) { e.printStackTrace(); } } }