Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class DownloadXML extends AsyncTask<Void, Integer, Void> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- mProgressStatus = 0;
- }
- @Override
- protected Void doInBackground(Void... params) {
- while(mProgressStatus<100){
- try{
- mProgressStatus++;
- publishProgress(mProgressStatus);
- Thread.sleep(100);
- try {
- datasource = new DataSource(mContext);
- db = datasource.getWritableDatabase();
- ContentValues cv = new ContentValues();
- URL url = new URL("http://123.231.241.53:48100/mobileapplication/AndroidFin.asmx/GetZipCode");
- DocumentBuilderFactory dbf = DocumentBuilderFactory
- .newInstance();
- DocumentBuilder db1 = dbf.newDocumentBuilder();
- // Download the XML file
- Document doc = db1.parse(new InputSource(url.openStream()));
- doc.getDocumentElement().normalize();
- // Locate the Tag Name
- nodelist = doc.getElementsByTagName("zipcode");
- for (int i=0;i<nodelist.getLength();i++) {
- Node fieldNode = nodelist.item(i);
- Log.d("waduh", "GetZipCodeData: "+nodelist.getLength());
- NamedNodeMap map = fieldNode.getAttributes();
- cv.put("KOTA", map.getNamedItem("KOTA").getNodeValue());
- cv.put("KECAMATAN", map.getNamedItem("KECAMATAN").getNodeValue());
- cv.put("KELURAHAN", map.getNamedItem("KELURAHAN").getNodeValue());
- cv.put("Description", map.getNamedItem("Description").getNodeValue());
- datasource.generateData(db, cv, "zipcode");
- cv.clear();
- }
- Node fieldNode = nodelist.item(0);
- NamedNodeMap map = fieldNode.getAttributes();
- lastinsertzipcode = map.getNamedItem("lastinsertzipcode").getNodeValue();
- Cursor cursor = db.rawQuery("SELECT id FROM " + "control", null);
- try {
- if(cursor.moveToFirst())
- {
- cv.put("lastinsertzipcode", lastinsertasset);
- datasource.updateData(db,cv,"control",null);
- }
- else{
- cv.put("lastinsertzipcode", lastinsertasset);
- datasource.generateData(db,cv,"control");
- }
- }
- finally{
- cursor.close();
- }
- } catch (Exception e) {
- Log.e("Error", e.getMessage());
- e.printStackTrace();
- }finally{
- datasource.close();
- db.close();
- }
- }catch(Exception e){
- Log.d("Exception", e.toString());
- }
- }
- return null;
- }
- @Override
- protected void onProgressUpdate(Integer... values) {
- super.onProgressUpdate(values);
- mProgressDialog.setProgress(mProgressStatus);
- }
- @Override
- protected void onPostExecute(Void args) {
- mProgressDialog.dismiss();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement