- package mx.unam.tulmovil; 
-   
- import java.util.ArrayList; 
-   
- import org.json.JSONException; 
-   
- import android.app.Activity; 
- import android.app.AlertDialog; 
- import android.app.ProgressDialog; 
- import android.content.Context; 
- import android.content.DialogInterface; 
- import android.content.Intent; 
-   
- import android.net.ConnectivityManager; 
- import android.os.Bundle; 
- import android.os.Handler; 
- import android.os.Looper; 
- import android.os.Message; 
- import android.util.Log; 
- import android.view.View; 
- import android.view.View.OnClickListener; 
- import android.widget.AdapterView; 
- import android.widget.AdapterView.OnItemClickListener; 
- import android.widget.Button; 
- import android.widget.ImageButton; 
- import android.widget.LinearLayout; 
- import android.widget.ListView; 
- import android.widget.Toast; 
-   
-     /** Called when the activity is first created. */ 
-      
-     private AdapterCategorias categorias; 
-     private AdapterNoticias noticias; 
-     private ArrayList<Categoria> itemsCategorias; 
-     private ProgressDialog progreso; 
-     private JSONData webService; 
-     private Toast msj; 
-      
-     private LinearLayout principal; 
-     private LinearLayout conexion; 
-     private ImageButton opciones; 
-     private Acciones accion; 
-     @Override 
-     public void onCreate(Bundle savedInstanceState) { 
-         super.onCreate(savedInstanceState); 
-         setContentView(R.layout.main); 
-         try{ 
-              
-             principal=(LinearLayout) findViewById(R.id.lycontenidoprincipal); 
-             conexion=(LinearLayout) findViewById(R.id.lyconexion); 
-   
-             //this.mostrarPrincipal(); 
-             this.obtenerCategorias(); 
-              
-             opciones=(ImageButton) findViewById(R.id.btnopciones); 
-             opciones.setOnClickListener(opcionesListener); 
-             categorias.notifyDataSetChanged(); 
-             listaCat =(ListView)-  findViewById (- R. id- . categorias);
-             listaCat.setAdapter(categorias); 
-             listaCat.setOnItemClickListener(new OnItemClickListener() { 
-   
-                 public void-  onItemClick (- AdapterView <?>-  adapter,  View-  view,  int-  position, long-  id ) {
 
-                     // TODO Auto-generated method stub 
-                       //startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("vnd.youtube:"+lista.videos.get(position).getUrl()))); 
-                 } 
-             }); 
-           
-          
-             // TODO: handle exception 
-         } 
-     } 
-      
-     public boolean-  detectarConexion (Context-  ctx ){
 
-         try{ 
-          ConnectivityManager cm  = (- ConnectivityManager )-  ctx. getSystemService(Context- . CONNECTIVITY_SERVICE);
-          return cm.getActiveNetworkInfo().isConnectedOrConnecting(); 
-              return false; 
-          } 
-     } 
-      
-     private void mostrarPrincipal(){ 
-         if(this.detectarConexion(this)){ 
-            progreso=ProgressDialog.show(this, "UNAM en YouTube", "Cargando...",true); 
-          
-           spin.start(); 
-         }else{ 
-             principal.setVisibility(LinearLayout.GONE); 
-             conexion.setVisibility(LinearLayout.VISIBLE); 
-             btnreintentar =(Button)-  findViewById (- R. id- . btnreintentar);
-             btnreintentar.setOnClickListener(reintentarListener); 
-         } 
-     } 
-   
-     public void run() { 
-         // TODO Auto-generated method stub 
-         this.obtenerPrincipal(); 
-     } 
-      
-     public void obtenerPrincipal(){ 
-         try{ 
-             Looper.prepare(); 
-              
-             this.obtenerCategorias(); 
-             cargarListas.sendEmptyMessage(0); 
-             Looper.loop(); 
-             Looper.myLooper().quit(); 
-              
-             // TODO: handle exception 
-         } 
-     } 
-      
-     public void-  obtenerCategorias () throws-  JSONException,  Exception{
 
-         webService=new JSONData("http://gama.dgsca.unam.mx/iunamdev/movil/webservice/webserviceCategorias.php"); 
-         itemsCategorias=webService.getListaCategorias(); 
-         categorias=new AdapterCategorias(this,itemsCategorias); 
-     } 
-      
-     private Handler cargarListas= new Handler(){ 
-         public void handleMessage(Message msg){ 
-              
-             conexion.setVisibility(LinearLayout.GONE); 
-             principal.setVisibility(LinearLayout.VISIBLE); 
-             accion=new Acciones(); 
-             opciones=(ImageButton) findViewById(R.id.btnopciones); 
-             opciones.setOnClickListener(opcionesListener); 
-             categorias.notifyDataSetChanged(); 
-             listaCat =(ListView)-  findViewById (- R. id- . categorias);
-             listaCat.setAdapter(categorias); 
-             listaCat.setOnItemClickListener(new OnItemClickListener() { 
-   
-                 public void-  onItemClick (- AdapterView <?>-  adapter,  View-  view,  int-  position, long-  id ) {
 
-                     // TODO Auto-generated method stub 
-                       //startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("vnd.youtube:"+lista.videos.get(position).getUrl()))); 
-                 } 
-             }); 
-             progreso.dismiss(); 
-         } 
-     }; 
-      
-     private OnClickListener reintentarListener=new OnClickListener() { 
-          
-         public void-  onClick (View-  v ) {
 
-             // TODO Auto-generated method stub 
-             mostrarPrincipal(); 
-         } 
-     }; 
-      
-     private OnClickListener opcionesListener=new OnClickListener() { 
-          
-         public void-  onClick (View-  v ) {
 
-             // TODO Auto-generated method stub 
-             //accion.mostrarOpciones(Principal.this); 
-             crearDialogoSeleccion(); 
-         } 
-     }; 
-      
-     private void crearDialogoSeleccion() 
-     { 
-         final String[]-  items  = {"Enviar Sugerencia"- ,  "Recomendaciones"};
 
-       
-         AlertDialog.Builder builder = new AlertDialog.Builder(this); 
-       
-         builder.setTitle("Selección"); 
-         builder.setItems(items, new DialogInterface.OnClickListener() { 
-             public void onClick(DialogInterface dialog, int item) { 
-                 if(items[item].equals("Enviar Sugerencia")) 
-                     enviarMail(); 
-                 else if(items[item].equals("Recomendaciones")) 
-                     Log.i("opcion seleccionada","Mostrar recomendaciones"); 
-             } 
-         }); 
-       
-         builder.create(); 
-         builder.show(); 
-     } 
-      
-     private void enviarMail(){ 
-         Intent correo = new Intent(Intent.ACTION_SEND); 
-         /*String contenido="Sugerencia o comentario enviado por:\n\nSugerencia:\n\n"; 
-         correo.setType("plain/text"); 
-         correo.putExtra(Intent.EXTRA_EMAIL, new String[] {mail}); 
-         correo.putExtra(Intent.EXTRA_TEXT, contenido); 
-         setResult(RESULT_OK, correo);*/ 
-         startActivity(correo); 
-     } 
-      
- }