Advertisement
brutual123

provideractivity java class code

Oct 13th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.65 KB | None | 0 0
  1. package com.adigroup;
  2.  
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Context;
  6. import android.content.SharedPreferences;
  7. import android.content.SharedPreferences.Editor;
  8. import android.os.Bundle;
  9. import android.text.Editable;
  10. import android.text.TextWatcher;
  11. import android.text.method.KeyListener;
  12. import android.util.Log;
  13. import android.view.KeyEvent;
  14. import android.view.View;
  15. import android.view.Window;
  16. import android.view.View.OnClickListener;
  17. import android.view.View.OnKeyListener;
  18. import android.widget.Button;
  19. import android.widget.EditText;
  20. import android.widget.ImageView;
  21. import android.widget.TextView;
  22. import android.widget.Toast;
  23.  
  24. public class ProviderActivity extends Activity implements OnClickListener,TextWatcher,OnKeyListener{
  25.  
  26. private static int edittextFalg;
  27. private String _preference = "AutoSmsData" ;
  28. private Editor _editor;
  29. private SharedPreferences _sharedPreference;
  30. private ImageView _saveBtn,_resetBtn;
  31. //private EditText _firstName,_firstName2,_secondName,_telephone1,_telephone2,_mobile,_email,_website,_fax,_im,_address,_companyName;
  32.  
  33. private EditText _companyName,_yourName,_telephone,_cellOrMob,_website,_email,_fax,_im,_addressLine1,_addressLine2,_addressLine3,_addressLine4;
  34. private static int _noOfSmsCount = 0,smsno;
  35. private TextView _textCountTv;
  36. public static boolean cancleClickFlag = false;
  37.  
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. // TODO Auto-generated method stub
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.provider);
  43. _sharedPreference = getSharedPreferences(_preference,Context.MODE_PRIVATE);
  44.  
  45. _companyName = (EditText)findViewById(R.id.companyName);
  46. _companyName.setOnKeyListener(this);
  47. _companyName.addTextChangedListener(this);
  48.  
  49. _yourName = (EditText)findViewById(R.id.yourName);
  50. _yourName.setOnKeyListener(this);
  51. _yourName.addTextChangedListener(this);
  52.  
  53. _telephone = (EditText)findViewById(R.id.telephone);
  54. _telephone.setOnKeyListener(this);
  55. _telephone.addTextChangedListener(this);
  56.  
  57. _cellOrMob = (EditText)findViewById(R.id.cellOrMobile);
  58. _cellOrMob.setOnKeyListener(this);
  59. _cellOrMob.addTextChangedListener(this);
  60.  
  61. _website = (EditText)findViewById(R.id.website);
  62. _website.setOnKeyListener(this);
  63. _website.addTextChangedListener(this);
  64.  
  65. _email = (EditText)findViewById(R.id.email);
  66. _email.setOnKeyListener(this);
  67. _email.addTextChangedListener(this);
  68.  
  69. _fax = (EditText)findViewById(R.id.fax);
  70. _fax.setOnKeyListener(this);
  71. _fax.addTextChangedListener(this);
  72.  
  73. _im = (EditText)findViewById(R.id.im);
  74. _im.setOnKeyListener(this);
  75. _im.addTextChangedListener(this);
  76.  
  77. _addressLine1 = (EditText)findViewById(R.id.addressLine1);
  78. _addressLine1.setOnKeyListener(this);
  79. _addressLine1.addTextChangedListener(this);
  80.  
  81. _addressLine2 = (EditText)findViewById(R.id.addressLine2);
  82. _addressLine2.setOnKeyListener(this);
  83. _addressLine2.addTextChangedListener(this);
  84.  
  85. _addressLine3 = (EditText)findViewById(R.id.addressLine3);
  86. _addressLine3.setOnKeyListener(this);
  87. _addressLine3.addTextChangedListener(this);
  88.  
  89. _addressLine4 = (EditText)findViewById(R.id.addressLine4);
  90. _addressLine4.setOnKeyListener(this);
  91. _addressLine4.addTextChangedListener(this);
  92.  
  93.  
  94. _companyName.setText(_sharedPreference.getString("CompanyName",""));
  95. _yourName.setText(_sharedPreference.getString("YourName",""));
  96. _telephone.setText(_sharedPreference.getString("Telephone",""));
  97. _cellOrMob.setText(_sharedPreference.getString("CellOrMobile",""));
  98. _website.setText(_sharedPreference.getString("WebSite",""));
  99. _email.setText(_sharedPreference.getString("Email",""));
  100. _fax.setText(_sharedPreference.getString("Fax",""));
  101. _im.setText(_sharedPreference.getString("IM",""));
  102. _addressLine1.setText(_sharedPreference.getString("AddressLine1",""));
  103. _addressLine2.setText(_sharedPreference.getString("AddressLine2",""));
  104. _addressLine3.setText(_sharedPreference.getString("AddressLine3",""));
  105. _addressLine4.setText(_sharedPreference.getString("AddressLine4",""));
  106.  
  107.  
  108. _saveBtn = (ImageView)findViewById(R.id.SaveBtn);
  109. _saveBtn.setOnClickListener(this);
  110. _resetBtn = (ImageView)findViewById(R.id.ResetBtn);
  111. _resetBtn.setOnClickListener(this);
  112.  
  113. _textCountTv = (TextView)findViewById(R.id.detailsTextwatcherNoOfSMS);
  114. _noOfSmsCount = _sharedPreference.getInt("NOOFSMSINDETAILS",0);
  115. _textCountTv.setText(""+_noOfSmsCount);
  116. }
  117. @Override
  118. public void onClick(View v) {
  119. if(v == _saveBtn){
  120.  
  121. String _companyNameValue = _companyName.getText().toString();
  122. String _yourNameValue = _yourName.getText().toString();
  123. String _telephoneValue = _telephone.getText().toString();
  124. String _cellOrMobileValue = _cellOrMob.getText().toString();
  125. String _webSiteValue = _website.getText().toString();
  126. String _emailValue = _email.getText().toString();
  127. String _faxValue = _fax.getText().toString();
  128. String _iMValue = _im.getText().toString();
  129. String _addressLine1Value = _addressLine1.getText().toString();
  130. String _addressLine2Value = _addressLine2.getText().toString();
  131. String _addressLine3Value = _addressLine3.getText().toString();
  132. String _addressLine4Value = _addressLine4.getText().toString();
  133.  
  134.  
  135. _editor = _sharedPreference.edit();
  136. if(cancleClickFlag){
  137.  
  138. _editor.putInt("NOOFSMSINDETAILS",0);
  139. cancleClickFlag = false;
  140. }
  141. else{
  142. Log.d("ffffffffffffff", "ggggggggggggggg" + smsno);
  143. _editor.putInt("NOOFSMSINDETAILS",smsno);
  144. }
  145.  
  146. if(_companyNameValue.length()!= 0)
  147. edittextFalg++;
  148. if(_yourNameValue.length()!= 0)
  149. edittextFalg++;
  150. if(_telephoneValue.length() != 0)
  151. edittextFalg++;
  152. if(_cellOrMobileValue.length()!= 0)
  153. edittextFalg++;
  154. if(_webSiteValue.length()!= 0)
  155. edittextFalg++;
  156. if(_emailValue.length()!= 0)
  157. edittextFalg++;
  158. if(_faxValue.length()!= 0)
  159. edittextFalg++;
  160. if(_iMValue.length()!= 0)
  161. edittextFalg++;
  162. if(_addressLine1Value.length()!= 0)
  163. edittextFalg++;
  164. if(_addressLine2Value.length()!= 0)
  165. edittextFalg++;
  166. if(_addressLine3Value.length()!= 0)
  167. edittextFalg++;
  168. if(_addressLine4Value.length()!= 0)
  169. edittextFalg++;
  170.  
  171. if(edittextFalg >= 2){
  172.  
  173. //_editor = _sharedPreference.edit();
  174.  
  175. _editor.putString("CompanyName",_companyNameValue);
  176. _editor.putString("YourName",_yourNameValue);
  177. _editor.putString("Telephone",_telephoneValue);
  178. _editor.putString("CellOrMobile",_cellOrMobileValue);
  179. _editor.putString("WebSite",_webSiteValue);
  180. _editor.putString("Email",_emailValue );
  181. _editor.putString("Fax",_faxValue );
  182. _editor.putString("IM",_iMValue );
  183. _editor.putString("AddressLine1",_addressLine1Value);
  184. _editor.putString("AddressLine2",_addressLine2Value);
  185. _editor.putString("AddressLine3",_addressLine3Value);
  186. _editor.putString("AddressLine4",_addressLine4Value);
  187.  
  188. _editor.commit();
  189. Toast.makeText(this,"Saved successfully",Toast.LENGTH_LONG).show();
  190. edittextFalg = 0;
  191. }
  192. else{
  193.  
  194. Dialog errorDialog = new Dialog(this);
  195. errorDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  196. errorDialog.setContentView(R.layout.errormesage);
  197. TextView _errorMsg = (TextView)errorDialog.findViewById(R.id.errormessage);
  198. _errorMsg.setText("Please enter at least two fields ");
  199. errorDialog.show();
  200. }
  201.  
  202. }
  203. else if(v == _resetBtn){
  204.  
  205.  
  206. _companyName.setText("");
  207. _yourName.setText("");
  208. _telephone.setText("");
  209. _cellOrMob.setText("");
  210. _website.setText("");
  211. _email.setText("");
  212. _fax.setText("");
  213. _im.setText("");
  214. _addressLine1.setText("");
  215. _addressLine2.setText("");
  216. _addressLine3.setText("");
  217. _addressLine4.setText("");
  218.  
  219.  
  220. cancleClickFlag = true;
  221.  
  222. _noOfSmsCount = 0;
  223. smsno = 0;
  224. _textCountTv.setText(""+smsno);
  225. Editor _edit = _sharedPreference.edit();
  226. _edit.putString("PromotionalMsg","no");
  227. _edit.putInt("NOOFSMSINDETAILS",0);
  228. _edit.commit();
  229.  
  230. }
  231. }
  232. @Override
  233. public void afterTextChanged(Editable s) {
  234.  
  235. }
  236. @Override
  237. public void beforeTextChanged(CharSequence s, int start, int count,
  238. int after) {
  239.  
  240. }
  241. @Override
  242. public void onTextChanged(CharSequence s, int start, int before, int count) {
  243.  
  244. try {
  245. String _companyNameValue = _companyName.getText().toString();
  246. String _yourNameValue = _yourName.getText().toString();
  247. String _telephoneValue = _telephone.getText().toString();
  248. String _cellOrMobileValue = _cellOrMob.getText().toString();
  249. String _webSiteValue = _website.getText().toString();
  250. String _emailValue = _email.getText().toString();
  251. String _faxValue = _fax.getText().toString();
  252. String _iMValue = _im.getText().toString();
  253. String _addressLine1Value = _addressLine1.getText().toString();
  254. String _addressLine2Value = _addressLine2.getText().toString();
  255. String _addressLine3Value = _addressLine3.getText().toString();
  256. String _addressLine4Value = _addressLine4.getText().toString();
  257.  
  258. int len = _companyNameValue.length()+_yourNameValue.length()+_telephoneValue.length()+_cellOrMobileValue.length()+_webSiteValue.length()+_emailValue.length()+_emailValue.length()+_faxValue.length()+_faxValue.length()+_iMValue.length()+_addressLine1Value.length()+_addressLine2Value.length()+_addressLine3Value.length()+_addressLine4Value.length();
  259. Log.d("Lengthhhhh","lennnnnnnnnnnnnnnnn " + len);
  260.  
  261. _editor = _sharedPreference.edit();
  262.  
  263. if(len == 1){
  264.  
  265. smsno = 1;
  266. _textCountTv.setText(""+smsno);
  267. _editor.putInt("NOOFSMSINDETAILS",1);
  268. _noOfSmsCount = 1;
  269. }
  270.  
  271. if((len % 161) == 0 && len != 0){
  272.  
  273. smsno = ++_noOfSmsCount;
  274. _textCountTv.setText(""+smsno);
  275. Toast.makeText(ProviderActivity.this,"Sms Text Limit Exceed",Toast.LENGTH_LONG).show();
  276. len = 0;
  277. }
  278. }
  279. catch(Exception e){
  280.  
  281. }
  282. }
  283.  
  284. @Override
  285. public boolean onKey(View v, int keyCode, KeyEvent event) {
  286.  
  287. if(keyCode == KeyEvent.KEYCODE_DEL){
  288.  
  289. _editor = _sharedPreference.edit();
  290. String _companyNameValue = _companyName.getText().toString();
  291. String _yourNameValue = _yourName.getText().toString();
  292. String _telephoneValue = _telephone.getText().toString();
  293. String _cellOrMobileValue = _cellOrMob.getText().toString();
  294. String _webSiteValue = _website.getText().toString();
  295. String _emailValue = _email.getText().toString();
  296. String _faxValue = _fax.getText().toString();
  297. String _iMValue = _im.getText().toString();
  298. String _addressLine1Value = _addressLine1.getText().toString();
  299. String _addressLine2Value = _addressLine2.getText().toString();
  300. String _addressLine3Value = _addressLine3.getText().toString();
  301. String _addressLine4Value = _addressLine4.getText().toString();
  302.  
  303. int len = _companyNameValue.length()+_yourNameValue.length()+_telephoneValue.length()+_cellOrMobileValue.length()+_webSiteValue.length()+_emailValue.length()+_emailValue.length()+_faxValue.length()+_faxValue.length()+_iMValue.length()+_addressLine1Value.length()+_addressLine2Value.length()+_addressLine3Value.length()+_addressLine4Value.length();
  304. if(len == 0){
  305.  
  306. smsno = 0;
  307. _textCountTv.setText(""+smsno);
  308. _noOfSmsCount = 0;
  309. _editor.putInt("NOOFSMSINDETAILS",0);
  310. }
  311. if((len % 161) == 0 && len != 0){
  312.  
  313. smsno = --_noOfSmsCount;
  314. _textCountTv.setText(""+(smsno));
  315. if(cancleClickFlag){
  316.  
  317. _editor.putInt("NOOFSMSINDETAILS",0);
  318. cancleClickFlag = false;
  319. }
  320. else{
  321.  
  322. _editor.putInt("NOOFSMSINDETAILS",smsno);
  323. }
  324. _editor.commit();
  325. }
  326. }
  327.  
  328. return false;
  329. }
  330.  
  331. @Override
  332. protected void onStop() {
  333. super.onStop();
  334.  
  335. String _companyNameValue = _companyName.getText().toString();
  336. String _yourNameValue = _yourName.getText().toString();
  337. String _telephoneValue = _telephone.getText().toString();
  338. String _cellOrMobileValue = _cellOrMob.getText().toString();
  339. String _webSiteValue = _website.getText().toString();
  340. String _emailValue = _email.getText().toString();
  341. String _faxValue = _fax.getText().toString();
  342. String _iMValue = _im.getText().toString();
  343. String _addressLine1Value = _addressLine1.getText().toString();
  344. String _addressLine2Value = _addressLine2.getText().toString();
  345. String _addressLine3Value = _addressLine3.getText().toString();
  346. String _addressLine4Value = _addressLine4.getText().toString();
  347.  
  348. _editor = _sharedPreference.edit();
  349.  
  350. if(cancleClickFlag){
  351.  
  352. _editor.putInt("NOOFSMSINDETAILS",0);
  353. cancleClickFlag = false;
  354. }
  355. else{
  356. Log.d("ffffffffffffff", "ggggggggggggggg" + smsno);
  357. _editor.putInt("NOOFSMSINDETAILS",smsno);
  358. }
  359.  
  360. _editor.putString("CompanyName",_companyNameValue);
  361. _editor.putString("YourName",_yourNameValue);
  362. _editor.putString("Telephone",_telephoneValue);
  363. _editor.putString("CellOrMobile",_cellOrMobileValue);
  364. _editor.putString("WebSite",_webSiteValue);
  365. _editor.putString("Email",_emailValue );
  366. _editor.putString("Fax",_faxValue );
  367. _editor.putString("IM",_iMValue );
  368. _editor.putString("AddressLine1",_addressLine1Value);
  369. _editor.putString("AddressLine2",_addressLine2Value);
  370. _editor.putString("AddressLine3",_addressLine3Value);
  371. _editor.putString("AddressLine4",_addressLine4Value);
  372.  
  373. _editor.commit();
  374. //Toast.makeText(this,"Saved successfully",Toast.LENGTH_LONG).show();
  375.  
  376. }
  377. }
  378.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement