Back to project page WorkTime.
The source code is released under:
GNU General Public License
If you think the Android project WorkTime 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.overapps.worktime; // w w w.j av a 2s . c o m import android.app.*; import android.os.*; import android.widget.*; import java.text.*; import java.util.*; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity implements OnClickListener { // Database Helper dbHelper db; TextView t1, t2, t3, tf; Calendar cal; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); db = new dbHelper(getApplicationContext()); t1 = (TextView)findViewById(R.id.text1); t2 = (TextView)findViewById(R.id.text2); t3 = (TextView)findViewById(R.id.text3); tf = (TextView)findViewById(R.id.bottomText); Button startButton = (Button)findViewById(R.id.startB); Button endButton = (Button)findViewById(R.id.endB); Button bottomB = (Button)findViewById(R.id.bottomButton); startButton.setOnClickListener(this); endButton.setOnClickListener(this); bottomB.setOnClickListener(this); } private String getDate(int p) { cal = Calendar.getInstance(); Date date = cal.getTime(); String out ="NA"; if (p == 0) { SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); out = formatDate.format(date); } else { SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); out = formatTime.format(date); } return out; } private void startRecord() { String day = getDate(0); String time = getDate(1); t1.setText(day +" "+ time); t2.setText("starting timer"); insertTimestamp(day, time, 0); } private void endRecord() { String day = getDate(0); String time = getDate(1); t2.setText("ending timer"); t3.setText(day +" "+ time); insertTimestamp(day, time, 1); } private void insertTimestamp(String date, String time, int status) { dbModel record = new dbModel(time, date, status); db.createTimeRow(record); db.close(); } private void getLastTime() { String txt = ""; List<dbModel> allRecord = db.getAllRecords(); for (dbModel t : allRecord) { txt = txt + t.getDay() + " " + t.getTime() + " " + + t.getStatus() + "##"; } tf.setText(txt); db.close(); } @Override public void onClick(View arg0) { //Switch statement so you don't have to use a lot of click listeners switch (arg0.getId()) { case R.id.startB: startRecord(); break; case R.id.endB: endRecord(); break; case R.id.bottomButton: getLastTime(); break; } } } // // Creating tags // Tag tag1 = new Tag("Shopping"); // Tag tag2 = new Tag("Important"); // Tag tag3 = new Tag("Watchlist"); // // // Inserting tags in db // long tag1_id = db.createTag(tag1); // // Log.d("Tag Count", "Tag Count: " + db.getAllTags().size()); // // // Creating ToDos // Todo todo1 = new Todo("iPhone 5S", 0); // Todo todo2 = new Todo("Galaxy Note II", 0); // Todo todo3 = new Todo("Whiteboard", 0); // // Todo todo4 = new Todo("Riddick", 0); // Todo todo5 = new Todo("Prisoners", 0); // Todo todo6 = new Todo("The Croods", 0); // Todo todo7 = new Todo("Insidious: Chapter 2", 0); // // Todo todo8 = new Todo("Don't forget to call MOM", 0); // Todo todo9 = new Todo("Collect money from John", 0); // // Todo todo10 = new Todo("Post new Article", 0); // Todo todo11 = new Todo("Take database backup", 0); // // // Inserting todos in db // // Inserting todos under "Shopping" Tag // long todo1_id = db.createToDo(todo1, new long[] { tag1_id }); // long todo2_id = db.createToDo(todo2, new long[] { tag1_id }); // long todo3_id = db.createToDo(todo3, new long[] { tag1_id }); // // // Inserting todos under "Watchlist" Tag // long todo4_id = db.createToDo(todo4, new long[] { tag3_id }); // long todo5_id = db.createToDo(todo5, new long[] { tag3_id }); // long todo6_id = db.createToDo(todo6, new long[] { tag3_id }); // long todo7_id = db.createToDo(todo7, new long[] { tag3_id }); // // // Inserting todos under "Important" Tag // long todo8_id = db.createToDo(todo8, new long[] { tag2_id }); // long todo9_id = db.createToDo(todo9, new long[] { tag2_id }); // // // Inserting todos under "Androidhive" Tag // long todo10_id = db.createToDo(todo10, new long[] { tag4_id }); // long todo11_id = db.createToDo(todo11, new long[] { tag4_id }); // // Log.e("Todo Count", "Todo count: " + db.getToDoCount()); // // // "Post new Article" - assigning this under "Important" Tag // // Now this will have - "Androidhive" and "Important" Tags // db.createTodoTag(todo10_id, tag2_id); // // // Getting all tag names // Log.d("Get Tags", "Getting All Tags"); // // List<Tag> allTags = db.getAllTags(); // for (Tag tag : allTags) { // Log.d("Tag Name", tag.getTagName()); // } // // // Getting all Todos // Log.d("Get Todos", "Getting All ToDos"); // // List<Todo> allToDos = db.getAllToDos(); // for (Todo todo : allToDos) { // Log.d("ToDo", todo.getNote()); // } // // // Getting todos under "Watchlist" tag name // Log.d("ToDo", "Get todos under single Tag name"); // // List<Todo> tagsWatchList = db.getAllToDosByTag(tag3.getTagName()); // for (Todo todo : tagsWatchList) { // Log.d("ToDo Watchlist", todo.getNote()); // } // // // Deleting a ToDo // Log.d("Delete ToDo", "Deleting a Todo"); // Log.d("Tag Count", "Tag Count Before Deleting: " + db.getToDoCount()); // // db.deleteToDo(todo8_id); // // Log.d("Tag Count", "Tag Count After Deleting: " + db.getToDoCount()); // // // Deleting all Todos under "Shopping" tag // Log.d("Tag Count", // "Tag Count Before Deleting 'Shopping' Todos: " // + db.getToDoCount()); // // db.deleteTag(tag1, true); // // Log.d("Tag Count", // "Tag Count After Deleting 'Shopping' Todos: " // + db.getToDoCount()); // // // Updating tag name // tag3.setTagName("Movies to watch"); // db.updateTag(tag3); // // // Don't forget to close database connection // db.closeDB();