Created
March 12, 2011 07:17
-
-
Save anonymous/867109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package acarin.timetracker.com; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import android.app.Activity; | |
| import android.app.Dialog; | |
| import android.os.Bundle; | |
| import android.os.SystemClock; | |
| import android.view.MotionEvent; | |
| import android.view.View; | |
| import android.view.View.OnClickListener; | |
| import android.view.View.OnTouchListener; | |
| import android.widget.AdapterView; | |
| import android.widget.ArrayAdapter; | |
| import android.widget.Button; | |
| import android.widget.Chronometer; | |
| import android.widget.EditText; | |
| import android.widget.PopupWindow; | |
| import android.widget.Spinner; | |
| import android.widget.Toast; | |
| import android.widget.AdapterView.OnItemSelectedListener; | |
| public class Starttracker extends Activity | |
| { | |
| PopupWindow popupWindow; | |
| List<String> Items =new ArrayList<String>(); | |
| String[] tempArray={ | |
| "Events:", | |
| "Alarm", | |
| "Office", | |
| "Meeting", | |
| "Party", | |
| "Lunch", | |
| "Breakfast", | |
| "Supper", | |
| "Home", | |
| "Private", | |
| "Outdoor", | |
| "Family", | |
| "Friends", | |
| "Others" | |
| }; | |
| Spinner s1; | |
| /** Called when the activity is first created. */ | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.starttracker); | |
| /** | |
| * Here i m converting String array to List Array | |
| * so that i can add value to list dynamically | |
| */ | |
| { | |
| int size=tempArray.length; | |
| for(int i=0;i<size;i++){ | |
| Items.add(tempArray[i]); | |
| } | |
| } | |
| //HH:MM:SS format | |
| final Chronometer chrono = (Chronometer)findViewById(R.id.chronometer); | |
| chrono.setFormat("%s"); | |
| chrono.start(); | |
| //home button | |
| Button next = (Button) findViewById(R.id.home); | |
| next.setOnClickListener(new View.OnClickListener() | |
| { | |
| public void onClick(View view) | |
| { | |
| finish(); | |
| } | |
| }); | |
| s1 = (Spinner) findViewById(R.id.spinner); | |
| final ArrayAdapter<String> adapter = new ArrayAdapter<String>( | |
| this,android.R.layout.simple_spinner_item,Items); | |
| adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
| s1.setAdapter(adapter); | |
| s1.setOnItemSelectedListener(new OnItemSelectedListener() | |
| { | |
| public void onItemSelected(final AdapterView<?> arg0, | |
| View arg1, final int index, long arg3) | |
| { | |
| // final int index = s1.getSelectedItemPosition(); | |
| Toast.makeText(getBaseContext(), | |
| "You have selected item : " + Items.get(index), | |
| Toast.LENGTH_SHORT).show(); | |
| chrono.setBase(SystemClock.elapsedRealtime()); | |
| chrono.start(); | |
| if(index==0) | |
| { | |
| chrono.stop(); | |
| } | |
| if(index==13) | |
| { | |
| final Dialog dialog=new Dialog(Starttracker.this); | |
| dialog.setContentView(R.layout.popup); | |
| dialog.setTitle("Enter The Item"); | |
| dialog.setCanceledOnTouchOutside(true); | |
| //chronometer stop | |
| chrono.stop(); | |
| final EditText filename=(EditText)dialog.findViewById(R.id.filename); | |
| filename.setText(""); | |
| Button d_ok=(Button)dialog.findViewById(R.id.d_ok); | |
| Button d_cancel=(Button)dialog.findViewById(R.id.d_cancel); | |
| d_ok.setOnClickListener(new OnClickListener(){ | |
| public void onClick(View arg0) { | |
| // TODO Auto-generated method stub | |
| String textHolder = filename.getText().toString(); | |
| dialog.dismiss(); | |
| Items.add(textHolder); | |
| // s1.setAdapter(adapter); | |
| // notifyDataSetChanged(); | |
| chrono.setBase(SystemClock.elapsedRealtime()); | |
| chrono.start(); | |
| } | |
| }); | |
| d_cancel.setOnTouchListener(new OnTouchListener(){ | |
| public boolean onTouch(View v,MotionEvent me){ | |
| dialog.dismiss(); | |
| return false; | |
| } | |
| }); | |
| dialog.show(); | |
| return; | |
| } | |
| if(index>13) | |
| { | |
| Button clearButton=(Button)findViewById(R.id.delete); | |
| clearButton.setOnClickListener(new OnClickListener(){ | |
| public void onClick(View v) { | |
| Toast.makeText(getBaseContext(), "Your have selected item was successfully deleted. ", Toast.LENGTH_SHORT).show(); | |
| clearSpinnerItems(); | |
| } | |
| private void clearSpinnerItems() { | |
| Object t=Items.get(index); | |
| Items.remove((CharSequence) t); | |
| chrono.stop(); | |
| } | |
| }); | |
| } | |
| if(index<13) | |
| { | |
| Button clearButton=(Button)findViewById(R.id.delete); | |
| clearButton.setOnClickListener(new OnClickListener(){ | |
| public void onClick(View v) { | |
| Toast.makeText(getBaseContext(), "You can not delete this item. ", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| } | |
| else | |
| { | |
| } | |
| } | |
| public void onNothingSelected(AdapterView<?> arg0) {} | |
| }); | |
| } | |
| @Override | |
| protected void onRestoreInstanceState(Bundle savedInstanceState) { | |
| super.onRestoreInstanceState(savedInstanceState); | |
| this.Items(); | |
| } | |
| private void Items() { | |
| // TODO Auto-generated method stub | |
| } | |
| @Override | |
| protected void onSaveInstanceState(Bundle outState) { | |
| super.onSaveInstanceState(outState); | |
| this.Items(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment