Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.84 KB | None | 0 0
  1. package com.example.layouty;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.io.UnsupportedEncodingException;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12. import java.net.URLEncoder;
  13. import java.sql.Date;
  14. import java.sql.Time;
  15. import java.text.SimpleDateFormat;
  16. import java.util.ArrayList;
  17. import java.util.Calendar;
  18.  
  19. import org.apache.http.HttpEntity;
  20. import org.apache.http.HttpResponse;
  21. import org.apache.http.HttpStatus;
  22. import org.apache.http.client.HttpClient;
  23. import org.apache.http.client.methods.HttpGet;
  24. import org.apache.http.impl.client.DefaultHttpClient;
  25. import org.json.JSONArray;
  26. import org.json.JSONException;
  27. import org.json.JSONObject;
  28.  
  29.  
  30. import android.R.integer;
  31. import android.os.AsyncTask;
  32. import android.os.Bundle;
  33. import android.app.Activity;
  34. import android.app.ProgressDialog;
  35. import android.content.Context;
  36. import android.text.format.DateFormat;
  37. import android.util.Log;
  38. import android.view.View;
  39. import android.view.View.OnClickListener;
  40. import android.widget.Button;
  41. import android.widget.EditText;
  42. import android.widget.ImageView;
  43. import android.widget.TextView;
  44. import android.widget.Toast;
  45. import android.database.Cursor;
  46. import android.database.SQLException;
  47. import android.database.sqlite.SQLiteOpenHelper;
  48. import android.database.sqlite.SQLiteDatabase;
  49. import android.graphics.Bitmap;
  50. import android.graphics.BitmapFactory;
  51.  
  52. public class VyberAktualizovania extends Activity {
  53.  
  54.     private Databaza db = null;
  55.     private Cursor constantsCursor = null;
  56.     private String datumAktualizacii = "1.1.1940";
  57.     private String pocetPodujati = "0";
  58.     private String pocetSkupin = "0";
  59.     private String pocetRecenzii = "0";
  60.     private String dnesnyDatum = "0";
  61.     private TextView datumAktualizacieTextview;
  62.     private TextView pocetPodujatiTextview;
  63.     private TextView pocetSkupinTextview;
  64.     private TextView pocetRecenziiTextview;
  65.    
  66.     private int pocetPodujatiDoTabulky = 0;
  67.     private ImageView downloadedImg;
  68.     private ProgressDialog simpleWaitDialog;
  69.     private String downloadUrl = "http://festival.vv.si/obrazky/";
  70.     ArrayList<Integer> idecka = new ArrayList<Integer>();
  71.     private String nazov=null; 
  72.     @Override
  73.     protected void onCreate(Bundle savedInstanceState) {
  74.         super.onCreate(savedInstanceState);
  75.         setContentView(R.layout.aktualizovanie);
  76.  
  77.         datumAktualizacieTextview = (TextView) findViewById(R.id.NaposledyAktualizovanieVypis);
  78.         pocetPodujatiTextview = (TextView) findViewById(R.id.pocetPodujatiVypis);
  79.         pocetSkupinTextview = (TextView) findViewById(R.id.pocetSkupinVypis);
  80.         pocetRecenziiTextview = (TextView) findViewById(R.id.pocetRecenziiVypis);
  81.  
  82.         downloadedImg = (ImageView) findViewById(R.id.obrazok);
  83.        
  84.         db = new Databaza(this);
  85.  
  86.         // WebServer Request URL
  87.         String serverURL = "http://festival.vv.si/insert.php";
  88.  
  89.         // Use AsyncTask execute Method To Prevent ANR Problem
  90.  
  91.         db = new Databaza(this);
  92.         constantsCursor = db.getReadableDatabase().rawQuery(
  93.                 "SELECT _id, datumAktualizacie, pocetPodujati, pocetSkupin, pocetRecenzii "
  94.                         + "FROM aktualizacia order by _id asc",
  95.                 null);
  96.  
  97.         while (constantsCursor.moveToNext()) {
  98.  
  99.             datumAktualizacii = (constantsCursor.getString(constantsCursor
  100.                     .getColumnIndex("datumAktualizacie")));
  101.             pocetPodujati = constantsCursor.getString(constantsCursor
  102.                     .getColumnIndex("pocetPodujati"));
  103.             pocetSkupin = constantsCursor.getString(constantsCursor
  104.                     .getColumnIndex("pocetSkupin"));
  105.             pocetRecenzii = constantsCursor.getString(constantsCursor
  106.                     .getColumnIndex("pocetRecenzii"));
  107.  
  108.         }
  109.  
  110.         SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy");
  111.         dnesnyDatum = df.format(Calendar.getInstance().getTime());
  112.        
  113.         datumAktualizacii += " / ";
  114.         pocetPodujati += " / ";
  115.         pocetSkupin += " / ";
  116.         pocetRecenzii += " / ";
  117.  
  118.         new LongOperation().execute(serverURL);
  119.  
  120.  
  121.  
  122.     }
  123.    
  124.     // Class with extends AsyncTask class
  125.  
  126.     protected class LongOperation extends AsyncTask<String, Void, Void> {
  127.  
  128.         // Required initialization
  129.  
  130.         private final HttpClient Client = new DefaultHttpClient();
  131.         private String Content;
  132.         private String Error = null;
  133.         private ProgressDialog Dialog = new ProgressDialog(VyberAktualizovania.this);
  134.         String data = "";
  135.  
  136.        
  137.         protected void onPreExecute() {
  138.             // NOTE: You can call UI Element here.
  139.  
  140.             //Start Progress Dialog (Message)
  141.             String data ="";
  142.            
  143.             Dialog.setMessage("Prosim cakajte..");
  144.             Dialog.show();
  145.  
  146.             try{
  147.                 // Set Request parameter
  148.                 data +="&" + URLEncoder.encode("data", "UTF-8") ;
  149.  
  150.             } catch (UnsupportedEncodingException e) {
  151.                 // TODO Auto-generated catch block
  152.                 e.printStackTrace();
  153.             }
  154.  
  155.         }
  156.        
  157.        
  158.         // Call after onPreExecute method
  159.         protected Void doInBackground(String... urls) {
  160.  
  161.             BufferedReader reader = null;
  162.  
  163.             // Send data
  164.             try {
  165.  
  166.                 // Defined URL where to send data
  167.                 URL url = new URL(urls[0]);
  168.  
  169.                 // Send POST data request
  170.  
  171.                 URLConnection conn = url.openConnection();
  172.                 conn.setDoOutput(true);
  173.                 OutputStreamWriter wr = new OutputStreamWriter(
  174.                         conn.getOutputStream());
  175.                 wr.write(data);
  176.                 wr.flush();
  177.  
  178.                 // Get the server response
  179.  
  180.                 reader = new BufferedReader(new InputStreamReader(
  181.                         conn.getInputStream()));
  182.                 StringBuilder sb = new StringBuilder();
  183.                 String line = null;
  184.  
  185.                 // Read Server Response
  186.                 while ((line = reader.readLine()) != null) {
  187.                     // Append server response in string
  188.                     sb.append(line + " ");
  189.                 }
  190.  
  191.                 // Append Server Response To Content String
  192.                 Content = sb.toString();
  193.             } catch (Exception ex) {
  194.                 Error = ex.getMessage();
  195.             } finally {
  196.                 try {
  197.  
  198.                     reader.close();
  199.                    
  200.                 }
  201.  
  202.                 catch (Exception ex) {
  203.                 }
  204.             }
  205.  
  206.             return null;
  207.         }
  208.  
  209.         protected void onPostExecute(Void unused) {
  210.             // NOTE: You can call UI Element here.
  211.  
  212.             // Close progress dialog
  213.             Dialog.dismiss();
  214.  
  215.             if (Error != null) {
  216.  
  217.                 // uiUpdate.setText("Output : "+Error);
  218.                
  219.             } else {
  220.  
  221.                 // Show Response Json On Screen (activity)
  222.                 // uiUpdate.setText( Content );
  223.  
  224.                 /****************** Start Parse Response JSON Data *************/
  225.  
  226.                 String OutputData = "";
  227.                 JSONObject jsonResponse;
  228.  
  229.                 try {
  230.                     // premazanie tabuliek
  231.                     db.getReadableDatabase().execSQL(
  232.                             "delete from skupina_podujatie");
  233.                     db.getReadableDatabase().execSQL("delete from album");
  234.                     db.getReadableDatabase().execSQL("delete from clenSkupiny");
  235.                     db.getReadableDatabase().execSQL("delete from recenzia");
  236.                     db.getReadableDatabase()
  237.                             .execSQL("delete from castProgramu");
  238.                     db.getReadableDatabase().execSQL("delete from skupina");
  239.                     db.getReadableDatabase().execSQL("delete from podujatie");
  240.                 //  db.getReadableDatabase()
  241.                 //          .execSQL("delete from aktualizacia");
  242.  
  243.                     /******
  244.                      * Creates a new JSONObject with name/value mappings from
  245.                      * the JSON string.
  246.                      ********/
  247.                     jsonResponse = new JSONObject(Content);
  248.  
  249.                     /*****
  250.                      * Returns the value mapped by name if it exists and is a
  251.                      * JSONArray.
  252.                      ***/
  253.                     /******* Returns null otherwise. *******/
  254.  
  255.                     /********************************** naplnanie tabulky podujatie **********************/
  256.  
  257.                     JSONArray podujatie = jsonResponse
  258.                             .optJSONArray("podujatie");
  259.  
  260.                     /*********** Process each JSON Node ************/
  261.  
  262.                     int lengthJsonArr = podujatie.length();
  263.  
  264.                     for (int i = 0; i < lengthJsonArr; i++) {
  265.                         /****** Get Object for each JSON node. ***********/
  266.                         JSONObject jsonChildPodujatie = podujatie
  267.                                 .getJSONObject(i);
  268.  
  269.                         /******* Fetch node values **********/
  270.  
  271.                         int idInsertPodujatie = jsonChildPodujatie
  272.                                 .getInt("idI");
  273.                         idecka.add(idInsertPodujatie);
  274.                         String nazovPodujatiaInsert = jsonChildPodujatie
  275.                                 .getString("nazovPodujatiaI");
  276.                         String popisPodujatiaInsert = jsonChildPodujatie
  277.                                 .getString("popisPodujatiaI");
  278.                         String webInsert = jsonChildPodujatie.getString("webI");
  279.                         String miestoKonaniaInsert = jsonChildPodujatie
  280.                                 .getString("miestoKonaniaI");
  281.                         String odDatumInsert = jsonChildPodujatie
  282.                                 .getString("odDatumI");
  283.                         String doDatumInsert = jsonChildPodujatie
  284.                                 .getString("doDatumI");
  285.                         String doVstupneInsert = jsonChildPodujatie
  286.                                 .getString("vstupneI");
  287.                         double latitudeInsert = jsonChildPodujatie
  288.                                 .getDouble("latitudeI");
  289.                         double longitudeInsert = jsonChildPodujatie
  290.                                 .getDouble("longitudeI");
  291.  
  292.                        
  293.                         db.getReadableDatabase()
  294.                                 .execSQL(
  295.                                         "Insert into podujatie(_id,nazovPodujatia,popisPodujatia,web,"
  296.                                                 + "odDatum,doDatum,miestoKonania,vstupne,latitude,longitude)"
  297.                                                 + " values("
  298.                                                 + idInsertPodujatie + ",'"
  299.                                                 + nazovPodujatiaInsert + "','"
  300.                                                 + popisPodujatiaInsert + "','"
  301.                                                 + webInsert + "','"
  302.                                                 + odDatumInsert + "','"
  303.                                                 + doDatumInsert + "','"
  304.                                                 + miestoKonaniaInsert + "',"
  305.                                                 + doVstupneInsert+","
  306.                                                 + latitudeInsert + ","
  307.                                                 + longitudeInsert + ")");
  308.  
  309.                     }
  310.  
  311.                     /***************************** naplnanie tabulky skupiny *********************/
  312.  
  313.                     JSONArray skupiny = jsonResponse.optJSONArray("skupina");
  314.  
  315.                     /*********** Process each JSON Node ************/
  316.  
  317.                     lengthJsonArr = skupiny.length();
  318.  
  319.                     for (int i = 0; i < lengthJsonArr; i++) {
  320.                         /****** Get Object for each JSON node. ***********/
  321.                         JSONObject jsonChildSkupiny = skupiny.getJSONObject(i);
  322.  
  323.                         /******* Fetch node values **********/
  324.  
  325.                         int idInsertSkupina = jsonChildSkupiny.getInt("idI");
  326.                         String nazovSkupinyInsert = jsonChildSkupiny
  327.                                 .getString("nazovSkupinyI");
  328.                         String krajinaPovoduInsert = jsonChildSkupiny
  329.                                 .getString("krajinaPovoduI");
  330.                         int rokZalozeniaInsert = jsonChildSkupiny
  331.                                 .getInt("rokZalozeniaSkupinyI");
  332.                         String popisSkupinyInsert = jsonChildSkupiny
  333.                                 .getString("popisSkupinyI");
  334.                         String zanerSkupinyInsert = jsonChildSkupiny
  335.                                 .getString("zanerSkupinyI");
  336.  
  337.                         db.getReadableDatabase().execSQL(
  338.                                 "Insert into skupina(_id,nazovSkupiny,krajinaPovodu,rokZalozeniaSkupiny,"
  339.                                         + "popisSkupiny,zanerSkupiny)"
  340.                                         + " values(" + idInsertSkupina + ",'"
  341.                                         + nazovSkupinyInsert + "','"
  342.                                         + krajinaPovoduInsert + "',"
  343.                                         + rokZalozeniaInsert + ",'"
  344.                                         + popisSkupinyInsert + "','"
  345.                                         + zanerSkupinyInsert + "')");
  346.  
  347.                     }
  348.  
  349.                     /************************************** naplnanie tabulky castProgramu ************************/
  350.  
  351.                     JSONArray castProgramu = jsonResponse
  352.                             .optJSONArray("castProgramu");
  353.  
  354.                     /*********** Process each JSON Node ************/
  355.  
  356.                     lengthJsonArr = castProgramu.length();
  357.  
  358.                     for (int i = 0; i < lengthJsonArr; i++) {
  359.                         /****** Get Object for each JSON node. ***********/
  360.                         JSONObject jsonChildPodujatie = castProgramu
  361.                                 .getJSONObject(i);
  362.  
  363.                         /******* Fetch node values **********/
  364.  
  365.                         int idInsertCastProgramu = jsonChildPodujatie
  366.                                 .getInt("idI");
  367.                         String popisCastiProgramuInsert = jsonChildPodujatie
  368.                                 .getString("popisCastiProgramuI");
  369.                         String datumCastiProgramuInsert = jsonChildPodujatie
  370.                                 .getString("datumCastiProgramuI");
  371.                         int podujatie_idInsert = jsonChildPodujatie
  372.                                 .getInt("podujatie_idI");
  373.  
  374.                         db.getReadableDatabase().execSQL(
  375.                                 "Insert into castProgramu(_id,popisCastiProgramu,"
  376.                                         + "datumCastiProgramu,podujatie_id)"
  377.                                         + " values(" + idInsertCastProgramu + ",'"
  378.                                         + popisCastiProgramuInsert + "','"
  379.                                         + datumCastiProgramuInsert + "',"
  380.                                         + podujatie_idInsert + ")");
  381.  
  382.                     }
  383.                     /************************************** naplnanie tabulky recenzia ************************/
  384.  
  385.                     JSONArray recenzia = jsonResponse.optJSONArray("recenzia");
  386.  
  387.                     /*********** Process each JSON Node ************/
  388.  
  389.                     lengthJsonArr = recenzia.length();
  390.  
  391.                     for (int i = 0; i < lengthJsonArr; i++) {
  392.                         /****** Get Object for each JSON node. ***********/
  393.                         JSONObject jsonChildPodujatie = recenzia
  394.                                 .getJSONObject(i);
  395.  
  396.                         /******* Fetch node values **********/
  397.  
  398.                         int idInsertRecenzia = jsonChildPodujatie.getInt("idI");
  399.                         String prezyvkaInsert = jsonChildPodujatie
  400.                                 .getString("prezyvkaI");
  401.                         String hlavickaInsert = jsonChildPodujatie
  402.                                 .getString("hlavickaI");
  403.                         String popisRecenzieInsert = jsonChildPodujatie
  404.                                 .getString("popisRecenzieI");
  405.                         int pocetHviezdInsert = jsonChildPodujatie
  406.                                 .getInt("pocetHviezdI");
  407.                         int podujatie_idInsert = jsonChildPodujatie
  408.                                 .getInt("podujatie_idI");
  409.  
  410.                         db.getReadableDatabase().execSQL(
  411.                                 "Insert into recenzia(_id,prezyvka,hlavicka,popisRecenzie,"
  412.                                         + "pocetHviezd,podujatie_id)"
  413.                                         + " values(" + idInsertRecenzia + ",'"
  414.                                         + prezyvkaInsert + "','"
  415.                                         + hlavickaInsert + "','"
  416.                                         + popisRecenzieInsert + "',"
  417.                                         + pocetHviezdInsert + ","
  418.                                         + podujatie_idInsert + ")");
  419.  
  420.                     }
  421.  
  422.                     /************************************** naplnanie tabulky clenSkupiny ************************/
  423.  
  424.                     JSONArray clenSkupiny = jsonResponse
  425.                             .optJSONArray("clenSkupiny");
  426.  
  427.                     /*********** Process each JSON Node ************/
  428.  
  429.                     lengthJsonArr = clenSkupiny.length();
  430.  
  431.                     for (int i = 0; i < lengthJsonArr; i++) {
  432.                         /****** Get Object for each JSON node. ***********/
  433.                         JSONObject jsonChildPodujatie = clenSkupiny
  434.                                 .getJSONObject(i);
  435.  
  436.                         /******* Fetch node values **********/
  437.  
  438.                         int idInsertClenSkupiny = jsonChildPodujatie
  439.                                 .getInt("idI");
  440.                         String menoInsert = jsonChildPodujatie
  441.                                 .getString("menoI");
  442.                         int rokVstupuInsert = jsonChildPodujatie
  443.                                 .getInt("rokVstupuI");
  444.                         String poziciaInsert = jsonChildPodujatie
  445.                                 .getString("poziciaI");
  446.                         int skupina_idInsert = jsonChildPodujatie
  447.                                 .getInt("skupina_idI");
  448.  
  449.                         db.getReadableDatabase().execSQL(
  450.                                 "Insert into clenSkupiny(_id,meno,rokVstupu,pozicia,"
  451.                                         + "skupina_id)" + " values("
  452.                                         + idInsertClenSkupiny + ",'"
  453.                                         + menoInsert + "'," + rokVstupuInsert
  454.                                         + ",'" + poziciaInsert + "',"
  455.                                         + skupina_idInsert + ")");
  456.  
  457.                     }
  458.  
  459.                     /************************************** naplnanie tabulky album ************************/
  460.  
  461.                     JSONArray album = jsonResponse.optJSONArray("album");
  462.  
  463.                     /*********** Process each JSON Node ************/
  464.  
  465.                     lengthJsonArr = album.length();
  466.  
  467.                     for (int i = 0; i < lengthJsonArr; i++) {
  468.                         /****** Get Object for each JSON node. ***********/
  469.                         JSONObject jsonChildPodujatie = album.getJSONObject(i);
  470.  
  471.                         /******* Fetch node values **********/
  472.  
  473.                         int idInsertAlbum = jsonChildPodujatie.getInt("idI");
  474.                         String nazovAlbumuInsert = jsonChildPodujatie
  475.                                 .getString("nazovAlbumuI");
  476.                         int rokVydaniaInsert = jsonChildPodujatie
  477.                                 .getInt("rokVydaniaI");
  478.                         int skupina_idInsert = jsonChildPodujatie
  479.                                 .getInt("skupina_idI");
  480.  
  481.                         db.getReadableDatabase().execSQL(
  482.                                 "Insert into album(_id,nazovAlbumu,rokVydania,"
  483.                                         + "skupina_id)" + " values("
  484.                                         + idInsertAlbum + ",'"
  485.                                         + nazovAlbumuInsert + "',"
  486.                                         + rokVydaniaInsert + ","
  487.                                         + skupina_idInsert + ")");
  488.  
  489.                     }
  490.  
  491.                     /************************************** naplnanie tabulky skupina_podujatie ************************/
  492.  
  493.                     JSONArray skupina_podujatie = jsonResponse
  494.                             .optJSONArray("skupina_podujatie");
  495.  
  496.                     /*********** Process each JSON Node ************/
  497.  
  498.                     lengthJsonArr = skupina_podujatie.length();
  499.  
  500.                     for (int i = 0; i < lengthJsonArr; i++) {
  501.                         /****** Get Object for each JSON node. ***********/
  502.                         JSONObject jsonChildPodujatie = skupina_podujatie
  503.                                 .getJSONObject(i);
  504.  
  505.                         /******* Fetch node values **********/
  506.  
  507.                         int idInsertSkupina_Podujatie = jsonChildPodujatie
  508.                                 .getInt("idI");
  509.                         int podujatie_idInsert = jsonChildPodujatie
  510.                                 .getInt("podujatie_idI");
  511.                         int skupina_idInsert = jsonChildPodujatie
  512.                                 .getInt("skupina_idI");
  513.  
  514.                         db.getReadableDatabase().execSQL(
  515.                                 "Insert into skupina_podujatie(_id,podujatie_id,skupina_id)"
  516.                                         + " values("
  517.                                         + idInsertSkupina_Podujatie + ","
  518.                                         + podujatie_idInsert + ","
  519.                                         + skupina_idInsert + ")");
  520.  
  521.                     }
  522.                    
  523.                     /****************** End Parse Response JSON Data *************/
  524.  
  525.                     //Context context = getApplicationContext();
  526.  
  527.                     //int duration = Toast.LENGTH_SHORT;
  528.                     /*
  529.                      * Toast toast = Toast.makeText(context, OutputData,
  530.                      * duration); toast.show();
  531.                      */
  532.                     // Show Parsed Output on screen (activity)
  533.                     // jsonParsed.setText( OutputData );
  534.                    
  535.                     Dialog.dismiss();
  536.  
  537.                    
  538.                     int pocetSkupinDoTabulky =0;
  539.                     int pocetRecenziiDoTabulky = 0;
  540.                     /************************** pridanie aktualneho poctu podujati ***************/
  541.                     constantsCursor = db.getReadableDatabase().rawQuery(
  542.                             "SELECT _id, count(_id)  " + "FROM podujatie", null);
  543.  
  544.                     while (constantsCursor.moveToNext()) {
  545.  
  546.                         pocetPodujatiDoTabulky = constantsCursor.getInt(constantsCursor
  547.                                 .getColumnIndex("count(_id)"));
  548.  
  549.                     }
  550.  
  551.                     /************************** pridanie aktualneho poctu skupin ***************/
  552.                     constantsCursor = db.getReadableDatabase().rawQuery(
  553.                             "SELECT _id, count(_id) " + "FROM skupina", null);
  554.  
  555.                     while (constantsCursor.moveToNext()) {
  556.  
  557.                         pocetSkupinDoTabulky = constantsCursor.getInt(constantsCursor
  558.                                 .getColumnIndex("count(_id)"));
  559.  
  560.                     }
  561.                     /************************** pridanie aktualneho poctu recenzii ***************/
  562.                     constantsCursor = db.getReadableDatabase().rawQuery(
  563.                             "SELECT _id, count(_id) " + "FROM recenzia", null);
  564.  
  565.                     while (constantsCursor.moveToNext()) {
  566.  
  567.                         pocetRecenziiDoTabulky = constantsCursor.getInt(constantsCursor
  568.                                 .getColumnIndex("count(_id)"));
  569.  
  570.                     }
  571.  
  572.                     datumAktualizacii += dnesnyDatum;
  573.                     pocetPodujati += pocetPodujatiDoTabulky;
  574.                     pocetSkupin += pocetSkupinDoTabulky;
  575.                     pocetRecenzii += pocetRecenziiDoTabulky;
  576.  
  577.                     /*************************** aktualizacia tabulky aktualizacii ***********************/
  578.  
  579.                     db.getReadableDatabase().execSQL(
  580.                             "Insert into aktualizacia(datumAktualizacie,pocetPodujati,"
  581.                                     + "pocetSkupin,pocetRecenzii) values('"
  582.                                     + dnesnyDatum + "'," + pocetPodujatiDoTabulky + ","
  583.                                     + pocetSkupinDoTabulky + "," + pocetRecenziiDoTabulky
  584.                                     + ")");
  585.  
  586.                     /***************************/
  587.                     datumAktualizacieTextview.setText(datumAktualizacii);
  588.                     pocetPodujatiTextview.setText(pocetPodujati);
  589.                     pocetSkupinTextview.setText(pocetSkupin);
  590.                     pocetRecenziiTextview.setText(pocetRecenzii);
  591.  
  592.                    
  593.                    
  594.                 } catch (JSONException e) {
  595.  
  596.                     e.printStackTrace();
  597.                 }
  598.            
  599.                 //for(int i=0; i<idecka.size();i++){
  600.                 //  nazov=""+idecka.get(i);
  601.                    
  602.                     String urlObrazku =downloadUrl+"5.png";
  603.                 //  System.out.println(""+downloadUrl+idecka.get(i)+".png");
  604.             //  new ImageDownloader().execute(urlObrazku);
  605.                     urlObrazku =downloadUrl+"4.png";
  606.                 new ImageDownloader().execute(urlObrazku);
  607.                 //}
  608.             }
  609.         }
  610.     }
  611.    
  612.         private class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
  613.  
  614.             @Override
  615.             protected Bitmap doInBackground(String... param) {
  616.                 // TODO Auto-generated method stub
  617.                 return downloadBitmap(param[0]);
  618.             }
  619.  
  620.             @Override
  621.             protected void onPreExecute() {
  622.                 Log.i("Async-Example", "onPreExecute Called");
  623.                 simpleWaitDialog = ProgressDialog.show(VyberAktualizovania.this,"Wait", "Stahujem obrazky");
  624.  
  625.             }
  626.  
  627.             @Override
  628.             protected void onPostExecute(Bitmap result) {
  629.                 Log.i("Async-Example", "onPostExecute Called");
  630.                 simpleWaitDialog.dismiss();
  631.                 FileOutputStream fos;
  632.                 try {
  633.                     fos = openFileOutput(nazov, Context.MODE_PRIVATE);
  634.                     result.compress(Bitmap.CompressFormat.PNG, 100, fos);
  635.                     fos.close();
  636.                 }catch(Exception e){
  637.                    
  638.                 }
  639.                 FileInputStream fis;
  640.                 Bitmap bitmapA=null;
  641.                  try {
  642.                         fis = openFileInput(nazov);
  643.                         bitmapA = BitmapFactory.decodeStream(fis);
  644.                         fis.close();
  645.                  }catch(Exception e){
  646.                      
  647.                      
  648.                  }
  649.                 //downloadedImg.setImageBitmap(bitmapA);
  650.             }
  651.  
  652.             private Bitmap downloadBitmap(String url) {
  653.                 // initilize the default HTTP client object
  654.                 final DefaultHttpClient client = new DefaultHttpClient();
  655.                
  656.                 //forming a HttoGet request
  657.                 final HttpGet getRequest = new HttpGet(url);
  658.                 try {
  659.                    
  660.                     HttpResponse response = client.execute(getRequest);
  661.  
  662.                     //check 200 OK for success
  663.                     final int statusCode = response.getStatusLine().getStatusCode();
  664.  
  665.                     if (statusCode != HttpStatus.SC_OK) {
  666.                         Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
  667.                         return null;
  668.  
  669.                     }
  670.                    
  671.                     final HttpEntity entity = response.getEntity();
  672.                     if (entity != null) {
  673.                         InputStream inputStream = null;
  674.                         try {
  675.                             // getting contents from the stream
  676.                             inputStream = entity.getContent();
  677.                            
  678.                             // decoding stream data back into image Bitmap that android understands
  679.                             final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
  680.  
  681.                             return bitmap;
  682.                         } finally {
  683.                             if (inputStream != null) {
  684.                                 inputStream.close();
  685.                             }
  686.                             entity.consumeContent();
  687.                         }
  688.                     }
  689.                    
  690.                 } catch (Exception e) {
  691.                     // You Could provide a more explicit error message for IOException
  692.                     getRequest.abort();
  693.                     Log.e("ImageDownloader", "Something went wrong while retrieving bitmap from " + url + e.toString());
  694.                 }
  695.                    
  696.                 return null;
  697.             }
  698.         }
  699. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement