TODO
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); } }); } }
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; } } }
<?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="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.LoginActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustResize|stateVisible" > <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> <!-- Passar llista Activity --> <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.PassarLlistaActivity" android:label="Inici > Passar llista"></activity> <!-- Tutoria Activity --> <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.TutoriaActivity" android:label="Inici > Tutoria"></activity> <!-- Alumnes - grups Activity --> <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.AlumnesGrupsActivity" android:label="Inici > Alumnes -grups"></activity> <!-- Informes Activity --> <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.InformesActivity" android:label="Inici > Informes"></activity> </application> </manifest>
Principal
public class DashboardDesignActivity 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 //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 //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 //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 //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 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(DashboardDesignActivity.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 (En proces...)
public class PassarLlistaFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.passar_llista_layout, container, false); } }
Classe entrada llista
public class EntradaLlista { private String nom; private String num_tel; private int foto; public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getNum_tel() { return num_tel; } public void setNum_tel(String num_tel) { this.num_tel = num_tel; } 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); } }
<?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" /> <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.RegisterFragment" android:label="Registrar un nou compte"></activity> <!-- Entry for DashboardDesignActivity.class --> <activity android:name="com.iesebre.dam22012.andrescorazon.webfaltes.DashboardDesignActivity" android:label="Inici"></activity> </application> </manifest>