Back to project page digitalcampus.
The source code is released under:
MIT License
If you think the Android project digitalcampus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.llenguatges.digitalcampus; //ww w .j av a 2 s. c o m import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import com.llenguatges.digitalcampus.adapters.CustomGridViewAdapter; import com.llenguatges.digitalcampus.exams.ExamsActivity; import com.llenguatges.digitalcampus.exams.NewExamActivity; import com.llenguatges.digitalcampus.login.SessionManager; import com.llenguatges.digitalcampus.objects.Item; import com.llenguatges.digitalcampus.students.NewStudentActivity; import com.llenguatges.digitalcampus.students.StudentsActivity; import com.llenguatges.digitalcampus.subjects.NewSubjectActivity; import com.llenguatges.digitalcampus.subjects.SubjectsActivity; public class MainActivity extends Activity { private GridView gridView; private ArrayList<Item> gridArray = new ArrayList<Item>(); private CustomGridViewAdapter customGridAdapter; private String user; private static String USER_EMAIL = "email"; private SessionManager session; /** * Called when the activity is first created. * This is where you all of static set up: customize ActionBar. * This method also provides you with a Bundle containing the * activity's previously frozen state, if there was one. */ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); session = new SessionManager(getApplicationContext()); if(session.isLoggedIn()){ user = session.getUserDetails().get(USER_EMAIL); }else{ Intent iin= getIntent(); Bundle b = iin.getExtras(); user = (String) b.getString(USER_EMAIL); } Toast.makeText(getApplicationContext(), "Welcome "+user, Toast.LENGTH_SHORT).show(); Bitmap studentsManagerIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher); Bitmap subjectManagerIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher); Bitmap examsIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher); Bitmap exitIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher); gridArray.add(new Item(studentsManagerIcon,"Students Manager")); gridArray.add(new Item(subjectManagerIcon,"Subject Manager")); gridArray.add(new Item(examsIcon,"Exams")); gridArray.add(new Item(exitIcon,"Logout")); gridView = (GridView) findViewById(R.id.gridView1); customGridAdapter = new CustomGridViewAdapter(this, R.layout.row_grid, gridArray); gridView.setAdapter(customGridAdapter); gridView.setOnItemClickListener(new OnItemClickListener() { private Intent intent; public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { switch (position){ case 0: intent = new Intent().setClass(MainActivity.this, StudentsActivity.class); startActivity(intent); break; case 1: intent = new Intent().setClass(MainActivity.this, SubjectsActivity.class); startActivity(intent); break; case 2: intent = new Intent().setClass(MainActivity.this, ExamsActivity.class); startActivity(intent); break; case 3: session.logoutUser(); Toast.makeText(getApplicationContext(), "Goodbye "+user, Toast.LENGTH_SHORT).show(); finish(); break; } } }); } /** * Initialize the contents of the Activity's standard options menu. */ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } /** * This hook is called whenever an item in your options menu is selected. */ public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case android.R.id.home: this.finish(); return true; case R.id.main_new_subject: intent = new Intent().setClass(MainActivity.this, NewSubjectActivity.class); startActivity(intent); return true; case R.id.main_new_student: intent = new Intent().setClass(MainActivity.this, NewStudentActivity.class); startActivity(intent); return true; case R.id.main_new_exam: intent = new Intent().setClass(MainActivity.this, NewExamActivity.class); intent.putExtra("exam", 0); startActivity(intent); return true; case R.id.main_exit: finish(); return true; default: return super.onOptionsItemSelected(item); } } }