College Routine Example in Android

RoutineActivity
 package com.nepal.loadshedding;  
 import java.security.Provider;  
 import java.sql.Time;  
 import java.util.Calendar;  
 import android.app.Activity;  
 import android.app.AlarmManager;  
 import android.app.PendingIntent;  
 import android.app.TimePickerDialog;  
 import android.content.Intent;  
 import android.os.Bundle;  
 import android.os.SystemClock;  
 import android.view.View;  
 import android.view.View.OnClickListener;  
 import android.widget.AdapterView;  
 import android.widget.AdapterView.OnItemSelectedListener;  
 import android.widget.ArrayAdapter;  
 import android.widget.Button;  
 import android.widget.EditText;  
 import android.widget.ImageButton;  
 import android.widget.Spinner;  
 import android.widget.TextView;  
 import android.widget.Toast;  
 import com.islington.timetable.R;  
 public class RoutineActivity extends Activity {  
   /** Called when the activity is first created. */  
      private String arrayGrp[] = {"Group C1","Group C2","Group C3","Group C4"};  
      private String arrayDay[] ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};  
      private ArrayAdapter<String> grpAdapter;  
      private ArrayAdapter<String> dayAdapter;  
      private TextView time1,time2;  
      final private Calendar cal =Calendar.getInstance();  
      private TextView time3;  
      ImageButton btn_alarm_3;  
      ImageButton btn_alarm_2;  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.main);  
     time1 =(TextView) findViewById(R.id.textView_time1);  
     time2 = (TextView) findViewById(R.id.textView_time2);  
     time3 = (TextView) findViewById(R.id.textView_time3);  
     final Spinner spinnerGrp= (Spinner) findViewById(R.id.spinner_group);  
     grpAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,arrayGrp);  
     spinnerGrp.setAdapter(grpAdapter);  
     final Spinner spinnerDay =(Spinner) findViewById(R.id.spinner_day);  
     dayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,arrayDay);  
     spinnerDay.setAdapter(dayAdapter);  
     ImageButton btn_alarm_1 = (ImageButton) findViewById(R.id.imageButton_alarm1);  
     btn_alarm_2 = (ImageButton) findViewById(R.id.imageButton_alarm2);  
     btn_alarm_3= (ImageButton) findViewById(R.id.imageButton_alarm3);  
     spinnerDay.setOnItemSelectedListener(new OnItemSelectedListener()  
     {  
           @Override  
           public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,  
                     long arg3) {  
                // TODO Auto-generated method stub  
                String GrpValue = (String) spinnerGrp.getSelectedItem();  
                //Group one  
                if(GrpValue == "Group C1")  
                {  
                     time3.setVisibility(EditText.INVISIBLE);  
                     btn_alarm_3.setVisibility(-1);  
                     switch (spinnerDay.getSelectedItemPosition()) {  
                     case 0:  
                          time1.setText("11:30 am - 01:30 pm E-Business London Block Kensington Palace");  
                          time2.setText("02:00 pm - 04:00 pm Advance DataBase System London Block Westminister Palace");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          break;  
                     case 1:  
                          time1.setText("08:30 am - 10:00 am Advance DataBase System Nepal Kantipur");  
                          time2.setText("10:00 am - 12:00 pm Post Implementation Issues London Block Kensington Palace");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          break;  
                     case 2:  
                          time1.setText("07:00 am - 08:30 am E-Business Himalaya Kanchanjunga");  
                          //time2.setText("5:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 3:  
                          time1.setText("08:30 am - 10:00 am E-Business Himalaya Kanchanjunga");  
                          time2.setText("10:30 am - 12:00 pm Post Implementation Issues Himalaya Machapuchare");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          break;  
                     case 4:  
                          time1.setText("01:30 pm - 03:00 pm Advance DataBase System Lab 10 - Liverpool");  
                          //time2.setText("2:00 pm - 8:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 5:  
                          time1.setText("07:00 am - 08:30 am Post Implementation Issues Nepal TR09 - Patan");  
                          //time2.setText("1:00 pm - 8:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     }  
                }  
                //Group 2  
                if(GrpValue == "Group C2")  
                {  
                     switch (spinnerDay.getSelectedItemPosition()) {  
                     case 0:  
                          time1.setText("11:30 am - 01:30 pm E-Business London Block Kensington Palace");  
                          time2.setText("02:00 pm - 04:00 pm Advance DataBase System London Block Westminister Palace");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          break;  
                     case 1:  
                          time1.setText("10:00 am - 12:00 pm Post Implementation Issues London Block Kensington Palace");  
                          //time2.setText("7:00 pm - 1:00 am");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 2:  
                          time1.setText("12:30 pm - 02:00 pm Advanced Database Systems Himalaya Machapuchare");  
                     //     time2.setText("5:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 3:  
                          time1.setText("07:00 am - 08:30 am E-Business Himalaya Kanchanjunga");  
                          //time2.setText("3:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 4:  
                          time1.setText("07:00 am - 08:30 am E-Business Nepal Patan");  
                          time2.setText("08:30 am - 10:00 am Post Implementation Issues Nepal Pokhara");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          break;  
                     case 5:  
                          time1.setText("07:00 am - 08:30 Advance DataBase System Lab 11- York Lab");  
                          //time2.setText("1:00 pm - 8:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;                           
                     }                                          
                }  
                //Group 3  
                if(GrpValue == "Group C3")  
                {  
                     switch (spinnerDay.getSelectedItemPosition()) {  
                     case 0:  
                          time1.setText("11:30 am - 01:30 pm E-Business London Block Kensington Palace");  
                          time2.setText("02:00 pm - 04:00 pm Advance DataBase System London Block Westminister Palace");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          break;  
                     case 1:  
                          time1.setText("08:00 AM - 09:30 AM E-Business SR03-Piccadilly Circus");  
                          time2.setText("10:00 am - 12:00 pm Post Implementation Issues London Block Kensington Palace");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          break;  
                     case 2:  
                          time1.setText("08:30 am - 10:00 am Post Implementation Issues London SR04 - Tower of London");  
                     //     time2.setText("5:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 3:  
                          time1.setText("10:30 am - 12:00 pm E-Business Himalaya Kanchanjunga");  
                          //time2.setText("3:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     case 4:  
                          time1.setText("09:30 am - 11:00 am Advance DataBase System UK TR12 - Gorkha");  
                          time2.setText("11:00 am -12:30 pm Post Implementation Issues Nepal TR10 -Pokhara");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          break;  
                     case 5:  
                          time1.setText(" 10:00 am - 11:30 am Advance DataBase System Lab 11 - York");  
                          //time2.setText("12:00 am - 7:00 am");  
                          time1.setVisibility(1);  
                          time2.setVisibility( -1);  
                          btn_alarm_2.setVisibility(1);  
                          btn_alarm_2.setVisibility(-1);  
                          break;  
                     }                                          
                }  
                //Group 4  
                if(GrpValue == "Group C4")  
                {  
                     switch (spinnerDay.getSelectedItemPosition()) {  
                     case 0:  
                          time1.setText("02:00 pm - 04:00 pm Advance DataBase System London Block Westminister Palace");  
                          //time2.setText("8:00 pm - 1:00 am");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          time3.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          btn_alarm_3.setVisibility(-1);  
                          break;  
                     case 1:  
                          time1.setText("10:00 am - 12:00 pm Post Implementation Issues London Block Kensington Palace");  
                          time2.setText("12:30 pm - 02:30 pm E-Business London SR03-Piccadilly Circus");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          time3.setVisibility(-1);  
                          btn_alarm_2.setVisibility(1);  
                          btn_alarm_3.setVisibility(-1);  
                          break;  
                     case 2:  
                          time1.setText("08:30 am - 10:00 am E-Business Himalaya TR03-Kanchanjunga ");  
                          time2.setText("10:30 am - 12:00 pm Post Implementation Issues London SR04 - Tower of London");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          time3.setVisibility(-1);  
                          btn_alarm_2.setVisibility(1);  
                          btn_alarm_3.setVisibility(-1);  
                          break;  
                     case 3:  
                          time1.setText("Leave");  
                          //time2.setText("3:00 pm - 9:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          time3.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          btn_alarm_3.setVisibility(-1);  
                          btn_alarm_3.setVisibility(-1);  
                          break;  
                     case 4:  
                          time1.setText("07:00 am - 08:30 am Post Implementation Issues Nepal TR10 - Pokhara");  
                          time2.setText("12:00 pm - 01:30 pm Advance Database System UK Lab 05 - Bath");  
                          time3.setText("08:30 am - 10:00 am E-Business Nepal TR09 - Patan");  
                          time1.setVisibility(1);  
                          time2.setVisibility(1);  
                          time3.setVisibility(1);  
                          btn_alarm_2.setVisibility(1);  
                          btn_alarm_3.setVisibility(1);  
                          break;  
                     case 5:  
                          time1.setText("11:30 am - 01:00 pm Advance Database System Lab 11 - York ");  
                          //time2.setText("1:00 pm - 8:00 pm");  
                          time1.setVisibility(1);  
                          time2.setVisibility(-1);  
                          time3.setVisibility(-1);  
                          btn_alarm_2.setVisibility(-1);  
                          btn_alarm_3.setVisibility(-1);  
                          break;  
                     }                                          
                }                           
           }  
           @Override  
           public void onNothingSelected(AdapterView<?> arg0) {  
                // TODO Auto-generated method stub  
                time1.setVisibility(3);  
           }  
     });    
   }  
 }  

