acano

Untitled

Mar 18th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 53.14 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.io.Reader;
  7. import java.io.UnsupportedEncodingException;
  8. import java.net.URLDecoder;
  9. import java.util.ArrayList;
  10. import java.util.Iterator;
  11. import java.util.LinkedList;
  12. import java.util.List;
  13.  
  14. import javax.xml.parsers.DocumentBuilder;
  15. import javax.xml.parsers.DocumentBuilderFactory;
  16. import javax.xml.parsers.ParserConfigurationException;
  17.  
  18. import org.apache.http.HttpEntity;
  19. import org.apache.http.HttpResponse;
  20. import org.apache.http.NameValuePair;
  21. import org.apache.http.client.ClientProtocolException;
  22. import org.apache.http.client.HttpClient;
  23. import org.apache.http.client.entity.UrlEncodedFormEntity;
  24. import org.apache.http.client.methods.HttpGet;
  25. import org.apache.http.client.methods.HttpPost;
  26. import org.apache.http.impl.client.DefaultHttpClient;
  27. import org.apache.http.params.BasicHttpParams;
  28. import org.apache.http.params.HttpConnectionParams;
  29. import org.apache.http.params.HttpParams;
  30. import org.apache.http.util.EntityUtils;
  31. import org.json.JSONArray;
  32. import org.json.JSONException;
  33. import org.json.JSONObject;
  34. import org.w3c.dom.Document;
  35. import org.w3c.dom.Node;
  36. import org.xml.sax.SAXException;
  37.  
  38. import com.squareup.picasso.Picasso;
  39.  
  40. import android.os.AsyncTask;
  41. import android.os.Bundle;
  42. import android.annotation.SuppressLint;
  43. import android.app.Activity;
  44. import android.content.Context;
  45. import android.content.Intent;
  46. import android.text.Editable;
  47. import android.text.TextWatcher;
  48. import android.util.Log;
  49. import android.util.TypedValue;
  50. import android.view.View;
  51. import android.view.ViewGroup.LayoutParams;
  52. import android.view.Window;
  53. import android.view.WindowManager;
  54. import android.webkit.WebView;
  55. import android.widget.DigitalClock;
  56. import android.widget.ImageView;
  57. import android.widget.RelativeLayout;
  58. import android.widget.TextView;
  59. import android.widget.Toast;
  60.  
  61. public class Display extends Activity {
  62.  
  63.     private ImageView iv, iv2, iv3;
  64.     private List<String> urls = new LinkedList<String>();
  65.     private int choice;
  66.     private Thread wpThread = null, rssThread, bgThread;
  67.     private DoPOST mDoPOST;
  68.     private Picasso.Builder builder;
  69.     private Picasso picasso;
  70.     private static String data;
  71.     private Intent lastIntent;
  72.     private RelativeLayout weatherLayOut;
  73.     public static int visible;
  74.     private CustomTextView text;
  75.     private TextView rssTV, weatherTV, forecastTV;
  76.     private String baseURL, apiURL, confSTR, user, weather, clock, rss,
  77.             watermark, webcontent, rotation, transition; // , name, id;
  78.     private DigitalClock digClock;
  79.     private int weatherImg;
  80.     private String newsString, forecast, weatherString;
  81.     private Document newsDoc, weatherDoc;
  82.     private Toast toast;
  83.     private WebView wv;
  84.     private boolean first, shouldShowWebView = false,
  85.             shouldShowWatermark = false, shouldShowClock = false,
  86.             shouldShowNews = false, shouldShowWeather = false;
  87.  
  88.     @Override
  89.     protected void onCreate(Bundle savedInstanceState) {
  90.         super.onCreate(savedInstanceState);
  91.         lastIntent = getIntent();
  92.         setFullScreen();
  93.         setContentView(R.layout.activity_display);
  94.         init();
  95.         parseConf();
  96.         enableElements();
  97.         defineGUI();
  98.         initElements();
  99.     }
  100.  
  101.     private void init() {
  102.         visible = 1;
  103.         choice = 0;
  104.         first = true;
  105.         toast = new Toast(Display.this);
  106.         builder = new Picasso.Builder(getBaseContext());
  107.         picasso = builder.build();
  108.         picasso.setDebugging(false);
  109.         text = new CustomTextView(Display.this);
  110.     }
  111.  
  112.     private void parseConf() {
  113.         confSTR = lastIntent.getStringExtra("CONF");
  114.         try {
  115.             JSONObject jo = new JSONObject(confSTR);
  116.             // get all values from json.
  117.             // id = jo.getString("id");
  118.             user = jo.getString("user");
  119.             // name = jo.getString("name");
  120.             rss = myDecode(jo.getString("rss"));
  121.             watermark = myDecode(jo.getString("watermark"));
  122.             webcontent = myDecode(jo.getString("web_content"));
  123.             clock = myDecode(jo.getString("clock"));
  124.             weather = myDecode(jo.getString("weather"));
  125.             rotation = jo.getString("rotation");
  126.             transition = jo.getString("transition");
  127.         } catch (JSONException e) {
  128.             // TODO Auto-generated catch block
  129.             e.printStackTrace();
  130.         }
  131.         baseURL = lastIntent.getStringExtra("URL") + "/upload/" + user + "/";
  132.         apiURL = lastIntent.getStringExtra("URL") + "/api.php?kind=photo&user="
  133.                 + user;
  134.     }
  135.  
  136.     @SuppressLint("CutPasteId")
  137.     private void defineGUI() {
  138.         weatherLayOut = (RelativeLayout) findViewById(R.id.weatherContainer);
  139.         rssTV = (TextView) findViewById(R.id.rssTV);
  140.         weatherTV = (TextView) findViewById(R.id.weatherTV);
  141.         wv = (WebView) findViewById(R.id.webView1);
  142.         forecastTV = (TextView) findViewById(R.id.forecastTV);
  143.         iv = (ImageView) findViewById(R.id.imageView1);
  144.         iv2 = (ImageView) findViewById(R.id.imageView2);
  145.         iv3 = (ImageView) findViewById(R.id.weatherIV);
  146.         digClock = (DigitalClock) findViewById(R.id.digitalClock);
  147.     }
  148.  
  149.     private void enableElements() {
  150.  
  151.         if (!rss.contentEquals("false")) {
  152.             shouldShowNews = true;
  153.         } else {
  154.             shouldShowNews = false;
  155.         }
  156.         if (!watermark.contentEquals("false")) {
  157.             shouldShowWatermark = true;
  158.         } else {
  159.             shouldShowWatermark = false;
  160.         }
  161.         if (!webcontent.contentEquals("false")) {
  162.             shouldShowWebView = true;
  163.         } else {
  164.             shouldShowWebView = false;
  165.         }
  166.         if (!weather.contentEquals("false")) {
  167.             shouldShowWeather = true;
  168.         } else {
  169.             shouldShowWeather = false;
  170.         }
  171.         if (!clock.contentEquals("false")) {
  172.             shouldShowClock = true;
  173.         } else {
  174.             shouldShowClock = false;
  175.         }
  176.     }
  177.  
  178.     private void initElements() {
  179.         if (shouldShowWebView) {
  180.             wv.loadUrl(webcontent);
  181.         } else {
  182.             wv.setVisibility(View.GONE);
  183.         }
  184.         if (shouldShowWatermark) {
  185.             ivParams();
  186.         } else {
  187.             iv2.setVisibility(View.GONE);
  188.         }
  189.         if (shouldShowClock) {
  190.             clockParams();
  191.         } else {
  192.             digClock.setVisibility(View.GONE);
  193.         }
  194.         if (shouldShowNews) {
  195.             rssTVParams();
  196.             startNewsThread();
  197.         } else {
  198.             rssTV.setVisibility(View.GONE);
  199.         }
  200.         if (shouldShowWeather) {
  201.             startWeatherThread();
  202.         } else {
  203.             weatherLayOut.setVisibility(View.GONE);
  204.         }
  205.         startWallpaperThread();
  206.     }
  207.  
  208.     public String myDecode(String s) {
  209.         if (s != "false" || s != "true") {
  210.             try {
  211.                 s = URLDecoder.decode(s, "UTF-8");
  212.             } catch (UnsupportedEncodingException e) {
  213.                 // TODO Auto-generated catch block
  214.                 e.printStackTrace();
  215.             }
  216.         }
  217.  
  218.         return s;
  219.     }
  220.  
  221.     private void rssTVParams() {
  222.         rssTV.setRotation(Integer.valueOf(rotation));
  223.         // get Density
  224.         final int marginSide = (int) TypedValue.applyDimension(
  225.                 TypedValue.COMPLEX_UNIT_DIP, 10, getResources()
  226.                         .getDisplayMetrics());
  227.         final int marginTB = (int) TypedValue.applyDimension(
  228.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  229.                         .getDisplayMetrics());
  230.  
  231.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
  232.                 LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
  233.         switch (Integer.valueOf(rotation)) {
  234.         case 0:
  235.             break;
  236.         case 90:
  237.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  238.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  239.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  240.             rssTV.setLayoutParams(lp);
  241.             break;
  242.         case 180:
  243.             break;
  244.         case 270:
  245.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  246.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  247.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  248.             rssTV.setLayoutParams(lp);
  249.             break;
  250.         }
  251.     }
  252.  
  253.     private void clockParams() {
  254.  
  255.         DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock);
  256.         dc.addTextChangedListener(new TextWatcher() {
  257.  
  258.             @Override
  259.             public void onTextChanged(CharSequence s, int start, int before,
  260.                     int count) {
  261.             }
  262.  
  263.             @Override
  264.             public void beforeTextChanged(CharSequence s, int start, int count,
  265.                     int after) {
  266.             }
  267.  
  268.             @Override
  269.             public void afterTextChanged(Editable s) {
  270.                 if (s.charAt(4) == ':') {
  271.                     s.delete(4, 7);
  272.                 } else if (s.charAt(5) == ':') {
  273.                     s.delete(5, 8);
  274.                 }
  275.             }
  276.         });
  277.  
  278.         digClock.setRotation(Integer.valueOf(rotation));
  279.         // get Density
  280.         final int height = (int) TypedValue.applyDimension(
  281.                 TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
  282.                         .getDisplayMetrics());
  283.         final int width = (int) TypedValue.applyDimension(
  284.                 TypedValue.COMPLEX_UNIT_DIP, 100, getResources()
  285.                         .getDisplayMetrics());
  286.         final int marginSide = (int) TypedValue.applyDimension(
  287.                 TypedValue.COMPLEX_UNIT_DIP, 10, getResources()
  288.                         .getDisplayMetrics());
  289.         final int marginTB = (int) TypedValue.applyDimension(
  290.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  291.                         .getDisplayMetrics());
  292.  
  293.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width,
  294.                 height);
  295.         switch (Integer.valueOf(rotation)) {
  296.         case 0:
  297.             break;
  298.         case 90:
  299.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  300.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  301.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  302.             digClock.setLayoutParams(lp);
  303.             break;
  304.         case 180:
  305.             break;
  306.         case 270:
  307.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  308.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  309.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  310.             digClock.setLayoutParams(lp);
  311.             break;
  312.         }
  313.     }
  314.  
  315.     private void ivParams() {
  316.  
  317.         iv2.setRotation(Integer.valueOf(rotation));
  318.         // get Density
  319.         final int height = (int) TypedValue.applyDimension(
  320.                 TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
  321.                         .getDisplayMetrics());
  322.         final int width = (int) TypedValue.applyDimension(
  323.                 TypedValue.COMPLEX_UNIT_DIP, 100, getResources()
  324.                         .getDisplayMetrics());
  325.         final int marginSide = (int) TypedValue.applyDimension(
  326.                 TypedValue.COMPLEX_UNIT_DIP, 50, getResources()
  327.                         .getDisplayMetrics());
  328.         final int marginTB = (int) TypedValue.applyDimension(
  329.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  330.                         .getDisplayMetrics());
  331.  
  332.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width,
  333.                 height);
  334.         switch (Integer.valueOf(rotation)) {
  335.         case 0:
  336.             break;
  337.         case 90:
  338.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  339.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  340.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  341.             iv2.setLayoutParams(lp);
  342.             break;
  343.         case 180:
  344.             break;
  345.         case 270:
  346.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  347.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  348.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  349.             iv2.setLayoutParams(lp);
  350.             break;
  351.  
  352.         }
  353.         picasso.load(watermark).into(iv2);
  354.         // iv2.setAlpha(100);
  355.     }
  356.  
  357.     private void setFullScreen() {
  358.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  359.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  360.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  361.     }
  362.  
  363.     public void setImage() throws IndexOutOfBoundsException {
  364.         if (choice >= urls.size()) {
  365.             choice = 0;
  366.             try {
  367.                 picasso.load(urls.get(choice))
  368.                         .rotate(Integer.valueOf(rotation)).into(iv);
  369.                 System.out.println("Debug: Wallpaper url is "
  370.                         + urls.get(choice));
  371.             } catch (Exception e) {
  372.                 e.printStackTrace();
  373.             }
  374.             choice++;
  375.         } else {
  376.             try {
  377.                 picasso.load(urls.get(choice))
  378.                         .rotate(Integer.valueOf(rotation)).into(iv);
  379.                 System.out.println("Debug: Wallpaper url is "
  380.                         + urls.get(choice));
  381.             } catch (Exception e) {
  382.                 e.printStackTrace();
  383.             }
  384.             choice++;
  385.         }
  386.     }
  387.  
  388.     private class DoPOST extends AsyncTask<String, Void, Boolean> {
  389.         // Context mContext = null;
  390.         Exception exception = null;
  391.  
  392.         DoPOST(Context context, String nameToSearch) {
  393.             // mContext = context;
  394.         }
  395.  
  396.         @Override
  397.         protected Boolean doInBackground(String... arg0) {
  398.             try {
  399.                 if (!urls.isEmpty()) {
  400.                     urls.clear();
  401.                 }
  402.                 HttpParams httpParameters = new BasicHttpParams();
  403.                 HttpConnectionParams
  404.                         .setConnectionTimeout(httpParameters, 15000);
  405.                 HttpConnectionParams.setSoTimeout(httpParameters, 15000);
  406.                 HttpClient httpclient = new DefaultHttpClient(httpParameters);
  407.                 HttpGet httppost = new HttpGet(apiURL);
  408.                 HttpResponse response = httpclient.execute(httppost);
  409.                 HttpEntity entity = response.getEntity();
  410.                 String result = EntityUtils.toString(entity);
  411.                 JSONObject jsonObject = new JSONObject(result);
  412.                 JSONObject jsonPhotos = jsonObject.getJSONObject("Images");
  413.                 Iterator<?> keys = jsonPhotos.keys();
  414.                 while (keys.hasNext()) {
  415.                     String key = (String) keys.next();
  416.                     if (jsonPhotos.get(key) instanceof JSONObject) {
  417.                         JSONObject jsonPhoto = (JSONObject) jsonPhotos.get(key);
  418.                         String image = jsonPhoto.getString("file");
  419.                         urls.add(baseURL + image);
  420.                     }
  421.                 }
  422.                 System.out.println("Debug: Wallpaper update.");
  423.  
  424.             } catch (Exception e) {
  425.                 e.printStackTrace();
  426.                 Log.e("", "Error:", e);
  427.                 exception = e;
  428.             }
  429.  
  430.             return true;
  431.         }
  432.  
  433.         @Override
  434.         protected void onPostExecute(Boolean valid) {
  435.             if (exception != null) {
  436.                 text.SetText("Lost connection to host!");
  437.                 toast.setView(text);
  438.                 toast.setDuration(Toast.LENGTH_SHORT);
  439.                 toast.show();
  440.             }
  441.             setImage();
  442.         }
  443.  
  444.     }
  445.  
  446.     private News parseNews(Document srcDoc) {
  447.         News myNews = new News();
  448.         int i = 0;
  449.         System.out.println(String.valueOf("Debug: Number of Headlines is "
  450.                 + srcDoc.getElementsByTagName("title").getLength() + "."));
  451.         myNews.headline = "\t\t\t\t";
  452.         // Iterate over titles and get total number and display that many.
  453.         while (i < srcDoc.getElementsByTagName("title").getLength()) {
  454.             myNews.headline = myNews.headline
  455.                     + srcDoc.getElementsByTagName("title").item(i)
  456.                             .getTextContent() + "\t\t\t\t";
  457.             i++;
  458.         }
  459.  
  460.         return myNews;
  461.     }
  462.  
  463.     private Document convertNewsStringToDocument(String src) {
  464.  
  465.         Document dest = null;
  466.         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  467.         DocumentBuilder parser;
  468.  
  469.         try {
  470.             parser = dbFactory.newDocumentBuilder();
  471.             dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
  472.         } catch (ParserConfigurationException e1) {
  473.             e1.printStackTrace();
  474.         } catch (SAXException e) {
  475.             e.printStackTrace();
  476.         } catch (IOException e) {
  477.             e.printStackTrace();
  478.         }
  479.  
  480.         return dest;
  481.     }
  482.  
  483.     private String queryNews() {
  484.  
  485.         String qResult = "";
  486.         String queryString = rss;
  487.  
  488.         HttpClient httpClient = new DefaultHttpClient();
  489.         HttpGet httpGet = new HttpGet(queryString);
  490.  
  491.         try {
  492.             HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
  493.  
  494.             if (httpEntity != null) {
  495.                 InputStream inputStream = httpEntity.getContent();
  496.                 Reader in = new InputStreamReader(inputStream);
  497.                 BufferedReader bufferedreader = new BufferedReader(in);
  498.                 StringBuilder stringBuilder = new StringBuilder();
  499.  
  500.                 String stringReadLine = null;
  501.  
  502.                 while ((stringReadLine = bufferedreader.readLine()) != null) {
  503.                     stringBuilder.append(stringReadLine + "\n");
  504.                 }
  505.  
  506.                 qResult = stringBuilder.toString();
  507.             }
  508.         } catch (ClientProtocolException e) {
  509.             e.printStackTrace();
  510.         } catch (IOException e) {
  511.             e.printStackTrace();
  512.         }
  513.  
  514.         return qResult;
  515.     }
  516.  
  517.     public String windDir(String deg) {
  518.         String dir = null;
  519.         InputStream inputStream = null;
  520.         String finalDIR = null;
  521.         JSONObject jObject;
  522.         JSONArray direction;
  523.  
  524.         String confAPI = lastIntent.getStringExtra("URL")
  525.                 + "/api.php?kind=wind&deg=" + deg;
  526.         ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
  527.         try {
  528.  
  529.             HttpClient httpClient = new DefaultHttpClient();
  530.             HttpPost httpPost = new HttpPost(confAPI);
  531.             httpPost.setEntity(new UrlEncodedFormEntity(param));
  532.             HttpResponse httpResponse = httpClient.execute(httpPost);
  533.             HttpEntity httpEntity = httpResponse.getEntity();
  534.             inputStream = httpEntity.getContent();
  535.  
  536.             BufferedReader bReader = new BufferedReader(new InputStreamReader(
  537.                     inputStream, "iso-8859-1"), 8);
  538.             StringBuilder sBuilder = new StringBuilder();
  539.  
  540.             String line = null;
  541.             while ((line = bReader.readLine()) != null) {
  542.                 sBuilder.append(line + "\n");
  543.             }
  544.  
  545.             dir = sBuilder.toString();
  546.             jObject = new JSONObject(dir);
  547.             direction = jObject.getJSONArray("Direction");
  548.             // The next few lines are slop. I need to change this to use the JSON parser...
  549.             finalDIR = direction.toString().replaceAll("\"", "");
  550.             finalDIR = finalDIR.replace("[", "");
  551.             finalDIR = finalDIR.replace("]", "");
  552.             System.out.println("Debug: Wind direction is " + finalDIR);
  553.  
  554.         } catch (Exception e) {
  555.             e.printStackTrace();
  556.         }
  557.         return finalDIR;
  558.     }
  559.  
  560.     private Weather parseWeather(Document srcDoc) {
  561.         int currentCode;
  562.         Weather myWeather = new Weather();
  563.  
  564.         // <description>Yahoo! Weather for New York, NY</description>
  565.         // myWeather.description = "Current Weather: Troy NY";
  566.  
  567.         myWeather.description = srcDoc.getElementsByTagName("description")
  568.                 .item(0).getTextContent();
  569.  
  570.         // <yweather:location.../>
  571.  
  572.         Node locationNode = srcDoc.getElementsByTagName("yweather:location")
  573.                 .item(0);
  574.         myWeather.city = locationNode.getAttributes().getNamedItem("city")
  575.                 .getNodeValue().toString();
  576.         myWeather.region = locationNode.getAttributes().getNamedItem("region")
  577.                 .getNodeValue().toString();
  578.         myWeather.country = locationNode.getAttributes()
  579.                 .getNamedItem("country").getNodeValue().toString();
  580.  
  581.         // <yweather:condition.../>
  582.         Node conditionNode = srcDoc.getElementsByTagName("yweather:condition")
  583.                 .item(0);
  584.         myWeather.conditiontext = conditionNode.getAttributes()
  585.                 .getNamedItem("text").getNodeValue().toString();
  586.         myWeather.conditiondate = conditionNode.getAttributes()
  587.                 .getNamedItem("date").getNodeValue().toString();
  588.         currentCode = Integer
  589.                 .valueOf(myWeather.conditioncode = conditionNode
  590.                         .getAttributes().getNamedItem("code").getNodeValue()
  591.                         .toString());
  592.         System.out.println("Debug: Weather code is " + currentCode + ".");
  593.         setWeatherIcon(currentCode);
  594.  
  595.         // <yweather:wind.../>
  596.         Node windNode = srcDoc.getElementsByTagName("yweather:wind").item(0);
  597.         myWeather.windChill = windNode.getAttributes().getNamedItem("chill")
  598.                 .getNodeValue().toString();
  599.  
  600.         myWeather.windDirection = windDir(windNode.getAttributes()
  601.                 .getNamedItem("direction").getNodeValue().toString());
  602.         myWeather.windSpeed = windNode.getAttributes().getNamedItem("speed")
  603.                 .getNodeValue().toString();
  604.  
  605.         // <yweather:astronomy.../>
  606.         Node astronomyNode = srcDoc.getElementsByTagName("yweather:astronomy")
  607.                 .item(0);
  608.         myWeather.sunrise = astronomyNode.getAttributes()
  609.                 .getNamedItem("sunrise").getNodeValue().toString();
  610.         myWeather.sunset = astronomyNode.getAttributes().getNamedItem("sunset")
  611.                 .getNodeValue().toString();
  612.         // forecast info
  613.         Node forecastNode1 = srcDoc.getElementsByTagName("yweather:forecast")
  614.                 .item(0);
  615.         myWeather.day1 = "\t\t"
  616.                 + forecastNode1.getAttributes().getNamedItem("day")
  617.                         .getNodeValue().toString()
  618.                 + ": "
  619.                 + forecastNode1.getAttributes().getNamedItem("high")
  620.                         .getNodeValue().toString()
  621.                 + (char) 0x00B0
  622.                 + "F "
  623.                 + forecastNode1.getAttributes().getNamedItem("text")
  624.                         .getNodeValue().toString() + "\n";
  625.  
  626.         Node forecastNode2 = srcDoc.getElementsByTagName("yweather:forecast")
  627.                 .item(1);
  628.  
  629.         myWeather.day2 = "\t\t"
  630.                 + forecastNode2.getAttributes().getNamedItem("day")
  631.                         .getNodeValue().toString()
  632.                 + ": "
  633.                 + forecastNode2.getAttributes().getNamedItem("high")
  634.                         .getNodeValue().toString()
  635.                 + (char) 0x00B0
  636.                 + "F "
  637.                 + forecastNode2.getAttributes().getNamedItem("text")
  638.                         .getNodeValue().toString() + "\n";
  639.  
  640.         Node forecastNode3 = srcDoc.getElementsByTagName("yweather:forecast")
  641.                 .item(2);
  642.  
  643.         myWeather.day3 = "\t\t"
  644.                 + forecastNode3.getAttributes().getNamedItem("day")
  645.                         .getNodeValue().toString()
  646.                 + ": "
  647.                 + forecastNode3.getAttributes().getNamedItem("high")
  648.                         .getNodeValue().toString()
  649.                 + (char) 0x00B0
  650.                 + "F "
  651.                 + forecastNode3.getAttributes().getNamedItem("text")
  652.                         .getNodeValue().toString() + "\n";
  653.  
  654.         Node forecastNode4 = srcDoc.getElementsByTagName("yweather:forecast")
  655.                 .item(3);
  656.  
  657.         myWeather.day4 = "\t\t"
  658.                 + forecastNode4.getAttributes().getNamedItem("day")
  659.                         .getNodeValue().toString()
  660.                 + ": "
  661.                 + forecastNode4.getAttributes().getNamedItem("high")
  662.                         .getNodeValue().toString()
  663.                 + (char) 0x00B0
  664.                 + "F "
  665.                 + forecastNode4.getAttributes().getNamedItem("text")
  666.                         .getNodeValue().toString() + "\n";
  667.  
  668.         Node forecastNode5 = srcDoc.getElementsByTagName("yweather:forecast")
  669.                 .item(4);
  670.  
  671.         myWeather.day5 = "\t\t"
  672.                 + forecastNode5.getAttributes().getNamedItem("day")
  673.                         .getNodeValue().toString()
  674.                 + ": "
  675.                 + forecastNode5.getAttributes().getNamedItem("high")
  676.                         .getNodeValue().toString()
  677.                 + (char) 0x00B0
  678.                 + "F "
  679.                 + forecastNode5.getAttributes().getNamedItem("text")
  680.                         .getNodeValue().toString() + "\n";
  681.  
  682.         forecast = "\t\t" + myWeather.day1 + myWeather.day2 + myWeather.day3
  683.                 + myWeather.day4 + myWeather.day5 + "\t\t";
  684.  
  685.         return myWeather;
  686.     }
  687.  
  688.     private void startWeatherThread() {
  689.         bgThread = new Thread(new Runnable() {
  690.             public void run() {
  691.                 while (visible == 1) {
  692.                     weatherString = queryWeather();
  693.                     weatherDoc = convertStringToDocument(weatherString);
  694.                     final Weather weatherResult = parseWeather(weatherDoc);
  695.                     runOnUiThread(new Runnable() {
  696.                         @Override
  697.                         public void run() {
  698.                             weatherTV.invalidate();
  699.                             weatherTV.setText(weatherResult.toString());
  700.                             Picasso.with(getBaseContext()).load(weatherImg)
  701.                                     .error(R.drawable.dunno).into(iv3);
  702.                             forecastTV.invalidate();
  703.                             forecastTV.setText(forecast);
  704.                             forecastTV.setSelected(true);
  705.                             System.out.println("Debug: Weather update.");
  706.                         }
  707.                     });
  708.                     try {
  709.                         Thread.sleep(600000);
  710.                     } catch (InterruptedException e) {
  711.                         e.printStackTrace();
  712.                     }
  713.                 }
  714.             }
  715.         });
  716.         bgThread.start();
  717.     }
  718.  
  719.     private Document convertStringToDocument(String src) {
  720.  
  721.         Document dest = null;
  722.         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  723.         DocumentBuilder parser;
  724.  
  725.         try {
  726.             parser = dbFactory.newDocumentBuilder();
  727.             dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
  728.         } catch (ParserConfigurationException e1) {
  729.             e1.printStackTrace();
  730.         } catch (SAXException e) {
  731.             e.printStackTrace();
  732.         } catch (IOException e) {
  733.             e.printStackTrace();
  734.         }
  735.  
  736.         return dest;
  737.     }
  738.  
  739.     private void startNewsThread() {
  740.         rssThread = new Thread(new Runnable() {
  741.             public void run() {
  742.                 while (visible == 1) {
  743.                     newsString = queryNews();
  744.                     newsDoc = convertNewsStringToDocument(newsString);
  745.                     final News newsResult = parseNews(newsDoc);
  746.                     runOnUiThread(new Runnable() {
  747.                         @Override
  748.                         public void run() {
  749.                             rssTV.invalidate();
  750.                             rssTV.setText(newsResult.toString());
  751.                             rssTV.setSelected(true);
  752.                             System.out.println("Debug: News update.");
  753.                         }
  754.                     });
  755.                     try {
  756.                         Thread.sleep(600000);
  757.                     } catch (InterruptedException e) {
  758.                         e.printStackTrace();
  759.                     }
  760.                 }
  761.             }
  762.         });
  763.         rssThread.start();
  764.     }
  765.  
  766.     private void startWallpaperThread() {
  767.         wpThread = new Thread(new Runnable() {
  768.             public void run() {
  769.                 while (visible == 1) {
  770.                     try {
  771.                         if (first) {
  772.                             first = false;
  773.                             mDoPOST = new DoPOST(Display.this, data);
  774.                             mDoPOST.execute("");
  775.                             Thread.sleep(Integer.valueOf(transition) * 1000);
  776.                         } else {
  777.                             Thread.sleep(Integer.valueOf(transition) * 1000);
  778.                             mDoPOST = new DoPOST(Display.this, data);
  779.                             mDoPOST.execute("");
  780.                         }
  781.                     } catch (InterruptedException e) {
  782.                         e.printStackTrace();
  783.                     }
  784.                 }
  785.             }
  786.         });
  787.         wpThread.start();
  788.     }
  789.  
  790.     private String queryWeather() {
  791.  
  792.         String qResult = "";
  793.         String queryString = getResources().getString(R.string.yahooWeatherAPI)
  794.                 .toString() + lastIntent.getStringExtra("ZIP");
  795.  
  796.         HttpClient httpClient = new DefaultHttpClient();
  797.         HttpGet httpGet = new HttpGet(queryString);
  798.  
  799.         try {
  800.             HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
  801.  
  802.             if (httpEntity != null) {
  803.                 InputStream inputStream = httpEntity.getContent();
  804.                 Reader in = new InputStreamReader(inputStream);
  805.                 BufferedReader bufferedreader = new BufferedReader(in);
  806.                 StringBuilder stringBuilder = new StringBuilder();
  807.  
  808.                 String stringReadLine = null;
  809.  
  810.                 while ((stringReadLine = bufferedreader.readLine()) != null) {
  811.                     stringBuilder.append(stringReadLine + "\n");
  812.                 }
  813.  
  814.                 qResult = stringBuilder.toString();
  815.             }
  816.         } catch (ClientProtocolException e) {
  817.             e.printStackTrace();
  818.         } catch (IOException e) {
  819.             e.printStackTrace();
  820.         }
  821.  
  822.         return qResult;
  823.     }
  824.  
  825.     // use our icons based on yahoo weather code.
  826.     public void setWeatherIcon(int currentCode) {
  827.         // using switch-case fall through to keep things short and neat.
  828.         switch (currentCode) {
  829.         // t-storm 3
  830.         case 0:
  831.         case 1:
  832.         case 2:
  833.         case 3:
  834.         case 4:
  835.             weatherImg = R.drawable.tstorm3;
  836.             break;
  837.         // sleet
  838.         case 5:
  839.         case 6:
  840.         case 7:
  841.         case 8:
  842.         case 10:
  843.         case 18:
  844.             weatherImg = R.drawable.sleet;
  845.             break;
  846.         // light rain
  847.         case 9:
  848.             weatherImg = R.drawable.light_rain;
  849.             break;
  850.         // shower 3
  851.         case 11:
  852.         case 12:
  853.             weatherImg = R.drawable.shower3;
  854.             break;
  855.         // snow 4
  856.         case 13:
  857.         case 14:
  858.         case 15:
  859.         case 46:
  860.             weatherImg = R.drawable.snow4;
  861.             break;
  862.         // snow 5
  863.         case 16:
  864.             weatherImg = R.drawable.snow5;
  865.             break;
  866.         // hail
  867.         case 17:
  868.         case 35:
  869.             weatherImg = R.drawable.hail;
  870.             break;
  871.         // mist
  872.         case 19:
  873.         case 21:
  874.             weatherImg = R.drawable.mist;
  875.             break;
  876.         // fog
  877.         case 20:
  878.         case 22:
  879.             weatherImg = R.drawable.fog;
  880.             break;
  881.         // sunny
  882.         case 23:
  883.         case 24:
  884.         case 25:
  885.         case 32:
  886.         case 34:
  887.         case 36:
  888.             weatherImg = R.drawable.sunny;
  889.             break;
  890.         // overcast
  891.         case 26:
  892.             weatherImg = R.drawable.overcast;
  893.             break;
  894.         // cloudy 4 night
  895.         case 27:
  896.             weatherImg = R.drawable.cloudy4_night;
  897.             break;
  898.         // cloudy 4
  899.         case 28:
  900.             weatherImg = R.drawable.cloudy4;
  901.             break;
  902.         // cloudy 1 night
  903.         case 29:
  904.             weatherImg = R.drawable.cloudy1_night;
  905.             break;
  906.         // cloudy 1
  907.         case 30:
  908.             weatherImg = R.drawable.cloudy1;
  909.             break;
  910.         // suny night
  911.         case 31:
  912.         case 33:
  913.             weatherImg = R.drawable.sunny_night;
  914.             break;
  915.         // tstorm 2
  916.         case 37:
  917.         case 38:
  918.         case 39:
  919.         case 45:
  920.         case 47:
  921.             weatherImg = R.drawable.tstorm2;
  922.             break;
  923.         // shower 1
  924.         case 40:
  925.             weatherImg = R.drawable.shower1;
  926.             break;
  927.         // snow 5
  928.         case 41:
  929.         case 43:
  930.             weatherImg = R.drawable.snow5;
  931.             break;
  932.         // snow 3
  933.         case 42:
  934.             weatherImg = R.drawable.snow3;
  935.             break;
  936.         // cloudy 2
  937.         case 44:
  938.             weatherImg = R.drawable.cloudy2;
  939.             break;
  940.         // not sure
  941.         case 3200:
  942.             weatherImg = R.drawable.dunno;
  943.             break;
  944.  
  945.         }
  946.     }
  947.  
  948.     @Override
  949.     public void onBackPressed() {
  950.         finish();
  951.     }
  952.  
  953. }import java.io.BufferedReader;
  954. import java.io.ByteArrayInputStream;
  955. import java.io.IOException;
  956. import java.io.InputStream;
  957. import java.io.InputStreamReader;
  958. import java.io.Reader;
  959. import java.io.UnsupportedEncodingException;
  960. import java.net.URLDecoder;
  961. import java.util.ArrayList;
  962. import java.util.Iterator;
  963. import java.util.LinkedList;
  964. import java.util.List;
  965.  
  966. import javax.xml.parsers.DocumentBuilder;
  967. import javax.xml.parsers.DocumentBuilderFactory;
  968. import javax.xml.parsers.ParserConfigurationException;
  969.  
  970. import org.apache.http.HttpEntity;
  971. import org.apache.http.HttpResponse;
  972. import org.apache.http.NameValuePair;
  973. import org.apache.http.client.ClientProtocolException;
  974. import org.apache.http.client.HttpClient;
  975. import org.apache.http.client.entity.UrlEncodedFormEntity;
  976. import org.apache.http.client.methods.HttpGet;
  977. import org.apache.http.client.methods.HttpPost;
  978. import org.apache.http.impl.client.DefaultHttpClient;
  979. import org.apache.http.params.BasicHttpParams;
  980. import org.apache.http.params.HttpConnectionParams;
  981. import org.apache.http.params.HttpParams;
  982. import org.apache.http.util.EntityUtils;
  983. import org.json.JSONArray;
  984. import org.json.JSONException;
  985. import org.json.JSONObject;
  986. import org.w3c.dom.Document;
  987. import org.w3c.dom.Node;
  988. import org.xml.sax.SAXException;
  989.  
  990. import com.squareup.picasso.Picasso;
  991.  
  992. import android.os.AsyncTask;
  993. import android.os.Bundle;
  994. import android.annotation.SuppressLint;
  995. import android.app.Activity;
  996. import android.content.Context;
  997. import android.content.Intent;
  998. import android.text.Editable;
  999. import android.text.TextWatcher;
  1000. import android.util.Log;
  1001. import android.util.TypedValue;
  1002. import android.view.View;
  1003. import android.view.ViewGroup.LayoutParams;
  1004. import android.view.Window;
  1005. import android.view.WindowManager;
  1006. import android.webkit.WebView;
  1007. import android.widget.DigitalClock;
  1008. import android.widget.ImageView;
  1009. import android.widget.RelativeLayout;
  1010. import android.widget.TextView;
  1011. import android.widget.Toast;
  1012.  
  1013. public class Display extends Activity {
  1014.  
  1015.     private ImageView iv, iv2, iv3;
  1016.     private List<String> urls = new LinkedList<String>();
  1017.     private int choice;
  1018.     private Thread wpThread = null, rssThread, bgThread;
  1019.     private DoPOST mDoPOST;
  1020.     private Picasso.Builder builder;
  1021.     private Picasso picasso;
  1022.     private static String data;
  1023.     private Intent lastIntent;
  1024.     private RelativeLayout weatherLayOut;
  1025.     public static int visible;
  1026.     private CustomTextView text;
  1027.     private TextView rssTV, weatherTV, forecastTV;
  1028.     private String baseURL, apiURL, confSTR, user, weather, clock, rss,
  1029.             watermark, webcontent, rotation, transition; // , name, id;
  1030.     private DigitalClock digClock;
  1031.     private int weatherImg;
  1032.     private String newsString, forecast, weatherString;
  1033.     private Document newsDoc, weatherDoc;
  1034.     private Toast toast;
  1035.     private WebView wv;
  1036.     private boolean first, shouldShowWebView = false,
  1037.             shouldShowWatermark = false, shouldShowClock = false,
  1038.             shouldShowNews = false, shouldShowWeather = false;
  1039.  
  1040.     @Override
  1041.     protected void onCreate(Bundle savedInstanceState) {
  1042.         super.onCreate(savedInstanceState);
  1043.         lastIntent = getIntent();
  1044.         setFullScreen();
  1045.         setContentView(R.layout.activity_display);
  1046.         init();
  1047.         parseConf();
  1048.         enableElements();
  1049.         defineGUI();
  1050.         initElements();
  1051.     }
  1052.  
  1053.     private void init() {
  1054.         visible = 1;
  1055.         choice = 0;
  1056.         first = true;
  1057.         toast = new Toast(Display.this);
  1058.         builder = new Picasso.Builder(getBaseContext());
  1059.         picasso = builder.build();
  1060.         picasso.setDebugging(false);
  1061.         text = new CustomTextView(Display.this);
  1062.     }
  1063.  
  1064.     private void parseConf() {
  1065.         confSTR = lastIntent.getStringExtra("CONF");
  1066.         try {
  1067.             JSONObject jo = new JSONObject(confSTR);
  1068.             // get all values from json.
  1069.             // id = jo.getString("id");
  1070.             user = jo.getString("user");
  1071.             // name = jo.getString("name");
  1072.             rss = myDecode(jo.getString("rss"));
  1073.             watermark = myDecode(jo.getString("watermark"));
  1074.             webcontent = myDecode(jo.getString("web_content"));
  1075.             clock = myDecode(jo.getString("clock"));
  1076.             weather = myDecode(jo.getString("weather"));
  1077.             rotation = jo.getString("rotation");
  1078.             transition = jo.getString("transition");
  1079.         } catch (JSONException e) {
  1080.             // TODO Auto-generated catch block
  1081.             e.printStackTrace();
  1082.         }
  1083.         baseURL = lastIntent.getStringExtra("URL") + "/upload/" + user + "/";
  1084.         apiURL = lastIntent.getStringExtra("URL") + "/api.php?kind=photo&user="
  1085.                 + user;
  1086.     }
  1087.  
  1088.     @SuppressLint("CutPasteId")
  1089.     private void defineGUI() {
  1090.         weatherLayOut = (RelativeLayout) findViewById(R.id.weatherContainer);
  1091.         rssTV = (TextView) findViewById(R.id.rssTV);
  1092.         weatherTV = (TextView) findViewById(R.id.weatherTV);
  1093.         wv = (WebView) findViewById(R.id.webView1);
  1094.         forecastTV = (TextView) findViewById(R.id.forecastTV);
  1095.         iv = (ImageView) findViewById(R.id.imageView1);
  1096.         iv2 = (ImageView) findViewById(R.id.imageView2);
  1097.         iv3 = (ImageView) findViewById(R.id.weatherIV);
  1098.         digClock = (DigitalClock) findViewById(R.id.digitalClock);
  1099.     }
  1100.  
  1101.     private void enableElements() {
  1102.  
  1103.         if (!rss.contentEquals("false")) {
  1104.             shouldShowNews = true;
  1105.         } else {
  1106.             shouldShowNews = false;
  1107.         }
  1108.         if (!watermark.contentEquals("false")) {
  1109.             shouldShowWatermark = true;
  1110.         } else {
  1111.             shouldShowWatermark = false;
  1112.         }
  1113.         if (!webcontent.contentEquals("false")) {
  1114.             shouldShowWebView = true;
  1115.         } else {
  1116.             shouldShowWebView = false;
  1117.         }
  1118.         if (!weather.contentEquals("false")) {
  1119.             shouldShowWeather = true;
  1120.         } else {
  1121.             shouldShowWeather = false;
  1122.         }
  1123.         if (!clock.contentEquals("false")) {
  1124.             shouldShowClock = true;
  1125.         } else {
  1126.             shouldShowClock = false;
  1127.         }
  1128.     }
  1129.  
  1130.     private void initElements() {
  1131.         if (shouldShowWebView) {
  1132.             wv.loadUrl(webcontent);
  1133.         } else {
  1134.             wv.setVisibility(View.GONE);
  1135.         }
  1136.         if (shouldShowWatermark) {
  1137.             ivParams();
  1138.         } else {
  1139.             iv2.setVisibility(View.GONE);
  1140.         }
  1141.         if (shouldShowClock) {
  1142.             clockParams();
  1143.         } else {
  1144.             digClock.setVisibility(View.GONE);
  1145.         }
  1146.         if (shouldShowNews) {
  1147.             rssTVParams();
  1148.             startNewsThread();
  1149.         } else {
  1150.             rssTV.setVisibility(View.GONE);
  1151.         }
  1152.         if (shouldShowWeather) {
  1153.             startWeatherThread();
  1154.         } else {
  1155.             weatherLayOut.setVisibility(View.GONE);
  1156.         }
  1157.         startWallpaperThread();
  1158.     }
  1159.  
  1160.     public String myDecode(String s) {
  1161.         if (s != "false" || s != "true") {
  1162.             try {
  1163.                 s = URLDecoder.decode(s, "UTF-8");
  1164.             } catch (UnsupportedEncodingException e) {
  1165.                 // TODO Auto-generated catch block
  1166.                 e.printStackTrace();
  1167.             }
  1168.         }
  1169.  
  1170.         return s;
  1171.     }
  1172.  
  1173.     private void rssTVParams() {
  1174.         rssTV.setRotation(Integer.valueOf(rotation));
  1175.         // get Density
  1176.         final int marginSide = (int) TypedValue.applyDimension(
  1177.                 TypedValue.COMPLEX_UNIT_DIP, 10, getResources()
  1178.                         .getDisplayMetrics());
  1179.         final int marginTB = (int) TypedValue.applyDimension(
  1180.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  1181.                         .getDisplayMetrics());
  1182.  
  1183.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
  1184.                 LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
  1185.         switch (Integer.valueOf(rotation)) {
  1186.         case 0:
  1187.             break;
  1188.         case 90:
  1189.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  1190.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  1191.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1192.             rssTV.setLayoutParams(lp);
  1193.             break;
  1194.         case 180:
  1195.             break;
  1196.         case 270:
  1197.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  1198.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  1199.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1200.             rssTV.setLayoutParams(lp);
  1201.             break;
  1202.         }
  1203.     }
  1204.  
  1205.     private void clockParams() {
  1206.  
  1207.         DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock);
  1208.         dc.addTextChangedListener(new TextWatcher() {
  1209.  
  1210.             @Override
  1211.             public void onTextChanged(CharSequence s, int start, int before,
  1212.                     int count) {
  1213.             }
  1214.  
  1215.             @Override
  1216.             public void beforeTextChanged(CharSequence s, int start, int count,
  1217.                     int after) {
  1218.             }
  1219.  
  1220.             @Override
  1221.             public void afterTextChanged(Editable s) {
  1222.                 if (s.charAt(4) == ':') {
  1223.                     s.delete(4, 7);
  1224.                 } else if (s.charAt(5) == ':') {
  1225.                     s.delete(5, 8);
  1226.                 }
  1227.             }
  1228.         });
  1229.  
  1230.         digClock.setRotation(Integer.valueOf(rotation));
  1231.         // get Density
  1232.         final int height = (int) TypedValue.applyDimension(
  1233.                 TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
  1234.                         .getDisplayMetrics());
  1235.         final int width = (int) TypedValue.applyDimension(
  1236.                 TypedValue.COMPLEX_UNIT_DIP, 100, getResources()
  1237.                         .getDisplayMetrics());
  1238.         final int marginSide = (int) TypedValue.applyDimension(
  1239.                 TypedValue.COMPLEX_UNIT_DIP, 10, getResources()
  1240.                         .getDisplayMetrics());
  1241.         final int marginTB = (int) TypedValue.applyDimension(
  1242.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  1243.                         .getDisplayMetrics());
  1244.  
  1245.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width,
  1246.                 height);
  1247.         switch (Integer.valueOf(rotation)) {
  1248.         case 0:
  1249.             break;
  1250.         case 90:
  1251.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  1252.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  1253.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1254.             digClock.setLayoutParams(lp);
  1255.             break;
  1256.         case 180:
  1257.             break;
  1258.         case 270:
  1259.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  1260.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  1261.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1262.             digClock.setLayoutParams(lp);
  1263.             break;
  1264.         }
  1265.     }
  1266.  
  1267.     private void ivParams() {
  1268.  
  1269.         iv2.setRotation(Integer.valueOf(rotation));
  1270.         // get Density
  1271.         final int height = (int) TypedValue.applyDimension(
  1272.                 TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
  1273.                         .getDisplayMetrics());
  1274.         final int width = (int) TypedValue.applyDimension(
  1275.                 TypedValue.COMPLEX_UNIT_DIP, 100, getResources()
  1276.                         .getDisplayMetrics());
  1277.         final int marginSide = (int) TypedValue.applyDimension(
  1278.                 TypedValue.COMPLEX_UNIT_DIP, 50, getResources()
  1279.                         .getDisplayMetrics());
  1280.         final int marginTB = (int) TypedValue.applyDimension(
  1281.                 TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
  1282.                         .getDisplayMetrics());
  1283.  
  1284.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width,
  1285.                 height);
  1286.         switch (Integer.valueOf(rotation)) {
  1287.         case 0:
  1288.             break;
  1289.         case 90:
  1290.             lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  1291.             lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  1292.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1293.             iv2.setLayoutParams(lp);
  1294.             break;
  1295.         case 180:
  1296.             break;
  1297.         case 270:
  1298.             lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  1299.             lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  1300.             lp.setMargins(marginTB, marginSide, marginTB, marginSide);
  1301.             iv2.setLayoutParams(lp);
  1302.             break;
  1303.  
  1304.         }
  1305.         picasso.load(watermark).into(iv2);
  1306.         // iv2.setAlpha(100);
  1307.     }
  1308.  
  1309.     private void setFullScreen() {
  1310.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  1311.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  1312.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  1313.     }
  1314.  
  1315.     public void setImage() throws IndexOutOfBoundsException {
  1316.         if (choice >= urls.size()) {
  1317.             choice = 0;
  1318.             try {
  1319.                 picasso.load(urls.get(choice))
  1320.                         .rotate(Integer.valueOf(rotation)).into(iv);
  1321.                 System.out.println("Debug: Wallpaper url is "
  1322.                         + urls.get(choice));
  1323.             } catch (Exception e) {
  1324.                 e.printStackTrace();
  1325.             }
  1326.             choice++;
  1327.         } else {
  1328.             try {
  1329.                 picasso.load(urls.get(choice))
  1330.                         .rotate(Integer.valueOf(rotation)).into(iv);
  1331.                 System.out.println("Debug: Wallpaper url is "
  1332.                         + urls.get(choice));
  1333.             } catch (Exception e) {
  1334.                 e.printStackTrace();
  1335.             }
  1336.             choice++;
  1337.         }
  1338.     }
  1339.  
  1340.     private class DoPOST extends AsyncTask<String, Void, Boolean> {
  1341.         // Context mContext = null;
  1342.         Exception exception = null;
  1343.  
  1344.         DoPOST(Context context, String nameToSearch) {
  1345.             // mContext = context;
  1346.         }
  1347.  
  1348.         @Override
  1349.         protected Boolean doInBackground(String... arg0) {
  1350.             try {
  1351.                 if (!urls.isEmpty()) {
  1352.                     urls.clear();
  1353.                 }
  1354.                 HttpParams httpParameters = new BasicHttpParams();
  1355.                 HttpConnectionParams
  1356.                         .setConnectionTimeout(httpParameters, 15000);
  1357.                 HttpConnectionParams.setSoTimeout(httpParameters, 15000);
  1358.                 HttpClient httpclient = new DefaultHttpClient(httpParameters);
  1359.                 HttpGet httppost = new HttpGet(apiURL);
  1360.                 HttpResponse response = httpclient.execute(httppost);
  1361.                 HttpEntity entity = response.getEntity();
  1362.                 String result = EntityUtils.toString(entity);
  1363.                 JSONObject jsonObject = new JSONObject(result);
  1364.                 JSONObject jsonPhotos = jsonObject.getJSONObject("Images");
  1365.                 Iterator<?> keys = jsonPhotos.keys();
  1366.                 while (keys.hasNext()) {
  1367.                     String key = (String) keys.next();
  1368.                     if (jsonPhotos.get(key) instanceof JSONObject) {
  1369.                         JSONObject jsonPhoto = (JSONObject) jsonPhotos.get(key);
  1370.                         String image = jsonPhoto.getString("file");
  1371.                         urls.add(baseURL + image);
  1372.                     }
  1373.                 }
  1374.                 System.out.println("Debug: Wallpaper update.");
  1375.  
  1376.             } catch (Exception e) {
  1377.                 e.printStackTrace();
  1378.                 Log.e("", "Error:", e);
  1379.                 exception = e;
  1380.             }
  1381.  
  1382.             return true;
  1383.         }
  1384.  
  1385.         @Override
  1386.         protected void onPostExecute(Boolean valid) {
  1387.             if (exception != null) {
  1388.                 text.SetText("Lost connection to host!");
  1389.                 toast.setView(text);
  1390.                 toast.setDuration(Toast.LENGTH_SHORT);
  1391.                 toast.show();
  1392.             }
  1393.             setImage();
  1394.         }
  1395.  
  1396.     }
  1397.  
  1398.     private News parseNews(Document srcDoc) {
  1399.         News myNews = new News();
  1400.         int i = 0;
  1401.         System.out.println(String.valueOf("Debug: Number of Headlines is "
  1402.                 + srcDoc.getElementsByTagName("title").getLength() + "."));
  1403.         myNews.headline = "\t\t\t\t";
  1404.         // Iterate over titles and get total number and display that many.
  1405.         while (i < srcDoc.getElementsByTagName("title").getLength()) {
  1406.             myNews.headline = myNews.headline
  1407.                     + srcDoc.getElementsByTagName("title").item(i)
  1408.                             .getTextContent() + "\t\t\t\t";
  1409.             i++;
  1410.         }
  1411.  
  1412.         return myNews;
  1413.     }
  1414.  
  1415.     private Document convertNewsStringToDocument(String src) {
  1416.  
  1417.         Document dest = null;
  1418.         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  1419.         DocumentBuilder parser;
  1420.  
  1421.         try {
  1422.             parser = dbFactory.newDocumentBuilder();
  1423.             dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
  1424.         } catch (ParserConfigurationException e1) {
  1425.             e1.printStackTrace();
  1426.         } catch (SAXException e) {
  1427.             e.printStackTrace();
  1428.         } catch (IOException e) {
  1429.             e.printStackTrace();
  1430.         }
  1431.  
  1432.         return dest;
  1433.     }
  1434.  
  1435.     private String queryNews() {
  1436.  
  1437.         String qResult = "";
  1438.         String queryString = rss;
  1439.  
  1440.         HttpClient httpClient = new DefaultHttpClient();
  1441.         HttpGet httpGet = new HttpGet(queryString);
  1442.  
  1443.         try {
  1444.             HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
  1445.  
  1446.             if (httpEntity != null) {
  1447.                 InputStream inputStream = httpEntity.getContent();
  1448.                 Reader in = new InputStreamReader(inputStream);
  1449.                 BufferedReader bufferedreader = new BufferedReader(in);
  1450.                 StringBuilder stringBuilder = new StringBuilder();
  1451.  
  1452.                 String stringReadLine = null;
  1453.  
  1454.                 while ((stringReadLine = bufferedreader.readLine()) != null) {
  1455.                     stringBuilder.append(stringReadLine + "\n");
  1456.                 }
  1457.  
  1458.                 qResult = stringBuilder.toString();
  1459.             }
  1460.         } catch (ClientProtocolException e) {
  1461.             e.printStackTrace();
  1462.         } catch (IOException e) {
  1463.             e.printStackTrace();
  1464.         }
  1465.  
  1466.         return qResult;
  1467.     }
  1468.  
  1469.     public String windDir(String deg) {
  1470.         String dir = null;
  1471.         InputStream inputStream = null;
  1472.         String finalDIR = null;
  1473.         JSONObject jObject;
  1474.         JSONArray direction;
  1475.  
  1476.         String confAPI = lastIntent.getStringExtra("URL")
  1477.                 + "/api.php?kind=wind&deg=" + deg;
  1478.         ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
  1479.         try {
  1480.  
  1481.             HttpClient httpClient = new DefaultHttpClient();
  1482.             HttpPost httpPost = new HttpPost(confAPI);
  1483.             httpPost.setEntity(new UrlEncodedFormEntity(param));
  1484.             HttpResponse httpResponse = httpClient.execute(httpPost);
  1485.             HttpEntity httpEntity = httpResponse.getEntity();
  1486.             inputStream = httpEntity.getContent();
  1487.  
  1488.             BufferedReader bReader = new BufferedReader(new InputStreamReader(
  1489.                     inputStream, "iso-8859-1"), 8);
  1490.             StringBuilder sBuilder = new StringBuilder();
  1491.  
  1492.             String line = null;
  1493.             while ((line = bReader.readLine()) != null) {
  1494.                 sBuilder.append(line + "\n");
  1495.             }
  1496.  
  1497.             dir = sBuilder.toString();
  1498.             jObject = new JSONObject(dir);
  1499.             direction = jObject.getJSONArray("Direction");
  1500.             // The next few lines are slop. I need to change this to use the JSON parser...
  1501.             finalDIR = direction.toString().replaceAll("\"", "");
  1502.             finalDIR = finalDIR.replace("[", "");
  1503.             finalDIR = finalDIR.replace("]", "");
  1504.             System.out.println("Debug: Wind direction is " + finalDIR);
  1505.  
  1506.         } catch (Exception e) {
  1507.             e.printStackTrace();
  1508.         }
  1509.         return finalDIR;
  1510.     }
  1511.  
  1512.     private Weather parseWeather(Document srcDoc) {
  1513.         int currentCode;
  1514.         Weather myWeather = new Weather();
  1515.  
  1516.         // <description>Yahoo! Weather for New York, NY</description>
  1517.         // myWeather.description = "Current Weather: Troy NY";
  1518.  
  1519.         myWeather.description = srcDoc.getElementsByTagName("description")
  1520.                 .item(0).getTextContent();
  1521.  
  1522.         // <yweather:location.../>
  1523.  
  1524.         Node locationNode = srcDoc.getElementsByTagName("yweather:location")
  1525.                 .item(0);
  1526.         myWeather.city = locationNode.getAttributes().getNamedItem("city")
  1527.                 .getNodeValue().toString();
  1528.         myWeather.region = locationNode.getAttributes().getNamedItem("region")
  1529.                 .getNodeValue().toString();
  1530.         myWeather.country = locationNode.getAttributes()
  1531.                 .getNamedItem("country").getNodeValue().toString();
  1532.  
  1533.         // <yweather:condition.../>
  1534.         Node conditionNode = srcDoc.getElementsByTagName("yweather:condition")
  1535.                 .item(0);
  1536.         myWeather.conditiontext = conditionNode.getAttributes()
  1537.                 .getNamedItem("text").getNodeValue().toString();
  1538.         myWeather.conditiondate = conditionNode.getAttributes()
  1539.                 .getNamedItem("date").getNodeValue().toString();
  1540.         currentCode = Integer
  1541.                 .valueOf(myWeather.conditioncode = conditionNode
  1542.                         .getAttributes().getNamedItem("code").getNodeValue()
  1543.                         .toString());
  1544.         System.out.println("Debug: Weather code is " + currentCode + ".");
  1545.         setWeatherIcon(currentCode);
  1546.  
  1547.         // <yweather:wind.../>
  1548.         Node windNode = srcDoc.getElementsByTagName("yweather:wind").item(0);
  1549.         myWeather.windChill = windNode.getAttributes().getNamedItem("chill")
  1550.                 .getNodeValue().toString();
  1551.  
  1552.         myWeather.windDirection = windDir(windNode.getAttributes()
  1553.                 .getNamedItem("direction").getNodeValue().toString());
  1554.         myWeather.windSpeed = windNode.getAttributes().getNamedItem("speed")
  1555.                 .getNodeValue().toString();
  1556.  
  1557.         // <yweather:astronomy.../>
  1558.         Node astronomyNode = srcDoc.getElementsByTagName("yweather:astronomy")
  1559.                 .item(0);
  1560.         myWeather.sunrise = astronomyNode.getAttributes()
  1561.                 .getNamedItem("sunrise").getNodeValue().toString();
  1562.         myWeather.sunset = astronomyNode.getAttributes().getNamedItem("sunset")
  1563.                 .getNodeValue().toString();
  1564.         // forecast info
  1565.         Node forecastNode1 = srcDoc.getElementsByTagName("yweather:forecast")
  1566.                 .item(0);
  1567.         myWeather.day1 = "\t\t"
  1568.                 + forecastNode1.getAttributes().getNamedItem("day")
  1569.                         .getNodeValue().toString()
  1570.                 + ": "
  1571.                 + forecastNode1.getAttributes().getNamedItem("high")
  1572.                         .getNodeValue().toString()
  1573.                 + (char) 0x00B0
  1574.                 + "F "
  1575.                 + forecastNode1.getAttributes().getNamedItem("text")
  1576.                         .getNodeValue().toString() + "\n";
  1577.  
  1578.         Node forecastNode2 = srcDoc.getElementsByTagName("yweather:forecast")
  1579.                 .item(1);
  1580.  
  1581.         myWeather.day2 = "\t\t"
  1582.                 + forecastNode2.getAttributes().getNamedItem("day")
  1583.                         .getNodeValue().toString()
  1584.                 + ": "
  1585.                 + forecastNode2.getAttributes().getNamedItem("high")
  1586.                         .getNodeValue().toString()
  1587.                 + (char) 0x00B0
  1588.                 + "F "
  1589.                 + forecastNode2.getAttributes().getNamedItem("text")
  1590.                         .getNodeValue().toString() + "\n";
  1591.  
  1592.         Node forecastNode3 = srcDoc.getElementsByTagName("yweather:forecast")
  1593.                 .item(2);
  1594.  
  1595.         myWeather.day3 = "\t\t"
  1596.                 + forecastNode3.getAttributes().getNamedItem("day")
  1597.                         .getNodeValue().toString()
  1598.                 + ": "
  1599.                 + forecastNode3.getAttributes().getNamedItem("high")
  1600.                         .getNodeValue().toString()
  1601.                 + (char) 0x00B0
  1602.                 + "F "
  1603.                 + forecastNode3.getAttributes().getNamedItem("text")
  1604.                         .getNodeValue().toString() + "\n";
  1605.  
  1606.         Node forecastNode4 = srcDoc.getElementsByTagName("yweather:forecast")
  1607.                 .item(3);
  1608.  
  1609.         myWeather.day4 = "\t\t"
  1610.                 + forecastNode4.getAttributes().getNamedItem("day")
  1611.                         .getNodeValue().toString()
  1612.                 + ": "
  1613.                 + forecastNode4.getAttributes().getNamedItem("high")
  1614.                         .getNodeValue().toString()
  1615.                 + (char) 0x00B0
  1616.                 + "F "
  1617.                 + forecastNode4.getAttributes().getNamedItem("text")
  1618.                         .getNodeValue().toString() + "\n";
  1619.  
  1620.         Node forecastNode5 = srcDoc.getElementsByTagName("yweather:forecast")
  1621.                 .item(4);
  1622.  
  1623.         myWeather.day5 = "\t\t"
  1624.                 + forecastNode5.getAttributes().getNamedItem("day")
  1625.                         .getNodeValue().toString()
  1626.                 + ": "
  1627.                 + forecastNode5.getAttributes().getNamedItem("high")
  1628.                         .getNodeValue().toString()
  1629.                 + (char) 0x00B0
  1630.                 + "F "
  1631.                 + forecastNode5.getAttributes().getNamedItem("text")
  1632.                         .getNodeValue().toString() + "\n";
  1633.  
  1634.         forecast = "\t\t" + myWeather.day1 + myWeather.day2 + myWeather.day3
  1635.                 + myWeather.day4 + myWeather.day5 + "\t\t";
  1636.  
  1637.         return myWeather;
  1638.     }
  1639.  
  1640.     private void startWeatherThread() {
  1641.         bgThread = new Thread(new Runnable() {
  1642.             public void run() {
  1643.                 while (visible == 1) {
  1644.                     weatherString = queryWeather();
  1645.                     weatherDoc = convertStringToDocument(weatherString);
  1646.                     final Weather weatherResult = parseWeather(weatherDoc);
  1647.                     runOnUiThread(new Runnable() {
  1648.                         @Override
  1649.                         public void run() {
  1650.                             weatherTV.invalidate();
  1651.                             weatherTV.setText(weatherResult.toString());
  1652.                             Picasso.with(getBaseContext()).load(weatherImg)
  1653.                                     .error(R.drawable.dunno).into(iv3);
  1654.                             forecastTV.invalidate();
  1655.                             forecastTV.setText(forecast);
  1656.                             forecastTV.setSelected(true);
  1657.                             System.out.println("Debug: Weather update.");
  1658.                         }
  1659.                     });
  1660.                     try {
  1661.                         Thread.sleep(600000);
  1662.                     } catch (InterruptedException e) {
  1663.                         e.printStackTrace();
  1664.                     }
  1665.                 }
  1666.             }
  1667.         });
  1668.         bgThread.start();
  1669.     }
  1670.  
  1671.     private Document convertStringToDocument(String src) {
  1672.  
  1673.         Document dest = null;
  1674.         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  1675.         DocumentBuilder parser;
  1676.  
  1677.         try {
  1678.             parser = dbFactory.newDocumentBuilder();
  1679.             dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
  1680.         } catch (ParserConfigurationException e1) {
  1681.             e1.printStackTrace();
  1682.         } catch (SAXException e) {
  1683.             e.printStackTrace();
  1684.         } catch (IOException e) {
  1685.             e.printStackTrace();
  1686.         }
  1687.  
  1688.         return dest;
  1689.     }
  1690.  
  1691.     private void startNewsThread() {
  1692.         rssThread = new Thread(new Runnable() {
  1693.             public void run() {
  1694.                 while (visible == 1) {
  1695.                     newsString = queryNews();
  1696.                     newsDoc = convertNewsStringToDocument(newsString);
  1697.                     final News newsResult = parseNews(newsDoc);
  1698.                     runOnUiThread(new Runnable() {
  1699.                         @Override
  1700.                         public void run() {
  1701.                             rssTV.invalidate();
  1702.                             rssTV.setText(newsResult.toString());
  1703.                             rssTV.setSelected(true);
  1704.                             System.out.println("Debug: News update.");
  1705.                         }
  1706.                     });
  1707.                     try {
  1708.                         Thread.sleep(600000);
  1709.                     } catch (InterruptedException e) {
  1710.                         e.printStackTrace();
  1711.                     }
  1712.                 }
  1713.             }
  1714.         });
  1715.         rssThread.start();
  1716.     }
  1717.  
  1718.     private void startWallpaperThread() {
  1719.         wpThread = new Thread(new Runnable() {
  1720.             public void run() {
  1721.                 while (visible == 1) {
  1722.                     try {
  1723.                         if (first) {
  1724.                             first = false;
  1725.                             mDoPOST = new DoPOST(Display.this, data);
  1726.                             mDoPOST.execute("");
  1727.                             Thread.sleep(Integer.valueOf(transition) * 1000);
  1728.                         } else {
  1729.                             Thread.sleep(Integer.valueOf(transition) * 1000);
  1730.                             mDoPOST = new DoPOST(Display.this, data);
  1731.                             mDoPOST.execute("");
  1732.                         }
  1733.                     } catch (InterruptedException e) {
  1734.                         e.printStackTrace();
  1735.                     }
  1736.                 }
  1737.             }
  1738.         });
  1739.         wpThread.start();
  1740.     }
  1741.  
  1742.     private String queryWeather() {
  1743.  
  1744.         String qResult = "";
  1745.         String queryString = getResources().getString(R.string.yahooWeatherAPI)
  1746.                 .toString() + lastIntent.getStringExtra("ZIP");
  1747.  
  1748.         HttpClient httpClient = new DefaultHttpClient();
  1749.         HttpGet httpGet = new HttpGet(queryString);
  1750.  
  1751.         try {
  1752.             HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
  1753.  
  1754.             if (httpEntity != null) {
  1755.                 InputStream inputStream = httpEntity.getContent();
  1756.                 Reader in = new InputStreamReader(inputStream);
  1757.                 BufferedReader bufferedreader = new BufferedReader(in);
  1758.                 StringBuilder stringBuilder = new StringBuilder();
  1759.  
  1760.                 String stringReadLine = null;
  1761.  
  1762.                 while ((stringReadLine = bufferedreader.readLine()) != null) {
  1763.                     stringBuilder.append(stringReadLine + "\n");
  1764.                 }
  1765.  
  1766.                 qResult = stringBuilder.toString();
  1767.             }
  1768.         } catch (ClientProtocolException e) {
  1769.             e.printStackTrace();
  1770.         } catch (IOException e) {
  1771.             e.printStackTrace();
  1772.         }
  1773.  
  1774.         return qResult;
  1775.     }
  1776.  
  1777.     // use our icons based on yahoo weather code.
  1778.     public void setWeatherIcon(int currentCode) {
  1779.         // using switch-case fall through to keep things short and neat.
  1780.         switch (currentCode) {
  1781.         // t-storm 3
  1782.         case 0:
  1783.         case 1:
  1784.         case 2:
  1785.         case 3:
  1786.         case 4:
  1787.             weatherImg = R.drawable.tstorm3;
  1788.             break;
  1789.         // sleet
  1790.         case 5:
  1791.         case 6:
  1792.         case 7:
  1793.         case 8:
  1794.         case 10:
  1795.         case 18:
  1796.             weatherImg = R.drawable.sleet;
  1797.             break;
  1798.         // light rain
  1799.         case 9:
  1800.             weatherImg = R.drawable.light_rain;
  1801.             break;
  1802.         // shower 3
  1803.         case 11:
  1804.         case 12:
  1805.             weatherImg = R.drawable.shower3;
  1806.             break;
  1807.         // snow 4
  1808.         case 13:
  1809.         case 14:
  1810.         case 15:
  1811.         case 46:
  1812.             weatherImg = R.drawable.snow4;
  1813.             break;
  1814.         // snow 5
  1815.         case 16:
  1816.             weatherImg = R.drawable.snow5;
  1817.             break;
  1818.         // hail
  1819.         case 17:
  1820.         case 35:
  1821.             weatherImg = R.drawable.hail;
  1822.             break;
  1823.         // mist
  1824.         case 19:
  1825.         case 21:
  1826.             weatherImg = R.drawable.mist;
  1827.             break;
  1828.         // fog
  1829.         case 20:
  1830.         case 22:
  1831.             weatherImg = R.drawable.fog;
  1832.             break;
  1833.         // sunny
  1834.         case 23:
  1835.         case 24:
  1836.         case 25:
  1837.         case 32:
  1838.         case 34:
  1839.         case 36:
  1840.             weatherImg = R.drawable.sunny;
  1841.             break;
  1842.         // overcast
  1843.         case 26:
  1844.             weatherImg = R.drawable.overcast;
  1845.             break;
  1846.         // cloudy 4 night
  1847.         case 27:
  1848.             weatherImg = R.drawable.cloudy4_night;
  1849.             break;
  1850.         // cloudy 4
  1851.         case 28:
  1852.             weatherImg = R.drawable.cloudy4;
  1853.             break;
  1854.         // cloudy 1 night
  1855.         case 29:
  1856.             weatherImg = R.drawable.cloudy1_night;
  1857.             break;
  1858.         // cloudy 1
  1859.         case 30:
  1860.             weatherImg = R.drawable.cloudy1;
  1861.             break;
  1862.         // suny night
  1863.         case 31:
  1864.         case 33:
  1865.             weatherImg = R.drawable.sunny_night;
  1866.             break;
  1867.         // tstorm 2
  1868.         case 37:
  1869.         case 38:
  1870.         case 39:
  1871.         case 45:
  1872.         case 47:
  1873.             weatherImg = R.drawable.tstorm2;
  1874.             break;
  1875.         // shower 1
  1876.         case 40:
  1877.             weatherImg = R.drawable.shower1;
  1878.             break;
  1879.         // snow 5
  1880.         case 41:
  1881.         case 43:
  1882.             weatherImg = R.drawable.snow5;
  1883.             break;
  1884.         // snow 3
  1885.         case 42:
  1886.             weatherImg = R.drawable.snow3;
  1887.             break;
  1888.         // cloudy 2
  1889.         case 44:
  1890.             weatherImg = R.drawable.cloudy2;
  1891.             break;
  1892.         // not sure
  1893.         case 3200:
  1894.             weatherImg = R.drawable.dunno;
  1895.             break;
  1896.  
  1897.         }
  1898.     }
  1899.  
  1900.     @Override
  1901.     public void onBackPressed() {
  1902.         finish();
  1903.     }
  1904.  
  1905. }
Advertisement
Add Comment
Please, Sign In to add comment