import org.json.JSONObject;
import com.Webnetware.Sqlitedatabase.DatabaseAdapter;
import com.Webnetware.adapter.ConnectionDetector;
import com.Webnetware.adapter.Listview_Utility;
import com.Webnetware.resApi.RestAPI;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends Activity implements
android.view.View.OnClickListener {
TextView sginUp_btn;
EditText edit_email, editText_password;
String string_email, string_password;
Button btn_signIn;
ProgressDialog progressdialog;
RestAPI obj_restapi = new RestAPI();
ArrayList<HashMap<String, String>> ParameterList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
public static final String Pssword = "PsswordKey";
public static final String Email = "emailKey";
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle(" LogIn");
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
setContentView(R.layout.login_actvity);
setContentView(R.layout.login_actvity);
sginUp_btn = (TextView) findViewById(R.id.textView_registration);
edit_email = (EditText) findViewById(R.id.email);
editText_password = (EditText) findViewById(R.id.password);
btn_signIn = (Button) findViewById(R.id.btn_signUp);
btn_signIn.setOnClickListener(this);
sginUp_btn.setOnClickListener(this);
}
}
//
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressdialog = new ProgressDialog(LoginActivity.this);
progressdialog.setMessage("Please Wait...");
progressdialog.show();
progressdialog.setCancelable(false);
progressdialog.setCanceledOnTouchOutside(false);
}
@Override
protected String doInBackground(String... cname) {
try {
// set json url
obj_restapi.setApiUrl("http://.comp/ais/Login.ashx");
//set json parameter array
obj_restapi.setParameterList(ParameterList);
} catch (Exception e) {
Log.d("Exception", e.toString());
}
return obj_restapi.ResponseApi();
}
@Override
protected void onPostExecute(String result) {
JSONObject json2;
String value = "True";
try {
json2 = new JSONObject(result);
if (value.equals(json2.getString("Message"))) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Email, string_email);
editor.putString(Pssword, string_password);
editor.commit();
Toast.makeText(getApplication(), "Your Well Come...",Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right,R.anim.stay);
if (progressdialog != null) {
progressdialog.dismiss();
}
}
else {
Toast.makeText(getApplication(), "Please Try Again...",Toast.LENGTH_LONG).show();
if (progressdialog != null) {
progressdialog.dismiss();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
overridePendingTransition(R.anim.stay, R.anim.slide_out_right);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_signUp:
string_email = edit_email.getText().toString();
string_password = editText_password.getText().toString();
map.put("EmailID", string_email);
map.put("Password", string_password);
ParameterList.add(map);
new HttpAsyncTask().execute();
break;
case R.id.textView_registration:
Intent intent = new Intent(LoginActivity.this,Registrations.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right,R.anim.stay);
break;
default:
break;
}
}
}