Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You Smell Whore
- Main
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.RadioButton;
- import android.widget.ViewFlipper;
- import java.util.ArrayList;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.RadioButton;
- import android.widget.Toast;
- import android.widget.ViewFlipper;
- import android.widget.ViewSwitcher;
- import java.util.ArrayList;
- public class MainActivity extends ListActivity {
- RadioButton RB0;
- RadioButton RB1;
- RadioButton RB2;
- ViewFlipper VF;
- Button meme;
- ListView jeff, sus;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Log.e(getPackageName(), "just before avw");
- //avw = (ViewSwitcher) findViewById(R.id.vwSwitch);
- RB0 = (RadioButton) findViewById(R.id.radio0);
- RB1 = (RadioButton) findViewById(R.id.radio1);
- RB2 = (RadioButton) findViewById(R.id.radio2);
- VF = (ViewFlipper) findViewById(R.id.ViewFlipper01);
- meme = (Button) findViewById(R.id.memes);
- jeff = (ListView) findViewById(R.id.jeff);
- //sus = (ListView) findViewById(R.id.jeff);
- RB0.setOnClickListener(radio_listener);
- RB1.setOnClickListener(radio_listener);
- RB2.setOnClickListener(radio_listener);
- ArrayList<String> headlines = new ArrayList<>();
- RetrieveFeed getXML = new RetrieveFeed();
- getXML.execute();
- headlines = getXML.heads();
- /* ArrayList<String> headlines1 = new ArrayList<>();
- RetrieveFeed2 getXML1 = new RetrieveFeed2();
- getXML1.execute();
- headlines1 = getXML1.heads();
- ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines1);
- setListAdapter(adapter1);*/
- // Binding data
- ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines);
- setListAdapter(adapter);
- jeff.setAdapter(adapter);
- // handling onclick
- /* private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
- public void onItemClick(AdapterView parent, View v, int position, long id) {
- // Do something in response to the click
- }
- };
- listView.setOnItemClickListener(mMessageClickedHandler);
- }*/
- /*
- ArrayList<String> headlines2 = new ArrayList<>();
- RetrieveFeed2 getXML2 = new RetrieveFeed2();
- getXML2.execute();
- headlines2 = getXML2.heads();
- ArrayAdapter jof = new ArrayAdapter(this,android.R.layout.simple_list_item_2,headlines2);
- setListAdapter(jof);*/
- }
- private View.OnClickListener radio_listener = new View.OnClickListener() {
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.radio0:
- VF.setDisplayedChild(0);
- break;
- case R.id.radio1:
- VF.setDisplayedChild(1);
- break;
- case R.id.radio2:
- VF.setDisplayedChild(2);//changed
- break;
- }
- }
- };
- }
- RetrieveFeed
- import android.app.Activity;
- import android.os.AsyncTask;
- import org.xmlpull.v1.XmlPullParser;
- import org.xmlpull.v1.XmlPullParserException;
- import org.xmlpull.v1.XmlPullParserFactory;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Collections;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- public class RetrieveFeed extends AsyncTask {
- String jeff = "";
- String jeff1 = "";
- URL url;
- ArrayList<String> headlines = new ArrayList();
- ArrayList<String> links = new ArrayList();
- @Override
- protected Object doInBackground(Object[] objects) {
- // Initializing instance variables
- try {
- url = new URL("https://trafficscotland.org/rss/feeds/currentincidents.aspx");//changed to planned!!!
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
- factory.setNamespaceAware(false);
- XmlPullParser xpp = factory.newPullParser();
- // We will get the XML from an input stream
- xpp.setInput(getInputStream(url), "UTF_8");
- /* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
- * However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
- * As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
- * so we should skip the "<title>" tag which is a child of "<channel>" tag,
- * and take in consideration only "<title>" tag which is a child of "<item>"
- *
- * In order to achieve this, we will make use of a boolean variable.
- */
- boolean insideItem = false;
- // Returns the type of current event: START_TAG, END_TAG, etc..
- int eventType = xpp.getEventType();
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- if (xpp.getName().equalsIgnoreCase("item")) {
- insideItem = true;
- } else if (xpp.getName().equalsIgnoreCase("title")) {
- if (insideItem)
- headlines.add(xpp.nextText()); //extract the headline
- } else if (xpp.getName().equalsIgnoreCase("description")) {
- if (insideItem)
- headlines.add(xpp.nextText());
- }else if (xpp.getName().equalsIgnoreCase("georss:point")) {
- headlines.add(xpp.nextText());//extract the link of article //you added Map in here!
- }
- } else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")) {
- insideItem = false;
- }
- eventType = xpp.next(); //move to next element
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (XmlPullParserException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- //System.out.println(headlines);
- /*String[] headlinesArr = new String[headlines.size()];
- for (int i = 0; i <headlines.size(); i++) {
- headlinesArr[i] = headlines.get(i);
- }
- for (int i = 0; i <headlinesArr.length; i++){
- headlinesArr[i] = headlinesArr[i].replaceAll("<br>"," ");
- }
- Collections.replaceAll(headlines,"Scotland","LOOK HERE BIG MEMES SMOKE IT UP ");*/
- Collections.replaceAll(headlines,"<br />","LOOK HERE BIG MEMES SMOKE IT UP ");
- System.out.println("LOOK HERE!!!!!!!!!");
- System.out.println(headlines.toString());
- return headlines;
- }
- public InputStream getInputStream(URL url) {
- try {
- return url.openConnection().getInputStream();
- } catch (IOException e) {
- return null;
- }
- }
- public ArrayList<String> heads()
- {
- Collections.replaceAll(headlines,"a","LOOK HERE BIG MEMES SMOKE IT UP ");
- return headlines;
- }
- }
- XML
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/vwSwitch"
- >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
- <RadioGroup android:id="@+id/radioGroup1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <RadioButton android:layout_height="wrap_content"
- android:id="@+id/radio0" android:layout_width="wrap_content"
- android:text="Current" android:checked="true"></RadioButton>
- <RadioButton android:layout_height="wrap_content"
- android:id="@+id/radio1" android:layout_width="wrap_content"
- android:text="Planned RoadWorks"></RadioButton>
- <RadioButton android:layout_height="wrap_content"
- android:id="@+id/radio2" android:layout_width="wrap_content"
- android:text="Search"></RadioButton>
- </RadioGroup>
- <ViewFlipper android:id="@+id/ViewFlipper01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <!--adding views to ViewFlipper-->
- <ListView
- android:id="@+android:id/list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:divider="#AB9B9F"
- android:dividerHeight="1dp"
- android:listSelector="#5EF905"
- >
- </ListView>
- <ListView
- android:id="@+id/jeff"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:divider="#AB9B9F"
- android:dividerHeight="1dp"
- android:listSelector="#AB9B9F"
- >
- </ListView>
- <Button
- android:id="@+id/memes"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button" />
- <Button
- android:id="@+id/e"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Button" />
- />
- </ViewFlipper>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement