Thursday 24 October 2013

Login Registration Demo

1)Create class Register.java
=======================
package com.example.demoproject;
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class Register extends Activity implements OnClickListener{
private CommanClass mCommanClass = null;
private Button btnSubmit = null;
private Button btnSkip = null;
private Button btnBack= null;
private EditText edtName_Of_Owner = null;
private EditText edtEmailID = null;
private EditText edtMobileNo = null;
private EditText edtPassword = null;
private EditText edtConfirmPassword = null;
private EditText edtChasisNo = null;
private String strUserId = null;
// private SharedPreferences mSharedPreferencesRead=null;
private SharedPreferences mSharedPreferencesWrite=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

setContentView(R.layout.xregister);
// viewfocus=(View)findViewById(R.id.viewfocus);
// mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
mSharedPreferencesWrite = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_WRITEABLE);
mCommanClass = new CommanClass();

edtName_Of_Owner = (EditText)findViewById(R.id.edtNameOfOwner);
edtEmailID = (EditText)findViewById(R.id.edtEmail_Id);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtPassword = (EditText)findViewById(R.id.edtPassword);
edtConfirmPassword = (EditText)findViewById(R.id.edtConfirmPassword);
edtChasisNo = (EditText)findViewById(R.id.edtChasisNumber);

btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(this);
btnSkip = (Button)findViewById(R.id.btnSkip);
btnSkip.setOnClickListener(this);
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
}


//************************************************************************************************************************************
//This class is used for get Add appointment
   private class Register_Vehical extends AsyncTask
   {
    private ProcessDialog mProcessDialog=null;
        protected void onPreExecute() {
           mProcessDialog = new ProcessDialog(Register.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
               super.onPreExecute();
        }
        protected String doInBackground(String... params) {
           String strURL = getResources().getString(R.string.REGISTER_VEHICAL_URL);
        ArrayList mNameValuePair = new ArrayList();
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.ID, String.valueOf(intID)));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.MOBILE_NO, edtMobileNo.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.EMAIL_ID, edtEmailID.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.PASSWORD, edtPassword.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.MOBILE_TYPE,"Android"));
       
    System.out.println("Register Value ==="+mNameValuePair.toString());
    return mCommanClass.PostConnection(strURL, mNameValuePair);
        }
       
        protected void onPostExecute(String result) {
        mProcessDialog.dismiss();
            if(result!=null){  
            System.out.println("RegisterResponse====="+result);
            try {
            JSONObject mJSONOBJECT = new JSONObject(result);
            String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
   
    if(strType.equalsIgnoreCase(Constant.JSON.OK)){
    JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.JSON.RESULT);
    strUserId = mJSONOBJECT_RESULT.getString(Constant.REGISTER_VEHICAL_RESPONSE.USER_ID);
    System.out.println("strUserId====="+strUserId.toString());
    SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, String.valueOf(strUserId));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_CHASIS_NO,edtChasisNo.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,edtName_Of_Owner.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,edtEmailID.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,edtMobileNo.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_PASSWORD, edtPassword.getText().toString().trim());
mSharedPreferencesEdit.commit();

Toast.makeText(Register.this,mJSONOBJECT_RESULT.getString(Constant.REGISTER_RESPONSE.RAGISTER_MESSAGE), Toast.LENGTH_SHORT).show();
Intent mIntent=new Intent(Register.this,Verification.class);
mIntent.setAction(Constant.REGISTER_VEHICAL.REGISTER_L_INTENT);
startActivity(mIntent);
finish();
}
else{
Toast.makeText(Register.this,mJSONOBJECT.getString(Constant.REGISTER__RESPONSE.RAGISTER__MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}                          
            }  
            else{
            Toast.makeText(Register.this,Constant.SERVERCONNERROR, Toast.LENGTH_SHORT).show();    
            }
            super.onPostExecute(result);
        }            
   }
 
private boolean check_not_null()
{
boolean blank = true;
if (edtName_Of_Owner.getText().toString().equals("") || edtEmailID.getText().toString().equals("")
|| edtMobileNo.getText().toString().equals("") || edtPassword.getText().toString().equals("")
|| edtConfirmPassword.getText().toString().equals("") || edtChasisNo.getText().toString().equals("")) {
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_REQUIRED_FIELD, Toast.LENGTH_SHORT).show();
blank = true;
}else if(edtMobileNo.getText().length() < 10){
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}
else {
if(CommanClass.isEmailValid(edtEmailID.getText().toString()) == false){
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.ENTER_VALID_EMAILID) , Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
if(!edtPassword.getText().toString().equals(edtConfirmPassword.getText().toString())){
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.PASSWORD_NOT_MATCH_MESSAGE), Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
}
return blank;
}



@Override
public void onClick(View v) {
if(v==btnSubmit){
if(!check_not_null() ){
if(mCommanClass.CheckNetwork(this)){
new Register_Vehical().execute("");
}
}
}
else if(v==btnSkip){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID,"-1");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,"");
mSharedPreferencesEdit.commit();

Intent mIntent = new Intent(Register.this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SKIP_INTENT);
startActivity(mIntent);
finish();
}
else if(v==btnBack){
finish();
}
}
}
2)create class Login.java
====================
package com.example.demoproject;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends Activity implements OnClickListener{
private EditText edtMobileNo = null;
private EditText edtPassword = null;
private Button btnSubmit = null;
private Button btnNewUSer = null;
private Button btnSkip = null;
private CommanClass mCommanClass = null;
private String strUserId = null, strVerified = null;
private String strMobileNo, strPassword = null; 
private SharedPreferences mSharedPreferencesWrite=null;
private SharedPreferences mSharedPreferencesRead=null;
private CheckBox chkRememberMe=null;
@Override
protected void onCreate(Bundle savedInstanceState){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.xlogin);
mSharedPreferencesWrite = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_WRITEABLE);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
mCommanClass = new CommanClass();
strUserId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, "");
chkRememberMe = (CheckBox)findViewById(R.id.chkbox_remember_psw);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtPassword = (EditText)findViewById(R.id.edtPassword);
btnSubmit = (Button)findViewById(R.id.btn_Submit);
btnSubmit.setOnClickListener(this);
btnNewUSer = (Button)findViewById(R.id.btnNewUser);
btnNewUSer.setOnClickListener(this);
btnSkip = (Button)findViewById(R.id.btnSkip);
btnSkip.setOnClickListener(this);
if(mSharedPreferencesRead.getBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,false)){
strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME,"");
strPassword = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD,"");
System.out.println("Mobile=="+strMobileNo);
System.out.println("Password=="+strPassword);
edtMobileNo.setText(strMobileNo);
edtPassword.setText(strPassword);
}
}
private ProcessDialog mProcessDialogLogin=null;
private class Login_Service extends AsyncTask
    {        
            protected void onPreExecute(){
            mProcessDialogLogin = new ProcessDialog(Login.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
                    super.onPreExecute();
            }        
            protected String doInBackground(String... params) {
 String strURL = getResources().getString(R.string.LOGIN_URL);  
     ArrayList mNameValuePair = new ArrayList();
     mNameValuePair.add(new BasicNameValuePair(Constant.LOGIN_REQUEST.MOBILE_NO,edtMobileNo.getText().toString().trim()));
 mNameValuePair.add(new BasicNameValuePair(Constant.LOGIN_REQUEST.PASSWORD,edtPassword.getText().toString().trim()));
 System.out.println("mNameValuePair=="+mNameValuePair.toString());
 return mCommanClass.PostConnection(strURL, mNameValuePair);  
            } 
            
            protected void onPostExecute(String result) {
            mProcessDialogLogin.dismiss();
           
            if(result!=null)
{
            System.out.println("Login=="+result.toString());
        try{
            JSONObject mJSONOBJECT = new JSONObject(result);
            String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
    if(strType.toString().trim().equalsIgnoreCase(Constant.JSON.OK)){
    JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.LOGIN_RESPONSE.RESULT);
strVerified = mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.STATUS);
strUserId = mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID);
JSONArray mJSONARRAY_LOGIN_VEHICAL_DETAIL = mJSONOBJECT_RESULT.getJSONArray(Constant.LOGIN_RESPONSE.VEHICLE_DETAIL);
    System.out.println("mJSONARRAY_SERVICE_RESULT=="+mJSONARRAY_LOGIN_VEHICAL_DETAIL.toString());
    // System.out.println("strUserId=="+strUserId.toString());
 
    for(int i = 0; i
     JSONObject mJSONOBJECT_VEHICAL_DETAIL = mJSONARRAY_LOGIN_VEHICAL_DETAIL.getJSONObject(i);
   
      mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.B_ID));
   
        mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.P_ID),
      mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.BD_ID));
   
        mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.M_ID),
    }
   
    String strUserID =  mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID);
    System.out.println("strUserId=="+strUserId.toString());
    SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.OWNER_NAME));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.MOBILE_NO));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.EMAIL_ID));
mSharedPreferencesEdit.commit();
if(strVerified.toString().trim().equals(Constant.LOGIN_RESPONSE.STATUS_VALUE)){
Toast.makeText(Login.this,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.MESSAGE).toString().trim(), Toast.LENGTH_SHORT).show();
Intent mIntent=new Intent(Login.this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SUBMIT_INTENT);
startActivity(mIntent);
finish();
}
else{
//Toast.makeText(Login.this,Constant.LOGIN.LOGIN_FAIL_MESSAGE, Toast.LENGTH_SHORT).show();
//LoginFailMessageDialog();
Intent mIntent=new Intent(Login.this,Verification.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SUBMIT_INTENT);
startActivity(mIntent);
finish();
}
}
else{
LoginFailMessageDialog();
}
} catch (Exception e) {
e.printStackTrace();
}                    
}
            else{
    Toast.makeText(Login.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
    }
                 super.onPostExecute(result);
            }
    }

@Override
public void onClick(View v) {
if(v == btnSubmit){
if(chkRememberMe.isChecked()){
strMobileNo=edtMobileNo.getText().toString().trim();
strPassword=edtPassword.getText().toString().trim();
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME, strMobileNo);
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD, strPassword);
mSharedPreferencesEdit.putBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,true);
mSharedPreferencesEdit.commit();
}
else{
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME, "");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD, "");
mSharedPreferencesEdit.putBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,false);
mSharedPreferencesEdit.commit();
}
if(edtMobileNo.getText().toString().trim().equals("")|| (edtMobileNo.getText().length() < 10)){
Animation shake = AnimationUtils.loadAnimation(this,R.anim.shake);
edtMobileNo.startAnimation(shake);
Toast.makeText(this, Constant.LOGIN.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}  
else if(edtPassword.getText().toString().trim().equals("")){
Animation shake = AnimationUtils.loadAnimation(this,R.anim.shake);
edtPassword.startAnimation(shake);
Toast.makeText(this, Constant.LOGIN.FILL_PASSWORd,Toast.LENGTH_LONG).show();
}
else{
if(mCommanClass.CheckNetwork(Login.this)){
new Login_Service().execute("");
}
}
}
else if(v==btnNewUSer){
Intent miIntent = new Intent(this,RegisterVehical.class);
startActivity(miIntent);
}
else if(v==btnSkip){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID,"-1");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,"");
mSharedPreferencesEdit.commit();
 
Intent mIntent = new Intent(this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SKIP_INTENT);
startActivity(mIntent);
}
}    
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void 
* @use This Dialog is used for show welcome msg when app start 
*/  
public void LoginFailMessageDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Login.this);
//alertDialogBuilder.setTitle(Constant.LOGIN.LOGIN_FAIL_MESSAGE);
alertDialogBuilder
.setMessage(Constant.LOGIN.LOGIN_FAIL_MESSAGE)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id){
edtPassword.setText("");
dialog.cancel();
}
 });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
