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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| public class MainActivity extends SlidingActivity implements OnItemClickListener, OnClickListener{
private ArrayList<Article> articles;
private ListView articlesList;
private TextView foot;
private TextView omnisport;
private TextView media;
private TextView rank;
private TextView program;
private TextView gall;
private TextView twitter;
private TextView fb;
private TextView yt;
private ImageView imgmenu;
private ImageView imginf;
private String[] data;
private String array_data;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_view);
init();
checkInternetConnection();
}
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
return true;
} else {
Log.v("wa makaynash connexion a sahbé :s", null);
return false;
}
}
private void init() {
foot=(TextView)findViewById(R.textviews.txtFoot);
foot.setOnClickListener(this);
yt=(TextView)findViewById(R.textviews.txtytb);
yt.setOnClickListener(this);
fb=(TextView)findViewById(R.textviews.txtfb);
fb.setOnClickListener(this);
twitter=(TextView)findViewById(R.textviews.txttw);
twitter.setOnClickListener(this);
gall=(TextView)findViewById(R.textviews.txtgal);
gall.setOnClickListener(this);
omnisport=(TextView)findViewById(R.textviews.txtOmnisport);
omnisport.setOnClickListener(this);
program=(TextView)findViewById(R.textviews.txtprog);
program.setOnClickListener(this);
media=(TextView)findViewById(R.textviews.txtmedia);
media.setOnClickListener(this);
rank=(TextView)findViewById(R.textviews.txtclass);
rank.setOnClickListener(this);
imgmenu =(ImageView)findViewById(R.imageviews.imgMenu);
imgmenu.setOnClickListener(this);
imginf =(ImageView)findViewById(R.imageviews.imgInfo);
imginf.setOnClickListener(this);
articlesList = (ListView) findViewById(R.listviews.wnlist);
articlesList.setOnItemClickListener(this);
new FetchRecentPosts().execute();
}
class FetchRecentPosts extends AsyncTask<Void, Void, Void> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
}
@Override
protected Void doInBackground(Void... params) {
articles = Services.getRecentPosts();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for (Article article : articles) {
System.out.println(article.getTitle());
}
progressDialog.dismiss();
ArticlesAdapter adapter = new ArticlesAdapter(MainActivity.this, R.layout.list_item, articles);
articlesList.setAdapter(adapter);
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Article selectedArticle = (Article) arg0.getItemAtPosition(arg2);
Intent intent = new Intent(this, ReadArticleActivity.class);
intent.putExtra("selectedArticle", selectedArticle);
startActivity(intent);
}
private void LoadPf(){
SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
Editor edit=sp.edit();
edit.putString("","");
edit.commit();
}
private void SavePf(String val1, String val2,String Val3, String val4){
SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
Editor edit=sp.edit();
edit.putString("","");
edit.commit();
}
@Override
public void onClick(View v) {
if(v.getId() == foot.getId()) {
new FetchRecentPosts().execute();
} else if(v.getId() == omnisport.getId() ){
Intent intent = new Intent(MainActivity.this,OmniSports.class);
startActivity(intent);
SavePf("","","","");
this.finish();
} else if(v.getId() == media.getId() ){
Intent intent = new Intent(MainActivity.this,WydadTv.class);
startActivity(intent);
this.finish();
} else if(v.getId() == program.getId() ){
Intent intent = new Intent(MainActivity.this,ProgramActivity.class);
startActivity(intent);
this.finish();
}else if(v.getId() == gall.getId() ){
Intent intent = new Intent(MainActivity.this,Gallery_Activity.class);
startActivity(intent);
} else if(v.getId() == rank.getId() ){
Intent intent = new Intent(MainActivity.this,RankingActivity.class);
startActivity(intent);
this.finish();
} else if(v.getId() == imginf.getId() ){
Intent intent = new Intent(MainActivity.this,About.class);
startActivity(intent);
} else if(v.getId() == fb.getId() ){
Intent intent = new Intent(MainActivity.this,FbActivity.class);
startActivity(intent);
} else if(v.getId() == yt.getId() ){
Intent intent = new Intent(MainActivity.this,YoutubeActivity.class);
startActivity(intent);
} else if(v.getId() == twitter.getId() ){
Intent intent = new Intent(MainActivity.this,TwitterActivity.class);
startActivity(intent);
} else if(v.getId() == imgmenu.getId()) {
getSlidingMenu().toggle();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
} |
Partager