package org.hirodana.libtool;
import org.hirodana.libtool.activity.PanierActivity;
import org.hirodana.libtool.activity.RechercheActivity;
import org.hirodana.libtool.sqLite.PanierSQLite;
import org.hirodana.libtool.sqLite.sQLiteAutocp;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.Toast;
/**
* Classe libtool.
* Dispose les onglets et le menu.
* Surchage de TabActivity
*
* @author Braque Romain
* @author Dubessy David
* @author Gros Hippolyte
* @author Payet Anas
* @version 1.0
*
*/
public class libtool extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
//Onglet recherche
Intent next = new Intent(this, RechercheActivity.class);
spec = tabHost.newTabSpec("Recherche").setIndicator("Recherche",
res.getDrawable(R.drawable.tab_recherche)).setContent(next);
tabHost.addTab(spec);
//Onglet Panier
next = new Intent().setClass(this, PanierActivity.class);
spec = tabHost.newTabSpec("Panier").setIndicator("Panier",
res.getDrawable(R.drawable.tab_panier)).setContent(next);
tabHost.addTab(spec);
// On ouvre par dfaut sur l'onglet RechercheActivity
tabHost.setCurrentTab(0);
//Pour la personnalisation des onglets
TabWidget tabWidget = getTabWidget();
for(int i = 0; i < tabWidget.getChildCount(); i++) {
RelativeLayout tabLayout = (RelativeLayout) tabWidget.getChildAt(i);
//tabLayout.setBackgroundDrawable(res.getDrawable(R.drawable.tab));
//tabLayout.setBackgroundColor();
}
}// Fin de onCreate
/*** Cration du menu */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu);
return true;
}
/** Mthode qui se dclenchera au clic sur un item du Menu */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Selon l'option choisie
switch (item.getItemId()) {
//On vide le panier
case R.id.videpanier:
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.videpanier, null);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setView(alertDialogView);
adb.setIcon(android.R.drawable.ic_dialog_alert);
adb.setTitle("Vider le panier ?");
adb.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
PanierSQLite bdd = new PanierSQLite(libtool.this);
bdd.open();
bdd.videCatalogue();
Toast.makeText(libtool.this, "Le panier a t vid", Toast.LENGTH_SHORT).show();
bdd.close();
}
});
adb.setNegativeButton("Non",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {}
});
adb.show();
return true;
// On informe
case R.id.propos:
// On instancie notre layout en tant que View
LayoutInflater factory2 = LayoutInflater.from(this);
final View alertDialogView2 = factory2.inflate(
R.layout.propos, null);
// Cration de l'AlertDialog
AlertDialog.Builder adb2 = new AlertDialog.Builder(this);
// On affecte la vue personnalise que l'on a cre notre AlertDialog
adb2.setView(alertDialogView2);
adb2.setIcon(R.drawable.interrogation);
adb2.setTitle("A propos");
adb2.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {}
});
adb2.show();
return true;
// On vide l'autocompltion
case R.id.vide:
sQLiteAutocp autocp = new sQLiteAutocp(this);
autocp.openDB();
autocp.videCache();
autocp.closeDB();
return true;
//rafraichir l'application
case R.id.refresh:
Intent intent = new Intent(this, libtool.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
//On quitte l'application
case R.id.quitter:
finish();
return true;
}
return false;
}// Fin de onOptionsItemSelected
}// Fin de libtool
|