Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../img/srcFileCovDistChart9.png 40% of files have more coverage
112   273   32   5,6
20   210   0,29   20
20     1,6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  TimeWidget       Line # 15 112 32 84,9% 0.8486842
 
No Tests
 
1   
2    package pl.magot.vetch.widgets;
3   
4   
5    import android.app.*;
6    import android.content.Intent;
7    import android.os.Bundle;
8    import android.view.*;
9    import android.widget.Button;
10    import android.widget.LinearLayout;
11    import android.widget.TextView;
12    import android.widget.LinearLayout.LayoutParams;
13   
14   
 
15    public class TimeWidget extends Activity
16    {
17    //fields
18    private static String sStrSelect = "Select time";
19    private static String sStrSet = "set";
20    private static String sStrNone = "none";
21   
22    //fields
23    public static final int SELECT_TIME_REQUEST = 112;
24    public static final int iSliderViewWidth = 276;
25    private static final int iSmallButtonWidth = 100;
26   
27    //fields
28    private LinearLayout layContent = null;
29    private Button btnNone = null;
30    private Button btnOK = null;
31   
32    //fields
33    private boolean bNoneButton = true;
34    private boolean b24HourMode = false;
35    private int iHour = -1;
36    private int iMinutes = -1;
37   
38    //fields
39    TimeCaption labCaption = null;
40    TimeWidgetSlider timeSliderHour = null;
41    TimeWidgetSlider timeSliderMinutes = null;
42   
43   
44    //methods
 
45  2 toggle @Override
46    public void onCreate(Bundle icicle)
47    {
48  2 super.onCreate(icicle);
49   
50  2 setTitle(sStrSelect);
51   
52    //init to defaults
53  2 bNoneButton = true;
54  2 b24HourMode = false;
55  2 iHour = -1;
56  2 iMinutes = -1;
57   
58    //get startup data
59  2 Bundle data = this.getIntent().getExtras();
60  2 if (data != null)
61    {
62  2 if (data.containsKey("noneButton"))
63  2 bNoneButton = data.getBoolean("noneButton");
64  2 if (data.containsKey("24HourMode"))
65  2 b24HourMode = data.getBoolean("24HourMode");
66  2 if (data.containsKey("Hour"))
67  2 iHour = data.getInt("Hour");
68  2 if (data.containsKey("Minute"))
69  2 iMinutes = data.getInt("Minute");
70    }
71   
72  2 setContentView(generateContentView());
73   
74  2 timeSliderHour.setValue(iHour, false);
75  2 timeSliderMinutes.setValue(iMinutes, false);
76   
77  2 timeSliderHour.requestFocus();
78    }
79   
 
80  0 toggle @Override
81    protected void onSaveInstanceState(Bundle outState)
82    {
83  0 super.onSaveInstanceState(outState);
84   
85    //cancel time edit on activity change
86  0 this.finish();
87    }
88   
 
89  2 toggle @Override
90    public void onStart()
91    {
92  2 super.onStart();
93   
94    }
95   
 
96  1 toggle public static void setStrings(String strSelect, String strNone, String strSet)
97    {
98  1 sStrSelect = new String(strSelect);
99  1 sStrNone = new String(strNone);
100  1 sStrSet = new String(strSet);
101    }
102   
 
103  2 toggle public static void Open(Activity parentActivity, boolean bNoneButton, boolean b24HourMode, int iHour, int iMinute)
104    {
105  2 Intent it = new Intent("android.intent.action.AnCal.ACTION_MODE_EDIT_SELECT_TIME");
106  2 Bundle data = new Bundle();
107  2 data.putInt("Hour", iHour);
108  2 data.putInt("Minute", iMinute);
109  2 data.putBoolean("24HourMode", b24HourMode);
110  2 data.putBoolean("noneButton", bNoneButton);
111  2 it.putExtras(data);
112  2 parentActivity.startActivityForResult(it, SELECT_TIME_REQUEST);
113    }
114   
 
115  2 toggle public static int GetSelectedTimeHourOnActivityResult(int requestCode, int resultCode, Bundle extras)
116    {
117  2 if ((requestCode == TimeWidget.SELECT_TIME_REQUEST) && (resultCode == RESULT_OK))
118  2 if (extras.containsKey("Hour"))
119  2 return extras.getInt("Hour");
120  0 return -1;
121    }
122   
 
123  2 toggle public static int GetSelectedTimeMinuteOnActivityResult(int requestCode, int resultCode, Bundle extras)
124    {
125  2 if ((requestCode == TimeWidget.SELECT_TIME_REQUEST) && (resultCode == RESULT_OK))
126  2 if (extras.containsKey("Minute"))
127  2 return extras.getInt("Minute");
128  0 return -1;
129    }
130   
 
131  14 toggle public LinearLayout createLayout(int iOrientation)
132    {
133  14 LinearLayout lay = new LinearLayout(this);
134  14 lay.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
135  14 lay.setOrientation(iOrientation);
136  14 return lay;
137    }
138   
 
139  4 toggle public Button createButton(String sText, int iWidth, int iHeight)
140    {
141  4 Button btn = new Button(this);
142  4 btn.setText(sText);
143  4 btn.setLayoutParams(new LayoutParams(iWidth, iHeight));
144  4 return btn;
145    }
146   
 
147  2 toggle public TextView createLabel(String sText, int iWidth, int iHeight)
148    {
149  2 TextView label = new TextView(this);
150  2 label.setText(sText);
151  2 label.setLayoutParams(new LayoutParams(iWidth, iHeight));
152  2 return label;
153    }
154   
 
155  2 toggle private void getDataFromSliders()
156    {
157  2 iHour = timeSliderHour.getValue();
158  2 iMinutes = timeSliderMinutes.getValue();
159    }
160   
 
161  2 toggle public void generateBottomButtons(LinearLayout layBottomControls)
162    {
163  2 TextView labMargin = createLabel("", 8, android.view.ViewGroup.LayoutParams.FILL_PARENT);
164   
165  2 btnNone = createButton(sStrNone, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
166  2 btnNone.setBackgroundResource(android.R.drawable.btn_default_small);
167   
168  2 btnOK = createButton(sStrSet, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
169  2 btnOK.setBackgroundResource(android.R.drawable.btn_default_small);
170   
171    //set events
172  2 btnNone.setOnClickListener(new Button.OnClickListener()
173    {
 
174  0 toggle public void onClick(View arg0) {
175  0 clearTime();
176  0 OnClose();
177    }});
178   
179  2 btnOK.setOnClickListener(new Button.OnClickListener()
180    {
 
181  2 toggle public void onClick(View arg0) {
182  2 getDataFromSliders();
183  2 OnClose();
184    }});
185   
186  2 layBottomControls.setGravity(Gravity.CENTER_HORIZONTAL);
187  2 if (bNoneButton)
188    {
189  0 layBottomControls.addView(btnNone);
190  0 layBottomControls.addView(labMargin);
191    }
192  2 layBottomControls.addView(btnOK);
193    }
194   
 
195  2 toggle private View createLabelCaption()
196    {
197  2 labCaption = new TimeCaption(this, b24HourMode, iSliderViewWidth - 120);
198  2 return labCaption;
199    }
200   
 
201  2 toggle private View generateContentView()
202    {
203  2 LinearLayout layMain = createLayout(LinearLayout.VERTICAL);
204  2 layMain.setPadding(8, 8, 8, 8);
205   
206  2 LinearLayout layTopControls = createLayout(LinearLayout.HORIZONTAL);
207  2 LinearLayout layContentTop = createLayout(LinearLayout.HORIZONTAL);
208  2 LinearLayout layContentBottom = createLayout(LinearLayout.HORIZONTAL);
209  2 LinearLayout layBottomControls = createLayout(LinearLayout.HORIZONTAL);
210  2 LinearLayout layMargin = createLayout(LinearLayout.HORIZONTAL);
211  2 layContent = createLayout(LinearLayout.VERTICAL);
212   
213  2 layTopControls.addView(createLabelCaption());
214  2 layTopControls.setGravity(Gravity.CENTER_HORIZONTAL);
215   
216  2 generateBottomButtons(layBottomControls);
217   
218  2 layContentTop.getLayoutParams().height = 16;
219  2 layContentBottom.getLayoutParams().height = 18;
220  2 layMargin.getLayoutParams().height = 18;
221   
222  2 timeSliderHour = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth);
223  2 timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth);
224   
225  2 timeSliderHour.setTimeChangeEvent(mOnTimeChangeEvent);
226  2 timeSliderMinutes.setTimeChangeEvent(mOnTimeChangeEvent);
227   
228  2 layContent.addView(timeSliderHour);
229  2 layContent.addView(layMargin);
230  2 layContent.addView(timeSliderMinutes);
231   
232  2 layMain.addView(layTopControls);
233  2 layMain.addView(layContentTop);
234  2 layMain.addView(layContent);
235  2 layMain.addView(layContentBottom);
236  2 layMain.addView(layBottomControls);
237   
238  2 return layMain;
239    }
240   
 
241  2 toggle public void OnClose()
242    {
243  2 Bundle data = new Bundle();
244  2 data.putInt("Hour", iHour);
245  2 data.putInt("Minute", iMinutes);
246   
247  2 Intent intentData = new Intent("");
248  2 intentData.putExtras(data);
249  2 setResult(RESULT_OK, intentData);
250   
251  2 this.finish();
252    }
253   
 
254  0 toggle public void clearTime()
255    {
256  0 iHour = -1;
257  0 iMinutes = -1;
258    }
259   
 
260  27 toggle public void updateLabelCaption()
261    {
262  27 labCaption.setTime(timeSliderHour.getValue(), timeSliderMinutes.getValue());
263    }
264   
265    private TimeWidgetSlider.OnTimeChange mOnTimeChangeEvent = new TimeWidgetSlider.OnTimeChange()
266    {
 
267  27 toggle public void OnChange(TimeWidgetSlider slider)
268    {
269  27 updateLabelCaption();
270    }
271    };
272   
273    }