Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.adigroup;
- import android.app.Activity;
- import android.app.Dialog;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import android.os.Bundle;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.text.method.KeyListener;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.Window;
- import android.view.View.OnClickListener;
- import android.view.View.OnKeyListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class ProviderActivity extends Activity implements OnClickListener,TextWatcher,OnKeyListener{
- private static int edittextFalg;
- private String _preference = "AutoSmsData" ;
- private Editor _editor;
- private SharedPreferences _sharedPreference;
- private ImageView _saveBtn,_resetBtn;
- //private EditText _firstName,_firstName2,_secondName,_telephone1,_telephone2,_mobile,_email,_website,_fax,_im,_address,_companyName;
- private EditText _companyName,_yourName,_telephone,_cellOrMob,_website,_email,_fax,_im,_addressLine1,_addressLine2,_addressLine3,_addressLine4;
- private static int _noOfSmsCount = 0,smsno;
- private TextView _textCountTv;
- public static boolean cancleClickFlag = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.provider);
- _sharedPreference = getSharedPreferences(_preference,Context.MODE_PRIVATE);
- _companyName = (EditText)findViewById(R.id.companyName);
- _companyName.setOnKeyListener(this);
- _companyName.addTextChangedListener(this);
- _yourName = (EditText)findViewById(R.id.yourName);
- _yourName.setOnKeyListener(this);
- _yourName.addTextChangedListener(this);
- _telephone = (EditText)findViewById(R.id.telephone);
- _telephone.setOnKeyListener(this);
- _telephone.addTextChangedListener(this);
- _cellOrMob = (EditText)findViewById(R.id.cellOrMobile);
- _cellOrMob.setOnKeyListener(this);
- _cellOrMob.addTextChangedListener(this);
- _website = (EditText)findViewById(R.id.website);
- _website.setOnKeyListener(this);
- _website.addTextChangedListener(this);
- _email = (EditText)findViewById(R.id.email);
- _email.setOnKeyListener(this);
- _email.addTextChangedListener(this);
- _fax = (EditText)findViewById(R.id.fax);
- _fax.setOnKeyListener(this);
- _fax.addTextChangedListener(this);
- _im = (EditText)findViewById(R.id.im);
- _im.setOnKeyListener(this);
- _im.addTextChangedListener(this);
- _addressLine1 = (EditText)findViewById(R.id.addressLine1);
- _addressLine1.setOnKeyListener(this);
- _addressLine1.addTextChangedListener(this);
- _addressLine2 = (EditText)findViewById(R.id.addressLine2);
- _addressLine2.setOnKeyListener(this);
- _addressLine2.addTextChangedListener(this);
- _addressLine3 = (EditText)findViewById(R.id.addressLine3);
- _addressLine3.setOnKeyListener(this);
- _addressLine3.addTextChangedListener(this);
- _addressLine4 = (EditText)findViewById(R.id.addressLine4);
- _addressLine4.setOnKeyListener(this);
- _addressLine4.addTextChangedListener(this);
- _companyName.setText(_sharedPreference.getString("CompanyName",""));
- _yourName.setText(_sharedPreference.getString("YourName",""));
- _telephone.setText(_sharedPreference.getString("Telephone",""));
- _cellOrMob.setText(_sharedPreference.getString("CellOrMobile",""));
- _website.setText(_sharedPreference.getString("WebSite",""));
- _email.setText(_sharedPreference.getString("Email",""));
- _fax.setText(_sharedPreference.getString("Fax",""));
- _im.setText(_sharedPreference.getString("IM",""));
- _addressLine1.setText(_sharedPreference.getString("AddressLine1",""));
- _addressLine2.setText(_sharedPreference.getString("AddressLine2",""));
- _addressLine3.setText(_sharedPreference.getString("AddressLine3",""));
- _addressLine4.setText(_sharedPreference.getString("AddressLine4",""));
- _saveBtn = (ImageView)findViewById(R.id.SaveBtn);
- _saveBtn.setOnClickListener(this);
- _resetBtn = (ImageView)findViewById(R.id.ResetBtn);
- _resetBtn.setOnClickListener(this);
- _textCountTv = (TextView)findViewById(R.id.detailsTextwatcherNoOfSMS);
- _noOfSmsCount = _sharedPreference.getInt("NOOFSMSINDETAILS",0);
- _textCountTv.setText(""+_noOfSmsCount);
- }
- @Override
- public void onClick(View v) {
- if(v == _saveBtn){
- String _companyNameValue = _companyName.getText().toString();
- String _yourNameValue = _yourName.getText().toString();
- String _telephoneValue = _telephone.getText().toString();
- String _cellOrMobileValue = _cellOrMob.getText().toString();
- String _webSiteValue = _website.getText().toString();
- String _emailValue = _email.getText().toString();
- String _faxValue = _fax.getText().toString();
- String _iMValue = _im.getText().toString();
- String _addressLine1Value = _addressLine1.getText().toString();
- String _addressLine2Value = _addressLine2.getText().toString();
- String _addressLine3Value = _addressLine3.getText().toString();
- String _addressLine4Value = _addressLine4.getText().toString();
- _editor = _sharedPreference.edit();
- if(cancleClickFlag){
- _editor.putInt("NOOFSMSINDETAILS",0);
- cancleClickFlag = false;
- }
- else{
- Log.d("ffffffffffffff", "ggggggggggggggg" + smsno);
- _editor.putInt("NOOFSMSINDETAILS",smsno);
- }
- if(_companyNameValue.length()!= 0)
- edittextFalg++;
- if(_yourNameValue.length()!= 0)
- edittextFalg++;
- if(_telephoneValue.length() != 0)
- edittextFalg++;
- if(_cellOrMobileValue.length()!= 0)
- edittextFalg++;
- if(_webSiteValue.length()!= 0)
- edittextFalg++;
- if(_emailValue.length()!= 0)
- edittextFalg++;
- if(_faxValue.length()!= 0)
- edittextFalg++;
- if(_iMValue.length()!= 0)
- edittextFalg++;
- if(_addressLine1Value.length()!= 0)
- edittextFalg++;
- if(_addressLine2Value.length()!= 0)
- edittextFalg++;
- if(_addressLine3Value.length()!= 0)
- edittextFalg++;
- if(_addressLine4Value.length()!= 0)
- edittextFalg++;
- if(edittextFalg >= 2){
- //_editor = _sharedPreference.edit();
- _editor.putString("CompanyName",_companyNameValue);
- _editor.putString("YourName",_yourNameValue);
- _editor.putString("Telephone",_telephoneValue);
- _editor.putString("CellOrMobile",_cellOrMobileValue);
- _editor.putString("WebSite",_webSiteValue);
- _editor.putString("Email",_emailValue );
- _editor.putString("Fax",_faxValue );
- _editor.putString("IM",_iMValue );
- _editor.putString("AddressLine1",_addressLine1Value);
- _editor.putString("AddressLine2",_addressLine2Value);
- _editor.putString("AddressLine3",_addressLine3Value);
- _editor.putString("AddressLine4",_addressLine4Value);
- _editor.commit();
- Toast.makeText(this,"Saved successfully",Toast.LENGTH_LONG).show();
- edittextFalg = 0;
- }
- else{
- Dialog errorDialog = new Dialog(this);
- errorDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- errorDialog.setContentView(R.layout.errormesage);
- TextView _errorMsg = (TextView)errorDialog.findViewById(R.id.errormessage);
- _errorMsg.setText("Please enter at least two fields ");
- errorDialog.show();
- }
- }
- else if(v == _resetBtn){
- _companyName.setText("");
- _yourName.setText("");
- _telephone.setText("");
- _cellOrMob.setText("");
- _website.setText("");
- _email.setText("");
- _fax.setText("");
- _im.setText("");
- _addressLine1.setText("");
- _addressLine2.setText("");
- _addressLine3.setText("");
- _addressLine4.setText("");
- cancleClickFlag = true;
- _noOfSmsCount = 0;
- smsno = 0;
- _textCountTv.setText(""+smsno);
- Editor _edit = _sharedPreference.edit();
- _edit.putString("PromotionalMsg","no");
- _edit.putInt("NOOFSMSINDETAILS",0);
- _edit.commit();
- }
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- try {
- String _companyNameValue = _companyName.getText().toString();
- String _yourNameValue = _yourName.getText().toString();
- String _telephoneValue = _telephone.getText().toString();
- String _cellOrMobileValue = _cellOrMob.getText().toString();
- String _webSiteValue = _website.getText().toString();
- String _emailValue = _email.getText().toString();
- String _faxValue = _fax.getText().toString();
- String _iMValue = _im.getText().toString();
- String _addressLine1Value = _addressLine1.getText().toString();
- String _addressLine2Value = _addressLine2.getText().toString();
- String _addressLine3Value = _addressLine3.getText().toString();
- String _addressLine4Value = _addressLine4.getText().toString();
- 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();
- Log.d("Lengthhhhh","lennnnnnnnnnnnnnnnn " + len);
- _editor = _sharedPreference.edit();
- if(len == 1){
- smsno = 1;
- _textCountTv.setText(""+smsno);
- _editor.putInt("NOOFSMSINDETAILS",1);
- _noOfSmsCount = 1;
- }
- if((len % 161) == 0 && len != 0){
- smsno = ++_noOfSmsCount;
- _textCountTv.setText(""+smsno);
- Toast.makeText(ProviderActivity.this,"Sms Text Limit Exceed",Toast.LENGTH_LONG).show();
- len = 0;
- }
- }
- catch(Exception e){
- }
- }
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if(keyCode == KeyEvent.KEYCODE_DEL){
- _editor = _sharedPreference.edit();
- String _companyNameValue = _companyName.getText().toString();
- String _yourNameValue = _yourName.getText().toString();
- String _telephoneValue = _telephone.getText().toString();
- String _cellOrMobileValue = _cellOrMob.getText().toString();
- String _webSiteValue = _website.getText().toString();
- String _emailValue = _email.getText().toString();
- String _faxValue = _fax.getText().toString();
- String _iMValue = _im.getText().toString();
- String _addressLine1Value = _addressLine1.getText().toString();
- String _addressLine2Value = _addressLine2.getText().toString();
- String _addressLine3Value = _addressLine3.getText().toString();
- String _addressLine4Value = _addressLine4.getText().toString();
- 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();
- if(len == 0){
- smsno = 0;
- _textCountTv.setText(""+smsno);
- _noOfSmsCount = 0;
- _editor.putInt("NOOFSMSINDETAILS",0);
- }
- if((len % 161) == 0 && len != 0){
- smsno = --_noOfSmsCount;
- _textCountTv.setText(""+(smsno));
- if(cancleClickFlag){
- _editor.putInt("NOOFSMSINDETAILS",0);
- cancleClickFlag = false;
- }
- else{
- _editor.putInt("NOOFSMSINDETAILS",smsno);
- }
- _editor.commit();
- }
- }
- return false;
- }
- @Override
- protected void onStop() {
- super.onStop();
- String _companyNameValue = _companyName.getText().toString();
- String _yourNameValue = _yourName.getText().toString();
- String _telephoneValue = _telephone.getText().toString();
- String _cellOrMobileValue = _cellOrMob.getText().toString();
- String _webSiteValue = _website.getText().toString();
- String _emailValue = _email.getText().toString();
- String _faxValue = _fax.getText().toString();
- String _iMValue = _im.getText().toString();
- String _addressLine1Value = _addressLine1.getText().toString();
- String _addressLine2Value = _addressLine2.getText().toString();
- String _addressLine3Value = _addressLine3.getText().toString();
- String _addressLine4Value = _addressLine4.getText().toString();
- _editor = _sharedPreference.edit();
- if(cancleClickFlag){
- _editor.putInt("NOOFSMSINDETAILS",0);
- cancleClickFlag = false;
- }
- else{
- Log.d("ffffffffffffff", "ggggggggggggggg" + smsno);
- _editor.putInt("NOOFSMSINDETAILS",smsno);
- }
- _editor.putString("CompanyName",_companyNameValue);
- _editor.putString("YourName",_yourNameValue);
- _editor.putString("Telephone",_telephoneValue);
- _editor.putString("CellOrMobile",_cellOrMobileValue);
- _editor.putString("WebSite",_webSiteValue);
- _editor.putString("Email",_emailValue );
- _editor.putString("Fax",_faxValue );
- _editor.putString("IM",_iMValue );
- _editor.putString("AddressLine1",_addressLine1Value);
- _editor.putString("AddressLine2",_addressLine2Value);
- _editor.putString("AddressLine3",_addressLine3Value);
- _editor.putString("AddressLine4",_addressLine4Value);
- _editor.commit();
- //Toast.makeText(this,"Saved successfully",Toast.LENGTH_LONG).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement