summaryrefslogtreecommitdiffstats
path: root/Android
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-03-02 12:09:16 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 17:40:55 +0100
commit9f4f2c3cd098159e741995c453df6d5da9fdb89d (patch)
treea183d3f592c1bfa771ca9938046587c27affdae2 /Android
parentd1d4b77dccabb24d88cb3de78d6e9c374ddf5676 (diff)
downloadcoursera-9f4f2c3cd098159e741995c453df6d5da9fdb89d.zip
coursera-9f4f2c3cd098159e741995c453df6d5da9fdb89d.tar.gz
Android : 05-UserInterface: implement
Diffstat (limited to 'Android')
-rw-r--r--Android/05-UserInterface/UILab/src/course/labs/todomanager/AddToDoActivity.java31
-rw-r--r--Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoListAdapter.java39
-rw-r--r--Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoManagerActivity.java20
3 files changed, 47 insertions, 43 deletions
diff --git a/Android/05-UserInterface/UILab/src/course/labs/todomanager/AddToDoActivity.java b/Android/05-UserInterface/UILab/src/course/labs/todomanager/AddToDoActivity.java
index 6604871..23e7198 100644
--- a/Android/05-UserInterface/UILab/src/course/labs/todomanager/AddToDoActivity.java
+++ b/Android/05-UserInterface/UILab/src/course/labs/todomanager/AddToDoActivity.java
@@ -43,6 +43,9 @@ public class AddToDoActivity extends Activity {
private RadioButton mDefaultStatusButton;
private RadioButton mDefaultPriorityButton;
+ private int defaultPriority;
+ private int defaultStatus;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -56,6 +59,9 @@ public class AddToDoActivity extends Activity {
dateView = (TextView) findViewById(R.id.date);
timeView = (TextView) findViewById(R.id.time);
+ defaultPriority = mPriorityRadioGroup.getCheckedRadioButtonId ();
+ defaultStatus = mStatusRadioGroup.getCheckedRadioButtonId ();
+
// Set the default date and time
setDefaultDateTime();
@@ -85,7 +91,8 @@ public class AddToDoActivity extends Activity {
@Override
public void onClick(View v) {
log("Entered cancelButton.OnClickListener.onClick()");
- //TODO - Implement onClick().
+ setResult(RESULT_CANCELED, new Intent());
+ finish();
}
});
@@ -95,7 +102,10 @@ public class AddToDoActivity extends Activity {
@Override
public void onClick(View v) {
log("Entered resetButton.OnClickListener.onClick()");
- //TODO - Reset data fields to default values
+ mTitleText.getText().clear();
+ mPriorityRadioGroup.check(defaultPriority);
+ mStatusRadioGroup.check(defaultStatus);
+ setDefaultDateTime();
}
});
@@ -108,23 +118,16 @@ public class AddToDoActivity extends Activity {
log("Entered submitButton.OnClickListener.onClick()");
// Gather ToDoItem data
-
- //TODO - Get Priority
- Priority priority = null;
-
- //TODO - Get Status
- Status status = null;
-
- //TODO - Title
- String titleString = null;
-
- // Date
+ Priority priority = getPriority();
+ Status status = getStatus();
+ String titleString = mTitleText.getText().toString();
String fullDate = dateString + " " + timeString;
// Package ToDoItem data into an Intent
Intent data = new Intent();
ToDoItem.packageIntent(data, titleString, priority, status, fullDate);
- //TODO - return data Intent and finish
+ setResult(RESULT_OK, data);
+ finish();
}
});
}
diff --git a/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoListAdapter.java b/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoListAdapter.java
index 5f16ac8..7cad4be 100644
--- a/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoListAdapter.java
+++ b/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoListAdapter.java
@@ -65,39 +65,38 @@ public class ToDoListAdapter extends BaseAdapter {
// at specified position in mItems
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- //TODO - Get the current ToDoItem
- final ToDoItem toDoItem = null;
+ final ToDoItem toDoItem = (ToDoItem) getItem(position);
- //TODO - Inflate the View for this ToDoItem
- // from todo_item.xml.
RelativeLayout itemLayout = null;
+ if (convertView == null) {
+ itemLayout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.todo_item, null);
+ } else {
+ itemLayout = (RelativeLayout) convertView;
+ }
- //TODO - Fill in specific ToDoItem data
- // Remember that the data that goes in this View
- // corresponds to the user interface elements defined
- // in the layout file
-
- //TODO - Display Title in TextView
- final TextView titleView = null;
+ final TextView titleView = (TextView) itemLayout.findViewById(R.id.titleView);
+ titleView.setText(toDoItem.getTitle());
- // TODO - Set up Status CheckBox
- final CheckBox statusView = null;
+ final CheckBox statusView = (CheckBox) itemLayout.findViewById(R.id.statusCheckBox);
+ statusView.setChecked(toDoItem.getStatus() == Status.DONE);
statusView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
log("Entered onCheckedChanged()");
- // TODO - Set up and implement an OnCheckedChangeListener, which
- // is called when the user toggles the status checkbox
+ if(isChecked){
+ toDoItem.setStatus(Status.DONE);
+ } else {
+ toDoItem.setStatus(Status.NOTDONE);
+ }
}
});
- //TODO - Display Priority in a TextView
- final TextView priorityView = null;
+ final TextView priorityView = (TextView) itemLayout.findViewById(R.id.priorityView);
+ priorityView.setText(toDoItem.getPriority().toString());
- // TODO - Display Time and Date.
- // Hint - use ToDoItem.FORMAT.format(toDoItem.getDate()) to get date and time String
- final TextView dateView = null;
+ final TextView dateView = (TextView) itemLayout.findViewById(R.id.dateView);
+ dateView.setText(ToDoItem.FORMAT.format(toDoItem.getDate()));
// Return the View you just created
return itemLayout;
diff --git a/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoManagerActivity.java b/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoManagerActivity.java
index fe8d9eb..a911b1d 100644
--- a/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoManagerActivity.java
+++ b/Android/05-UserInterface/UILab/src/course/labs/todomanager/ToDoManagerActivity.java
@@ -49,29 +49,31 @@ public class ToDoManagerActivity extends ListActivity {
// Put divider between ToDoItems and FooterView
getListView().setFooterDividersEnabled(true);
- //TODO - Inflate footerView for footer_view.xml file
- TextView footerView = null;
- //TODO - Add footerView to ListView
+ TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, null);
+ getListView().addFooterView(footerView);
footerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
log("Entered footerView.OnClickListener.onClick()");
- //TODO - Attach Listener to FooterView. Implement onClick().
+ Intent intent = new Intent(ToDoManagerActivity.this, AddToDoActivity.class);
+ startActivityForResult(intent, ADD_TODO_ITEM_REQUEST);
}
});
- //TODO - Attach the adapter to this ListActivity's ListView
+ getListView().setAdapter(mAdapter);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
log("Entered onActivityResult()");
- // TODO - Check result code and request code.
- // If user submitted a new ToDoItem
- // Create a new ToDoItem from the data Intent
- // and then add it to the adapter
+ if (requestCode == ADD_TODO_ITEM_REQUEST) {
+ if (resultCode == RESULT_OK) {
+ ToDoItem item = new ToDoItem(data);
+ mAdapter.add(item);
+ }
+ }
}
// Do not modify below here