Back to project page RiceCourses.
The source code is released under:
MIT License
If you think the Android project RiceCourses 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 info.kevinlin.ricecourses; /*from w w w. ja va 2s .c om*/ import android.app.ActionBar; import android.app.AlertDialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CourseDetails extends ActionBarActivity { private ViewPager viewPager; private TabsPagerAdapter mAdapter; private ActionBar actionBar; private String[] tabs = {"DETAILS", "WEBPAGE"}; String sessionCode = ""; String clickedCourseNumber, clickedCourseCode, clickedCourseLength, clickedCourseTitle, clickedCourseInstructor, clickedCourseTime, clickedCourseCredits; ArrayList<String> courseDetails = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_course_details); ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(11, 35, 69))); Intent intent = getIntent(); clickedCourseNumber = intent.getStringExtra(CourseList.CLICKED_COURSE_NUMBER); clickedCourseCode = intent.getStringExtra(CourseList.CLICKED_COURSE_CODE); clickedCourseLength = intent.getStringExtra(CourseList.CLICKED_COURSE_LENGTH); clickedCourseTitle = intent.getStringExtra(CourseList.CLICKED_COURSE_TITLE); clickedCourseInstructor = intent.getStringExtra(CourseList.CLICKED_COURSE_INSTRUCTOR); clickedCourseTime = intent.getStringExtra(CourseList.CLICKED_COURSE_TIME); clickedCourseCredits = intent.getStringExtra(CourseList.CLICKED_COURSE_CREDITS); sessionCode = intent.getStringExtra(CourseList.SESSION_CODE); courseDetails.add(clickedCourseNumber); courseDetails.add(clickedCourseCode); courseDetails.add(clickedCourseLength); courseDetails.add(clickedCourseTitle); courseDetails.add(clickedCourseInstructor); courseDetails.add(clickedCourseTime); courseDetails.add(clickedCourseCredits); courseDetails.add("Course Number: " + clickedCourseNumber + ", Course Code: " + clickedCourseCode + ", Course Length: " + clickedCourseLength + ", Course Title: " + clickedCourseTitle + ", Course Instructor: " + clickedCourseInstructor + ", Course Time: " + clickedCourseTime + ", Course Credits: " + clickedCourseCredits); ((TextView)findViewById(R.id.courseNumberTextView)).setText(clickedCourseNumber); ((TextView)findViewById(R.id.courseCodeTextView)).setText(clickedCourseCode); ((TextView)findViewById(R.id.courseLengthTextView)).setText(clickedCourseLength); ((TextView)findViewById(R.id.courseTitleTextView)).setText(clickedCourseTitle); ((TextView)findViewById(R.id.courseInstructorTextView)).setText(clickedCourseInstructor); ((TextView)findViewById(R.id.courseTimeTextView)).setText(clickedCourseTime); ((TextView)findViewById(R.id.courseCreditTextView)).setText(clickedCourseCredits); /* viewPager = (ViewPager)findViewById(R.id.pager); actionBar = getActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); //actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (String tab_name : tabs) actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } });*/ } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.course_details, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return(true); case R.id.action_esther: openPage(); return true; case R.id.action_copy: copyDialog(); return true; default: return super.onOptionsItemSelected(item); } } public void openPage() { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://courses.rice.edu/admweb/!SWKSCAT.cat?p_action=COURSE&p_term=" + sessionCode + "&p_crn=" + clickedCourseNumber)); startActivity(browserIntent); } public void copyDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Copy to clipboard") .setItems(R.array.course_details_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("Copied course details", courseDetails.get(which))); showCopiedToast(courseDetails.get(which)); } }); builder.create().show(); } private void showCopiedToast(String copiedText) { Toast toast; if (copiedText.length() > 0) toast = Toast.makeText(getApplicationContext(), "Copied to clipboard: " + copiedText, Toast.LENGTH_SHORT); else toast = Toast.makeText(getApplicationContext(), "Nothing copied to clipboard" + copiedText, Toast.LENGTH_SHORT); toast.show(); } /*@Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // on tab selected // show respected fragment view viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { }*/ }