Skip to content

Instantly share code, notes, and snippets.

@sakshiagg1993
Created April 12, 2016 16:11
Show Gist options
  • Save sakshiagg1993/99a0290af2fd885f159214094ccb3239 to your computer and use it in GitHub Desktop.
Save sakshiagg1993/99a0290af2fd885f159214094ccb3239 to your computer and use it in GitHub Desktop.
package me.zhanghai.android.patternlock.sample.app;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import me.zhanghai.android.patternlock.sample.R;
/**
* Created by dev on 30-Mar-16.
*/
public class Main extends AppCompatActivity implements View.OnClickListener {
ProgressDialog mProgressDialog;
EditText Emailid, Phonenumber;
Button save;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Emailid = (EditText) findViewById(R.id.editText_username);
Phonenumber = (EditText) findViewById(R.id.editText_phone);
save = (Button) findViewById(R.id.button_save);
save.setOnClickListener(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
@Override
public void onClick(View v) {
String emailid = " ", phonenumber = " ";
emailid = Emailid.getText().toString();
phonenumber = Phonenumber.getText().toString();
if (emailid.length() == 0) {
Emailid.setError("PLEASE ENTER A VALID EMAIL ID");
} else if (phonenumber.length() != 10) {
Phonenumber.setError("PLEASE ENTER A VALID MOBILE NUMBER");
} else {
Intent intent = new Intent(Main.this, Main2.class);
startActivity(intent);
String url;
url = "http://sakshi.byethost14.com/register2.php?email=" + Emailid + "&phone=" + Phonenumber;
url = url.replaceAll(" ", "%20");
Log.d("url", url);
new Checkemail().execute(url);
}
}
class Checkemail extends AsyncTask<String, Void, Integer> {
@Override
protected void onPreExecute() {
mProgressDialog = new ProgressDialog(Main.this);
// Set progressdialog title
mProgressDialog.setMessage("Submitting data");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setCancelable(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Integer doInBackground(String... params) {
Integer result = 0;
HttpURLConnection urlConnection;
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
int statusCode = urlConnection.getResponseCode();
// 200 represents HTTP OK
if (statusCode == 200) {
BufferedReader r = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
response.append(line);
}
Log.d("str", response.toString());
checkemailfunction(response.toString());
result = 1; // Successful
} else {
result = 0; //"Failed to fetch data!";
}
} catch (Exception e) {
//Log.d(TAG, e.getLocalizedMessage());
}
return result; //"Failed to fetch data!";
}
@Override
protected void onPostExecute(Integer result) {
try {
if ((mProgressDialog != null) && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
} catch (final IllegalArgumentException e) {
// Handle or log or ignore
} catch (final Exception e) {
// Handle or log or ignore
} finally {
mProgressDialog = null;
}
if (result == 1) {
} else {
Toast.makeText(Main.this, "Failed to store data!", Toast.LENGTH_SHORT).show();
}
}
private void checkemailfunction(String result) {
try {
Log.d("this is result", result);
JSONObject jsonObject = new JSONObject(result);
String phonenumber = jsonObject.getString("phonenumber");
String emailid = jsonObject.getString("emailid");
} catch (JSONException e1) {
e1.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment