IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

Introducció

Aquesta aplicació serà una adaptació per a dispositius Android de la web http://www.iesebre.com/webfaltes/identifica.php que serveix per a que els professors portin un control de l'assistència de l'alumnat.

Enllaç als primers apunts realitzats corresponents a la primera part del projecte: Usuari:Andrescorazon/Webfaltes

Especificacions del programa

Informació de la que es disposa

  • Captures de pantalla realitzades a classe de l'aplicació actual de faltes.
  • Apunts del professor a aquesta wiki.
  • Suport a classe.

Objectius

  • Crear una pàgina inicial després del login de tipus Dashboard. Cal utilitzar al menys un recurs drawable que s'adapti a les diferents mides de pantalla. Vegeu Android resources.
  • Linkar la pàgina de Login amb el Dashboard utilitzant intents.
  • Crear una interfície utilitzant Action Bars.
  • Fer algun canvi a l'estil de l'Action Bar.
  • Implementar i demostrar que les tabs funcionen Ok al canviar l'orientació.
  • Utilitzar fragments (Android Fragments) per implementar la pestanya Passar llista:
  • Cal definir dos fragments:

Opcional

Breu explicació i justificació dels objectius assolits i dels no assolits

Problemes molt greus amb el Dashboard al incloure els ActionBars. La solució més ràpida hagués sigut fer el Dashboard un fragment per a incloure'l dins de l'activitat on hi han els Tabs i els fragments.

També destacar la falta de tenir al llistat d'alumnes la incorporació de forma dinàmica de les imatges dels diferents alumnes i també incloure mostrar els seus detalls al clicar.

Altres problemes no són esmentats per la falta de comprensió d'alguns detalls de la programació en Android i per no saber ajuntar totes els objectius dins d'un mateix projecte.

Codi Font

Login i dashboard

Activitys

Login

public class LoginActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setting default screen to login.xml
        setContentView(R.layout.login);
 
        TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
        
        Button btnLogin = (Button) findViewById(R.id.btnLogin);
        
        // Listening to login button event
        btnLogin.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View arg0) {
                //Starting a new Intent
                Intent login = new Intent(getApplicationContext(), DashboardDesignActivity.class);
                startActivity(login);
            }
        });
 
        // Listening to register new account link
        registerScreen.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
                // Switching to Register screen
                Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
                startActivity(i);
            }
        });
    }
}

Registre

public class RegisterActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set View to register.xml
        setContentView(R.layout.register);
 
        TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
 
        // Listening to Login Screen link
        loginScreen.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View arg0) {
                                // Closing registration screen
                // Switching to Login Screen/closing register screen
                finish();
            }
        });
    }
}

Dashboard

public class DashboardDesignActivity extends Activity {

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dashboard_layout);
 
        /**
         * Creating all buttons instances
         * */
        // Dashboard News feed button
        Button btn_passar_llista = (Button) findViewById(R.id.btn_passar_llista);
 
        // Dashboard Friends button
        Button btn_tutoria = (Button) findViewById(R.id.btn_tutoria);
 
        // Dashboard Messages button
        Button btn_alumnes_grups = (Button) findViewById(R.id.btn_alumnes_grups);
 
        // Dashboard Places button
        Button btn_informes = (Button) findViewById(R.id.btn_informes);
 
        /**
         * Handling all button click events
         * */
 
        // Listening to News Feed button click
        btn_passar_llista.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
                Intent i = new Intent(getApplicationContext(), PassarLlistaActivity.class);
                startActivity(i);
            }
        });
        
     // Listening Messages button click
        btn_tutoria.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
                Intent i = new Intent(getApplicationContext(), TutoriaActivity.class);
                startActivity(i);
            }
        });
 
        // Listening to Places button click
        btn_alumnes_grups.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
                Intent i = new Intent(getApplicationContext(), AlumnesGrupsActivity.class);
                startActivity(i);
            }
        });
 
        // Listening to Events button click
        btn_informes.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
                Intent i = new Intent(getApplicationContext(), InformesActivity.class);
                startActivity(i);
            }
        });
        
	}

}

Layouts

Login

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true">
  <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="#ffffff">
 
        <!--  Header Starts-->
        <LinearLayout android:id="@+id/header"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content"
    		android:background="@drawable/header"
    		android:paddingTop="5dip"
    		android:paddingBottom="5dip">
		</LinearLayout>
        <!--  Header Ends -->
 
        <!-- Footer Start -->
        <LinearLayout android:id="@+id/footer"
    		android:layout_width="fill_parent"
    		android:layout_height="50dip"
    		android:background="@layout/footer_repeat"
    		android:layout_alignParentBottom="true">
		</LinearLayout>
        <!-- Footer Ends -->
 
        <!-- Login Form -->
        <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:padding="10dip"
          android:layout_below="@id/header">
          <!--  Email Label -->
          <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372c24"
                android:text="Usuari"/>
          <EditText android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:layout_marginBottom="20dip"
                android:singleLine="true"/>
          <!--  Password Label -->
          <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372c24"
                android:text="Password"/>
          <EditText android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:singleLine="true"
                android:password="true"/>
          <!-- Login button -->
          <Button android:id="@+id/btnLogin"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dip"
                android:text="Entrar"/>
          <!-- Link to Registration Screen -->

          <TextView
              android:id="@+id/link_to_register"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginBottom="40dip"
              android:layout_marginTop="40dip"
              android:gravity="center"
              android:text="He olvidat la meva paraula de pas"
              android:textColor="#0b84aa"
              android:textSize="18dip" />

		</LinearLayout>
        <!-- Login Form Ends -->
 
  </RelativeLayout>
</ScrollView>

Registre

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true">
  <RelativeLayout 
  		android:layout_width="fill_parent"
  		android:layout_height="wrap_content" android:background="#fff">
  		
  		<!--  Header  Starts-->
  		<LinearLayout android:id="@+id/header"
  				android:layout_width="fill_parent"
  				android:layout_height="wrap_content"
  				android:background="@drawable/header"
  				android:paddingTop="5dip"
  				android:paddingBottom="5dip">
  		</LinearLayout>
  		<!--  Header Ends -->
  		
  		<!-- Footer Start -->
  		<LinearLayout android:id="@+id/footer"
  				android:layout_width="fill_parent"
  				android:layout_height="50dip"
  				android:background="@layout/footer_repeat"
  				android:layout_alignParentBottom="true">
  		</LinearLayout>
  		<!-- Footer Ends --> 
  		
  		<!-- Registration Form -->
		<LinearLayout
		  xmlns:android="http://schemas.android.com/apk/res/android"
		  android:orientation="vertical"
		  android:layout_width="match_parent"
		  android:layout_height="wrap_content"
		  android:padding="10dip"
		  android:layout_below="@id/header">
		  <!-- Full Name Label -->
		  <TextView android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:textColor="#372c24"
		  		android:text="Nom complert"/>
		  <EditText android:id="@+id/reg_fullname" 
		  		android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:layout_marginTop="5dip"
		  		android:singleLine="true"
		  		android:layout_marginBottom="20dip"/>
		  <!--  Email Label -->
		  <TextView android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:textColor="#372c24"
		  		android:text="Email"/>
		  <EditText android:id="@+id/reg_email" 
		  		android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:layout_marginTop="5dip"
		  		android:singleLine="true"
		  		android:layout_marginBottom="20dip"/>
		  <!-- Password Label -->
		  <TextView android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:textColor="#372c24"
		  		android:text="Password"/>
		  <EditText android:id="@+id/reg_password" 
		        android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:password="true"
		  		android:singleLine="true"
		  		android:layout_marginTop="5dip"/>
		  <!-- Register Button -->		
		  <Button android:id="@+id/btnRegister" 
		  		android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:layout_marginTop="10dip"
		  		android:text="Registrar un Nou Compte"/>
		  <!-- Link to Login Screen -->
		  <TextView android:id="@+id/link_to_login" 
		  		android:layout_width="fill_parent"
		  		android:layout_height="wrap_content"
		  		android:layout_marginTop="40dip"
		  		android:layout_marginBottom="40dip"
		  		android:text="Ja tinc un compte! Entrar aquí"
		  		android:gravity="center"
		  		android:textSize="18dip"
		  		android:textColor="#025f7c"/>
		    
		</LinearLayout>
  		<!-- Registration Form Ends -->
  		
  		
  </RelativeLayout>
</ScrollView>

Dashboard

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_root"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
        <!--  Header  Starts-->
  		<LinearLayout android:id="@+id/header"
  				android:layout_width="fill_parent"
  				android:layout_height="wrap_content"
  				android:background="@drawable/header"
  				android:paddingTop="5dip"
  				android:paddingBottom="5dip">
  		</LinearLayout>
  		<!--  Header Ends -->
 
        <!--  Include Fragmented dashboard -->
        <include layout="@layout/fragment_layout"/>  
 
        <!-- Footer Start -->
  		<LinearLayout android:id="@+id/footer"
  				android:layout_width="fill_parent"
  				android:layout_height="50dip"
  				android:background="@layout/footer_repeat">
  		</LinearLayout>
  		<!-- Footer Ends -->
 
</LinearLayout>

Estructura i disseny del dashboard

public class DashboardLayout extends ViewGroup {

	private static final int UNEVEN_GRID_PENALTY_MULTIPLIER = 10;
	 
    private int mMaxChildWidth = 0;
    private int mMaxChildHeight = 0;
 
    public DashboardLayout(Context context) {
        super(context, null);
    }
 
    public DashboardLayout(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
    }
 
    public DashboardLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
 
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        mMaxChildWidth = 0;
        mMaxChildHeight = 0;
 
        // Measure once to find the maximum child size.
 
        int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
                MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
        int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
                MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
 
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
 
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
 
            mMaxChildWidth = Math.max(mMaxChildWidth, child.getMeasuredWidth());
            mMaxChildHeight = Math.max(mMaxChildHeight, child.getMeasuredHeight());
        }
 
        // Measure again for each child to be exactly the same size.
 
        childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
                mMaxChildWidth, MeasureSpec.EXACTLY);
        childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
                mMaxChildHeight, MeasureSpec.EXACTLY);
 
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
 
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        }
        
        setMeasuredDimension(
                resolveSize(mMaxChildWidth, widthMeasureSpec),
                resolveSize(mMaxChildHeight, heightMeasureSpec));
    }
    
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int width = r - l;
        int height = b - t;
 
        final int count = getChildCount();
 
        // Calculate the number of visible children.
        int visibleCount = 0;
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
            ++visibleCount;
        }
 
        if (visibleCount == 0) {
            return;
        }
 
        // Calculate what number of rows and columns will optimize for even horizontal and
        // vertical whitespace between items. Start with a 1 x N grid, then try 2 x N, and so on.
        int bestSpaceDifference = Integer.MAX_VALUE;
        int spaceDifference;
 
        // Horizontal and vertical space between items
        int hSpace = 0;
        int vSpace = 0;
 
        int cols = 1;
        int rows;
 
        while (true) {
            rows = (visibleCount - 1) / cols + 1;
 
            hSpace = ((width - mMaxChildWidth * cols) / (cols + 1));
            vSpace = ((height - mMaxChildHeight * rows) / (rows + 1));
 
            spaceDifference = Math.abs(vSpace - hSpace);
            if (rows * cols != visibleCount) {
                spaceDifference *= UNEVEN_GRID_PENALTY_MULTIPLIER;
            }
 
            if (spaceDifference < bestSpaceDifference) {
                // Found a better whitespace squareness/ratio
                bestSpaceDifference = spaceDifference;
 
                // If we found a better whitespace squareness and there's only 1 row, this is
                // the best we can do.
                if (rows == 1) {
                    break;
                }
            } else {
                // This is a worse whitespace ratio, use the previous value of cols and exit.
                --cols;
                rows = (visibleCount - 1) / cols + 1;
                hSpace = ((width - mMaxChildWidth * cols) / (cols + 1));
                vSpace = ((height - mMaxChildHeight * rows) / (rows + 1));
                break;
            }
 
            ++cols;
        }
 
        // Lay out children based on calculated best-fit number of rows and cols.
 
        // If we chose a layout that has negative horizontal or vertical space, force it to zero.
        hSpace = Math.max(0, hSpace);
        vSpace = Math.max(0, vSpace);
 
        // Re-use width/height variables to be child width/height.
        width = (width - hSpace * (cols + 1)) / cols;
        height = (height - vSpace * (rows + 1)) / rows;
 
        int left, top;
        int col, row;
        int visibleIndex = 0;
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
 
            row = visibleIndex / cols;
            col = visibleIndex % cols;
 
            left = hSpace * (col + 1) + width * col;
            top = vSpace * (row + 1) + height * row;
 
            child.layout(left, top,
                    (hSpace == 0 && col == cols - 1) ? r : (left + width),
                    (vSpace == 0 && row == rows - 1) ? b : (top + height));
            ++visibleIndex;
        }
    }

}

Action bars i fragments

Activitys i fragments

Principal

public class ActionBarActivity extends Activity {
	
	public static Context appContext;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dashboard_layout);
        appContext = getApplicationContext();

        //ActionBar
        ActionBar actionbar = getActionBar();
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
         
        ActionBar.Tab PassarLlistaTab = actionbar.newTab().setText("Passar llista");
        ActionBar.Tab AlumnesGrupsTab = actionbar.newTab().setText("Alumnes - Grups");
        ActionBar.Tab InformesTab = actionbar.newTab().setText("Informes");
        ActionBar.Tab TutoriaTab = actionbar.newTab().setText("Tutoria");
         
        Fragment PassarLlistaFragment = new PassarLlistaFragment();
        Fragment AlumnesGrupsFragment = new AlumnesGrupsFragment();
        Fragment InformesFragment = new InformesFragment();
        Fragment TutoriaFragment = new TutoriaFragment();

        PassarLlistaTab.setTabListener(new MyTabsListener(PassarLlistaFragment));
        AlumnesGrupsTab.setTabListener(new MyTabsListener(AlumnesGrupsFragment));
        InformesTab.setTabListener(new MyTabsListener(InformesFragment));
        TutoriaTab.setTabListener(new MyTabsListener(TutoriaFragment));

        actionbar.addTab(PassarLlistaTab);
        actionbar.addTab(AlumnesGrupsTab);
        actionbar.addTab(InformesTab);
        actionbar.addTab(TutoriaTab);
 
        /**
         * Creating all buttons instances
         * */
        // Dashboard Passar llista feed button
        Button btn_passar_llista = (Button) findViewById(R.id.btn_passar_llista);
 
        // Dashboard Tutoria button
        Button btn_tutoria = (Button) findViewById(R.id.btn_tutoria);
 
        // Dashboard Alumnes - grups button
        Button btn_alumnes_grups = (Button) findViewById(R.id.btn_alumnes_grups);
 
        // Dashboard Informes button
        Button btn_informes = (Button) findViewById(R.id.btn_informes);
        
        // Dashboard Logout button
        Button btn_logout = (Button) findViewById(R.id.btn_logout);
 
        /**
         * Handling all button click events
         * */
 
        // Listening to Passar llista button click
        btn_passar_llista.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
            	FragmentManager fm = getFragmentManager();
            	FragmentTransaction ft = fm.beginTransaction();
            	PassarLlistaFragment plf = new PassarLlistaFragment();
            	ft.replace(android.R.id.content, plf).commit();
                //Intent i = new Intent(getApplicationContext(), PassarLlistaFragment.class);
                //startActivity(i);
            }
        });
        
        // Listening Tutoria button click
        btn_tutoria.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
            	FragmentManager fm = getFragmentManager();
            	FragmentTransaction ft = fm.beginTransaction();
            	TutoriaFragment tf = new TutoriaFragment();
            	ft.replace(android.R.id.content, tf).commit();
                //Intent i = new Intent(getApplicationContext(), TutoriaFragment.class);
                //startActivity(i);
            }
        });
 
        // Listening to Alumnes - grups button click
        btn_alumnes_grups.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
            	FragmentManager fm = getFragmentManager();
            	FragmentTransaction ft = fm.beginTransaction();
            	AlumnesGrupsFragment agf = new AlumnesGrupsFragment();
            	ft.replace(android.R.id.content, agf).commit();
                //Intent i = new Intent(getApplicationContext(), AlumnesGrupsFragment.class);
                //startActivity(i);
            }
        });
 
        // Listening to Informes button click
        btn_informes.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
            	FragmentManager fm = getFragmentManager();
            	FragmentTransaction ft = fm.beginTransaction();
            	InformesFragment inff = new InformesFragment();
            	ft.replace(android.R.id.content, inff).commit();
                //Intent i = new Intent(getApplicationContext(), InformesFragment.class);
                //startActivity(i);
            }
        });
        
        // Listening to Logout button click
        btn_logout.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // Launching News Feed Screen
                Intent i = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(i);
            }
        });
        
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.action_bar, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case android.R.id.home:
	            // app icon in action bar clicked; go home
	            /*Intent intent = new Intent(this, LoginActivity.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(intent);*/
	        	finish();
	            return true;
	        
	        case R.id.search:
	        	Toast.makeText(appContext, "Buscar", Toast.LENGTH_SHORT).show();
	        	return true;
	        	
	        case R.id.save:
	        	Toast.makeText(appContext, "Guardar", Toast.LENGTH_SHORT).show();
	        	return true;
	        
	        case R.id.overflow:
	        	Toast.makeText(appContext, "Més", Toast.LENGTH_SHORT).show();
	        	return true;
	            
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
	
	@Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
    }
	
	class MyTabsListener implements ActionBar.TabListener {
		public Fragment fragment;
		
		public MyTabsListener(Fragment fragment) {
			this.fragment = fragment;
		}
		
		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
			Toast.makeText(ActionBarActivity.appContext, "Reseleccionat!", Toast.LENGTH_LONG).show();
		}

		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragment);
		}

		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			ft.remove(fragment);
		}
		
	}

}

Fragment passar llista

public class PassarLlistaFragment extends Fragment {
	
	ArrayAdapterLlista adapter;
	ListView llista;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		
		View v = inflater.inflate(R.layout.passar_llista_layout, container, false);
		llista = (ListView) v.findViewById(R.id.listView1);
		ArrayList<EntradaLlista> objects = new ArrayList<EntradaLlista>();
		
		EntradaLlista alumne1 = new EntradaLlista();
		alumne1.setNom("Andres");
		alumne1.setNum_tel("666888999");
		
		EntradaLlista alumne2 = new EntradaLlista();
		alumne2.setNom("Alex");
		alumne2.setNum_tel("609708809");
		
		objects.add(alumne1);
		objects.add(alumne2);
		
		adapter= new ArrayAdapterLlista(getActivity(), R.layout.alumnes_llista, R.id.Nom, objects);
		llista.setAdapter(adapter);
		return v;
	}

}

Classe array adapter

public class ArrayAdapterLlista extends ArrayAdapter<EntradaLlista> {
	
	private ArrayList<EntradaLlista> items;
    private int rsrc;
    
    public ArrayAdapterLlista(Context context, int resourceId,
			int textViewResourceId, ArrayList<EntradaLlista> objects) {
		super(context, resourceId, textViewResourceId, objects);
		this.items = objects;
        this.rsrc = resourceId;
	}
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = li.inflate(rsrc, null);
        }
        EntradaLlista e = items.get(position);
        if (e != null) {
            ((TextView)v.findViewById(R.id.Nom)).setText(e.getNom());
            ((TextView)v.findViewById(R.id.Telefon)).setText(e.getNum_tel());
            if (e.getFoto() != -1) {
            	((ImageView)v.findViewById(R.id.Foto)).setImageResource(e.getFoto());               
            } else {
            	((ImageView)v.findViewById(R.id.Foto)).setImageResource(R.drawable.img_alumne_nofoto); 
            }
        }
        return v;
    }
}

Classe dels alumnes (les entrades de la llista)

public class EntradaLlista {
	
	private String nom;
	private String cognoms;
	private String usuari;
        private String num_tel;
        private String correu;
        private int foto;
    
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getCognoms() {
		return cognoms;
	}
	public void setCognoms(String cognoms) {
		this.cognoms = cognoms;
	}
	
	public String getNum_tel() {
		return num_tel;
	}
	public void setNum_tel(String num_tel) {
		this.num_tel = num_tel;
	}
	public String getUsuari() {
		return usuari;
	}
	public void setUsuari(String usuari) {
		this.usuari = usuari;
	}
	public String getCorreu() {
		return correu;
	}
	public void setCorreu(String correu) {
		this.correu = correu;
	}
	public int getFoto() {
		return foto;
	}
	public void setFoto(int foto) {
		this.foto = foto;
	}
}

Fragment tutoria

public class TutoriaFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.tutoria_layout, container, false);
	}

}

Fragment informes

public class InformesFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.informes_layout, container, false);
	}

}

Fragment alumnes grups

public class AlumnesGrupsFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.alumnes_grups_layout, container, false);
	}

}

Layouts

El layout més substancios, el de passar llista (els altres no tenen pràcticament contingut)

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f8f9fe"
    android:orientation="vertical" >
 
    <!--  Header  Starts-->
  	<LinearLayout android:id="@+id/header"
  			android:layout_width="fill_parent"
  			android:layout_height="wrap_content"
  			android:background="@drawable/header"
  			android:paddingTop="5dip"
  			android:paddingBottom="5dip">
  	</LinearLayout>
  	<!--  Header Ends -->
	
	  <TextView
		android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="15dip"
        android:text="Passar llista"
        android:textColor="#ff29549f"
        android:textSize="25sp"
        android:textStyle="bold" />
	  
  	<ListView
  	    android:id="@+id/listView1"
  	    android:layout_width="match_parent"
  	    android:layout_height="wrap_content" 
  	    android:divider="#000000"
  	    android:dividerHeight="1dp">
  	</ListView>
  	
  	<LinearLayout
  	    android:id="@+id/footer"
  	    android:layout_width="fill_parent"
  	    android:layout_height="50dip"
  	    android:background="@layout/footer_repeat"
  	    android:baselineAligned="true" >
  	</LinearLayout> 	
 
</LinearLayout>

alumnes_llista.xml (el ListView)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     
	<ImageView 
	    android:id="@+id/Foto"
    	android:layout_width="48dp"
    	android:layout_height="48dp"  	
    	android:contentDescription="FotoAlumne"
    	android:src="@drawable/img_alumne_andres" />
	<LinearLayout 
	    android:orientation="vertical"
      	android:paddingLeft="10dp"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent">
    <TextView 
        android:id="@+id/Nom"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:paddingLeft="50dp"
    	android:textSize="22sp" />
    <TextView 
        android:id="@+id/Telefon"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:paddingLeft="50dp"
    	android:textSize="16sp" />
  	</LinearLayout>
  	<TextView 
  	    android:id="@+id/eNull"
  		android:layout_width="fill_parent"
  		android:layout_height="wrap_content" /> 

</RelativeLayout>

Menú ActionBar

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item android:id="@+id/search"
          android:icon="@drawable/ic_menu_search"
          android:title="Buscar"
          android:showAsAction="ifRoom"
          android:actionViewClass="android.widget.SearchView" />
    
    <item android:id="@+id/save"
          android:icon="@drawable/ic_menu_save"
          android:title="Guardar"
          android:showAsAction="ifRoom" />
    
    <item android:id="@+id/overflow"
          android:icon="@drawable/ic_menu_moreoverflow_normal_holo_light"
          android:title="Més"
          android:showAsAction="ifRoom" />

</menu>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.iesebre.dam22012.andrescorazon.webfaltes"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="16" />
    
    <!-- <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> -->

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo" >
        <activity
            android:name="com.iesebre.dam22012.andrescorazon.webfaltes.LoginActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize|stateVisible"
            android:uiOptions="splitActionBarWhenNarrow" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!--  Entry for RegisterActivity.class -->
        <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.RegisterActivity"
                  android:label="Registrar un nou compte"></activity>
        
        <!--  Entry for DashboardDesignActivity.class -->
        <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.DashboardDesignActivity"
                  android:label="Inici"></activity>
        
        <!--  Entry for ActionBarActivity.class -->
        <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.ActionBarActivity"
                  android:label="Webfaltes"
                  android:configChanges="keyboardHidden|orientation|screenSize"></activity>
        
    </application>

</manifest>

Gitorious

https://gitorious.org/2dam201213/alumnes/trees/master/corazonandres/WebFaltes

Programa final

Andrescorazon webfaltes apk qrcode.png

Captures de pantalla

Andrescorazon webfaltes android login.png

Andrescorazon webfaltes android registre.png

Andrescorazon webfaltes android dashboard.png

Andrescorazon webfaltes android actionbar.png

Vegeu també

Enllaços externs