1)create xml login.xml
==================
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/imgapp_bg">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="@drawable/imgtop_tab">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/login_header"
android:layout_marginTop="3dip"
android:layout_marginBottom="3dip"
android:gravity="center"
android:textColor="@color/font_color"
android:textSize="20dip"/>
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="top|right">
android:id="@+id/viewfocus"
android:layout_width="0dip"
android:layout_height="0dip"
android:focusable="true"
android:focusableInTouchMode="true"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal">
android:id="@+id/edt_username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/login_username"
android:text="manisha.savaliya@gmail.com"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal">
android:id="@+id/edt_Password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/login_pass"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="manisha"
android:singleLine="true"
android:password="true"/>
android:layout_width="fill_parent"
android:layout_marginTop="5dip"
android:layout_height="wrap_content">
android:id="@+id/chkbox_remember_psw"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:checked="true"
android:textColor="@color/font_color"
android:text="@string/login_remember_me"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal">
2)Create a java file named Login.java
===================================
package com.example.login;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity implements OnClickListener{
private Button btnSignUp,btnLogin;
private CheckBox chk_Remember=null;
private EditText edtUserName,edtPassword;
private String uName, mPswd;
private boolean remember_me = false;
private SOAPService mSoapService = null;
private View viewfocus=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
GetBasicData();
}
/*
* Method Name : getBasicData()
* User of Method : this methiod is used for mainly initilize the variable and memory*/
public void GetBasicData(){
btnSignUp = (Button)findViewById(R.id.btnSignUp);
btnSignUp.setOnClickListener(this);
btnLogin = (Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
chk_Remember = (CheckBox)findViewById(R.id.chkbox_remember_psw);
edtUserName = (EditText)findViewById(R.id.edt_username);
edtPassword = (EditText)findViewById(R.id.edt_Password);
SharedPreferences get_remember_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_READABLE);
uName = get_remember_password.getString(Constant.USERNAME, "" );
mPswd = get_remember_password.getString(Constant.PASSWORD, "" );
if(!uName.equals("") || !mPswd.equals("")){
edtUserName.setText( uName );
edtPassword.setText( mPswd );
}
}
/*
* Method Name : remember Password
* Use : for remember password*/
private void remember_password(boolean remember){
SharedPreferences mSharePref_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mSharePref_pass_edit = mSharePref_password.edit();
if( remember ){
mSharePref_pass_edit.putString(Constant.USERNAME, edtUserName.getText().toString().trim() );
mSharePref_pass_edit.putString(Constant.PASSWORD, edtPassword.getText().toString().trim() );
mSharePref_pass_edit.commit();
}else{
mSharePref_pass_edit.putString(Constant.USERNAME, "");
mSharePref_pass_edit.putString(Constant.PASSWORD, "");
mSharePref_pass_edit.commit();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnLogin){
if(edtUserName.getText().toString().equals("") || edtPassword.getText().toString().equals("")){
Toast.makeText(this, Html.fromHtml(Constant.FILL_ALL_THE_FIELD), Toast.LENGTH_SHORT).show();
}
else{
if(GlobalClass.isEmailValid(edtUserName.getText().toString()))
{
if( chk_Remember.isChecked() ){
remember_me = true;
remember_password( remember_me );
}else{
remember_me = false;
remember_password( remember_me );
}
if(GlobalClass.CheckNetwork(this)){
new getDataFromSoapWebService().execute("DATA_FROM_WEB");
}
}
else
{
Toast.makeText(this,Html.fromHtml(Constant.REGISTER_VALID_EMAILID), Toast.LENGTH_SHORT).show();
}
}
}
else if(v==btnSignUp){
Intent iv = new Intent(this,Register.class);
startActivity(iv);
finish();
}
}
//*******************************************************************************************************************************
private class getDataFromSoapWebService extends AsyncTask {
private ProcessDialog mProcessDialog = null;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
mProcessDialog = new ProcessDialog(Login.this, "Login", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "validateLogin";
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"username","password"};
Object keyValue[] = { edtUserName.getText().toString().trim() , edtPassword.getText().toString().trim() };
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if( result != null){
JSONObject job_login=null;
JSONObject json_user=null;
String Status="",USERID="",LANGID="",LANGUAGE="";
System.out.println("Login Response " + result);
try {
job_login = new JSONObject(result);
Status=job_login.getString("SUCCESS").toString();
USERID=job_login.getString("ID").toString();
LANGUAGE=job_login.getString("LANGUAGE").toString();
} catch (JSONException e) {
e.printStackTrace();
}
if(job_login != null){
if(Status.equals("OK") ){
try {
json_user=job_login.getJSONObject("USER");
LANGID=json_user.getString("pref_lang_id").toString();
SharedPreferences spLoginUserDetails = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spEdit_Login_Details = spLoginUserDetails.edit();
spEdit_Login_Details.putString(Constant.USER_ID, USERID);
spEdit_Login_Details.putString(Constant.PREF_LANG_ID,LANGID);
spEdit_Login_Details.putString(Constant.PREF_LANG_NAME,LANGUAGE);
spEdit_Login_Details.commit();
new GetCommunityListData().execute();
} catch (JSONException e) {
e.printStackTrace();
}
// if(json_user!=null){
// try {
// jon_array=json_user.getJSONArray("COMMUNITY");
// } catch (JSONException e) {
// e.printStackTrace();
// }
// if(jon_array!=null){
//
// for(int i=0;i// try {
// JsonObjectid=jon_array.getJSONObject(i);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// if(JsonObjectid!=null){
// String strcommunity_id="";
// try {
// strcommunity_id = JsonObjectid.getString("id").toString();
// } catch (JSONException e) {
// e.printStackTrace();
// }
// Constant.alstTempCommunityID.add(strcommunity_id);
// System.out.println("community id" + strcommunity_id);
// }
// }
//
// }
// }
}else{
Toast.makeText(Login.this, Html.fromHtml(Constant.USERNAMEPASSWORD),Toast.LENGTH_SHORT).show();
}
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
//This function is used for get community
private class GetCommunityListData extends AsyncTask {
private ProcessDialog mProcesCommunityDialog = null;
@Override
protected void onPreExecute() {
mProcesCommunityDialog = new ProcessDialog(Login.this, "Community", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... UserID) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "GetMethodTable";
SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"user_id"};
Object keyValue[] = {strUserID};
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcesCommunityDialog.dismiss();
if(result != null){
String strSuccess,strMessage;
try {
System.out.println("Community Response : " + result);
JSONObject json_Community = new JSONObject(result);
if(json_Community != null)
{
strSuccess = json_Community.getString("SUCCESS").toString();
if(strSuccess.equals("OK")){
JSONArray jsonArray_CommunityList = json_Community.getJSONArray("COMMUNITY");
if(jsonArray_CommunityList!=null){
OpenDatabase();
mDbHelper.DeleteCommunityList(mSQLiteDatabase);
for(int i=0;i JSONObject jsonCommunity_attribute=jsonArray_CommunityList.getJSONObject(i);
if(jsonCommunity_attribute!=null){
int id =jsonCommunity_attribute.getInt("id");
int level=jsonCommunity_attribute.getInt("level");
String name=jsonCommunity_attribute.getString("name").toString();
String status=jsonCommunity_attribute.getString("status").toString();
mDbHelper.InsertCommunityList(mSQLiteDatabase, id, level, name, status);
}
}
CloseDataBase();
new GetCategoryListData().execute("");
}
}
else{
strMessage = json_Community.getString("MESSAGE").toString();
Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();
}
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
////This class is used for get Category List
private class GetCategoryListData extends AsyncTask {
private ProcessDialog mProcesCategoryDialog = null;
@Override
protected void onPreExecute() {
mProcesCategoryDialog = new ProcessDialog(Login.this, "Category", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "GetCategoryTable";
SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"user_id"};
Object keyValue[] = {strUserID};
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcesCategoryDialog.dismiss();
if(result != null){
String strSuccess,strMessage;
try {
System.out.println("Category Response : " + result);
JSONObject json_Category = new JSONObject(result);
if(json_Category != null)
{
strSuccess = json_Category.getString("SUCCESS").toString();
if(strSuccess.equals("OK")){
JSONArray jsonArray_CategoryList = json_Category.getJSONArray("CATEGORY");
if(jsonArray_CategoryList!=null){
OpenDatabase();
mDbHelper.DeleteCategoryList(mSQLiteDatabase);
for(int i=0;i JSONObject jsonCategory_attribute=jsonArray_CategoryList.getJSONObject(i);
if(jsonCategory_attribute!=null){
int id =jsonCategory_attribute.getInt("id");
int level=jsonCategory_attribute.getInt("level");
String name=jsonCategory_attribute.getString("name").toString();
String status=jsonCategory_attribute.getString("status").toString(); mDbHelper.InsertCategoryList(mSQLiteDatabase, id, level, name, status);
}
}
CloseDataBase();
Intent in = new Intent(Login.this, HomeScreen.class);
startActivity(in);
finish();
}
}
else{
strMessage = json_Category.getString("MESSAGE").toString();
Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();
}
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
//For open & close database
private DbHelper mDbHelper=null;
private SQLiteDatabase mSQLiteDatabase=null;
private void OpenDatabase()
{
mDbHelper = new DbHelper(this);
mSQLiteDatabase = mDbHelper.getWritableDatabase();
mSQLiteDatabase.setLockingEnabled(true);
}
private void CloseDataBase()
{
if(mDbHelper!=null && mSQLiteDatabase!=null){
if(mSQLiteDatabase.isOpen()){
mSQLiteDatabase.close();
mDbHelper.close();
}
}
}
}
==================
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/imgapp_bg">
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="@drawable/imgtop_tab">
android:layout_height="wrap_content"
android:text="@string/login_header"
android:layout_marginTop="3dip"
android:layout_marginBottom="3dip"
android:gravity="center"
android:textColor="@color/font_color"
android:textSize="20dip"/>
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="top|right">
android:layout_width="0dip"
android:layout_height="0dip"
android:focusable="true"
android:focusableInTouchMode="true"/>
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/login_username"
android:text="manisha.savaliya@gmail.com"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"/>
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/login_pass"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="manisha"
android:singleLine="true"
android:password="true"/>
android:layout_marginTop="5dip"
android:layout_height="wrap_content">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:checked="true"
android:textColor="@color/font_color"
android:text="@string/login_remember_me"
/>
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal">
2)Create a java file named Login.java
===================================
package com.example.login;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity implements OnClickListener{
private Button btnSignUp,btnLogin;
private CheckBox chk_Remember=null;
private EditText edtUserName,edtPassword;
private String uName, mPswd;
private boolean remember_me = false;
private SOAPService mSoapService = null;
private View viewfocus=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
GetBasicData();
}
/*
* Method Name : getBasicData()
* User of Method : this methiod is used for mainly initilize the variable and memory*/
public void GetBasicData(){
btnSignUp = (Button)findViewById(R.id.btnSignUp);
btnSignUp.setOnClickListener(this);
btnLogin = (Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
chk_Remember = (CheckBox)findViewById(R.id.chkbox_remember_psw);
edtUserName = (EditText)findViewById(R.id.edt_username);
edtPassword = (EditText)findViewById(R.id.edt_Password);
SharedPreferences get_remember_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_READABLE);
uName = get_remember_password.getString(Constant.USERNAME, "" );
mPswd = get_remember_password.getString(Constant.PASSWORD, "" );
if(!uName.equals("") || !mPswd.equals("")){
edtUserName.setText( uName );
edtPassword.setText( mPswd );
}
}
/*
* Method Name : remember Password
* Use : for remember password*/
private void remember_password(boolean remember){
SharedPreferences mSharePref_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mSharePref_pass_edit = mSharePref_password.edit();
if( remember ){
mSharePref_pass_edit.putString(Constant.USERNAME, edtUserName.getText().toString().trim() );
mSharePref_pass_edit.putString(Constant.PASSWORD, edtPassword.getText().toString().trim() );
mSharePref_pass_edit.commit();
}else{
mSharePref_pass_edit.putString(Constant.USERNAME, "");
mSharePref_pass_edit.putString(Constant.PASSWORD, "");
mSharePref_pass_edit.commit();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnLogin){
if(edtUserName.getText().toString().equals("") || edtPassword.getText().toString().equals("")){
Toast.makeText(this, Html.fromHtml(Constant.FILL_ALL_THE_FIELD), Toast.LENGTH_SHORT).show();
}
else{
if(GlobalClass.isEmailValid(edtUserName.getText().toString()))
{
if( chk_Remember.isChecked() ){
remember_me = true;
remember_password( remember_me );
}else{
remember_me = false;
remember_password( remember_me );
}
if(GlobalClass.CheckNetwork(this)){
new getDataFromSoapWebService().execute("DATA_FROM_WEB");
}
}
else
{
Toast.makeText(this,Html.fromHtml(Constant.REGISTER_VALID_EMAILID), Toast.LENGTH_SHORT).show();
}
}
}
else if(v==btnSignUp){
Intent iv = new Intent(this,Register.class);
startActivity(iv);
finish();
}
}
//*******************************************************************************************************************************
private class getDataFromSoapWebService extends AsyncTask
private ProcessDialog mProcessDialog = null;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
mProcessDialog = new ProcessDialog(Login.this, "Login", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "validateLogin";
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"username","password"};
Object keyValue[] = { edtUserName.getText().toString().trim() , edtPassword.getText().toString().trim() };
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if( result != null){
JSONObject job_login=null;
JSONObject json_user=null;
String Status="",USERID="",LANGID="",LANGUAGE="";
System.out.println("Login Response " + result);
try {
job_login = new JSONObject(result);
Status=job_login.getString("SUCCESS").toString();
USERID=job_login.getString("ID").toString();
LANGUAGE=job_login.getString("LANGUAGE").toString();
} catch (JSONException e) {
e.printStackTrace();
}
if(job_login != null){
if(Status.equals("OK") ){
try {
json_user=job_login.getJSONObject("USER");
LANGID=json_user.getString("pref_lang_id").toString();
SharedPreferences spLoginUserDetails = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spEdit_Login_Details = spLoginUserDetails.edit();
spEdit_Login_Details.putString(Constant.USER_ID, USERID);
spEdit_Login_Details.putString(Constant.PREF_LANG_ID,LANGID);
spEdit_Login_Details.putString(Constant.PREF_LANG_NAME,LANGUAGE);
spEdit_Login_Details.commit();
new GetCommunityListData().execute();
} catch (JSONException e) {
e.printStackTrace();
}
// if(json_user!=null){
// try {
// jon_array=json_user.getJSONArray("COMMUNITY");
// } catch (JSONException e) {
// e.printStackTrace();
// }
// if(jon_array!=null){
//
// for(int i=0;i
// JsonObjectid=jon_array.getJSONObject(i);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// if(JsonObjectid!=null){
// String strcommunity_id="";
// try {
// strcommunity_id = JsonObjectid.getString("id").toString();
// } catch (JSONException e) {
// e.printStackTrace();
// }
// Constant.alstTempCommunityID.add(strcommunity_id);
// System.out.println("community id" + strcommunity_id);
// }
// }
//
// }
// }
}else{
Toast.makeText(Login.this, Html.fromHtml(Constant.USERNAMEPASSWORD),Toast.LENGTH_SHORT).show();
}
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
//This function is used for get community
private class GetCommunityListData extends AsyncTask
private ProcessDialog mProcesCommunityDialog = null;
@Override
protected void onPreExecute() {
mProcesCommunityDialog = new ProcessDialog(Login.this, "Community", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... UserID) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "GetMethodTable";
SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"user_id"};
Object keyValue[] = {strUserID};
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcesCommunityDialog.dismiss();
if(result != null){
String strSuccess,strMessage;
try {
System.out.println("Community Response : " + result);
JSONObject json_Community = new JSONObject(result);
if(json_Community != null)
{
strSuccess = json_Community.getString("SUCCESS").toString();
if(strSuccess.equals("OK")){
JSONArray jsonArray_CommunityList = json_Community.getJSONArray("COMMUNITY");
if(jsonArray_CommunityList!=null){
OpenDatabase();
mDbHelper.DeleteCommunityList(mSQLiteDatabase);
for(int i=0;i
if(jsonCommunity_attribute!=null){
int id =jsonCommunity_attribute.getInt("id");
int level=jsonCommunity_attribute.getInt("level");
String name=jsonCommunity_attribute.getString("name").toString();
String status=jsonCommunity_attribute.getString("status").toString();
mDbHelper.InsertCommunityList(mSQLiteDatabase, id, level, name, status);
}
}
CloseDataBase();
new GetCategoryListData().execute("");
}
}
else{
strMessage = json_Community.getString("MESSAGE").toString();
Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();
}
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
////This class is used for get Category List
private class GetCategoryListData extends AsyncTask
private ProcessDialog mProcesCategoryDialog = null;
@Override
protected void onPreExecute() {
mProcesCategoryDialog = new ProcessDialog(Login.this, "Category", Constant.LOADING);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String SOAP_URL = getResources().getString(R.string.Webservice_URL);
String SOAP_ACTION = getResources().getString(R.string.SOAP_Action);
String SOAP_NAMESPACE = getResources().getString(R.string.SOAP_NAMESPACE);
String SOAP_METHOD = "GetCategoryTable";
SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);
String keyName[] = {"user_id"};
Object keyValue[] = {strUserID};
return mSoapService.getSoapData(keyName, keyValue);
}
@Override
protected void onPostExecute(String result) {
mProcesCategoryDialog.dismiss();
if(result != null){
String strSuccess,strMessage;
try {
System.out.println("Category Response : " + result);
JSONObject json_Category = new JSONObject(result);
if(json_Category != null)
{
strSuccess = json_Category.getString("SUCCESS").toString();
if(strSuccess.equals("OK")){
JSONArray jsonArray_CategoryList = json_Category.getJSONArray("CATEGORY");
if(jsonArray_CategoryList!=null){
OpenDatabase();
mDbHelper.DeleteCategoryList(mSQLiteDatabase);
for(int i=0;i
if(jsonCategory_attribute!=null){
int id =jsonCategory_attribute.getInt("id");
int level=jsonCategory_attribute.getInt("level");
String name=jsonCategory_attribute.getString("name").toString();
String status=jsonCategory_attribute.getString("status").toString(); mDbHelper.InsertCategoryList(mSQLiteDatabase, id, level, name, status);
}
}
CloseDataBase();
Intent in = new Intent(Login.this, HomeScreen.class);
startActivity(in);
finish();
}
}
else{
strMessage = json_Category.getString("MESSAGE").toString();
Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();
}
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
else{
Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
//*******************************************************************************************************************************
//For open & close database
private DbHelper mDbHelper=null;
private SQLiteDatabase mSQLiteDatabase=null;
private void OpenDatabase()
{
mDbHelper = new DbHelper(this);
mSQLiteDatabase = mDbHelper.getWritableDatabase();
mSQLiteDatabase.setLockingEnabled(true);
}
private void CloseDataBase()
{
if(mDbHelper!=null && mSQLiteDatabase!=null){
if(mSQLiteDatabase.isOpen()){
mSQLiteDatabase.close();
mDbHelper.close();
}
}
}
}
No comments:
Post a Comment