Advertisement
Guest User

Dont Click On this

a guest
Mar 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 KB | None | 0 0
  1. You Smell Whore
  2.  
  3.  
  4. Main
  5. import android.app.ListActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.ArrayAdapter;
  10. import android.widget.Button;
  11. import android.widget.ListView;
  12. import android.widget.RadioButton;
  13. import android.widget.ViewFlipper;
  14.  
  15. import java.util.ArrayList;
  16. import android.support.v7.app.AppCompatActivity;
  17. import android.os.Bundle;
  18. import android.app.ListActivity;
  19. import android.os.Bundle;
  20. import android.util.Log;
  21. import android.view.View;
  22. import android.view.View.OnClickListener;
  23. import android.widget.ArrayAdapter;
  24. import android.widget.Button;
  25. import android.widget.ListView;
  26. import android.widget.RadioButton;
  27. import android.widget.Toast;
  28. import android.widget.ViewFlipper;
  29. import android.widget.ViewSwitcher;
  30. import java.util.ArrayList;
  31.  
  32. public class MainActivity extends ListActivity {
  33.  
  34. RadioButton RB0;
  35. RadioButton RB1;
  36. RadioButton RB2;
  37. ViewFlipper VF;
  38. Button meme;
  39. ListView jeff, sus;
  40.  
  41.  
  42. @Override
  43. protected void onCreate(Bundle savedInstanceState) {
  44. super.onCreate(savedInstanceState);
  45. setContentView(R.layout.activity_main);
  46. Log.e(getPackageName(), "just before avw");
  47. //avw = (ViewSwitcher) findViewById(R.id.vwSwitch);
  48. RB0 = (RadioButton) findViewById(R.id.radio0);
  49. RB1 = (RadioButton) findViewById(R.id.radio1);
  50. RB2 = (RadioButton) findViewById(R.id.radio2);
  51. VF = (ViewFlipper) findViewById(R.id.ViewFlipper01);
  52. meme = (Button) findViewById(R.id.memes);
  53. jeff = (ListView) findViewById(R.id.jeff);
  54. //sus = (ListView) findViewById(R.id.jeff);
  55.  
  56. RB0.setOnClickListener(radio_listener);
  57. RB1.setOnClickListener(radio_listener);
  58. RB2.setOnClickListener(radio_listener);
  59.  
  60.  
  61. ArrayList<String> headlines = new ArrayList<>();
  62. RetrieveFeed getXML = new RetrieveFeed();
  63. getXML.execute();
  64. headlines = getXML.heads();
  65.  
  66. /* ArrayList<String> headlines1 = new ArrayList<>();
  67. RetrieveFeed2 getXML1 = new RetrieveFeed2();
  68. getXML1.execute();
  69. headlines1 = getXML1.heads();
  70. ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines1);
  71. setListAdapter(adapter1);*/
  72.  
  73.  
  74. // Binding data
  75. ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines);
  76. setListAdapter(adapter);
  77. jeff.setAdapter(adapter);
  78.  
  79.  
  80. // handling onclick
  81. /* private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
  82. public void onItemClick(AdapterView parent, View v, int position, long id) {
  83. // Do something in response to the click
  84. }
  85. };
  86.  
  87. listView.setOnItemClickListener(mMessageClickedHandler);
  88. }*/
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /*
  96. ArrayList<String> headlines2 = new ArrayList<>();
  97. RetrieveFeed2 getXML2 = new RetrieveFeed2();
  98. getXML2.execute();
  99. headlines2 = getXML2.heads();
  100.  
  101. ArrayAdapter jof = new ArrayAdapter(this,android.R.layout.simple_list_item_2,headlines2);
  102. setListAdapter(jof);*/
  103. }
  104.  
  105.  
  106. private View.OnClickListener radio_listener = new View.OnClickListener() {
  107. public void onClick(View v) {
  108. switch (v.getId()) {
  109. case R.id.radio0:
  110. VF.setDisplayedChild(0);
  111.  
  112. break;
  113. case R.id.radio1:
  114. VF.setDisplayedChild(1);
  115.  
  116.  
  117. break;
  118. case R.id.radio2:
  119. VF.setDisplayedChild(2);//changed
  120.  
  121. break;
  122. }
  123. }
  124. };
  125. }
  126.  
  127. RetrieveFeed
  128. import android.app.Activity;
  129. import android.os.AsyncTask;
  130. import org.xmlpull.v1.XmlPullParser;
  131. import org.xmlpull.v1.XmlPullParserException;
  132. import org.xmlpull.v1.XmlPullParserFactory;
  133.  
  134.  
  135. import java.io.IOException;
  136. import java.io.InputStream;
  137.  
  138. import java.net.MalformedURLException;
  139. import java.net.URL;
  140.  
  141. import java.util.ArrayList;
  142. import java.util.Collections;
  143.  
  144. import javax.xml.parsers.DocumentBuilder;
  145. import javax.xml.parsers.DocumentBuilderFactory;
  146.  
  147. public class RetrieveFeed extends AsyncTask {
  148. String jeff = "";
  149. String jeff1 = "";
  150.  
  151. URL url;
  152. ArrayList<String> headlines = new ArrayList();
  153. ArrayList<String> links = new ArrayList();
  154. @Override
  155. protected Object doInBackground(Object[] objects) {
  156. // Initializing instance variables
  157.  
  158.  
  159. try {
  160. url = new URL("https://trafficscotland.org/rss/feeds/currentincidents.aspx");//changed to planned!!!
  161.  
  162. XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  163. factory.setNamespaceAware(false);
  164. XmlPullParser xpp = factory.newPullParser();
  165.  
  166. // We will get the XML from an input stream
  167. xpp.setInput(getInputStream(url), "UTF_8");
  168.  
  169. /* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
  170. * However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
  171. * As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
  172. * so we should skip the "<title>" tag which is a child of "<channel>" tag,
  173. * and take in consideration only "<title>" tag which is a child of "<item>"
  174. *
  175. * In order to achieve this, we will make use of a boolean variable.
  176. */
  177. boolean insideItem = false;
  178.  
  179. // Returns the type of current event: START_TAG, END_TAG, etc..
  180. int eventType = xpp.getEventType();
  181. while (eventType != XmlPullParser.END_DOCUMENT) {
  182. if (eventType == XmlPullParser.START_TAG) {
  183.  
  184. if (xpp.getName().equalsIgnoreCase("item")) {
  185. insideItem = true;
  186. } else if (xpp.getName().equalsIgnoreCase("title")) {
  187. if (insideItem)
  188. headlines.add(xpp.nextText()); //extract the headline
  189. } else if (xpp.getName().equalsIgnoreCase("description")) {
  190. if (insideItem)
  191. headlines.add(xpp.nextText());
  192. }else if (xpp.getName().equalsIgnoreCase("georss:point")) {
  193. headlines.add(xpp.nextText());//extract the link of article //you added Map in here!
  194. }
  195. } else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")) {
  196. insideItem = false;
  197. }
  198.  
  199. eventType = xpp.next(); //move to next element
  200. }
  201.  
  202. } catch (MalformedURLException e) {
  203. e.printStackTrace();
  204. } catch (XmlPullParserException e) {
  205. e.printStackTrace();
  206. } catch (IOException e) {
  207. e.printStackTrace();
  208. }
  209.  
  210. //System.out.println(headlines);
  211.  
  212.  
  213. /*String[] headlinesArr = new String[headlines.size()];
  214. for (int i = 0; i <headlines.size(); i++) {
  215. headlinesArr[i] = headlines.get(i);
  216. }
  217.  
  218. for (int i = 0; i <headlinesArr.length; i++){
  219. headlinesArr[i] = headlinesArr[i].replaceAll("<br>"," ");
  220. }
  221. Collections.replaceAll(headlines,"Scotland","LOOK HERE BIG MEMES SMOKE IT UP ");*/
  222. Collections.replaceAll(headlines,"<br />","LOOK HERE BIG MEMES SMOKE IT UP ");
  223. System.out.println("LOOK HERE!!!!!!!!!");
  224. System.out.println(headlines.toString());
  225. return headlines;
  226.  
  227.  
  228.  
  229. }
  230.  
  231.  
  232. public InputStream getInputStream(URL url) {
  233. try {
  234. return url.openConnection().getInputStream();
  235. } catch (IOException e) {
  236. return null;
  237. }
  238. }
  239.  
  240. public ArrayList<String> heads()
  241. {
  242. Collections.replaceAll(headlines,"a","LOOK HERE BIG MEMES SMOKE IT UP ");
  243. return headlines;
  244. }
  245.  
  246. }
  247.  
  248.  
  249. XML
  250.  
  251. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  252.  
  253. android:layout_width="fill_parent"
  254. android:layout_height="fill_parent"
  255. android:id="@+id/vwSwitch"
  256. >
  257. <LinearLayout
  258. android:layout_width="fill_parent"
  259. android:layout_height="fill_parent"
  260. android:orientation="vertical">
  261.  
  262. <RadioGroup android:id="@+id/radioGroup1"
  263. android:layout_width="wrap_content"
  264. android:layout_height="wrap_content">
  265. <RadioButton android:layout_height="wrap_content"
  266. android:id="@+id/radio0" android:layout_width="wrap_content"
  267. android:text="Current" android:checked="true"></RadioButton>
  268. <RadioButton android:layout_height="wrap_content"
  269. android:id="@+id/radio1" android:layout_width="wrap_content"
  270. android:text="Planned RoadWorks"></RadioButton>
  271. <RadioButton android:layout_height="wrap_content"
  272. android:id="@+id/radio2" android:layout_width="wrap_content"
  273. android:text="Search"></RadioButton>
  274. </RadioGroup>
  275.  
  276. <ViewFlipper android:id="@+id/ViewFlipper01"
  277. android:layout_width="wrap_content"
  278. android:layout_height="wrap_content">
  279. <!--adding views to ViewFlipper-->
  280. <ListView
  281. android:id="@+android:id/list"
  282. android:layout_width="fill_parent"
  283. android:layout_height="wrap_content"
  284. android:divider="#AB9B9F"
  285. android:dividerHeight="1dp"
  286. android:listSelector="#5EF905"
  287. >
  288. </ListView>
  289.  
  290. <ListView
  291. android:id="@+id/jeff"
  292. android:layout_width="fill_parent"
  293. android:layout_height="wrap_content"
  294. android:divider="#AB9B9F"
  295. android:dividerHeight="1dp"
  296. android:listSelector="#AB9B9F"
  297. >
  298. </ListView>
  299.  
  300. <Button
  301. android:id="@+id/memes"
  302. android:layout_width="match_parent"
  303. android:layout_height="wrap_content"
  304. android:text="Button" />
  305. <Button
  306. android:id="@+id/e"
  307. android:layout_width="match_parent"
  308. android:layout_height="wrap_content"
  309. android:text="Button" />
  310. />
  311.  
  312.  
  313.  
  314. </ViewFlipper>
  315. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement