1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
package com.andreani;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class andreani extends Activity {
public static RssItem selectedRssItem = null;
String feedUrl = "http://andre-ani.fr/feed";
ListView rssListView = null;
ArrayAdapter<RssItem> aa = null;
ArrayList<RssItem> rssItems = RssItem.getRssItems(feedUrl);
public static final int RssItemDialog = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
//
// ajout menu
//
//Méthode qui se déclenchera lorsque vous appuierez sur le bouton menu du téléphone
public boolean onCreateOptionsMenu(Menu menu) {
//Création d'un MenuInflater qui va permettre d'instancier un Menu XML en un objet Menu
MenuInflater inflater = getMenuInflater();
//Instanciation du menu XML spécifier en un objet Menu
inflater.inflate(R.layout.menu, menu);
//Il n'est pas possible de modifier l'icône d'en-tête du sous menu via le fichier XML on le fait donc en JAVA
menu.getItem(0).getSubMenu().setHeaderIcon(R.drawable.option_white);
return true;
}
//Méthode qui se déclenchera au clic sur un item
public boolean onOptionsItemSelected(MenuItem item) {
//On regarde quel item a été cliqué grâce à son id et on déclenche une action
switch (item.getItemId()) {
case R.id.option:
Toast.makeText(andreani.this, "Option", Toast.LENGTH_SHORT).show();
return true;
case R.id.favoris:
Toast.makeText(andreani.this, "Favoris", Toast.LENGTH_SHORT).show();
return true;
case R.id.quitter:
//Pour fermer l'application il suffit de faire finish()
finish();
return true;
}
return false;}
}
//
// fin menu
//
// get the listview from layout.xml
rssListView = (ListView) findViewById(R.id.rssListView);
// here we specify what to execute when individual list items clicked
rssListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View view, int index,
long arg3) {
selectedRssItem = rssItems.get(index);
Intent intent = new Intent(getBaseContext(), Affiche.class);
String lien = rssItems.get(index).getLink().toString();
intent.putExtra("UrlString", lien);
startActivity(intent);
}
});
aa = new ArrayAdapter<RssItem>(this, R.layout.list_item, rssItems);
rssListView.setAdapter(aa);
refressRssList();
}
protected Dialog onCreateDialog(int id, Bundle args) {
// TODO Auto-generated method stub
switch (id) {
case RssItemDialog: {
LayoutInflater li = LayoutInflater.from(this);
View rssDetails = li.inflate(R.layout.rss_details, null);
AlertDialog.Builder rssDialog = new AlertDialog.Builder(this);
rssDialog.setTitle("Article");
rssDialog.setView(rssDetails);
return rssDialog.create();
}
}
return null;
}
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
// TODO Auto-generated method stub
switch (id) {
case RssItemDialog: {
AlertDialog rssDialog = (AlertDialog) dialog;
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd - hh:mm:ss");
rssDialog.setTitle(selectedRssItem.getTitle() + " : "
+ sdf.format(selectedRssItem.getPubDate()));
String text = selectedRssItem.getDescription() + " : "
+ selectedRssItem.getLink();
TextView tv = (TextView) rssDialog
.findViewById(R.id.rssDetailsTextView);
tv.setText(text);
}
}
}
private void refressRssList() {
ArrayList<RssItem> newItems = RssItem.getRssItems(feedUrl);
rssItems.clear();
rssItems.addAll(newItems);
aa.notifyDataSetChanged();
}
} |