1 | /*
|
1 | /**
|
2 | *
|
2 | *
|
3 | * Enhanced by Zoff (c) 2011
|
3 | * Enhanced by Zoff (c) 2011 - 2012
|
4 | * zoff@zanavi.cc
|
4 | * zoff@zanavi.cc
|
5 | *
|
5 | *
|
6 | */
|
6 | */
|
7 |
|
7 |
|
8 | /*
|
8 | /**
|
9 | * Copyright (c) 2010, Jeffrey F. Cole
|
9 | * Copyright (c) 2010, Jeffrey F. Cole
|
10 | * All rights reserved.
|
10 | * All rights reserved.
|
11 | *
|
11 | *
|
12 | * Redistribution and use in source and binary forms, with or without
|
12 | * Redistribution and use in source and binary forms, with or without
|
13 | * modification, are permitted provided that the following conditions are met:
|
13 | * modification, are permitted provided that the following conditions are met:
|
… | |
… | |
38 |
|
38 |
|
39 | package net.technologichron.manacalc;
|
39 | package net.technologichron.manacalc;
|
40 |
|
40 |
|
41 | import android.content.Context;
|
41 | import android.content.Context;
|
42 | import android.os.Handler;
|
42 | import android.os.Handler;
|
|
|
43 | import android.text.Editable;
|
43 | import android.text.InputType;
|
44 | import android.text.InputType;
|
|
|
45 | import android.text.TextWatcher;
|
44 | import android.util.AttributeSet;
|
46 | import android.util.AttributeSet;
|
45 | import android.view.Gravity;
|
47 | import android.view.Gravity;
|
46 | import android.view.KeyEvent;
|
48 | import android.view.KeyEvent;
|
47 | import android.view.MotionEvent;
|
49 | import android.view.MotionEvent;
|
48 | import android.view.View;
|
50 | import android.view.View;
|
… | |
… | |
200 | // number
|
202 | // number
|
201 | valueText.setOnKeyListener(new View.OnKeyListener()
|
203 | valueText.setOnKeyListener(new View.OnKeyListener()
|
202 | {
|
204 | {
|
203 | public boolean onKey(View v, int arg1, KeyEvent event)
|
205 | public boolean onKey(View v, int arg1, KeyEvent event)
|
204 | {
|
206 | {
|
|
|
207 | //System.out.println("xx222222222222");
|
205 | int backupValue = value;
|
208 | int backupValue = value;
|
206 | try
|
209 | try
|
207 | {
|
210 | {
|
208 | value = Integer.parseInt(((EditText) v).getText().toString());
|
211 | value = Integer.parseInt(((EditText) v).getText().toString());
|
209 | }
|
212 | }
|
210 | catch (NumberFormatException nfe)
|
213 | catch (NumberFormatException nfe)
|
211 | {
|
214 | {
|
212 | value = backupValue;
|
215 | value = backupValue;
|
213 | }
|
216 | }
|
214 | return false;
|
217 | return false;
|
|
|
218 | }
|
|
|
219 | });
|
|
|
220 |
|
|
|
221 | valueText.addTextChangedListener(new TextWatcher()
|
|
|
222 | {
|
|
|
223 | @Override
|
|
|
224 | public void afterTextChanged(Editable s)
|
|
|
225 | {
|
|
|
226 | //System.out.println("xxxxxxxx111");
|
|
|
227 | int backupValue = value;
|
|
|
228 | try
|
|
|
229 | {
|
|
|
230 | value = Integer.parseInt(valueText.getText().toString());
|
|
|
231 | }
|
|
|
232 | catch (NumberFormatException nfe)
|
|
|
233 | {
|
|
|
234 | value = backupValue;
|
|
|
235 | }
|
|
|
236 | }
|
|
|
237 |
|
|
|
238 | @Override
|
|
|
239 | public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
|
|
240 | {
|
|
|
241 | }
|
|
|
242 |
|
|
|
243 | @Override
|
|
|
244 | public void onTextChanged(CharSequence s, int start, int before, int count)
|
|
|
245 | {
|
215 | }
|
246 | }
|
216 | });
|
247 | });
|
217 |
|
248 |
|
218 | // Highlight the number when we get focus
|
249 | // Highlight the number when we get focus
|
219 | valueText.setOnFocusChangeListener(new View.OnFocusChangeListener()
|
250 | valueText.setOnFocusChangeListener(new View.OnFocusChangeListener()
|