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
119   300   36   6,26
28   230   0,3   19
19     1,89  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  KeyboardWidget       Line # 15 119 36 84,9% 0.8493976
 
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 KeyboardWidget extends Activity
16    {
17    //fields
18    public static final int EDIT_TEXT_REQUEST = 113;
19    private static final int iSmallButtonWidth = 100;
20   
21    //margin from left/right to window frame: 8px. window frame: 2px
22    public static final int iMaxWidth = 320 - (20 * 2);
23    public static final int iMaxHeight = 480;
24   
25    //fields
26    private static String sStrTitle = "Enter text";
27    private static String sStrSet = "set";
28    private static String sStrCancel= "cancel";
29   
30    //fields
31    private LinearLayout layContent = null;
32    private KeyboardWidgetView keyboard = null;
33    private HintEdit edit = null;
34    private Button btnCancel = null;
35    private Button btnSet = null;
36   
37    //methods
 
38  5 toggle @Override
39    public void onCreate(Bundle icicle)
40    {
41  5 super.onCreate(icicle);
42   
43  5 setTitle(sStrTitle);
44   
45    //get startup data
46  5 String sText = "";
47  5 Bundle data = this.getIntent().getExtras();
48  5 if (data != null)
49    {
50  5 if (data.containsKey("text"))
51  5 sText = data.getString("text");
52    }
53   
54    //restore data from freeze state
55  5 if (icicle != null)
56    {
57  0 sText = icicle.getString("freezeText");
58    }
59   
60  5 setContentView(generateContentView());
61   
62  5 initializeEditing(sText);
63    }
64   
 
65  1 toggle @Override
66    protected void onSaveInstanceState(Bundle outState)
67    {
68  1 super.onSaveInstanceState(outState);
69    //save controls state
70  1 outState.putString("freezeText", edit.getText().toString().trim());
71    }
72   
 
73  5 toggle @Override
74    public void onStart()
75    {
76  5 super.onStart();
77   
78    }
79   
 
80  0 toggle public static void setStrings(String sStrTitle)
81    {
82  0 KeyboardWidget.sStrTitle = new String(sStrTitle);
83    }
84   
 
85  0 toggle public static void setStrings(String sStrTitle, String sStrCancel, String strSet)
86    {
87  0 sStrTitle = new String(sStrTitle);
88  0 sStrCancel = new String(sStrCancel);
89  0 strSet = new String(strSet);
90    }
91   
 
92  5 toggle public static void Open(Activity parentActivity, String sText)
93    {
94  5 Intent it = new Intent("android.intent.action.AnCal.ACTION_MODE_EDIT_TEXT");
95  5 Bundle data = new Bundle();
96  5 data.putString("text", sText);
97  5 it.putExtras(data);
98  5 parentActivity.startActivityForResult(it, EDIT_TEXT_REQUEST);
99    }
100   
 
101  4 toggle public static String GetTextOnActivityResult(int requestCode, int resultCode, Bundle extras)
102    {
103  4 if ((requestCode == KeyboardWidget.EDIT_TEXT_REQUEST) && (resultCode == RESULT_OK))
104    {
105  4 if (extras.containsKey("text"))
106    {
107  4 return extras.getString("text");
108    }
109    }
110  0 return "";
111    }
112   
 
113  30 toggle public LinearLayout createLayout(int iOrientation)
114    {
115  30 LinearLayout lay = new LinearLayout(this);
116  30 lay.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
117  30 lay.setOrientation(iOrientation);
118  30 return lay;
119    }
120   
 
121  10 toggle public Button createButton(String sText, int iWidth, int iHeight)
122    {
123  10 Button btn = new Button(this);
124  10 btn.setText(sText);
125  10 btn.setLayoutParams(new LayoutParams(iWidth, iHeight));
126  10 return btn;
127    }
128   
 
129  5 toggle public TextView createLabel(String sText, int iWidth, int iHeight)
130    {
131  5 TextView label = new TextView(this);
132  5 label.setText(sText);
133  5 label.setLayoutParams(new LayoutParams(iWidth, iHeight));
134  5 return label;
135    }
136   
 
137  5 toggle public void generateBottomButtons(LinearLayout layBottomControls)
138    {
139  5 TextView labMargin = createLabel("", 8, android.view.ViewGroup.LayoutParams.FILL_PARENT);
140   
141  5 btnCancel = createButton(sStrCancel, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
142  5 btnCancel.setBackgroundResource(android.R.drawable.btn_default_small);
143   
144  5 btnSet = createButton(sStrSet, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
145  5 btnSet.setBackgroundResource(android.R.drawable.btn_default_small);
146   
147    //set events
148  5 btnCancel.setOnClickListener(new Button.OnClickListener()
149    {
 
150  1 toggle public void onClick(View arg0) {
151  1 OnClose(false);
152    }});
153  5 btnSet.setOnClickListener(new Button.OnClickListener()
154    {
 
155  4 toggle public void onClick(View arg0) {
156  4 OnClose(true);
157    }});
158   
159  5 layBottomControls.setGravity(Gravity.CENTER_HORIZONTAL);
160  5 layBottomControls.addView(btnCancel);
161  5 layBottomControls.addView(labMargin);
162  5 layBottomControls.addView(btnSet);
163    }
164   
 
165  5 toggle public void OnClose(boolean bOK)
166    {
167  5 Bundle data = new Bundle();
168  5 data.putString("text", edit.getText().toString().trim());
169   
170  5 Intent intentData = new Intent("");
171  5 intentData.putExtras(data);
172  5 setResult(bOK?RESULT_OK:RESULT_CANCELED, intentData);
173   
174  5 this.finish();
175    }
176   
 
177  5 toggle public HintEdit createEditBox()
178    {
179  5 edit = new HintEdit(this);
180  5 edit.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
181  5 edit.setLines(3);
182  5 edit.setGravity(Gravity.TOP);
183  5 edit.setFocusable(true);
184   
185  5 return edit;
186    }
187   
 
188  5 toggle private View generateContentView()
189    {
190  5 LinearLayout layMain = createLayout(LinearLayout.VERTICAL);
191  5 layMain.setPadding(8, 8, 8, 8);
192   
193  5 LinearLayout layTopControls = createLayout(LinearLayout.HORIZONTAL);
194  5 LinearLayout layMargin = createLayout(LinearLayout.HORIZONTAL);
195  5 layMargin.getLayoutParams().height = 12;
196   
197  5 LinearLayout layContentBottom = createLayout(LinearLayout.HORIZONTAL);
198  5 layContentBottom.getLayoutParams().height = 18;
199   
200  5 LinearLayout layBottomControls = createLayout(LinearLayout.HORIZONTAL);
201   
202    //top edit box
203  5 edit = createEditBox();
204  5 layTopControls.addView(edit);
205   
206    //content
207  5 layContent = createLayout(LinearLayout.VERTICAL);
208   
209  5 keyboard = new KeyboardWidgetView(this, iMaxWidth);
210   
211  5 layContent.getLayoutParams().width = iMaxWidth;
212  5 layContent.getLayoutParams().height = keyboard.getTotalHeight();
213   
214  5 layContent.addView(keyboard);
215   
216  5 generateBottomButtons(layBottomControls);
217   
218  5 layMain.addView(layTopControls);
219  5 layMain.addView(layMargin);
220  5 layMain.addView(layContent);
221  5 layMain.addView(layContentBottom);
222  5 layMain.addView(layBottomControls);
223   
224  5 return layMain;
225    }
226   
 
227  5 toggle public void initializeEditing(String sText)
228    {
229  5 keyboard.setKeyClickEvent(mOnKeyClick);
230  5 keyboard.editText = edit;
231  5 edit.setText(sText);
232  5 edit.setSelectAllOnFocus(true);
233    }
234   
235    public KeyboardWidgetView.OnKeyClick mOnKeyClick = new KeyboardWidgetView.OnKeyClick()
236    {
 
237  25 toggle public void OnKeyClicked(KeyItem key, boolean bCapital)
238    {
239  25 key.sendKey(edit, bCapital);
240  25 autoChangeLayout(key);
241    }
242    };
243   
 
244  25 toggle public void autoChangeLayout(KeyItem key)
245    {
246  25 KeyItemLayout keys = keyboard.getKeyLayout();
247  25 String sText = edit.getText().toString();
248   
249    //reset layout
250  25 if (sText.length() == 0)
251    {
252  0 keys.setLayoutBigCaps();
253  0 keyboard.invalidate();
254  0 return;
255    }
256   
257    //change layout to small caps after first letter
258  25 if (sText.length() == 1)
259    {
260  2 keys.setLayoutSmallCaps();
261  2 keyboard.invalidate();
262  2 return;
263    }
264   
265    //change layout to big caps after period
266  23 if ((sText.length() > 0) && (key.iType == KeyItem.kAlphaCycle))
267    {
268  1 if (sText.charAt(sText.length() - 1) == '.')
269    {
270  1 keys.setLayoutBigCaps();
271  1 keyboard.invalidate();
272  1 return;
273    }
274  0 if (sText.charAt(sText.length() - 1) == ',')
275    {
276  0 keys.setLayoutSmallCaps();
277  0 keyboard.invalidate();
278  0 return;
279    }
280    }
281   
282    //change layout to big caps after period and big letter
283  22 int index = sText.lastIndexOf(".");
284  22 if ((index != -1) && (sText.length() > 0))
285    {
286  10 sText = sText.substring(index + 1).trim();
287  10 if (sText.length() == 1)
288    {
289  1 if (Character.isUpperCase(sText.charAt(0)))
290    {
291  1 keys.setLayoutSmallCaps();
292  1 keyboard.invalidate();
293  1 return;
294    }
295    }
296    }
297   
298    }
299   
300    }