main.xml


 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="wrap_content"  
   android:orientation="vertical"  
   android:keepScreenOn="true"  
    >  
   <TextView  
     android:layout_width="fill_parent"  
     android:layout_height="wrap_content"  
     android:text="@string/hello" />  
   <Spinner  
     android:id="@+id/spinner_group"  
     android:layout_width="fill_parent"  
     android:layout_height="wrap_content"  
      />  
   <Spinner  
     android:id="@+id/spinner_day"  
     android:layout_width="fill_parent"  
     android:layout_height="wrap_content" />   
   <ScrollView  
     android:id="@+id/scrollView1"  
     android:layout_width="fill_parent"  
     android:layout_height="wrap_content"   
     >  
    <LinearLayout  
    android:layout_width="fill_parent"  
   android:layout_height="wrap_content"  
       >  
       <TableLayout  
     android:layout_width="fill_parent"  
     android:layout_height="wrap_content"   
     android:paddingTop="10px"  
     android:layout_marginTop="30dp"  
     >  
     <TableRow  
       android:id="@+id/tableRow1"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"   
       android:gravity="center_vertical"  
       >  
       <ImageButton  
         android:id="@+id/imageButton_alarm1"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:src="@drawable/alarm_clock" />  
       <TextView  
         android:id="@+id/textView_time1"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:text="Large Text"  
         android:textAppearance="?android:attr/textAppearanceLarge"  
         android:visibility="visible"  
          />  
     </TableRow>  
     <TableRow  
       android:id="@+id/tableRow2"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"  
       android:layout_gravity="center_horizontal"  
       android:gravity="center_vertical" >  
       <ImageButton  
         android:id="@+id/imageButton_alarm2"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:src="@drawable/alarm_clock" />  
       <TextView  
         android:id="@+id/textView_time2"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:text="Large Text"  
         android:textAppearance="?android:attr/textAppearanceLarge"  
         android:visibility="visible"  
          />  
     </TableRow>  
     <TableRow  
       android:id="@+id/tableRow3"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"  
       android:layout_gravity="center_vertical" >  
       <ImageButton  
         android:id="@+id/imageButton_alarm3"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:src="@drawable/alarm_clock" />  
       <TextView  
         android:id="@+id/textView_time3"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:text="Large Text"  
         android:textAppearance="?android:attr/textAppearanceLarge"   
         android:visibility="visible"  
         />  
     </TableRow>  
     <TableRow  
       android:id="@+id/tableRow4"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content" >  
     </TableRow>  
   </TableLayout>  
    </LinearLayout>  
   </ScrollView>  
 </LinearLayout>  

No comments:

Post a Comment