3)create Comman Class.java
======================
package com.example.demoproject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

public class CommanClass {

private ConnectivityManager connectivity=null;
private NetworkInfo netinfo=null;
/**This method use for check Network Connectivity
*/
public boolean CheckNetwork(Context mContext) {
   this.connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
       this.netinfo= connectivity.getActiveNetworkInfo();
       if(netinfo!=null && netinfo.isConnected()==true)
       {      
        return true;
       }
       else
       {
        Toast.makeText(mContext, Constant.NETWORK_NOT_AVAILABLE, Toast.LENGTH_LONG).show();
        return false;      
       }
 
}
/**This method use for check Network Connectivity No Message
*/
public boolean CheckNetworkNoMessage(Context mContext) {
   this.connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
       this.netinfo= connectivity.getActiveNetworkInfo();
       if(netinfo!=null && netinfo.isConnected()==true)
       {
        return true;
       }
       else
       {
        return false;      
       }
}
//************************************************************************************************************************
/**This method use for email validation check
*/
public static boolean isEmailValid(String email)
    {
int lastDotIndex = 0;
        String regExpn = "[A-Z0-9a-z][A-Z0-9a-z._%+-]*@[A-Za-z0-9][A-Za-z0-9.-]*\\.[A-Za-z]{2,6}";

        CharSequence inputStr = email;
    Pattern pattern = Pattern.compile(regExpn,Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if(matcher.matches()){
     
    lastDotIndex = email.lastIndexOf(".");
    String substr = email.substring(lastDotIndex, email.length());
         
    String[] domains = {".aero", ".asia", ".biz", ".cat", ".com", ".coop", ".edu", ".gov", ".info", ".int", ".jobs", ".mil", ".mobi", ".museum", ".name", ".net", ".org", ".pro", ".tel", ".travel", ".ac", ".ad", ".ae", ".af", ".ag", ".ai", ".al", ".am", ".an", ".ao", ".aq", ".ar", ".as", ".at", ".au", ".aw", ".ax", ".az", ".ba", ".bb", ".bd", ".be", ".bf", ".bg", ".bh", ".bi", ".bj", ".bm", ".bn", ".bo", ".br", ".bs", ".bt", ".bv", ".bw", ".by", ".bz", ".ca", ".cc", ".cd", ".cf", ".cg", ".ch", ".ci", ".ck", ".cl", ".cm", ".cn", ".co", ".cr", ".cu", ".cv", ".cx", ".cy", ".cz", ".de", ".dj", ".dk", ".dm", ".do", ".dz", ".ec", ".ee", ".eg", ".er", ".es", ".et", ".eu", ".fi", ".fj", ".fk", ".fm", ".fo", ".fr", ".ga", ".gb", ".gd", ".ge", ".gf", ".gg", ".gh", ".gi", ".gl", ".gm", ".gn", ".gp", ".gq", ".gr", ".gs", ".gt", ".gu", ".gw", ".gy", ".hk", ".hm", ".hn", ".hr", ".ht", ".hu", ".id", ".ie", " No", ".il", ".im", ".in", ".io", ".iq", ".ir", ".is", ".it", ".je", ".jm", ".jo", ".jp", ".ke", ".kg", ".kh", ".ki", ".km", ".kn", ".kp", ".kr", ".kw", ".ky", ".kz", ".la", ".lb", ".lc", ".li", ".lk", ".lr", ".ls", ".lt", ".lu", ".lv", ".ly", ".ma", ".mc", ".md", ".me", ".mg", ".mh", ".mk", ".ml", ".mm", ".mn", ".mo", ".mp", ".mq", ".mr", ".ms", ".mt", ".mu", ".mv", ".mw", ".mx", ".my", ".mz", ".na", ".nc", ".ne", ".nf", ".ng", ".ni", ".nl", ".no", ".np", ".nr", ".nu", ".nz", ".om", ".pa", ".pe", ".pf", ".pg", ".ph", ".pk", ".pl", ".pm", ".pn", ".pr", ".ps", ".pt", ".pw", ".py", ".qa", ".re", ".ro", ".rs", ".ru", ".rw", ".sa", ".sb", ".sc", ".sd", ".se", ".sg", ".sh", ".si", ".sj", ".sk", ".sl", ".sm", ".sn", ".so", ".sr", ".st", ".su", ".sv", ".sy", ".sz", ".tc", ".td", ".tf", ".tg", ".th", ".tj", ".tk", ".tl", ".tm", ".tn", ".to", ".tp", ".tr", ".tt", ".tv", ".tw", ".tz", ".ua", ".ug", ".uk", ".us", ".uy", ".uz", ".va", ".vc", ".ve", ".vg", ".vi", ".vn", ".vu", ".wf", ".ws", ".ye", ".yt", ".za", ".zm", ".zw"};
     
    for(int i = 0 ; i < domains.length ; i ++ ){
    if(substr.trim().equals(domains[i])){
    return true;
    }
    }
    }
   
return false;
}
/**This function use for check service running or not*/
public static boolean IsServiceRunning(Context context,String package_class) {
   ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
   for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
       if (package_class.equals(service.service.getClassName())) {
           return true;
       }
   }
   return false;
}
/**This method use for PostConnection to Server
*/
public String PostConnection(String strUrl,ArrayList alstNameValuePair) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
// HttpConnectionParams.setConnectionTimeout(mHttpClient.getParams(), 60000); //Timeout Limit
//Pathe of serverside 
HttpPost mHttpPost = new HttpPost(strUrl);
if(alstNameValuePair!=null)
//post the valur you want to pass.
mHttpPost.setEntity(new UrlEncodedFormEntity(alstNameValuePair));
}
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpPost);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
 } 
 catch (Exception e) {
 e.printStackTrace();
 }
String strLine = null;
String strResult = "";
 
//convert response in to the string.
try {
if(mInputStream!=null){
 BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,HTTP.UTF_8), 8);
 StringBuilder mStringBuilder = new StringBuilder();
   while((strLine = mBufferedReader.readLine()) != null) {
  mStringBuilder.append(strLine + "\n");
 }
   strResult = mStringBuilder.toString();
   mInputStream.close();
}
  } 
  catch (Exception e) {
  e.printStackTrace();
   }
return strResult;
}
/**This method use for GetConnectionObject to Server
*/
public String GetConnectionObject(String strUrl) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
//Pathe of serverside 
HttpGet mHttpGet = new HttpGet(strUrl);
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
 } 
 catch (Exception e) {
// TODO Auto-generated catch block
Log.e(Constant.TAG,"Error in HttpClient,HttpPost,HttpResponse,HttpEntity");
 }
String strLine = null;
String strResult = null;
//convert response in to the string.
try{
 BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,"iso-8859-1"), 8);
 StringBuilder mStringBuilder = new StringBuilder();
   while((strLine = mBufferedReader.readLine()) != null){
  mStringBuilder.append(strLine + "\n");
 }
   mInputStream.close();
   strResult = mStringBuilder.toString();
  } 
  catch (Exception e) {
 //System.out.println("Error in BufferedReadering");
     Log.e(Constant.TAG,"Error in BufferedReadering");
   }
return strResult;   
}
}
4)Create class ProcessDialog.java
==============================
 package com.example.demoproject;

import android.R;
import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.Window;
import android.widget.TextView;

public class ProcessDialog extends Dialog{
private TextView title;       
     public ProcessDialog(Context context,String strtitle,String strbody) 
     {
         super(context);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.xcustomdialog);
         setCancelable(true);
         title = (TextView)findViewById(R.id.txtdialogtext);
         title.setText(Html.fromHtml(strbody.toString()));
         show();
     }
}

6)Constants
========
public static final String NETWORK_NOT_AVAILABLE = "Network not available";
public final static String SERVERCONNERROR = "Could not connect to server, Please try again.";
7)cycle_7.xml
==========




8)shake.xml
=========


No comments:

Post a Comment