Permalink
Browse files

Added an interactivelistview class for the countdowntimer, added oncl…

…icked events for the iteractivelistview.
  • Loading branch information...
1 parent 98b737c commit f4c7d2ca3d5568ca601539bc06bf60a8a6db16a7 @maddog666 committed Apr 19, 2012
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -44,7 +44,7 @@
android:layout_height="0sp"
android:layout_width="fill_parent"/>
- <fragment android:name="com.hook38.sporttimer.view.ListView"
+ <fragment android:name="com.hook38.sporttimer.view.InteractiveListView"
android:id="@+id/listview_fragment"
android:layout_weight="5"
android:layout_height="0dp"
@@ -3,6 +3,7 @@
import com.hook38.sporttimer.controller.ActivityController;
import com.hook38.sporttimer.controller.CountdownTimerController;
import com.hook38.sporttimer.view.ClockView;
+import com.hook38.sporttimer.view.InteractiveListView;
import com.hook38.sporttimer.view.ListView;
import com.hook38.sporttimer.view.TimeInputView;
@@ -47,7 +48,7 @@ public void onCreate(Bundle savedInstanceState) {
ClockView clockview_fragment =
(ClockView) getSupportFragmentManager().findFragmentById(R.id.clock_fragment);
ListView listview_fragment =
- (ListView) getSupportFragmentManager().findFragmentById(R.id.listview_fragment);
+ (InteractiveListView) getSupportFragmentManager().findFragmentById(R.id.listview_fragment);
timeinputview_fragment =
(TimeInputView) getSupportFragmentManager().findFragmentById(R.id.timer_input_fragment);
@@ -99,12 +100,15 @@ public void onClick(View arg0) {
switch(arg0.getId()) {
case R.id.add_button:
+ /*
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Time input");
alertDialog.setMessage(controller.getInputHour()+" " +
controller.getInputMinute() + " " +
controller.getInputSecond());
alertDialog.show();
+ */
+ controller.addTime();
break;
}
}
@@ -8,6 +8,8 @@
import android.os.Handler;
import android.util.Log;
+import com.hook38.sporttimer.model.CountdownTimerModel;
+import com.hook38.sporttimer.utils.TimeUnits;
import com.hook38.sporttimer.utils.countdowntimer.RoutineList;
import com.hook38.sporttimer.view.ClockView;
import com.hook38.sporttimer.view.ListView;
@@ -18,12 +20,14 @@
private static final String ROUTINE_LIST = "RoutineList";
private Handler handler = new Handler();
private TimeInputView timeinputview;
+ private CountdownTimerModel timerModel;
public CountdownTimerController(Context context, ClockView clockView, ListView listView,
TimeInputView timeinput) {
super(context, clockView, listView);
// TODO Auto-generated constructor stub
this.timeinputview = timeinput;
+ this.timerModel = new CountdownTimerModel();
}
@Override
@@ -65,4 +69,52 @@ public String getInputMinute() {
public String getInputSecond() {
return this.timeinputview.getSecond();
}
+
+ private void updateView() {
+ this.listView.populateList(timerModel.toStringList());
+ }
+
+ public void addTime() {
+ TimeUnits units = new TimeUnits();
+ units.add(Float.parseFloat(getInputHour()));
+ units.add(Float.parseFloat(getInputMinute()));
+ units.add(Float.parseFloat(getInputSecond()));
+ this.addTime(units);
+ }
+
+ /**
+ * Return the size of the current timers in the timer model
+ * @return size of the current timer
+ */
+ public int timerSize() {
+ return timerModel.size();
+ }
+
+ /**
+ * Add the user defined time into the timer model
+ * @param units
+ */
+ public void addTime(TimeUnits units) {
+ timerModel.add(units);
+ this.updateView();
+ }
+
+ /**
+ * Get the time in timer model given the
+ * @param posi position of the list
+ * @return TimeUnits at the position
+ */
+ public TimeUnits getTime(int posi) {
+ return timerModel.get(posi);
+ }
+
+ /**
+ * Remove the time at the defined position in the timer model
+ * @param posi
+ */
+ public void removeTime(int posi) {
+ timerModel.remove(posi);
+ this.updateView();
+ }
+
}
@@ -13,10 +13,11 @@
private ArrayList<TimeUnits> list = new ArrayList<TimeUnits>();
public void add(TimeUnits units) {
- list.add(units);
+ list.add(0, units);
}
- public TimeUnits get(int posi) {
+ public TimeUnits get(int posi)
+ throws ArrayIndexOutOfBoundsException {
return list.get(posi);
}
@@ -28,11 +29,13 @@ public void clear() {
list.clear();
}
- public void remove(int i) {
+ public void remove(int i)
+ throws ArrayIndexOutOfBoundsException {
list.remove(i);
}
- public void set(int posi, TimeUnits units) {
+ public void set(int posi, TimeUnits units)
+ throws ArrayIndexOutOfBoundsException {
list.set(posi, units);
}
@@ -48,15 +51,15 @@ public String toString() {
text = text.concat(",");
start = false;
}
- text = text.concat(units.toString());
+ text = text.concat(units.toIntString());
}
return text;
}
public List<String> toStringList() {
ArrayList<String> tempList = new ArrayList<String>();
for(TimeUnits units : this.list) {
- tempList.add(units.toString());
+ tempList.add(units.toIntString());
}
return tempList;
}
@@ -62,5 +62,16 @@ public String toString() {
return string;
}
+ public String toIntString() {
+ String string = "";
+ for(int i=0; i<units.size(); i++) {
+ if(i!=0){
+ string +=":";
+ }
+ string+=(Math.round(units.get(i)));
+ }
+ return string;
+ }
+
}
@@ -0,0 +1,37 @@
+package com.hook38.sporttimer.view;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemLongClickListener;
+
+public class InteractiveListView extends ListView {
+ @Override
+ public void onStart() {
+ super.onStart();
+ getListView().setOnItemLongClickListener(new OnItemLongClickListener(){
+
+ public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
+ int arg2, long arg3) {
+ // TODO Auto-generated method stub
+ final CharSequence[] items = {"Edit", "Delete"};
+ final int selected = arg2;
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle("Choose an action");
+ builder.setItems(items, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ Toast.makeText(getActivity().getApplicationContext(), items[item]+" "+selected, Toast.LENGTH_SHORT).show();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ return false;
+ }
+
+ });
+ }
+}
@@ -5,13 +5,17 @@
import com.hook38.sporttimer.R;
+import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
+import android.widget.Toast;
public class ListView extends ListFragment {
@@ -28,6 +32,8 @@ public View onCreateView (LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.listview_fragment, container, false);
}
+
+
public void populateList(List<String> list) {
ListAdapter myListAdapter = new ArrayAdapter<String> (
getActivity(),

0 comments on commit f4c7d2c

Please sign in to comment.